Remove AVPacket, more

This commit is contained in:
Henrik Rydgård 2024-04-11 00:29:53 +02:00
parent 08d5de9f4c
commit 7d680c9883
10 changed files with 46 additions and 1472 deletions

View File

@ -627,7 +627,6 @@
<ClCompile Include="..\ext\at3_standalone\atrac3plusdec.c" />
<ClCompile Include="..\ext\at3_standalone\atrac3plusdsp.c" />
<ClCompile Include="..\ext\at3_standalone\avfft.c" />
<ClCompile Include="..\ext\at3_standalone\avpacket.c" />
<ClCompile Include="..\ext\at3_standalone\av_buffer.c" />
<ClCompile Include="..\ext\at3_standalone\bitstream.c" />
<ClCompile Include="..\ext\at3_standalone\channel_layout.c" />

View File

@ -1137,9 +1137,6 @@
<ClCompile Include="..\ext\at3_standalone\atrac.c">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\avpacket.c">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\mathematics.c">
<Filter>ext\at3_standalone</Filter>
</ClCompile>

View File

@ -923,13 +923,8 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
AVCodec ff_atrac3_decoder = {
.name = "atrac3",
.long_name = "ATRAC3 (Adaptive TRansform Acoustic Coding 3)",
.type = AVMEDIA_TYPE_AUDIO,
.id = AV_CODEC_ID_ATRAC3,
.priv_data_size = sizeof(ATRAC3Context),
.init = atrac3_decode_init,
.close = atrac3_decode_close,
.decode = atrac3_decode_frame,
.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
AV_SAMPLE_FMT_NONE },
};

View File

@ -387,12 +387,9 @@ int atrac3p_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_p
AVCodec ff_atrac3p_decoder = {
.name = "atrac3plus",
.long_name = "ATRAC3+ (Adaptive TRansform Acoustic Coding 3+)",
.type = AVMEDIA_TYPE_AUDIO,
.id = AV_CODEC_ID_ATRAC3P,
.capabilities = AV_CODEC_CAP_DR1,
.priv_data_size = sizeof(ATRAC3PContext),
.init = atrac3p_decode_init,
.close = atrac3p_decode_close,
.decode = atrac3p_decode_frame,
};

View File

@ -360,48 +360,6 @@ typedef struct RcOverride{
struct AVBufferRef;
typedef struct AVPacket {
/**
* A reference to the reference-counted buffer where the packet data is
* stored.
* May be NULL, then the packet data is not reference-counted.
*/
AVBufferRef *buf;
/**
* Presentation timestamp in AVStream->time_base units; the time at which
* the decompressed packet will be presented to the user.
* Can be AV_NOPTS_VALUE if it is not stored in the file.
* pts MUST be larger or equal to dts as presentation cannot happen before
* decompression, unless one wants to view hex dumps. Some formats misuse
* the terms dts and pts/cts to mean something different. Such timestamps
* must be converted to true pts/dts before they are stored in AVPacket.
*/
int64_t pts;
/**
* Decompression timestamp in AVStream->time_base units; the time at which
* the packet is decompressed.
* Can be AV_NOPTS_VALUE if it is not stored in the file.
*/
int64_t dts;
uint8_t *data;
int size;
int stream_index;
/**
* A combination of AV_PKT_FLAG values
*/
int flags;
/**
* Duration of this packet in AVStream->time_base units, 0 if unknown.
* Equals next_pts - this_pts in presentation order.
*/
int64_t duration;
int64_t pos; ///< byte position in stream, -1 if unknown
} AVPacket;
#define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe
#define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
/**
* @}
*/
@ -425,7 +383,6 @@ typedef struct AVCodecContext {
const AVClass *av_class;
int log_level_offset;
enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */
const struct AVCodec *codec;
#if FF_API_CODEC_NAME
/**
@ -504,28 +461,6 @@ typedef struct AVCodecContext {
uint8_t *extradata;
int extradata_size;
/**
* This is the fundamental unit of time (in seconds) in terms
* of which frame timestamps are represented. For fixed-fps content,
* timebase should be 1/framerate and timestamp increments should be
* identically 1.
* This often, but not always is the inverse of the frame rate or field rate
* for video.
* - encoding: MUST be set by user.
* - decoding: the use of this field for decoding is deprecated.
* Use framerate instead.
*/
AVRational time_base;
/**
* For some codecs, the time base is closer to the field rate than the frame rate.
* Most notably, H.264 and MPEG-2 specify time_base as half of frame duration
* if no telecine is used ...
*
* Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.
*/
int ticks_per_frame;
/**
* Codec delay.
*
@ -550,104 +485,6 @@ typedef struct AVCodecContext {
*/
int delay;
#if FF_API_ASPECT_EXTENDED
#define FF_ASPECT_EXTENDED 15
#endif
/**
* qscale offset between IP and B-frames
* - encoding: Set by user.
* - decoding: unused
*/
float b_quant_offset;
#if FF_API_PRIVATE_OPT
/** @deprecated use encoder private options instead */
attribute_deprecated
int mpeg_quant;
#endif
/**
* slice count
* - encoding: Set by libavcodec.
* - decoding: Set by user (or 0).
*/
int slice_count;
#if FF_API_PRIVATE_OPT
/** @deprecated use encoder private options instead */
attribute_deprecated
int prediction_method;
#define FF_PRED_LEFT 0
#define FF_PRED_PLANE 1
#define FF_PRED_MEDIAN 2
#endif
/**
* slice offsets in the frame in bytes
* - encoding: Set/allocated by libavcodec.
* - decoding: Set/allocated by user (or NULL).
*/
int *slice_offset;
/**
* custom intra quantization matrix
* - encoding: Set by user, can be NULL.
* - decoding: Set by libavcodec.
*/
uint16_t *intra_matrix;
/**
* custom inter quantization matrix
* - encoding: Set by user, can be NULL.
* - decoding: Set by libavcodec.
*/
uint16_t *inter_matrix;
/**
*
* - encoding: Set by user.
* - decoding: unused
*/
int bidir_refine;
#if FF_API_PRIVATE_OPT
/** @deprecated use encoder private options instead */
attribute_deprecated
int brd_scale;
#endif
/**
* minimum GOP size
* - encoding: Set by user.
* - decoding: unused
*/
int keyint_min;
/**
* number of reference frames
* - encoding: Set by user.
* - decoding: Set by lavc.
*/
int refs;
/**
* Number of slices.
* Indicates number of picture subdivisions. Used for parallelized
* decoding.
* - encoding: Set by user
* - decoding: unused
*/
int slices;
/** Field order
* - encoding: set by libavcodec
* - decoding: Set by user.
*/
enum AVFieldOrder field_order;
/* audio only */
int sample_rate; ///< samples per second
int channels; ///< number of audio channels
@ -702,28 +539,6 @@ typedef struct AVCodecContext {
*/
uint64_t channel_layout;
/**
* Request decoder to use this channel layout if it can (0 for default)
* - encoding: unused
* - decoding: Set by user.
*/
uint64_t request_channel_layout;
/**
* Type of service that the audio stream conveys.
* - encoding: Set by user.
* - decoding: Set by libavcodec.
*/
enum AVAudioServiceType audio_service_type;
/**
* desired sample format
* - encoding: Not used.
* - decoding: Set by user.
* Decoder will decode to this format if it can.
*/
enum AVSampleFormat request_sample_fmt;
/**
* This callback is called at the beginning of each frame to get data
* buffer(s) for it. There may be one contiguous buffer for all the data or
@ -819,37 +634,6 @@ typedef struct AVCodecContext {
*/
int refcounted_frames;
/**
* decoder bitstream buffer size
* - encoding: Set by user.
* - decoding: unused
*/
int rc_buffer_size;
/**
* ratecontrol override, see RcOverride
* - encoding: Allocated/set/freed by user.
* - decoding: unused
*/
int rc_override_count;
RcOverride *rc_override;
/**
* error concealment flags
* - encoding: unused
* - decoding: Set by user.
*/
int error_concealment;
#define FF_EC_GUESS_MVS 1
#define FF_EC_DEBLOCK 2
#define FF_EC_FAVOR_INTER 256
/**
* Error recognition; may misdetect some more or less valid parts as errors.
* - encoding: unused
* - decoding: Set by user.
*/
int err_recognition;
/**
* Verify checksums embedded in the bitstream (could be of either encoded or
@ -909,41 +693,6 @@ typedef struct AVCodecContext {
#endif
#define FF_IDCT_SIMPLEAUTO 128
/**
* bits per sample/pixel from the demuxer (needed for huffyuv).
* - encoding: Set by libavcodec.
* - decoding: Set by user.
*/
int bits_per_coded_sample;
/**
* Bits per sample/pixel of internal libavcodec pixel/sample format.
* - encoding: set by user.
* - decoding: set by libavcodec.
*/
int bits_per_raw_sample;
/**
* noise vs. sse weight for the nsse comparison function
* - encoding: Set by user.
* - decoding: unused
*/
int nsse_weight;
/**
* Skip IDCT/dequantization for selected frames.
* - encoding: unused
* - decoding: Set by user.
*/
enum AVDiscard skip_idct;
/**
* Skip decoding for selected frames.
* - encoding: unused
* - decoding: Set by user.
*/
enum AVDiscard skip_frame;
/**
* Audio only. The number of "priming" samples (padding) inserted by the
@ -961,47 +710,8 @@ typedef struct AVCodecContext {
* -initial_padding.
*/
int initial_padding;
/**
* Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
* Code outside libavcodec should access this field using:
* av_codec_{get,set}_pkt_timebase(avctx)
* - encoding unused.
* - decoding set by user.
*/
AVRational pkt_timebase;
/**
* Number of samples to skip after a discontinuity
* - decoding: unused
* - encoding: set by libavcodec
*/
int seek_preroll;
/*
* Properties of the stream that gets decoded
* To be accessed through av_codec_get_properties() (NO direct access)
* - encoding: unused
* - decoding: set by libavcodec
*/
unsigned properties;
#define FF_CODEC_PROPERTY_LOSSLESS 0x00000001
#define FF_CODEC_PROPERTY_CLOSED_CAPTIONS 0x00000002
} AVCodecContext;
/**
* AVProfile.
*/
typedef struct AVProfile {
int profile;
const char *name; ///< short name for the profile
} AVProfile;
typedef struct AVCodecDefault AVCodecDefault;
struct AVSubtitle;
/**
* AVCodec.
*/
@ -1013,26 +723,14 @@ typedef struct AVCodec {
* This is the primary way to find a codec from the user perspective.
*/
const char *name;
/**
* Descriptive name for the codec, meant to be more human readable than name.
* You should use the NULL_IF_CONFIG_SMALL() macro to define it.
*/
const char *long_name;
enum AVMediaType type;
enum AVCodecID id;
/**
* Codec capabilities.
* see AV_CODEC_CAP_*
*/
int capabilities;
const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
const enum AVPixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
const uint64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
uint8_t max_lowres; ///< maximum value for lowres supported by the decoder, no direct access, use av_codec_get_max_lowres()
const AVClass *priv_class; ///< AVClass for the private context
const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
/*****************************************************************
* No fields below this line are part of the public API. They
@ -1042,31 +740,6 @@ typedef struct AVCodec {
*****************************************************************
*/
int priv_data_size;
struct AVCodec *next;
/**
* @name Frame-level threading support functions
* @{
*/
/**
* If defined, called on thread contexts when they are created.
* If the codec allocates writable tables in init(), re-allocate them here.
* priv_data will be set to a copy of the original.
*/
int (*init_thread_copy)(AVCodecContext *);
/**
* Copy necessary context variables from a previous thread context to the current one.
* If not defined, the next thread will start automatically; otherwise, the codec
* must call ff_thread_finish_setup().
*
* dst and src will (rarely) point to the same context, in which case memcpy should be skipped.
*/
int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src);
/** @} */
/**
* Private codec-specific defaults.
*/
const AVCodecDefault *defaults;
/**
* Initialize codec static data, called from avcodec_register().
@ -1074,8 +747,6 @@ typedef struct AVCodec {
void (*init_static_data)(struct AVCodec *codec);
int (*init)(AVCodecContext *);
int (*encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size,
const struct AVSubtitle *sub);
/**
* Encode data to an AVPacket.
*
@ -1086,9 +757,6 @@ typedef struct AVCodec {
* non-empty packet was returned in avpkt.
* @return 0 on success, negative error code on failure
*/
int (*encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame,
int *got_packet_ptr);
int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);
int (*close)(AVCodecContext *);
/**
* Flush buffers.
@ -1102,259 +770,6 @@ typedef struct AVCodec {
int caps_internal;
} AVCodec;
int av_codec_get_max_lowres(const AVCodec *codec);
struct MpegEncContext;
/**
* @defgroup lavc_hwaccel AVHWAccel
* @{
*/
typedef struct AVHWAccel {
/**
* Name of the hardware accelerated codec.
* The name is globally unique among encoders and among decoders (but an
* encoder and a decoder can share the same name).
*/
const char *name;
/**
* Type of codec implemented by the hardware accelerator.
*
* See AVMEDIA_TYPE_xxx
*/
enum AVMediaType type;
/**
* Codec implemented by the hardware accelerator.
*
* See AV_CODEC_ID_xxx
*/
enum AVCodecID id;
/**
* Supported pixel format.
*
* Only hardware accelerated formats are supported here.
*/
enum AVPixelFormat pix_fmt;
/**
* Hardware accelerated codec capabilities.
* see HWACCEL_CODEC_CAP_*
*/
int capabilities;
/*****************************************************************
* No fields below this line are part of the public API. They
* may not be used outside of libavcodec and can be changed and
* removed at will.
* New public fields should be added right above.
*****************************************************************
*/
struct AVHWAccel *next;
/**
* Allocate a custom buffer
*/
int (*alloc_frame)(AVCodecContext *avctx, AVFrame *frame);
/**
* Called at the beginning of each frame or field picture.
*
* Meaningful frame information (codec specific) is guaranteed to
* be parsed at this point. This function is mandatory.
*
* Note that buf can be NULL along with buf_size set to 0.
* Otherwise, this means the whole frame is available at this point.
*
* @param avctx the codec context
* @param buf the frame data buffer base
* @param buf_size the size of the frame in bytes
* @return zero if successful, a negative value otherwise
*/
int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
/**
* Callback for each slice.
*
* Meaningful slice information (codec specific) is guaranteed to
* be parsed at this point. This function is mandatory.
* The only exception is XvMC, that works on MB level.
*
* @param avctx the codec context
* @param buf the slice data buffer base
* @param buf_size the size of the slice in bytes
* @return zero if successful, a negative value otherwise
*/
int (*decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
/**
* Called at the end of each frame or field picture.
*
* The whole picture is parsed at this point and can now be sent
* to the hardware accelerator. This function is mandatory.
*
* @param avctx the codec context
* @return zero if successful, a negative value otherwise
*/
int (*end_frame)(AVCodecContext *avctx);
/**
* Size of per-frame hardware accelerator private data.
*
* Private data is allocated with av_mallocz() before
* AVCodecContext.get_buffer() and deallocated after
* AVCodecContext.release_buffer().
*/
int frame_priv_data_size;
/**
* Called for every Macroblock in a slice.
*
* XvMC uses it to replace the ff_mpv_decode_mb().
* Instead of decoding to raw picture, MB parameters are
* stored in an array provided by the video driver.
*
* @param s the mpeg context
*/
void (*decode_mb)(struct MpegEncContext *s);
/**
* Initialize the hwaccel private data.
*
* This will be called from ff_get_format(), after hwaccel and
* hwaccel_context are set and the hwaccel private data in AVCodecInternal
* is allocated.
*/
int (*init)(AVCodecContext *avctx);
/**
* Uninitialize the hwaccel private data.
*
* This will be called from get_format() or avcodec_close(), after hwaccel
* and hwaccel_context are already uninitialized.
*/
int (*uninit)(AVCodecContext *avctx);
/**
* Size of the private data to allocate in
* AVCodecInternal.hwaccel_priv_data.
*/
int priv_data_size;
} AVHWAccel;
/**
* Hardware acceleration should be used for decoding even if the codec level
* used is unknown or higher than the maximum supported level reported by the
* hardware driver.
*
* It's generally a good idea to pass this flag unless you have a specific
* reason not to, as hardware tends to under-report supported levels.
*/
#define AV_HWACCEL_FLAG_IGNORE_LEVEL (1 << 0)
/**
* Hardware acceleration can output YUV pixel formats with a different chroma
* sampling than 4:2:0 and/or other than 8 bits per component.
*/
#define AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH (1 << 1)
/**
* @}
*/
#if FF_API_AVPICTURE
/**
* @defgroup lavc_picture AVPicture
*
* Functions for working with AVPicture
* @{
*/
/**
* Picture data structure.
*
* Up to four components can be stored into it, the last component is
* alpha.
* @deprecated use AVFrame or imgutils functions instead
*/
typedef struct AVPicture {
attribute_deprecated
uint8_t *data[AV_NUM_DATA_POINTERS]; ///< pointers to the image data planes
attribute_deprecated
int linesize[AV_NUM_DATA_POINTERS]; ///< number of bytes per line
} AVPicture;
/**
* @}
*/
#endif
enum AVSubtitleType {
SUBTITLE_NONE,
SUBTITLE_BITMAP, ///< A bitmap, pict will be set
/**
* Plain text, the text field must be set by the decoder and is
* authoritative. ass and pict fields may contain approximations.
*/
SUBTITLE_TEXT,
/**
* Formatted text, the ass field must be set by the decoder and is
* authoritative. pict and text fields may contain approximations.
*/
SUBTITLE_ASS,
};
#define AV_SUBTITLE_FLAG_FORCED 0x00000001
typedef struct AVSubtitleRect {
int x; ///< top left corner of pict, undefined when pict is not set
int y; ///< top left corner of pict, undefined when pict is not set
int w; ///< width of pict, undefined when pict is not set
int h; ///< height of pict, undefined when pict is not set
int nb_colors; ///< number of colors in pict, undefined when pict is not set
#if FF_API_AVPICTURE
/**
* @deprecated unused
*/
attribute_deprecated
AVPicture pict;
#endif
/**
* data+linesize for the bitmap of this subtitle.
* Can be set for text/ass as well once they are rendered.
*/
uint8_t *data[4];
int linesize[4];
enum AVSubtitleType type;
char *text; ///< 0 terminated plain UTF-8 text
/**
* 0 terminated ASS/SSA compatible event line.
* The presentation of this is unaffected by the other values in this
* struct.
*/
char *ass;
int flags;
} AVSubtitleRect;
typedef struct AVSubtitle {
uint16_t format; /* 0 = graphics */
uint32_t start_display_time; /* relative to packet pts, in ms */
uint32_t end_display_time; /* relative to packet pts, in ms */
unsigned num_rects;
AVSubtitleRect **rects;
int64_t pts; ///< Same as packet pts, in AV_TIME_BASE
} AVSubtitle;
/**
* If c is NULL, returns the first registered codec,
* if c is non-NULL, returns the next registered codec after c,
@ -1362,43 +777,6 @@ typedef struct AVSubtitle {
*/
AVCodec *av_codec_next(const AVCodec *c);
/**
* Return the LIBAVCODEC_VERSION_INT constant.
*/
unsigned avcodec_version(void);
/**
* Return the libavcodec build-time configuration.
*/
const char *avcodec_configuration(void);
/**
* Return the libavcodec license.
*/
const char *avcodec_license(void);
/**
* Register the codec codec and initialize libavcodec.
*
* @warning either this function or avcodec_register_all() must be called
* before any other libavcodec functions.
*
* @see avcodec_register_all()
*/
void avcodec_register(AVCodec *codec);
/**
* Register all the codecs, parsers and bitstream filters which were enabled at
* configuration time. If you do not call this function you can select exactly
* which formats you want to support, by using the individual registration
* functions.
*
* @see avcodec_register
* @see av_register_codec_parser
* @see av_register_bitstream_filter
*/
void avcodec_register_all(void);
/**
* Allocate an AVCodecContext and set its fields to default values. The
* resulting struct should be freed with avcodec_free_context().
@ -1432,43 +810,6 @@ void avcodec_free_context(AVCodecContext **avctx);
*/
int avcodec_get_context_defaults3(AVCodecContext *s, const AVCodec *codec);
/**
* Get the AVClass for AVCodecContext. It can be used in combination with
* AV_OPT_SEARCH_FAKE_OBJ for examining options.
*
* @see av_opt_find().
*/
const AVClass *avcodec_get_class(void);
/**
* Get the AVClass for AVFrame. It can be used in combination with
* AV_OPT_SEARCH_FAKE_OBJ for examining options.
*
* @see av_opt_find().
*/
const AVClass *avcodec_get_frame_class(void);
/**
* Get the AVClass for AVSubtitleRect. It can be used in combination with
* AV_OPT_SEARCH_FAKE_OBJ for examining options.
*
* @see av_opt_find().
*/
const AVClass *avcodec_get_subtitle_rect_class(void);
/**
* Copy the settings of the source AVCodecContext into the destination
* AVCodecContext. The resulting destination codec context will be
* unopened, i.e. you are required to call avcodec_open2() before you
* can use this AVCodecContext to decode/encode video/audio data.
*
* @param dest target codec context, should be initialized with
* avcodec_alloc_context3(NULL), but otherwise uninitialized
* @param src source codec context
* @return AVERROR() on error (e.g. memory allocation error), 0 on success
*/
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src);
/**
* Initialize the AVCodecContext to use the given AVCodec. Prior to using this
* function the context has to be allocated with avcodec_alloc_context3().
@ -1521,176 +862,6 @@ int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, void *options);
*/
int avcodec_close(AVCodecContext *avctx);
/**
* @}
*/
/**
* @addtogroup lavc_packet
* @{
*/
/**
* Allocate an AVPacket and set its fields to default values. The resulting
* struct must be freed using av_packet_free().
*
* @return An AVPacket filled with default values or NULL on failure.
*
* @note this only allocates the AVPacket itself, not the data buffers. Those
* must be allocated through other means such as av_new_packet.
*
* @see av_new_packet
*/
AVPacket *av_packet_alloc(void);
/**
* Create a new packet that references the same data as src.
*
* This is a shortcut for av_packet_alloc()+av_packet_ref().
*
* @return newly created AVPacket on success, NULL on error.
*
* @see av_packet_alloc
* @see av_packet_ref
*/
AVPacket *av_packet_clone(AVPacket *src);
/**
* Free the packet, if the packet is reference counted, it will be
* unreferenced first.
*
* @param packet packet to be freed. The pointer will be set to NULL.
* @note passing NULL is a no-op.
*/
void av_packet_free(AVPacket **pkt);
/**
* Initialize optional fields of a packet with default values.
*
* Note, this does not touch the data and size members, which have to be
* initialized separately.
*
* @param pkt packet
*/
void av_init_packet(AVPacket *pkt);
/**
* Allocate the payload of a packet and initialize its fields with
* default values.
*
* @param pkt packet
* @param size wanted payload size
* @return 0 if OK, AVERROR_xxx otherwise
*/
int av_new_packet(AVPacket *pkt, int size);
/**
* Initialize a reference-counted packet from av_malloc()ed data.
*
* @param pkt packet to be initialized. This function will set the data, size,
* buf and destruct fields, all others are left untouched.
* @param data Data allocated by av_malloc() to be used as packet data. If this
* function returns successfully, the data is owned by the underlying AVBuffer.
* The caller may not access the data through other means.
* @param size size of data in bytes, without the padding. I.e. the full buffer
* size is assumed to be size + AV_INPUT_BUFFER_PADDING_SIZE.
*
* @return 0 on success, a negative AVERROR on error
*/
int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size);
#if FF_API_AVPACKET_OLD_API
/**
* @warning This is a hack - the packet memory allocation stuff is broken. The
* packet is allocated if it was not really allocated.
*
* @deprecated Use av_packet_ref
*/
attribute_deprecated
int av_dup_packet(AVPacket *pkt);
/**
* Copy packet, including contents
*
* @return 0 on success, negative AVERROR on fail
*/
int av_copy_packet(AVPacket *dst, const AVPacket *src);
/**
* Free a packet.
*
* @deprecated Use av_packet_unref
*
* @param pkt packet to free
*/
attribute_deprecated
void av_free_packet(AVPacket *pkt);
#endif
/**
* Setup a new reference to the data described by a given packet
*
* If src is reference-counted, setup dst as a new reference to the
* buffer in src. Otherwise allocate a new buffer in dst and copy the
* data from src into it.
*
* All the other fields are copied from src.
*
* @see av_packet_unref
*
* @param dst Destination packet
* @param src Source packet
*
* @return 0 on success, a negative AVERROR on error.
*/
int av_packet_ref(AVPacket *dst, const AVPacket *src);
/**
* Wipe the packet.
*
* Unreference the buffer referenced by the packet and reset the
* remaining packet fields to their default values.
*
* @param pkt The packet to be unreferenced.
*/
void av_packet_unref(AVPacket *pkt);
/**
* Move every field in src to dst and reset src.
*
* @see av_packet_unref
*
* @param src Source packet, will be reset
* @param dst Destination packet
*/
void av_packet_move_ref(AVPacket *dst, AVPacket *src);
/**
* Copy only "properties" fields from src to dst.
*
* Properties for the purpose of this function are all the fields
* beside those related to the packet data (buf, data, size)
*
* @param dst Destination packet
* @param src Source packet
*
* @return 0 on success AVERROR on failure.
*
*/
int av_packet_copy_props(AVPacket *dst, const AVPacket *src);
/**
* Convert valid timing fields (timestamps / durations) in a packet from one
* timebase to another. Timestamps with unknown values (AV_NOPTS_VALUE) will be
* ignored.
*
* @param pkt packet on which the conversion will be performed
* @param tb_src source timebase, in which the timing fields in pkt are
* expressed
* @param tb_dst destination timebase, to which the timing fields will be
* converted
*/
void av_packet_rescale_ts(AVPacket *pkt, AVRational tb_src, AVRational tb_dst);
/**
* @}
*/

View File

@ -1,287 +0,0 @@
/*
* AVPacket functions for libavcodec
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
*
* 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
*/
#include <string.h>
#include "common.h"
#include "internal.h"
#include "mathematics.h"
#include "mem.h"
#include "avcodec.h"
#include "bytestream.h"
#include "internal.h"
void av_init_packet(AVPacket *pkt)
{
pkt->pts = AV_NOPTS_VALUE;
pkt->dts = AV_NOPTS_VALUE;
pkt->pos = -1;
pkt->duration = 0;
#if FF_API_CONVERGENCE_DURATION
FF_DISABLE_DEPRECATION_WARNINGS
pkt->convergence_duration = 0;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
pkt->flags = 0;
pkt->stream_index = 0;
pkt->buf = NULL;
}
AVPacket *av_packet_alloc(void)
{
AVPacket *pkt = av_mallocz(sizeof(AVPacket));
if (!pkt)
return pkt;
av_packet_unref(pkt);
return pkt;
}
void av_packet_free(AVPacket **pkt)
{
if (!pkt || !*pkt)
return;
av_packet_unref(*pkt);
av_freep(pkt);
}
static int packet_alloc(AVBufferRef **buf, int size)
{
int ret;
if (size < 0 || size >= INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
return AVERROR(EINVAL);
ret = av_buffer_realloc(buf, size + AV_INPUT_BUFFER_PADDING_SIZE);
if (ret < 0)
return ret;
memset((*buf)->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
return 0;
}
int av_new_packet(AVPacket *pkt, int size)
{
AVBufferRef *buf = NULL;
int ret = packet_alloc(&buf, size);
if (ret < 0)
return ret;
av_init_packet(pkt);
pkt->buf = buf;
pkt->data = buf->data;
pkt->size = size;
return 0;
}
int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size)
{
if (size >= INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
return AVERROR(EINVAL);
pkt->buf = av_buffer_create(data, size + AV_INPUT_BUFFER_PADDING_SIZE,
av_buffer_default_free, NULL, 0);
if (!pkt->buf)
return AVERROR(ENOMEM);
pkt->data = data;
pkt->size = size;
return 0;
}
#if FF_API_AVPACKET_OLD_API
FF_DISABLE_DEPRECATION_WARNINGS
#define ALLOC_MALLOC(data, size) data = av_malloc(size)
#define ALLOC_BUF(data, size) \
do { \
av_buffer_realloc(&pkt->buf, size); \
data = pkt->buf ? pkt->buf->data : NULL; \
} while (0)
#define DUP_DATA(dst, src, size, padding, ALLOC) \
do { \
void *data; \
if (padding) { \
if ((unsigned)(size) > \
(unsigned)(size) + AV_INPUT_BUFFER_PADDING_SIZE) \
goto failed_alloc; \
ALLOC(data, size + AV_INPUT_BUFFER_PADDING_SIZE); \
} else { \
ALLOC(data, size); \
} \
if (!data) \
goto failed_alloc; \
memcpy(data, src, size); \
if (padding) \
memset((uint8_t *)data + size, 0, \
AV_INPUT_BUFFER_PADDING_SIZE); \
dst = data; \
} while (0)
/* Makes duplicates of data, side_data, but does not copy any other fields */
static int copy_packet_data(AVPacket *pkt, const AVPacket *src, int dup)
{
pkt->data = NULL;
if (pkt->buf) {
AVBufferRef *ref = av_buffer_ref(src->buf);
if (!ref)
return AVERROR(ENOMEM);
pkt->buf = ref;
pkt->data = ref->data;
} else {
DUP_DATA(pkt->data, src->data, pkt->size, 1, ALLOC_BUF);
}
return 0;
failed_alloc:
av_packet_unref(pkt);
return AVERROR(ENOMEM);
}
FF_ENABLE_DEPRECATION_WARNINGS
#endif
int av_dup_packet(AVPacket *pkt)
{
AVPacket tmp_pkt;
if (!pkt->buf && pkt->data) {
tmp_pkt = *pkt;
return copy_packet_data(pkt, &tmp_pkt, 1);
}
return 0;
}
int av_copy_packet(AVPacket *dst, const AVPacket *src)
{
*dst = *src;
return copy_packet_data(dst, src, 0);
}
#if FF_API_AVPACKET_OLD_API
FF_DISABLE_DEPRECATION_WARNINGS
void av_free_packet(AVPacket *pkt)
{
if (pkt) {
if (pkt->buf)
av_buffer_unref(&pkt->buf);
pkt->data = NULL;
pkt->size = 0;
}
}
FF_ENABLE_DEPRECATION_WARNINGS
#endif
#define FF_MERGE_MARKER 0x8c4d9d108e25e9feULL
int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
{
int i;
dst->pts = src->pts;
dst->dts = src->dts;
dst->pos = src->pos;
dst->duration = src->duration;
#if FF_API_CONVERGENCE_DURATION
FF_DISABLE_DEPRECATION_WARNINGS
dst->convergence_duration = src->convergence_duration;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
dst->flags = src->flags;
dst->stream_index = src->stream_index;
return 0;
}
void av_packet_unref(AVPacket *pkt)
{
av_buffer_unref(&pkt->buf);
av_init_packet(pkt);
pkt->data = NULL;
pkt->size = 0;
}
int av_packet_ref(AVPacket *dst, const AVPacket *src)
{
int ret;
ret = av_packet_copy_props(dst, src);
if (ret < 0)
return ret;
if (!src->buf) {
ret = packet_alloc(&dst->buf, src->size);
if (ret < 0)
goto fail;
memcpy(dst->buf->data, src->data, src->size);
} else {
dst->buf = av_buffer_ref(src->buf);
if (!dst->buf) {
ret = AVERROR(ENOMEM);
goto fail;
}
}
dst->size = src->size;
dst->data = dst->buf->data;
return 0;
fail:
return ret;
}
AVPacket *av_packet_clone(AVPacket *src)
{
AVPacket *ret = av_packet_alloc();
if (!ret)
return ret;
if (av_packet_ref(ret, src))
av_packet_free(&ret);
return ret;
}
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
{
*dst = *src;
av_init_packet(src);
}
void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
{
if (pkt->pts != AV_NOPTS_VALUE)
pkt->pts = av_rescale_q(pkt->pts, src_tb, dst_tb);
if (pkt->dts != AV_NOPTS_VALUE)
pkt->dts = av_rescale_q(pkt->dts, src_tb, dst_tb);
if (pkt->duration > 0)
pkt->duration = av_rescale_q(pkt->duration, src_tb, dst_tb);
#if FF_API_CONVERGENCE_DURATION
FF_DISABLE_DEPRECATION_WARNINGS
if (pkt->convergence_duration > 0)
pkt->convergence_duration = av_rescale_q(pkt->convergence_duration, src_tb, dst_tb);
FF_ENABLE_DEPRECATION_WARNINGS
#endif
}

View File

@ -160,45 +160,6 @@
* @}
*/
/**
* @addtogroup lavu_media Media Type
* @brief Media Type
*/
enum AVMediaType {
AVMEDIA_TYPE_UNKNOWN = -1, ///< Usually treated as AVMEDIA_TYPE_DATA
AVMEDIA_TYPE_AUDIO,
AVMEDIA_TYPE_DATA, ///< Opaque data information usually continuous
AVMEDIA_TYPE_SUBTITLE,
AVMEDIA_TYPE_ATTACHMENT, ///< Opaque data information usually sparse
AVMEDIA_TYPE_NB
};
/**
* @defgroup lavu_const Constants
* @{
*
* @defgroup lavu_enc Encoding specific
*
* @note those definition should move to avcodec
* @{
*/
#define FF_LAMBDA_SHIFT 7
#define FF_LAMBDA_SCALE (1<<FF_LAMBDA_SHIFT)
#define FF_QP2LAMBDA 118 ///< factor to convert from H.263 QP to lambda
#define FF_LAMBDA_MAX (256*128-1)
#define FF_QUALITY_SCALE FF_LAMBDA_SCALE //FIXME maybe remove
/**
* @}
* @defgroup lavu_time Timestamp specific
*
* FFmpeg internal timebase and timestamp definitions
*
* @{
*/
/**
* @brief Undefined timestamp value

View File

@ -32,11 +32,6 @@
#include "avcodec.h"
#include "config.h"
/**
* The codec does not modify any global variables in the init function,
* allowing to call the init function without locking any global mutexes.
*/
#define FF_CODEC_CAP_INIT_THREADSAFE (1 << 0)
/**
* The codec allows calling the close function for deallocation even if
* the init function returned a failure. Without this capability flag, a
@ -92,7 +87,6 @@ typedef struct FramePool {
* Pool parameters
*/
int format;
int width, height;
int stride_align[AV_NUM_DATA_POINTERS];
int linesize[4];
int planes;
@ -130,18 +124,10 @@ typedef struct AVCodecInternal {
*/
int last_audio_frame;
AVFrame *to_free;
FramePool *pool;
void *thread_ctx;
/**
* Current packet as passed into the decoder, to avoid having to pass the
* packet into every function.
*/
AVPacket *pkt;
/**
* temporary buffer used for encoders to store their bitstream
*/
@ -156,28 +142,13 @@ typedef struct AVCodecInternal {
int skip_samples;
} AVCodecInternal;
struct AVCodecDefault {
const uint8_t *key;
const uint8_t *value;
};
extern const uint8_t ff_log2_run[41];
/**
* 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.
*/
int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b);
/**
* does needed setup of pkt_pts/pos and such for (re)get_buffer();
*/
int ff_init_buffer_info(AVCodecContext *s, AVFrame *frame);
extern volatile int ff_avcodec_locked;
int ff_lock_avcodec(AVCodecContext *log_ctx, const AVCodec *codec);
int ff_unlock_avcodec(const AVCodec *codec);
/**
* Maximum size in bytes of extradata.
* This value was chosen such that every bit of the buffer is
@ -185,36 +156,6 @@ int ff_unlock_avcodec(const AVCodec *codec);
*/
#define FF_MAX_EXTRADATA_SIZE ((1 << 28) - AV_INPUT_BUFFER_PADDING_SIZE)
/**
* Check AVPacket size and/or allocate data.
*
* Encoders supporting AVCodec.encode2() can use this as a convenience to
* ensure the output packet data is large enough, whether provided by the user
* or allocated in this function.
*
* @param avctx the AVCodecContext of the encoder
* @param avpkt the AVPacket
* If avpkt->data is already set, avpkt->size is checked
* to ensure it is large enough.
* If avpkt->data is NULL, a new buffer is allocated.
* avpkt->size is set to the specified size.
* All other AVPacket fields will be reset with av_init_packet().
* @param size the minimum required packet size
* @param min_size This is a hint to the allocation algorithm, which indicates
* to what minimal size the caller might later shrink the packet
* to. Encoders often allocate packets which are larger than the
* amount of data that is written into them as the exact amount is
* not known at the time of allocation. min_size represents the
* size a packet might be shrunk to by the caller. Can be set to
* 0. setting this roughly correctly allows the allocation code
* to choose between several allocation strategies to improve
* speed slightly.
* @return non negative on success, negative error code on failure
*/
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);
/**
* Get a buffer for a frame. This is a wrapper around
* AVCodecContext.get_buffer() and should be used instead calling get_buffer()

View File

@ -31,47 +31,15 @@
#include <float.h> /* FLT_MIN, FLT_MAX */
#include <string.h>
static void *codec_child_next(void *obj, void *prev)
{
AVCodecContext *s = obj;
if (!prev && s->codec && s->codec->priv_class && s->priv_data)
return s->priv_data;
return NULL;
}
static const AVClass *codec_child_class_next(const AVClass *prev)
{
AVCodec *c = NULL;
/* find the codec that corresponds to prev */
while (prev && (c = av_codec_next(c)))
if (c->priv_class == prev)
break;
/* find next codec with priv options */
while (c = av_codec_next(c))
if (c->priv_class)
return c->priv_class;
return NULL;
}
static AVClassCategory get_category(void *ptr)
{
AVCodecContext* avctx = ptr;
if(avctx->codec && avctx->codec->decode) return AV_CLASS_CATEGORY_DECODER;
else return AV_CLASS_CATEGORY_ENCODER;
}
static const AVClass av_codec_context_class = {
.class_name = "AVCodecContext",
.item_name = NULL,
.option = NULL,
.version = LIBAVUTIL_VERSION_INT,
.log_level_offset_offset = offsetof(AVCodecContext, log_level_offset),
.child_next = codec_child_next,
.child_class_next = codec_child_class_next,
.category = AV_CLASS_CATEGORY_ENCODER,
.get_category = get_category,
.child_next = NULL,
.child_class_next = NULL,
.category = AV_CLASS_CATEGORY_DECODER,
};
int avcodec_get_context_defaults3(AVCodecContext *s, const AVCodec *codec)
@ -81,14 +49,11 @@ int avcodec_get_context_defaults3(AVCodecContext *s, const AVCodec *codec)
s->av_class = &av_codec_context_class;
s->codec_type = codec ? codec->type : AVMEDIA_TYPE_UNKNOWN;
if (codec) {
s->codec = codec;
s->codec_id = codec->id;
}
s->time_base = (AVRational){0,1};
s->pkt_timebase = (AVRational){ 0, 1 };
s->get_buffer2 = avcodec_default_get_buffer2;
s->sample_fmt = AV_SAMPLE_FMT_NONE;
@ -131,18 +96,10 @@ void avcodec_free_context(AVCodecContext **pavctx)
avcodec_close(avctx);
av_freep(&avctx->extradata);
av_freep(&avctx->intra_matrix);
av_freep(&avctx->inter_matrix);
av_freep(&avctx->rc_override);
av_freep(pavctx);
}
const AVClass *avcodec_get_class(void)
{
return &av_codec_context_class;
}
#define FOFFSET(x) offsetof(AVFrame,x)
static const AVClass av_frame_class = {
@ -152,9 +109,4 @@ static const AVClass av_frame_class = {
.version = LIBAVUTIL_VERSION_INT,
};
const AVClass *avcodec_get_frame_class(void)
{
return &av_frame_class;
}
#define SROFFSET(x) offsetof(AVSubtitleRect,x)

View File

@ -63,18 +63,6 @@ void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
memset(*p + min_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
}
/* encoder management */
static AVCodec *first_avcodec = NULL;
static AVCodec **last_avcodec = &first_avcodec;
AVCodec *av_codec_next(const AVCodec *c)
{
if (c)
return c->next;
else
return first_avcodec;
}
static av_cold void avcodec_init(void)
{
static int initialized = 0;
@ -86,7 +74,7 @@ static av_cold void avcodec_init(void)
int av_codec_is_decoder(const AVCodec *codec)
{
return codec && codec->decode;
return 1;
}
#if FF_API_EMU_EDGE
@ -101,43 +89,36 @@ static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame)
FramePool *pool = avctx->internal->pool;
int i, ret;
switch (avctx->codec_type) {
case AVMEDIA_TYPE_AUDIO: {
int ch = av_frame_get_channels(frame); //av_get_channel_layout_nb_channels(frame->channel_layout);
int planar = av_sample_fmt_is_planar(frame->format);
int planes = planar ? ch : 1;
int ch = av_frame_get_channels(frame); //av_get_channel_layout_nb_channels(frame->channel_layout);
int planar = av_sample_fmt_is_planar(frame->format);
int planes = planar ? ch : 1;
if (pool->format == frame->format && pool->planes == planes &&
pool->channels == ch && frame->nb_samples == pool->samples)
return 0;
if (pool->format == frame->format && pool->planes == planes &&
pool->channels == ch && frame->nb_samples == pool->samples)
return 0;
av_buffer_pool_uninit(&pool->pools[0]);
ret = av_samples_get_buffer_size(&pool->linesize[0], ch,
frame->nb_samples, frame->format, 0);
if (ret < 0)
goto fail;
av_buffer_pool_uninit(&pool->pools[0]);
ret = av_samples_get_buffer_size(&pool->linesize[0], ch,
frame->nb_samples, frame->format, 0);
if (ret < 0)
goto fail;
pool->pools[0] = av_buffer_pool_init(pool->linesize[0], NULL);
if (!pool->pools[0]) {
ret = AVERROR(ENOMEM);
goto fail;
}
pool->format = frame->format;
pool->planes = planes;
pool->channels = ch;
pool->samples = frame->nb_samples;
break;
}
default: av_assert0(0);
pool->pools[0] = av_buffer_pool_init(pool->linesize[0], NULL);
if (!pool->pools[0]) {
ret = AVERROR(ENOMEM);
goto fail;
}
pool->format = frame->format;
pool->planes = planes;
pool->channels = ch;
pool->samples = frame->nb_samples;
return 0;
fail:
for (i = 0; i < 4; i++)
av_buffer_pool_uninit(&pool->pools[i]);
pool->format = -1;
pool->planes = pool->channels = pool->samples = 0;
pool->width = pool->height = 0;
return ret;
}
@ -190,54 +171,34 @@ int avcodec_default_get_buffer2(AVCodecContext *avctx, AVFrame *frame, int flags
if ((ret = update_frame_pool(avctx, frame)) < 0)
return ret;
switch (avctx->codec_type) {
case AVMEDIA_TYPE_AUDIO:
return audio_get_buffer(avctx, frame);
default:
return -1;
}
return audio_get_buffer(avctx, frame);
}
int ff_init_buffer_info(AVCodecContext *avctx, AVFrame *frame)
{
AVPacket *pkt = avctx->internal->pkt;
if (pkt) {
av_frame_set_pkt_pos (frame, pkt->pos);
av_frame_set_pkt_duration(frame, pkt->duration);
av_frame_set_pkt_size (frame, pkt->size);
} else {
av_frame_set_pkt_pos (frame, -1);
av_frame_set_pkt_duration(frame, 0);
av_frame_set_pkt_size (frame, -1);
}
switch (avctx->codec->type) {
case AVMEDIA_TYPE_AUDIO:
if (!frame->sample_rate)
frame->sample_rate = avctx->sample_rate;
if (frame->format < 0)
frame->format = avctx->sample_fmt;
if (!frame->channel_layout) {
if (avctx->channel_layout) {
if (av_get_channel_layout_nb_channels(avctx->channel_layout) !=
avctx->channels) {
av_log(avctx, AV_LOG_ERROR, "Inconsistent channel "
"configuration.\n");
return AVERROR(EINVAL);
}
frame->channel_layout = avctx->channel_layout;
} else {
if (avctx->channels > FF_SANE_NB_CHANNELS) {
av_log(avctx, AV_LOG_ERROR, "Too many channels: %d.\n",
avctx->channels);
return AVERROR(ENOSYS);
if (!frame->sample_rate)
frame->sample_rate = avctx->sample_rate;
if (frame->format < 0)
frame->format = avctx->sample_fmt;
if (!frame->channel_layout) {
if (avctx->channel_layout) {
if (av_get_channel_layout_nb_channels(avctx->channel_layout) !=
avctx->channels) {
av_log(avctx, AV_LOG_ERROR, "Inconsistent channel "
"configuration.\n");
return AVERROR(EINVAL);
}
frame->channel_layout = avctx->channel_layout;
} else {
if (avctx->channels > FF_SANE_NB_CHANNELS) {
av_log(avctx, AV_LOG_ERROR, "Too many channels: %d.\n",
avctx->channels);
return AVERROR(ENOSYS);
}
}
av_frame_set_channels(frame, avctx->channels);
break;
}
av_frame_set_channels(frame, avctx->channels);
return 0;
}
@ -254,18 +215,12 @@ int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
return ret;
}
MAKE_ACCESSORS(AVCodecContext, codec, AVRational, pkt_timebase)
MAKE_ACCESSORS(AVCodecContext, codec, int, seek_preroll)
int attribute_align_arg ff_codec_open2_recursive(AVCodecContext *avctx, const AVCodec *codec, void **options)
{
int ret = 0;
ff_unlock_avcodec(codec);
ret = avcodec_open2(avctx, codec, options);
ff_lock_avcodec(avctx, codec);
return ret;
}
@ -287,10 +242,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
return AVERROR(EINVAL);
ret = ff_lock_avcodec(avctx, codec);
if (ret < 0)
return ret;
avctx->internal = av_mallocz(sizeof(AVCodecInternal));
if (!avctx->internal) {
ret = AVERROR(ENOMEM);
@ -303,12 +254,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
goto free_and_end;
}
avctx->internal->to_free = av_frame_alloc();
if (!avctx->internal->to_free) {
ret = AVERROR(ENOMEM);
goto free_and_end;
}
if (codec->priv_data_size > 0) {
if (!avctx->priv_data) {
avctx->priv_data = av_mallocz(codec->priv_data_size);
@ -330,25 +275,10 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
}
avctx->codec = codec;
if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
avctx->codec_id == AV_CODEC_ID_NONE) {
avctx->codec_type = codec->type;
avctx->codec_id = codec->id;
}
if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
&& avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n");
ret = AVERROR(EINVAL);
goto free_and_end;
}
avctx->codec_id = codec->id;
avctx->frame_number = 0;
if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
(!avctx->time_base.num || !avctx->time_base.den)) {
avctx->time_base.num = 1;
avctx->time_base.den = avctx->sample_rate;
}
#if FF_API_VISMV
if (avctx->debug_mv)
av_log(avctx, AV_LOG_WARNING, "The 'vismv' option is deprecated, "
@ -401,7 +331,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
}
end:
ff_unlock_avcodec(codec);
return ret;
free_and_end:
@ -417,7 +346,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
av_freep(&avctx->priv_data);
if (avctx->internal) {
av_frame_free(&avctx->internal->to_free);
av_freep(&avctx->internal->pool);
}
av_freep(&avctx->internal);
@ -425,52 +353,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
goto end;
}
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
{
if (avpkt->size < 0) {
av_log(avctx, AV_LOG_ERROR, "Invalid negative user packet size %d\n", avpkt->size);
return AVERROR(EINVAL);
}
if (size < 0 || size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
av_log(avctx, AV_LOG_ERROR, "Invalid minimum required packet size %"PRId64" (max allowed is %d)\n",
size, INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE);
return AVERROR(EINVAL);
}
if (avctx && 2*min_size < size) { // FIXME The factor needs to be finetuned
av_assert0(!avpkt->data || avpkt->data != avctx->internal->byte_buffer);
if (!avpkt->data || avpkt->size < size) {
av_fast_padded_malloc(&avctx->internal->byte_buffer, &avctx->internal->byte_buffer_size, size);
avpkt->data = avctx->internal->byte_buffer;
avpkt->size = avctx->internal->byte_buffer_size;
}
}
if (avpkt->data) {
AVBufferRef *buf = avpkt->buf;
if (avpkt->size < size) {
av_log(avctx, AV_LOG_ERROR, "User packet is too small (%d < %"PRId64")\n", avpkt->size, size);
return AVERROR(EINVAL);
}
av_init_packet(avpkt);
avpkt->buf = buf;
avpkt->size = size;
return 0;
} else {
int ret = av_new_packet(avpkt, size);
if (ret < 0)
av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %"PRId64"\n", size);
return ret;
}
}
int ff_alloc_packet(AVPacket *avpkt, int size)
{
return ff_alloc_packet2(NULL, avpkt, size, 0);
}
av_cold int avcodec_close(AVCodecContext *avctx)
{
int i;
@ -484,7 +366,6 @@ av_cold int avcodec_close(AVCodecContext *avctx)
avctx->codec->close(avctx);
avctx->internal->byte_buffer_size = 0;
av_freep(&avctx->internal->byte_buffer);
av_frame_free(&avctx->internal->to_free);
for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++)
av_buffer_pool_uninit(&pool->pools[i]);
av_freep(&avctx->internal->pool);
@ -499,39 +380,6 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
{
if (avctx->codec->flush)
avctx->codec->flush(avctx);
if (!avctx->refcounted_frames)
av_frame_unref(avctx->internal->to_free);
}
int ff_lock_avcodec(AVCodecContext *log_ctx, const AVCodec *codec)
{
if (codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE || !codec->init)
return 0;
if (lockmgr_cb) {
if ((*lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
return -1;
}
av_assert0(!ff_avcodec_locked);
ff_avcodec_locked = 1;
return 0;
}
int ff_unlock_avcodec(const AVCodec *codec)
{
if (codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE || !codec->init)
return 0;
av_assert0(ff_avcodec_locked);
ff_avcodec_locked = 0;
if (lockmgr_cb) {
if ((*lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE))
return -1;
}
return 0;
}
int avcodec_is_open(AVCodecContext *s)