当前位置: 首页>>代码示例>>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;未经允许,请勿转载。