FFmpeg
Data Structures | Macros | Functions | Variables
ohenc.c File Reference
#include "config_components.h"
#include <stdbool.h>
#include <multimedia/player_framework/native_avcapability.h>
#include <multimedia/player_framework/native_avcodec_videoencoder.h>
#include <native_window/external_window.h>
#include "libavutil/fifo.h"
#include "libavutil/hwcontext_oh.h"
#include "libavutil/imgutils.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/thread.h"
#include "avcodec.h"
#include "codec_internal.h"
#include "encode.h"
#include "hwconfig.h"
#include "ohcodec.h"

Go to the source code of this file.

Data Structures

struct  OHCodecEncContext
 

Macros

#define OFFSET(x)   offsetof(OHCodecEncContext, x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 
#define DECLARE_OHCODEC_CLASS(name)
 
#define DECLARE_OHCODEC_ENCODER(short_name, long_name, codec_id)
 

Functions

static int oh_encode_create (OHCodecEncContext *s, AVCodecContext *avctx)
 
static int oh_encode_set_format (OHCodecEncContext *s, AVCodecContext *avctx)
 
static void oh_encode_on_err (OH_AVCodec *codec, int32_t err, void *userdata)
 
static void oh_encode_on_stream_changed (OH_AVCodec *codec, OH_AVFormat *format, void *userdata)
 
static void oh_encode_on_need_input (OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userdata)
 
static void oh_encode_on_output (OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userdata)
 
static int oh_encode_start (OHCodecEncContext *s, AVCodecContext *avctx)
 
static av_cold int oh_encode_init (AVCodecContext *avctx)
 
static av_cold int oh_encode_close (AVCodecContext *avctx)
 
static int oh_encode_output_packet (AVCodecContext *avctx, AVPacket *pkt, OHBufferQueueItem *output)
 
static int oh_encode_send_hw_frame (AVCodecContext *avctx)
 
static int oh_encode_send_sw_frame (AVCodecContext *avctx, OHBufferQueueItem *input)
 
static int oh_encode_receive (AVCodecContext *avctx, AVPacket *pkt)
 
static void oh_encode_flush (AVCodecContext *avctx)
 

Variables

static enum AVPixelFormat ohcodec_pix_fmts []
 
static const AVCodecHWConfigInternal *const oh_hw_configs []
 
static const FFCodecDefault ohcodec_defaults []
 
static const AVOption ohcodec_venc_options []
 

Macro Definition Documentation

◆ OFFSET

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

Definition at line 655 of file ohenc.c.

◆ VE

Definition at line 656 of file ohenc.c.

◆ DECLARE_OHCODEC_CLASS

#define DECLARE_OHCODEC_CLASS (   name)
Value:
static const AVClass name ## _oh_enc_class = { \
.class_name = #name "_ohcodec", \
.item_name = av_default_item_name, \
.option = ohcodec_venc_options, \
.version = LIBAVUTIL_VERSION_INT, \
}; \

Definition at line 673 of file ohenc.c.

◆ DECLARE_OHCODEC_ENCODER

#define DECLARE_OHCODEC_ENCODER (   short_name,
  long_name,
  codec_id 
)
Value:
DECLARE_OHCODEC_CLASS(short_name) \
const FFCodec ff_ ## short_name ## _oh_encoder = { \
.p.name = #short_name "_ohcodec", \
CODEC_LONG_NAME(long_name " OpenHarmony Codec"), \
.p.type = AVMEDIA_TYPE_VIDEO, \
.p.id = codec_id, \
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | \
AV_CODEC_CAP_HARDWARE | \
AV_CODEC_CAP_ENCODER_FLUSH, \
.priv_data_size = sizeof(OHCodecEncContext), \
.color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG, \
.defaults = ohcodec_defaults, \
.init = oh_encode_init, \
FF_CODEC_RECEIVE_PACKET_CB(oh_encode_receive), \
.close = oh_encode_close, \
.flush = oh_encode_flush, \
.p.priv_class = &short_name ## _oh_enc_class, \
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
.p.wrapper_name = "ohcodec", \
.hw_configs = oh_hw_configs, \
}; \

Definition at line 681 of file ohenc.c.

Function Documentation

◆ oh_encode_create()

static int oh_encode_create ( OHCodecEncContext s,
AVCodecContext avctx 
)
static

Definition at line 76 of file ohenc.c.

Referenced by oh_encode_init().

◆ oh_encode_set_format()

static int oh_encode_set_format ( OHCodecEncContext s,
AVCodecContext avctx 
)
static

Definition at line 113 of file ohenc.c.

Referenced by oh_encode_init().

◆ oh_encode_on_err()

static void oh_encode_on_err ( OH_AVCodec *  codec,
int32_t  err,
void *  userdata 
)
static

Definition at line 215 of file ohenc.c.

Referenced by oh_encode_on_need_input(), oh_encode_on_output(), and oh_encode_start().

◆ oh_encode_on_stream_changed()

static void oh_encode_on_stream_changed ( OH_AVCodec *  codec,
OH_AVFormat *  format,
void *  userdata 
)
static

Definition at line 232 of file ohenc.c.

Referenced by oh_encode_send_sw_frame(), and oh_encode_start().

◆ oh_encode_on_need_input()

static void oh_encode_on_need_input ( OH_AVCodec *  codec,
uint32_t  index,
OH_AVBuffer *  buffer,
void *  userdata 
)
static

Definition at line 246 of file ohenc.c.

Referenced by oh_encode_start().

◆ oh_encode_on_output()

static void oh_encode_on_output ( OH_AVCodec *  codec,
uint32_t  index,
OH_AVBuffer *  buffer,
void *  userdata 
)
static

Definition at line 265 of file ohenc.c.

Referenced by oh_encode_start().

◆ oh_encode_start()

static int oh_encode_start ( OHCodecEncContext s,
AVCodecContext avctx 
)
static

Definition at line 284 of file ohenc.c.

Referenced by oh_encode_init().

◆ oh_encode_init()

static av_cold int oh_encode_init ( AVCodecContext avctx)
static

Definition at line 320 of file ohenc.c.

◆ oh_encode_close()

static av_cold int oh_encode_close ( AVCodecContext avctx)
static

Definition at line 353 of file ohenc.c.

◆ oh_encode_output_packet()

static int oh_encode_output_packet ( AVCodecContext avctx,
AVPacket pkt,
OHBufferQueueItem output 
)
static

Definition at line 386 of file ohenc.c.

Referenced by oh_encode_receive().

◆ oh_encode_send_hw_frame()

static int oh_encode_send_hw_frame ( AVCodecContext avctx)
static

Definition at line 454 of file ohenc.c.

Referenced by oh_encode_receive().

◆ oh_encode_send_sw_frame()

static int oh_encode_send_sw_frame ( AVCodecContext avctx,
OHBufferQueueItem input 
)
static

Definition at line 471 of file ohenc.c.

Referenced by oh_encode_receive().

◆ oh_encode_receive()

static int oh_encode_receive ( AVCodecContext avctx,
AVPacket pkt 
)
static

Definition at line 556 of file ohenc.c.

◆ oh_encode_flush()

static void oh_encode_flush ( AVCodecContext avctx)
static

Definition at line 621 of file ohenc.c.

Variable Documentation

◆ ohcodec_pix_fmts

enum AVPixelFormat ohcodec_pix_fmts[]
static
Initial value:

Definition at line 70 of file ohenc.c.

◆ oh_hw_configs

const AVCodecHWConfigInternal* const oh_hw_configs[]
static
Initial value:
= {
.public = {
.pix_fmt = AV_PIX_FMT_OHCODEC,
},
.hwaccel = NULL,
},
}

Definition at line 639 of file ohenc.c.

◆ ohcodec_defaults

const FFCodecDefault ohcodec_defaults[]
static
Initial value:
= {
{"g", "-2"},
{NULL},
}

Definition at line 650 of file ohenc.c.

◆ ohcodec_venc_options

const AVOption ohcodec_venc_options[]
static
Initial value:
= {
{"codec_name", "Select codec by name",
{"allow_sw", "Allow software encoding",
OFFSET(allow_sw), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VE},
{"bitrate_mode", "Bitrate control method",
OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, .unit = "bitrate_mode"},
{"cbr", "Constant bitrate mode",
0, AV_OPT_TYPE_CONST, {.i64 = CBR}, 0, 0, VE, .unit = "bitrate_mode"},
{"vbr", "Variable bitrate mode",
0, AV_OPT_TYPE_CONST, {.i64 = VBR}, 0, 0, VE, .unit = "bitrate_mode"},
{"cq", "Constant quality mode",
0, AV_OPT_TYPE_CONST, {.i64 = CQ}, 0, 0, VE, .unit = "bitrate_mode"},
{NULL},
}

Definition at line 657 of file ohenc.c.

name
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 default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
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
ohcodec_venc_options
static const AVOption ohcodec_venc_options[]
Definition: ohenc.c:657
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:767
FFCodec
Definition: codec_internal.h:127
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
VE
#define VE
Definition: ohenc.c:656
AV_CODEC_HW_CONFIG_METHOD_AD_HOC
@ AV_CODEC_HW_CONFIG_METHOD_AD_HOC
The codec supports this format by some ad-hoc method.
Definition: codec.h:327
oh_encode_close
static av_cold int oh_encode_close(AVCodecContext *avctx)
Definition: ohenc.c:353
ohcodec_defaults
static const FFCodecDefault ohcodec_defaults[]
Definition: ohenc.c:650
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:410
DECLARE_OHCODEC_CLASS
#define DECLARE_OHCODEC_CLASS(name)
Definition: ohenc.c:673
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
NULL
#define NULL
Definition: coverity.c:32
CODEC_PIXFMTS_ARRAY
#define CODEC_PIXFMTS_ARRAY(array)
Definition: codec_internal.h:387
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:240
OHCodecEncContext
Definition: ohenc.c:41
oh_encode_receive
static int oh_encode_receive(AVCodecContext *avctx, AVPacket *pkt)
Definition: ohenc.c:556
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVCodecHWConfigInternal
Definition: hwconfig.h:25
oh_encode_init
static av_cold int oh_encode_init(AVCodecContext *avctx)
Definition: ohenc.c:320
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:179
CBR
@ CBR
Definition: af_afade.c:60
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:750
oh_encode_flush
static void oh_encode_flush(AVCodecContext *avctx)
Definition: ohenc.c:621
AV_PIX_FMT_NV12
@ 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
oh_hw_configs
static const AVCodecHWConfigInternal *const oh_hw_configs[]
Definition: ohenc.c:639
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
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:200
AV_PIX_FMT_OHCODEC
@ AV_PIX_FMT_OHCODEC
Definition: pixfmt.h:500
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
ohcodec_pix_fmts
static enum AVPixelFormat ohcodec_pix_fmts[]
Definition: ohenc.c:70
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
OFFSET
#define OFFSET(x)
Definition: ohenc.c:655