dequeueOutputBuffer eleva IllegalStateException cuando se utiliza COLOR_FormatYUV420Codec compatible con Planar

Estoy corriendo esta simple prueba de MediaCodec en LG G2 con Android 4.4.2:

 public class MyActivity extends Activity { private static final String MIME_TYPE = "video/avc"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, 1280, 720); int numCodecs = MediaCodecList.getCodecCount(); for (int i = 0; i < numCodecs; i++) { MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i); if (codecInfo.isEncoder()) { String[] types = codecInfo.getSupportedTypes(); for (int j = 0; j < types.length; j++) { if (types[j].equalsIgnoreCase(MIME_TYPE)) { MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(MIME_TYPE); for(int colorFormat : capabilities.colorFormats) { if (colorFormat == MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar) { format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar); format.setInteger(MediaFormat.KEY_BIT_RATE, 1000000); format.setInteger(MediaFormat.KEY_FRAME_RATE, 15); format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 10); MediaCodec mMediaCodec = MediaCodec.createByCodecName(codecInfo.getName()); mMediaCodec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE); mMediaCodec.start(); MediaCodec.BufferInfo mBufferInfo = new MediaCodec.BufferInfo(); mMediaCodec.dequeueOutputBuffer(mBufferInfo, 1000); return; } } } } } } } } 

Y plantea el error siguiente:

 04-21 18:08:29.531 6513-6513/com.example.mediacodec I/OMXClient﹕ Using client-side OMX mux. 04-21 18:08:29.531 6513-6513/com.example.mediacodec E/OMXMaster﹕ A component of name 'OMX.qcom.audio.decoder.aac' already exists, ignoring this one. 04-21 18:08:29.531 6513-6513/com.example.mediacodec I/﹕ @@@VOLOG Info THD 4001A154: VOOMXPlugin.cpp VOOMXPlugin 59 open libvoOMXOne.so successfully. 0X5BB9A5B8 04-21 18:08:29.541 6513-6513/com.example.mediacodec E/﹕ VOLOG Info THD 4001A154 voCOMXBaseConfig.cpp Open 368 The config file vomeOne.cfg could not be opened! 04-21 18:08:29.541 6513-6513/com.example.mediacodec I/SoftAVCEncoder﹕ Construct SoftAVCEncoder 04-21 18:08:29.541 6513-6536/com.example.mediacodec I/OMXClient﹕ Using client-side OMX mux. 04-21 18:08:29.541 6513-6536/com.example.mediacodec E/OMXMaster﹕ A component of name 'OMX.qcom.audio.decoder.aac' already exists, ignoring this one. 04-21 18:08:29.541 6513-6536/com.example.mediacodec I/﹕ @@@VOLOG Info THD 60471CD0: VOOMXPlugin.cpp VOOMXPlugin 59 open libvoOMXOne.so successfully. 0X5BB9A370 04-21 18:08:29.541 6513-6536/com.example.mediacodec E/﹕ VOLOG Info THD 60471CD0 voCOMXBaseConfig.cpp Open 368 The config file vomeOne.cfg could not be opened! 04-21 18:08:29.541 6513-6536/com.example.mediacodec I/SoftAVCEncoder﹕ Construct SoftAVCEncoder 04-21 18:08:29.541 6513-6536/com.example.mediacodec E/SoftAVCEncoder﹕ internalSetParameter: StoreMetadataInBuffersParams.nPortIndex not zero! 04-21 18:08:29.541 6513-6536/com.example.mediacodec E/OMXNodeInstance﹕ OMX_SetParameter() failed for StoreMetaDataInBuffers: 0x80001001 04-21 18:08:29.541 6513-6536/com.example.mediacodec E/ACodec﹕ [OMX.google.h264.encoder] storeMetaDataInBuffers (output) failed w/ err -2147483648 04-21 18:08:29.541 6513-6536/com.example.mediacodec I/ACodec﹕ setupVideoEncoder succeeded 04-21 18:08:29.541 6513-6537/com.example.mediacodec E/SoftAVCEncoder﹕ Failed to initialize the encoder: -8 04-21 18:08:29.551 6513-6536/com.example.mediacodec E/ACodec﹕ [OMX.google.h264.encoder] ERROR(0x80001001) 04-21 18:08:29.551 6513-6535/com.example.mediacodec E/MediaCodec﹕ Codec reported an error. (omx error 0x80001001, internalError -2147483648) 04-21 18:08:29.551 6513-6513/com.example.mediacodec D/AndroidRuntime﹕ Shutting down VM 04-21 18:08:29.551 6513-6513/com.example.mediacodec W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x417a8e48) 04-21 18:08:29.551 6513-6513/com.example.mediacodec E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.mediacodec, PID: 6513 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mediacodec/com.example.mediacodec.MyActivity}: java.lang.IllegalStateException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2200) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250) at android.app.ActivityThread.access$800(ActivityThread.java:139) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5105) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.IllegalStateException at android.media.MediaCodec.dequeueOutputBuffer(Native Method) at com.example.mediacodec.MyActivity.onCreate(MyActivity.java:49) at android.app.Activity.performCreate(Activity.java:5275) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)            at android.app.ActivityThread.access$800(ActivityThread.java:139)            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)            at android.os.Handler.dispatchMessage(Handler.java:102)            at android.os.Looper.loop(Looper.java:136)            at android.app.ActivityThread.main(ActivityThread.java:5105)            at java.lang.reflect.Method.invokeNative(Native Method)            at java.lang.reflect.Method.invoke(Method.java:515)            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)            at dalvik.system.NativeStart.main(Native Method) 

El mismo error se puede reproducir en Sony Xperia ZR. Ambos dispositivos también soportan COLOR_FormatYUV420SemiPlanar y funciona bien con los mismos parámetros. He intentado ejecutar EncodeDecodeTest desde el paquete android.media.cts y pasa con éxito, pero parece que sólo prueba el primer formato de color soportado del primer códec compatible que es COLOR_FormatYUV420SemiPlanar en este caso.

en su registro,

 04-21 18:08:29.541 6513-6536/com.example.mediacodec E/SoftAVCEncoder﹕ internalSetParameter: StoreMetadataInBuffersParams.nPortIndex not zero! 04-21 18:08:29.541 6513-6536/com.example.mediacodec E/OMXNodeInstance﹕ OMX_SetParameter() failed for StoreMetaDataInBuffers: 0x80001001 04-21 18:08:29.541 6513-6536/com.example.mediacodec E/ACodec﹕ [OMX.google.h264.encoder] storeMetaDataInBuffers (output) failed w/ err -2147483648 04-21 18:08:29.541 6513-6536/com.example.mediacodec I/ACodec﹕ setupVideoEncoder succeeded 04-21 18:08:29.541 6513-6537/com.example.mediacodec E/SoftAVCEncoder﹕ Failed to initialize the encoder: -8 

AVC detenido que nPortIndex no es cero. vea el siguiente enlace como ref. http://androidxref.com/4.4.2_r2/xref/frameworks/av/media/libstagefright/codecs/avc/enc/SoftAVCEncoder.cpp#684

 686 StoreMetaDataInBuffersParams *storeParams = 687 (StoreMetaDataInBuffersParams*)params; 688 if (storeParams->nPortIndex != 0) { 689 ALOGE("%s: StoreMetadataInBuffersParams.nPortIndex not zero!", 690 __FUNCTION__); 691 return OMX_ErrorUndefined; 692 } 

que hará error en SoftAVCEncoder.cpp,

 150 /** There was an error, but the cause of the error could not be determined */ 151 OMX_ErrorUndefined = (OMX_S32) 0x80001001, 

http://androidxref.com/4.4.2_r2/xref/frameworks/native/include/media/openmax/OMX_Core.h#151

¿Qué tal si revisas tu configuración o buscas una solución para este error?

  • Algoritmo de tasa de bits adaptativo RTMP
  • ¿Cómo inicializar MediaFormat para configurar un MediaCodec para decodificar datos AAC sin procesar?
  • Cómo utilizar MediaCodec sin MediaExtractor para H264
  • Transcodifique vídeo para reducir la velocidad de bits y transmitir
  • Codificador AAC de Android MediaCodec
  • ¿Cómo incrustar texto durante la grabación de vídeo en Android?
  • Conversión de imágenes en vídeo
  • Pausa / Reanudar MediaCodec
  • Decodificador de vídeo acelerado por hardware para H264
  • Error en el codificador OMX.qcom aleatorio
  • Cambiar el tamaño de la vista de la superficie para el cambio de la relación de aspecto en la visualización de vídeo en android
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.