]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
parsers, tsfix: improve the packet log, merge common code
authorJaroslav Kysela <perex@perex.cz>
Sun, 14 Aug 2016 08:01:16 +0000 (10:01 +0200)
committerJaroslav Kysela <perex@perex.cz>
Sun, 14 Aug 2016 08:01:16 +0000 (10:01 +0200)
src/packet.c
src/packet.h
src/parsers/parsers.c
src/plumbing/tsfix.c

index 96cd78358792cf9239ace196c775e4cd32d9be57..6eb6b683fe1438a732de5bfd0cc28170432ae68a 100644 (file)
@@ -143,6 +143,41 @@ pkt_ref_inc_poly(th_pkt_t *pkt, int n)
   atomic_add(&pkt->pkt_refcount, n);
 }
 
+/**
+ *
+ */
+void
+pkt_trace_(const char *file, int line, const char *subsys, th_pkt_t *pkt,
+           int index, streaming_component_type_t type, const char *fmt, ...)
+{
+  char buf[512], _dts[22], _pts[22], _type[2];
+  va_list args;
+
+  va_start(args, fmt);
+  if (pkt->pkt_frametype) {
+    _type[0] = pkt_frametype_to_char(pkt->pkt_frametype);
+    _type[1] = '\0';
+  } else {
+    _type[0] = '\0';
+  }
+  snprintf(buf, sizeof(buf),
+           "%s%spkt stream %d %s%s%s"
+           " dts %s pts %s"
+           " dur %d len %zu err %i%s",
+           fmt ? fmt : "",
+           fmt ? " (" : "",
+           index,
+           streaming_component_type2txt(type),
+           _type[0] ? " type " : "", _type,
+           pts_to_string(pkt->pkt_dts, _dts),
+           pts_to_string(pkt->pkt_pts, _pts),
+           pkt->pkt_duration,
+           pktbuf_len(pkt->pkt_payload),
+           pkt->pkt_err,
+           fmt ? ")" : "");
+  tvhlogv(file, line, 0, LOG_TRACE, subsys, buf, &args);
+  va_end(args);
+}
 
 /**
  *
@@ -327,3 +362,15 @@ pktbuf_append(pktbuf_t *pb, const void *data, size_t size)
   }
   return pb;
 }
+
+/*
+ *
+ */
+
+const char *pts_to_string(int64_t pts, char *buf)
+{
+  if (pts == PTS_UNSET)
+    return strcpy(buf, "<unset>");
+  snprintf(buf, 22, "%"PRId64, pts);
+  return buf;
+}
index 9253201e2305b86e7a8a7320d95bf2a573ea9bfb..77f0bce8b0dc2cf5ae2f87816803950166a2840e 100644 (file)
@@ -119,6 +119,16 @@ th_pkt_t *pkt_copy_nodata(th_pkt_t *pkt);
 
 th_pktref_t *pktref_create(th_pkt_t *pkt);
 
+void pkt_trace_
+  (const char *file, int line, const char *subsys, th_pkt_t *pkt,
+   int index, streaming_component_type_t type, const char *fmt, ...);
+
+#define pkt_trace(subsys, pkt, index, type, fmt, ...) \
+  do { \
+    if (tvhtrace_enabled()) \
+      pkt_trace_(__FILE__, __LINE__, subsys, pkt, index, type, fmt, ##__VA_ARGS__); \
+  } while (0)
+
 /*
  *
  */
@@ -138,6 +148,10 @@ pktbuf_t *pktbuf_append(pktbuf_t *pb, const void *data, size_t size);
 static inline size_t   pktbuf_len(pktbuf_t *pb) { return pb ? pb->pb_size : 0; }
 static inline uint8_t *pktbuf_ptr(pktbuf_t *pb) { return pb->pb_data; }
 
+/*
+ *
+ */
+
 static inline int64_t pts_diff(int64_t a, int64_t b)
 {
   if (a == PTS_UNSET || b == PTS_UNSET)
@@ -163,4 +177,6 @@ static inline int pts_is_greater_or_equal(int64_t base, int64_t value)
   return 0;
 }
 
+const char *pts_to_string(int64_t pts, char *buf);
+
 #endif /* PACKET_H_ */
index 793ffcb6e46302490a47c9c69670f77c6883dcd1..6151641bce316297dc7c4aa22c6713118e3f4732 100644 (file)
@@ -1822,20 +1822,7 @@ parser_deliver(service_t *t, elementary_stream_t *st, th_pkt_t *pkt)
       pkt->pkt_pts < t->s_current_pts - 180000))
     t->s_current_pts = pkt->pkt_pts;
 
-  tvhtrace("parser",
-           "pkt stream %2d %-12s type %c"
-           " dts %10"PRId64" (%10"PRId64") pts %10"PRId64" (%10"PRId64")"
-           " dur %10d len %10zu err %i",
-           st->es_index,
-           streaming_component_type2txt(st->es_type),
-           pkt_frametype_to_char(pkt->pkt_frametype),
-           ts_rescale(pkt->pkt_dts, 1000000),
-           pkt->pkt_dts,
-           ts_rescale(pkt->pkt_pts, 1000000),
-           pkt->pkt_pts,
-           pkt->pkt_duration,
-           pktbuf_len(pkt->pkt_payload),
-           pkt->pkt_err);
+  pkt_trace("parser", pkt, st->es_index, st->es_type, "deliver");
 
   pkt->pkt_aspect_num = st->es_aspect_num;
   pkt->pkt_aspect_den = st->es_aspect_den;
@@ -1885,24 +1872,15 @@ parser_backlog(service_t *t, elementary_stream_t *st, th_pkt_t *pkt)
   pkt_ref_dec(pkt); /* streaming_msg_create_pkt increses ref counter */
 
 #if ENABLE_TRACE
-  int64_t dts = pts_no_backlog(pkt->pkt_dts);
-  int64_t pts = pts_no_backlog(pkt->pkt_pts);
-  tvhtrace("parser",
-           "pkt bcklog %2d %-12s type %c"
-           " dts%s%10"PRId64" (%10"PRId64") pts%s%10"PRId64" (%10"PRId64")"
-           " dur %10d len %10zu err %i",
-           st->es_index,
-           streaming_component_type2txt(st->es_type),
-           pkt_frametype_to_char(pkt->pkt_frametype),
-           pts_is_backlog(pkt->pkt_dts) ? "+" : " ",
-           ts_rescale(dts, 1000000),
-           dts,
-           pts_is_backlog(pkt->pkt_pts) ? "+" : " ",
-           ts_rescale(pts, 1000000),
-           pts,
-           pkt->pkt_duration,
-           pktbuf_len(pkt->pkt_payload),
-           pkt->pkt_err);
+  if (tvhtrace_enabled()) {
+    int64_t dts = pkt->pkt_dts;
+    int64_t pts = pkt->pkt_pts;
+    pkt->pkt_dts = pts_no_backlog(dts);
+    pkt->pkt_pts = pts_no_backlog(pts);
+    pkt_trace("parser", pkt, st->es_index, st->es_type, "backlog");
+    pkt->pkt_dts = dts;
+    pkt->pkt_pts = pts;
+  }
 #endif
 }
 
index d4380966fd181d91777592a6aff6942be306178f..6497b7b6664941ee52fa05e710aaafabb638e31d 100644 (file)
@@ -191,14 +191,7 @@ tsfix_stop(tsfix_t *tf)
 static void
 tsfix_packet_drop(tfstream_t *tfs, th_pkt_t *pkt, const char *reason)
 {
-  tvhtrace("tsfix", "DROP: %-12s %c %10"PRId64" %10"PRId64" %10d %zd (%s)",
-             streaming_component_type2txt(tfs->tfs_type),
-             pkt_frametype_to_char(pkt->pkt_frametype),
-             pkt->pkt_dts,
-             pkt->pkt_pts,
-             pkt->pkt_duration,
-             pktbuf_len(pkt->pkt_payload),
-             reason);
+  pkt_trace("tsfix", pkt, tfs->tfs_index, tfs->tfs_type, "drop");
   pkt_ref_dec(pkt);
 }
 
@@ -208,7 +201,7 @@ tsfix_packet_drop(tfstream_t *tfs, th_pkt_t *pkt, const char *reason)
 static void
 normalize_ts(tsfix_t *tf, tfstream_t *tfs, th_pkt_t *pkt, int backlog)
 {
-  int64_t ref, dts, d;
+  int64_t ref, dts, odts, opts, d;
 
   if(tf->tf_tsref == PTS_UNSET) {
     if (backlog) {
@@ -220,6 +213,10 @@ normalize_ts(tsfix_t *tf, tfstream_t *tfs, th_pkt_t *pkt, int backlog)
     return;
   }
 
+  ref = tfs->tfs_local_ref != PTS_UNSET ? tfs->tfs_local_ref : tf->tf_tsref;
+  odts = pkt->pkt_dts;
+  opts = pkt->pkt_pts;
+
   if (pkt->pkt_dts == PTS_UNSET) {
     if (pkt->pkt_pts != PTS_UNSET)
       pkt->pkt_dts = pkt->pkt_pts;
@@ -230,7 +227,6 @@ normalize_ts(tsfix_t *tf, tfstream_t *tfs, th_pkt_t *pkt, int backlog)
   pkt->pkt_dts &= PTS_MASK;
 
   /* Subtract the transport wide start offset */
-  ref = tfs->tfs_local_ref != PTS_UNSET ? tfs->tfs_local_ref : tf->tf_tsref;
   dts = pkt->pkt_dts - ref;
 
   if (tfs->tfs_last_dts_norm == PTS_UNSET) {
@@ -289,13 +285,13 @@ normalize_ts(tsfix_t *tf, tfstream_t *tfs, th_pkt_t *pkt, int backlog)
   pkt->pkt_dts = dts;
 
 deliver:
-  tvhtrace("tsfix", "%-12s %c %10"PRId64" %10"PRId64" %10d %zd",
-             streaming_component_type2txt(tfs->tfs_type),
-             pkt_frametype_to_char(pkt->pkt_frametype),
-             pkt->pkt_dts,
-             pkt->pkt_pts,
-             pkt->pkt_duration,
-             pktbuf_len(pkt->pkt_payload));
+  if (tvhtrace_enabled()) {
+    char _odts[22], _opts[22];
+    pkt_trace("tsfix", pkt, tfs->tfs_index, tfs->tfs_type,
+              "deliver odts %s opts %s ref %"PRId64" epoch %"PRId64,
+              pts_to_string(odts, _odts), pts_to_string(opts, _opts),
+              ref, tfs->tfs_dts_epoch);
+  }
 
   streaming_message_t *sm = streaming_msg_create_pkt(pkt);
   streaming_target_deliver2(tf->tf_output, sm);