private ByteBuffer getInputBuffer(int inputIndex) { if (Util.SDK_INT >= 21) { return codec.getInputBuffer(inputIndex); } else { return inputBuffers[inputIndex]; } }
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]; } }
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]; } }
@Test @Config(minSdk = LOLLIPOP) public void providesValidInputBuffer() { ArgumentCaptor<Integer> indexCaptor = ArgumentCaptor.forClass(Integer.class); verify(callback).onInputBufferAvailable(same(codec), indexCaptor.capture()); ByteBuffer buffer = codec.getInputBuffer(indexCaptor.getValue()); assertThat(buffer.remaining()).isGreaterThan(0); }
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]; } }
@Test @Config(minSdk = LOLLIPOP) public void presentsOutputBufferAfterQueuingInputBuffer() { ArgumentCaptor<Integer> indexCaptor = ArgumentCaptor.forClass(Integer.class); verify(callback).onInputBufferAvailable(same(codec), indexCaptor.capture()); ByteBuffer buffer = codec.getInputBuffer(indexCaptor.getValue()); int start = buffer.position(); // "Write" to the buffer. buffer.position(buffer.limit()); codec.queueInputBuffer( indexCaptor.getValue(), /* offset= */ start, /* size= */ buffer.position() - start, /* presentationTimeUs= */ 0, /* flags= */ 0); verify(callback).onOutputBufferAvailable(same(codec), anyInt(), any()); }
@Test @Config(minSdk = LOLLIPOP) public void providesValidOutputBuffer() { ArgumentCaptor<Integer> indexCaptor = ArgumentCaptor.forClass(Integer.class); verify(callback).onInputBufferAvailable(same(codec), indexCaptor.capture()); ByteBuffer buffer = codec.getInputBuffer(indexCaptor.getValue()); int start = buffer.position(); // "Write" to the buffer. buffer.position(buffer.limit()); codec.queueInputBuffer( indexCaptor.getValue(), /* offset= */ start, /* size= */ buffer.position() - start, /* presentationTimeUs= */ 0, /* flags= */ 0); verify(callback).onOutputBufferAvailable(same(codec), indexCaptor.capture(), any()); buffer = codec.getOutputBuffer(indexCaptor.getValue()); assertThat(buffer.remaining()).isGreaterThan(0); }
@Test @Config(minSdk = LOLLIPOP) public void passesEndOfStreamFlagWithFinalOutputBuffer() { ArgumentCaptor<Integer> indexCaptor = ArgumentCaptor.forClass(Integer.class); verify(callback).onInputBufferAvailable(same(codec), indexCaptor.capture()); ByteBuffer buffer = codec.getInputBuffer(indexCaptor.getValue()); int start = buffer.position(); // "Write" to the buffer. buffer.position(buffer.limit()); codec.queueInputBuffer( indexCaptor.getValue(), /* offset= */ start, /* size= */ buffer.position() - start, /* presentationTimeUs= */ 0, /* flags= */ MediaCodec.BUFFER_FLAG_END_OF_STREAM); ArgumentCaptor<BufferInfo> infoCaptor = ArgumentCaptor.forClass(BufferInfo.class); verify(callback) .onOutputBufferAvailable(same(codec), indexCaptor.capture(), infoCaptor.capture()); assertThat(infoCaptor.getValue().flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM).isNotEqualTo(0); }
@Test @Config(minSdk = LOLLIPOP) public void doesNotPresentInputBufferAfterReleasingOutputBufferFinished() { ArgumentCaptor<Integer> indexCaptor = ArgumentCaptor.forClass(Integer.class); verify(callback).onInputBufferAvailable(same(codec), indexCaptor.capture()); ByteBuffer buffer = codec.getInputBuffer(indexCaptor.getValue()); int start = buffer.position(); // "Write" to the buffer. buffer.position(buffer.limit()); codec.queueInputBuffer( indexCaptor.getValue(), /* offset= */ start, /* size= */ buffer.position() - start, /* presentationTimeUs= */ 0, /* flags= */ MediaCodec.BUFFER_FLAG_END_OF_STREAM); verify(callback).onOutputBufferAvailable(same(codec), indexCaptor.capture(), any()); codec.releaseOutputBuffer(indexCaptor.getValue(), /* render= */ false); verify(callback, times(1)).onInputBufferAvailable(same(codec), anyInt()); }
@Test @Config(minSdk = LOLLIPOP) public void presentsInputBufferAfterReleasingOutputBufferWhenNotFinished() { ArgumentCaptor<Integer> indexCaptor = ArgumentCaptor.forClass(Integer.class); verify(callback).onInputBufferAvailable(same(codec), indexCaptor.capture()); ByteBuffer buffer = codec.getInputBuffer(indexCaptor.getValue()); int start = buffer.position(); // "Write" to the buffer. buffer.position(buffer.limit()); codec.queueInputBuffer( indexCaptor.getValue(), /* offset= */ start, /* size= */ buffer.position() - start, /* presentationTimeUs= */ 0, /* flags= */ 0); verify(callback).onOutputBufferAvailable(same(codec), indexCaptor.capture(), any()); codec.releaseOutputBuffer(indexCaptor.getValue(), /* render= */ false); verify(callback, times(2)).onInputBufferAvailable(same(codec), anyInt()); }
public ByteBuffer getInputBuffer(final int index) { if (Build.VERSION.SDK_INT >= 21) { return mMediaCodec.getInputBuffer(index); } return mInputBuffers[index]; }
public ByteBuffer getInputBuffer(final int index) { if (Build.VERSION.SDK_INT >= 21) { return mMediaCodec.getInputBuffer(index); } return mInputBuffers[index]; }
ByteBuffer getInputBuffer(final int index) { if (Build.VERSION.SDK_INT >= 21) { return mediaCodec.getInputBuffer(index); } return inputBuffers[index]; }
public ByteBuffer getInputBuffer(final int index) { if (Build.VERSION.SDK_INT >= 21) { return mMediaCodec.getInputBuffer(index); } return mInputBuffers[index]; }
public ByteBuffer getInputBuffer(final int index) { if (Build.VERSION.SDK_INT >= 21) { return mMediaCodec.getInputBuffer(index); } return mInputBuffers[index]; }
ByteBuffer getInputBuffer(final int index) { if (Build.VERSION.SDK_INT >= 21) { return mediaCodec.getInputBuffer(index); } return inputBuffers[index]; }
public ByteBuffer getInputBuffer(final int index) { if (Build.VERSION.SDK_INT >= 21) { return mMediaCodec.getInputBuffer(index); } return mInputBuffers[index]; }
ByteBuffer getInputBuffer(final int index) { if (Build.VERSION.SDK_INT >= 21) { return mediaCodec.getInputBuffer(index); } return inputBuffers[index]; }
@Override public void onInputBufferAvailable(@NonNull MediaCodec mediaCodec, int i) { ByteBuffer inputBuffer = mediaCodec.getInputBuffer(i); if (inputBuffer == null) return; MediaCodec.BufferInfo info = AudioDecoder.super.onInputBufferAvailable(extractor, inputBuffer); mediaCodec.queueInputBuffer(i, info.offset, info.size, info.presentationTimeUs, info.flags); }
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private void getDataFromEncoderAPI21(byte[] data, int size) { int inBufferIndex = audioEncoder.dequeueInputBuffer(-1); if (inBufferIndex >= 0) { ByteBuffer bb = audioEncoder.getInputBuffer(inBufferIndex); bb.put(data, 0, size); long pts = System.nanoTime() / 1000 - presentTimeUs; audioEncoder.queueInputBuffer(inBufferIndex, 0, size, pts, 0); } for (; ; ) { int outBufferIndex = audioEncoder.dequeueOutputBuffer(audioInfo, 0); if (outBufferIndex == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) { getAacData.onAudioFormat(audioEncoder.getOutputFormat()); } else if (outBufferIndex >= 0) { //This ByteBuffer is AAC ByteBuffer bb = audioEncoder.getOutputBuffer(outBufferIndex); getAacData.getAacData(bb, audioInfo); audioEncoder.releaseOutputBuffer(outBufferIndex, false); } else { break; } } }