Commit Graph

24156 Commits

Author SHA1 Message Date
Gijs Peskens
5274f2f7f8 avformat/librist: replace deprecated functions
This gets rid of of rist_receiver_data_read, rist_receiver_data_block_free and rist_parse_address
these functions have been deprecated since librist release v0.2.1 and are replaced with functions
suffixed with 2.
I added a version macro check at the top of the file to ensure ffmpeg can still be compiled against
older versions.

Signed-off-by: Gijs Peskens <gijs@peskens.net>
Signed-off-by: Marton Balint <cus@passwd.hu>
2021-10-10 17:25:23 +02:00
Marton Balint
9420f7e095 avformat/mpegts: fix max_packet_size in mpegts payload parsing
The maximum allowed useful PES payload data was set to PES_packet_length, but
it is in fact smaller by the length of the PES header.

This changes how corrupt streams are packetized:
- If PES header length is bigger than PES_packet_length then the PES packet
  payload will be handled as an unbound packet
- PES packets with payload across multiple MPEGTS packets will always be
  splitted if with the next chunk of data the payload should exceed
  PES_packet_length, previously a PES_header_length amount of excess was
  allowed.

Fixes ticket #9355.

Signed-off-by: Marton Balint <cus@passwd.hu>
2021-10-10 16:54:15 +02:00
Marton Balint
aeea2ad0e4 avformat/mpegts: rename PES total_size to PES_packet_length
This renames PESContext->total_size to PESContext->PES_packet_length and keeps
it 0 for unbound packets, so its name and semantics will match the standard.

There should be no change in functionality.

Signed-off-by: Marton Balint <cus@passwd.hu>
2021-10-10 16:54:15 +02:00
Marton Balint
65cd43cff3 avformat/mpegts: delay allocation of PES buffer
This allows us to allocate the buffer in a single code path.

Signed-off-by: Marton Balint <cus@passwd.hu>
2021-10-10 16:54:15 +02:00
Marton Balint
ce8db0c253 avformat/mpegts: use named constants for stream_id types
Signed-off-by: Marton Balint <cus@passwd.hu>
2021-10-10 16:54:15 +02:00
Limin Wang
b4d665bf69 avformat/libsrt: specify base of maxbw string to 10 instead of auto-detect
Make all options string conversion consistent.

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2021-10-10 11:00:59 +08:00
Limin Wang
1161d8b4b3 avformat/libsrt: use strtoll/strtol for int64_t/int
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2021-10-10 11:00:59 +08:00
Michael Niedermayer
d115eec979 avformat/matroskadec: Reset state also on failure in matroska_reset_status()
The calling code does not handle failures and will fail with assertion failures later.
Seeking can always fail even when the position was previously read.

Fixes: Assertion failure
Fixes: 35253/clusterfuzz-testcase-minimized-ffmpeg_dem_MATROSKA_fuzzer-4693059982983168

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-10-09 17:01:49 +02:00
Andreas Rheinhardt
5a261cfa32 avformat/allformats: Fix data race when accessing devices lists
Up until now setting the input and output devices lists is guarded
by a mutex. This prevents data races emanating from multiple concurrent
calls to avpriv_register_devices() (triggered by multiple concurrent
calls to avdevice_register_all()). Yet reading the lists pointers was
done without any lock and with nonatomic variables. This means that
there are data races in case of concurrent calls to
av_(de)muxer_iterate() and avdevice_register_all() (but only if the
iteration in av_(de)muxer_iterate exhausts the non-device (de)muxers).

This commit fixes this by putting said pointers into atomic objects.
Due to the unavailability of _Atomic the object is an atomic_uintptr,
leading to ugly casts. Switching to atomics also allowed to remove
the mutex currently used in avpriv_register_devices().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-09 13:20:39 +02:00
Michael Niedermayer
849138f476 avformat/wavdec: Check smv_block_size
Fixes: Timeout
Fixes: 39554/clusterfuzz-testcase-minimized-ffmpeg_dem_WAV_fuzzer-4915221701984256

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-10-09 11:42:16 +02:00
Michael Niedermayer
8fe3566b8f avformat/rmdec: Check for multiple audio_stream_info
Fixes: memleak
Fixes: 39166/clusterfuzz-testcase-minimized-ffmpeg_dem_IVR_fuzzer-5153276690038784

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-10-09 11:42:16 +02:00
Peter Ross
4ff8840697 avformat/img2dec: add GEM Raster image demuxer
Signed-off-by: Peter Ross <pross@xvid.org>
2021-10-08 20:37:36 +11:00
Michael Niedermayer
255a7b423e oavformat/avidec: Check offset in odml
Fixes: signed integer overflow: 9223372036854775807 + 8 cannot be represented in type 'long'
Fixes: 38787/clusterfuzz-testcase-minimized-ffmpeg_dem_AVI_fuzzer-4859845799444480

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-10-07 23:38:57 +02:00
Michael Niedermayer
83b2e4c8f1 avformat/mpegts: use actually read packet size in mpegts_resync special case
Fixes: infinite loop
Fixes: 37986/clusterfuzz-testcase-minimized-ffmpeg_dem_MPEGTSRAW_fuzzer-5292311517462528 -

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-10-07 23:38:57 +02:00
Andreas Rheinhardt
fadefe356a avformat/flacdec: Also set channels when setting channel_layout
This brings the FLAC demuxer in line with all the other demuxers.
Furthermore, if it is not done and the FLAC decoder is disabled,
the FLAC parser will overwrite the channel layout with the standard
channel layout for that number of channels.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-07 22:06:27 +02:00
Andreas Rheinhardt
baf89ab9a7 avformat/format: Improve const-correctness
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-07 14:06:58 +02:00
Andreas Rheinhardt
14baf4cd92 avformat/lrcenc: Unify writing timestamps
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-07 11:55:55 +02:00
Andreas Rheinhardt
e110076d8c avformat/lrcenc: Avoid allocations for writing packet data
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-07 11:54:28 +02:00
Andreas Rheinhardt
07bf8f8332 avformat/sccdec: Remove nonsense cast
In most contexts, arrays are automatically converted to a pointer
to their first element; taking the address of the array just yields
a pointer to an array of fixed-size arrays, which is not intended here.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-07 11:52:10 +02:00
Jan Ekström
7a446b1179 avformat/{isom,mov,movenc}: add support for CMAF DASH roles
This information is coded in a standard MP4 KindBox and utilizes the
scheme and values as per the DASH role scheme defined in MPEG-DASH.
Other schemes are technically allowed, but where multiple schemes
define the same concepts, the DASH scheme should be utilized.

Such flagging is additionally utilized by the DASH-IF CMAF ingest
specification, enabling an encoder to inform the following component
of the roles of the incoming media streams.

A test is added for this functionality in a similar manner to the
matroska test.

Signed-off-by: Jan Ekström <jan.ekstrom@24i.com>
2021-10-04 17:55:27 +03:00
Jan Ekström
847fd8de7c avformat/{aviobuf,avio_internal}: add max_len argument to ff_read_string_to_bprint_overwrite
This is especially useful when reading things such as null-terminated
strings from MOV/MP4-likes, where the size of the box is known, but
not the exact size of the string.

Signed-off-by: Jan Ekström <jan.ekstrom@24i.com>
2021-10-04 17:13:21 +03:00
Jan Ekström
151f46e84d avformat/{aviobuf,avio_internal}: add ff_read_string_to_bprint_overwrite
For now, same as ff_read_line_to_bprint_overwrite, but reads until
the end of a null-terminated string.

Signed-off-by: Jan Ekström <jan.ekstrom@24i.com>
2021-10-04 17:13:21 +03:00
Jan Ekström
94f227bac1 avformat/aviobuf: add a full string reading mode to read_line_to_bprint
Additionally:
* rename it to read_string_to_bprint
* split most of ff_read_line_to_bprint_overwrite into an internal
  function which can then be utilized to implement other
  functionality without duplicating code.

Signed-off-by: Jan Ekström <jan.ekstrom@24i.com>
2021-10-04 17:13:21 +03:00
Andreas Rheinhardt
5de6c90187 avformat/mux: Remove unnecessary av_packet_unref()
AVFormatInternal.parse_pkt is always blank after having been used.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:56:12 +02:00
Andreas Rheinhardt
c012fc34df avformat/tee: Reindentation
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:56:12 +02:00
Andreas Rheinhardt
b3612b5f52 avformat/tee: Process strings immediately if possible
This avoids having to free them manually lateron.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:56:12 +02:00
Andreas Rheinhardt
3a27fcb168 avformat/tee: Fix leak of FIFO-options dictionary
Happened for all slaves which didn't use the FIFO.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:56:12 +02:00
Andreas Rheinhardt
4df34df642 avformat/tee: Fix leak of strings
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:56:12 +02:00
Andreas Rheinhardt
e54bad3fce avformat/tee: Avoid stack packet
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:56:12 +02:00
Andreas Rheinhardt
b0e4865187 avformat/tee: Unref packet on av_bsf_send_packet() failure
Given that the packet sent to av_bsf_send_packet() is always
already refcounted, it is doubtful whether the error can even
be triggered currently.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:56:12 +02:00
Andreas Rheinhardt
2b5d296533 avformat/tee: Fix inconsistency wrt av_packet_ref() failure handling
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:56:12 +02:00
Andreas Rheinhardt
029df555f8 avformat/webpenc: Don't use sizeof(AVPacket)
In this case it means replacing a packet in the muxer's context by
a pointer to an AVPacket, namely AVFormatInternal.pkt.
Because this packet is freed generically, one can remove the muxer's
deinit function.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:56:12 +02:00
Andreas Rheinhardt
f42a2b1349 avformat/flacenc: Avoid stack packet
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:56:12 +02:00
Andreas Rheinhardt
12a88f806f avformat/img2enc: Don't use sizeof(AVPacket)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:56:12 +02:00
Andreas Rheinhardt
0bf63099cd avformat/mp3enc: Avoid stack packet
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:56:12 +02:00
Andreas Rheinhardt
751e334aa9 avformat/ttaenc: Avoid stack packet
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:56:12 +02:00
Andreas Rheinhardt
9b41fddf3e avformat/matroskaenc: Avoid allocation of AVPacket
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:56:12 +02:00
Andreas Rheinhardt
f660b8d1de avformat/avienc: Avoid allocating AVPacket
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:56:12 +02:00
Andreas Rheinhardt
4e6e14f496 avformat/amvenc: Avoid allocating packet
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:56:12 +02:00
Andreas Rheinhardt
c2bb054979 avformat/internal: Allow AVFormatInternal.pkt to be used by muxers
It is unused by the generic muxing code.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:56:05 +02:00
Andreas Rheinhardt
eadb1cd6f8 avformat/asfenc: Return proper error codes
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:50:50 +02:00
Andreas Rheinhardt
87a4138d4b avformat/asfenc: Add deinit function
Fixes leaks when the trailer is never written.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:50:50 +02:00
Andreas Rheinhardt
ea7a81bc1d avformat/asfenc: Avoid allocations when writing metadata
Also improves the error check for avio_open_dyn_buf().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:50:50 +02:00
Andreas Rheinhardt
c128bffa05 avformat/asfenc: Remove unused fields from ASFStream
It has never been done in b08569a239,
30b8f3e7dc.

After this change, this muxer does no longer use sizeof(AVPacket).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:50:50 +02:00
Andreas Rheinhardt
2ce6a9f847 avformat/mux: Use AVFormatInternal.parse_pkt for temporary packets
The documentation of said packet ("Every user has to ensure that
this packet is blank after using it") perfectly fits how we use said
packet in the generic muxing code. Better than the documentation of pkt.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:50:50 +02:00
Andreas Rheinhardt
4fa8daab79 avformat/mux: Don't use stack packet when writing interleaved packets
Currently the interleave_packet functions use a packet for
a new packet to be interleaved (may be NULL if there is none) and
a packet for output; said packet is always a stack packet in
interleaved_write_packet(). But all the interleave_packet functions
in use first move the packet to the packet list and then check whether
a packet can be returned, i.e. the effective lifetime of the new packet
ends before the packet for output is touched.

So one can use one packet both for input and output by adding a new
parameter that indicates whether there is a packet to add to the packet
list; there is just one complication: In case the muxer is flushed,
there is no packet available. This can be solved by reusing one of
the packets from AVFormatInternal. They are currently unused when
flushing in av_interleaved_write_frame().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:50:50 +02:00
Andreas Rheinhardt
259026b457 avformat/avformat: Clarify documentation of av_interleaved_write_frame()
The earlier documentation claimed that av_interleaved_write_frame()
always orders by dts, which is not necessarily true when using muxers
with custom interleavement functions or the audio_preload option.

Furthermore, the documentation stated that libavformat takes ownership
of the reference of the provided packet (if it is refcounted) and that
the caller may not access the data through this reference after the
function returns. This suggests that the returned packet is not blank,
but instead still contains some set, but invalid fields, which implies
that it would be dangerous to unreference this packet again.

But this is not true: av_interleaved_write_frame()'s actual behaviour
is to always output blank packet (even on error). This commit documents
this fact so that callers know that they can directly reuse this packet.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:50:49 +02:00
Andreas Rheinhardt
805ec95f8e avformat/mux: Sanitize packets without data and side-data
The BSF API treats such packets as signalling EOF and therefore
such a packet might corrupt the BSF state. In such a case,
the guarantee that av_interleaved_write_frame() always frees
the packet is not upheld.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:50:49 +02:00
Paul B Mahol
f282c34c00 avcodec/amr*dec: add multichannel support 2021-10-03 11:42:15 +02:00
Paul B Mahol
1f447fd954 avcodec: add amr parser 2021-10-02 18:49:40 +02:00