title: Android MediaCodec fails to start
body: <p>I'm trying to use MediaCodec to generate a mp4 file from a set of bitmaps i have.<br>
  After a lot of coding and testing I noticed that no example existent on internet or whatever work on the Android Studio emulator, but they do work in both of my real phone (android 7 and 9)... So i kept develoing only testing on real phones.</p>
  
  <p>after a lot of coding and testing i got a working coding (working for both of my phones but crashing for the android emulator) and deployed to production.</p>
  
  <p>My has been online for a couple of months and I have around 150 daily users, but around 30% of them are getting the same crash i noticed on the android emulator. so that isn't a limitation of the emulator.</p>
  
  <p>E/ACodec: [OMX.google.h264.encoder] configureCodec returning error -38
      signalError(omxError 0x80001001, internalError -2147483648)
  E/MediaCodec: Codec reported err 0x80001001, actionCode 0, while in state 3
  E/MediaCodec: configure failed with err 0x80001001, resetting... </p>
  
  <pre><code>private static MediaCodecInfo selectCodec(String mimeType) {
          int numCodecs = MediaCodecList.getCodecCount();
          for (int i = 0; i &lt; numCodecs; i++) {
              MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
              if (!codecInfo.isEncoder()) {
                  continue;
              }
              String[] types = codecInfo.getSupportedTypes();
              for (String type : types) {
                  if (type.equalsIgnoreCase(mimeType)) {
                      return codecInfo;
                  }
              }
          }
          return null;
      }
  
  
  MediaCodecInfo codecInfo = EncoderUtils.selectCodec("video/avc");
  MediaCodec.createByCodecName(codecInfo.getName()).encoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
  </code></pre>
  
  <p><code>format</code> has the following keys</p>
  
  <pre><code>"color-format" -&gt; {Integer@17131} 21
  "i-frame-interval" -&gt; {Integer@17133} 3
  "mime" -&gt; "video/avc"
  "profile" -&gt; {Integer@17136} 8
  "width" -&gt; {Integer@17138} 928
  "bitrate-mode" -&gt; {Integer@17140} 0
  "bitrate" -&gt; {Integer@17142} 3500000
  "language" -&gt; "eng"
  "frame-rate" -&gt; {Integer@17146} 12
  "max-input-size" -&gt; {Integer@17140} 0
  "height" -&gt; {Integer@17149} 1152
  </code></pre>
  
  <p>then i get the following exception:</p>
  
  <pre><code>Non-fatal Exception: android.media.MediaCodec$CodecException: Error 0x80001001
         at android.media.MediaCodec.native_configure(MediaCodec.java)
         at android.media.MediaCodec.configure(MediaCodec.java:1960)
         at android.media.MediaCodec.configure(MediaCodec.java:1889)
         at com.tomatedigital.lottogram.util.EncoderUtils.start(EncoderUtils.java:98)
         at com.tomatedigital.lottogram.service.LottogramService$3.run(LottogramService.java:329)
         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
         at java.lang.Thread.run(Thread.java:764)
  </code></pre>
  
  <p>while the logcat prints:</p>
  
  <pre><code>I/OMXClient: IOmx service obtained
  E/ACodec: [OMX.google.h264.encoder] configureCodec returning error -38
      signalError(omxError 0x80001001, internalError -2147483648)
  E/MediaCodec: Codec reported err 0x80001001, actionCode 0, while in state 3
  E/MediaCodec: configure failed with err 0x80001001, resetting...
  I/OMXClient: IOmx service obtained
  W/AMessage: failed to deliver message as target handler 7 is gone.
  E/ACodec: [OMX.google.h264.encoder] configureCodec returning error -38
      signalError(omxError 0x80001001, internalError -2147483648)
  E/MediaCodec: Codec reported err 0x80001001, actionCode 0, while in state 3
  E/MediaCodec: configure failed with err 0x80001001, resetting...
  I/OMXClient: IOmx service obtained
  </code></pre>
  
  <p>there is no such reference to 0x80001001 error anywhere i could find. what does it mean? how to solve it? does anyone have any clue?</p>