Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2022-09-03avcodec/frame_thread_encoder: Stop serializing unreferencing AVFramesAndreas Rheinhardt
Currently, the frame-threaded decoding API still supports thread-unsafe callbacks. If one uses a thread-unsafe get_buffer2() callback, calls to av_frame_unref() by the decoder are serialized, because it is presumed that the underlying deallocator is thread-unsafe. The frame-threaded encoder seems to have been written with this restriction in mind: It always serializes unreferencing its AVFrames, although no documentation forces it to do so. This commit schedules to change this behaviour as soon as thread-unsafe callbacks are removed. For this reason, the FF_API_THREAD_SAFE_CALLBACKS define is reused. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-08-27avcodec/encode, frame_thread_encoder: Unify calling encode callbackAndreas Rheinhardt
The encode-callback (the callback used by the FF_CODEC_CB_TYPE_ENCODE encoders) is currently called in two places: encode_simple_internal() and by the worker threads of frame-threaded encoders. After the call, some packet properties are set based upon the corresponding AVFrame properties and the packet is made refcounted if it isn't already. So there is some code duplication. There was also non-duplicated code in encode_simple_internal() which is executed even when using frame-threading. This included an emms_c() (which is needed for frame-threading, too, if it is needed for the single-threaded case, because there are allocations (via av_packet_make_refcounted()) immediately after returning from the encode-callback). Furthermore, some further properties are only set in encode_simple_internal(): For audio, pts and duration are derived from the corresponding fields of the frame if the encoder does not have the AV_CODEC_CAP_DELAY set. Yet this is wrong for frame-threaded encoders, because frame-threading always introduces delay regardless of whether the underlying codec has said cap. This only worked because there are no frame-threaded audio encoders. This commit fixes the code duplication and the above issue by factoring this code out and reusing it in both places. It would work in case of audio codecs with frame-threading, because now the values are derived from the correct AVFrame. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-08-27avcodec/frame_thread_encoder: Forward got_packet directlyAndreas Rheinhardt
Instead of indicating whether we got a packet by setting pkt->data and pkt->size to zero. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-04-05avcodec/codec_internal: Use union for FFCodec decode/encode callbacksAndreas Rheinhardt
This is possible, because every given FFCodec has to implement exactly one of these. Doing so decreases sizeof(FFCodec) and therefore decreases the size of the binary. Notice that in case of position-independent code the decrease is in .data.rel.ro, so that this translates to decreased memory consumption. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-03-21avcodec/codec_internal: Add FFCodec, hide internal part of AVCodecAndreas Rheinhardt
Up until now, codec.h contains both public and private parts of AVCodec. This exposes the internals of AVCodec to users and leads them into the temptation of actually using them and forces us to forward-declare structures and types that users can't use at all. This commit changes this by adding a new structure FFCodec to codec_internal.h that extends AVCodec, i.e. contains the public AVCodec as first member; the private fields of AVCodec are moved to this structure, leaving codec.h clean. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-04avcodec/frame_thread_encoder: Mark init and free functions as av_coldAndreas Rheinhardt
Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-04avcodec/frame_thread_encoder: Return proper error codesAndreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-04avcodec/frame_thread_encoder: Don't shadow variablesAndreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-04avcodec/frame_thread_encoder: Reindent after the previous commitAndreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-04avcodec/frame_thread_encoder: Check initializing mutexes/conditionsAndreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-17avcodec/frame_thread_encoder: Free AVCodecContext structure on error during initMichael Niedermayer
Fixes: MemLeak Fixes: 8281 Fixes: PoC_option158.jpg Fixes: CVE-2020-22037 Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-07-22avcodec/avcodec: Don't include cpu.hAndreas Rheinhardt
It is not used here at all; instead, add it where it is used without including it or any of the arch-specific CPU headers. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-06-08avcodec/frame_thread_encoder: Remove redundant memcpyAndreas Rheinhardt
In case the underlying AVCodec has no private class, the private data of both the main as well as each worker AVCodecContext is just zeroed (the codec's init function has not been called on any of them and without a private class there is no way to legitimately set anything before the aforementioned init function). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-06-08avcodec/frame_thread_encoder: Avoid dictionariesAndreas Rheinhardt
avcodec_open2() allows to provide options via an AVDictionary; but it is also allowed to set options by simply setting the value of the AVCodecContext or via the AVOptions API if the codec has a private class. Any options provided via an AVDictionary have already been applied before ff_frame_thread_init(), so in order to copy all the options from the main AVCodecContext and its private context, it is enough to av_opt_copy() these options. The current code does this, but it does more: It also copies the user-provided AVDictionary and uses it for the initialization of each of the worker-AVCodecContexts. This is completely unnecessary, because said options have already been copied from the main context. Furthermore, these options were also examined to decide if frame threading should be used for huffman encoding in case this would incur nondeterminism. This is wrong, because options not set via an AVDictionary are ignored. Instead inspect the values stored in the contexts directly. (In order to maintain the current behaviour, the default value of the "non_deterministic" option has been changed to false, because the absence of an entry with said key in the AVDictionary had the consequence of disallowing nondeterminism.) Finally, the AVDictionary has been removed from the signature of ff_frame_thread_encoder_init(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-02-17avcodec/frame_thread_encoder: Use more natural typesAndreas Rheinhardt
Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-02-17avcodec/frame_thread_encoder: Reduce amount of code guarded by mutexAndreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-02-17avcodec/frame_thread_encoder: Avoid FIFOAndreas Rheinhardt
It can be replaced by a simple counter. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-02-17avcodec/frame_thread_encoder: Avoid allocations of AVFramesAndreas Rheinhardt
Up until now, when using frame threaded encoding, an AVFrame would be allocated for every frame to be encoded. These AVFrames would reach the worker threads via a FIFO of tasks, a structure which contained the AVFrame as well as an index into an array which gives the place where the worker thread shall put the returned packet; in addition to that, said structure also contained several unused fields. This commit changes this: The AVFrames are now allocated during init in the array that is up until now only used to return the packets. The contents to be encoded are put into the AVFrame in the same array element that is also used to return the packets. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-02-17avcodec/frame_thread_encoder: Avoid creating reference to frameAndreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-02-17avcodec/frame_thread_encoder: Avoid allocations of AVPackets, fix deadlockAndreas Rheinhardt
Up until now, when doing frame thread encoding, each worker thread tried to allocate an AVPacket for every AVFrame to be encoded; said packets would then be handed back to the main thread, where the content of said packet is copied into the packet actually destined for output; the temporary AVPacket is then freed. Besides being wasteful this also has another problem: There is a risk of deadlock, namely if no AVPacket can be allocated at all. The user doesn't get an error at all in this case and the worker threads will simply try to allocate a packet again and again. If the user has supplied enough frames, the user's thread will block until a task has been completed, which just doesn't happen if no packet can ever be allocated. This patch instead modifies the code to allocate the packets during init; they are then reused again and again. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-02-17avcodec/frame_thread_encoder: Fix segfault on allocation errorAndreas Rheinhardt
Fixes a segfault from av_fifo_size(NULL) that happens in ff_frame_thread_encoder_free if the fifo couldn't be allocted; furthermore the mutexes and conditions that are destroyed in ff_frame_thread_encoder_free are not even initialized at this point, so don't call said function. Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-02-17avcodec/frame_thread_encoder: Improve type safetyAndreas Rheinhardt
Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-25avcodec/frame_thread_encoder: remove usage of avcodec_encode_video2()James Almer
Call the encoder's internal AVCodec.encode2() function instead. Signed-off-by: James Almer <jamrial@gmail.com>
2020-05-18avcodec/frame_thread_encoder: check for frame threading codec cap instead of ↵James Almer
intra only It's the correct dedicated capability reported by supported encoders. Otherwise, the frame thread path will be used for unsupported encoders like r210 for no gain. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: James Almer <jamrial@gmail.com>
2019-08-11lavc/frame_thread_encoder: Do not memcpy() from NULL.Carl Eugen Hoyos
Fixes ticket #7981.
2018-08-16avcodec/frame_thread_encoder: fix memory leak that occurs when close ↵lee ju
encoder without sending eof and receiving to end Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-02avcodec/frame_thread_encoder: remove usage of av_dup_packet()James Almer
Signed-off-by: James Almer <jamrial@gmail.com>
2017-09-23avcodec/frame_thread_encoder: use av_packet_alloc()James Almer
Signed-off-by: James Almer <jamrial@gmail.com>
2017-09-18lavc/frame_thread_encoder: Do not mix variable declaration and code.Carl Eugen Hoyos
Fixes a warning: ISO C90 forbids mixed declarations and code
2017-09-16avcodec/frame_thread_encoder: Fix AV_OPT_TYPE_STRING handling in avctxReimar Döffinger
This is the equivalent to what 7d317d4706b49d572a1eb5269438753be18362c7 did for the codec-specific options. av_opt_copy has specific handling so it's fine that we already copied the whole context before. Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
2017-09-12frame_thread_encoder: make 'exit' member atomic.Ronald S. Bultje
Should fix the following tsan warning: WARNING: ThreadSanitizer: data race (pid=19806) Read of size 4 at 0x7b84000012f0 by thread T9: #0 worker src/libavcodec/frame_thread_encoder.c:66 (ffmpeg+0x0000007f349e) [..] Previous write of size 4 at 0x7b84000012f0 by main thread (mutexes: write M1395): #0 ff_frame_thread_encoder_free src/libavcodec/frame_thread_encoder.c:239 (ffmpeg+0x0000007f379e) [..]
2017-06-26avcodec/frame_thread_encoder: Fix AV_OPT_TYPE_STRING handling in priv_dataMichael Niedermayer
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-05-25frame_thread_encoder: extend critical code covered by finished_task_mutex.Ronald S. Bultje
Should fix tsan errors in utvideoenc_rgb_left and related tests.
2016-06-05Check av_dup_packet() return codeMichael Niedermayer
Fixes: CID1338320 Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-01-28avcodec/frame_thread_encoder: Check the private option for huffy's context ↵Derek Buitenhuis
modelling Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2015-12-07lavc, lavu: use avutil/thread.h instead of redundant conditional includesClément Bœsch
2015-07-27Merge commit 'def97856de6021965db86c25a732d78689bd6bb0'Michael Niedermayer
* commit 'def97856de6021965db86c25a732d78689bd6bb0': lavc: AV-prefix all codec capabilities Conflicts: cmdutils.c ffmpeg.c ffplay.c libavcodec/8svx.c libavcodec/aacenc.c libavcodec/ac3dec.c libavcodec/adpcm.c libavcodec/alac.c libavcodec/atrac3plusdec.c libavcodec/bink.c libavcodec/dnxhddec.c libavcodec/dvdec.c libavcodec/dvenc.c libavcodec/ffv1dec.c libavcodec/ffv1enc.c libavcodec/fic.c libavcodec/flacdec.c libavcodec/flacenc.c libavcodec/flvdec.c libavcodec/fraps.c libavcodec/frwu.c libavcodec/gifdec.c libavcodec/h261dec.c libavcodec/hevc.c libavcodec/iff.c libavcodec/imc.c libavcodec/libopenjpegdec.c libavcodec/libvo-aacenc.c libavcodec/libvorbisenc.c libavcodec/libvpxdec.c libavcodec/libvpxenc.c libavcodec/libx264.c libavcodec/mjpegbdec.c libavcodec/mjpegdec.c libavcodec/mpegaudiodec_float.c libavcodec/msmpeg4dec.c libavcodec/mxpegdec.c libavcodec/nvenc_h264.c libavcodec/nvenc_hevc.c libavcodec/pngdec.c libavcodec/qpeg.c libavcodec/ra288.c libavcodec/rv10.c libavcodec/s302m.c libavcodec/sp5xdec.c libavcodec/takdec.c libavcodec/tiff.c libavcodec/tta.c libavcodec/utils.c libavcodec/v210dec.c libavcodec/vp6.c libavcodec/vp9.c libavcodec/wavpack.c libavcodec/yop.c Merged-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-27Merge commit '7c6eb0a1b7bf1aac7f033a7ec6d8cacc3b5c2615'Michael Niedermayer
* commit '7c6eb0a1b7bf1aac7f033a7ec6d8cacc3b5c2615': lavc: AV-prefix all codec flags Conflicts: doc/examples/muxing.c ffmpeg.c ffmpeg_opt.c ffplay.c libavcodec/aacdec.c libavcodec/aacenc.c libavcodec/ac3dec.c libavcodec/ac3enc_float.c libavcodec/atrac1.c libavcodec/atrac3.c libavcodec/atrac3plusdec.c libavcodec/dcadec.c libavcodec/ffv1enc.c libavcodec/h264.c libavcodec/h264_loopfilter.c libavcodec/h264_mb.c libavcodec/imc.c libavcodec/libmp3lame.c libavcodec/libtheoraenc.c libavcodec/libtwolame.c libavcodec/libvpxenc.c libavcodec/libxavs.c libavcodec/libxvid.c libavcodec/mpeg12dec.c libavcodec/mpeg12enc.c libavcodec/mpegaudiodec_template.c libavcodec/mpegvideo.c libavcodec/mpegvideo_enc.c libavcodec/mpegvideo_motion.c libavcodec/nellymoserdec.c libavcodec/nellymoserenc.c libavcodec/nvenc.c libavcodec/on2avc.c libavcodec/options_table.h libavcodec/opus_celt.c libavcodec/pngenc.c libavcodec/ra288.c libavcodec/ratecontrol.c libavcodec/twinvq.c libavcodec/vc1_block.c libavcodec/vc1_loopfilter.c libavcodec/vc1_mc.c libavcodec/vc1dec.c libavcodec/vorbisdec.c libavcodec/vp3.c libavcodec/wma.c libavcodec/wmaprodec.c libavcodec/x86/hpeldsp_init.c libavcodec/x86/me_cmp_init.c Merged-by: Michael Niedermayer <michael@niedermayer.cc>
2014-12-23frame_thread_encoder: use ref-counting to avoid memcpy of all input framesHendrik Leppkes
Apparently uneeded lock/unlock removed by commiter Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-08-19huffyuvenc: add a non-deterministic optionChristophe Gisquet
Not actually used in huffyuvenc, but rather in setting the frame threading. Example for some files: context=0: 851974 27226 1137281 context=1,ND=0: 471819 22604 972351 context=1,ND=1: 472875 22673 972582 Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-05-20lavc/frame_thread_encoder: use av_fifo_alloc_arrayLukasz Marek
Signed-off-by: Lukasz Marek <lukasz.m.luki2@gmail.com>
2014-05-08lavc: use av_fifo_freepLukasz Marek
Signed-off-by: Lukasz Marek <lukasz.m.luki2@gmail.com>
2014-04-27Fix dont and doesnt typosMichael Niedermayer
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-02-15avcodec/frame_thread_encoder: warn about huffyuv limitationsMichael Niedermayer
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-02-15avcodec/frame_thread_encoder: restructure huffyuv checksMichael Niedermayer
This makes them similar to the other checks Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-01-30Warn the user if mjpeg cbr encoding with frame threading was requested.Carl Eugen Hoyos
2014-01-30Force automatic thread_count to 1 for cbr mjpeg frame threading.Carl Eugen Hoyos
Constant bit rate mjpeg encoding fails for threads > 1 and frame threading.
2014-01-28avcodec/huffyuvenc: frame multi-threading supportMichael Niedermayer
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-05-28os2threads: move from lavc to compat/Dave Yeo
For useage in other places besides lavc. Needed after commit 90f9a5830b5d332de7ebb1ab45589f1870cbd65d Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-05-24avcodec: remove ff_get_logical_cpus()Michael Niedermayer
This simplifies the code Signed-off-by: Michael Niedermayer <michaelni@gmx.at>