I would like to utilize OMX HW renderer as described here: http://www.slideshare.net/RaghavanVenkateswaran/iomx-in-android
OS: Android 2.3.4
System libaries used: libmedia, libbinder, libstagefright, libutils
OMX components on my device:
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
I have done these steps:
1, Passed the Android Surface object through the JNI that way (exactly as in the native 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);
}
}
Surface variable in MMediaPlayer is declared as:
android::sp<android::Surface> surface;
Java:
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, Initialized the IOMX node:
Note: hardcoded values are there only for simplicity and testing purposes
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, Tried to create the OMX Renderer:
android::sp<android::IOMXRenderer> mOMXRenderer;
mOMXRenderer = omxContext->iomx->createRenderer(surface, "OMX.TI.VPP", OMX_COLOR_FormatYUV420Planar, 256, 144, displayWidth, displayHeight, 0);
which always returns NULL.
Has anybody an idea what’s wrong with that? Am I initializing wrong component? Or there must be followed some special calling sequence? Or something else?