当前位置: 首页>>代码示例>>Java>>正文


Java MediaCodec.getOutputBuffers方法代码示例

本文整理汇总了Java中android.media.MediaCodec.getOutputBuffers方法的典型用法代码示例。如果您正苦于以下问题:Java MediaCodec.getOutputBuffers方法的具体用法?Java MediaCodec.getOutputBuffers怎么用?Java MediaCodec.getOutputBuffers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.media.MediaCodec的用法示例。


在下文中一共展示了MediaCodec.getOutputBuffers方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleCodecOutput

import android.media.MediaCodec; //导入方法依赖的package包/类
private void handleCodecOutput(MediaCodec mediaCodec,
                               ByteBuffer[] codecOutputBuffers,
                               MediaCodec.BufferInfo bufferInfo,
                               OutputStream outputStream)
    throws IOException
{
  int codecOutputBufferIndex = mediaCodec.dequeueOutputBuffer(bufferInfo, 0);

  while (codecOutputBufferIndex != MediaCodec.INFO_TRY_AGAIN_LATER) {
    if (codecOutputBufferIndex >= 0) {
      ByteBuffer encoderOutputBuffer = codecOutputBuffers[codecOutputBufferIndex];

      encoderOutputBuffer.position(bufferInfo.offset);
      encoderOutputBuffer.limit(bufferInfo.offset + bufferInfo.size);

      if ((bufferInfo.flags & MediaCodec.BUFFER_FLAG_CODEC_CONFIG) != MediaCodec.BUFFER_FLAG_CODEC_CONFIG) {
        byte[] header = createAdtsHeader(bufferInfo.size - bufferInfo.offset);


        outputStream.write(header);

        byte[] data = new byte[encoderOutputBuffer.remaining()];
        encoderOutputBuffer.get(data);
        outputStream.write(data);
      }

      encoderOutputBuffer.clear();

      mediaCodec.releaseOutputBuffer(codecOutputBufferIndex, false);
    }  else if (codecOutputBufferIndex== MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) {
      codecOutputBuffers = mediaCodec.getOutputBuffers();
    }

    codecOutputBufferIndex = mediaCodec.dequeueOutputBuffer(bufferInfo, 0);
  }

}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:38,代码来源:AudioCodec.java

示例2: recorderEncoderLoop

import android.media.MediaCodec; //导入方法依赖的package包/类
/**
 * Reads bytes from the given recorder and encodes them with the given encoder.
 * Uses the (deprecated) Synchronous Processing using Buffer Arrays.
 * <p/>
 * Encoders (or codecs that generate compressed data) will create and return the codec specific
 * data before any valid output buffer in output buffers marked with the codec-config flag.
 * Buffers containing codec-specific-data have no meaningful timestamps.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void recorderEncoderLoop(MediaCodec codec, SpeechRecord speechRecord) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        codec.start();
        // Getting some buffers (e.g. 4 of each) to communicate with the codec
        ByteBuffer[] codecInputBuffers = codec.getInputBuffers();
        ByteBuffer[] codecOutputBuffers = codec.getOutputBuffers();
        Log.i("input buffers " + codecInputBuffers.length + "; output buffers: " + codecOutputBuffers.length);
        boolean doneSubmittingInput = false;
        int numRetriesDequeueOutputBuffer = 0;
        int index;
        while (true) {
            if (!doneSubmittingInput) {
                index = codec.dequeueInputBuffer(DEQUEUE_TIMEOUT);
                if (index >= 0) {
                    int size = queueInputBuffer(codec, codecInputBuffers, index, speechRecord);
                    if (size == -1) {
                        codec.queueInputBuffer(index, 0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM);
                        Log.i("enc: in: EOS");
                        doneSubmittingInput = true;
                    } else {
                        Log.i("enc: in: " + size);
                        mNumBytesSubmitted += size;
                    }
                } else {
                    Log.i("enc: in: timeout, will try again");
                }
            }
            MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
            index = codec.dequeueOutputBuffer(info, DEQUEUE_TIMEOUT);
            Log.i("enc: out: flags/index: " + info.flags + "/" + index);
            if (index == MediaCodec.INFO_TRY_AGAIN_LATER) {
                Log.i("enc: out: INFO_TRY_AGAIN_LATER: " + numRetriesDequeueOutputBuffer);
                if (++numRetriesDequeueOutputBuffer > MAX_NUM_RETRIES_DEQUEUE_OUTPUT_BUFFER) {
                    break;
                }
            } else if (index == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
                MediaFormat format = codec.getOutputFormat();
                Log.i("enc: out: INFO_OUTPUT_FORMAT_CHANGED: " + format.toString());
            } else if (index == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) {
                codecOutputBuffers = codec.getOutputBuffers();
                Log.i("enc: out: INFO_OUTPUT_BUFFERS_CHANGED");
            } else {
                dequeueOutputBuffer(codec, codecOutputBuffers, index, info);
                mNumBytesDequeued += info.size;
                if ((info.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) {
                    Log.i("enc: out: EOS");
                    break;
                }
            }
        }
        codec.stop();
        codec.release();
    }
}
 
开发者ID:vaibhavs4424,项目名称:AI-Powered-Intelligent-Banking-Platform,代码行数:64,代码来源:EncodedAudioRecorder.java

示例3: getOutputBuffer

import android.media.MediaCodec; //导入方法依赖的package包/类
private ByteBuffer getOutputBuffer(MediaCodec codec, int index){
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return codec.getOutputBuffer(index);
    }else{
        return codec.getOutputBuffers()[index];
    }
}
 
开发者ID:aiyaapp,项目名称:AAVT,代码行数:8,代码来源:Mp4Processor.java

示例4: getOutputBuffer

import android.media.MediaCodec; //导入方法依赖的package包/类
public static ByteBuffer getOutputBuffer(MediaCodec codec, int index){
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return codec.getOutputBuffer(index);
    }else{
        return codec.getOutputBuffers()[index];
    }
}
 
开发者ID:aiyaapp,项目名称:AAVT,代码行数:8,代码来源:CodecUtil.java

示例5: MediaCodecBufferCompatWrapper

import android.media.MediaCodec; //导入方法依赖的package包/类
public MediaCodecBufferCompatWrapper(MediaCodec mediaCodec) {
    mMediaCodec = mediaCodec;

    if (Build.VERSION.SDK_INT < 21) {
        mInputBuffers = mediaCodec.getInputBuffers();
        mOutputBuffers = mediaCodec.getOutputBuffers();
    } else {
        mInputBuffers = mOutputBuffers = null;
    }
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:11,代码来源:MediaCodecBufferCompatWrapper.java

示例6: getOutputBuffer

import android.media.MediaCodec; //导入方法依赖的package包/类
/**
 * 防止出现 http://stackoverflow.com/q/30646885 的问题
 *
 * @param codec
 * @param index
 * @return
 */
public static ByteBuffer getOutputBuffer(MediaCodec codec, int index) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return codec.getOutputBuffer(index);
    } else {
        return codec.getOutputBuffers()[index];
    }
}
 
开发者ID:uestccokey,项目名称:EZFilter,代码行数:15,代码来源:MediaUtil.java


注:本文中的android.media.MediaCodec.getOutputBuffers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。