Go to the documentation of this file.
24 #include <sys/types.h>
86 #define INPUT_DEQUEUE_TIMEOUT_US 8000
87 #define OUTPUT_DEQUEUE_TIMEOUT_US 8000
88 #define OUTPUT_DEQUEUE_BLOCK_TIMEOUT_US 1000000
124 av_log(avctx,
AV_LOG_ERROR,
"Output sample format 0x%x (value=%d) is not supported\n",
152 static const struct {
181 uint64_t channel_layout = 0;
188 return channel_layout;
203 static const struct {
280 AVMediaCodecBuffer *
buffer = opaque;
287 "Releasing output buffer %zd (%p) ts=%"PRId64
" on free() [%d pending]\n",
339 if (!
frame->buf[0]) {
356 "Wrapping output buffer %zd (%p) ts=%"PRId64
" [%d pending]\n",
422 "Frame: format=%d channels=%d sample_rate=%d nb_samples=%d",
475 "Frame: width=%d stride=%d height=%d slice-height=%d "
476 "crop-top=%d crop-bottom=%d crop-left=%d crop-right=%d encoder=%s "
477 "destination linesizes=%d,%d,%d\n" ,
479 s->crop_top,
s->crop_bottom,
s->crop_left,
s->crop_right,
s->codec_name,
482 switch (
s->color_format) {
500 s->color_format,
s->color_format);
532 #define AMEDIAFORMAT_GET_INT32(name, key, mandatory) do { \
534 if (ff_AMediaFormat_getInt32(s->format, key, &value)) { \
536 } else if (mandatory) { \
537 av_log(avctx, AV_LOG_ERROR, "Could not get %s from format %s\n", key, format); \
538 ret = AVERROR_EXTERNAL; \
549 int color_standard = 0;
550 int color_transfer = 0;
569 s->stride =
s->stride > 0 ?
s->stride :
s->width;
573 if (strstr(
s->codec_name,
"OMX.Nvidia.") &&
s->slice_height == 0) {
574 s->slice_height =
FFALIGN(
s->height, 16);
575 }
else if (strstr(
s->codec_name,
"OMX.SEC.avc.dec")) {
576 s->slice_height = avctx->
height;
578 }
else if (
s->slice_height == 0) {
579 s->slice_height =
s->height;
598 if (!(
s->crop_right &&
s->crop_bottom) &&
s->use_ndk_codec && !strstr(
s->codec_name,
".mtk."))
601 if (
s->crop_right &&
s->crop_bottom) {
602 width =
s->crop_right + 1 -
s->crop_left;
603 height =
s->crop_bottom + 1 -
s->crop_top;
619 if (
s->display_width &&
s->display_height) {
631 if (color_standard) {
641 "Output crop parameters top=%d bottom=%d left=%d right=%d, "
642 "resulting dimensions width=%d height=%d\n",
643 s->crop_top,
s->crop_bottom,
s->crop_left,
s->crop_right,
657 int channel_count = 0;
658 int channel_mask = 0;
659 int pcm_encoding = 0;
692 "Output parameters channel-count=%d channel-layout=%x sample-rate=%d\n",
693 channel_count, channel_mask, sample_rate);
715 s->output_buffer_count = 0;
722 s->current_input_buffer = -1;
751 if (device_ctx->
hwctx) {
759 if (!
s->surface && user_ctx && user_ctx->
surface) {
771 if (!
s->codec_name) {
774 if (!
s->use_ndk_codec) {
793 av_log(avctx,
AV_LOG_ERROR,
"Failed to create media decoder for type %s and name %s\n", mime,
s->codec_name);
810 if (!
s->codec_name) {
829 s->current_input_buffer = -1;
844 "Failed to configure codec %s (status = %d) with format %s\n",
856 "Failed to start codec %s (status = %d) with format %s\n",
868 "Failed to configure context\n");
888 int need_draining = 0;
898 "until all output buffers have been released\n");
906 if (
s->draining &&
s->eos) {
910 while (offset < pkt->
size || (need_draining && !
s->draining)) {
911 ssize_t
index =
s->current_input_buffer;
924 s->current_input_buffer = -1;
953 "Queued empty EOS input buffer %zd with flags=%d\n",
index,
flags);
970 "Queued input buffer %zd size=%zd ts=%"PRIi64
"\n",
index,
size,
pts);
990 if (
s->draining &&
s->eos) {
998 }
else if (
s->output_buffer_count == 0 || !wait) {
1002 output_dequeue_timeout_us = 0;
1008 " offset=%" PRIi32
" size=%" PRIi32
" ts=%" PRIi64
1010 info.presentationTimeUs,
info.flags);
1035 s->output_buffer_count++;
1076 "while draining remaining frames, output will probably lack frames\n",
1077 output_dequeue_timeout_us / 1000);
1086 if (
s->draining &&
s->eos)
1105 if (!
s->surface || !
s->delay_flush ||
atomic_load(&
s->refcount) == 1) {
1131 av_log(avctx,
AV_LOG_DEBUG,
"Not stopping MediaCodec (there are buffers pending)\n");
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
void * hwaccel_context
Legacy hardware accelerator context.
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel format.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
enum AVColorSpace colorspace
YUV colorspace type.
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
#define AV_CH_TOP_FRONT_CENTER
int sample_rate
samples per second
#define atomic_fetch_add(object, operand)
#define AVERROR_EOF
End of file.
uint8_t * data
The data buffer.
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
void * surface
android/view/Surface handle, to be filled by the user.
#define AV_CH_TOP_FRONT_RIGHT
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
@ AV_HWDEVICE_TYPE_MEDIACODEC
#define AV_CH_TOP_FRONT_LEFT
#define atomic_fetch_sub(object, operand)
int nb_channels
Number of channels in this layout.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
#define AV_CH_TOP_BACK_LEFT
#define AV_CH_TOP_BACK_CENTER
AVChannelLayout ch_layout
Audio channel layout.
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
#define AV_CH_LOW_FREQUENCY
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask)
Initialize a native channel layout from a bitmask indicating which channels are present.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static enum AVPixelFormat pix_fmts[]
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define atomic_load(object)
@ AV_PIX_FMT_MEDIACODEC
hardware decoding through MediaCodec
enum AVColorRange color_range
MPEG vs JPEG YUV range.
This structure holds a reference to a android/view/Surface object that will be used as output by the ...
Rational number (pair of numerator and denominator).
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
#define AV_CH_FRONT_CENTER
#define AV_CH_FRONT_LEFT_OF_CENTER
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
enum AVSampleFormat sample_fmt
audio sample format
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AVERROR_EXTERNAL
Generic error in an external library.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
#define AV_CH_TOP_BACK_RIGHT
#define AV_CH_FRONT_RIGHT_OF_CENTER
#define AV_LOG_INFO
Standard information.
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
@ AV_SAMPLE_FMT_U8
unsigned 8 bits
AVSampleFormat
Audio sample formats.
#define AV_CH_BACK_CENTER
@ AV_SAMPLE_FMT_S16
signed 16 bits
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
void * surface
android/view/Surface object reference.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
void * native_window
Pointer to ANativeWindow.
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
main external API structure.
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
#define AV_CH_FRONT_RIGHT
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
enum AVMediaType codec_type
char * av_strdup(const char *s)
Duplicate a string.
This structure stores compressed data.
int width
picture width / height.
#define flags(name, subs,...)
#define atomic_init(obj, value)
@ AV_SAMPLE_FMT_S32
signed 32 bits
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.