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",
181 uint64_t channel_layout = 0;
188 return channel_layout;
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",
428 "Frame: format=%d channels=%d sample_rate=%d nb_samples=%d",
481 "Frame: width=%d stride=%d height=%d slice-height=%d "
482 "crop-top=%d crop-bottom=%d crop-left=%d crop-right=%d encoder=%s "
483 "destination linesizes=%d,%d,%d\n" ,
485 s->crop_top,
s->crop_bottom,
s->crop_left,
s->crop_right,
s->codec_name,
488 switch (
s->color_format) {
506 s->color_format,
s->color_format);
538#define AMEDIAFORMAT_GET_INT32(name, key, mandatory) do { \
540 if (ff_AMediaFormat_getInt32(s->format, key, &value)) { \
542 } else if (mandatory) { \
543 av_log(avctx, AV_LOG_ERROR, "Could not get %s from format %s\n", key, format); \
544 ret = AVERROR_EXTERNAL; \
557 int color_standard = 0;
558 int color_transfer = 0;
577 s->stride =
s->stride > 0 ?
s->stride :
s->width;
581 if (strstr(
s->codec_name,
"OMX.Nvidia.") &&
s->slice_height == 0) {
582 s->slice_height =
FFALIGN(
s->height, 16);
583 }
else if (strstr(
s->codec_name,
"OMX.SEC.avc.dec")) {
584 s->slice_height = avctx->
height;
586 }
else if (strstr(
s->codec_name,
"OMX.MTK.VIDEO.DECODER.MPEG2")) {
587 s->slice_height =
s->height;
588 }
else if (
s->slice_height == 0) {
589 s->slice_height =
s->height;
608 if (!(
s->crop_right &&
s->crop_bottom) &&
s->use_ndk_codec && !strstr(
s->codec_name,
".mtk."))
611 if (
s->crop_right &&
s->crop_bottom) {
612 width =
s->crop_right + 1 -
s->crop_left;
613 height =
s->crop_bottom + 1 -
s->crop_top;
629 if (
s->display_width &&
s->display_height) {
641 if (color_standard) {
651 "Output crop parameters top=%d bottom=%d left=%d right=%d, "
652 "resulting dimensions width=%d height=%d\n",
653 s->crop_top,
s->crop_bottom,
s->crop_left,
s->crop_right,
667 int channel_count = 0;
668 int channel_mask = 0;
669 int pcm_encoding = 0;
702 "Output parameters channel-count=%d channel-layout=%x sample-rate=%d\n",
703 channel_count, channel_mask, sample_rate);
725 s->output_buffer_count = 0;
732 s->current_input_buffer = -1;
761 if (device_ctx->
hwctx) {
769 if (!
s->surface && user_ctx && user_ctx->
surface) {
785 if (!
s->codec_name) {
789 if (!
s->use_ndk_codec) {
807 av_log(avctx,
AV_LOG_ERROR,
"Failed to create media decoder for type %s and name %s\n", mime,
s->codec_name);
824 if (!
s->codec_name) {
843 s->current_input_buffer = -1;
858 "Failed to configure codec %s (status = %d) with format %s\n",
859 s->codec_name, status,
desc);
870 "Failed to start codec %s (status = %d) with format %s\n",
871 s->codec_name, status,
desc);
882 "Failed to configure context\n");
902 int need_draining = 0;
912 "until all output buffers have been released\n");
916 if (
pkt->size == 0) {
920 if (
s->draining &&
s->eos) {
925 ssize_t
index =
s->current_input_buffer;
938 s->current_input_buffer = -1;
962 av_log(avctx,
AV_LOG_ERROR,
"Failed to queue input empty buffer (status = %d)\n", status);
967 "Queued empty EOS input buffer %zd with flags=%d\n",
index,
flags);
984 "Queued input buffer %zd size=%zd ts=%"PRIi64
"\n",
index,
size,
pts);
1004 if (
s->draining &&
s->eos) {
1012 }
else if (
s->output_buffer_count == 0 || !wait) {
1016 output_dequeue_timeout_us = 0;
1022 " offset=%" PRIi32
" size=%" PRIi32
" ts=%" PRIi64
1049 s->output_buffer_count++;
1090 "while draining remaining frames, output will probably lack frames\n",
1091 output_dequeue_timeout_us / 1000);
1100 if (
s->draining &&
s->eos)
1119 if (!
s->surface || !
s->delay_flush ||
atomic_load(&
s->refcount) == 1) {
1145 av_log(avctx,
AV_LOG_DEBUG,
"Not stopping MediaCodec (there are buffers pending)\n");
static const char *const format[]
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
common internal and external API header
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
static enum AVPixelFormat pix_fmt
#define atomic_load(object)
#define atomic_init(obj, value)
#define AV_CH_TOP_FRONT_LEFT
#define AV_CH_FRONT_RIGHT
#define AV_CH_TOP_BACK_CENTER
#define AV_CH_FRONT_RIGHT_OF_CENTER
#define AV_CH_BACK_CENTER
#define AV_CH_TOP_FRONT_CENTER
#define AV_CH_FRONT_LEFT_OF_CENTER
#define AV_CH_FRONT_CENTER
#define AV_CH_TOP_BACK_RIGHT
#define AV_CH_TOP_BACK_LEFT
#define AV_CH_LOW_FREQUENCY
#define AV_CH_TOP_FRONT_RIGHT
#define AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH
Hardware acceleration should still be attempted for decoding when the codec profile does not match th...
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
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.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
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.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_EOF
End of file.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_S32
signed 32 bits
@ AV_SAMPLE_FMT_U8
unsigned 8 bits
@ AV_SAMPLE_FMT_S16
signed 16 bits
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
@ AV_HWDEVICE_TYPE_MEDIACODEC
static enum AVPixelFormat pix_fmts[]
static const uint16_t mask[17]
Memory handling functions.
AVPixelFormat
Pixel format.
@ 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...
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_MEDIACODEC
hardware decoding through MediaCodec
#define FF_ARRAY_ELEMS(a)
uint8_t * data
The data buffer.
int nb_channels
Number of channels in this layout.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int hwaccel_flags
Bit set of AV_HWACCEL_FLAG_* flags, which affect hardware accelerated decoding (if active).
int width
picture width / height.
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
enum AVColorRange color_range
MPEG vs JPEG YUV range.
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
enum AVMediaType codec_type
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
enum AVColorSpace colorspace
YUV colorspace type.
int sample_rate
samples per second
void * hwaccel_context
Legacy hardware accelerator context.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
This structure describes decoded (raw) audio or video data.
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
This structure holds a reference to a android/view/Surface object that will be used as output by the ...
void * surface
android/view/Surface object reference.
void * native_window
Pointer to ANativeWindow.
void * surface
android/view/Surface handle, to be filled by the user.
This structure stores compressed data.
Rational number (pair of numerator and denominator).
static AVFormatContext * ctx
timestamp utils, mostly useful for debugging/logging purposes
#define atomic_fetch_sub(object, operand)
#define atomic_fetch_add(object, operand)