音频codeC dequeueInputBuffer返回-1装置 [英] audio codec dequeueInputBuffer returns -1 on device

查看:3691
本文介绍了音频codeC dequeueInputBuffer返回-1装置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打从MPEG2传输(.TS)文件采取了一些声音。我通过MediaExtractor获得音频流,使用readSampleData来样复制到媒体codeC输入缓冲器,然后写媒体codeC输出缓冲到AudioTrack。 MediaExtractor显示的音频MIME类型为音频/ MP4A-LATM。

I'm trying to play some audio taken from an MPEG2 transport (.ts) file. I'm getting the audio stream via MediaExtractor, using readSampleData to copy samples to MediaCodec input buffers, then writing the MediaCodec output buffer to an AudioTrack. MediaExtractor indicates the audio MIME type as "audio/mp4a-latm".

这一切奇妙的作品上的Nexus 7平板电脑2013

All this works wonderfully on a Nexus 7 2013 tablet.

不过,这并不在一个便宜的Neutab X7平板电脑在所有的工作。问题是,少数样品后,dequeueInputBuffer多次返回-1。
注释掉调用AudioTrack.write()不改变这一事实,所以这个问题是媒体codeC的操作。

But it does not work at all on an inexpensive Neutab x7 tablet. The problem is that after a few samples, dequeueInputBuffer repeatedly returns -1. Commenting out the call to AudioTrack.write() does not change that fact, so the issue is with the operation of MediaCodec.

在code样子(日志,处理省略了一些错误):

The code looks like (logging, some error handling omitted):

  audioInputBufferIndex = audioCodec.dequeueInputBuffer(TIMEOUT);
  if (audioInputBufferIndex >= 0) {
    audioInputBuffers[audioInputBufferIndex].clear();
    sampleSize = audioExtractor.readSampleData(audioInputBuffers[audioInputBufferIndex], 0);
    audioPresentationTimeUs = audioExtractor.getSampleTime();
    audioCodec.queueInputBuffer(audioInputBufferIndex,0,sampleSize,audioPresentationTimeUs,0);
    audioOutputBufferIndex = audioCodec.dequeueOutputBuffer(audioBufferInfo, TIMEOUT);
    if (audioOutputBufferIndex >= 0) {
      ByteBuffer buffer = audioOutputBuffers[audioOutputBufferIndex];
      byte[] chunk = new byte[audioBufferInfo.size];
      buffer.get(chunk);
      buffer.clear();
      if (audioTrack != null & chunk.length > 0) {
        audioTrack.write(chunk, 0, chunk.length);
        audioExtractor.advance();
      }
      audioCodec.releaseOutputBuffer(audioOutputBufferIndex,false);

音频codeC 配置与 audioExtractor 获得MediaFormat。我试着增加超时值很大,没有喜悦。

The audioCodec is configured with a MediaFormat obtained from audioExtractor. I've tried increasing the TIMEOUT to large values, no joy.

为什么会变成这样code不同的表现这两种设备上?任何旋钮转?

Why would this code behave differently on these two devices? Any knobs to turn?

有上可以播放此文件中的一个Neutab视频应用只是fine.Logcat表明,它也使用MediaExtractor和AudioTrack但不是,appparently,媒体codeC。我看到OMX *在logcat中的条目,所以也许它直接使用libstagefright。

There is a "Videos" app on the Neutab that plays this file just fine.Logcat reveals that it's also using MediaExtractor and AudioTrack but not, appparently, MediaCodec. I see Omx* entries in logcat, so maybe it's using libstagefright directly.

推荐答案

据我看了你的code,你只有想尽一切您管理要排队一个输入缓冲时间来消除输出缓冲器一次。

As far as I read your code, you only try to dequeue output buffers once every time you manage to queue one input buffer.

请的德codeR异步运行,并取得了输入和输出缓冲器的数量有限。即使去codeR确实德code的输入缓冲区,输出可能不立即输出缓冲区可用。在这种情况下,增加超时值,也许可以帮助,但它不能保证。

Keep in mind that the decoder runs asynchronously, and has got a limited number of input and output buffers. Even if the decoder does decode your input buffer, the output may not be available in an output buffer immediately. Increasing the TIMEOUT value in this case could maybe help, but it's not guaranteed.

各地尝试拆分的两个if语句,让你叫 dequeueOutputBuffer 每次都在循环,就算 dequeueInputBuffer 未返回任何缓冲。

Try splitting your two if statements, so that you call dequeueOutputBuffer every time around in the loop, even if dequeueInputBuffer didn't return any buffer.

这篇关于音频codeC dequeueInputBuffer返回-1装置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆