本文介绍了创建OMX codeC连接codeR在硬件模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现在Android ICS 4.0.4 HW-accelrated H264视频编码。由于媒体codec类不可用我一定要使用stagefright API。但是,当我把硬件codecsOnly 标志,OMX codeC:创建总是返回NULL。如果我叫OMX codeC :: findMatching codeCS(),旗kHardware codecsOnly,我得到了下面的列表:
- OMX.TI.DUCATI1.VIDEO.H264E
- OMX.qcom.7x30.video.en coder.avc
- OMX.qcom.video.en coder.avc
- OMX.TI.Video.en codeR
- OMX.Nvidia.h264.en codeR
- OMX.SEC.AVC.En codeR

所以我想这意味着硬件编码支持的硬件。

当我把 OMX codeC无标志:创建 - $ C $创造良好CC,但我想它是在软件模式(顺便说一句,我怎么能入住其中codeC正好被创造?)

浏览OMX codeC的来源,我发现有趣的台词:

 如果(createEn codeR){
SP< MediaSource的>软件codeC =
 InstantiateSoftwareEn codeR(组件名,来源,元);
    如果(软件codeC!= NULL){
    LOGV(成功分配软件codeC'%s'的,组件名称);
    返回软件codeC;
}
}
 

它看起来像恩codeR它总是试图实例软件codeC第一​​。我究竟做错了什么?任何帮助时便会大大AP preciated。谢谢

下面是OMX codeC创建一个code:

  mClient =新OMXClient();
        mClient->连接();
     logger->日志(mClient.connect(););

      enc_meta =新的元数据;
     //帧目标视频文件的大小
    INT宽度= 640; // 720;
    INT高= 480;
     INT kFramerate = 15;
     INT kVideoBitRate = 500000;
     INT kIFramesIntervalSec = 5;
     int32_t colorFormat = OMX_COLOR_FormatYUV420SemiPlanar;

    enc_meta-> setCString(kKeyMIMEType,MEDIA_MIMETYPE_VIDEO_AVC); // MEDIA_MIMETYPE_VIDEO_MPEG4); // MEDIA_MIMETYPE_VIDEO_H263); // MEDIA_MIMETYPE_VIDEO_AVC);
    enc_meta-> setInt32(kKeyWidth,宽度);
    enc_meta-> setInt32(kKeyHeight,高度);
    enc_meta-> setInt32(kKeyFrameRate,kFramerate);
    enc_meta-> setInt32(kKeySampleRate,44100);
    enc_meta-> setInt32(kKeyBitRate,kVideoBitRate);
    enc_meta-> setInt32(kKeyStride,宽度);
    enc_meta-> setInt32(kKeySliceHeight,高度);
    enc_meta-> setInt32(kKeyIFramesInterval,kIFramesIntervalSec);
    enc_meta-> setInt32(kKeyColorFormat,colorFormat);

  mVideoSource = OMX codeC:创建(
            mClient->接口(),
            enc_meta,
            真正,
            MSRC,
            空值,
            OMX codeC :: kHardware codecsOnly);

    logger->日志(OMX codec_CREATED结果数:%d,(mVideoSource = NULL)1:?0);
 

解决方案

安卓 ICS 4.0.4 ,在codeC的注册是静态的,即所有codeCS登记为阵列的一部分肯coderInfo 一样可以找到的。

该方法以硬件软件 codeCS区分是pretty的简单。如果组件名称的开头不是 OMX ,那么它被解释为是一个软件 codeC作为在 IsSoftware codeC 的方法。

既然你想一个 AVC 连接codeR,如果创建将是软件codeC AVCEn codeR 为可以发现,从它的参考。

要检查哪些codeC被创建,您可以通过删除注释为启用 OMX codec.cpp日志文件#定义LOG_NDEBUG 0 中的行,保存并重新编译建立 libstagefright.so 这可能是用于生成的logcat 画面。

编辑:

如果 RTSP 分流,需要启用的。

一个人需要,以确定是否 libstagefrighthw.so 是present在 /系统/ lib目录这将注册在 OMX 核心与 Stagefright 框架。

I'm trying to implement HW-accelrated H264 video encoding on Android ICS 4.0.4. Since MediaCodec class is not available I have to use stagefright API. But when I put HardwareCodecsOnly flag, OMXCodec::Create always returns NULL.If I call OMXCodec::findMatchingCodecs() with flag kHardwareCodecsOnly, I got following list:
- OMX.TI.DUCATI1.VIDEO.H264E
- OMX.qcom.7x30.video.encoder.avc
- OMX.qcom.video.encoder.avc
- OMX.TI.Video.encoder
- OMX.Nvidia.h264.encoder
- OMX.SEC.AVC.Encoder

so I guess it means that HW-encoding supported by hardware.

When I put no flags in OMXCodec::Create - codec created well, but I guess it is in software mode(btw, how can I check- which codec exactly was created?)

Browsing OMXCodec sources I've found interesting lines:

if (createEncoder) {
sp<MediaSource> softwareCodec =
 InstantiateSoftwareEncoder(componentName, source, meta);
    if (softwareCodec != NULL) {
    LOGV("Successfully allocated software codec '%s'", componentName);
    return softwareCodec;
}
}

it looks like for Encoder it always tries to instance Software codec first.What am I doing wrong? Any help wil be greatly appreciated. Thanks

Here's a code of OMXCodec creation:

         mClient = new OMXClient();
        mClient->connect();
     logger->log("mClient.connect();");

      enc_meta = new MetaData;
     // frame size of target video file
    int width = 640; //720;
    int height = 480;
     int kFramerate = 15;
     int kVideoBitRate = 500000;
     int kIFramesIntervalSec = 5;
     int32_t colorFormat = OMX_COLOR_FormatYUV420SemiPlanar;

    enc_meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC); //MEDIA_MIMETYPE_VIDEO_MPEG4); //MEDIA_MIMETYPE_VIDEO_H263);//MEDIA_MIMETYPE_VIDEO_AVC);
    enc_meta->setInt32(kKeyWidth, width);
    enc_meta->setInt32(kKeyHeight, height);
    enc_meta->setInt32(kKeyFrameRate, kFramerate);
    enc_meta->setInt32(kKeySampleRate, 44100);
    enc_meta->setInt32(kKeyBitRate, kVideoBitRate);
    enc_meta->setInt32(kKeyStride, width);
    enc_meta->setInt32(kKeySliceHeight, height);
    enc_meta->setInt32(kKeyIFramesInterval, kIFramesIntervalSec);
    enc_meta->setInt32(kKeyColorFormat, colorFormat);

  mVideoSource = OMXCodec::Create(
            mClient->interface(),
            enc_meta,
            true,
            mSrc,
            NULL,
            OMXCodec::kHardwareCodecsOnly );

    logger->log("OMXCodec_CREATED result: %d", (mVideoSource!=NULL) ? 1 : 0);
解决方案

In Android ICS 4.0.4, the codec registration was static i.e. all codecs were registered as part of an array KEncoderInfo as can be found here.

The methodology to differentiate between hardware and software codecs is pretty simple. If the component name doesn't start with OMX, then it is construed to be a software codec as shown in theIsSoftwareCodec method.

Since you are trying an AVC encoder, the software codec if created would be AVCEncoder as can be found from it's Factory reference.

To check which codec was created, you can enable logs in OMXCodec.cpp file by removing the comment as #define LOG_NDEBUG 0 in this line, save and recompile to build libstagefright.so which could be used to generate the logs on logcat screen.

EDIT:

In case of rtsp streaming, one needs to enable the logs in ACodec.cpp .

One needs to ascertain if libstagefrighthw.so is present in /system/lib which will register the OMX core with the Stagefright framework.

这篇关于创建OMX codeC连接codeR在硬件模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 21:03