diff options
author | John Högberg <john.hogberg@ericsson.com> | 2015-04-28 10:20:33 +0200 |
---|---|---|
committer | Reinhard Tartler <siretart@tauware.de> | 2015-05-31 11:14:03 -0400 |
commit | feedde4d8702d554a7f46de824a887fe4d75a714 (patch) | |
tree | f6ee1db8a9db572a58ef1dc6b94d87fa763f4997 | |
parent | 4c4cc9b27b69a86e405fd7612aa0a62f3b62b027 (diff) | |
download | ffmpeg-feedde4d8702d554a7f46de824a887fe4d75a714.tar.gz |
mpegts: Update the PSI/SI table only if the version change
If a PAT is finished while a PMT section filter is opened but
not yet finished, the PMT section filter is closed and all
the received data is discarded.
This is usually not an issue but some multiplexers (With very
quick PAT/PMT repetition settings) consistently emit a PMT
section start, then a PAT, and then the rest of the PMT,
causing the aforementioned behavior to result in no PMT being
finished.
In the most pathologic situation the stream information are lost
and the probe fallback miscategorizes subtitles as mp3 audio.
Avoid the issue through eliminating redundant PSI/SI table
updates by checking their version field, which is required by
the standard to be incremented on every change no matter how
minor.
CC: libav-stable@libav.org
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
(cherry picked from commit 844201e35fe575710be8218d45828df49b77f205)
Signed-off-by: Reinhard Tartler <siretart@tauware.de>
Conflicts:
libavformat/mpegts.c
-rw-r--r-- | libavformat/mpegts.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 3f828b4f26..88bef79db0 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -66,6 +66,7 @@ typedef void SetServiceCallback(void *opaque, int ret); typedef struct MpegTSSectionFilter { int section_index; int section_h_size; + int last_ver; uint8_t *section_buf; unsigned int check_crc:1; unsigned int end_of_section_reached:1; @@ -340,6 +341,8 @@ static MpegTSFilter *mpegts_open_section_filter(MpegTSContext *ts, unsigned int sec->opaque = opaque; sec->section_buf = av_malloc(MAX_SECTION_SIZE); sec->check_crc = check_crc; + sec->last_ver = -1; + if (!sec->section_buf) { av_free(filter); return NULL; @@ -1186,6 +1189,7 @@ static int mp4_read_od(AVFormatContext *s, const uint8_t *buf, unsigned size, static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) { MpegTSContext *ts = filter->u.section_filter.opaque; + MpegTSSectionFilter *tssf = &filter->u.section_filter; SectionHeader h; const uint8_t *p, *p_end; AVIOContext pb; @@ -1200,6 +1204,9 @@ static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, int section_le return; if (h.tid != M4OD_TID) return; + if (h.version == tssf->last_ver) + return; + tssf->last_ver = h.version; mp4_read_od(s, p, (unsigned)(p_end - p), mp4_descr, &mp4_descr_count, MAX_MP4_DESCR_COUNT); @@ -1374,6 +1381,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) { MpegTSContext *ts = filter->u.section_filter.opaque; + MpegTSSectionFilter *tssf = &filter->u.section_filter; SectionHeader h1, *h = &h1; PESContext *pes; AVStream *st; @@ -1393,6 +1401,9 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len p = section; if (parse_section_header(h, &p, p_end) < 0) return; + if (h->version == tssf->last_ver) + return; + tssf->last_ver = h->version; av_dlog(ts->stream, "sid=0x%x sec_num=%d/%d\n", h->id, h->sec_num, h->last_sec_num); @@ -1519,6 +1530,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) { MpegTSContext *ts = filter->u.section_filter.opaque; + MpegTSSectionFilter *tssf = &filter->u.section_filter; SectionHeader h1, *h = &h1; const uint8_t *p, *p_end; int sid, pmt_pid; @@ -1532,6 +1544,9 @@ static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len return; if (h->tid != PAT_TID) return; + if (h->version == tssf->last_ver) + return; + tssf->last_ver = h->version; clear_programs(ts); for(;;) { @@ -1562,6 +1577,7 @@ static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len static void sdt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) { MpegTSContext *ts = filter->u.section_filter.opaque; + MpegTSSectionFilter *tssf = &filter->u.section_filter; SectionHeader h1, *h = &h1; const uint8_t *p, *p_end, *desc_list_end, *desc_end; int onid, val, sid, desc_list_len, desc_tag, desc_len, service_type; @@ -1576,6 +1592,10 @@ static void sdt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len return; if (h->tid != SDT_TID) return; + if (h->version == tssf->last_ver) + return; + tssf->last_ver = h->version; + onid = get16(&p, p_end); if (onid < 0) return; |