mpegts mux: the mm_pids flush must be protected by mi_output_lock

This commit is contained in:
Jaroslav Kysela 2014-10-21 16:07:59 +02:00
parent 33449e80f5
commit 43a7a077e6

View file

@ -713,19 +713,26 @@ mpegts_mux_stop ( mpegts_mux_t *mm, int force )
mpegts_input_flush_mux(mi, mm); mpegts_input_flush_mux(mi, mm);
/* Ensure PIDs are cleared */ /* Ensure PIDs are cleared */
mm->mm_last_pid = -1; if (mi) {
mm->mm_last_mp = NULL; pthread_mutex_lock(&mi->mi_output_lock);
while ((mp = RB_FIRST(&mm->mm_pids))) { mm->mm_last_pid = -1;
while ((mps = RB_FIRST(&mp->mp_subs))) { mm->mm_last_mp = NULL;
RB_REMOVE(&mp->mp_subs, mps, mps_link); while ((mp = RB_FIRST(&mm->mm_pids))) {
free(mps); assert(mi);
while ((mps = RB_FIRST(&mp->mp_subs))) {
RB_REMOVE(&mp->mp_subs, mps, mps_link);
free(mps);
}
RB_REMOVE(&mm->mm_pids, mp, mp_link);
if (mp->mp_fd != -1) {
tvhdebug("mpegts", "%s - close PID %04X (%d)", buf, mp->mp_pid, mp->mp_pid);
close(mp->mp_fd);
}
free(mp);
} }
RB_REMOVE(&mm->mm_pids, mp, mp_link); pthread_mutex_unlock(&mi->mi_output_lock);
if (mp->mp_fd != -1) { } else {
tvhdebug("mpegts", "%s - close PID %04X (%d)", buf, mp->mp_pid, mp->mp_pid); assert(RB_FIRST(&mm->mm_pids) == NULL);
close(mp->mp_fd);
}
free(mp);
} }
/* Scanning */ /* Scanning */