Android MediaCodec dequeueOutputBuffer返回非法的缓冲区索引

Android MediaCodec dequeueOutputBuffer返回非法的缓冲区索引,android,android-mediacodec,Android,Android Mediacodec,我按原样编译 大概这在某个地方起作用了,但在我的Nexus7(版本1)上使用Kitkat时,outIndex返回的是5,而videoOutputBuffers只有5长,这导致了IndexOutOfBoundsException 主要相关回路是: int outIndex = videoDecoder.dequeueOutputBuffer(info, 10000); switch (outIndex) { case MediaCodec.INFO_OUTPUT_BUFFERS

我按原样编译

大概这在某个地方起作用了,但在我的Nexus7(版本1)上使用Kitkat时,outIndex返回的是5,而videoOutputBuffers只有5长,这导致了IndexOutOfBoundsException

主要相关回路是:

int outIndex = videoDecoder.dequeueOutputBuffer(info, 10000);
    switch (outIndex) {
      case MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED:
        Log.d(Const.TAG, "INFO_OUTPUT_BUFFERS_CHANGED");
        videoOutputBuffers = videoDecoder.getOutputBuffers();
        break;
      case MediaCodec.INFO_OUTPUT_FORMAT_CHANGED:
        Log.d(Const.TAG, "New format " + videoDecoder.getOutputFormat());
        break;
      case MediaCodec.INFO_TRY_AGAIN_LATER:
        Log.d(Const.TAG, "dequeueOutputBuffer timed out!");
        break;
      default:
        ByteBuffer buffer = videoOutputBuffers[outIndex];


        while (audioPtsUs > 0 && (info.presentationTimeUs / 1000.0 - getAudioPtsMs()) > 40.0) {
          try {
            Log.d(Const.TAG, "Wait video " + info.presentationTimeUs / 1000.0 + " audio " + audioPtsUs / 1000.0);
            Thread.sleep(10);
          } catch (InterruptedException e) {
            e.printStackTrace();
            break;
          }
        }


        if ((info.presentationTimeUs / 1000.0 - getAudioPtsMs()) < -40.0) {
          Log.d(Const.TAG, "Need to SKIP Video frame video " + info.presentationTimeUs / 1000.0 + " audio " + getAudioPtsMs());
        }


        videoDecoder.releaseOutputBuffer(outIndex, true);
        break;
    }

您的音频解码器和视频解码器是否有可能相互碰撞?代码似乎很好。好主意,但没有。我在应用程序中看不到任何地方会发生这种情况。都在这里:
06-03 00:53:11.965: D/OpenGLRenderer(32252): Enabling debug mode 0
06-03 00:53:13.495: I/OMXClient(32252): Using client-side OMX mux.
06-03 00:53:13.495: D/NvOsDebugPrintf(126): NvxLiteH264DecoderInit : Opening TVMR H264 block 
06-03 00:53:13.505: E/OMXNodeInstance(126): OMX_SetParameter() failed for StoreMetaDataInBuffers: 0x80001006
06-03 00:53:13.505: E/ACodec(32252): [OMX.Nvidia.h264.decode] storeMetaDataInBuffers failed w/ err -2147483648
06-03 00:53:13.515: I/OMXClient(32252): Using client-side OMX mux.
06-03 00:53:13.605: D/NvOsDebugPrintf(126): NvMMLiteOpen : Block : BlockType = 261
06-03 00:53:13.605: D/NvOsDebugPrintf(126): ++++++ NvAvpOpen +++++++
06-03 00:53:13.605: I/Choreographer(32252): Skipped 105 frames!  The application may be doing too much work on its main thread.
06-03 00:53:13.625: D/NvOsDebugPrintf(126): NvMMLiteBlockCreate : Block : BlockType = 261 
06-03 00:53:13.625: D/NvOsDebugPrintf(126): ++++++++++++ TVMRFrameDelivery +++++++++++++++
06-03 00:53:13.635: D/MyMediaPlayer(32252): dequeueOutputBuffer timed out!
06-03 00:53:13.635: I/SoftAAC2(32252): Reconfiguring decoder: 0->44100 Hz, 0->2 channels
06-03 00:53:13.635: D/NvOsDebugPrintf(126): BeginSequence 1280x720
06-03 00:53:13.635: D/NvOsDebugPrintf(126): pnvsi->nDecodeBuffers = 2 
06-03 00:53:13.645: D/MyMediaPlayer(32252): dequeueOutputBuffer timed out!
06-03 00:53:13.645: D/MyMediaPlayer(32252): dequeueOutputBuffer timed out!
06-03 00:53:13.655: D/MyMediaPlayer(32252): INFO_OUTPUT_BUFFERS_CHANGED
06-03 00:53:13.655: D/NvOsDebugPrintf(126): Display Resolution : (1280x720) 
06-03 00:53:13.655: D/NvOsDebugPrintf(126): Display Aspect Ratio : (1280x720) 
06-03 00:53:13.655: D/NvOsDebugPrintf(126): cbBeginSequence@448: SurfaceLayout = 2
06-03 00:53:13.655: D/NvOsDebugPrintf(126): pStreamInfo->NumOfSurfaces = 6, MaxDPB = 24, InteraceStream = 0, InterlaceEnabled = 0 
06-03 00:53:13.655: D/NvOsDebugPrintf(126): Allocating new output: 1280x720 (x 8)
06-03 00:53:13.665: D/MyMediaPlayer(32252): New format {sample-rate=44100, channel-count=2, what=1869968451, mime=audio/raw}
06-03 00:53:13.665: D/MyMediaPlayer(32252): dequeueOutputBuffer timed out!
06-03 00:53:13.675: D/MyMediaPlayer(32252): dequeueOutputBuffer timed out!
06-03 00:53:13.705: I/ActivityManager(505): Displayed io.dp.media.player/.MainActivity: +2s169ms
06-03 00:53:13.725: D/MyMediaPlayer(32252): INFO_OUTPUT_BUFFERS_CHANGED
06-03 00:53:13.735: D/MyMediaPlayer(32252): New format {height=720, what=1869968451, color-format=256, slice-height=0, crop-left=0, width=1280, crop-bottom=719, crop-top=0, mime=video/raw, stride=1280, crop-right=1279}
06-03 00:53:13.775: D/MyMediaPlayer(32252): Need to SKIP Video frame video 0.0 audio 46.439909297052154
06-03 00:53:13.835: I/hwcomposer(123): Setting interactive mode: Off
06-03 00:53:13.865: W/dalvikvm(32252): threadid=12: thread exiting with uncaught exception (group=0x419b6ba8)
06-03 00:53:13.875: E/AndroidRuntime(32252): FATAL EXCEPTION: Thread-1887
06-03 00:53:13.875: E/AndroidRuntime(32252): Process: io.dp.media.player, PID: 32252
06-03 00:53:13.875: E/AndroidRuntime(32252): java.lang.ArrayIndexOutOfBoundsException: length=5; index=5
06-03 00:53:13.875: E/AndroidRuntime(32252):    at io.dp.media.player.Player.processVideo(Player.java:154)
06-03 00:53:13.875: E/AndroidRuntime(32252):    at io.dp.media.player.Player.access$500(Player.java:34)
06-03 00:53:13.875: E/AndroidRuntime(32252):    at io.dp.media.player.Player$VideoThread.run(Player.java:276)
06-03 00:53:13.885: W/ActivityManager(505):   Force finishing activity io.dp.media.player/.MainActivity