On Tue, 24 Nov 2020, Deep Thought wrote:
I have opened a ticket explaining a problem with the code for
merge_pmt_versions.
Attached is also a patch which fixes this problem. The main idea is the
following:
for the INITIAL pmt, the old code finds matching streams by
1) checking the stream_identifier. If the current stream has one,
and if an earlier processed stream has the same one, it is assumed
that the two streams should be merged (I am not sure what this really
means, but the result is playback problems).
This behavior is wrong for streams having multiple audio streams with the
same stream_identifier
2) for streams without a stream identifier, it will look for a stream which
has the same position in the pmt as the current stream and will obviously
not find one. This is correct
So the patch solves the problem in 1) as follows:
1) if a stream has a stream identifier, it first computes a new variable
pmt_stream_index which will equal for the first stream with that
identifier, 1 for the second one with that identifier and so on
2) if a stream has no stream_identifier, pmt_stream_index will equal 0 for
the first such stream, 1 for the second such stream ... This is the same
as 1) but with stream_identifier==-1
find_matching_stream then compares streams based on a DUAL criterion:
pmt_stream_index must match, and stream_type must match.
The result is that for the INITIAL pmt all audi streams will be considered
different. If later the PMT changes, streams will be matched based on
stream identifier as the primary criterion and based on pmt_stream_index as
the secondary criterion.
It looks complicated and your patch was using tabs instead of spaces. I
have attached a patch (untested) which should resolve this in a more
starightforward way. Can you please test and comment?
Thanks,
Marton
From 189a44108fb3f7e9ee4e0991614cf1b7b9acf36a Mon Sep 17 00:00:00 2001
From: Marton Balint <c...@passwd.hu>
Date: Tue, 24 Nov 2020 22:58:18 +0100
Subject: [PATCH] avformat/mpegts: use stream index based lookup with
merge_pmt_versions if stream identifier matches multiple streams
Fixes streams having the same identifier mixed up on pmt version change.
Signed-off-by: Marton Balint <c...@passwd.hu>
---
libavformat/mpegts.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index a2003c6632..375d7996ac 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -2206,6 +2206,7 @@ static AVStream *find_matching_stream(MpegTSContext *ts, int pid, unsigned int p
AVFormatContext *s = ts->stream;
int i;
AVStream *found = NULL;
+ AVStream *idxfound = NULL;
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
@@ -2213,15 +2214,23 @@ static AVStream *find_matching_stream(MpegTSContext *ts, int pid, unsigned int p
continue;
if (stream_identifier != -1) { /* match based on "stream identifier descriptor" if present */
if (st->stream_identifier == stream_identifier+1) {
- found = st;
- break;
+ if (found) { /* fallback to idx based guess if multiple streams have the same identifier */
+ stream_identifier = -1;
+ found = NULL;
+ } else {
+ found = st;
+ }
}
- } else if (st->pmt_stream_idx == pmt_stream_idx) { /* match based on position within the PMT */
- found = st;
- break;
+ }
+ if (st->pmt_stream_idx == pmt_stream_idx) { /* match based on position within the PMT */
+ if (!idxfound)
+ idxfound = st;
}
}
+ if (!found)
+ found = idxfound;
+
if (found) {
av_log(ts->stream, AV_LOG_VERBOSE,
"re-using existing %s stream %d (pid=0x%x) for new pid=0x%x\n",
--
2.26.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".