Commit c6c172d1 authored by Michael Niedermayer's avatar Michael Niedermayer

avformat/mpegts: skip updating programs/streams when determining duration

Fixes Ticket2441
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent c9d64abe
...@@ -137,6 +137,8 @@ struct MpegTSContext { ...@@ -137,6 +137,8 @@ struct MpegTSContext {
/** to detect seek */ /** to detect seek */
int64_t last_pos; int64_t last_pos;
int skip_changes;
/******************************************/ /******************************************/
/* private mpegts data */ /* private mpegts data */
/* scan context */ /* scan context */
...@@ -173,6 +175,8 @@ static const AVOption mpegts_options[] = { ...@@ -173,6 +175,8 @@ static const AVOption mpegts_options[] = {
{.i64 = 1}, 0, 1, AV_OPT_FLAG_DECODING_PARAM }, {.i64 = 1}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
{"ts_packetsize", "Output option carrying the raw packet size.", offsetof(MpegTSContext, raw_packet_size), AV_OPT_TYPE_INT, {"ts_packetsize", "Output option carrying the raw packet size.", offsetof(MpegTSContext, raw_packet_size), AV_OPT_TYPE_INT,
{.i64 = 0}, 0, 0, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY }, {.i64 = 0}, 0, 0, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
{"skip_changes", "Skip changing / adding streams / programs.", offsetof(MpegTSContext, skip_changes), AV_OPT_TYPE_INT,
{.i64 = 0}, 0, 1, 0 },
{ NULL }, { NULL },
}; };
...@@ -237,6 +241,7 @@ static void clear_avprogram(MpegTSContext *ts, unsigned int programid) ...@@ -237,6 +241,7 @@ static void clear_avprogram(MpegTSContext *ts, unsigned int programid)
{ {
AVProgram *prg = NULL; AVProgram *prg = NULL;
int i; int i;
for (i = 0; i < ts->stream->nb_programs; i++) for (i = 0; i < ts->stream->nb_programs; i++)
if (ts->stream->programs[i]->id == programid) { if (ts->stream->programs[i]->id == programid) {
prg = ts->stream->programs[i]; prg = ts->stream->programs[i];
...@@ -952,6 +957,9 @@ static int mpegts_push_data(MpegTSFilter *filter, ...@@ -952,6 +957,9 @@ static int mpegts_push_data(MpegTSFilter *filter,
/* stream not present in PMT */ /* stream not present in PMT */
if (!pes->st) { if (!pes->st) {
if (ts->skip_changes)
goto skip;
pes->st = avformat_new_stream(ts->stream, NULL); pes->st = avformat_new_stream(ts->stream, NULL);
if (!pes->st) if (!pes->st)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
...@@ -1721,6 +1729,8 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len ...@@ -1721,6 +1729,8 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
if (h->tid != PMT_TID) if (h->tid != PMT_TID)
return; return;
if (ts->skip_changes)
return;
clear_program(ts, h->id); clear_program(ts, h->id);
pcr_pid = get16(&p, p_end); pcr_pid = get16(&p, p_end);
...@@ -1874,6 +1884,8 @@ static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len ...@@ -1874,6 +1884,8 @@ static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
return; return;
if (h->tid != PAT_TID) if (h->tid != PAT_TID)
return; return;
if (ts->skip_changes)
return;
ts->stream->ts_id = h->id; ts->stream->ts_id = h->id;
...@@ -1942,6 +1954,8 @@ static void sdt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len ...@@ -1942,6 +1954,8 @@ static void sdt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
return; return;
if (h->tid != SDT_TID) if (h->tid != SDT_TID)
return; return;
if (ts->skip_changes)
return;
onid = get16(&p, p_end); onid = get16(&p, p_end);
if (onid < 0) if (onid < 0)
return; return;
......
...@@ -2500,6 +2500,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) ...@@ -2500,6 +2500,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
} }
} }
av_opt_set(ic, "skip_changes", "1", AV_OPT_SEARCH_CHILDREN);
/* estimate the end time (duration) */ /* estimate the end time (duration) */
/* XXX: may need to support wrapping */ /* XXX: may need to support wrapping */
filesize = ic->pb ? avio_size(ic->pb) : 0; filesize = ic->pb ? avio_size(ic->pb) : 0;
...@@ -2567,6 +2568,8 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) ...@@ -2567,6 +2568,8 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
offset && offset &&
++retry <= DURATION_MAX_RETRY); ++retry <= DURATION_MAX_RETRY);
av_opt_set(ic, "skip_changes", "0", AV_OPT_SEARCH_CHILDREN);
/* warn about audio/video streams which duration could not be estimated */ /* warn about audio/video streams which duration could not be estimated */
for (i = 0; i < ic->nb_streams; i++) { for (i = 0; i < ic->nb_streams; i++) {
st = ic->streams[i]; st = ic->streams[i];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment