summaryrefslogtreecommitdiff
path: root/libavcodec/avcodec.c
Commit message (Collapse)AuthorAgeFilesLines
* avcodec/avcodec: fix UB NULL+0Zhao Zhili2023-05-041-2/+3
| | | | Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avcodec: add AVCodecContext.frame_num as 64 bit variant to frame_numberMarton Balint2023-02-131-1/+6
| | | | | | | | | | Frame counters can overflow relatively easily (INT_MAX number of frames is slightly more than 1 year for 60 fps content), so make sure we use 64 bit values for them. Also deprecate the old 32 bit frame_number attribute. Signed-off-by: Marton Balint <cus@passwd.hu>
* avcodec: remove FF_API_AVCTX_TIMEBASEJames Almer2023-02-091-5/+0
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* Revert "avcodec/decode: use a packet list to store packet properties"James Almer2022-12-071-10/+0
| | | | | | | | | | | | | | The idea behind last_pkt_props was to store the properties of the last packet fed to the decoder. Any sort of queueing required by CODEC_CAP_DELAY decoders that consume several packets before they start outputting frames should be done by the decoders in question. An example of this is libdav1d. This is required for the following commits that will fix last_pkt_props in frame threading scenarios, as well as maintain its contents during flush. This revers commit 022a12b306ab2096e6ac9fc9b149828a849d65b2. Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/avcodec: Always use old channel count/layout if setAndreas Rheinhardt2022-09-221-2/+2
| | | | | | | | | | | This ensures that if AVCodecContext.channels or AVCodecContext.channel_layout are set, AVCodecContext.ch_layout has the equivalent values after this block. (In case these values are set inconsistently, the consistency check for ch_layout below will error out.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/avcodec: Check for more invalid channel layoutsAndreas Rheinhardt2022-09-221-0/+14
| | | | | | | | | | In particular, check the provided channel layout for encoders without AVCodec.ch_layouts set. This fixes an infinite loop in the WavPack encoder (and maybe other issues in other encoders as well) in case the channel count is zero. Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/avcodec: Uninitialize AVChannelLayout before overwriting itAndreas Rheinhardt2022-09-221-0/+1
| | | | | | Otherwise, there might be leaks. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/avcodec: Use the new API fields to validate the layout returned by ↵James Almer2022-09-191-18/+4
| | | | | | | | | | | decoders This block was scheduled for removal, which means that no validation would have taken place after the old API was removed. It was algo going to mistakenly remove an unrelated bits_per_coded_sample check. Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/avcodec: Remove redundant checkAndreas Rheinhardt2022-08-151-2/+1
| | | | | | | | At this point active_thread_type is set iff active_thread_type is set to FF_THREAD_FRAME iff AVCodecInternal.frame_thread_encoder is set. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/avcodec: Move initializing frame-thrd encoder to encode_preinitAndreas Rheinhardt2022-08-151-6/+0
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* lavc: add API for exporting reconstructed frames from encodersAnton Khirnov2022-08-021-0/+12
|
* avcodec: add common fflcms2 boilerplateNiklas Haas2022-07-301-0/+4
| | | | | | | | | | | | | Handling this in general code makes more sense than handling it in individual codec files, because it would be a lot of unnecessary code duplication for the plenty of formats that support exporting ICC profiles (jpg, png, tiff, webp, jxl, ...). encode.c and decode.c will be in charge of initializing this state as needed, so we merely need to make sure to uninit it afterwards from the common destructor path. Signed-off-by: Niklas Haas <git@haasn.dev>
* avcodec/aacdec: remove skip samples multiplierJames Almer2022-07-221-2/+0
| | | | | | | | | The amount of padding samples reported by containers take into account the extended samplerate in HE-AAC. Fixes ticket #9671. Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec: Make init-threadsafety the defaultAndreas Rheinhardt2022-07-181-2/+2
| | | | | | | | | | | and remove FF_CODEC_CAP_INIT_THREADSAFE All our native codecs are already init-threadsafe (only wrappers for external libraries and hwaccels are typically not marked as init-threadsafe yet), so it is only natural for this to also be the default state. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/internal: Hide stuff only used by the core decode APIAndreas Rheinhardt2022-05-121-0/+1
| | | | | | | | | | | | | | | | | | | | | | The general decoding API uses bitstream filters and an AVFifo and therefore AVCodecInternal contains pointers to an AVBSFContext and to an AVFifo and lavc/internal.h includes lavc/bsf.h and lavu/fifo.h. Yet actually, only two files are supposed to use these, namely avcodec.c and (mainly) decode.c. For all the other files, it should be an opaque type that they should not touch and that they need not know anything about. This can be achieved by not including these headers and using the structs instead of the corresponding typedefs. This also forces translation units that really use the BSF and the FIFO APIs themselves to include the relevant headers directly instead of relying on indirect inclusions (up until now, even avcodec.c and decode.c relied on fifo.h to be included by internal.h). Of course, it also avoids unnecessary rebuilds when bsf.h or fifo.h change. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* lavc: drop a confusing message about "thread emulation"Anton Khirnov2022-05-111-3/+0
| | | | There is no such thing.
* lavc/avcodec: only allocate decoding packets for decodersAnton Khirnov2022-05-111-6/+1
|
* lib*/version: Move library version functions into files of their ownAndreas Rheinhardt2022-05-101-25/+0
| | | | | | | This avoids having to rebuild big files every time FFMPEG_VERSION changes (which it does with every commit). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/avcodec: Don't reset decoder-fields for encoders when flushingAndreas Rheinhardt2022-04-131-12/+11
| | | | | Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/avcodec: Simplify accessing AVSubtitleRect via dedicated pointerAndreas Rheinhardt2022-04-131-6/+9
| | | | | Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/avcodec: Avoid av_frame_unref(NULL)Andreas Rheinhardt2022-04-131-1/+2
| | | | | | | It works, but it is not documented to work. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* lavc/encode: drop EncodeSimpleContextAnton Khirnov2022-04-131-2/+2
| | | | It has only a single member.
* lavc/avcodec: only allocate the encoding frame for encodersAnton Khirnov2022-04-131-3/+1
| | | | And only when needed, i.e. for encoders using the simple API.
* lavc/avcodec: simplify codec id/type validity checkingAnton Khirnov2022-04-131-8/+6
| | | | | On entry to avcodec_open2(), the AVCodecContext type and id either have to be UNKNOWN/NONE or have to match the codec to be used.
* avcodec/codec_internal: Add FFCodec, hide internal part of AVCodecAndreas Rheinhardt2022-03-211-17/+19
| | | | | | | | | | | | | | | | 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>
* avcodec/internal: Move FF_CODEC_CAP_* to a new header codec_internal.hAndreas Rheinhardt2022-03-211-0/+1
| | | | | | | | | | Also move FF_CODEC_TAGS_END as well as struct AVCodecDefault. This reduces the amount of files that have to include internal.h (which comes with quite a lot of indirect inclusions), as e.g. most encoders don't need it. It is furthemore in preparation for moving the private part of AVCodec out of the public codec.h. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* libavcodec: Split version.hMartin Storsjö2022-03-161-0/+1
| | | | | | | | | | | | | | This avoids including version.h in all source files, avoiding unnecessary rebuilds when the version number is bumped. Only version_major.h is included by the main header, which defines availability of e.g. FF_API_* macros, and which is bumped much less often. This isn't done for libavutil/version.h, because that header needs to be included essentially everywhere due to LIBAVUTIL_VERSION_INT being used wherever an AVClass is constructed. Signed-off-by: Martin Storsjö <martin@martin.st>
* lavc: drop temporary compat wrappers for channel layout API changeAnton Khirnov2022-03-151-29/+0
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* lavc: switch to the new channel layout APIVittorio Giovara2022-03-151-8/+73
| | | | | | | | Since the request_channel_layout is used only by a handful of codecs, move the option to codec private contexts. Signed-off-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/avcodec: Decrease the amount of time while holding the lockAndreas Rheinhardt2022-02-181-5/+5
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* lavc/avcodec: switch to new FIFO APIAnton Khirnov2022-02-071-11/+6
|
* avcodec/internal: Allow receive_frame codecs to use decode_simple pktAndreas Rheinhardt2021-11-071-4/+4
| | | | | | | | | | | | | | | | | | Decoders implementing the receive_frame API currently mostly use stack packets to temporarily hold the packet they receive from ff_decode_get_packet(). This role directly parallels the role of in_pkt, the spare packet used in decode_simple_internal for the decoders implementing the traditional decoding API. Said packet is unused by the generic code for the decoders implementing the receive_frame API, so allow them to use it to fulfill the function it already fulfills for the traditional API for both APIs. There is only one caveat in this: The packet is automatically unreferenced in avcodec_flush_buffers(). But this is actually positive as it means the decoders don't have to do this themselves (in case the packet is preserved between receive_frame calls). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/avcodec: Simplify check for flushing of bsfAndreas Rheinhardt2021-09-261-1/+1
| | | | | | | Just check for the existence of the bsf. This is equivalent to the old criterion of the AVCodecContext being a decoder. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/avcodec: Remove redundant assertAndreas Rheinhardt2021-09-261-3/+0
| | | | | | | | It is now checked by FATE that no encoder capable of flushing uses frame threads, so this now redundant runtime check can be removed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/avcodec: Make sanity check stricterAndreas Rheinhardt2021-09-261-2/+1
| | | | | | | | | | | | | If an AVCodec has a private class, its priv_data_size must be > 0 and at the end of a successful call to avcodec_open2() the AVCodecContext's priv_data must exist and its first element must be a pointer to said AVClass. This should not be conditional on priv_data_size being > 0 (which is tested by FATE) or on the private context having been successfully allocated (which has to have happened at that point). So remove these preconditions to make the test stricter. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: add a Film Grain codec property flagJames Almer2021-08-241-0/+2
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/avcodec: Stop including channel_layout.h in avcodec.hAndreas Rheinhardt2021-07-221-0/+1
| | | | | | Also include channel_layout.h directly wherever used. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/avcodec: Stop including bsf.h in avcodec.hAndreas Rheinhardt2021-07-221-0/+1
| | | | | | Also include bsf.h directly wherever it is used. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/avcodec: Don't free options on failure in avcodec_open2()Andreas Rheinhardt2021-06-081-1/+0
| | | | | | | | | | Instead return the dictionary in the state it is at the time the error occurred. This is more in line with the description of this parameter and allows to notify the user of unrecognized options if an error happens lateron (which might very well be due to e.g. misspelled options). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/avcodec: Avoid redundant copies of options in avcodec_open2Andreas Rheinhardt2021-06-081-11/+3
| | | | | | | It is no longer necessary now that ff_frame_thread_encoder_init() no longer receives an options dictionary. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/frame_thread_encoder: Avoid dictionariesAndreas Rheinhardt2021-06-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* avcodec/avcodec: Use avcodec_close() on avcodec_open2() failureAndreas Rheinhardt2021-04-281-40/+9
| | | | | | | | | | | | | | | | | | | | | | Compared to the earlier behaviour the following changes: a) AVCodecInternal.byte_buffer is freed. b) The last_pkt_props FIFO is emptied before freeing it. c) If set AVCodecContext.hwaccel is uninitialized and its private data is freed; hw_frames_ctx and hw_device_ctx are also unreferenced. d) coded_side_data is freed. e) active_thread_type is reset. a), b), d) should be no-ops as the buffer/fifo should be empty and no coded_side_data should exist at any point of avcodec_open2(). e) is obviously not bad. c) is in accordance with the documentation of hw_(frames|device)_ctx which states that libacodec takes over ownership of these references. At least in the case of VC-1 it is possible for the hw acceleration to be set during init and in this case freeing it actually fixes a memleak. avcodec_close() needed only minor adjustments to make it work with a potentially not fully initialized codec. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/avcodec: Store whether AVCodec->close needs to be calledAndreas Rheinhardt2021-04-281-12/+11
| | | | | | | | | | | | | | | Right now all AVCodecContexts except those using frame-threaded decoding call the codec's init function and expect its close function to be called. In order to make sure that the close function is not called for frame-threaded decoding ff_frame_thread_free() resets AVCodecContext.codec (and because of this it has to free the private AVOptions of the main AVCodecContext itself). This is not obvious and potentially fragile. Instead add a field to AVCodecInternal that indicates whether close should be called for this AVCodecContext. It is always zero when using frame-threaded decoding, so that resetting the codec is no longer necessary and has been removed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/avcodec: Free frame_thread_encoder on avcodec_open2() errorAndreas Rheinhardt2021-04-281-0/+2
| | | | | | | | The frame_thread_encoder has so far not been freed in case an error happened in avcodec_open2() after ff_frame_thread_encoder_init(). This commit changes this. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: Remove deprecated old encode/decode APIsAndreas Rheinhardt2021-04-271-30/+0
| | | | | | | | Deprecated in commits 7fc329e2dd6226dfecaa4a1d7adf353bf2773726 and 31f6a4b4b83aca1d73f3cfc99ce2b39331970bf3. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec: Remove deprecated AVCodecContext.coded_frameAndreas Rheinhardt2021-04-271-10/+0
| | | | | | | | | | Deprecated in 40cf1bbacc6220a0aa6bed5c331871d43f9ce370. (The currently disabled filter vf_mcdeint and vf_uspp were users of this field; they have not been changed, so that whoever wants to fix them can see the state of these filters when they were disabled.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec: Remove lock manager APIAndreas Rheinhardt2021-04-271-7/+0
| | | | | | | Deprecated in a04c2c707de2ce850f79870e84ac9d7ec7aa9143. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/avcodec: Actually honour the documentation of subtitle_headerAndreas Rheinhardt2021-04-241-2/+5
| | | | | | | | | | It is only supposed to be freed by libavcodec for decoders, yet avcodec_open2() always frees it on failure. Furthermore, avcodec_close() doesn't free it for decoders. Both of this has been changed. Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/avcodec: Use AVBPrint in avcodec_string()Andreas Rheinhardt2021-03-241-68/+65
| | | | | | | | It automatically records the current length of the string, whereas the current code contains lots of instances of snprintf(buf + strlen(buf), buf_size - strlen(buf), ...). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/avcodec: Update check for identical colorspace/primaries/trc namesAndreas Rheinhardt2021-03-241-7/+7
| | | | | | | | | | | | | | | | | If the numerical constants for colorspace, transfer characteristics and color primaries coincide, the current code presumes the corresponding names to be identical and prints only one of them obtained via av_get_colorspace_name(). There are two issues with this: The first is that the underlying assumption is wrong: The names only coincide in the 0-7 range, they differ for more recent additions. The second is that av_get_colorspace_name() is outdated itself; it has not been updated with the names of the newly defined colorspaces. Fix both of this by using the names from av_color_(space|primaries|transfer)_name() and comparing them via strcmp; don't use av_get_colorspace_name() at all. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>