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 11:12:44 +02:00
|
|
|
#include "libavutil/buffer.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;
|
|
|
|
|
2022-07-16 16:36:23 +02:00
|
|
|
/**
|
|
|
|
* avcodec_receive_frame() implementation for decoders.
|
|
|
|
*/
|
|
|
|
int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame);
|
|
|
|
|
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);
|
|
|
|
|
2021-03-09 12:35:47 +02:00
|
|
|
/**
|
|
|
|
* Perform decoder initialization and validation.
|
2022-03-16 22:09:54 +02:00
|
|
|
* Called when opening the decoder, before the FFCodec.init() call.
|
2021-03-09 12:35:47 +02:00
|
|
|
*/
|
|
|
|
int ff_decode_preinit(AVCodecContext *avctx);
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Allocate a hwaccel frame private data and create an AVBufferRef
|
|
|
|
* from it.
|
|
|
|
*
|
|
|
|
* @param avctx The codec context which to attach as an opaque value
|
|
|
|
* @param hwaccel The hwaccel for which to allocate
|
|
|
|
* @return The allocated buffer
|
|
|
|
*/
|
|
|
|
AVBufferRef *ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx,
|
|
|
|
const AVHWAccel *hwaccel);
|
|
|
|
|
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 */
|