title: How MediaCodec finds the codec inside the framework in Android?
body: <p>I am trying to understanding how MediaCodec is used for hardware decoding. </p>
  
  <p>My knowledge in android internal is very limited. </p>
  
  <p><strong>Here is my findings:</strong></p>
  
  <p>There is a xml file which represents the codec details in the android system .</p>
  
  <pre><code> device/ti/omap3evm/media_codecs.xml for an example. 
  </code></pre>
  
  <p>Which means, that If we create a codec from the Java Application with Media Codec</p>
  
  <pre><code>MediaCodec codec = MediaCodec.createDecoderByType(type);
  </code></pre>
  
  <p>It should be finding out respective coder with the help of xml file. </p>
  
  <p><strong>What am I  doing?</strong></p>
  
  <p>I am trying to figure our which part of the code is reading xml and find the codec based on given 'type'. </p>
  
  <p>1)   Application Layer :  </p>
  
  <pre><code>   MediaCodec codec = MediaCodec.createDecoderByType(type);
  </code></pre>
  
  <p>2)   MediaCodec.java  ->  [ <strong>frameworks/base/media/java/android/media/MediaCodec.java</strong>  ]</p>
  
  <pre><code>     public static MediaCodec createDecoderByType(String type) {
  
      return new MediaCodec(type, true /* nameIsType */, false /* encoder */);
  }
  </code></pre>
  
  <p>3)</p>
  
  <pre><code>private MediaCodec(
          String name, boolean nameIsType, boolean encoder) {
      native_setup(name, nameIsType, encoder);    --&gt; JNI Call.
  }
  </code></pre>
  
  <p>4) 
  JNI Implementation -> [ <strong>frameworks/base/media/jni/android_media_MediaCodec.cpp</strong> ]</p>
  
  <pre><code>static void android_media_MediaCodec_native_setup (..) {
          .......
      const char *tmp = env-&gt;GetStringUTFChars(name, NULL);
      sp&lt;JMediaCodec&gt; codec = new JMediaCodec(env, thiz, tmp, nameIsType, encoder);     ---&gt; Here
  }
  </code></pre>
  
  <p>from frameworks/base/media/jni/android_media_MediaCodec.cpp</p>
  
  <pre><code>    JMediaCodec::JMediaCodec( ..) { 
           .... 
            mCodec = MediaCodec::CreateByType(mLooper, name, encoder); //Call goes to libstagefright 
            .... }
  
  
      sp&lt;MediaCodec&gt; MediaCodec::CreateByType(
              const sp&lt;ALooper&gt; &amp;looper, const char *mime, bool encoder) {
          sp&lt;MediaCodec&gt; codec = new MediaCodec(looper);
          if (codec-&gt;init(mime, true /* nameIsType */, encoder) != OK) {  --&gt; HERE.
              return NULL;
          }    
      return codec;
     }
  
  
  
      status_t MediaCodec::init(const char *name, bool nameIsType, bool encoder) {
             // MediaCodec
      }
  </code></pre>
  
  <p>I am struck with this flow. If someone points out how to take it forward would help a lot. </p>
  
  <p>thanks. </p>