OpenHarmony Codec HDI codec_capabilities HCS配置解析
一、简介 HCS(HDF Configuration Source)是HDF驱动框架的配置描述源码,内容以Key-Value为主要形式。它实现了配置代码与驱动代码解耦,便于开发者进行配置管理。本文主要讲解Codec HDI 支持的编解码组件HCS配置文件,简单分析每一个key的意义和用途。 二、编解码组件HCS配置 编解码组件配
一、简介
HCS(HDF Configuration Source)是HDF驱动框架的配置描述源码,内容以Key-Value为主要形式。它实现了配置代码与驱动代码解耦,便于开发者进行配置管理。本文主要讲解Codec HDI 支持的编解码组件HCS配置文件,简单分析每一个key的意义和用途。
二、编解码组件HCS配置
编解码组件配置文件一般位于 //vendor/{company}/{chiptype}/hdf_config/uhdf/media_codec/codec_component_capabilities.hcs
root {
module = "master";
codec_config {
match_attr = "media_codec_capabilities";
use_openmax = true;
VideoHwEncoders {
HDF_video_hw_enc_avc_xxx {
role = 1;
type = 1;
name = "OMX.xxx.video_encoder.avc";
supportProfiles = [1, 32768, 2, 32768, 8, 32768];
maxInst = 4;
isSoftwareCodec = false;
processModeMask = [];
capsMask = [0x01];
minBitRate = 1;
maxBitRate = 40000000;
minWidth = 144;
minHeight = 144;
maxWidth = 4096;
maxHeight = 4096;
widthAlignment = 2;
heightAlignment = 2;
minBlockCount = 99;
maxBlockCount = 8160;
minBlocksPerSecond = 99;
maxBlocksPerSecond = 489600;
blockSizeWidth = 16;
blockSizeHeight = 16;
supportPixelFmts = [28, 24, 20, 12];
measuredFrameRate = [320, 240, 165, 165, 720, 480, 149, 149, 1280, 720, 73, 73, 1920, 1080, 18, 18];
bitRateMode = [1, 2];
minFrameRate = 1;
maxFrameRate = 60;
canSwapWidthHeight = true;
}
}
VideoHwDecoders {
HDF_video_hw_dec_avc_xxx {
role = 1;
type = 0;
name = "OMX.xxx.video_decoder.avc";
supportProfiles = [1, 32768, 2, 32768, 8, 32768];
...
supportPixelFmts = [24, 12, 20];
measuredFrameRate = [320, 240, 617, 617, 720, 480, 559, 559, 1280, 720, 276, 276, 1920, 1080, 164, 164, 3840, 2160, 30, 30];
bitRateMode = [];
minFrameRate = 1;
maxFrameRate = 60;
canSwapWidthHeight = true;
}
}
VideoSwEncoders {
}
VideoSwDecoders {
}
AudioHwEncoders {
}
AudioHwDecoders {
}
AudioSwEncoders {
}
AudioSwDecoders {
}
}
1、通用配置
(1)codecGroupsNode
VideoHwEncoders:视频硬件编码组件 VideoHwDecoders:视频硬件解码组件 VideoSwEncoders:视频软件编码组件 VideoSwDecoders:视频软件解码组件
AudioHwEncoders:音频硬件编码组件 AudioHwDecoders:音频硬件解码组件 AudioSwEncoders:音频软件编码组件 AudioSwDecoders:音频软件解码组件
(2)role
drivers/peripheral/codec/interfaces/include/codec_component_type.h
typedef enum {
/** JPEG image */
MEDIA_ROLETYPE_IMAGE_JPEG = 0,
/** H.264 video */
MEDIA_ROLETYPE_VIDEO_AVC,
/** H.265 video */
MEDIA_ROLETYPE_VIDEO_HEVC,
/** MPEG4 video */
MEDIA_ROLETYPE_VIDEO_MPEG4,
...
MEDIA_ROLETYPE_AUDIO_FIRST = 0x10000,
/** Advanced Audio Coding (AAC) */
MEDIA_ROLETYPE_AUDIO_AAC = 0x10000,
...
/** Invalid type */
MEDIA_ROLETYPE_INVALID,
} AvCodecRole;
如果role = 1则代表是AVC,role = 2 则代表是HEVC
(3)type
drivers/peripheral/codec/interfaces/include/codec_common_type.h
typedef enum {
/** Video decoder */
VIDEO_DECODER,
/** Video encoder */
VIDEO_ENCODER,
/** Audio decoder */
AUDIO_DECODER,
/** Audio encoder */
AUDIO_ENCODER,
/** Invalid type */
INVALID_TYPE
} CodecType;
如上,type = 0代表解码,type = 1代表编码
(4)name
组件名,需要和libOMX_Core.z.so中定义的组件名一致,否则创建组件会失败
(5)supportProfiles
支持的profile和最大level,每2个uint值为一组,分别代表profile和最大level
H264的profile和level定义在OMX标准头文件 OMX_Video.h
typedef enum OMX_VIDEO_AVCPROFILETYPE {
OMX_VIDEO_AVCProfileBaseline = 0x01,
OMX_VIDEO_AVCProfileMain = 0x02,
OMX_VIDEO_AVCProfileExtended = 0x04,
OMX_VIDEO_AVCProfileHigh = 0x08,
OMX_VIDEO_AVCProfileHigh10 = 0x10,
OMX_VIDEO_AVCProfileHigh422 = 0x20,
OMX_VIDEO_AVCProfileHigh444 = 0x40,
OMX_VIDEO_AVCProfileUnknown = 0x6EFFFFFF,
...
OMX_VIDEO_AVCProfileMax = 0x7FFFFFFF
} OMX_VIDEO_AVCPROFILETYPE;
typedef enum OMX_VIDEO_AVCLEVELTYPE {
OMX_VIDEO_AVCLevel1 = 0x01,
OMX_VIDEO_AVCLevel1b = 0x02,
OMX_VIDEO_AVCLevel11 = 0x04,
...
OMX_VIDEO_AVCLevel5 = 0x4000,
OMX_VIDEO_AVCLevel51 = 0x8000,
...
OMX_VIDEO_AVCLevelMax = 0x7FFFFFFF
} OMX_VIDEO_AVCLEVELTYPE;
配置文件中[1, 32768, 2, 32768, 8, 32768] 代表最大支持AVC baseline@5.1,main@5.1,high@5.1
(6)maxInst
最大可以创建的该组件实例个数,最大几路
(7)isSoftwareCodec
是否是软件编解码器,bool类型
(8)processModeMask
组件支持的处理模式标志
drivers/peripheral/codec/interfaces/include/codec_common_type.h
typedef enum {
/** Input buffer in sync mode */
PROCESS_BLOCKING_INPUT_BUFFER = 0X1,
/** Output buffer in sync mode */
PROCESS_BLOCKING_OUTPUT_BUFFER = 0X2,
/** Control flow in sync mode */
PROCESS_BLOCKING_CONTROL_FLOW = 0X4,
/** Input buffer in async mode */
PROCESS_NONBLOCKING_INPUT_BUFFER = 0X100,
/** Output buffer in async mode */
PROCESS_NONBLOCKING_OUTPUT_BUFFER = 0X200,
/** Control flow in async mode */
PROCESS_NONBLOCKING_CONTROL_FLOW = 0X400,
} CodecProcessMode;
处理输入输出buffer和控制命令时是否会阻塞,目前多媒体框架层未使用,“processModeMask = []“即可
(9)capsMask
组件支持的能力标志,uint32_t类型,使用掩码
typedef enum {
/** Adaptive playback */
CODEC_CAP_ADAPTIVE_PLAYBACK = 0x1,
/** Secure playback */
CODEC_CAP_SECURE_PLAYBACK = 0x2,
/** Tunnel playback */
CODEC_CAP_TUNNEL_PLAYBACK = 0x4,
/** Multi-plane (video image plane and audio tunnel plane) playback */
CODEC_CAP_MULTI_PLANE = 0x10000,
} CodecCapsMask;
自适应播放、安全通路、tunnel模式、多平面视频(MVC?)
目前多媒体框架层未使用
(10)minBitRate、maxBitRate
支持的码率范围
2、视频配置
(1)minWidth minHeight maxWidth maxHeight
视频支持的分辨率范围,尽量和芯片能力保持一致,框架层会去根据这个范围检测当前分辨率是否支持,不在这个范围内可能会报错退出
(2)widthAlignment heightAlignment
水平对齐和垂直对齐
(3)minBlockCount maxBlockCount minBlocksPerSecond maxBlocksPerSecond blockSizeWidth blockSizeHeight
宏块相关参数,uint类型,框架层avcodeclist会根据这些值计算帧率等值,用于返回OH_AVCapability_GetVideoFrameRateRangeForSize,感觉意义不大,专业参数,可直接配置0xFFFFFFFF
(4)supportPixelFmts
支持的像素格式,uint数组,定义在foundation/graphic/graphic_2d/interfaces/inner_api/surface/surface_type.h或drivers/peripheral/display/interfaces/include/display_type.h,二者定义的值相同
using GraphicPixelFormat = enum {
GRAPHIC_PIXEL_FMT_CLUT8 = 0, /**< CLUT8 format */
...
GRAPHIC_PIXEL_FMT_RGBA_8888 = 12, /**< RGBA8888 format */
...
GRAPHIC_PIXEL_FMT_YCBCR_420_SP = 24, /**< YCBCR420 semi-planar format */
GRAPHIC_PIXEL_FMT_YCRCB_420_SP = 25, /**< YCRCB420 semi-planar format */
GRAPHIC_PIXEL_FMT_YCBCR_422_P = 26, /**< YCBCR422 planar format */
GRAPHIC_PIXEL_FMT_YCRCB_422_P = 27, /**< YCRCB422 planar format */
GRAPHIC_PIXEL_FMT_YCBCR_420_P = 28, /**< YCBCR420 planar format */
...
GRAPHIC_PIXEL_FMT_BUTT = 0X7FFFFFFF /**< Invalid pixel format */
};
比如常见的12代表RGBA,24代表NV12,25代表NV21,28代表I420,OMX组件支持的像素格式尽量都写明,避免框架层获取不到支持的能力处理异常
(5)measuredFrameRate
帧率测量,uint数组,每4个值为一组,分别代表宽、高、最小帧率、最大帧率,如[320, 240, 165, 165],分辨率320X240支持的最大帧率为165,框架层avcodeclist使用这个来计算特定分辨率下支持的帧率能力,用途不大
(6)bitRateMode
码率模式,uint数组,drivers/peripheral/codec/interfaces/include/codec_component_type.h
typedef enum {
BIT_RATE_MODE_INVALID,
/** Variable Bit Rate. */
BIT_RATE_MODE_VBR,
/* Constant Bit Rate. */
BIT_RATE_MODE_CBR,
/* Constant Quality. */
BIT_RATE_MODE_CQ,
/* Constrained VariableBit Rate. */
BIT_RATE_MODE_VCBR,
/* Average Bit Rate. */
BIT_RATE_MODE_ABR,
} BitRateMode;
如上,1代表VBR,2代表CBR,3代表CQ,编码需要填写该值,解码不需要填写
(7)minFrameRate maxFrameRate
支持的帧率范围,uint类型
(8)canSwapWidthHeight
是否支持交换宽高,bool类型,比如解码器支持的maxWidth是1920,maxHeight是1080,如果设置为true,那么1080X1920解码也是支持的
3、音频配置
当前版本框架层并没有使用Codec HDI的音频编解码能力,暂不必实现
(1)sampleFormats
采样格式,uint数组,可参考CodecAudioSampleFormat
(2)sampleRate
采样率,uint数组,可参考AudioSampleRate
(3)channelLayouts
声道布局,uint数组
(4)channelCount
声道数,uint数组
4、新特性配置
5.0-Beta1版本支持
(1)isSupportLowLatency
是否支持低延时,bool类型
(2)isSupportTSVC
是否支持全局时域可分层特性(SVC),编码参数,bool类型
(3)isSupportLTR
是否支持长期参考帧,编码参数,bool类型
(4)maxLTRFrameNum
编码最大支持的长期参考帧个数,uint类型
媒体框架层获取这些配置信息,应用通过特性能力查询接口来校验是否支持这些新特性
OH_AVCapability *cap = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true);
bool isSupportedLowLatency = OH_AVCapability_isFeatureSupported(cap, VIDEO_LOW_LATENCY);
bool isSupportedTSVC = OH_AVCapability_isFeatureSupported(cap,VIDEO_ENCODER_TEMPORAL_SCALABILITY);
bool isSupportedLTR = OH_AVCapability_isFeatureSupported(cap, VIDEO_ENCODER_LONG_TERM_REFERENCE);
三、结语
HCS组件配置中,部分参数需要按照芯片实际能力配置,如分辨率范围、支持的像素格式、码率模式等,部分参数只是用于avcodeclist模块获取当前组件的特定能力,可填写默认值。
更多推荐
所有评论(0)