上篇传送门: OpenHarmony AVCodec模块分析(三):Codec HDI适配(一)

4、IPC

(1)系统属性

服务层默认不会通过IPC模式调用Codec HDI,可设置系统属性 param set hcodec.usePassthrough false 使能该模式,这种模式下Codec HDI位于codec_host进程中。

(2)配置codec_host 服务

以rk3568为例,配置如下文件 vendor/hihope/rk3568/hdf_config/uhdf/device_info.hcs

codec :: host {
    hostName = "codec_host";
    priority = 50;
    gid = ["codec_host", "uhdf_driver", "vendor_mpp_driver"];
    codec_omx_device :: device {
        device0 :: deviceNode {
        policy = 2;
        priority = 100;
        moduleName = "libcodec_hdi_omx_server.z.so";
        serviceName = "codec_hdi_omx_service";
        deviceMatchAttr = "media_codec_capabilities";
        }
    }
    codec_omx_idl_device :: device {
        device0 :: deviceNode {
        policy = 2;
        priority = 100;
        moduleName = "libcodec_driver.z.so";
        serviceName = "codec_component_manager_service";
        deviceMatchAttr = "media_codec_capabilities";
        }
    }
    ...
}

第一个codec_hdi_omx_service服务被AVPlayer gstreamer引擎硬件编解码插件调用;第二个codec_component_manager_service 服务被AVCodec视频编解码服务层调用的,重点是这个服务的配置。
deviceMatchAttr 建议设置 media_codec_capabilities,与passthrough方式保持一致,方便兼容。

(3)配置codec_capabilities hcs文件

根据codec_host codec_component_manager_service 服务配置的deviceMatchAttr,codec_capabilities hcs文件的match_attr 为media_codec_capabilities
以rk3568为例,添加 vendor/hihope/rk3568/hdf_config/uhdf/media_codec/media_codec_capabilities.hcs 文件

root {
    module = "master";
    codec_config {
        match_attr = "media_codec_capabilities";
        use_openmax = true;
        // capsMask: 0x01, Adaptive playback; 0x02, Secure playback; 0x04, Tunnel playback.
        // allocateMask: 0x01, Input buffer allocated within the Codec module;
        // allocateMask: 0x02, Input buffer allocated by an external user;
        // allocateMask: 0x04, Output buffer allocated within the Codec module;
        // allocateMask: 0x08, Output buffer allocated by an external user.

        VideoHwEncoders {
            /* node name explanation -- HDF_video_hw_enc_avc_rk:
            **
            **    HDF____________video_________hw___________________enc_________avc____rk
            **       |                                |                       |                                          |                       |            |
            ** HDF or OMX    video or audio    hardware or software      encoder or decoder    mime    vendor
            */
            HDF_video_hw_enc_avc_rk {
                role = 1;
                type = 1;
                name = "OMX.rk.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_rk {
                role = 1;
                type = 0;
                name = "OMX.rk.video_decoder.avc";
                supportProfiles = [1, 32768, 2, 32768, 8, 32768];
                maxInst = 6;
                isSoftwareCodec = false;
                processModeMask = [];
                capsMask = [0x01];
                minBitRate = 1;
                maxBitRate = 10000000;
                minWidth = 144;
                minHeight = 144;
                maxWidth = 4096;
                maxHeight = 4096;
                widthAlignment = 2;
                heightAlignment = 2;
                minBlockCount = 99;
                maxBlockCount = 34560;
                minBlocksPerSecond = 99;
                maxBlocksPerSecond = 2073600;
                blockSizeWidth = 16;
                blockSizeHeight = 16;
                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;
            }
        ...
        }
    }
}

注意match_attr 必须为codec_host codec_component_manager_service 服务配置的 deviceMatchAttr

(4)hdf.hcs文件引入codec_capabilities hcs文件

以rk3568为例,vendor/hihope/rk3568/hdf_config/uhdf/hdf.hcs

+     #include "media_codec/media_codec_capabilities.hcs"

(5)OMX Wrapper的封装

封装实现libOMX_Core.z.so,供Codec HDI接口dlopen调用。

三、适配验证

适配完成后可以编译foundation/multimedia/av_codec/test/nativedemo/codeclist_demo/codeclist_demo.cpp 生成av_codec_demo简单测试或使用其他三方应用测试,看能否获取到硬件解码器。适配成功首次调用到codeclist接口会有如下打印:

I C02bac/HCODEC: [hcodec_list.cpp][IsPassthrough 32] passthrough mode

I C02bac/HCODEC: [hcodec_list.cpp][IsPassthrough 32] ipc mode

组件能力列表

I C02bac/HCODEC: [hcodec_list.cpp][GetCapList 64] GetComponentCapabilityList return xxx components
I C02bac/HCODEC: [hcodec_list.cpp][HdiCapToUserCap 111] ----- codecName: OMX.xxx.video_encoder.avc -----
I C02bac/HCODEC: [hcodec_list.cpp][HdiCapToUserCap 113] codecType: 1, mimeType: video/avc, maxInstance 4
...
I C02bac/HCODEC: [hcodec_list.cpp][HdiCapToUserCap 111] ----- codecName: OMX.xxx.video_decoder.avc -----
I C02bac/HCODEC: [hcodec_list.cpp][HdiCapToUserCap 113] codecType: 0, mimeType: video/avc, maxInstance 6

四、结语

目前支持的视频编解码格式有限,下一篇介绍如何扩展新的视频编解码格式。

Logo

社区规范:仅讨论OpenHarmony相关问题。

更多推荐