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
|
|
|
/*
|
|
|
|
* generic decoding-related code
|
|
|
|
*
|
2017-04-23 01:08:42 +02:00
|
|
|
* This file is part of FFmpeg.
|
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
|
|
|
*
|
2017-04-23 01:08:42 +02:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
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
|
|
|
* 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.
|
|
|
|
*
|
2017-04-23 01:08:42 +02:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
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
|
|
|
* 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
|
2017-04-23 01:08:42 +02:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
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
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef AVCODEC_DECODE_H
|
|
|
|
#define AVCODEC_DECODE_H
|
|
|
|
|
2017-07-01 12:09:58 +02:00
|
|
|
#include "libavutil/frame.h"
|
2017-10-19 16:38:20 +02:00
|
|
|
#include "libavutil/hwcontext.h"
|
2017-07-01 11:12:44 +02:00
|
|
|
|
2016-12-14 15:05:16 +02:00
|
|
|
#include "avcodec.h"
|
|
|
|
|
2017-10-13 18:59:17 +02:00
|
|
|
/**
|
|
|
|
* This struct stores per-frame lavc-internal data and is attached to it via
|
|
|
|
* private_ref.
|
|
|
|
*/
|
|
|
|
typedef struct FrameDecodeData {
|
2017-11-10 17:07:44 +02:00
|
|
|
/**
|
|
|
|
* The callback to perform some delayed processing on the frame right
|
|
|
|
* before it is returned to the caller.
|
|
|
|
*
|
|
|
|
* @note This code is called at some unspecified point after the frame is
|
|
|
|
* returned from the decoder's decode/receive_frame call. Therefore it cannot rely
|
|
|
|
* on AVCodecContext being in any specific state, so it does not get to
|
|
|
|
* access AVCodecContext directly at all. All the state it needs must be
|
|
|
|
* stored in the post_process_opaque object.
|
|
|
|
*/
|
|
|
|
int (*post_process)(void *logctx, AVFrame *frame);
|
|
|
|
void *post_process_opaque;
|
|
|
|
void (*post_process_opaque_free)(void *opaque);
|
2017-10-13 18:59:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Per-frame private data for hwaccels.
|
|
|
|
*/
|
|
|
|
void *hwaccel_priv;
|
|
|
|
void (*hwaccel_priv_free)(void *priv);
|
2017-10-13 18:59:17 +02:00
|
|
|
} FrameDecodeData;
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Called by decoders to get the next packet for decoding.
|
|
|
|
*
|
|
|
|
* @param pkt An empty packet to be filled with data.
|
|
|
|
* @return 0 if a new reference has been successfully written to pkt
|
|
|
|
* AVERROR(EAGAIN) if no data is currently available
|
|
|
|
* AVERROR_EOF if and end of stream has been reached, so no more data
|
|
|
|
* will be available
|
|
|
|
*/
|
|
|
|
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt);
|
|
|
|
|
2022-12-08 15:05:26 +02:00
|
|
|
/**
|
|
|
|
* Set various frame properties from the provided packet.
|
|
|
|
*/
|
2023-01-31 12:07:50 +02:00
|
|
|
int ff_decode_frame_props_from_pkt(const AVCodecContext *avctx,
|
|
|
|
AVFrame *frame, const AVPacket *pkt);
|
2022-12-08 15:05:26 +02:00
|
|
|
|
2020-08-16 16:43:48 +02:00
|
|
|
/**
|
|
|
|
* Set various frame properties from the codec context / packet data.
|
|
|
|
*/
|
|
|
|
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame);
|
|
|
|
|
2017-10-19 16:38:20 +02:00
|
|
|
/**
|
|
|
|
* Make sure avctx.hw_frames_ctx is set. If it's not set, the function will
|
|
|
|
* try to allocate it from hw_device_ctx. If that is not possible, an error
|
|
|
|
* message is printed, and an error code is returned.
|
|
|
|
*/
|
|
|
|
int ff_decode_get_hw_frames_ctx(AVCodecContext *avctx,
|
|
|
|
enum AVHWDeviceType dev_type);
|
|
|
|
|
2017-10-13 18:59:17 +02:00
|
|
|
int ff_attach_decode_data(AVFrame *frame);
|
|
|
|
|
2021-03-17 23:43:32 +02:00
|
|
|
/**
|
|
|
|
* Check whether the side-data of src contains a palette of
|
|
|
|
* size AVPALETTE_SIZE; if so, copy it to dst and return 1;
|
|
|
|
* else return 0.
|
|
|
|
* Also emit an error message upon encountering a palette
|
|
|
|
* with invalid size.
|
|
|
|
*/
|
|
|
|
int ff_copy_palette(void *dst, const AVPacket *src, void *logctx);
|
|
|
|
|
2022-08-24 22:03:27 +02:00
|
|
|
/**
|
|
|
|
* Check that the provided frame dimensions are valid and set them on the codec
|
|
|
|
* context.
|
|
|
|
*/
|
|
|
|
int ff_set_dimensions(AVCodecContext *s, int width, int height);
|
|
|
|
|
2022-08-24 21:43:37 +02:00
|
|
|
/**
|
|
|
|
* Check that the provided sample aspect ratio is valid and set it on the codec
|
|
|
|
* context.
|
|
|
|
*/
|
|
|
|
int ff_set_sar(AVCodecContext *avctx, AVRational sar);
|
|
|
|
|
2022-08-24 19:54:25 +02:00
|
|
|
/**
|
|
|
|
* Select the (possibly hardware accelerated) pixel format.
|
|
|
|
* This is a wrapper around AVCodecContext.get_format() and should be used
|
|
|
|
* instead of calling get_format() directly.
|
|
|
|
*
|
|
|
|
* The list of pixel formats must contain at least one valid entry, and is
|
|
|
|
* terminated with AV_PIX_FMT_NONE. If it is possible to decode to software,
|
|
|
|
* the last entry in the list must be the most accurate software format.
|
|
|
|
* If it is not possible to decode to software, AVCodecContext.sw_pix_fmt
|
|
|
|
* must be set before calling this function.
|
|
|
|
*/
|
|
|
|
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt);
|
|
|
|
|
2022-08-24 21:28:16 +02:00
|
|
|
/**
|
|
|
|
* Get a buffer for a frame. This is a wrapper around
|
|
|
|
* AVCodecContext.get_buffer() and should be used instead calling get_buffer()
|
|
|
|
* directly.
|
|
|
|
*/
|
|
|
|
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags);
|
|
|
|
|
2022-08-24 20:49:25 +02:00
|
|
|
#define FF_REGET_BUFFER_FLAG_READONLY 1 ///< the returned buffer does not need to be writable
|
|
|
|
/**
|
|
|
|
* Identical in function to ff_get_buffer(), except it reuses the existing buffer
|
|
|
|
* if available.
|
|
|
|
*/
|
|
|
|
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags);
|
|
|
|
|
2022-08-25 02:00:21 +02:00
|
|
|
/**
|
|
|
|
* Add or update AV_FRAME_DATA_MATRIXENCODING side data.
|
|
|
|
*/
|
|
|
|
int ff_side_data_update_matrix_encoding(AVFrame *frame,
|
|
|
|
enum AVMatrixEncoding matrix_encoding);
|
|
|
|
|
2022-03-10 19:03:05 +02:00
|
|
|
/**
|
2023-08-01 21:02:13 +02:00
|
|
|
* Allocate a hwaccel frame private data if the provided avctx
|
2022-08-04 16:21:03 +02:00
|
|
|
* uses a hwaccel method that needs it. The returned data is
|
|
|
|
* a RefStruct reference (if allocated).
|
2022-03-10 19:03:05 +02:00
|
|
|
*
|
2023-08-01 21:02:13 +02:00
|
|
|
* @param avctx The codec context
|
|
|
|
* @param hwaccel_picture_private Pointer to return hwaccel_picture_private
|
|
|
|
* @return 0 on success, < 0 on error
|
2022-03-10 19:03:05 +02:00
|
|
|
*/
|
2022-08-04 16:21:03 +02:00
|
|
|
int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private);
|
2022-03-10 19:03:05 +02:00
|
|
|
|
2023-07-17 22:55:30 +02:00
|
|
|
/**
|
|
|
|
* Get side data of the given type from a decoding context.
|
|
|
|
*/
|
|
|
|
const AVPacketSideData *ff_get_coded_side_data(const AVCodecContext *avctx,
|
|
|
|
enum AVPacketSideDataType type);
|
|
|
|
|
2024-02-17 22:35:25 +02:00
|
|
|
/**
|
|
|
|
* Wrapper around av_frame_new_side_data, which rejects side data overridden by
|
|
|
|
* the demuxer. Returns 0 on success, and a negative error code otherwise.
|
|
|
|
* If successful and sd is not NULL, *sd may either contain a pointer to the new
|
|
|
|
* side data, or NULL in case the side data was already present.
|
|
|
|
*/
|
|
|
|
int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame,
|
|
|
|
enum AVFrameSideDataType type, size_t size,
|
|
|
|
AVFrameSideData **sd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Similar to `ff_frame_new_side_data`, but using an existing buffer ref.
|
|
|
|
*
|
|
|
|
* *buf is ALWAYS consumed by this function and NULL written in its place, even
|
|
|
|
* on failure.
|
|
|
|
*/
|
|
|
|
int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx,
|
|
|
|
AVFrame *frame, enum AVFrameSideDataType type,
|
|
|
|
AVBufferRef **buf, AVFrameSideData **sd);
|
|
|
|
|
2024-02-23 11:12:46 +02:00
|
|
|
struct AVMasteringDisplayMetadata;
|
|
|
|
struct AVContentLightMetadata;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper around av_mastering_display_metadata_create_side_data(), which
|
|
|
|
* rejects side data overridden by the demuxer. Returns 0 on success, and a
|
|
|
|
* negative error code otherwise. If successful, *mdm may either be a pointer to
|
|
|
|
* the new side data, or NULL in case the side data was already present.
|
|
|
|
*/
|
|
|
|
int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame,
|
|
|
|
struct AVMasteringDisplayMetadata **mdm);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper around av_content_light_metadata_create_side_data(), which
|
|
|
|
* rejects side data overridden by the demuxer. Returns 0 on success, and a
|
|
|
|
* negative error code otherwise. If successful, *clm may either be a pointer to
|
|
|
|
* the new side data, or NULL in case the side data was already present.
|
|
|
|
*/
|
|
|
|
int ff_decode_content_light_new(const AVCodecContext *avctx, AVFrame *frame,
|
|
|
|
struct AVContentLightMetadata **clm);
|
|
|
|
|
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
|
|
|
#endif /* AVCODEC_DECODE_H */
|