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 11:59:15 +00:00
|
|
|
/*
|
|
|
|
* generic decoding-related code
|
|
|
|
*
|
2017-04-22 23:08:42 +00: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 11:59:15 +00:00
|
|
|
*
|
2017-04-22 23:08:42 +00: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 11:59:15 +00: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-22 23:08:42 +00: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 11:59:15 +00: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-22 23:08:42 +00: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 11:59:15 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef AVCODEC_DECODE_H
|
|
|
|
#define AVCODEC_DECODE_H
|
|
|
|
|
2017-07-01 09:12:44 +00:00
|
|
|
#include "libavutil/buffer.h"
|
2017-07-01 10:09:58 +00:00
|
|
|
#include "libavutil/frame.h"
|
2017-10-19 14:38:20 +00:00
|
|
|
#include "libavutil/hwcontext.h"
|
2017-07-01 09:12:44 +00:00
|
|
|
|
2016-12-14 13:05:16 +00:00
|
|
|
#include "avcodec.h"
|
|
|
|
|
2017-10-13 16:59:17 +00:00
|
|
|
/**
|
|
|
|
* This struct stores per-frame lavc-internal data and is attached to it via
|
|
|
|
* private_ref.
|
|
|
|
*/
|
|
|
|
typedef struct FrameDecodeData {
|
2017-11-10 15:07:44 +00: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 16:59:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Per-frame private data for hwaccels.
|
|
|
|
*/
|
|
|
|
void *hwaccel_priv;
|
|
|
|
void (*hwaccel_priv_free)(void *priv);
|
2017-10-13 16:59:17 +00:00
|
|
|
} FrameDecodeData;
|
|
|
|
|
2022-07-16 14:36:23 +00: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 11:59:15 +00: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 13:05:26 +00:00
|
|
|
/**
|
|
|
|
* Set various frame properties from the provided packet.
|
|
|
|
*/
|
2023-01-31 10:07:50 +00:00
|
|
|
int ff_decode_frame_props_from_pkt(const AVCodecContext *avctx,
|
|
|
|
AVFrame *frame, const AVPacket *pkt);
|
2022-12-08 13:05:26 +00:00
|
|
|
|
2020-08-16 14:43:48 +00:00
|
|
|
/**
|
|
|
|
* Set various frame properties from the codec context / packet data.
|
|
|
|
*/
|
|
|
|
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame);
|
|
|
|
|
2017-10-19 14:38:20 +00: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 16:59:17 +00:00
|
|
|
int ff_attach_decode_data(AVFrame *frame);
|
|
|
|
|
2021-03-17 21:43:32 +00: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 10:35:47 +00:00
|
|
|
/**
|
|
|
|
* Perform decoder initialization and validation.
|
2022-03-16 20:09:54 +00:00
|
|
|
* Called when opening the decoder, before the FFCodec.init() call.
|
2021-03-09 10:35:47 +00:00
|
|
|
*/
|
|
|
|
int ff_decode_preinit(AVCodecContext *avctx);
|
|
|
|
|
2022-08-24 20:03:27 +00: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 19:43:37 +00: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 17:54:25 +00: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 19:28:16 +00: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 18:49:25 +00: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 00:00:21 +00: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 17:03:05 +00: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 11:59:15 +00:00
|
|
|
#endif /* AVCODEC_DECODE_H */
|