]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
mpegts input: only cleanups for mi_output_lock
authorJaroslav Kysela <perex@perex.cz>
Fri, 14 Nov 2014 17:41:20 +0000 (18:41 +0100)
committerJaroslav Kysela <perex@perex.cz>
Fri, 14 Nov 2014 17:41:20 +0000 (18:41 +0100)
src/input/mpegts/mpegts_input.c
src/input/mpegts/mpegts_mux.c
src/subscriptions.c

index 8605d9d940c9775eadd32560a53fd5b3d5c14439..327ecf20a62f3d6854d2361a1c9f0ca426302ee7 100644 (file)
@@ -363,7 +363,7 @@ mpegts_input_close_pid
   mpegts_pid_t *mp;
   assert(owner != NULL);
   lock_assert(&mi->mi_output_lock);
-  if (!(mp = mpegts_mux_find_pid(mm, pid, 1)))
+  if (!(mp = mpegts_mux_find_pid(mm, pid, 0)))
     return;
   skel.mps_type  = type;
   skel.mps_owner = owner;
@@ -373,17 +373,15 @@ mpegts_input_close_pid
     mm->mm_last_mp = NULL;
   }
   if (mps) {
+    mpegts_mux_nice_name(mm, buf, sizeof(buf));
+    tvhdebug("mpegts", "%s - close PID %04X (%d) [%d/%p]",
+             buf, mp->mp_pid, mp->mp_pid, type, owner);
     RB_REMOVE(&mp->mp_subs, mps, mps_link);
     free(mps);
-
     if (!RB_FIRST(&mp->mp_subs)) {
       RB_REMOVE(&mm->mm_pids, mp, mp_link);
-      if (mp->mp_fd != -1) {
-        mpegts_mux_nice_name(mm, buf, sizeof(buf));
-        tvhdebug("mpegts", "%s - close PID %04X (%d) [%d/%p]",
-               buf, mp->mp_pid, mp->mp_pid, type, owner);
+      if (mp->mp_fd != -1)
         close(mp->mp_fd);
-      }
       free(mp);
     }
   }
@@ -768,6 +766,8 @@ mpegts_input_process
     /* Ignore NUL packets */
     if (pid == 0x1FFF) goto done;
 
+    lock_assert(&mi->mi_output_lock);
+
     /* Find PID */
     if ((mp = mpegts_mux_find_pid(mm, pid, 0))) {
 
index d4a647b0dfc9b2bd530396813c0943f3a9daa599..ddb800234d7ce397a0be3c662094575cbc863091 100644 (file)
@@ -721,14 +721,14 @@ mpegts_mux_stop ( mpegts_mux_t *mm, int force )
   while ((mp = RB_FIRST(&mm->mm_pids))) {
     assert(mi);
     while ((mps = RB_FIRST(&mp->mp_subs))) {
+      tvhdebug("mpegts", "%s - close PID %04X (%d) [%d/%p]", buf,
+               mp->mp_pid, mp->mp_pid, mps->mps_type, mps->mps_owner);
       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);
+    if (mp->mp_fd != -1)
       close(mp->mp_fd);
-    }
     free(mp);
   }
   pthread_mutex_unlock(&mi->mi_output_lock);
@@ -1130,17 +1130,16 @@ mpegts_mux_find_service ( mpegts_mux_t *mm, uint16_t sid)
 static int mp_cmp ( mpegts_pid_t *a, mpegts_pid_t *b )
 {
   return a->mp_pid - b->mp_pid;
-};
+}
 
 mpegts_pid_t *
 mpegts_mux_find_pid_ ( mpegts_mux_t *mm, int pid, int create )
 {
-  mpegts_pid_t *mp;
-  
+  mpegts_pid_t skel, *mp;
+
   if (pid > 0x2000) return NULL;
 
   if (!create) {
-    mpegts_pid_t skel;
     skel.mp_pid = pid;
     mp = RB_FIND(&mm->mm_pids, &skel, mp_link, mp_cmp);
   } else {
index 041983d182071e3f2c38fbf9ac2c70a39f42585d..7bafb89150fb09681485b0ee9d9134c34fbecb0b 100644 (file)
@@ -785,14 +785,11 @@ subscription_create_from_mux(profile_chain_t *prch,
   mi = s->ths_mmi->mmi_input;
   assert(mi);
 
-  if (s->ths_flags & SUBSCRIPTION_FULLMUX) {
-    pthread_mutex_lock(&mi->mi_output_lock);
-    mi->mi_open_pid(mi, mm, MPEGTS_FULLMUX_PID, MPS_NONE, s);
-    pthread_mutex_unlock(&mi->mi_output_lock);
-  }
-
   pthread_mutex_lock(&mi->mi_output_lock);
 
+  if (s->ths_flags & SUBSCRIPTION_FULLMUX)
+    mi->mi_open_pid(mi, mm, MPEGTS_FULLMUX_PID, MPS_NONE, s);
+
   /* Store */
   LIST_INSERT_HEAD(&mm->mm_active->mmi_subs, s, ths_mmi_link);