mpegts tables: reorganize destroy / mt_subscribed code
This commit is contained in:
parent
e2df5d2700
commit
0b2e072076
3 changed files with 42 additions and 30 deletions
|
@ -802,7 +802,10 @@ static inline void mpegts_table_release
|
|||
(mpegts_table_t *mt)
|
||||
{
|
||||
assert(mt->mt_refcount > 0);
|
||||
if(--mt->mt_refcount == 0) mpegts_table_release_(mt);
|
||||
if(--mt->mt_refcount == 0) {
|
||||
assert(mt->mt_destroyed == 1);
|
||||
mpegts_table_release_(mt);
|
||||
}
|
||||
}
|
||||
int mpegts_table_type
|
||||
( mpegts_table_t *mt );
|
||||
|
|
|
@ -770,16 +770,16 @@ mpegts_mux_open_table ( mpegts_mux_t *mm, mpegts_table_t *mt, int subscribe )
|
|||
mi = mm->mm_active->mmi_input;
|
||||
LIST_INSERT_HEAD(&mm->mm_tables, mt, mt_link);
|
||||
mm->mm_num_tables++;
|
||||
mpegts_table_grab(mt);
|
||||
pthread_mutex_unlock(&mm->mm_tables_lock);
|
||||
pthread_mutex_lock(&mi->mi_output_lock);
|
||||
if (subscribe) {
|
||||
mi->mi_open_pid(mi, mm, mt->mt_pid, mpegts_table_type(mt), mt);
|
||||
if (subscribe && !mt->mt_subscribed) {
|
||||
mpegts_table_grab(mt);
|
||||
mt->mt_subscribed = 1;
|
||||
pthread_mutex_unlock(&mm->mm_tables_lock);
|
||||
pthread_mutex_lock(&mi->mi_output_lock);
|
||||
mi->mi_open_pid(mi, mm, mt->mt_pid, mpegts_table_type(mt), mt);
|
||||
pthread_mutex_unlock(&mi->mi_output_lock);
|
||||
pthread_mutex_lock(&mm->mm_tables_lock);
|
||||
mpegts_table_release(mt);
|
||||
}
|
||||
pthread_mutex_unlock(&mi->mi_output_lock);
|
||||
pthread_mutex_lock(&mm->mm_tables_lock);
|
||||
mpegts_table_release(mt);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -819,16 +819,16 @@ mpegts_mux_close_table ( mpegts_mux_t *mm, mpegts_table_t *mt )
|
|||
mi = mm->mm_active->mmi_input;
|
||||
LIST_REMOVE(mt, mt_link);
|
||||
mm->mm_num_tables--;
|
||||
mpegts_table_grab(mt);
|
||||
pthread_mutex_unlock(&mm->mm_tables_lock);
|
||||
pthread_mutex_lock(&mi->mi_output_lock);
|
||||
if (mt->mt_subscribed) {
|
||||
mi->mi_close_pid(mi, mm, mt->mt_pid, mpegts_table_type(mt), mt);
|
||||
mpegts_table_grab(mt);
|
||||
mt->mt_subscribed = 0;
|
||||
pthread_mutex_unlock(&mm->mm_tables_lock);
|
||||
pthread_mutex_lock(&mi->mi_output_lock);
|
||||
mi->mi_close_pid(mi, mm, mt->mt_pid, mpegts_table_type(mt), mt);
|
||||
pthread_mutex_unlock(&mi->mi_output_lock);
|
||||
pthread_mutex_lock(&mm->mm_tables_lock);
|
||||
mpegts_table_release(mt);
|
||||
}
|
||||
pthread_mutex_unlock(&mi->mi_output_lock);
|
||||
pthread_mutex_lock(&mm->mm_tables_lock);
|
||||
mpegts_table_release(mt);
|
||||
}
|
||||
|
||||
/* **************************************************************************
|
||||
|
|
|
@ -148,24 +148,38 @@ mpegts_table_release_ ( mpegts_table_t *mt )
|
|||
if (mt->mt_destroy)
|
||||
mt->mt_destroy(mt);
|
||||
free(mt->mt_name);
|
||||
#if ENABLE_TRACE
|
||||
/* poison */
|
||||
memset(mt, 0xa5, sizeof(*mt));
|
||||
#endif
|
||||
free(mt);
|
||||
}
|
||||
|
||||
static void
|
||||
mpegts_table_destroy_ ( mpegts_table_t *mt )
|
||||
{
|
||||
mpegts_mux_t *mm = mt->mt_mux;
|
||||
|
||||
lock_assert(&mm->mm_tables_lock);
|
||||
|
||||
tvhtrace("mpegts", "table: mux %p destroy %s %02X/%02X (%d) pid %04X (%d)",
|
||||
mm, mt->mt_name, mt->mt_table, mt->mt_mask, mt->mt_table,
|
||||
mt->mt_pid, mt->mt_pid);
|
||||
mpegts_table_consistency_check(mm);
|
||||
mt->mt_destroyed = 1;
|
||||
mt->mt_mux->mm_close_table(mt->mt_mux, mt);
|
||||
mpegts_table_consistency_check(mm);
|
||||
mpegts_table_release(mt);
|
||||
}
|
||||
|
||||
void
|
||||
mpegts_table_destroy ( mpegts_table_t *mt )
|
||||
{
|
||||
mpegts_mux_t *mm = mt->mt_mux;
|
||||
|
||||
pthread_mutex_lock(&mm->mm_tables_lock);
|
||||
tvhtrace("mpegts", "table: mux %p destroy %s %02X/%02X (%d) pid %04X (%d)",
|
||||
mm, mt->mt_name, mt->mt_table, mt->mt_mask, mt->mt_table,
|
||||
mt->mt_pid, mt->mt_pid);
|
||||
mpegts_table_consistency_check(mm);
|
||||
mt->mt_destroyed = 1;
|
||||
mt->mt_mux->mm_close_table(mt->mt_mux, mt);
|
||||
mpegts_table_consistency_check(mm);
|
||||
mpegts_table_destroy_(mt);
|
||||
pthread_mutex_unlock(&mm->mm_tables_lock);
|
||||
mpegts_table_release(mt);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -271,13 +285,8 @@ mpegts_table_flush_all ( mpegts_mux_t *mm )
|
|||
}
|
||||
while ((mt = LIST_FIRST(&mm->mm_tables))) {
|
||||
mt->mt_flags &= ~MT_DEFER; /* force destroy */
|
||||
mt->mt_destroyed = 1; /* early destroy mark */
|
||||
mpegts_table_grab(mt);
|
||||
mpegts_table_consistency_check(mm);
|
||||
pthread_mutex_unlock(&mm->mm_tables_lock);
|
||||
mpegts_table_destroy(mt);
|
||||
mpegts_table_release(mt);
|
||||
pthread_mutex_lock(&mm->mm_tables_lock);
|
||||
mpegts_table_destroy_(mt);
|
||||
mpegts_table_consistency_check(mm);
|
||||
}
|
||||
assert(mm->mm_num_tables == 0);
|
||||
|
|
Loading…
Add table
Reference in a new issue