1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00
Commit Graph

104021 Commits

Author SHA1 Message Date
Andreas Rheinhardt
e61393d006 avfilter/af_contrast: Use formats list instead of query function
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-05 18:01:01 +02:00
Andreas Rheinhardt
b4f5201967 avfilter: Replace query_formats callback with union of list and callback
If one looks at the many query_formats callbacks in existence,
one will immediately recognize that there is one type of default
callback for video and a slightly different default callback for
audio: It is "return ff_set_common_formats_from_list(ctx, pix_fmts);"
for video with a filter-specific pix_fmts list. For audio, it is
the same with a filter-specific sample_fmts list together with
ff_set_common_all_samplerates() and ff_set_common_all_channel_counts().

This commit allows to remove the boilerplate query_formats callbacks
by replacing said callback with a union consisting the old callback
and pointers for pixel and sample format arrays. For the not uncommon
case in which these lists only contain a single entry (besides the
sentinel) enum AVPixelFormat and enum AVSampleFormat fields are also
added to the union to store them directly in the AVFilter,
thereby avoiding a relocation.

The state of said union will be contained in a new, dedicated AVFilter
field (the nb_inputs and nb_outputs fields have been shrunk to uint8_t
in order to create a hole for this new field; this is no problem, as
the maximum of all the nb_inputs is four; for nb_outputs it is only
two).

The state's default value coincides with the earlier default of
query_formats being unset, namely that the filter accepts all formats
(and also sample rates and channel counts/layouts for audio)
provided that these properties agree coincide for all inputs and
outputs.

By using different union members for audio and video filters
the type-unsafety of using the same functions for audio and video
lists will furthermore be more confined to formats.c than before.

When the new fields are used, they will also avoid allocations:
Currently something nearly equivalent to ff_default_query_formats()
is called after every successful call to a query_formats callback;
yet in the common case that the newly allocated AVFilterFormats
are not used at all (namely if there are no free links) these newly
allocated AVFilterFormats are freed again without ever being used.
Filters no longer using the callback will not exhibit this any more.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-05 17:48:25 +02:00
Andreas Rheinhardt
aa6360928e avfilter/formats: Add function to create AVFilterFormats with one entry
Most instances ff_add_formats() actually only ever add one format;
this function can be used to simplify those callers.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-05 17:37:09 +02:00
Andreas Rheinhardt
628b30e886 avfilter/vf_fieldorder: Remove always-true check
A filter's formats.query callback is only called after all
the inputs and outputs have already been created.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-05 17:30:40 +02:00
Paul B Mahol
38b9dc98a8 avfilter/af_dynaudnorm: add support for filtering non-writable frames
Previously it would continue processing frame even if call
to make frame writable failed.
2021-10-05 16:28:47 +02:00
Paul B Mahol
fcbaeefb45 avfilter/af_dynaudnorm: fix possible clipping at start when alt-boundary mode is disabled 2021-10-05 15:40:45 +02:00
Paul B Mahol
3fe49b51fc avfilter/af_speechnorm: fix possible memleak on error to make frame writable
Fix this by adding support for non-writable frames.
2021-10-05 14:49:44 +02:00
Andreas Rheinhardt
2ee4077248 avfilter/vf_morpho: Fix invalid frees on error
The current code used a pointer to an array (of arrays) that
is offset relative to the start of the actually allocated buffer.
Yet offsetting the pointer is only done on success, whereas the
freeing code believes it to have happened even on error.
So if any of the subarrays (or the subarrays' subarrays) can't
be successfully allocated, one gets a bad free in free_lut().

Furthermore, said offsetting is only permissible in case the
offsetted pointer points in the allocated buffer (here: in case
the LUT's min_r is <= 0), as pointer arithmetic is undefined
in case it exceeds the allocated object.

Moreover, in case one of the subarrays couldn't be allocated,
the code nevertheless tried to free the subarray's subarrays;
and in case one of the subarray's subarrays could not be allocated
successfully, there will be an invalid free, too, because the
pointers for the subarrays' subarrays are also offset compared
to the base pointer.

This commit fixes all of this, by using the actually allocated
pointer for freeing and by adding appropriate checks before
freeing the subarrays. The former also allows to distinguish
the cases in which the lut is currently only half-allocated due to
an error in an earlier allocation attempt from the success case.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-04 17:27:50 +02:00
Andreas Rheinhardt
806a91bd4c avfilter/vf_morpho: Take pre-padding into account for LUT-reallocation
Fixes heap-buffer underflows.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-04 17:27:50 +02:00
Andreas Rheinhardt
0536c5a449 avfilter/vf_morpho: Factor out (re)allocating lut
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-04 17:27:50 +02:00
Andreas Rheinhardt
beded39b19 avfilter/vf_morpho: Fix leak of output frame on error
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-04 17:27:50 +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
2761a7403b avfilter/avfilter: Make ff_tlog_ref() static
It allows compilers to inline the one and only call to this function
in its caller or even to optimize it away completely (this function
is empty in case TRACE is not defined).

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 22:54:54 +02: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
9190302b2e examples/qsvdec: Don't use stack packet
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:50:50 +02:00
Andreas Rheinhardt
e9182820ad examples/hw_decode: Don't use stack packet
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:50:49 +02:00
Andreas Rheinhardt
86ec1093eb examples/filtering_video: Don't use stack packet
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:50:49 +02:00
Andreas Rheinhardt
a75f518b65 examples/filtering_audio: Don't use stack packet
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:50:49 +02:00
Andreas Rheinhardt
f495604361 examples/extract_mvs: Do not use stack packet
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:50:49 +02:00
Andreas Rheinhardt
0230d125cb examples/muxing: Don't use stack packet
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:50:49 +02:00
Andreas Rheinhardt
53f374c08d examples/remuxing: Don't use stack packet
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:50:49 +02:00
Andreas Rheinhardt
78426da3f4 examples/remuxing: Use av_packet_rescale_ts()
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:50:49 +02:00
Andreas Rheinhardt
8a23159797 fftools/ffmpeg, doc/examples: Remove redundant av_packet_unref
av_interleaved_write_frame() already returns blank packets.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-10-03 20:50:49 +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