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


Java MediaCodec.releaseOutputBuffer方法代碼示例

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


在下文中一共展示了MediaCodec.releaseOutputBuffer方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: dequeueOutputBuffer

import android.media.MediaCodec; //導入方法依賴的package包/類
private int dequeueOutputBuffer(MediaCodec codec, int outputBufferId, MediaCodec.BufferInfo info) throws IOException {
    int outBitsSize = info.size;
    int outPacketSize = outBitsSize + 7;    // 7 is ADTS header size
    ByteBuffer outBuf = codec.getOutputBuffer(outputBufferId);

    outBuf.position(info.offset);
    outBuf.limit(info.offset + outBitsSize);
    byte[] data = new byte[outPacketSize];
    addADTStoPacket(data, outPacketSize);
    outBuf.get(data, 7, outBitsSize);
    outBuf.position(info.offset);
    pipedOutputStream.write(data, 0, outPacketSize);
    pipedOutputStream.flush();

    outBuf.clear();
    codec.releaseOutputBuffer(outputBufferId, false);

    return outBitsSize;
}
 
開發者ID:aschober,項目名稱:vinyl-cast,代碼行數:20,代碼來源:ConvertAudioTask.java

示例3: dequeueOutputBuffer

import android.media.MediaCodec; //導入方法依賴的package包/類
/**
 * Save the encoded (output) buffer into the complete encoded recording.
 * TODO: copy directly (without the intermediate byte array)
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void dequeueOutputBuffer(MediaCodec codec, ByteBuffer[] outputBuffers, int index, MediaCodec.BufferInfo info) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        ByteBuffer buffer = outputBuffers[index];
        Log.i("size/remaining: " + info.size + "/" + buffer.remaining());
        if (info.size <= buffer.remaining()) {
            final byte[] bufferCopied = new byte[info.size];
            buffer.get(bufferCopied); // TODO: catch BufferUnderflow
            // TODO: do we need to clear?
            // on N5: always size == remaining(), clearing is not needed
            // on SGS2: remaining decreases until it becomes less than size, which results in BufferUnderflow
            // (but SGS2 records only zeros anyway)
            //buffer.clear();
            codec.releaseOutputBuffer(index, false);
            addEncoded(bufferCopied);
            if (Log.DEBUG) {
                AudioUtils.showSomeBytes("out", bufferCopied);
            }
        } else {
            Log.e("size > remaining");
            codec.releaseOutputBuffer(index, false);
        }
    }
}
 
開發者ID:vaibhavs4424,項目名稱:AI-Powered-Intelligent-Banking-Platform,代碼行數:29,代碼來源:EncodedAudioRecorder.java

示例4: dropOutputBuffer

import android.media.MediaCodec; //導入方法依賴的package包/類
protected void dropOutputBuffer(MediaCodec codec, int bufferIndex) {
  TraceUtil.beginSection("dropVideoBuffer");
  codec.releaseOutputBuffer(bufferIndex, false);
  TraceUtil.endSection();
  codecCounters.droppedOutputBufferCount++;
  droppedFrameCount++;
  consecutiveDroppedFrameCount++;
  codecCounters.maxConsecutiveDroppedOutputBufferCount = Math.max(consecutiveDroppedFrameCount,
      codecCounters.maxConsecutiveDroppedOutputBufferCount);
  if (droppedFrameCount == maxDroppedFrameCountToNotify) {
    maybeNotifyDroppedFrameCount();
  }
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:14,代碼來源:MediaCodecVideoTrackRenderer.java

示例5: renderOutputBuffer

import android.media.MediaCodec; //導入方法依賴的package包/類
protected void renderOutputBuffer(MediaCodec codec, int bufferIndex) {
  maybeNotifyVideoSizeChanged();
  TraceUtil.beginSection("releaseOutputBuffer");
  codec.releaseOutputBuffer(bufferIndex, true);
  TraceUtil.endSection();
  codecCounters.renderedOutputBufferCount++;
  renderedFirstFrame = true;
  maybeNotifyDrawnToSurface();
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:10,代碼來源:MediaCodecVideoTrackRenderer.java

示例6: renderOutputBufferV21

import android.media.MediaCodec; //導入方法依賴的package包/類
@TargetApi(21)
protected void renderOutputBufferV21(MediaCodec codec, int bufferIndex, long releaseTimeNs) {
  maybeNotifyVideoSizeChanged();
  TraceUtil.beginSection("releaseOutputBuffer");
  codec.releaseOutputBuffer(bufferIndex, releaseTimeNs);
  TraceUtil.endSection();
  codecCounters.renderedOutputBufferCount++;
  renderedFirstFrame = true;
  maybeNotifyDrawnToSurface();
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:11,代碼來源:MediaCodecVideoTrackRenderer.java

示例7: onOutputBufferAvailable

import android.media.MediaCodec; //導入方法依賴的package包/類
@Override
public void onOutputBufferAvailable(@NonNull final MediaCodec codec, final int index,
        @NonNull final MediaCodec.BufferInfo info) {
    ByteBuffer buffer = codec.getOutputBuffer(index);
    if (buffer != null) {
        reportEncodedImage(info, buffer);
    }
    codec.releaseOutputBuffer(index, false);
}
 
開發者ID:Piasy,項目名稱:InsideCodec,代碼行數:10,代碼來源:EncoderWrapper.java

示例8: processOutputBuffer

import android.media.MediaCodec; //導入方法依賴的package包/類
@Override
protected boolean processOutputBuffer(long positionUs, long elapsedRealtimeUs, MediaCodec codec,
    ByteBuffer buffer, int bufferIndex, int bufferFlags, long bufferPresentationTimeUs,
    boolean shouldSkip) throws ExoPlaybackException {
  if (passthroughEnabled && (bufferFlags & MediaCodec.BUFFER_FLAG_CODEC_CONFIG) != 0) {
    // Discard output buffers from the passthrough (raw) decoder containing codec specific data.
    codec.releaseOutputBuffer(bufferIndex, false);
    return true;
  }

  if (shouldSkip) {
    codec.releaseOutputBuffer(bufferIndex, false);
    decoderCounters.skippedOutputBufferCount++;
    audioTrack.handleDiscontinuity();
    return true;
  }

  try {
    if (audioTrack.handleBuffer(buffer, bufferPresentationTimeUs)) {
      codec.releaseOutputBuffer(bufferIndex, false);
      decoderCounters.renderedOutputBufferCount++;
      return true;
    }
  } catch (AudioTrack.InitializationException | AudioTrack.WriteException e) {
    throw ExoPlaybackException.createForRenderer(e, getIndex());
  }
  return false;
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:29,代碼來源:MediaCodecAudioRenderer.java

示例9: dropOutputBuffer

import android.media.MediaCodec; //導入方法依賴的package包/類
private void dropOutputBuffer(MediaCodec codec, int bufferIndex) {
  TraceUtil.beginSection("dropVideoBuffer");
  codec.releaseOutputBuffer(bufferIndex, false);
  TraceUtil.endSection();
  decoderCounters.droppedOutputBufferCount++;
  droppedFrames++;
  consecutiveDroppedFrameCount++;
  decoderCounters.maxConsecutiveDroppedOutputBufferCount = Math.max(consecutiveDroppedFrameCount,
      decoderCounters.maxConsecutiveDroppedOutputBufferCount);
  if (droppedFrames == maxDroppedFramesToNotify) {
    maybeNotifyDroppedFrames();
  }
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:14,代碼來源:MediaCodecVideoRenderer.java

示例10: renderOutputBuffer

import android.media.MediaCodec; //導入方法依賴的package包/類
private void renderOutputBuffer(MediaCodec codec, int bufferIndex) {
  maybeNotifyVideoSizeChanged();
  TraceUtil.beginSection("releaseOutputBuffer");
  codec.releaseOutputBuffer(bufferIndex, true);
  TraceUtil.endSection();
  decoderCounters.renderedOutputBufferCount++;
  consecutiveDroppedFrameCount = 0;
  maybeNotifyRenderedFirstFrame();
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:10,代碼來源:MediaCodecVideoRenderer.java

示例11: renderOutputBufferV21

import android.media.MediaCodec; //導入方法依賴的package包/類
@TargetApi(21)
private void renderOutputBufferV21(MediaCodec codec, int bufferIndex, long releaseTimeNs) {
  maybeNotifyVideoSizeChanged();
  TraceUtil.beginSection("releaseOutputBuffer");
  codec.releaseOutputBuffer(bufferIndex, releaseTimeNs);
  TraceUtil.endSection();
  decoderCounters.renderedOutputBufferCount++;
  consecutiveDroppedFrameCount = 0;
  maybeNotifyRenderedFirstFrame();
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:11,代碼來源:MediaCodecVideoRenderer.java

示例12: renderHevcImage

import android.media.MediaCodec; //導入方法依賴的package包/類
private static void renderHevcImage(ByteBuffer bitstream, ImageInfo info, Surface surface) {
    long beginTime = SystemClock.elapsedRealtimeNanos();

    // configure HEVC decoder
    MediaCodec decoder = configureDecoder(info, bitstream.limit(), surface);
    MediaFormat outputFormat = decoder.getOutputFormat();
    Log.d(TAG, "HEVC output-format=" + outputFormat);

    decoder.start();
    try {
        // set bitstream to decoder
        int inputBufferId = decoder.dequeueInputBuffer(-1);
        if (inputBufferId < 0) {
            throw new IllegalStateException("dequeueInputBuffer return " + inputBufferId);
        }
        ByteBuffer inBuffer = decoder.getInputBuffer(inputBufferId);
        inBuffer.put(bitstream);
        decoder.queueInputBuffer(inputBufferId, 0, bitstream.limit(), 0, 0);

        // notify end of stream
        inputBufferId = decoder.dequeueInputBuffer(-1);
        if (inputBufferId < 0) {
            throw new IllegalStateException("dequeueInputBuffer return " + inputBufferId);
        }
        decoder.queueInputBuffer(inputBufferId, 0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM);

        // get decoded image
        MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
        while (true) {
            int outputBufferId = decoder.dequeueOutputBuffer(bufferInfo, -1);
            if (outputBufferId >= 0) {
                decoder.releaseOutputBuffer(outputBufferId, true);
                break;
            } else if (outputBufferId == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
                outputFormat = decoder.getOutputFormat();
                Log.d(TAG, "HEVC output-format=" + outputFormat);
            } else {
                Log.d(TAG, "HEVC dequeueOutputBuffer return " + outputBufferId);
            }
        }
        decoder.flush();
    } finally {
        decoder.stop();
        decoder.release();
    }
    long endTime = SystemClock.elapsedRealtimeNanos();
    Log.i(TAG, "HEVC decoding elapsed=" + (endTime - beginTime) / 1000000.f + "[msec]");
}
 
開發者ID:yohhoy,項目名稱:heifreader,代碼行數:49,代碼來源:HeifReader.java

示例13: skipOutputBuffer

import android.media.MediaCodec; //導入方法依賴的package包/類
protected void skipOutputBuffer(MediaCodec codec, int bufferIndex) {
  TraceUtil.beginSection("skipVideoBuffer");
  codec.releaseOutputBuffer(bufferIndex, false);
  TraceUtil.endSection();
  codecCounters.skippedOutputBufferCount++;
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:7,代碼來源:MediaCodecVideoTrackRenderer.java

示例14: skipOutputBuffer

import android.media.MediaCodec; //導入方法依賴的package包/類
private void skipOutputBuffer(MediaCodec codec, int bufferIndex) {
  TraceUtil.beginSection("skipVideoBuffer");
  codec.releaseOutputBuffer(bufferIndex, false);
  TraceUtil.endSection();
  decoderCounters.skippedOutputBufferCount++;
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:7,代碼來源:MediaCodecVideoRenderer.java


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