]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
tsdebug: try to fix the locking mess
authorJaroslav Kysela <perex@perex.cz>
Wed, 7 Jun 2017 10:13:14 +0000 (12:13 +0200)
committerJaroslav Kysela <perex@perex.cz>
Wed, 7 Jun 2017 10:13:14 +0000 (12:13 +0200)
src/descrambler/descrambler.c
src/input/mpegts.h
src/input/mpegts/mpegts_input.c
src/input/mpegts/mpegts_mux.c

index d9559d7009650b3750c69483769d279eaf584be2..fbe5d1de9e4bb5535d9c50e251503a76e1efe468 100644 (file)
@@ -699,13 +699,11 @@ fin:
     mpegts_mux_t *mm = ms->s_dvb_mux;
     mpegts_mux_instance_t *mmi = mm ? mm->mm_active : NULL;
     mpegts_input_t *mi = mmi ? mmi->mmi_input : NULL;
-    if (mi == NULL) {
+    if (mi == NULL || (mm->mm_tsdebug_fd < 0 && mm->mm_tsdebug_fd2 < 0)) {
       free(tp);
-      return;
+      goto end;
     }
     pthread_mutex_unlock(&t->s_stream_mutex);
-    pthread_mutex_lock(&mi->mi_output_lock);
-    tp->pos = mm->mm_tsdebug_pos;
     memset(tp->pkt, 0xff, sizeof(tp->pkt));
     tp->pkt[pos++] = 0x47; /* sync byte */
     tp->pkt[pos++] = 0x1f; /* PID MSB */
@@ -727,11 +725,14 @@ fin:
     tp->pkt[pos++] = (crc >> 16) & 0xff;
     tp->pkt[pos++] = (crc >> 8) & 0xff;
     tp->pkt[pos++] = crc & 0xff;
+    pthread_mutex_lock(&mm->mm_tsdebug_lock);
+    tp->pos = mm->mm_tsdebug_pos;
     TAILQ_INSERT_HEAD(&mm->mm_tsdebug_packets, tp, link);
-    pthread_mutex_unlock(&mi->mi_output_lock);
+    pthread_mutex_unlock(&mm->mm_tsdebug_lock);
     return;
   }
 #endif
+end:
   pthread_mutex_unlock(&t->s_stream_mutex);
 }
 
index f641f8215e5b9cf11bab0e9c08caa7e5ef0dde55..ba4e7b5c3e1c1de9b16f894193c0661cdd4be8c7 100644 (file)
@@ -527,21 +527,22 @@ struct mpegts_mux
   /*
    * Configuration
    */
-  char *mm_crid_authority;
-  int   mm_enabled;
-  int   mm_epg;
-  char *mm_charset;
-  int   mm_pmt_ac3;
-  int   mm_eit_tsid_nocheck;
+  char    *mm_crid_authority;
+  int      mm_enabled;
+  int      mm_epg;
+  char    *mm_charset;
+  int      mm_pmt_ac3;
+  int      mm_eit_tsid_nocheck;
   uint16_t mm_sid_filter;
 
   /*
    * TSDEBUG
    */
 #if ENABLE_TSDEBUG
-  int   mm_tsdebug_fd;
-  int   mm_tsdebug_fd2;
-  off_t mm_tsdebug_pos;
+  pthread_mutex_t mm_tsdebug_lock;
+  int             mm_tsdebug_fd;
+  int             mm_tsdebug_fd2;
+  off_t           mm_tsdebug_pos;
   TAILQ_HEAD(, tsdebug_packet) mm_tsdebug_packets;
 #endif
 };
index daefc67861427b0592481c9a6ef95647ead66a21..175a27aa11591a2b5ab7b14f694651c8faab1398 100644 (file)
@@ -1396,10 +1396,11 @@ done:
     pktbuf_ref_dec(pb);
   }
 #if ENABLE_TSDEBUG
-  {
+  if (mm->mm_tsdebug_fd >= 0 || mm->mm_tsdebug_fd2 >= 0) {
     tsdebug_packet_t *tp, *tp_next;
     off_t pos = 0;
     size_t used = tsb - mpkt->mp_data;
+    pthread_mutex_lock(&mm->mm_tsdebug_lock);
     for (tp = TAILQ_FIRST(&mm->mm_tsdebug_packets); tp; tp = tp_next) {
       tp_next = TAILQ_NEXT(tp, link);
       assert((tp->pos % 188) == 0);
@@ -1414,6 +1415,7 @@ done:
     }
     if (pos < used && mm->mm_tsdebug_fd >= 0)
       tvh_write(mm->mm_tsdebug_fd, mpkt->mp_data + pos, used - pos);
+    pthread_mutex_unlock(&mm->mm_tsdebug_lock);
   }
 #endif
 
index 5f4791d62c2f7a110ac81bdcdc6e9eb3147a39e4..ea31ce1623bbb698e6a77901556f94b26f6fbc1a 100644 (file)
@@ -1219,6 +1219,11 @@ mpegts_mux_create0
 
   mm->mm_last_pid            = -1;
 
+#if ENABLE_TSDEBUG
+  pthread_mutex_init(&mm->mm_tsdebug_lock, NULL);
+  mm->mm_tsdebug_fd = mm->mm_tsdebug_fd2 = -1;
+#endif
+
   /* Configuration */
   if (conf)
     idnode_load(&mm->mm_id, conf);