From: Jaroslav Kysela Date: Mon, 3 Apr 2017 16:00:16 +0000 (+0200) Subject: packet: carry the packet contents type in the packet info data X-Git-Tag: v4.2.1~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7fa903f6e52606fe9abf491be6e30c00a3a4190;p=thirdparty%2Ftvheadend.git packet: carry the packet contents type in the packet info data --- diff --git a/src/packet.c b/src/packet.c index 18e4b7048..919989d1e 100644 --- a/src/packet.c +++ b/src/packet.c @@ -52,12 +52,14 @@ pkt_destroy(th_pkt_t *pkt) * suppoed to take care of) */ th_pkt_t * -pkt_alloc(const void *data, size_t datalen, int64_t pts, int64_t dts) +pkt_alloc(streaming_component_type_t type, const void *data, size_t datalen, + int64_t pts, int64_t dts) { th_pkt_t *pkt; pkt = calloc(1, sizeof(th_pkt_t)); if (pkt) { + pkt->pkt_type = type; if(datalen) pkt->pkt_payload = pktbuf_alloc(data, datalen); pkt->pkt_dts = dts; @@ -148,7 +150,7 @@ pkt_ref_inc_poly(th_pkt_t *pkt, int n) */ void pkt_trace_(const char *file, int line, int subsys, th_pkt_t *pkt, - int index, streaming_component_type_t type, const char *fmt, ...) + const char *fmt, ...) { char buf[512], _dts[22], _pts[22], _type[2]; va_list args; @@ -166,8 +168,8 @@ pkt_trace_(const char *file, int line, int subsys, th_pkt_t *pkt, " dur %d len %zu err %i%s", fmt ? fmt : "", fmt ? " (" : "", - index, - streaming_component_type2txt(type), + pkt->pkt_componentindex, + streaming_component_type2txt(pkt->pkt_type), _type[0] ? " type " : "", _type, pts_to_string(pkt->pkt_dts, _dts), pts_to_string(pkt->pkt_pts, _pts), diff --git a/src/packet.h b/src/packet.h index 88339e6f3..14b07af90 100644 --- a/src/packet.h +++ b/src/packet.h @@ -54,15 +54,17 @@ typedef struct th_pkt { int pkt_duration; int pkt_refcount; - uint8_t pkt_commercial; + uint8_t pkt_type; + uint8_t pkt_err; uint8_t pkt_componentindex; + uint8_t pkt_commercial; + uint8_t pkt_frametype; uint8_t pkt_field; // Set if packet is only a half frame (a field) uint8_t pkt_channels; uint8_t pkt_sri; uint8_t pkt_ext_sri; - uint8_t pkt_err; uint16_t pkt_aspect_num; uint16_t pkt_aspect_den; @@ -111,7 +113,8 @@ void pktref_insert_head(struct th_pktref_queue *q, th_pkt_t *pkt); #define PKTREF_FOREACH(item, queue) TAILQ_FOREACH((item), (queue), pr_link) -th_pkt_t *pkt_alloc(const void *data, size_t datalen, int64_t pts, int64_t dts); +th_pkt_t *pkt_alloc(streaming_component_type_t type, + const void *data, size_t datalen, int64_t pts, int64_t dts); th_pkt_t *pkt_copy_shallow(th_pkt_t *pkt); @@ -121,12 +124,12 @@ th_pktref_t *pktref_create(th_pkt_t *pkt); void pkt_trace_ (const char *file, int line, int subsys, th_pkt_t *pkt, - int index, streaming_component_type_t type, const char *fmt, ...); + const char *fmt, ...); -#define pkt_trace(subsys, pkt, index, type, fmt, ...) \ +#define pkt_trace(subsys, pkt, fmt, ...) \ do { \ if (tvhtrace_enabled()) \ - pkt_trace_(__FILE__, __LINE__, subsys, pkt, index, type, fmt, ##__VA_ARGS__); \ + pkt_trace_(__FILE__, __LINE__, subsys, pkt, fmt, ##__VA_ARGS__); \ } while (0) /* diff --git a/src/parsers/parser_latm.c b/src/parsers/parser_latm.c index 2961de69b..add36a7d2 100644 --- a/src/parsers/parser_latm.c +++ b/src/parsers/parser_latm.c @@ -260,7 +260,7 @@ parse_latm_audio_mux_element(service_t *t, elementary_stream_t *st, if(st->es_curdts == PTS_UNSET) return NULL; - th_pkt_t *pkt = pkt_alloc(NULL, slot_len + 7, st->es_curdts, st->es_curdts); + th_pkt_t *pkt = pkt_alloc(st->es_type, NULL, slot_len + 7, st->es_curdts, st->es_curdts); pkt->pkt_commercial = t->s_tt_commercial_advice; pkt->pkt_duration = st->es_frame_duration; diff --git a/src/parsers/parser_teletext.c b/src/parsers/parser_teletext.c index 183e755be..66d77fe1f 100644 --- a/src/parsers/parser_teletext.c +++ b/src/parsers/parser_teletext.c @@ -793,7 +793,7 @@ extract_subtitle(mpegts_service_t *t, elementary_stream_t *st, sub[off++] = 0; - th_pkt_t *pkt = pkt_alloc(sub, off, pts, pts); + th_pkt_t *pkt = pkt_alloc(st->es_type, sub, off, pts, pts); pkt->pkt_componentindex = st->es_index; streaming_pad_deliver(&t->s_streaming_pad, streaming_msg_create_pkt(pkt)); diff --git a/src/parsers/parsers.c b/src/parsers/parsers.c index 60d25fc89..79555129d 100644 --- a/src/parsers/parsers.c +++ b/src/parsers/parsers.c @@ -532,7 +532,7 @@ makeapkt(service_t *t, elementary_stream_t *st, const void *buf, int len, int64_t dts, int duration, int channels, int sri, int errors) { - th_pkt_t *pkt = pkt_alloc(buf, len, dts, dts); + th_pkt_t *pkt = pkt_alloc(st->es_type, buf, len, dts, dts); pkt->pkt_commercial = t->s_tt_commercial_advice; pkt->pkt_duration = duration; @@ -1196,7 +1196,7 @@ parse_mpeg2video(service_t *t, elementary_stream_t *st, size_t len, if(st->es_curpkt != NULL) pkt_ref_dec(st->es_curpkt); - pkt = pkt_alloc(NULL, 0, st->es_curpts, st->es_curdts); + pkt = pkt_alloc(st->es_type, NULL, 0, st->es_curpts, st->es_curdts); pkt->pkt_frametype = frametype; pkt->pkt_duration = st->es_frame_duration; pkt->pkt_commercial = t->s_tt_commercial_advice; @@ -1487,7 +1487,7 @@ parse_h264(service_t *t, elementary_stream_t *st, size_t len, if (st->es_frame_duration == 0) st->es_frame_duration = 1; - pkt = pkt_alloc(NULL, 0, st->es_curpts, st->es_curdts); + pkt = pkt_alloc(st->es_type, NULL, 0, st->es_curpts, st->es_curdts); pkt->pkt_frametype = pkttype; pkt->pkt_field = isfield; pkt->pkt_duration = st->es_frame_duration; @@ -1612,7 +1612,7 @@ parse_hevc(service_t *t, elementary_stream_t *st, size_t len, if (r > 0) return PARSER_APPEND; - st->es_curpkt = pkt_alloc(NULL, 0, st->es_curpts, st->es_curdts); + st->es_curpkt = pkt_alloc(st->es_type, NULL, 0, st->es_curpts, st->es_curdts); st->es_curpkt->pkt_frametype = pkttype; st->es_curpkt->pkt_field = 0; st->es_curpkt->pkt_duration = st->es_frame_duration; @@ -1757,7 +1757,7 @@ parse_subtitles(service_t *t, elementary_stream_t *st, const uint8_t *data, // end_of_PES_data_field_marker if(buf[psize - 1] == 0xff) { - pkt = pkt_alloc(buf, psize - 1, st->es_curpts, st->es_curdts); + pkt = pkt_alloc(st->es_type, buf, psize - 1, st->es_curpts, st->es_curdts); pkt->pkt_commercial = t->s_tt_commercial_advice; pkt->pkt_err = st->es_buf.sb_err; parser_deliver(t, st, pkt); @@ -1809,7 +1809,7 @@ parse_teletext(service_t *t, elementary_stream_t *st, const uint8_t *data, if(psize >= 46) { teletext_input((mpegts_service_t *)t, st, buf, psize); - pkt = pkt_alloc(buf, psize, st->es_curpts, st->es_curdts); + pkt = pkt_alloc(st->es_type, buf, psize, st->es_curpts, st->es_curdts); pkt->pkt_commercial = t->s_tt_commercial_advice; pkt->pkt_err = st->es_buf.sb_err; parser_deliver(t, st, pkt); @@ -1830,7 +1830,9 @@ parser_deliver(service_t *t, elementary_stream_t *st, th_pkt_t *pkt) t->s_current_pts = (pkt->pkt_pts + (int64_t)t->s_pts_shift * 900) % PTS_MASK; } - pkt_trace(LS_PARSER, pkt, st->es_index, st->es_type, "deliver"); + pkt->pkt_componentindex = st->es_index; + + pkt_trace(LS_PARSER, pkt, "deliver"); pkt->pkt_aspect_num = st->es_aspect_num; pkt->pkt_aspect_den = st->es_aspect_den; @@ -1844,8 +1846,6 @@ parser_deliver(service_t *t, elementary_stream_t *st, th_pkt_t *pkt) } /* Forward packet */ - pkt->pkt_componentindex = st->es_index; - streaming_pad_deliver(&t->s_streaming_pad, streaming_msg_create_pkt(pkt)); /* Decrease our own reference to the packet */ @@ -1863,7 +1863,7 @@ parser_deliver_error(service_t *t, elementary_stream_t *st) if (!st->es_buf.sb_err) return; - pkt = pkt_alloc(NULL, 0, PTS_UNSET, PTS_UNSET); + pkt = pkt_alloc(st->es_type, NULL, 0, PTS_UNSET, PTS_UNSET); pkt->pkt_err = st->es_buf.sb_err; parser_deliver(t, st, pkt); st->es_buf.sb_err = 0; @@ -1885,7 +1885,7 @@ parser_backlog(service_t *t, elementary_stream_t *st, th_pkt_t *pkt) int64_t pts = pkt->pkt_pts; pkt->pkt_dts = pts_no_backlog(dts); pkt->pkt_pts = pts_no_backlog(pts); - pkt_trace(LS_PARSER, pkt, st->es_index, st->es_type, "backlog"); + pkt_trace(LS_PARSER, pkt, "backlog"); pkt->pkt_dts = dts; pkt->pkt_pts = pts; } diff --git a/src/plumbing/globalheaders.c b/src/plumbing/globalheaders.c index 52e906af1..203387f44 100644 --- a/src/plumbing/globalheaders.c +++ b/src/plumbing/globalheaders.c @@ -295,7 +295,7 @@ gh_hold(globalheaders_t *gh, streaming_message_t *sm) return; } - pkt_trace(LS_GLOBALHEADERS, pkt, pkt->pkt_componentindex, ssc->ssc_type, "hold receive"); + pkt_trace(LS_GLOBALHEADERS, pkt, "hold receive"); pkt_ref_inc(pkt); diff --git a/src/plumbing/transcoding.c b/src/plumbing/transcoding.c index 1f2427bd0..7383447b2 100644 --- a/src/plumbing/transcoding.c +++ b/src/plumbing/transcoding.c @@ -850,7 +850,7 @@ scleanup: extra_size = 7; } - n = pkt_alloc(NULL, packet.size + extra_size, packet.pts, packet.pts); + n = pkt_alloc(ts->ts_type, NULL, packet.size + extra_size, packet.pts, packet.pts); memcpy(pktbuf_ptr(n->pkt_payload) + extra_size, packet.data, packet.size); n->pkt_componentindex = ts->ts_index; @@ -969,12 +969,12 @@ send_video_packet(transcoder_t *t, transcoder_stream_t *ts, th_pkt_t *pkt, if ((ts->ts_type == SCT_H264 || ts->ts_type == SCT_HEVC) && octx->extradata_size && (ts->ts_first || octx->coded_frame->pict_type == AV_PICTURE_TYPE_I)) { - n = pkt_alloc(NULL, octx->extradata_size + epkt->size, epkt->pts, epkt->dts); + n = pkt_alloc(ts->ts_type, NULL, octx->extradata_size + epkt->size, epkt->pts, epkt->dts); memcpy(pktbuf_ptr(n->pkt_payload), octx->extradata, octx->extradata_size); memcpy(pktbuf_ptr(n->pkt_payload) + octx->extradata_size, epkt->data, epkt->size); ts->ts_first = 0; } else { - n = pkt_alloc(epkt->data, epkt->size, epkt->pts, epkt->dts); + n = pkt_alloc(ts->ts_type, epkt->data, epkt->size, epkt->pts, epkt->dts); } switch (octx->coded_frame->pict_type) { @@ -1213,7 +1213,7 @@ transcoder_stream_video(transcoder_t *t, transcoder_stream_t *ts, th_pkt_t *pkt) if (!vs->vid_first_sent) { /* notify global headers that we're live */ /* the video packets might be delayed */ - pkt2 = pkt_alloc(NULL, 0, pkt->pkt_pts, pkt->pkt_dts); + pkt2 = pkt_alloc(ts->ts_type, NULL, 0, pkt->pkt_pts, pkt->pkt_dts); pkt2->pkt_componentindex = pkt->pkt_componentindex; sm = streaming_msg_create_pkt(pkt2); streaming_target_deliver2(ts->ts_target, sm); diff --git a/src/plumbing/tsfix.c b/src/plumbing/tsfix.c index db8e21ec2..1b69f897b 100644 --- a/src/plumbing/tsfix.c +++ b/src/plumbing/tsfix.c @@ -191,7 +191,7 @@ tsfix_stop(tsfix_t *tf) static void tsfix_packet_drop(tfstream_t *tfs, th_pkt_t *pkt, const char *reason) { - pkt_trace(LS_TSFIX, pkt, tfs->tfs_index, tfs->tfs_type, "drop"); + pkt_trace(LS_TSFIX, pkt, "drop"); pkt_ref_dec(pkt); } @@ -288,7 +288,7 @@ normalize_ts(tsfix_t *tf, tfstream_t *tfs, th_pkt_t *pkt, int backlog) deliver: if (tvhtrace_enabled()) { char _odts[22], _opts[22]; - pkt_trace(LS_TSFIX, pkt, tfs->tfs_index, tfs->tfs_type, + pkt_trace(LS_TSFIX, pkt, "deliver odts %s opts %s ref %"PRId64" epoch %"PRId64, pts_to_string(odts, _odts), pts_to_string(opts, _opts), ref, tfs->tfs_dts_epoch);