FFmpeg
Loading...
Searching...
No Matches
mediacodecenc.c File Reference
#include "config_components.h"
#include "libavutil/avassert.h"
#include "libavutil/fifo.h"
#include "libavutil/avstring.h"
#include "libavutil/hwcontext_mediacodec.h"
#include "libavutil/imgutils.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/thread.h"
#include "avcodec.h"
#include "bsf.h"
#include "codec_internal.h"
#include "encode.h"
#include "hwconfig.h"
#include "jni.h"
#include "mediacodec.h"
#include "mediacodec_wrapper.h"
#include "mediacodecdec_common.h"
#include "profiles.h"

Go to the source code of this file.

Data Structures

struct  MediaCodecAsyncOutput
 
struct  MediaCodecEncContext
 

Macros

#define INPUT_DEQUEUE_TIMEOUT_US   8000
 
#define OUTPUT_DEQUEUE_TIMEOUT_US   8000
 
#define OFFSET(x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 
#define COMMON_OPTION
 
#define MEDIACODEC_ENCODER_CLASS(name)
 
#define DECLARE_MEDIACODEC_ENCODER(short_name, long_name, codec_id)
 

Enumerations

enum  BitrateMode { BITRATE_MODE_CQ = 0 , BITRATE_MODE_VBR = 1 , BITRATE_MODE_CBR = 2 , BITRATE_MODE_CBR_FD = 3 }
 
enum  { COLOR_FormatYUV420Planar = 0x13 , COLOR_FormatYUV420SemiPlanar = 0x15 , COLOR_FormatSurface = 0x7F000789 }
 

Functions

static void mediacodec_dump_format (AVCodecContext *avctx, FFAMediaFormat *out_format)
 
static void mediacodec_output_format (AVCodecContext *avctx)
 
static int extract_extradata_support (AVCodecContext *avctx)
 
static int mediacodec_init_bsf (AVCodecContext *avctx)
 
static void copy_frame_to_buffer (AVCodecContext *avctx, const AVFrame *frame, uint8_t *dst, size_t size)
 
static void on_error (FFAMediaCodec *codec, void *userdata, int error, const char *detail)
 
static void on_input_available (FFAMediaCodec *codec, void *userdata, int32_t index)
 
static void on_output_available (FFAMediaCodec *codec, void *userdata, int32_t index, FFAMediaCodecBufferInfo *out_info)
 
static void on_format_changed (FFAMediaCodec *codec, void *userdata, FFAMediaFormat *format)
 
static int mediacodec_init_async_state (AVCodecContext *avctx)
 
static void mediacodec_uninit_async_state (AVCodecContext *avctx)
 
static int mediacodec_generate_extradata (AVCodecContext *avctx)
 
static void mediacodec_set_qp_range (AVCodecContext *avctx, FFAMediaFormat *format)
 
static av_cold int mediacodec_init (AVCodecContext *avctx)
 
static int mediacodec_get_output_index (AVCodecContext *avctx, ssize_t *index, FFAMediaCodecBufferInfo *out_info)
 
static int mediacodec_receive (AVCodecContext *avctx, AVPacket *pkt)
 
static int mediacodec_get_input_index (AVCodecContext *avctx, ssize_t *index)
 
static int mediacodec_send (AVCodecContext *avctx, const AVFrame *frame)
 
static int mediacodec_encode (AVCodecContext *avctx, AVPacket *pkt)
 
static int mediacodec_send_dummy_frame (AVCodecContext *avctx)
 
static int mediacodec_receive_dummy_pkt (AVCodecContext *avctx, AVPacket *pkt)
 
static av_cold int mediacodec_close (AVCodecContext *avctx)
 
static av_cold void mediacodec_flush (AVCodecContext *avctx)
 

Variables

struct { 
 
   int   color_format 
 
   enum AVPixelFormat   pix_fmt 
 
color_formats [] 
 
static enum AVPixelFormat avc_pix_fmts []
 
static const AVCodecHWConfigInternal *const mediacodec_hw_configs []
 
static const FFCodecDefault mediacodec_defaults []
 

Macro Definition Documentation

◆ INPUT_DEQUEUE_TIMEOUT_US

#define INPUT_DEQUEUE_TIMEOUT_US   8000

Definition at line 45 of file mediacodecenc.c.

◆ OUTPUT_DEQUEUE_TIMEOUT_US

#define OUTPUT_DEQUEUE_TIMEOUT_US   8000

Definition at line 46 of file mediacodecenc.c.

◆ OFFSET

#define OFFSET ( x)
Value:

Definition at line 1040 of file mediacodecenc.c.

◆ VE

Definition at line 1041 of file mediacodecenc.c.

◆ COMMON_OPTION

#define COMMON_OPTION

Definition at line 1042 of file mediacodecenc.c.

◆ MEDIACODEC_ENCODER_CLASS

#define MEDIACODEC_ENCODER_CLASS ( name)
Value:
static const AVClass name ## _mediacodec_class = { \
.class_name = #name "_mediacodec", \
.item_name = av_default_item_name, \
.option = name ## _options, \
.version = LIBAVUTIL_VERSION_INT, \
}; \
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
const char * name
Definition qsvenc.c:142
Describe the class of an AVClass context structure.
Definition log.h:76

Definition at line 1078 of file mediacodecenc.c.

◆ DECLARE_MEDIACODEC_ENCODER

#define DECLARE_MEDIACODEC_ENCODER ( short_name,
long_name,
codec_id )
Value:
const FFCodec ff_ ## short_name ## _mediacodec_encoder = { \
.p.name = #short_name "_mediacodec", \
CODEC_LONG_NAME(long_name " Android MediaCodec encoder"), \
.p.type = AVMEDIA_TYPE_VIDEO, \
.p.id = codec_id, \
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | \
.priv_data_size = sizeof(MediaCodecEncContext), \
.color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG, \
.defaults = mediacodec_defaults, \
.init = mediacodec_init, \
FF_CODEC_RECEIVE_PACKET_CB(mediacodec_encode), \
.close = mediacodec_close, \
.flush = mediacodec_flush, \
.p.priv_class = &short_name ## _mediacodec_class, \
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
.p.wrapper_name = "mediacodec", \
.hw_configs = mediacodec_hw_configs, \
}; \
#define CODEC_PIXFMTS_ARRAY(array)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define AV_CODEC_CAP_ENCODER_FLUSH
This encoder can be flushed using avcodec_flush_buffers().
Definition codec.h:154
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition codec.h:79
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
Definition codec.h:133
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
static const AVCodecHWConfigInternal *const mediacodec_hw_configs[]
static const FFCodecDefault mediacodec_defaults[]
static int mediacodec_encode(AVCodecContext *avctx, AVPacket *pkt)
static enum AVPixelFormat avc_pix_fmts[]
static av_cold int mediacodec_init(AVCodecContext *avctx)
#define MEDIACODEC_ENCODER_CLASS(name)
static av_cold void mediacodec_flush(AVCodecContext *avctx)
static av_cold int mediacodec_close(AVCodecContext *avctx)
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:766
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:783
enum AVCodecID codec_id

Definition at line 1086 of file mediacodecenc.c.

Enumeration Type Documentation

◆ BitrateMode

Enumerator
BITRATE_MODE_CQ 
BITRATE_MODE_VBR 
BITRATE_MODE_CBR 
BITRATE_MODE_CBR_FD 

Definition at line 48 of file mediacodecenc.c.

◆ anonymous enum

anonymous enum
Enumerator
COLOR_FormatYUV420Planar 
COLOR_FormatYUV420SemiPlanar 
COLOR_FormatSurface 

Definition at line 107 of file mediacodecenc.c.

Function Documentation

◆ mediacodec_dump_format()

static void mediacodec_dump_format ( AVCodecContext * avctx,
FFAMediaFormat * out_format )
static

Definition at line 129 of file mediacodecenc.c.

Referenced by mediacodec_output_format(), and on_format_changed().

◆ mediacodec_output_format()

static void mediacodec_output_format ( AVCodecContext * avctx)
static

Definition at line 141 of file mediacodecenc.c.

Referenced by mediacodec_init(), and mediacodec_receive().

◆ extract_extradata_support()

static int extract_extradata_support ( AVCodecContext * avctx)
static

Definition at line 152 of file mediacodecenc.c.

Referenced by mediacodec_init_bsf().

◆ mediacodec_init_bsf()

static int mediacodec_init_bsf ( AVCodecContext * avctx)
static

Definition at line 169 of file mediacodecenc.c.

Referenced by mediacodec_init().

◆ copy_frame_to_buffer()

static void copy_frame_to_buffer ( AVCodecContext * avctx,
const AVFrame * frame,
uint8_t * dst,
size_t size )
static

Definition at line 221 of file mediacodecenc.c.

Referenced by mediacodec_send().

◆ on_error()

static void on_error ( FFAMediaCodec * codec,
void * userdata,
int error,
const char * detail )
static

Definition at line 250 of file mediacodecenc.c.

Referenced by mediacodec_init(), on_input_available(), and on_output_available().

◆ on_input_available()

static void on_input_available ( FFAMediaCodec * codec,
void * userdata,
int32_t index )
static

Definition at line 271 of file mediacodecenc.c.

Referenced by mediacodec_init().

◆ on_output_available()

static void on_output_available ( FFAMediaCodec * codec,
void * userdata,
int32_t index,
FFAMediaCodecBufferInfo * out_info )
static

Definition at line 288 of file mediacodecenc.c.

Referenced by mediacodec_init().

◆ on_format_changed()

static void on_format_changed ( FFAMediaCodec * codec,
void * userdata,
FFAMediaFormat * format )
static

Definition at line 310 of file mediacodecenc.c.

Referenced by mediacodec_init().

◆ mediacodec_init_async_state()

static int mediacodec_init_async_state ( AVCodecContext * avctx)
static

Definition at line 316 of file mediacodecenc.c.

Referenced by mediacodec_init().

◆ mediacodec_uninit_async_state()

static void mediacodec_uninit_async_state ( AVCodecContext * avctx)
static

Definition at line 340 of file mediacodecenc.c.

Referenced by mediacodec_close(), and mediacodec_init().

◆ mediacodec_generate_extradata()

static int mediacodec_generate_extradata ( AVCodecContext * avctx)
static

Definition at line 938 of file mediacodecenc.c.

Referenced by mediacodec_init().

◆ mediacodec_set_qp_range()

static void mediacodec_set_qp_range ( AVCodecContext * avctx,
FFAMediaFormat * format )
static

Definition at line 361 of file mediacodecenc.c.

Referenced by mediacodec_init().

◆ mediacodec_init()

static av_cold int mediacodec_init ( AVCodecContext * avctx)
static

Definition at line 394 of file mediacodecenc.c.

◆ mediacodec_get_output_index()

static int mediacodec_get_output_index ( AVCodecContext * avctx,
ssize_t * index,
FFAMediaCodecBufferInfo * out_info )
static

Definition at line 627 of file mediacodecenc.c.

Referenced by mediacodec_receive().

◆ mediacodec_receive()

static int mediacodec_receive ( AVCodecContext * avctx,
AVPacket * pkt )
static

◆ mediacodec_get_input_index()

static int mediacodec_get_input_index ( AVCodecContext * avctx,
ssize_t * index )
static

Definition at line 755 of file mediacodecenc.c.

Referenced by mediacodec_send().

◆ mediacodec_send()

static int mediacodec_send ( AVCodecContext * avctx,
const AVFrame * frame )
static

Definition at line 788 of file mediacodecenc.c.

Referenced by mediacodec_encode(), and mediacodec_send_dummy_frame().

◆ mediacodec_encode()

static int mediacodec_encode ( AVCodecContext * avctx,
AVPacket * pkt )
static

Definition at line 839 of file mediacodecenc.c.

◆ mediacodec_send_dummy_frame()

static int mediacodec_send_dummy_frame ( AVCodecContext * avctx)
static

Definition at line 885 of file mediacodecenc.c.

Referenced by mediacodec_generate_extradata().

◆ mediacodec_receive_dummy_pkt()

static int mediacodec_receive_dummy_pkt ( AVCodecContext * avctx,
AVPacket * pkt )
static

Definition at line 916 of file mediacodecenc.c.

Referenced by mediacodec_generate_extradata().

◆ mediacodec_close()

static av_cold int mediacodec_close ( AVCodecContext * avctx)
static

Definition at line 990 of file mediacodecenc.c.

◆ mediacodec_flush()

static av_cold void mediacodec_flush ( AVCodecContext * avctx)
static

Definition at line 1012 of file mediacodecenc.c.

Variable Documentation

◆ color_format

int color_format

Definition at line 114 of file mediacodecenc.c.

◆ pix_fmt

enum AVPixelFormat pix_fmt

Definition at line 115 of file mediacodecenc.c.

◆ [struct]

const struct { ... } color_formats[]
Initial value:
= {
}
@ COLOR_FormatYUV420Planar
@ COLOR_FormatYUV420SemiPlanar
@ COLOR_FormatSurface
@ 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...
Definition pixfmt.h:96
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_MEDIACODEC
hardware decoding through MediaCodec
Definition pixfmt.h:316

◆ avc_pix_fmts

enum AVPixelFormat avc_pix_fmts[]
static
Initial value:

Definition at line 122 of file mediacodecenc.c.

◆ mediacodec_hw_configs

const AVCodecHWConfigInternal* const mediacodec_hw_configs[]
static
Initial value:
= {
.public = {
},
.hwaccel = NULL,
},
}
#define NULL
Definition coverity.c:32
@ AV_CODEC_HW_CONFIG_METHOD_AD_HOC
The codec supports this format by some ad-hoc method.
Definition codec.h:311
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
Definition codec.h:282
@ AV_HWDEVICE_TYPE_MEDIACODEC
Definition hwcontext.h:38

Definition at line 1021 of file mediacodecenc.c.

◆ mediacodec_defaults

const FFCodecDefault mediacodec_defaults[]
static
Initial value:
= {
{"qmin", "-1"},
{"qmax", "-1"},
{NULL},
}

Definition at line 1034 of file mediacodecenc.c.