Commit Graph

97661 Commits

Author SHA1 Message Date
Limin Wang
8b07751123 avcodec/libx264: return error if unknown picture type encountered
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-08 06:42:25 +08:00
Limin Wang
f5e33514e7 avcodec/libx264: return immediately if encode_nals return 0
x264_encoder_encode can return 0 with nnal 0. As a result, encode_nals will
return 0. In this condition, it's better to return 0 immediately to avoid
the following unneeded pict_type and flags setting.

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-08 06:42:25 +08:00
Limin Wang
d8e98d9348 avcodec/libx265: Fix Uninitialized scalar variable
return error if unknown picture type encountered

Fixes CID 1457234
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-08 06:42:25 +08:00
Marton Balint
8360fd2610 avformat: implement retiming directly in mxfenc and gxfenc
Generic retime functionality is replaced by a few lines of code directly in the
muxers which used it, which seems a lot easier to understand and this way the
retiming is not dependant of the input durations.

Also remove retimeinterleave, since it is not used by anything anymore.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-05-07 23:12:24 +02:00
Marton Balint
c5324d92c5 avformat/audiointerleave: only keep the retime functionality of the audio interleaver
And rename it to retimeinterleave, use the pcm_rechunk bitstream filter for
rechunking.

By seperating the two functions we hopefully get cleaner code.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-05-07 23:12:24 +02:00
Marton Balint
2035620b7c avcodec/pcm_rechunk_bsf: add bitstream filter to rechunk pcm audio
Signed-off-by: Marton Balint <cus@passwd.hu>
2020-05-07 23:12:24 +02:00
Marton Balint
d7a0071a44 avformat/mux: add proper support for full N:M bitstream filtering
Previously only 1:1 bitstream filters were supported, the end of the stream was
not signalled to the bitstream filters and time base changes were ignored.

This change also allows muxers to set up bitstream filters regardless of the
autobsf flag during write_header instead of during check_bitstream and those
bitstream filters will always be executed.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-05-07 22:49:50 +02:00
Marton Balint
6406351222 avformat/mux: factorize writing a packet
In preparation for N:M bsf support.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-05-07 22:48:06 +02:00
Marton Balint
c31ba86c37 avformat/mux: factorize interleaved write_packet
Signed-off-by: Marton Balint <cus@passwd.hu>
2020-05-07 22:41:24 +02:00
Marton Balint
7a8a5c200b avformat/mux: move interleaved packet functions upwards
Will be needed later to avoid a forward declaration.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-05-07 22:41:24 +02:00
Andreas Rheinhardt
1ec0fb56a7 avformat/hlsenc: Remove redundant setting of output format
avformat_alloc_output_context2() already sets the oformat member, so
that there is no reason to overwrite it again with the value it already
has.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-07 16:06:51 +02:00
Limin Wang
a8d7393804 avcodec/profiles: remove duplicate FF_PROFILE_RESERVED entry
Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-07 21:10:34 +08:00
Steven Liu
3523df947a avformat/dashdec: compute the segment size use current pos minus offset plus one
because the offset should use one byte

Reviewed-by: Zhao Jun <barryjzhao@tencent.com>
Reported-by: Zhao Jun <barryjzhao@tencent.com>
Signed-off-by: Steven Liu <liuqi05@kuaishou.com>
2020-05-07 19:33:35 +08:00
Limin Wang
96e5e6abb9 avformat/mux: Set AV_PKT_FLAG_KEY for is_intra_only packet
The patch will make audio and subtitle packets be marked as AV_PKT_FLAG_KEY.

For audio, it'll caused the audio sample to be sync sample.
To verify ref/fate/movenc results:
1. Get the movenc test data
[lmwang@vpn ffmpeg]$ libavformat/tests/movenc -w && mkdir -p audio_old && mv *.mp4 audio_old_

After applied the patch:
[lmwang@vpn ffmpeg]$ make fate-movenc SAMPLES=../fate-suite
[lmwang@vpn ffmpeg]$ libavformat/tests/movenc -w && mkdir -p audio_key && mv *.mp4 audio_key

2. Get l-smash and build boxdumper
https://github.com/l-smash/l-smash.git

3. dump the box of crc change mp4 and diff -u
[lmwang@vpn ffmpeg]$ ../l-smash/cli/boxdumper --box audio_key/non-empty-moov-no-elst.mp4  > audio_key/non-empty-moov-no-elst.log
[lmwang@vpn ffmpeg]$ ../l-smash/cli/boxdumper --box audio_old/non-empty-moov-no-elst.mp4  > audio_old/non-empty-moov-no-elst.log
[lmwang@vpn ffmpeg]$ diff -u audio_key/non-empty-moov-no-elst.log audio_old/non-empty-moov-no-elst.log
-                default_sample_flags = 0x02000000
-                    independent
-                    sync sample
+                default_sample_flags = 0x01010000
+                    dependent
+                    non-sync sample

4. have checked the change of crc are caused by default_sample_flags
non-empty-moov.mp4, non-empty-moov-elst.mp4,
non-empty-moov-no-elst.mp4, empty-moov.mp4, delay-moov-content.mp4,
empty-moov-second-frag.mp4, empty-moov-second-frag-discont.mp4,
delay-moov-second-frag-discont.mp4, delay-moov-elst-second-frag.mp4
etc

5 For subtitle, it'll effect for tests/ref/fate/binsub-movtextenc and
tests/ref/fate/sub2video, that's expecting result for the subtitle is
marked as keyframe. Below is the checking result of binsub-movtextenc:

[lmwang@vpn ffmpeg]$ ./ffmpeg -i ../fate-suite/sub/MovText_capability_tester.mp4 -map 0 -scodec mov_text -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov audio_key/binsub-movtextenc.mp4
[lmwang@vpn ffmpeg]$ ./ffmpeg -i ../fate-suite/sub/MovText_capability_tester.mp4 -map 0 -scodec mov_text -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov audio_old/binsub-movtextenc.mp4
[lmwang@vpn ffmpeg]$../l-smash/cli/boxdumper audio_key/binsub-movtextenc.mp4  > audio_key/binsub-movtextenc.log
[lmwang@vpn ffmpeg]$../l-smash/cli/boxdumper audio_old/binsub-movtextenc.mp4  > audio_old/binsub-movtextenc.log
[lmwang@vpn ffmpeg]$ diff -u audio_key/binsub-movtextenc.log audio_old/binsub-movtextenc.log
.... // the key difference is the flag for sync sample
-                flags = 0x000701
+                flags = 0x000301
                     data-offset-present
                     sample-duration-present
                     sample-size-present
-                    sample-flags-present
                 sample_count = 6
-                data_offset = 188
+                data_offset = 164
                 sample[0]
                     sample_duration = 1570000
                     sample_size = 21
-                    sample_flags = 0x02000000
-                        independent
-                        sync sample
-                        degradation_priority = 0
                 sample[1]
                     sample_duration = 510000
                     sample_size = 2
-                    sample_flags = 0x01010000
-                        dependent
-                        non-sync sample
-                        degradation_priority = 0
                 sample[2]
                     sample_duration = 1690000
                     sample_size = 9
-                    sample_flags = 0x02000000
-                        independent
-                        sync sample
-                        degradation_priority = 0

Suggested-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Suggested-by: Nicolas George <george@nsup.org>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-07 07:12:24 +08:00
Linjie Fu
74aa332157 MAINTAINERS: Add myself to libopenh264enc
Reviewed-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Linjie Fu <linjie.fu@intel.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-05-06 19:12:00 +02:00
Limin Wang
ba0d785fa5 avformat/utils: move is_intra_only() to header and rename to ff_is_intra_only()
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-06 23:02:00 +08:00
Limin Wang
fa21df2bd4 avformat/rtmpproto: use av_reallocp_array()
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-06 23:02:00 +08:00
Limin Wang
1a94456390 avformat/smoothstreamingenc: use av_reallocp_array()
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-06 23:02:00 +08:00
Limin Wang
683e421bcf fftools/ffmpeg: use local variable with same contents directly
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-06 23:02:00 +08:00
Andreas Rheinhardt
3a822717bd avformat/matroskaenc: Check allocations implicit in dynamic buffers
Failures of the allocations that happen under the hood when using dynamic
buffers are usually completely unchecked and the Matroska muxer is no
exception to this.

The API has its part in this, because there is no documented way to
actually check for errors: The return value of both avio_get_dyn_buf()
as well as avio_close_dyn_buf() is only documented as "the length of
the byte buffer", so that using this to return errors would be an API
break.

Therefore this commit uses the only reliable way to check for errors
with avio_get_dyn_buf(): The AVIOContext's error flag. (This is one of
the advantages of avio_get_dyn_buf(): By not destroying the AVIOContext
it is possible to inspect this value.) Checking whether the size or the
pointer vanishes is not enough as it does not check for truncated output
(the dynamic buffer API is int based and so has to truncate the buffer
even when enough memory would be available; it's current actual limit is
even way below INT_MAX).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-06 10:49:51 +02:00
Andreas Rheinhardt
8370c9c206 avformat/matroskaenc: Simplify writing buffer
If one already has the contents of a master elements in a buffer of
known size, then writing a EBML master element is no different from
writing an EBML binary element. It is overtly complicated to use
start/end_ebml_master() as these functions first write an unkown-length
size field of the appropriate length, then write the buffer's contents,
followed by a seek to the length field to overwrite it with the real
size (obtained via avio_tell() although it was already known in
advance), followed by another seek to the previous position. Just use
put_ebml_binary() instead.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-06 10:38:53 +02:00
Andreas Rheinhardt
3122dcf2fe avformat/matroskaenc: Avoid dynamic buffer when writing Colour
There is a good upper bound for the maximum length of the Colour master
element; it is therefore unnecessary to use a dynamic buffer for it.
A simple buffer on the stack is enough. This commit implements this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-06 10:22:48 +02:00
Andreas Rheinhardt
851283a777 avformat/matroskaenc: Unify writing level 1 elements preliminarily
The Matroska muxer updates several header elements when the output is
seekable; if unseekable, the buffer containing the contents of the element
is immediately freed after writing. Before this commit, there were three
places doing exactly the same: Checking whether the output is seekable
and calling the function that writes and frees or the function that
just writes the EBML master. This has been unified; adding SeekHead
entries for these elements has been unified, too.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-06 09:45:17 +02:00
Andreas Rheinhardt
4ed3c925c3 avformat/matroskaenc: Move adding SeekEntry into end_ebml_master_crc32()
Up until now, SeekEntries were already added before
start_ebml_master_crc32() was even called and before we were actually
sure that we really write the element the SeekHead references: After
all, we might also error out later; and given that the allocations
implicit in dynamic buffers should be checked, end_ebml_master_crc32()
will eventually have to return errors itself, so that it is the right
place to add SeekHead entries.

The earlier behaviour is of course a remnant of the time in which
start_ebml_master_crc32() really did output something, so that the
position before start_ebml_master_crc32() needed to be recorded.
Erroring out later is also not as dangerous as it seems because in
this case no SeekHead will be written (if it happened when writing
the header, the whole muxing process would abort; if it happened
when writing the trailer (when writing chapters not available initially),
writing the trailer would be aborted and no SeekHead containing the
bogus chapter entry would be written).

This commit does not change the way the SeekEntries are added for those
elements that are output preliminarily; this is so because the SeekHead
is written before those elements are finally output and doing it
otherwise would increase the amount of seeks.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-06 09:27:40 +02:00
Andreas Rheinhardt
c801ab43c3 avformat/hlsenc: Improve checks for invalid stream mappings
The mapping of streams to the various variant streams to be created by
the HLS muxer is roughly as follows: Space and tab separate variant
stream group maps while the entries in each variant stream group map are
separated by ','.

The parsing process of each variant stream group proceeded as follows:
At first the number of occurences of "a:", "v:" and "s:" in each variant
stream group is calculated so that one can can allocate an array of
streams with this number of entries. Then each entry is checked and the
check for stream numbers was deficient: It did check that there is a
number beginning after the ":", but it did not check that the number
extends until the next "," (or until the end).

This means that an invalid variant stream group like v:0_v:1 will not be
rejected; the problem is that the variant stream in this example is
supposed to have two streams associated with it (because it contains two
"v:"), yet only one stream is actually associated with it (because there
is no ',' to start a second stream specifier). This discrepancy led to
segfaults (null pointer dereferencing) in the rest of the code (when the
nonexistent second stream associated to the variant stream was inspected).

Furthermore, this commit also removes an instance of using atoi() whose
behaviour on a range error is undefined.

Fixes ticket #8652.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-06 08:47:35 +02:00
rcombs
2912118898 lavf/dashdec: support larger manifests 2020-05-06 00:11:37 -05:00
Steven Liu
648051f07c avformat/url: check url root node when rel include double dot and trim double dot
fix ticket: 8625
and add testcase into url for double dot corner case

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2020-05-06 12:00:26 +08:00
Steven Liu
666dbe7aac avformat/hlsenc: resend full url of the init fragment mp4
fix ticket: 8651
because the init fragment mp4 file name is without base url name,
so just modify it use the full url which splice after init function.

Tested-by: matclayton
Signed-off-by: Steven Liu <liuqi05@kuaishou.com>
2020-05-06 11:56:58 +08:00
Yaroslav Pogrebnyak
7f0200d0d2 libavformat/hlsenc: Allow usage of 'periodic-rekey' with multi-variant streams
This patch adds possibility to use 'periodic-rekey' option with
multi-variant streams to hlsenc muxer. All streams variants
use parameters from the same key_info_file.

There are 2 sets of encryption options that kind of overlaps and add
complexity, so I tried to do the thing without changing too much code.

There is a little duplication of the key_file, key_uri, iv_string, etc
in the VariantStream since we copy it from hls to each variant stream,
but generally all the code remains the same to minimise appearing
of unexpected bugs. Refactoring could be done as a separate patch then as needed.

Signed-off-by: Yaroslav Pogrebnyak <yyyaroslav@gmail.com>
2020-05-06 11:53:23 +08:00
Steven Liu
a7bab199e5 avformat/hlsenc: compute segment duration use current pts minus last segment end pts
segment duration is using vs duration which compute by frame per second,
that can not fix problem of VFR video stream, so compute the duration
when split the segment, set the segment target duration use
current packet pts minus the prev segment end pts..

Reported-by: Zhao Jun <barryjzhao@tencent.com>
Reviewed-by: Zhao Jun <barryjzhao@tencent.com>
Signed-off-by: Steven Liu <liuqi05@kuaishou.com>
2020-05-06 11:32:26 +08:00
Steven Liu
03b1b96832 tests/fate/hlsenc: rename fate macro define from FATE_AFILTER to FATE_HLSENC
and add fate-hlsenc for test all of the testcase
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2020-05-06 11:25:57 +08:00
Lynne
bdd57e2a37
lavc/bsf: add an Opus metadata bitstream filter
The only adjustable field is the gain. Some ripping/transcoding programs
have started to use it.
2020-05-05 22:25:33 +01:00
Michael Niedermayer
30f5d67510 avcodec/wavpack: Check rate_x and sample rate for overflow
Fixes: shift exponent 32 is too large for 32-bit type 'int'
Fixes: 21647/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WAVPACK_fuzzer-5686168323883008

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: David Bryant <david@wavpack.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-05-05 20:07:19 +02:00
Zane van Iperen
94f4fab69f avformat: add demuxer for Pro Pinball Series' Soundbanks
Adds support for the soundbank files used by the Pro Pinball series of games.

https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2020-May/262094.html

Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-05-05 20:07:19 +02:00
Mark Reid
b4967fc71c libswscale: add output support for AV_PIX_FMT_GBRAPF32
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-05-05 20:06:58 +02:00
Mark Reid
ba5d0515a6 libswscale: add input support AV_PIX_FMT_GBRAPF32
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-05-05 20:06:58 +02:00
Andreas Rheinhardt
f93bd30282 avformat/nutenc: Write size into right dynamic buffer
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-05 19:35:38 +02:00
Andreas Rheinhardt
781c7a6217 avformat/aviobuf, nutenc: Move ff_puv_v, ff_get_v_length to nutenc.c
and make it static again.

These functions have been moved from nutenc to aviobuf and internal.h
in f8280ff4c0 in order to use them in a
forthcoming patch in utils.c. Said patch never happened, so this commit
moves them back and makes them static, effectively reverting said
commit as well as f8280ff4c0 (which added
the ff-prefix to these functions).

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-05 19:28:28 +02:00
Andreas Rheinhardt
9b9a61ca77 avformat/nutenc: Add goto fail in nut_write_headers()
It allows to combine several ffio_free_dyn_buf().

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-05 19:17:13 +02:00
Andreas Rheinhardt
2ffa8be53b avformat/nutenc: Reuse dynamic buffers when possible
NUT uses variable-length integers in order to for length fields.
Therefore the NUT muxer often writes data into a dynamic buffer in order
to get the length of it, then writes the length field using the fewest
amount of bytes needed. To do this, a new dynamic buffer was opened,
used and freed for each element which involves lots of allocations. This
commit changes this: The dynamic buffers are now resetted and reused.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-05 19:06:18 +02:00
Andreas Rheinhardt
63a4cadd27 libavformat/nutenc: Remove redundant function parameter
calculate_checksum in put_packet() is always 1.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-05 18:47:52 +02:00
James Almer
f90a48b72e avcodec/avpacket: add missing entry for prft to av_packet_side_data_name()
Signed-off-by: James Almer <jamrial@gmail.com>
2020-05-05 11:54:58 -03:00
Linjie Fu
9473268cfb lavc/vp9: fix reference frame dimensions check for SINGLE_REFERENCE mode
With the description in frame size with refs semantics (SPEC 7.2.5),
it is a requirement of bitstream conformance that for at least one
reference frame has the valid dimensions.

Modify the check to make sure the decoder works well in SINGLE_REFERENCE
mode that not all reference frames have valid dimensions.

Check and error out if invalid reference frame is used in inter_recon.

One of the failure case is a 480x272 inter frame (SINGLE_REFERENCE mode)
with following reference pool:

0.  960x544    LAST    valid
1. 1920x1088 GOLDEN  invalid, but not used in single reference mode
2. 1920x1088 ALTREF  invalid, but not used in single reference mode
3~7  ...     Unused

Identical logic in libvpx:
<https://github.com/webmproject/libvpx/blob/master/vp9/decoder/vp9_decodeframe.c#L736>

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
2020-05-05 08:22:28 -04:00
Andriy Gelman
486ed509bc avcodec/v4l2_m2m_enc: Support changing qmin/qmax
Hard coded parameters for qmin and qmax are currently used to initialize
v4l2_m2m device. This commit uses values from avctx->{qmin,qmax} if they
are set.

Reviewed-by: Ming Qian <ming.qian@nxp.com>
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2020-05-05 00:49:42 -04:00
Limin Wang
79e3c4dd74 avcodec/utils: simplify, remove duplicate code
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-05 08:20:45 +08:00
Limin Wang
ab7bcfb80c avformat/mxfdec: reindent code
Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-05 08:20:45 +08:00
Limin Wang
e468106269 avcodec/v4l2_m2m_enc: reindent code
Reviewed-by: Andriy Gelman <andriy.gelman@gmail.com>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-05 08:20:45 +08:00
Limin Wang
6d720b1aef avcodec/prores_metadata_bsf: Use AVCOL_TRC_NB - 1 for the valid max range
Report by Marton after commit.

Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-05 08:20:45 +08:00
Linjie Fu
2b32068916 lavc/vaapi_encode: add FF_CODEC_CAP_INIT_CLEANUP caps for encoders
ff_vaapi_encode_close() is not enough to free the resources like cbs
if initialization failure happens after codec->configure (except for
vp8/vp9).

We need to call avctx->codec->close() to deallocate, otherwise memory
leak happens.

Add FF_CODEC_CAP_INIT_CLEANUP for vaapi encoders and deallocate the
resources at free_and_end inside avcodec_open2().

Reviewed-by: Timo Rothenpieler <timo@rothenpieler.org>
Signed-off-by: Linjie Fu <linjie.fu@intel.com>
2020-05-04 12:33:30 -03:00
Andreas Rheinhardt
5767a2ed74 avformat/matroskadec: Free right buffer on error
Since commit 979b5b8959, reverting the
Matroska ContentCompression is no longer done inside
matroska_parse_frame() (the function that creates AVPackets out of the
parsed data (unless we are dealing with certain codecs that need special
handling)), but instead in matroska_parse_block(). As a consequence,
the data that matroska_parse_frame() receives is no longer always owned
by an AVBuffer; it is owned by an AVBuffer iff no ContentCompression needed
to be reversed; otherwise the data is independently allocated and needs
to be freed on error.

Whether the data is owned by an AVBuffer or not is indicated by a variable
buf of type AVBufferRef *: If it is NULL, the data is independently
allocated, if not it is owned by the underlying AVBuffer (and is used to
avoid copying the data when creating the AVPackets).

Because the allocation of the buffer holding the uncompressed data happens
outside of matroska_parse_frame() (if a ContentCompression needs to be
reversed), the data is passed as uint8_t ** in order to not leave any
dangling pointers behind in matroska_parse_block() should the data need to
be freed: In case of errors, said uint8_t ** would be av_freep()'ed in
case buf indicated the data to be independently allocated.

Yet there is a problem with this: Some codecs (namely WavPack and
ProRes) need special handling: Their packets are only stored in
Matroska in a stripped form to save space and the demuxer reconstructs
full packets. This involved allocating a new, enlarged buffer. And if
an error happens when trying to wrap this new buffer into an AVBuffer,
this buffer needs to be freed; yet instead the given uint8_t ** (holding
the uncompressed, yet still stripped form of the data) would be freed
(av_freep()'ed) which certainly leads to a memleak of the new buffer;
even worse, in case the track does not use ContentCompression the given
uint8_t ** must not be freed as the actual data is owned by an AVBuffer
and the data given to matroska_parse_frame() is not the start of the
actual allocated buffer at all.

Both of these issues are fixed by always freeing the current data in
case it is independently allocated. Furthermore, while it would be
possible to track whether the pointer from matroska_parse_block() needs
to be reset or not, there is no gain in doing so, as the pointer is not
used at all afterwards and the sematics are clear: If the data passed
to matroska_parse_frame() is independently allocated, then ownership
of the data passes to matroska_parse_frame(). So don't pass the data
via uint8_t **.

Fixes Coverity ID 1462661 (the issue as described by Coverity is btw
a false positive: It thinks that this error can be triggered by ProRes
with a size of zero after reconstructing the original packets, but the
reconstructed packets can't have a size of zero).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-04 07:51:29 +02:00