欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

android7.1 MediaCodec到OMX流程

程序员文章站 2022-08-24 10:27:11
0.frameworks/base/media/java/android/media/mediacodec.java <1>.public static mediacodec cr...
0.frameworks/base/media/java/android/media/mediacodec.java
<1>.public static mediacodec createdecoderbytype(@nonnull string type) {
    eturn new mediacodec(type, true /* nameistype */, false /* encoder */); 
  }

<2>.public static mediacodec createencoderbytype(@nonnull string type){
    return new mediacodec(type, true /* nameistype */, true /* encoder */);
}

<3>.public static mediacodec createbycodecname(@nonnull string name){
    new mediacodec(name, false /* nameistype */, false /* unused */);
}

<4>.private mediacodec( @nonnull string name, boolean nameistype, boolean encoder) {
   native_setup(name, nameistype, encoder);
}


1.frameworks/base/media/jni/android_media_mediacodec.cpp
<1>.static void android_media_mediacodec_native_setup(){
    sp codec = new jmediacodec(env, thiz, tmp, nameistype, encoder);
 }

<2>.jmediacodec::jmediacodec(const char *name, bool nameistype, bool encoder){
    if(nameistype) { 
      mcodec = mediacodec::createbytype(mlooper, name, encoder, &minitstatus);
    }else{
      mcodec = mediacodec::createbycomponentname(mlooper, name, &minitstatus); 
    }
  }

2.frameworks/av/media/libstagefright/mediacodec.cpp
<1>sp mediacodec::createbycomponentname(){
   sp codec = new mediacodec(looper, pid);
   const status_t ret = codec->init(name, false /* nameistype */, false /* encoder */); 
}

sp mediacodec::createbytype(){
   sp codec = new mediacodec(looper, pid); 
   const status_t ret = codec->init(mime, true /* nameistype */, encoder);
}

<2>. status_t mediacodec::init(const astring &name, bool nameistype, bool encoder){
  sp msg = new amessage(kwhatinit, this);
}
<3>.case kwhatinit:{ 
  mcodec->initiateallocatecomponent(format); 
  break;
}
3.frameworks/av/media/libstagefright/acodec.cpp 
<1>.void acodec::initiateallocatecomponent(const sp &msg) {
     msg->setwhat(kwhatallocatecomponent); 
     msg->settarget(this); 
     msg->post();
}

<2>.bool acidic::uninitializedstate::onmessagereceived(const sp &msg) {
     case acodec::kwhatallocatecomponent: 
          onallocatecomponent(msg);
          handled = true;
          break;
}

<3>.bool acodec::uninitializedstate::onallocatecomponent(const sp &msg) {
   astring componentname;//就是codec编解码器的name
   err = omx->allocatenode(componentname.c_str(), observer, &mcodec->mnodebinder, &node);
}
4.frameworks/av/media/libstagefright/omx/omx.cpp
status_t omx::allocatenode(const char *name,…){
  omx_errortype err = mmaster->makecomponentinstance(name,…)
}

5.frameworks/av/media/libstagefright/omx/omxmaster.cpp
omx_errortype omxmaster::makecomponentinstance(const char* name,…){
   aloge("----omxmaster----------> %s(), line = %d, name = %s", __function__, __line__,name);
}