FFmpeg
Data Structures | Macros | Functions | Variables
omx.c File Reference
#include "config.h"
#include <dlfcn.h>
#include <OMX_Core.h>
#include <OMX_Component.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include "libavutil/avstring.h"
#include "libavutil/avutil.h"
#include "libavutil/common.h"
#include "libavutil/imgutils.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "codec_internal.h"
#include "h264.h"
#include "pthread_internal.h"

Go to the source code of this file.

Data Structures

struct  OMXContext
 
struct  OMXCodecContext
 

Macros

#define to_omx_ticks(x)   (x)
 
#define from_omx_ticks(x)   (x)
 
#define INIT_STRUCT(x)
 
#define CHECK(x)
 
#define NB_MUTEX_CONDS   6
 
#define OFF(field)   offsetof(OMXCodecContext, field)
 
#define OFFSET(x)   offsetof(OMXCodecContext, x)
 
#define VDE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Functions

static av_cold void * dlsym_prefixed (void *handle, const char *symbol, const char *prefix)
 
static av_cold int omx_try_load (OMXContext *s, void *logctx, const char *libname, const char *prefix, const char *libname2)
 
static av_cold OMXContextomx_init (void *logctx, const char *libname, const char *prefix)
 
static av_cold void omx_deinit (OMXContext *omx_context)
 
 DEFINE_OFFSET_ARRAY (OMXCodecContext, omx_codec_context, mutex_cond_inited_cnt,(OFF(input_mutex), OFF(output_mutex), OFF(state_mutex)),(OFF(input_cond), OFF(output_cond), OFF(state_cond)))
 
static void append_buffer (pthread_mutex_t *mutex, pthread_cond_t *cond, int *array_size, OMX_BUFFERHEADERTYPE **array, OMX_BUFFERHEADERTYPE *buffer)
 
static OMX_BUFFERHEADERTYPE * get_buffer (pthread_mutex_t *mutex, pthread_cond_t *cond, int *array_size, OMX_BUFFERHEADERTYPE **array, int wait)
 
static OMX_ERRORTYPE event_handler (OMX_HANDLETYPE component, OMX_PTR app_data, OMX_EVENTTYPE event, OMX_U32 data1, OMX_U32 data2, OMX_PTR event_data)
 
static OMX_ERRORTYPE empty_buffer_done (OMX_HANDLETYPE component, OMX_PTR app_data, OMX_BUFFERHEADERTYPE *buffer)
 
static OMX_ERRORTYPE fill_buffer_done (OMX_HANDLETYPE component, OMX_PTR app_data, OMX_BUFFERHEADERTYPE *buffer)
 
static av_cold int find_component (OMXContext *omx_context, void *logctx, const char *role, char *str, int str_size)
 
static av_cold int wait_for_state (OMXCodecContext *s, OMX_STATETYPE state)
 
static av_cold int omx_component_init (AVCodecContext *avctx, const char *role)
 
static av_cold void cleanup (OMXCodecContext *s)
 
static av_cold int omx_encode_init (AVCodecContext *avctx)
 
static int omx_encode_frame (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
 
static av_cold int omx_encode_end (AVCodecContext *avctx)
 

Variables

static const OMX_CALLBACKTYPE callbacks
 
static const AVOption options []
 
static enum AVPixelFormat omx_encoder_pix_fmts []
 
static const AVClass omx_mpeg4enc_class
 
const FFCodec ff_mpeg4_omx_encoder
 
static const AVClass omx_h264enc_class
 
const FFCodec ff_h264_omx_encoder
 

Macro Definition Documentation

◆ to_omx_ticks

#define to_omx_ticks (   x)    (x)

Definition at line 61 of file omx.c.

◆ from_omx_ticks

#define from_omx_ticks (   x)    (x)

Definition at line 62 of file omx.c.

◆ INIT_STRUCT

#define INIT_STRUCT (   x)
Value:
do { \
x.nSize = sizeof(x); \
x.nVersion = s->version; \
} while (0)

Definition at line 65 of file omx.c.

◆ CHECK

#define CHECK (   x)
Value:
do { \
if (x != OMX_ErrorNone) { \
av_log(avctx, AV_LOG_ERROR, \
"err %x (%d) on line %d\n", x, x, __LINE__); \
return AVERROR_UNKNOWN; \
} \
} while (0)

Definition at line 69 of file omx.c.

◆ NB_MUTEX_CONDS

#define NB_MUTEX_CONDS   6

Definition at line 233 of file omx.c.

◆ OFF

#define OFF (   field)    offsetof(OMXCodecContext, field)

Definition at line 234 of file omx.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(OMXCodecContext, x)

Definition at line 916 of file omx.c.

◆ VDE

Definition at line 917 of file omx.c.

◆ VE

Definition at line 918 of file omx.c.

Function Documentation

◆ dlsym_prefixed()

static av_cold void* dlsym_prefixed ( void *  handle,
const char *  symbol,
const char *  prefix 
)
static

Definition at line 90 of file omx.c.

Referenced by omx_try_load().

◆ omx_try_load()

static av_cold int omx_try_load ( OMXContext s,
void *  logctx,
const char *  libname,
const char *  prefix,
const char *  libname2 
)
static

Definition at line 97 of file omx.c.

Referenced by omx_init().

◆ omx_init()

static av_cold OMXContext* omx_init ( void *  logctx,
const char *  libname,
const char *  prefix 
)
static

Definition at line 141 of file omx.c.

Referenced by omx_encode_init().

◆ omx_deinit()

static av_cold void omx_deinit ( OMXContext omx_context)
static

Definition at line 181 of file omx.c.

Referenced by cleanup().

◆ DEFINE_OFFSET_ARRAY()

DEFINE_OFFSET_ARRAY ( OMXCodecContext  ,
omx_codec_context  ,
mutex_cond_inited_cnt  ,
(OFF(input_mutex), OFF(output_mutex), OFF(state_mutex))  ,
(OFF(input_cond), OFF(output_cond), OFF(state_cond))   
)

◆ append_buffer()

static void append_buffer ( pthread_mutex_t mutex,
pthread_cond_t cond,
int array_size,
OMX_BUFFERHEADERTYPE **  array,
OMX_BUFFERHEADERTYPE *  buffer 
)
static

Definition at line 239 of file omx.c.

Referenced by empty_buffer_done(), fill_buffer_done(), omx_encode_frame(), and omx_encode_init().

◆ get_buffer()

static OMX_BUFFERHEADERTYPE* get_buffer ( pthread_mutex_t mutex,
pthread_cond_t cond,
int array_size,
OMX_BUFFERHEADERTYPE **  array,
int  wait 
)
static

Definition at line 249 of file omx.c.

Referenced by cleanup(), omx_encode_frame(), and omx_encode_init().

◆ event_handler()

static OMX_ERRORTYPE event_handler ( OMX_HANDLETYPE  component,
OMX_PTR  app_data,
OMX_EVENTTYPE  event,
OMX_U32  data1,
OMX_U32  data2,
OMX_PTR  event_data 
)
static

Definition at line 270 of file omx.c.

◆ empty_buffer_done()

static OMX_ERRORTYPE empty_buffer_done ( OMX_HANDLETYPE  component,
OMX_PTR  app_data,
OMX_BUFFERHEADERTYPE *  buffer 
)
static

Definition at line 312 of file omx.c.

◆ fill_buffer_done()

static OMX_ERRORTYPE fill_buffer_done ( OMX_HANDLETYPE  component,
OMX_PTR  app_data,
OMX_BUFFERHEADERTYPE *  buffer 
)
static

Definition at line 330 of file omx.c.

◆ find_component()

static av_cold int find_component ( OMXContext omx_context,
void *  logctx,
const char *  role,
char *  str,
int  str_size 
)
static

Definition at line 345 of file omx.c.

Referenced by omx_encode_init().

◆ wait_for_state()

static av_cold int wait_for_state ( OMXCodecContext s,
OMX_STATETYPE  state 
)
static

Definition at line 382 of file omx.c.

Referenced by cleanup(), and omx_component_init().

◆ omx_component_init()

static av_cold int omx_component_init ( AVCodecContext avctx,
const char *  role 
)
static

Definition at line 394 of file omx.c.

Referenced by omx_encode_init().

◆ cleanup()

static av_cold void cleanup ( OMXCodecContext s)
static

Definition at line 597 of file omx.c.

Referenced by omx_encode_end().

◆ omx_encode_init()

static av_cold int omx_encode_init ( AVCodecContext avctx)
static

Definition at line 642 of file omx.c.

◆ omx_encode_frame()

static int omx_encode_frame ( AVCodecContext avctx,
AVPacket pkt,
const AVFrame frame,
int got_packet 
)
static

Definition at line 731 of file omx.c.

◆ omx_encode_end()

static av_cold int omx_encode_end ( AVCodecContext avctx)
static

Definition at line 908 of file omx.c.

Variable Documentation

◆ callbacks

const OMX_CALLBACKTYPE callbacks
static

◆ options

const AVOption options[]
static
Initial value:
= {
{ "omx_libname", "OpenMAX library name", OFFSET(libname), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VDE },
{ "omx_libprefix", "OpenMAX library prefix", OFFSET(libprefix), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VDE },
{ "zerocopy", "Try to avoid copying input frames if possible", OFFSET(input_zerocopy), AV_OPT_TYPE_INT, { .i64 = CONFIG_OMX_RPI }, 0, 1, VE },
{ "profile", "Set the encoding profile", OFFSET(profile), AV_OPT_TYPE_INT, { .i64 = AV_PROFILE_UNKNOWN }, AV_PROFILE_UNKNOWN, AV_PROFILE_H264_HIGH, VE, .unit = "profile" },
{ "baseline", "", 0, AV_OPT_TYPE_CONST, { .i64 = AV_PROFILE_H264_BASELINE }, 0, 0, VE, .unit = "profile" },
{ "main", "", 0, AV_OPT_TYPE_CONST, { .i64 = AV_PROFILE_H264_MAIN }, 0, 0, VE, .unit = "profile" },
{ "high", "", 0, AV_OPT_TYPE_CONST, { .i64 = AV_PROFILE_H264_HIGH }, 0, 0, VE, .unit = "profile" },
{ NULL }
}

Definition at line 919 of file omx.c.

◆ omx_encoder_pix_fmts

enum AVPixelFormat omx_encoder_pix_fmts[]
static
Initial value:

Definition at line 930 of file omx.c.

◆ omx_mpeg4enc_class

const AVClass omx_mpeg4enc_class
static
Initial value:
= {
.class_name = "mpeg4_omx",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 934 of file omx.c.

◆ ff_mpeg4_omx_encoder

const FFCodec ff_mpeg4_omx_encoder
Initial value:
= {
.p.name = "mpeg4_omx",
CODEC_LONG_NAME("OpenMAX IL MPEG-4 video encoder"),
.p.type = AVMEDIA_TYPE_VIDEO,
.priv_data_size = sizeof(OMXCodecContext),
.close = omx_encode_end,
.p.pix_fmts = omx_encoder_pix_fmts,
.p.capabilities = AV_CODEC_CAP_DELAY,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
.p.priv_class = &omx_mpeg4enc_class,
}

Definition at line 940 of file omx.c.

◆ omx_h264enc_class

const AVClass omx_h264enc_class
static
Initial value:
= {
.class_name = "h264_omx",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 955 of file omx.c.

◆ ff_h264_omx_encoder

const FFCodec ff_h264_omx_encoder
Initial value:
= {
.p.name = "h264_omx",
CODEC_LONG_NAME("OpenMAX IL H.264 video encoder"),
.p.type = AVMEDIA_TYPE_VIDEO,
.priv_data_size = sizeof(OMXCodecContext),
.close = omx_encode_end,
.p.pix_fmts = omx_encoder_pix_fmts,
.p.capabilities = AV_CODEC_CAP_DELAY,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
.p.priv_class = &omx_h264enc_class,
}

Definition at line 961 of file omx.c.

FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
AV_PROFILE_H264_MAIN
#define AV_PROFILE_H264_MAIN
Definition: defs.h:111
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
OMXCodecContext
Definition: omx.c:190
empty_buffer_done
static OMX_ERRORTYPE empty_buffer_done(OMX_HANDLETYPE component, OMX_PTR app_data, OMX_BUFFERHEADERTYPE *buffer)
Definition: omx.c:312
AVERROR_UNKNOWN
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:73
omx_encoder_pix_fmts
static enum AVPixelFormat omx_encoder_pix_fmts[]
Definition: omx.c:930
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:296
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AV_PROFILE_UNKNOWN
#define AV_PROFILE_UNKNOWN
Definition: defs.h:65
s
#define s(width, name)
Definition: cbs_vp9.c:198
OFFSET
#define OFFSET(x)
Definition: omx.c:916
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
NULL
#define NULL
Definition: coverity.c:32
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
VDE
#define VDE
Definition: omx.c:917
event_handler
static OMX_ERRORTYPE event_handler(OMX_HANDLETYPE component, OMX_PTR app_data, OMX_EVENTTYPE event, OMX_U32 data1, OMX_U32 data2, OMX_PTR event_data)
Definition: omx.c:270
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
options
static const AVOption options[]
Definition: omx.c:919
omx_h264enc_class
static const AVClass omx_h264enc_class
Definition: omx.c:955
omx_encode_frame
static int omx_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: omx.c:731
profile
int profile
Definition: mxfenc.c:2226
AV_PROFILE_H264_BASELINE
#define AV_PROFILE_H264_BASELINE
Definition: defs.h:109
omx_encode_init
static av_cold int omx_encode_init(AVCodecContext *avctx)
Definition: omx.c:642
AV_PROFILE_H264_HIGH
#define AV_PROFILE_H264_HIGH
Definition: defs.h:113
omx_encode_end
static av_cold int omx_encode_end(AVCodecContext *avctx)
Definition: omx.c:908
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
omx_mpeg4enc_class
static const AVClass omx_mpeg4enc_class
Definition: omx.c:934
AV_CODEC_CAP_DELAY
#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:76
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:239
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:244
VE
#define VE
Definition: omx.c:918
fill_buffer_done
static OMX_ERRORTYPE fill_buffer_done(OMX_HANDLETYPE component, OMX_PTR app_data, OMX_BUFFERHEADERTYPE *buffer)
Definition: omx.c:330