X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Finternal.h;h=60f65d3f2cd693fcbfe5375a3fb9f423074b3c78;hb=29f5c1e51b0d156f4650b96ab56c07727fe9a9b7;hp=0c2133f0925b3ec3e0dc3c70099de85a8b681195;hpb=03210fe138f3b3bd7f5272fe29aca810cf517329;p=ffmpeg diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 0c2133f0925..60f65d3f2cd 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -28,6 +28,7 @@ #include "libavutil/buffer.h" #include "libavutil/channel_layout.h" +#include "libavutil/fifo.h" #include "libavutil/mathematics.h" #include "libavutil/pixfmt.h" #include "avcodec.h" @@ -68,6 +69,21 @@ * Codec initializes slice-based threading with a main function */ #define FF_CODEC_CAP_SLICE_THREAD_HAS_MF (1 << 5) +/* + * The codec supports frame threading and has inter-frame dependencies, so it + * uses ff_thread_report/await_progress(). + */ +#define FF_CODEC_CAP_ALLOCATE_PROGRESS (1 << 6) +/** + * Codec handles avctx->thread_count == 0 (auto) internally. + */ +#define FF_CODEC_CAP_AUTO_THREADS (1 << 7) + +/** + * AVCodec.codec_tags termination value + */ +#define FF_CODEC_TAGS_END -1 + #ifdef TRACE # define ff_tlog(ctx, ...) av_log(ctx, AV_LOG_TRACE, __VA_ARGS__) @@ -83,7 +99,7 @@ #define FF_QSCALE_TYPE_H264 2 #define FF_QSCALE_TYPE_VP56 3 -#define FF_SANE_NB_CHANNELS 256U +#define FF_SANE_NB_CHANNELS 512U #define FF_SIGNBIT(x) ((x) >> CHAR_BIT * sizeof(x) - 1) @@ -97,34 +113,13 @@ # define STRIDE_ALIGN 8 #endif -typedef struct FramePool { - /** - * Pools for each data plane. For audio all the planes have the same size, - * so only pools[0] is used. - */ - AVBufferPool *pools[4]; - - /* - * Pool parameters - */ - int format; - int width, height; - int stride_align[AV_NUM_DATA_POINTERS]; - int linesize[4]; - int planes; - int channels; - int samples; -} FramePool; - typedef struct DecodeSimpleContext { AVPacket *in_pkt; - AVFrame *out_frame; } DecodeSimpleContext; -typedef struct DecodeFilterContext { - AVBSFContext **bsfs; - int nb_bsfs; -} DecodeFilterContext; +typedef struct EncodeSimpleContext { + AVFrame *in_frame; +} EncodeSimpleContext; typedef struct AVCodecInternal { /** @@ -135,41 +130,25 @@ typedef struct AVCodecInternal { */ int is_copy; - /** - * Whether to allocate progress for frame threading. - * - * The codec must set it to 1 if it uses ff_thread_await/report_progress(), - * then progress will be allocated in ff_thread_get_buffer(). The frames - * then MUST be freed with ff_thread_release_buffer(). - * - * If the codec does not need to call the progress functions (there are no - * dependencies between the frames), it should leave this at 0. Then it can - * decode straight to the user-provided frames (which the user will then - * free with av_frame_unref()), there is no need to call - * ff_thread_release_buffer(). - */ - int allocate_progress; - /** * An audio frame with less than required samples has been submitted and * padded with silence. Reject all subsequent frames. */ int last_audio_frame; - AVFrame *to_free; - - FramePool *pool; + AVBufferRef *pool; void *thread_ctx; DecodeSimpleContext ds; - DecodeFilterContext filter; + AVBSFContext *bsf; /** * Properties (timestamps+side data) extracted from the last packet passed * for decoding. */ AVPacket *last_pkt_props; + AVFifoBuffer *pkt_props; /** * temporary buffer used for encoders to store their bitstream @@ -179,6 +158,14 @@ typedef struct AVCodecInternal { void *frame_thread_encoder; + EncodeSimpleContext es; + + /** + * If this is set, then AVCodec->close (if existing) needs to be called + * for the parent AVCodecContext. + */ + int needs_close; + /** * Number of audio samples to skip at the start of the next decoded frame */ @@ -198,19 +185,8 @@ typedef struct AVCodecInternal { * buffers for using new encode/decode API through legacy API */ AVPacket *buffer_pkt; - int buffer_pkt_valid; // encoding: packet without data can be valid AVFrame *buffer_frame; int draining_done; - /* set to 1 when the caller is using the old decoding API */ - int compat_decode; - int compat_decode_warned; - /* this variable is set by the decoder internals to signal to the old - * API compat wrappers the amount of data consumed from the last packet */ - size_t compat_decode_consumed; - /* when a partial packet has been consumed, this stores the remaining size - * of the packet (that should be submitted in the next decode call */ - size_t compat_decode_partial_size; - AVFrame *compat_decode_frame; int showed_multi_packet_warning; @@ -218,6 +194,14 @@ typedef struct AVCodecInternal { /* to prevent infinite loop on errors when draining */ int nb_draining_errors; + + /* 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; + int initial_channels; + uint64_t initial_channel_layout; } AVCodecInternal; struct AVCodecDefault { @@ -272,8 +256,6 @@ void ff_color_frame(AVFrame *frame, const int color[4]); */ int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size); -attribute_deprecated int ff_alloc_packet(AVPacket *avpkt, int size); - /** * Rescale from sample rate to AVCodecContext.time_base. */ @@ -312,28 +294,17 @@ static av_always_inline float ff_exp2fi(int x) { */ int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags); +#define FF_REGET_BUFFER_FLAG_READONLY 1 ///< the returned buffer does not need to be writable /** - * Identical in function to av_frame_make_writable(), except it uses - * ff_get_buffer() to allocate the buffer when needed. + * Identical in function to ff_get_buffer(), except it reuses the existing buffer + * if available. */ -int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame); +int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags); int ff_thread_can_start_frame(AVCodecContext *avctx); int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx); -/** - * Call avcodec_open2 recursively by decrementing counter, unlocking mutex, - * calling the function and then restoring again. Assumes the mutex is - * already locked - */ -int ff_codec_open2_recursive(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options); - -/** - * Finalize buf into extradata and set its size appropriately. - */ -int avpriv_bprint_to_extradata(AVCodecContext *avctx, struct AVBPrint *buf); - const uint8_t *avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state); @@ -371,31 +342,25 @@ int ff_side_data_update_matrix_encoding(AVFrame *frame, */ int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt); -/** - * Set various frame properties from the codec context / packet data. - */ -int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame); - /** * Add a CPB properties side data to an encoding context. */ AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx); -int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type); - /** - * Check AVFrame for A53 side data and allocate and fill SEI message with A53 info + * Check AVFrame for S12M timecode side data and allocate and fill TC SEI message with timecode info * - * @param frame Raw frame to get A53 side data from + * @param frame Raw frame to get S12M timecode side data from + * @param rate The frame rate * @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 A53 info. + * 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 */ -int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len, +int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_len, void **data, size_t *sei_size); /** @@ -404,6 +369,20 @@ int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len, */ int64_t ff_guess_coded_bitrate(AVCodecContext *avctx); +/** + * Check if a value is in the list. If not, return the default value + * + * @param ctx Context for the log msg + * @param val_name Name of the checked value, for log msg + * @param array_valid_values Array of valid int, ended with INT_MAX + * @param default_value Value return if checked value is not in the array + * @return Value or default_value. + */ +int ff_int_from_list_or_default(void *ctx, const char * val_name, int val, + const int * array_valid_values, int default_value); + +void ff_dvdsub_parse_palette(uint32_t *palette, const char *p); + #if defined(_WIN32) && CONFIG_SHARED && !defined(BUILDING_avcodec) # define av_export_avcodec __declspec(dllimport) #else