World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
Decoding
+ Граф связей класса Decoding:

Группы

 Frame parsing
 

Перечисления

enum  AVDiscard {
  AVDISCARD_NONE =-16, AVDISCARD_DEFAULT = 0, AVDISCARD_NONREF = 8, AVDISCARD_BIDIR = 16,
  AVDISCARD_NONINTRA = 24, AVDISCARD_NONKEY = 32, AVDISCARD_ALL = 48
}
 

Функции

AVCodecavcodec_find_decoder (enum AVCodecID id)
 
AVCodecavcodec_find_decoder_by_name (const char *name)
 
int avcodec_default_get_buffer2 (AVCodecContext *s, AVFrame *frame, int flags)
 
void avcodec_align_dimensions (AVCodecContext *s, int *width, int *height)
 
void avcodec_align_dimensions2 (AVCodecContext *s, int *width, int *height, int linesize_align[AV_NUM_DATA_POINTERS])
 
int avcodec_enum_to_chroma_pos (int *xpos, int *ypos, enum AVChromaLocation pos)
 
enum AVChromaLocation avcodec_chroma_pos_to_enum (int xpos, int ypos)
 
attribute_deprecated int avcodec_decode_audio4 (AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, const AVPacket *avpkt)
 
attribute_deprecated int avcodec_decode_video2 (AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, const AVPacket *avpkt)
 
int avcodec_decode_subtitle2 (AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
 
int avcodec_send_packet (AVCodecContext *avctx, const AVPacket *avpkt)
 
int avcodec_receive_frame (AVCodecContext *avctx, AVFrame *frame)
 
int avcodec_send_frame (AVCodecContext *avctx, const AVFrame *frame)
 
int avcodec_receive_packet (AVCodecContext *avctx, AVPacket *avpkt)
 
int avcodec_get_hw_frames_parameters (AVCodecContext *avctx, AVBufferRef *device_ref, enum AVPixelFormat hw_pix_fmt, AVBufferRef **out_frames_ref)
 

Подробное описание

Перечисления

◆ AVDiscard

enum AVDiscard

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavcodec/avcodec.h>

Элементы перечислений
AVDISCARD_NONE 

discard nothing

AVDISCARD_DEFAULT 

discard useless packets like 0 size packets in avi

AVDISCARD_NONREF 

discard all non reference

AVDISCARD_BIDIR 

discard all bidirectional frames

AVDISCARD_NONINTRA 

discard all non intra frames

AVDISCARD_NONKEY 

discard all frames except keyframes

AVDISCARD_ALL 

discard all

См. определение в файле avcodec.h строка 802

802  {
803  /* We leave some space between them for extensions (drop some
804  * keyframes for intra-only or drop just some bidir frames). */
805  AVDISCARD_NONE =-16,
806  AVDISCARD_DEFAULT = 0,
807  AVDISCARD_NONREF = 8,
808  AVDISCARD_BIDIR = 16,
809  AVDISCARD_NONINTRA= 24,
810  AVDISCARD_NONKEY = 32,
811  AVDISCARD_ALL = 48,
812 };

Функции

◆ avcodec_find_decoder()

AVCodec* avcodec_find_decoder ( enum AVCodecID  id)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavcodec/avcodec.h>

Find a registered decoder with a matching codec ID.

Аргументы
idAVCodecID of the requested decoder
Возвращает
A decoder if one was found, NULL otherwise.

Используется в main().

+ Граф вызова функции:

◆ avcodec_find_decoder_by_name()

AVCodec* avcodec_find_decoder_by_name ( const char *  name)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavcodec/avcodec.h>

Find a registered decoder with the specified name.

Аргументы
namename of the requested decoder
Возвращает
A decoder if one was found, NULL otherwise.

◆ avcodec_default_get_buffer2()

int avcodec_default_get_buffer2 ( AVCodecContext s,
AVFrame frame,
int  flags 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavcodec/avcodec.h>

The default callback for AVCodecContext.get_buffer2(). It is made public so it can be called by custom get_buffer2() implementations for decoders without AV_CODEC_CAP_DR1 set.

◆ avcodec_align_dimensions()

void avcodec_align_dimensions ( AVCodecContext s,
int *  width,
int *  height 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavcodec/avcodec.h>

Modify width and height values so that they will result in a memory buffer that is acceptable for the codec if you do not use any horizontal padding.

May only be used if a codec with AV_CODEC_CAP_DR1 has been opened.

◆ avcodec_align_dimensions2()

void avcodec_align_dimensions2 ( AVCodecContext s,
int *  width,
int *  height,
int  linesize_align[AV_NUM_DATA_POINTERS] 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavcodec/avcodec.h>

Modify width and height values so that they will result in a memory buffer that is acceptable for the codec if you also ensure that all line sizes are a multiple of the respective linesize_align[i].

May only be used if a codec with AV_CODEC_CAP_DR1 has been opened.

◆ avcodec_enum_to_chroma_pos()

int avcodec_enum_to_chroma_pos ( int *  xpos,
int *  ypos,
enum AVChromaLocation  pos 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavcodec/avcodec.h>

Converts AVChromaLocation to swscale x/y chroma position.

The positions represent the chroma (0,0) position in a coordinates system with luma (0,0) representing the origin and luma(1,1) representing 256,256

Аргументы
xposhorizontal chroma sample position
yposvertical chroma sample position

◆ avcodec_chroma_pos_to_enum()

enum AVChromaLocation avcodec_chroma_pos_to_enum ( int  xpos,
int  ypos 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavcodec/avcodec.h>

Converts swscale x/y chroma position to AVChromaLocation.

The positions represent the chroma (0,0) position in a coordinates system with luma (0,0) representing the origin and luma(1,1) representing 256,256

Аргументы
xposhorizontal chroma sample position
yposvertical chroma sample position

◆ avcodec_decode_audio4()

attribute_deprecated int avcodec_decode_audio4 ( AVCodecContext avctx,
AVFrame frame,
int *  got_frame_ptr,
const AVPacket avpkt 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavcodec/avcodec.h>

Decode the audio frame of size avpkt->size from avpkt->data into frame.

Some decoders may support multiple frames in a single AVPacket. Such decoders would then just decode the first frame and the return value would be less than the packet size. In this case, avcodec_decode_audio4 has to be called again with an AVPacket containing the remaining data in order to decode the second frame, etc... Even if no frames are returned, the packet needs to be fed to the decoder with remaining data until it is completely consumed or an error occurs.

Some decoders (those marked with AV_CODEC_CAP_DELAY) have a delay between input and output. This means that for some packets they will not immediately produce decoded output and need to be flushed at the end of decoding to get all the decoded data. Flushing is done by calling this function with packets with avpkt->data set to NULL and avpkt->size set to 0 until it stops returning samples. It is safe to flush even those decoders that are not marked with AV_CODEC_CAP_DELAY, then no samples will be returned.

Предупреждения
The input buffer, avpkt->data must be AV_INPUT_BUFFER_PADDING_SIZE larger than the actual read bytes because some optimized bitstream readers read 32 or 64 bits at once and could read over the end.
Заметки
The AVCodecContext MUST have been opened with avcodec_open2() before packets may be fed to the decoder.
Аргументы
avctxthe codec context
[out]frameThe AVFrame in which to store decoded audio samples. The decoder will allocate a buffer for the decoded frame by calling the AVCodecContext.get_buffer2() callback. When AVCodecContext.refcounted_frames is set to 1, the frame is reference counted and the returned reference belongs to the caller. The caller must release the frame using av_frame_unref() when the frame is no longer needed. The caller may safely write to the frame if av_frame_is_writable() returns 1. When AVCodecContext.refcounted_frames is set to 0, the returned reference belongs to the decoder and is valid only until the next call to this function or until closing or flushing the decoder. The caller may not write to it.
[out]got_frame_ptrZero if no frame could be decoded, otherwise it is non-zero. Note that this field being set to zero does not mean that an error has occurred. For decoders with AV_CODEC_CAP_DELAY set, no given decode call is guaranteed to produce a frame.
[in]avpktThe input AVPacket containing the input buffer. At least avpkt->data and avpkt->size should be set. Some decoders might also require additional fields to be set.
Возвращает
A negative error code is returned if an error occurred during decoding, otherwise the number of bytes consumed from the input AVPacket is returned.
Уст.:
Use avcodec_send_packet() and avcodec_receive_frame().

◆ avcodec_decode_video2()

attribute_deprecated int avcodec_decode_video2 ( AVCodecContext avctx,
AVFrame picture,
int *  got_picture_ptr,
const AVPacket avpkt 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavcodec/avcodec.h>

Decode the video frame of size avpkt->size from avpkt->data into picture. Some decoders may support multiple frames in a single AVPacket, such decoders would then just decode the first frame.

Предупреждения
The input buffer must be AV_INPUT_BUFFER_PADDING_SIZE larger than the actual read bytes because some optimized bitstream readers read 32 or 64 bits at once and could read over the end.
The end of the input buffer buf should be set to 0 to ensure that no overreading happens for damaged MPEG streams.
Заметки
Codecs which have the AV_CODEC_CAP_DELAY capability set have a delay between input and output, these need to be fed with avpkt->data=NULL, avpkt->size=0 at the end to return the remaining frames.
The AVCodecContext MUST have been opened with avcodec_open2() before packets may be fed to the decoder.
Аргументы
avctxthe codec context
[out]pictureThe AVFrame in which the decoded video frame will be stored. Use av_frame_alloc() to get an AVFrame. The codec will allocate memory for the actual bitmap by calling the AVCodecContext.get_buffer2() callback. When AVCodecContext.refcounted_frames is set to 1, the frame is reference counted and the returned reference belongs to the caller. The caller must release the frame using av_frame_unref() when the frame is no longer needed. The caller may safely write to the frame if av_frame_is_writable() returns 1. When AVCodecContext.refcounted_frames is set to 0, the returned reference belongs to the decoder and is valid only until the next call to this function or until closing or flushing the decoder. The caller may not write to it.
[in]avpktThe input AVPacket containing the input buffer. You can create such packet with av_init_packet() and by then setting data and size, some decoders might in addition need other fields like flags&AV_PKT_FLAG_KEY. All decoders are designed to use the least fields possible.
[in,out]got_picture_ptrZero if no frame could be decompressed, otherwise, it is nonzero.
Возвращает
On error a negative value is returned, otherwise the number of bytes used or zero if no frame could be decompressed.
Уст.:
Use avcodec_send_packet() and avcodec_receive_frame().

◆ avcodec_decode_subtitle2()

int avcodec_decode_subtitle2 ( AVCodecContext avctx,
AVSubtitle sub,
int *  got_sub_ptr,
AVPacket avpkt 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavcodec/avcodec.h>

Decode a subtitle message. Return a negative value on error, otherwise return the number of bytes used. If no subtitle could be decompressed, got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. Note that AV_CODEC_CAP_DR1 is not available for subtitle codecs. This is for simplicity, because the performance difference is expect to be negligible and reusing a get_buffer written for video codecs would probably perform badly due to a potentially very different allocation pattern.

Some decoders (those marked with AV_CODEC_CAP_DELAY) have a delay between input and output. This means that for some packets they will not immediately produce decoded output and need to be flushed at the end of decoding to get all the decoded data. Flushing is done by calling this function with packets with avpkt->data set to NULL and avpkt->size set to 0 until it stops returning subtitles. It is safe to flush even those decoders that are not marked with AV_CODEC_CAP_DELAY, then no subtitles will be returned.

Заметки
The AVCodecContext MUST have been opened with avcodec_open2() before packets may be fed to the decoder.
Аргументы
avctxthe codec context
[out]subThe Preallocated AVSubtitle in which the decoded subtitle will be stored, must be freed with avsubtitle_free if *got_sub_ptr is set.
[in,out]got_sub_ptrZero if no subtitle could be decompressed, otherwise, it is nonzero.
[in]avpktThe input AVPacket containing the input buffer.

◆ avcodec_send_packet()

int avcodec_send_packet ( AVCodecContext avctx,
const AVPacket avpkt 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavcodec/avcodec.h>

Supply raw packet data as input to a decoder.

Internally, this call will copy relevant AVCodecContext fields, which can influence decoding per-packet, and apply them when the packet is actually decoded. (For example AVCodecContext.skip_frame, which might direct the decoder to drop the frame contained by the packet sent with this function.)

Предупреждения
The input buffer, avpkt->data must be AV_INPUT_BUFFER_PADDING_SIZE larger than the actual read bytes because some optimized bitstream readers read 32 or 64 bits at once and could read over the end.
Do not mix this API with the legacy API (like avcodec_decode_video2()) on the same AVCodecContext. It will return unexpected results now or in future libavcodec versions.
Заметки
The AVCodecContext MUST have been opened with avcodec_open2() before packets may be fed to the decoder.
Аргументы
avctxcodec context
[in]avpktThe input AVPacket. Usually, this will be a single video frame, or several complete audio frames. Ownership of the packet remains with the caller, and the decoder will not write to the packet. The decoder may create a reference to the packet data (or copy it if the packet is not reference-counted). Unlike with older APIs, the packet is always fully consumed, and if it contains multiple frames (e.g. some audio codecs), will require you to call avcodec_receive_frame() multiple times afterwards before you can send a new packet. It can be NULL (or an AVPacket with data set to NULL and size set to 0); in this case, it is considered a flush packet, which signals the end of the stream. Sending the first flush packet will return success. Subsequent ones are unnecessary and will return AVERROR_EOF. If the decoder still has frames buffered, it will return them after sending a flush packet.
Возвращает
0 on success, otherwise negative error code: AVERROR(EAGAIN): input is not accepted in the current state - user must read output with avcodec_receive_frame() (once all output is read, the packet should be resent, and the call will not fail with EAGAIN). AVERROR_EOF: the decoder has been flushed, and no new packets can be sent to it (also returned if more than 1 flush packet is sent) AVERROR(EINVAL): codec not opened, it is an encoder, or requires flush AVERROR(ENOMEM): failed to add packet to internal queue, or similar other errors: legitimate decoding errors

Используется в AVAudioStream::decode_frame(), AVVideoStream::decode_frame() и AudioBaseDataSource::GetNextBuffer().

+ Граф вызова функции:

◆ avcodec_receive_frame()

int avcodec_receive_frame ( AVCodecContext avctx,
AVFrame frame 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavcodec/avcodec.h>

Return decoded output data from a decoder.

Аргументы
avctxcodec context
frameThis will be set to a reference-counted video or audio frame (depending on the decoder type) allocated by the decoder. Note that the function will always call av_frame_unref(frame) before doing anything else.
Возвращает
0: success, a frame was returned AVERROR(EAGAIN): output is not available in this state - user must try to send new input AVERROR_EOF: the decoder has been fully flushed, and there will be no more output frames AVERROR(EINVAL): codec not opened, or it is an encoder AVERROR_INPUT_CHANGED: current decoded frame has changed parameters with respect to first decoded frame. Applicable when flag AV_CODEC_FLAG_DROPCHANGED is set. other negative values: legitimate decoding errors

Используется в AVAudioStream::decode_frame(), AVVideoStream::decode_frame() и AudioBaseDataSource::GetNextBuffer().

+ Граф вызова функции:

◆ avcodec_send_frame()

int avcodec_send_frame ( AVCodecContext avctx,
const AVFrame frame 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavcodec/avcodec.h>

Supply a raw video or audio frame to the encoder. Use avcodec_receive_packet() to retrieve buffered output packets.

Аргументы
avctxcodec context
[in]frameAVFrame containing the raw audio or video frame to be encoded. Ownership of the frame remains with the caller, and the encoder will not write to the frame. The encoder may create a reference to the frame data (or copy it if the frame is not reference-counted). It can be NULL, in which case it is considered a flush packet. This signals the end of the stream. If the encoder still has packets buffered, it will return them after this call. Once flushing mode has been entered, additional flush packets are ignored, and sending frames will return AVERROR_EOF.

For audio: If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame can have any number of samples. If it is not set, frame->nb_samples must be equal to avctx->frame_size for all frames except the last. The final frame may be smaller than avctx->frame_size.

Возвращает
0 on success, otherwise negative error code: AVERROR(EAGAIN): input is not accepted in the current state - user must read output with avcodec_receive_packet() (once all output is read, the packet should be resent, and the call will not fail with EAGAIN). AVERROR_EOF: the encoder has been flushed, and no new frames can be sent to it AVERROR(EINVAL): codec not opened, refcounted_frames not set, it is a decoder, or requires flush AVERROR(ENOMEM): failed to add packet to internal queue, or similar other errors: legitimate decoding errors

◆ avcodec_receive_packet()

int avcodec_receive_packet ( AVCodecContext avctx,
AVPacket avpkt 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavcodec/avcodec.h>

Read encoded data from the encoder.

Аргументы
avctxcodec context
avpktThis will be set to a reference-counted packet allocated by the encoder. Note that the function will always call av_frame_unref(frame) before doing anything else.
Возвращает
0 on success, otherwise negative error code: AVERROR(EAGAIN): output is not available in the current state - user must try to send input AVERROR_EOF: the encoder has been fully flushed, and there will be no more output packets AVERROR(EINVAL): codec not opened, or it is an encoder other errors: legitimate decoding errors

◆ avcodec_get_hw_frames_parameters()

int avcodec_get_hw_frames_parameters ( AVCodecContext avctx,
AVBufferRef device_ref,
enum AVPixelFormat  hw_pix_fmt,
AVBufferRef **  out_frames_ref 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavcodec/avcodec.h>

Create and return a AVHWFramesContext with values adequate for hardware decoding. This is meant to get called from the get_format callback, and is a helper for preparing a AVHWFramesContext for AVCodecContext.hw_frames_ctx. This API is for decoding with certain hardware acceleration modes/APIs only.

The returned AVHWFramesContext is not initialized. The caller must do this with av_hwframe_ctx_init().

Calling this function is not a requirement, but makes it simpler to avoid codec or hardware API specific details when manually allocating frames.

Alternatively to this, an API user can set AVCodecContext.hw_device_ctx, which sets up AVCodecContext.hw_frames_ctx fully automatically, and makes it unnecessary to call this function or having to care about AVHWFramesContext initialization at all.

There are a number of requirements for calling this function:

  • It must be called from get_format with the same avctx parameter that was passed to get_format. Calling it outside of get_format is not allowed, and can trigger undefined behavior.
  • The function is not always supported (see description of return values). Even if this function returns successfully, hwaccel initialization could fail later. (The degree to which implementations check whether the stream is actually supported varies. Some do this check only after the user's get_format callback returns.)
  • The hw_pix_fmt must be one of the choices suggested by get_format. If the user decides to use a AVHWFramesContext prepared with this API function, the user must return the same hw_pix_fmt from get_format.
  • The device_ref passed to this function must support the given hw_pix_fmt.
  • After calling this API function, it is the user's responsibility to initialize the AVHWFramesContext (returned by the out_frames_ref parameter), and to set AVCodecContext.hw_frames_ctx to it. If done, this must be done before returning from get_format (this is implied by the normal AVCodecContext.hw_frames_ctx API rules).
  • The AVHWFramesContext parameters may change every time time get_format is called. Also, AVCodecContext.hw_frames_ctx is reset before get_format. So you are inherently required to go through this process again on every get_format call.
  • It is perfectly possible to call this function without actually using the resulting AVHWFramesContext. One use-case might be trying to reuse a previously initialized AVHWFramesContext, and calling this API function only to test whether the required frame parameters have changed.
  • Fields that use dynamically allocated values of any kind must not be set by the user unless setting them is explicitly allowed by the documentation. If the user sets AVHWFramesContext.free and AVHWFramesContext.user_opaque, the new free callback must call the potentially set previous free callback. This API call may set any dynamically allocated fields, including the free callback.

The function will set at least the following fields on AVHWFramesContext (potentially more, depending on hwaccel API):

  • All fields set by av_hwframe_ctx_alloc().
  • Set the format field to hw_pix_fmt.
  • Set the sw_format field to the most suited and most versatile format. (An implication is that this will prefer generic formats over opaque formats with arbitrary restrictions, if possible.)
  • Set the width/height fields to the coded frame size, rounded up to the API-specific minimum alignment.
  • Only if the hwaccel requires a pre-allocated pool: set the initial_pool_size field to the number of maximum reference surfaces possible with the codec, plus 1 surface for the user to work (meaning the user can safely reference at most 1 decoded surface at a time), plus additional buffering introduced by frame threading. If the hwaccel does not require pre-allocation, the field is left to 0, and the decoder will allocate new surfaces on demand during decoding.
  • Possibly AVHWFramesContext.hwctx fields, depending on the underlying hardware API.

Essentially, out_frames_ref returns the same as av_hwframe_ctx_alloc(), but with basic frame parameters set.

The function is stateless, and does not change the AVCodecContext or the device_ref AVHWDeviceContext.

Аргументы
avctxThe context which is currently calling get_format, and which implicitly contains all state needed for filling the returned AVHWFramesContext properly.
device_refA reference to the AVHWDeviceContext describing the device which will be used by the hardware decoder.
hw_pix_fmtThe hwaccel format you are going to return from get_format.
out_frames_refOn success, set to a reference to an uninitialized AVHWFramesContext, created from the given device_ref. Fields will be set to values required for decoding. Not changed if an error is returned.
Возвращает
zero on success, a negative value on error. The following error codes have special semantics: AVERROR(ENOENT): the decoder does not support this functionality. Setup is always manual, or it is a decoder which does not support setting AVCodecContext.hw_frames_ctx at all, or it is a software format. AVERROR(EINVAL): it is known that hardware decoding is not supported for this configuration, or the device_ref is not supported for the hwaccel referenced by hw_pix_fmt.
AVDISCARD_NONE
@ AVDISCARD_NONE
discard nothing
Definition: avcodec.h:805
AVDISCARD_BIDIR
@ AVDISCARD_BIDIR
discard all bidirectional frames
Definition: avcodec.h:808
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: avcodec.h:811
AVDISCARD_NONKEY
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition: avcodec.h:810
AVDISCARD_DEFAULT
@ AVDISCARD_DEFAULT
discard useless packets like 0 size packets in avi
Definition: avcodec.h:806
AVDISCARD_NONINTRA
@ AVDISCARD_NONINTRA
discard all non intra frames
Definition: avcodec.h:809
AVDISCARD_NONREF
@ AVDISCARD_NONREF
discard all non reference
Definition: avcodec.h:807