2013-03-31 34 views
3

我正在尝试使用低级别媒体API来解码MP3和其他格式的文件,以便我可以处理它们。我按照教程here采取一个编码的文件,并用AudioTrack播放,我的代码基本相同,但我得到一个错误。错误“OMX_GetExtensionIndex失败”在MediaCodec的上下文中是什么意思,我该如何解决它?

这里是我的代码:

public void playSongMono(View view) 
{ 
    //create extractor and point it to file 
    AssetFileDescriptor fd = getResources().openRawResourceFd(R.raw.song); 

    MediaExtractor extractor = new MediaExtractor(); 
    extractor.setDataSource(fd.getFileDescriptor(),fd.getStartOffset(),fd.getLength()); 

    //get MIME type of file 
    MediaFormat inputFormat = extractor.getTrackFormat(0); 
    Log.d("MonoPlayer","TRACKS #: "+extractor.getTrackCount()); 
    String mime = inputFormat.getString(MediaFormat.KEY_MIME); 
    Log.d("MonoPlayer","FORMAT: "+mime); 

    extractor.selectTrack(0); 

    //create codec 
    MediaCodec codec = MediaCodec.createDecoderByType(mime); 
    Log.d("MonoPlayer","1"); 
    codec.configure(inputFormat, null, null, 0); 
    Log.d("MonoPlayer","2"); 
    codec.start(); 
    Log.d("MonoPlayer","3"); 

    ByteBuffer[] inputBuffers = codec.getInputBuffers(); 
    ByteBuffer[] outputBuffers = codec.getOutputBuffers(); 

    //get a buffer and fill it 
    int inputBufferIndex = codec.dequeueInputBuffer(1000000); 

    if(inputBufferIndex >= 0) 
    { 
     Log.d("MonoPlayer","4"); 
     //fill the buffer 
     int sampleSize = extractor.readSampleData(inputBuffers[inputBufferIndex], 0); 
     long presentationTimeUs = 0; 
     boolean sawInputEOS= false; 

     if (sampleSize < 0) { 
      sawInputEOS = true; 
      sampleSize = 0; 
     } else { 
      presentationTimeUs = extractor.getSampleTime(); 
     } 

     codec.queueInputBuffer(inputBufferIndex, 
           0, 
           sampleSize, 
           presentationTimeUs, 
           sawInputEOS ? MediaCodec.BUFFER_FLAG_END_OF_STREAM : 0); 

     if (!sawInputEOS) { 
      extractor.advance(); 
     } 
    } 

    BufferInfo info = new BufferInfo(); //this will be populated with data by dequeueOutputBuffer 

    //get the index of a finished buffer. since we only enqueued one we should only wait for one 
    int resultBufferIndex = codec.dequeueOutputBuffer(info, 1000000); 

    if (resultBufferIndex >= 0) 
    { 
     Log.d("MonoPlayer","5"); 
     //we now have a buffer of pcm data 
     byte[] chunk = new byte[info.size]; 
     outputBuffers[resultBufferIndex].get(chunk); 
     outputBuffers[resultBufferIndex].clear(); 
     codec.releaseOutputBuffer(resultBufferIndex, false); 

     //create audiotrack to play sound 
     audiotrack = new AudioTrack(AudioManager.STREAM_MUSIC, 
       44100, 
       AudioFormat.CHANNEL_OUT_STEREO, 
       AudioFormat.ENCODING_PCM_16BIT, 
       chunk.length, 
       AudioTrack.MODE_STATIC); 

     audiotrack.play(); 
     audiotrack.write(chunk, 0, chunk.length); 

    } 

    extractor.release(); 
    extractor = null; 

    codec.stop(); 
    codec.release(); 
    codec = null; 
} 

和这代码我得到以下logcat的输出

D MonoPlayer  TRACKS #: 1 
D MonoPlayer  FORMAT: audio/mpeg 
I OMXClient  Using client-side OMX mux. 
D MonoPlayer  1 
E OMXNodeInstance OMX_GetExtensionIndex failed 
D MonoPlayer  2 
D MonoPlayer  3 
D MonoPlayer  4 

以上的执行是我提到的错误。我不确定为什么这个错误正在发生或者意味着什么。但是,我试图收集一些信息。使用日志输出表明该错误发生在行codec.configure(inputFormat, null, null, 0);。我试图删除该行,这可预料会导致一个非法的状态错误,但消除了有问题的错误。此外,在我发布的代码中,即使出网呼叫超时被设置为无限期,也不会到达Log.d("MonoPlayer","5");,所以我假设解码器没有正确配置。

如果有人知道我为什么会出现这个错误以及我能做些什么来解决这个问题,那会很棒。提前致谢。

回答

1

该消息可能是无害的。我在成功的测试中看到它。

它似乎来自OMXNodeInstance.cpp的第288行。 OMX.google.android.index.enableAndroidNativeBuffers扩展名查找失败,这意味着该扩展没有在该设备上定义。

相关问题