title: OMXCodec die when start decoding
body: <p>I'd like to retrieve frames from video file. </p>
  
  <p>My code followed the article <a href="https://vec.io/posts/use-android-hardware-decoder-with-omxcodec-in-ndk" rel="nofollow">Use Android Hardware Decoder with OMXCodec in NDK</a>, and also referred the code of AwesomePlayer.cpp(AOSP) and libstagefright.cpp(ffmpeg). But it still hangs whenever OMXCodec start decoding. I have no idea what the problem is. </p>
  
  <p>I'd grateful for any help.</p>
  
  <p>the code:</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      OMXClient mClient;
      status_t ret = mClient.connect();
      LOGD("connect status is %d\n", ret);
  
      sp&lt;DataSource&gt; mDs = DataSource::CreateFromURI("file:///sdcard/display/lwtwjod.mp4");
      off64_t size = 0;
      ret = mDs-&gt;getSize(&amp;size);
      LOGD("getSize[ret=%d]: %lld\n", ret, size);
  
      sp&lt;MediaExtractor&gt; mMe = MediaExtractor::Create(mDs);
      size_t tracksNum = mMe-&gt;countTracks();
      LOGD("%u tracks\n", tracksNum);
  
      sp&lt;MediaSource&gt; mMs;
  
      bool hasVideo = false;
      for(size_t i = 0; i != mMe-&gt;countTracks(); i++){
      sp&lt;MetaData&gt; mMd_track = mMe-&gt;getTrackMetaData(i);
          const char *_mime;
      mMd_track-&gt;findCString(kKeyMIMEType, &amp;_mime);
          LOGD("the mime is %s\n", _mime);
          String8 mime = String8(_mime);
  
          if (!strncasecmp(mime.string(), "video/", 6)) {
          LOGD("find video track!\n");
          hasVideo = true;
          mMs = mMe-&gt;getTrack(i);
          int wid, hei;
          mMd_track-&gt;findInt32(kKeyWidth, &amp;wid);
          mMd_track-&gt;findInt32(kKeyHeight, &amp;hei);
          LOGD("width: %d, height: %d\n", wid, hei);
          break;
      }
      }
  
      if(hasVideo){
      sp&lt;MediaSource&gt; decoder = 
          OMXCodec::Create(mClient.interface(), mMs-&gt;getFormat(),
                   false, mMs, 
                   NULL, OMXCodec::kClientNeedsFramebuffer);
      LOGD("start decoding..\n");
      ret = decoder-&gt;start(); // hangs here
      LOGD("decoding return: %d\n", ret);
  
      for(;;){
          MediaBuffer *buffer;
          buffer = NULL;
          ret = decoder-&gt;read(&amp;buffer);
          LOGD("read decoded buffer result: %d\n", ret);
          break;
      }
      }    
  }  
  </code></pre>
  
  <p>The logcat output:</p>
  
  <pre><code>I/OMXClient( 5470): Using client-side OMX mux.
  D/NativeCodec( 5470): connect status is 0
  D/NativeCodec( 5470): getSize[ret=0]: 165748860
  D/NativeCodec( 5470): 2 tracks
  D/NativeCodec( 5470): the mime is video/avc
  D/NativeCodec( 5470): find video track!
  D/OMXCodec( 5470): Successfully allocated OMX node 'OMX.qcom.video.decoder.avc'
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] AVC profile = 100 (High), level = 31
  E/OMX-VDEC-1080P(  197): 
  E/OMX-VDEC-1080P(  197):  No color conversion required
  E/OMX-VDEC-1080P(  197): 
  E/OMX-VDEC-1080P(  197):  No color conversion required
  E/OMX-VDEC-1080P(  197): 
  E/OMX-VDEC-1080P(  197):  No color conversion required
  E/OMX-VDEC-1080P(  197): 
  E/OMX-VDEC-1080P(  197):  No color conversion required
  E/OMX-VDEC-1080P(  197): 
  E/OMX-VDEC-1080P(  197):  No color conversion required
  E/OMX-VDEC-1080P(  197): 
  E/OMX-VDEC-1080P(  197):  No color conversion required
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] video dimensions are 1280 x 720
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] Crop rect is 1280 x 720 @ (0, 0)
  D/NativeCodec( 5470): start decoding..
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocating 2 buffers of size 2097152 on input port
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8e39390 on input port
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8e393e0 on input port
  E/OMX-VDEC-1080P(  197): 
  E/OMX-VDEC-1080P(  197):  No color conversion required
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocating 15 buffers of size 1433600 on output port
  E/OMX-VDEC-1080P(  197): GET_MV_BUFFER_SIZE returned: Size: 245760 and alignment: 8192
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9b08 on output port
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9b58 on output port
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9ba8 on output port
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9bf8 on output port
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9c48 on output port
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9c98 on output port
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9ce8 on output port
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9d38 on output port
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9d88 on output port
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9dd8 on output port
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9e28 on output port
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9e78 on output port
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9ec8 on output port
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9f18 on output port
  I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9f68 on output port
  E/OMXNodeInstance(  197): !!! Observer died. Quickly, do something, ... anything...
  I/OMXNodeInstance(  197): OMX_FreeBuffer for buffer header 0xb8eb9f68 successful
  I/OMXNodeInstance(  197): OMX_FreeBuffer for buffer header 0xb8eb9f18 successful
  I/OMXNodeInstance(  197): OMX_FreeBuffer for buffer header 0xb8eb9ec8 successful
  I/OMXNodeInstance(  197): OMX_FreeBuffer for buffer header 0xb8eb9e78 successful
  I/OMXNodeInstance(  197): OMX_FreeBuffer for buffer header 0xb8eb9e28 successful
  I/OMXNodeInstance(  197): OMX_FreeBuffer for buffer header 0xb8eb9dd8 successful
  I/OMXNodeInstance(  197): OMX_FreeBuffer for buffer header 0xb8eb9d88 successful
  I/OMXNodeInstance(  197): OMX_FreeBuffer for buffer header 0xb8eb9d38 successful
  I/OMXNodeInstance(  197): OMX_FreeBuffer for buffer header 0xb8eb9ce8 successful
  I/OMXNodeInstance(  197): OMX_FreeBuffer for buffer header 0xb8eb9c98 successful
  I/OMXNodeInstance(  197): OMX_FreeBuffer for buffer header 0xb8eb9c48 successful
  I/OMXNodeInstance(  197): OMX_FreeBuffer for buffer header 0xb8eb9bf8 successful
  I/OMXNodeInstance(  197): OMX_FreeBuffer for buffer header 0xb8eb9ba8 successful
  I/OMXNodeInstance(  197): OMX_FreeBuffer for buffer header 0xb8eb9b58 successful
  I/OMXNodeInstance(  197): OMX_FreeBuffer for buffer header 0xb8eb9b08 successful
  I/OMXNodeInstance(  197): OMX_FreeBuffer for buffer header 0xb8e393e0 successful
  I/OMXNodeInstance(  197): OMX_FreeBuffer for buffer header 0xb8e39390 successful
  E/OMX-VDEC-1080P(  197): 
  E/OMX-VDEC-1080P(  197):  Error in ioctl read next msg
  E/        (  197): 
  E/        (  197):  Destroy C2D instance
  E/        (  197): 
  E/        (  197):  Destroy C2D instance
  </code></pre>