summaryrefslogtreecommitdiff
path: root/libavcodec/opusenc.c
Commit message (Collapse)AuthorAgeFilesLines
* avcodec: add AVCodecContext.frame_num as 64 bit variant to frame_numberMarton Balint2023-02-131-1/+1
| | | | | | | | | | 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/opustab: Avoid indirection to access ff_celt_windowAndreas Rheinhardt2022-10-101-2/+2
| | | | | | | | | | | | | | | Currently, it is accessed via a pointer (ff_celt_window) exported from opustab.h which points inside a static array (ff_celt_window_padded) in opustab.h. Instead export ff_celt_window_padded directly and make opustab.h a static const pointer pointing inside ff_celt_window_padded. Also mark all the declarations in opustab.h as hidden, so that the compiler knows that ff_celt_window has a fixed offset from the code even when compiling position-independent code. Reviewed-by: Lynne <dev@lynne.ee> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/opusenc_psy: Remove unused function parameterAndreas Rheinhardt2022-10-081-1/+1
| | | | | Reviewed-by: Lynne <dev@lynne.ee> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/opus: Move defines to better placesAndreas Rheinhardt2022-10-051-0/+2
| | | | | | | | | Move ROUND_MUL* macros to their only users and the Celt macros to opus_celt.h. Also improve the other headers a bit while at it. Reviewed-by: Lynne <dev@lynne.ee> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal: Avoid deprecation warnings for channel_layoutsAndreas Rheinhardt2022-09-281-4/+1
| | | | | | | | | | | | | | | | | | AVCodec.channel_layouts is deprecated and Clang (unlike GCC) warns when setting this field in a codec definition. Fortunately, Clang (unlike GCC) allows to use FF_DISABLE_DEPRECATION_WARNINGS inside a definition (of an FFCodec), so that one can create simple macros to set AVCodec.channel_layouts that also suppress deprecation warnings for Clang. (Notice that some of the codec definitions were already inside FF_DISABLE/ENABLE_DEPRECATION_WARNINGS (that were not guarded by FF_API_OLD_CHANNEL_LAYOUT); these have been removed. Also notice that setting AVCodec.channel_layouts was not guarded by FF_API_OLD_CHANNEL_LAYOUT either, so testing disabling it it without removing all the codeblocks would not have worked.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* opus: convert encoder and decoder to lavu/txLynne2022-09-261-6/+9
| | | | | This commit changes both the encoder and decoder to use the new lavu/tx code, which has faster C transforms and more assembly optimizations.
* avcodec/codec_internal: Add macro to set AVCodec.long_nameAndreas Rheinhardt2022-09-031-1/+1
| | | | | | | | It reduces typing: Before this patch, there were 105 codecs whose long_name-definition exceeded the 80 char line length limit. Now there are only nine of them. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: Make ff_alloc_packet() based encoders accept user buffersAndreas Rheinhardt2022-08-271-1/+2
| | | | | | | | | | | | | | | | | | Up until now, these encoders received non-refcounted packets (whose data was owned by the corresponding AVCodecContext) from ff_alloc_packet(); these packets were made refcounted lateron by av_packet_make_refcounted() generically. This commit makes these encoders accept user-supplied buffers by replacing av_packet_make_refcounted() with an equivalent function that is based upon get_encode_buffer(). (I am pretty certain that one can also set the flag for mpegvideo- based encoders, but I want to double-check this later. What is certain is that it reallocates the buffer owned by the AVCodecContext which should maybe be moved to encode.c, so that proresenc_kostya.c and ttaenc.c can make use of it, too.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: Make init-threadsafety the defaultAndreas Rheinhardt2022-07-181-1/+1
| | | | | | | | | | | 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/codec_internal: Use union for FFCodec decode/encode callbacksAndreas Rheinhardt2022-04-051-1/+1
| | | | | | | | | | | 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>
* avcodec/codec_internal: Rename AVCodecDefault->FFCodecDefaultAndreas Rheinhardt2022-03-211-1/+1
| | | | | | | This structure is no longer declared in a public header, so using an FF-prefix is more appropriate. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal: Add FFCodec, hide internal part of AVCodecAndreas Rheinhardt2022-03-211-11/+11
| | | | | | | | | | | | | | | | 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-1/+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>
* opus: convert to new channel layout APIAnton Khirnov2022-03-151-3/+12
| | | | 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/encode: Always use intermediate buffer in ff_alloc_packet2()Andreas Rheinhardt2021-06-081-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | Up until now, ff_alloc_packet2() has a min_size parameter: It is supposed to be a lower bound on the final size of the packet to allocate. If it is not too far from the upper bound (namely, if it is at least half the upper bound), then ff_alloc_packet2() already allocates the final, already refcounted packet; if it is not, then the packet is not refcounted and its data only points to a buffer owned by the AVCodecContext (in this case, the packet will be made refcounted in encode_simple_internal() in libavcodec/encode.c). The goal of this was to avoid data copies and intermediate buffers if one has a precise lower bound. Yet those encoders for which precise lower bounds exist have recently been switched to ff_get_encode_buffer() (which automatically allocates final buffers), leaving only two encoders to actually set the min_size to something else than zero (namely aliaspixenc and hapenc). Both of these encoders use a very low lower bound that is not helpful in any nontrivial case. This commit therefore removes the min_size parameter as well as the codepath in ff_alloc_packet2() for the allocation of final buffers. Furthermore, the function has been renamed to ff_alloc_packet() and moved to encode.h alongside ff_get_encode_buffer(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: Remove redundant freeing of extradata of encodersAndreas Rheinhardt2021-04-281-1/+0
| | | | | | | | AVCodecContext.extradata is freed generically by libavcodec for encoders, so it is unnecessary for an encoder to do it on its own. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: Constify AVCodecsAndreas Rheinhardt2021-04-271-1/+1
| | | | | | | | | | Given that the AVCodec.next pointer has now been removed, most of the AVCodecs are not modified at all any more and can therefore be made const (as this patch does); the only exceptions are the very few codecs for external libraries that have a init_static_data callback. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* lavu/mem: move the DECLARE_ALIGNED macro family to mem_internal on next+1 bumpAnton Khirnov2021-01-011-0/+1
| | | | They are not properly namespaced and not intended for public use.
* opusenc: add apply_phase_inv optionLynne2020-05-261-1/+2
| | | | | By popular request. Does the same as in libopusenc.
* opusenc: fix infinite loop if flushing encoder upon initRostislav Pehlivanov2018-12-121-1/+1
| | | | | | | | | | The issue is that the afq still has samples as on init it counts the overlap used as a delay to adjust the PTS it generates, hence we can't rely on it right after init. So just check to see if any frames have been encoded. frame_number can't be anything but 0 right after init and can only be set by lavc. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* opusenc: use for loops with declarationsRostislav Pehlivanov2018-05-181-54/+44
| | | | Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* opus: merge encoder and decoder bitallocation functions into oneRostislav Pehlivanov2017-12-301-332/+5
| | | | | | There's no difference apart from which entropy coding functions get called. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* opus_celt: deduplicate band quantization/dequantization functionRostislav Pehlivanov2017-12-041-99/+11
| | | | | | No point in having the same code twice to do exactly the same thing. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* opusenc: implement a psychoacoustic systemRostislav Pehlivanov2017-09-231-125/+145
| | | | | | | | | | | | | | This commit implements a psychoacoustic system for the native Opus encoder. Its unlike any other psychoacoustic system known since its capable of using a lookahead to make better choices on how to treat the current frame and how many bits to allocate for it (and future frames). Also, whilst the main bulk of the analysis function has to run in a single thread, the per-frame anaylsis functions does not modify the main psychoacoustic context, so in the future it will be fairly trivial to run those as slice threads. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* opus: simplify coarse energy beta coefficientsRostislav Pehlivanov2017-07-181-2/+2
| | | | | | Just put the subtraction in the table. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* opusenc: remove unused variableRostislav Pehlivanov2017-07-181-1/+1
| | | | Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* opusenc: use float_dsp for non-transient windowingRostislav Pehlivanov2017-07-141-12/+12
| | | | | | Also fixes transient windowing Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* opusenc: use float_dsp for transient mdctsRostislav Pehlivanov2017-07-131-5/+3
| | | | | | vector_fmul_reverse requires padding the window at the front Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* opusenc: don't set avctx->cutoffRostislav Pehlivanov2017-07-101-2/+0
| | | | | | | Its only use is to adjust the aac psychoacoustic/filter system which isn't used here. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* opus_pvq: port to allow for SIMD functionsRostislav Pehlivanov2017-05-161-3/+9
| | | | Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* opusenc: initialize PVQ prng seedRostislav Pehlivanov2017-05-161-1/+3
| | | | | | | Fixes valgrind warnings, didn't affect anything since it was only used for resynthesis. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* opusenc: switch between intra/inter mode for coarse energyRostislav Pehlivanov2017-04-081-8/+28
| | | | | | Saves around 5kbps. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* opusenc: do not signal digital silenceRostislav Pehlivanov2017-04-081-9/+3
| | | | | | Apparently its only use is to enable comfort noise/error recovery. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* opusenc: minor style changesRostislav Pehlivanov2017-04-081-18/+14
| | | | Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* opusenc: remove unused header entries and simplify normalizationRostislav Pehlivanov2017-04-081-11/+7
| | | | Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* libavcodec/opusenc: use correct format specifiersKyle Swanson2017-03-271-1/+1
| | | | | | | | | | | | | Squelches the following compiler warnings: libavcodec/opusenc.c:1051:16: warning: format specifies type 'long' but the argument has type 'long long' [-Wformat] avctx->bit_rate/1000, clipped_rate/1000); ^~~~~~~~~~~~~~~~~~~~ libavcodec/opusenc.c:1051:38: warning: format specifies type 'long' but the argument has type 'long long' [-Wformat] avctx->bit_rate/1000, clipped_rate/1000); ^~~~~~~~~~~~~~~~~
* opusenc: initialize the emphasis coefficients on initRostislav Pehlivanov2017-02-181-0/+3
| | | | Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* avcodec/opusenc: Add () protecting macro argumentsMichael Niedermayer2017-02-161-2/+2
| | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* opusenc: fix coarse energy quantization with 2 bits leftRostislav Pehlivanov2017-02-151-1/+1
| | | | | | Fixes CID1400584 Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* opus: add a native Opus encoderRostislav Pehlivanov2017-02-141-0/+1130
This marks the first time anyone has written an Opus encoder without using any libopus code. The aim of the encoder is to prove how far the format can go by writing the craziest encoder for it. Right now the encoder's basic, it only supports CBR encoding, however internally every single feature the CELT layer has is implemented (except the pitch pre-filter which needs to work well with the rest of whatever gets implemented). Psychoacoustic and rate control systems are under development. The encoder takes in frames of 120 samples and depending on the value of opus_delay the plan is to use the extra buffered frames as lookahead. Right now the encoder will pick the nearest largest legal frame size and won't use the lookahead, but that'll change once there's a psychoacoustic system. Even though its a pretty basic encoder its already outperforming any other native encoder FFmpeg has by a huge amount. The PVQ search algorithm is faster and more accurate than libopus's algorithm so the encoder's performance is close to that of libopus at zero complexity (libopus has more SIMD). The algorithm might be ported to libopus or other codecs using PVQ in the future. The encoder still has a few minor bugs, like desyncs at ultra low bitrates (below 9kbps with 20ms frames). Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>