From: Jaroslav Kysela Date: Thu, 27 Oct 2016 18:53:44 +0000 (+0200) Subject: tsfix: put back the MPEG2 PTS code, but only for unset pts, fixes #4040 X-Git-Tag: v4.2.1~244 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=50a370707aedf5c127e92bb517c378aa8ac04657;p=thirdparty%2Ftvheadend.git tsfix: put back the MPEG2 PTS code, but only for unset pts, fixes #4040 --- diff --git a/src/plumbing/tsfix.c b/src/plumbing/tsfix.c index 35ad025b4..02bfb83b5 100644 --- a/src/plumbing/tsfix.c +++ b/src/plumbing/tsfix.c @@ -343,19 +343,28 @@ tsfix_backlog_diff(tsfix_t *tf) /** * + * Recover unset PTS. + * + * MPEG2 DTS/PTS example (rpts = result pts): + * 01: I dts 4922701936 pts 4922712736 rpts 4922712736 + * 02: B dts 4922705536 pts rpts 4922705536 + * 03: B dts 4922709136 pts rpts 4922709136 + * 04: P dts 4922712736 pts rpts 4922723536 + * 05: B dts 4922716336 pts rpts 4922716336 + * 06: B dts 4922719936 pts rpts 4922719936 + * 07: P dts 4922723536 pts rpts 4922734336 + * 08: B dts 4922727136 pts rpts 4922727136 + * 09: B dts 4922730736 pts rpts 4922730736 + * 10: P dts 4922734336 pts rpts 4922745136 + * 11: B dts 4922737936 pts rpts 4922737936 + * 12: B dts 4922741536 pts rpts 4922741536 + * 13: I dts 4922745136 pts 4922755936 rpts 4922755936 */ -#if 1 -static void -recover_pts(tsfix_t *tf, tfstream_t *tfs, th_pkt_t *pkt) -{ - normalize_ts(tf, tfs, pkt, 1); -} -#else static void recover_pts(tsfix_t *tf, tfstream_t *tfs, th_pkt_t *pkt) { - //th_pktref_t *srch; - //int total; + th_pktref_t *srch; + int total; pktref_enqueue(&tf->tf_ptsq, pkt); @@ -369,41 +378,44 @@ recover_pts(tsfix_t *tf, tfstream_t *tfs, th_pkt_t *pkt) switch(pkt->pkt_frametype) { case PKT_B_FRAME: - /* B-frames have same PTS as DTS, pass them on */ - tvhtrace(LS_TSFIX, "%-12s PTS b-frame set to %"PRId64" (old %"PRId64")", - streaming_component_type2txt(tfs->tfs_type), - pkt->pkt_dts, pkt->pkt_pts); - pkt->pkt_pts = pkt->pkt_dts; + if (pkt->pkt_pts == PTS_UNSET) { + /* B-frames have same PTS as DTS, pass them on */ + tvhtrace(LS_TSFIX, "%-12s PTS b-frame set to %"PRId64" (old %"PRId64")", + streaming_component_type2txt(tfs->tfs_type), + pkt->pkt_dts, pkt->pkt_pts); + pkt->pkt_pts = pkt->pkt_dts; + } break; case PKT_I_FRAME: case PKT_P_FRAME: - /* Presentation occures at DTS of next I or P frame, - try to find it */ - total = 0; - PKTREF_FOREACH(srch, &tf->tf_ptsq) { - if (pkt->pkt_componentindex != tfs->tfs_index) - continue; - total++; - if (srch->pr_pkt->pkt_frametype <= PKT_P_FRAME && - pts_is_greater_or_equal(pkt->pkt_dts, srch->pr_pkt->pkt_dts) > 0 && - pts_diff(pkt->pkt_dts, srch->pr_pkt->pkt_dts) < 10 * 90000) { - tvhtrace(LS_TSFIX, "%-12s PTS *-frame set to %"PRId64" (old %"PRId64"), DTS %"PRId64, - streaming_component_type2txt(tfs->tfs_type), - srch->pr_pkt->pkt_dts, pkt->pkt_pts, pkt->pkt_dts); - pkt->pkt_pts = srch->pr_pkt->pkt_dts; - break; - } - - } - if (srch == NULL) { - if (total < 50) { - /* return packet back to tf_ptsq */ - pktref_insert_head(&tf->tf_ptsq, pkt); - } else { - tsfix_packet_drop(tfs, pkt, "mpeg2video overflow"); + if (pkt->pkt_pts == PTS_UNSET) { + /* Presentation occures at DTS of next I or P frame, + try to find it */ + total = 0; + PKTREF_FOREACH(srch, &tf->tf_ptsq) { + if (pkt->pkt_componentindex != tfs->tfs_index) + continue; + total++; + if (srch->pr_pkt->pkt_frametype <= PKT_P_FRAME && + pts_is_greater_or_equal(pkt->pkt_dts, srch->pr_pkt->pkt_dts) > 0 && + pts_diff(pkt->pkt_dts, srch->pr_pkt->pkt_dts) < 10 * 90000) { + tvhtrace(LS_TSFIX, "%-12s PTS *-frame set to %"PRId64" (old %"PRId64"), DTS %"PRId64, + streaming_component_type2txt(tfs->tfs_type), + srch->pr_pkt->pkt_dts, pkt->pkt_pts, pkt->pkt_dts); + pkt->pkt_pts = srch->pr_pkt->pkt_dts; + break; + } + } + if (srch == NULL) { + if (total < 50) { + /* return packet back to tf_ptsq */ + pktref_insert_head(&tf->tf_ptsq, pkt); + } else { + tsfix_packet_drop(tfs, pkt, "mpeg2video overflow"); + } + return; /* not arrived yet or invalid, wait */ } - return; /* not arrived yet or invalid, wait */ } } break; @@ -415,7 +427,6 @@ recover_pts(tsfix_t *tf, tfstream_t *tfs, th_pkt_t *pkt) normalize_ts(tf, tfs, pkt, 1); } } -#endif /**