我想使用OMX HW渲染器,如下所述: http://www.slideshare.net/RaghavanVenkateswaran/iomx-in-android
操作系统 Android 2.3.4
使用的系统库: libmedia,libbinder,libstagefright,libutils
设备上的OMX组件:
componentName:OMX.ITTIAM.AAC.decode,componentRole:audio_decoder.aac
componentName:OMX.ITTIAM.AAC.encode,componentRole:audio_encoder.aac
componentName:OMX.TI.720P.Decoder,componentRole:video_decoder.mpeg4
componentName:OMX.TI.720P.Decoder,componentRole:video_decoder.avc
componentName:OMX.TI.720P.Encoder,componentRole:video_encoder.mpeg4
componentName:OMX.TI.720P.Encoder,componentRole:video_encoder.avc
componentName:OMX.TI.AAC.decode,componentRole:audio_decoder.aac
componentName:OMX.TI.AAC.encode,componentRole:audio_encoder.aac
componentName:OMX.TI.AMR.decode,componentRole:audio_decoder.amrnb
componentName:OMX.TI.AMR.encode,componentRole:audio_encoder.amrnb
componentName:OMX.TI.Camera,componentRole:camera.yuv
componentName:OMX.TI.JPEG.decoder,componentRole:image_decoder.jpeg
componentName:OMX.TI.JPEG.encoder,componentRole:image_encoder.jpeg
componentName:OMX.TI.MP3.decode,componentRole:audio_decoder.mp3
componentName:OMX.TI.VPP,componentRole:iv_renderer.yuv.overlay
componentName:OMX.TI.Video.Decoder,componentRole:video_decoder.h263
componentName:OMX.TI.Video.Decoder,componentRole:video_decoder.avc
componentName:OMX.TI.Video.Decoder,componentRole:video_decoder.mpeg2
componentName:OMX.TI.Video.Decoder,componentRole:video_decoder.mpeg4
componentName:OMX.TI.Video.Decoder,componentRole:video_decoder.wmv
componentName:OMX.TI.Video.encoder,componentRole:video_encoder.mpeg4
componentName:OMX.TI.Video.encoder,componentRole:video_encoder.h263
componentName:OMX.TI.Video.encoder,componentRole:video_encoder.avc
componentName:OMX.TI.WBAMR.decode,componentRole:audio_decoder.amrwb
componentName:OMX.TI.WBAMR.encode,componentRole:audio_encoder.amrwb
componentName:OMX.TI.WMA.decode,componentRole:audio_decoder.wma
我已完成以下步骤:
1,通过JNI传递Android Surface对象(与原生MediaPlayer完全相同):
JNI(C ++):
static void com_mautilus_media_MMediaPlayer_setVideoSurface(JNIEnv *env, jobject thiz)
{
__android_log_print(ANDROID_LOG_INFO, TAG, "setVideoSurface");
MMediaPlayer *mp = getMediaPlayer(env, thiz);
if (mp == NULL )
{
jniThrowException(env, "java/lang/IllegalStateException", NULL);
return;
}
setVideoSurface(mp, env, thiz);
}
static void setVideoSurface(MMediaPlayer *mp, JNIEnv *env, jobject thiz)
{
__android_log_print(ANDROID_LOG_INFO, TAG, "setVideoSurface");
jobject surface = env->GetObjectField(thiz, fields.surface);
if (surface != NULL && mp != NULL)
{
const android::sp<android::Surface> native_surface = get_surface(env, surface);
mp->setVideoSurface(native_surface);
}
}
MMediaPlayer中的表面变量声明为:
android::sp<android::Surface> surface;
爪哇:
private Surface mSurface; // accessed by native methods
private SurfaceHolder mSurfaceHolder;
public void setDisplay(SurfaceHolder sh)
{
mSurfaceHolder = sh;
if (sh != null)
{
mSurface = sh.getSurface();
}
else
{
mSurface = null;
}
setVideoSurface(); // Native function call
}
2,初始化IOMX节点:
注意:硬编码值仅用于简化和测试目的
android::sp<android::IServiceManager> serviceManager = android::defaultServiceManager();
android::sp<android::IBinder> binder = serviceManager>getService(android::String16("media.player"));
android::sp<android::IMediaPlayerService> mediaPlayerService = android::interface_cast<android::IMediaPlayerService>(binder);
android::sp<android::IOMX> iomx = mediaPlayerService->getOMX();
android::IOMX::node_id node;
// observer is instance of class derived from android::BnOMXObserver class
iomx->allocateNode("OMX.TI.VPP", observer, &mRendererNode->node);
OMX_PARAM_PORTDEFINITIONTYPE portDefn;
portDefn.nPortIndex = 1;
iomx->getParameter(node, OMX_IndexParamPortDefinition, &portDefn, sizeof(portDefn));
//portDefn.nBufferCountActual = mInBufCnt; // set some suitable value here or don’t update to
//use default value
portDefn.format.video.nFrameWidth = 256; // width of the video to be played
portDefn.format.video.nFrameHeight = 144; // height of video to be played
portDefn.format.video.nStride = 256;
portDefn.format.video.nSliceHeight = 144;
iomx->setParameter(node, OMX_IndexParamPortDefinition, &portDefn, sizeof(portDefn));
portDefn.nPortIndex = 2;
iomx->getParameter(node, OMX_IndexParamPortDefinition, &portDefn, sizeof(portDefn));
//portDefn.nBufferCountActual = iOutBufCnt; // set suitable value or leave to default.
portDefn.nBufferSize = (256 * 144 * 3) / 2;
portDefn.format.video.nFrameWidth = 256;
portDefn.format.video.nFrameHeight = 144;
portDefn.format.video.nStride = 256;
portDefn.format.video.nSliceHeight = 144;
iomx->setParameter(node, OMX_IndexParamPortDefinition, &portDefn, sizeof(portDefn));
3,尝试创建OMX渲染器:
android::sp<android::IOMXRenderer> mOMXRenderer;
mOMXRenderer = omxContext->iomx->createRenderer(surface, "OMX.TI.VPP", OMX_COLOR_FormatYUV420Planar, 256, 144, displayWidth, displayHeight, 0);
总是返回NULL。
有人知道这有什么问题吗?我是在初始化错误的组件吗?或者必须遵循一些特殊的呼叫顺序?或其他什么?
答案 0 :(得分:1)
使用IOMX.h中定义的createRendererFromJavaSurface