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);
+}
/**
*
}
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;
+}
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)
+
/*
*
*/
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)
return 0;
}
+const char *pts_to_string(int64_t pts, char *buf);
+
#endif /* PACKET_H_ */
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;
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
}
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);
}
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) {
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;
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) {
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);