當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaCodec.getInputBuffers方法代碼示例

本文整理匯總了Java中android.media.MediaCodec.getInputBuffers方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaCodec.getInputBuffers方法的具體用法?Java MediaCodec.getInputBuffers怎麽用?Java MediaCodec.getInputBuffers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.media.MediaCodec的用法示例。


在下文中一共展示了MediaCodec.getInputBuffers方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: getInputBuffer

import android.media.MediaCodec; //導入方法依賴的package包/類
private ByteBuffer getInputBuffer(MediaCodec codec, int index){
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return codec.getInputBuffer(index);
    }else{
        return codec.getInputBuffers()[index];
    }
}
 
開發者ID:aiyaapp,項目名稱:AAVT,代碼行數:8,代碼來源:Mp4Processor.java

示例3: getInputBuffer

import android.media.MediaCodec; //導入方法依賴的package包/類
public static ByteBuffer getInputBuffer(MediaCodec codec, int index){
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return codec.getInputBuffer(index);
    }else{
        return codec.getInputBuffers()[index];
    }
}
 
開發者ID:aiyaapp,項目名稱:AAVT,代碼行數:8,代碼來源:CodecUtil.java

示例4: 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

示例5: getInputBuffer

import android.media.MediaCodec; //導入方法依賴的package包/類
private ByteBuffer getInputBuffer(MediaCodec codec, int bufferIndex) {
    ByteBuffer buffer;

    if (Build.VERSION.SDK_INT < 21) {
        buffer = codec.getInputBuffers()[bufferIndex];
        buffer.clear();
    } else {
        buffer = codec.getInputBuffer(bufferIndex);
    }

    return buffer;
}
 
開發者ID:ficklerobot,項目名稱:grid-video-viewer,代碼行數:13,代碼來源:DecodeThread.java

示例6: getInputBuffer

import android.media.MediaCodec; //導入方法依賴的package包/類
/**
 * 防止出現 http://stackoverflow.com/q/30646885 的問題
 *
 * @param codec
 * @param index
 * @return
 */
public static ByteBuffer getInputBuffer(MediaCodec codec, int index) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return codec.getInputBuffer(index);
    } else {
        return codec.getInputBuffers()[index];
    }
}
 
開發者ID:uestccokey,項目名稱:EZFilter,代碼行數:15,代碼來源:MediaUtil.java


注:本文中的android.media.MediaCodec.getInputBuffers方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。