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

107572 Commits

Author SHA1 Message Date
Andreas Rheinhardt
136ada2fc3 avcodec/hevc_mvs: Pass HEVCLocalContext when slice-threading
The HEVC decoder has both HEVCContext and HEVCLocalContext
structures. The latter is supposed to be the structure
containing the per-slicethread state.

Yet that is not how it is handled in practice: Each HEVCLocalContext
has a unique HEVCContext allocated for it and each of these
coincides except in exactly one field: The corresponding
HEVCLocalContext. This makes it possible to pass the HEVCContext
everywhere where logically a HEVCLocalContext should be used.

This commit stops doing this for lavc/hevc_mvs.c; it also constifies
everything that is possible in order to ensure that no slice thread
accidentally modifies the main HEVCContext state.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-25 23:31:12 +02:00
Andreas Rheinhardt
1837ae9d5f avcodec/hevcdec: Add pointers to logctx and parent ctx to HEVCLocalCtx
It is safe for a slice thread to read the main context
and therefore it is safe to add a pointer to const HEVCContext
(namely the parent context) to each HEVCLocalContext.
It is also safe (and actually redundant) to add a pointer
to a logcontext to HEVCLocalContext.

Doing so allows to pass the HEVCLocalContext as context in
the parts of the code that is run slice-threaded when slice-threading
is in use (currently these parts of the code use ordinary
HEVCContext*). This way one is not tempted to modify
the main context from the slice contexts.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-25 17:54:16 +02:00
Andreas Rheinhardt
c8d9d15f5e avcodec/hevcdec: Don't initialize HEVCContexts twice
The slicethread contexts need to be initialized for
every frame, not only the first one, so one can
remove the initialization when allocating these contexts,
because the ordinary per-frame initialization will
initialize them again just a few lines below.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-25 17:54:16 +02:00
Xu Guangxin
26ab6afcac fate/hevc: add clip for persistent_rice_adaptation_enabled_flag
Tests the issue fixed in c8bc0f66a8.

Signed-off-by: Xu Guangxin <oddstone@gmail.com>
2022-07-25 17:54:16 +02:00
Andreas Rheinhardt
cddb25c848 avcodec/x86/pngdsp: Remove obsolete ff_add_bytes_l2_mmx()
It is overridden by ff_add_bytes_l2_sse2() on any non-ancient CPU.

Reviewed-by: Henrik Gramner <henrik@gramner.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-25 16:00:57 +02:00
Andreas Rheinhardt
39a538f430 avcodec/hevcdec: Output MD5-message in one piece
Otherwise, there is no guarantee that the various av_log-messages
are not interrupted by another log statement. The latter may originate
from anywhere else, even the HEVC decoder itself, as happens when
one uses frame-threading to decode the BUMPING_A_ericsson_1.bit
sample from the FATE-suite.

Furthermore, the earlier approach suffered from the fact that
various parts of the logmsg were output with different loglevels
and that checking stopped after having encountered the first
plane with MD5 mismatch, although it is probably interesting to
know whether other planes are incorrect, too.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-24 18:42:32 +02:00
Marvin Scholz
564d7946de configure: properly require libx264 if enabled
When libx264 can not be found even though it is enabled, it should error
out properly instead of silently disabling it.
2022-07-24 17:41:21 +03:00
Zane van Iperen
8adbecc88e
avformat/argo_cvg: expose loop/reverb/checksum via metadata
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
2022-07-24 19:24:00 +10:00
Zane van Iperen
9054a99fea
avformat/argo_cvg: remove trace logging
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
2022-07-24 19:23:57 +10:00
Zane van Iperen
23f0c55ff8
avformat/argo_cvg: add -loop and -reverb options
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
2022-07-24 19:23:54 +10:00
Zane van Iperen
4dfa8341e0
avformat/argo_cvg: name unk{1,2} fields correctly
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
2022-07-24 19:23:18 +10:00
Anton Khirnov
34cbda3ee1 fftools/ffmpeg: replace AVFrame.pkt_duration with duration
Mistakenly reintroduced in 4740fea7dd.
2022-07-24 08:46:16 +02:00
Ting Fu
23953b9eb7 lavf/dnn: dump OpenVINO model input/output names to OVMdel struct.
Dump all input/output names to OVModel struct. In case other funcs use
them for reporting errors or locating issues.

Signed-off-by: Ting Fu <ting.fu@intel.com>
2022-07-24 08:38:50 +08:00
Andreas Rheinhardt
1cb7fd317c avcodec/svq1enc: Use unsigned for parameter >= 0 to workaround GCC bug
encode_block() in svq1enc.c looks like the following:

static int encode_block(int block[7][256], int level)
{
    int best_score = 0;

    for (unsigned x = 0; x < level; x++) {
        int v = block[1][x];
        block[level][x] = 0;
        best_score      += v * v;
    }

    if (level > 0 && best_score > 64) {
        int score = 0;

        score += encode_block(block, level - 1);
        score += encode_block(block, level - 1);

        if (score < best_score) {
            best_score = score;
        }
    }

    return best_score;
}

When called from outside of encode_block(), it is always called with
level == 5.

This triggers a bug [1] in GCC: On -O3, it creates eight clones of
encode_block with different values of level inlined into it. The clones
with negative values are of course useless*, but they also lead to
-Warray-bounds warnings, because they access block[-1].

This has been mitigated in GCC 12: It no longer creates clones
for parameters that it knows are impossible. Somehow switching levels
to unsigned makes GCC know this. Therefore this commit does this.
(For GCC 11, this changes the warning to "array subscript 4294967295 is
above array bounds" from "array subscript -1 is below array bounds".)

[1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102513

*: These clones can actually be discarded when compiling with
-ffunction-sections.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-23 22:53:29 +02:00
Andreas Rheinhardt
890efee2b8 avcodec/h264_loopfilter: Fix incorrect function parameter array size
filter_mb_mbaff_edgev() and filter_mb_mbaff_edgecv()
have a function parameter whose expected size depends upon
another parameter: It is 2 * bsi + 1 (with bsi always being 1 or 2).
This array is declared as const int16_t[7], yet some of the callers
with bsi == 1 call it with only an const int16_t[4] available.
This leads to -Wstringop-overread warnings from GCC 12.1.

This commit fixes these by replacing [7] with [/* 2 * bsi + 1 */],
so that the expected range and its dependence on bsi is immediately
visible.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-23 22:53:29 +02:00
Andreas Rheinhardt
708890e78f avcodec/snowenc: Don't pass int[2] as parameter declared as int[3]
check_block_inter() currently does this when calling check_block().
This leads to a -Wstringop-overflow= warning when compiling with
GCC 12.1.

Given that the main part of the body of check_block() consists
of an "if (intra) { ... } else { ... }" which is true iff
check_block() is not called from check_block_inter(),
it makes sense to fix this by just inlining check_block()
check_block_inter() and turning check_block() into a new
check_block_intra() (with the inter parts removed, of course).

This should also not make much of a difference for the generated code
given that both check_block() as well as check_block_inter()
are already marked as av_always_inline, so this commit follows
this route to fix the issue.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-23 22:53:29 +02:00
Andreas Rheinhardt
c807ee6975 avformat/asfcrypt: Fix wrong array length in function declaration
multiswap_step() and multiswap_inv_step() both only require
six keys; in all current callers, these keys are part of
an array of twelve keys, yet in some of these callers the keys
given to these functions point to the second half of these
twelve keys, so that only six keys are available to these functions.
This led to -Wstringop-overread warnings when compiling with GCC 12.1.
Fix these by adapting the declaration of these functions.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-23 22:53:29 +02:00
Andreas Rheinhardt
30c7cff399 avformat/lrcenc: Avoid reading packet padding
(Everything would be fine if the packet was properly padded.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-23 19:01:44 +02:00
Andreas Rheinhardt
b0ae5d02f3 fftools/ffmpeg: Zero subtitle packet padding
Fixes uninitialized reads in the sub-lrc-remux test.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-23 19:01:44 +02:00
Andreas Rheinhardt
8136ab8e76 fftools/objpool: Don't use return with expression when returning void
Using tail calls with functions returning void is forbidden
(C99/C11 6.8.6.4: "A return statement with an expression shall not appear
in a function whose return type is void.") GCC emits a warning
because of this when using -pedantic: "ISO C forbids ‘return’ with
expression, in function returning void"

Reviewed-by: Hendrik Leppkes <h.leppkes@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-23 18:58:35 +02:00
Anton Khirnov
2d924b3a63 fftools/ffmpeg: move each muxer to a separate thread 2022-07-23 11:53:19 +02:00
Anton Khirnov
37c764df67 fftools: add a multistream thread-safe queue
It is similar to AVThreadMessageQueue, but supports multiple streams,
each with its own EOF state.
2022-07-23 11:53:19 +02:00
Anton Khirnov
760ce4bc0b fftools/ffmpeg: depend on threads
ffmpeg will be switched to a fully threaded architecture, starting with
muxers.
2022-07-23 11:53:19 +02:00
Anton Khirnov
8e854cdd2e fftools/ffmpeg: stop using av_stream_get_end_pts()
It retrieves the muxer's internal timestamp with under-defined
semantics. Continuing to use this value would also require
synchronization once the muxer is moved to a separate thread.

Replace the value with last_mux_dts.
2022-07-23 11:53:19 +02:00
Anton Khirnov
33f5cacb1d fftools/ffmpeg_mux: do not call exit_program() in print_sdp()
Return an error instead, as is already done in other places in this
function.
2022-07-23 11:53:19 +02:00
Anton Khirnov
9fc64574e1 fftools/ffmpeg_mux: return errors from write_packet()
Do not call exit_program(), as that would conflict with moving this code
into a separate thread.
2022-07-23 11:53:19 +02:00
Anton Khirnov
279214dd51 fftools/ffmpeg_mux: return errors from submit_packet()
Do not call exit_program(), as that would conflict with moving this code
into a separate thread.
2022-07-23 11:53:19 +02:00
Anton Khirnov
52bc8a842e fftools/ffmpeg_mux: return errors from of_submit_packet()
Do not call exit_program(), as that would conflict with moving this code
into a separate thread.
2022-07-23 11:53:19 +02:00
Anton Khirnov
ff593c6c88 fftools/ffmpeg: make the muxer AVFormatContext private to ffmpeg_mux.c
Since the muxer will operate in a separate thread in the future, the
muxer context should not be accessed from the outside.
2022-07-23 11:53:19 +02:00
Anton Khirnov
4403851ca9 fftools/ffmpeg: only set OutputStream.frame_number for video encoding
It is unused otherwise.

Rename the field to vsync_frame_number to better reflect its current
purpose.
2022-07-23 11:53:19 +02:00
Anton Khirnov
4cd19eaffa fftools/ffmpeg: stop using OutputStream.frame_number in print_report()
This field means different things when the video is encoded (number of
frames emitted to the encoding sync queue/encoder by the video sync
code) or copied (number of packets sent to the muxer sync queue).

Print the value of packets_written instead, which means the same thing
in both cases. It is also more accurate, since packets may be dropped by
the sync queue or bitstream filters.
2022-07-23 11:53:19 +02:00
Anton Khirnov
587081a179 fftools/ffmpeg: use the sync queues to handle -frames
Same issues apply to it as to -shortest.

Changes the results of the following tests:
- matroska-flac-extradata-update
  The test reencodes two input FLAC streams into three output FLAC
  streams. The last output stream is limited to 8 frames. The current
  code results in the first two output streams having 12 frames, after
  this commit all three streams have 8 frames and are the same length.
  This new result is better, since it is predictable.
- mkv-1242
  The test streamcopies one video and one audio stream, video is limited
  to 11 frames. The new result shortens the audio stream so that it is
  not longer than the video.
2022-07-23 11:53:19 +02:00
Anton Khirnov
919638ff5c fftools/ffmpeg_mux: reindent 2022-07-23 11:53:19 +02:00
Anton Khirnov
4740fea7dd fftools/ffmpeg: rework -shortest implementation
The -shortest option (which finishes the output file at the time the
shortest stream ends) is currently implemented by faking the -t option
when an output stream ends. This approach is fragile, since it depends
on the frames/packets being processed in a specific order. E.g. there
are currently some situations in which the output file length will
depend unpredictably on unrelated factors like encoder delay. More
importantly, the present work aiming at splitting various ffmpeg
components into different threads will make this approach completely
unworkable, since the frames/packets will arrive in effectively random
order.

This commit introduces a "sync queue", which is essentially a collection
of FIFOs, one per stream. Frames/packets are submitted to these FIFOs
and are then released for further processing (encoding or muxing) when
it is ensured that the frame in question will not cause its stream to
get ahead of the other streams (the logic is similar to libavformat's
interleaving queue).

These sync queues are then used for encoding and/or muxing when the
-shortest option is specified.

A new option – -shortest_buf_duration – controls the maximum number of
queued packets, to avoid runaway memory usage.

This commit changes the results of the following tests:
- copy-shortest[12]: the last audio frame is now gone. This is
  correct, since it actually outlasts the last video frame.
- shortest-sub: the video packets following the last subtitle packet are
  now gone. This is also correct.
2022-07-23 11:53:19 +02:00
Anton Khirnov
9ac78fb347 fftools: add an object pool
Allows to avoid constantly allocating and freeing objects like AVFrame
or AVPacket.
2022-07-23 11:53:19 +02:00
Anton Khirnov
d02ae31fb2 fftools/ffmpeg: use pre-BSF DTS for choosing next output
The following commits will add a new buffering stage after bitstream
filters, which should not be taken into account for choosing next
output.

OutputStream.last_mux_dts is also used by the muxing code to make up
missing DTS values - that field is now moved to the muxer-private
MuxStream object.
2022-07-23 11:53:19 +02:00
Anton Khirnov
b2b9e9ccee fftools/ffmpeg: use last filter output pts to choose next output stream
This will be needed in following commits that will add new buffering
stages after encoding and bitstream filtering.
2022-07-23 11:53:19 +02:00
Anton Khirnov
d55b8dbcff fate/ffmpeg: add a test for interleaving video+subs 2022-07-23 11:53:19 +02:00
Anton Khirnov
f52d045e34 fftools/ffmpeg: do not send spurious EOF for streamcopy when looping 2022-07-23 11:53:19 +02:00
Anton Khirnov
481b27e850 fftools/ffmpeg: use refcounted packets for encoded subtitles 2022-07-23 11:53:19 +02:00
Anton Khirnov
dceccd4aeb fftools/ffmpeg: move freeing 2pass input stats to a better place
The current placement of this free is historical - it used to be
followed by avcodec_close(), since removed.

The proper place for freeing the stats is currently right before the
encoder context itself is freed.
2022-07-23 11:53:19 +02:00
Anton Khirnov
52fee96ae9 fftools/ffmpeg: move output file opts into private context
It is private to the muxer, no reason to access it from outside.
2022-07-23 11:53:19 +02:00
Anton Khirnov
ec00b005f9 fftools/ffmpeg_mux: split of_write_packet()
It is currently called from two places:
- output_packet() in ffmpeg.c, which submits the newly available output
  packet to the muxer
- from of_check_init() in ffmpeg_mux.c after the header has been
  written, to flush the muxing queue

Some packets will thus be processed by this function twice, so it
requires an extra parameter to indicate the place it is called from and
avoid modifying some state twice.

This is fragile and hard to follow, so split this function into two.
Also rename of_write_packet() to of_submit_packet() to better reflect
its new purpose.
2022-07-23 11:53:19 +02:00
Anton Khirnov
6999a3cb18 fftools/ffmpeg_mux: split queuing packets into a separate function 2022-07-23 11:53:19 +02:00
Anton Khirnov
9c2b800203 fftools/ffmpeg: move the mux queue into muxer private data
The muxing queue currently lives in OutputStream, which is a very large
struct storing the state for both encoding and muxing. The muxing queue
is only used by the code in ffmpeg_mux, so it makes sense to restrict it
to that file.

This makes the first step towards reducing the scope of OutputStream.
2022-07-23 11:53:19 +02:00
Anton Khirnov
35bfcff07f fftools/ffmpeg: do not log to the muxer context
All other logging goes to NULL context.
2022-07-23 11:53:19 +02:00
Anton Khirnov
48989efb76 fftools/ffmpeg: access output file chapters through a wrapper
Avoid accessing the muxer context directly, as this will become
forbidden in future commits.
2022-07-23 11:53:19 +02:00
Anton Khirnov
4877842bb5 fftools/ffmpeg: refactor the code checking for bitexact output
Figure out earlier whether the output stream/file should be bitexact and
store this information in a flag in OutputFile/OutputStream.

Stop accessing the muxer in set_encoder_id(), which will become
forbidden in future commits.
2022-07-23 11:53:19 +02:00
Anton Khirnov
cc1cc2c65e fftools/ffmpeg: move closing the file into of_write_trailer()
The current code postpones closing the files until after printing the
final report, which accesses the output file size. Deal with this by
storing the final file size before closing the file.
2022-07-23 11:53:19 +02:00
Anton Khirnov
cc49646077 fftools/ffmpeg: write the header for stream-less outputs when initializing the muxer
There is no reason to delay this.
2022-07-23 11:53:19 +02:00