[FFmpeg-devel] [PATCH 4/5] mpegts: add pcr filter for tracking standalone pcr pids
Marton Balint
cus at passwd.hu
Sun Mar 2 18:34:49 CET 2014
Signed-off-by: Marton Balint <cus at passwd.hu>
---
libavformat/mpegts.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index a0b253d..2881705 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -49,6 +49,7 @@
enum MpegTSFilterType {
MPEGTS_PES,
MPEGTS_SECTION,
+ MPEGTS_PCR,
};
typedef struct MpegTSFilter MpegTSFilter;
@@ -455,6 +456,11 @@ static MpegTSFilter *mpegts_open_pes_filter(MpegTSContext *ts, unsigned int pid,
return filter;
}
+static MpegTSFilter *mpegts_open_pcr_filter(MpegTSContext *ts, unsigned int pid)
+{
+ return mpegts_open_filter(ts, pid, MPEGTS_PCR);
+}
+
static void mpegts_close_filter(MpegTSContext *ts, MpegTSFilter *filter)
{
int pid;
@@ -1766,6 +1772,9 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
p = desc_list_end;
}
+ if (!ts->pids[pcr_pid])
+ mpegts_open_pcr_filter(ts, pcr_pid);
+
out:
for (i = 0; i < mp4_descr_count; i++)
av_free(mp4_descr[i].dec_config_descr);
@@ -1970,7 +1979,7 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
}
}
- if (!has_payload)
+ if (!has_payload && tss->type != MPEGTS_PCR)
return 0;
p = packet + 4;
if (has_adaptation) {
@@ -1979,7 +1988,7 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
}
/* if past the end of packet, ignore */
p_end = packet + TS_PACKET_SIZE;
- if (p >= p_end)
+ if (p > p_end || (p == p_end && tss->type != MPEGTS_PCR))
return 0;
pos = avio_tell(ts->stream->pb);
@@ -2037,9 +2046,11 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
if (parse_pcr(&pcr_h, &pcr_l, packet) == 0)
tss->last_pcr = pcr_h * 300 + pcr_l;
// Note: The position here points actually behind the current packet.
- if ((ret = tss->u.pes_filter.pes_cb(tss, p, p_end - p, is_start,
- pos - ts->raw_packet_size)) < 0)
- return ret;
+ if (tss->type == MPEGTS_PES) {
+ if ((ret = tss->u.pes_filter.pes_cb(tss, p, p_end - p, is_start,
+ pos - ts->raw_packet_size)) < 0)
+ return ret;
+ }
}
return 0;
--
1.8.4.5
More information about the ffmpeg-devel
mailing list