资源描述:
《李世杰---stagefright学习报告》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、在Java中,若要播放一个影片档,我们会这样写:MediaPlayermp=newMediaPlayer();mp.setDataSource(PATH_TO_FILE);......(1)mp.prepare();........................(2)、(3)mp.start();..........................(4)mediaplayer.java:publicstaticMediaPlayercreate(Contextcontext,intresid):MediaPlay
2、ermp=newMediaPlayer();mp.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());afd.close();mp.prepare();returnmp;privatevoidsetDataSource(Stringpath,String[]keys,String[]values)实现setDataSource:_setDataSource(path,keys,values);//该函数为native
3、函数,程序通过此native函数关联jni层的android_media_MediaPlayer.cpp;publicnativevoidprepare()throwsIOException,IllegalStateException;//该函数为native函数,程序通过此native函数关联jni层的android_media_MediaPlayer.cpp;当底层程序确认该准备的数据就绪,会调用privatestaticvoidpostEventFromNative(Objectmediaplayer_ref
4、,intwhat,intarg1,intarg2,Objectobj)这个native函数请求start:if(what==MEDIA_INFO&&arg1==MEDIA_INFO_STARTED_AS_NEXT){//thisacquiresthewakelockifneeded,andsetstheclientsidestatemp.start();publicvoidstart()throwsIllegalStateException:_start();//该函数为native函数,程序通过此native函数
5、关联jni层的android_media_MediaPlayer.cpp;android_media_MediaPlayer.cpp:staticJNINativeMethodgMethods[]这个数组会将java的native函数与C/C++中的本地实现关联起来,如下:{"_setDataSource","(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;)V",(void*)android_media_MediaPlayer_setDataSou
6、rceAndHeaders},{"prepare","()V",(void*)android_media_MediaPlayer_prepare},{"prepareAsync","()V",(void*)android_media_MediaPlayer_prepareAsync},{"_start","()V",(void*)android_media_MediaPlayer_start},红色字体:java的native函数名称;黄色字体:函数参数的signature表示,jni.h中有相应的接口使用sign
7、ature实现java和C/C++之间的参数解析及传递;绿色字体:C/C++中与javanative函数对应的函数名称。staticvoidandroid_media_MediaPlayer_setDataSourceAndHeaders(JNIEnv*env,jobjectthiz,jstringpath,jobjectArraykeys,jobjectArrayvalues):spmp=getMediaPlayer(env,thiz);//获取mediaplayer实例mp->setD
8、ataSource(pathStr,headersVector.size()>0?&headersVector:NULL);//调用mediaplayer的setDataSource方法process_media_player_call(env,thiz,opStatus,"java/io/IOException","setDataSourcefailed.