mpegts input: another optimization for mpegts_mux_find_pid_()

This commit is contained in:
Jaroslav Kysela 2014-11-16 10:54:36 +01:00
parent eb600253ae
commit 6ce9b4d3b1
3 changed files with 7 additions and 18 deletions

View file

@ -864,7 +864,6 @@ dvb_sat_position_to_str(int position, char *buf, size_t buflen)
snprintf(buf, buflen, "%d", abs(position / 10));
if (dec)
snprintf(buf + strlen(buf), buflen - strlen(buf), ".%d", abs(dec));
snprintf(buf + strlen(buf), buflen - strlen(buf), "%c", position < 0 ? 'W' : 'E');
return buf;
}
@ -899,19 +898,13 @@ dvb_sat_position_from_str( const char *buf )
/**
*
*/
extern pthread_mutex_t mpegts_pid_skel_mutex;
void dvb_init( void )
{
pthread_mutex_init(&mpegts_pid_skel_mutex, NULL);
}
void dvb_done( void )
{
extern SKEL_DECLARE(mpegts_table_state_skel, struct mpegts_table_state);
extern SKEL_DECLARE(mpegts_pid_skel, mpegts_pid_t);
SKEL_FREE(mpegts_table_state_skel);
SKEL_FREE(mpegts_pid_skel);
pthread_mutex_destroy(&mpegts_pid_skel_mutex);
}

View file

@ -349,6 +349,7 @@ mpegts_input_open_pid
buf, mp->mp_pid, mp->mp_pid, type, owner);
} else {
free(mps);
mps = NULL;
}
}
return mp;

View file

@ -28,9 +28,6 @@
#include <assert.h>
pthread_mutex_t mpegts_pid_skel_mutex;
SKEL_DECLARE(mpegts_pid_skel, mpegts_pid_t);
static void mpegts_mux_scan_timeout ( void *p );
/* ****************************************************************************
@ -1143,17 +1140,15 @@ mpegts_mux_find_pid_ ( mpegts_mux_t *mm, int pid, int create )
skel.mp_pid = pid;
mp = RB_FIND(&mm->mm_pids, &skel, mp_link, mp_cmp);
if (mp == NULL && create) {
pthread_mutex_lock(&mpegts_pid_skel_mutex);
SKEL_ALLOC(mpegts_pid_skel);
mpegts_pid_skel->mp_pid = pid;
mp = RB_INSERT_SORTED(&mm->mm_pids, mpegts_pid_skel, mp_link, mp_cmp);
if (!mp) {
mp = mpegts_pid_skel;
SKEL_USED(mpegts_pid_skel);
mp = calloc(1, sizeof(*mp));
mp->mp_pid = pid;
if (!RB_INSERT_SORTED(&mm->mm_pids, mp, mp_link, mp_cmp)) {
mp->mp_fd = -1;
mp->mp_cc = -1;
} else {
free(mp);
mp = NULL;
}
pthread_mutex_unlock(&mpegts_pid_skel_mutex);
}
if (mp) {
mm->mm_last_pid = pid;