2008-12-08 23:21:38 +02:00
|
|
|
/*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 17:45:34 +03:00
|
|
|
* @file
|
2008-12-08 23:21:38 +02:00
|
|
|
* common internal api header.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef AVCODEC_INTERNAL_H
|
|
|
|
#define AVCODEC_INTERNAL_H
|
|
|
|
|
2009-02-24 21:04:43 +02:00
|
|
|
#include <stdint.h>
|
2011-11-15 23:34:50 +03:00
|
|
|
|
2013-12-11 05:03:29 +03:00
|
|
|
#include "libavutil/channel_layout.h"
|
2009-02-24 21:04:43 +02:00
|
|
|
#include "avcodec.h"
|
2013-03-25 15:11:41 +03:00
|
|
|
#include "config.h"
|
2009-02-24 21:04:43 +02:00
|
|
|
|
2022-06-28 15:13:04 +02:00
|
|
|
#if CONFIG_LCMS2
|
|
|
|
# include "fflcms2.h"
|
|
|
|
#endif
|
|
|
|
|
2019-08-20 16:52:08 +02:00
|
|
|
#define FF_SANE_NB_CHANNELS 512U
|
2012-10-22 20:40:10 +03:00
|
|
|
|
2017-11-06 16:43:39 +02:00
|
|
|
#if HAVE_SIMD_ALIGN_64
|
|
|
|
# define STRIDE_ALIGN 64 /* AVX-512 */
|
|
|
|
#elif HAVE_SIMD_ALIGN_32
|
2014-05-19 03:59:57 +03:00
|
|
|
# define STRIDE_ALIGN 32
|
2014-07-22 23:32:40 +03:00
|
|
|
#elif HAVE_SIMD_ALIGN_16
|
2014-03-15 16:47:04 +03:00
|
|
|
# define STRIDE_ALIGN 16
|
|
|
|
#else
|
|
|
|
# define STRIDE_ALIGN 8
|
|
|
|
#endif
|
|
|
|
|
2012-11-21 23:34:46 +03:00
|
|
|
typedef struct AVCodecInternal {
|
2011-11-15 23:34:50 +03:00
|
|
|
/**
|
2021-09-24 18:06:28 +02:00
|
|
|
* When using frame-threaded decoding, this field is set for the first
|
|
|
|
* worker thread (e.g. to decode extradata just once).
|
2011-11-15 23:34:50 +03:00
|
|
|
*/
|
|
|
|
int is_copy;
|
2011-12-18 21:20:15 +03:00
|
|
|
|
2022-09-15 19:20:11 +02:00
|
|
|
/**
|
|
|
|
* Audio encoders can set this flag during init to indicate that they
|
|
|
|
* want the small last frame to be padded to a multiple of pad_samples.
|
|
|
|
*/
|
|
|
|
int pad_samples;
|
|
|
|
|
2022-08-04 15:57:41 +02:00
|
|
|
struct FramePool *pool;
|
2012-12-05 18:25:03 +03:00
|
|
|
|
2013-10-27 15:00:37 +03:00
|
|
|
void *thread_ctx;
|
2013-11-04 13:14:38 +03:00
|
|
|
|
2021-09-23 22:34:39 +02:00
|
|
|
/**
|
|
|
|
* This packet is used to hold the packet given to decoders
|
|
|
|
* implementing the .decode API; it is unused by the generic
|
|
|
|
* code for decoders implementing the .receive_frame API and
|
|
|
|
* may be freely used (but not freed) by them with the caveat
|
|
|
|
* that the packet will be unreferenced generically in
|
|
|
|
* avcodec_flush_buffers().
|
|
|
|
*/
|
|
|
|
AVPacket *in_pkt;
|
2022-05-09 22:30:11 +02:00
|
|
|
struct AVBSFContext *bsf;
|
decode: restructure the core decoding code
Currently, the new decoding API is pretty much just a wrapper around the
old deprecated one. This is problematic, since it interferes with making
full use of the flexibility added by the new API. The old API should
also be removed at some future point.
Reorganize the code so that the new send_packet/receive_frame functions
call the actual decoding directly and change the old deprecated
avcodec_decode_* functions into wrappers around the new API.
The new internal API for decoders is now changing as well. Before this
commit, it mirrors the public API, so the decoders need to implement
send_packet() and receive_frame() callbacks. This turns out to require
awkward constructs in both the decoders and the generic code. After this
commit, the decoders only implement the receive_frame() callback and
call a new internal function, ff_decode_get_packet() to obtain input
data, in the same manner to how the bitstream filters now work.
avcodec will now always make a reference to the input packet, which means
that non-refcounted input packets will be copied. Keeping the previous
behaviour, where this copy could sometimes be avoided, would make the
code significantly more complex and fragile for only dubious gains,
since packets are typically small and everyone who cares about
performance should use refcounted packets anyway.
2016-10-26 13:59:15 +02:00
|
|
|
|
2013-10-27 15:12:53 +03:00
|
|
|
/**
|
2016-10-26 13:41:12 +02:00
|
|
|
* Properties (timestamps+side data) extracted from the last packet passed
|
|
|
|
* for decoding.
|
2013-10-27 15:12:53 +03:00
|
|
|
*/
|
2016-10-26 13:41:12 +02:00
|
|
|
AVPacket *last_pkt_props;
|
2013-11-04 13:41:55 +03:00
|
|
|
|
2012-03-22 20:07:57 +03:00
|
|
|
/**
|
|
|
|
* temporary buffer used for encoders to store their bitstream
|
|
|
|
*/
|
|
|
|
uint8_t *byte_buffer;
|
|
|
|
unsigned int byte_buffer_size;
|
2012-06-14 22:19:02 +03:00
|
|
|
|
|
|
|
void *frame_thread_encoder;
|
2012-07-04 23:03:13 +03:00
|
|
|
|
2022-04-11 10:37:24 +02:00
|
|
|
/**
|
|
|
|
* The input frame is stored here for encoders implementing the simple
|
|
|
|
* encode API.
|
|
|
|
*
|
|
|
|
* Not allocated in other cases.
|
|
|
|
*/
|
|
|
|
AVFrame *in_frame;
|
2020-06-09 23:31:32 +02:00
|
|
|
|
2022-07-16 16:36:23 +02:00
|
|
|
/**
|
|
|
|
* When the AV_CODEC_FLAG_RECON_FRAME flag is used. the encoder should store
|
|
|
|
* here the reconstructed frame corresponding to the last returned packet.
|
|
|
|
*
|
|
|
|
* Not allocated in other cases.
|
|
|
|
*/
|
|
|
|
AVFrame *recon_frame;
|
|
|
|
|
2021-04-18 07:01:22 +02:00
|
|
|
/**
|
2022-03-16 22:09:54 +02:00
|
|
|
* If this is set, then FFCodec->close (if existing) needs to be called
|
2021-04-18 07:01:22 +02:00
|
|
|
* for the parent AVCodecContext.
|
|
|
|
*/
|
|
|
|
int needs_close;
|
|
|
|
|
2012-07-04 23:03:13 +03:00
|
|
|
/**
|
|
|
|
* Number of audio samples to skip at the start of the next decoded frame
|
|
|
|
*/
|
|
|
|
int skip_samples;
|
2014-05-12 01:21:44 +03:00
|
|
|
|
2014-03-06 20:37:42 +03:00
|
|
|
/**
|
|
|
|
* hwaccel-specific private data
|
|
|
|
*/
|
|
|
|
void *hwaccel_priv_data;
|
2016-03-22 20:09:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* checks API usage: after codec draining, flush is required to resume operation
|
|
|
|
*/
|
|
|
|
int draining;
|
|
|
|
|
|
|
|
/**
|
2022-08-24 03:19:05 +02:00
|
|
|
* Temporary buffers for newly received or not yet output packets/frames.
|
2016-03-22 20:09:53 +02:00
|
|
|
*/
|
|
|
|
AVPacket *buffer_pkt;
|
|
|
|
AVFrame *buffer_frame;
|
|
|
|
int draining_done;
|
2021-01-25 13:03:44 +02:00
|
|
|
|
2023-07-09 14:53:46 +02:00
|
|
|
#if FF_API_DROPCHANGED
|
2019-04-14 18:42:25 +02:00
|
|
|
/* used when avctx flag AV_CODEC_FLAG_DROPCHANGED is set */
|
|
|
|
int changed_frames_dropped;
|
|
|
|
int initial_format;
|
|
|
|
int initial_width, initial_height;
|
|
|
|
int initial_sample_rate;
|
2017-04-07 18:08:41 +02:00
|
|
|
AVChannelLayout initial_ch_layout;
|
2023-07-09 14:53:46 +02:00
|
|
|
#endif
|
2022-06-28 15:13:04 +02:00
|
|
|
|
|
|
|
#if CONFIG_LCMS2
|
|
|
|
FFIccContext icc; /* used to read and write embedded ICC profiles */
|
|
|
|
#endif
|
2024-03-17 22:51:29 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set when the user has been warned about a failed allocation from
|
|
|
|
* a fixed frame pool.
|
|
|
|
*/
|
|
|
|
int warned_on_failed_allocation_from_fixed_pool;
|
2011-11-15 23:34:50 +03:00
|
|
|
} AVCodecInternal;
|
|
|
|
|
2010-01-10 06:06:34 +02:00
|
|
|
/**
|
|
|
|
* Return the index into tab at which {a,b} match elements {[0],[1]} of tab.
|
|
|
|
* If there is no such matching pair then size is returned.
|
|
|
|
*/
|
2010-01-10 06:04:51 +02:00
|
|
|
int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b);
|
|
|
|
|
2021-12-13 20:55:39 +02:00
|
|
|
unsigned int ff_toupper4(unsigned int x);
|
2010-05-18 22:16:40 +03:00
|
|
|
|
2012-07-03 00:16:59 +03:00
|
|
|
int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx);
|
|
|
|
|
2016-04-20 19:19:25 +02:00
|
|
|
int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec);
|
|
|
|
|
2020-06-18 05:58:50 +02:00
|
|
|
/**
|
|
|
|
* Check AVFrame for S12M timecode side data and allocate and fill TC SEI message with timecode info
|
|
|
|
*
|
|
|
|
* @param frame Raw frame to get S12M timecode side data from
|
2020-07-12 16:19:31 +02:00
|
|
|
* @param rate The frame rate
|
2020-06-18 05:58:50 +02:00
|
|
|
* @param prefix_len Number of bytes to allocate before SEI message
|
|
|
|
* @param data Pointer to a variable to store allocated memory
|
|
|
|
* Upon return the variable will hold NULL on error or if frame has no S12M timecode info.
|
|
|
|
* Otherwise it will point to prefix_len uninitialized bytes followed by
|
|
|
|
* *sei_size SEI message
|
|
|
|
* @param sei_size Pointer to a variable to store generated SEI message length
|
|
|
|
* @return Zero on success, negative error code on failure
|
|
|
|
*/
|
2020-07-12 16:19:31 +02:00
|
|
|
int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_len,
|
2020-06-18 05:58:50 +02:00
|
|
|
void **data, size_t *sei_size);
|
2016-06-04 20:11:52 +02:00
|
|
|
|
2017-03-06 09:53:28 +02:00
|
|
|
/**
|
|
|
|
* Get an estimated video bitrate based on frame size, frame rate and coded
|
|
|
|
* bits per pixel.
|
|
|
|
*/
|
|
|
|
int64_t ff_guess_coded_bitrate(AVCodecContext *avctx);
|
|
|
|
|
2008-12-08 23:21:38 +02:00
|
|
|
#endif /* AVCODEC_INTERNAL_H */
|