Skip to content

Commit

Permalink
Prep for MediaCodec method name changes in SDKs > T.
Browse files Browse the repository at this point in the history
Most of the validate/invalidate methods have been renamed as *Locked.

PiperOrigin-RevId: 517162700
  • Loading branch information
brettchabot authored and Copybara-Service committed Mar 16, 2023
1 parent bca06c8 commit d6cf9f3
Showing 1 changed file with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.robolectric.shadows;

import static android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
import static android.os.Build.VERSION_CODES.JELLY_BEAN;
import static android.os.Build.VERSION_CODES.LOLLIPOP;
import static android.os.Build.VERSION_CODES.N_MR1;
import static android.os.Build.VERSION_CODES.O;
import static android.os.Build.VERSION_CODES.TIRAMISU;
import static com.google.common.base.Preconditions.checkState;
import static java.util.concurrent.TimeUnit.MICROSECONDS;
import static org.robolectric.shadow.api.Shadow.invokeConstructor;
Expand Down Expand Up @@ -404,22 +406,32 @@ private boolean canQueueInputBuffer(int index) {
}

/** Prevents calling Android-only methods on basic ByteBuffer objects. */
@Implementation(minSdk = LOLLIPOP)
@Implementation(minSdk = LOLLIPOP, maxSdk = TIRAMISU)
protected void invalidateByteBuffer(@Nullable ByteBuffer[] buffers, int index) {}

@Implementation(minSdk = CUR_DEVELOPMENT)
protected void invalidateByteBufferLocked(
@Nullable ByteBuffer[] buffers, int index, boolean input) {}

/** Prevents calling Android-only methods on basic ByteBuffer objects. */
@Implementation(minSdk = LOLLIPOP)
@Implementation(minSdk = LOLLIPOP, maxSdk = TIRAMISU)
protected void validateInputByteBuffer(@Nullable ByteBuffer[] buffers, int index) {}

@Implementation(minSdk = CUR_DEVELOPMENT)
protected void validateInputByteBufferLocked(@Nullable ByteBuffer[] buffers, int index) {}

/** Prevents calling Android-only methods on basic ByteBuffer objects. */
@Implementation(minSdk = LOLLIPOP)
@Implementation(minSdk = LOLLIPOP, maxSdk = TIRAMISU)
protected void revalidateByteBuffer(@Nullable ByteBuffer[] buffers, int index) {}

@Implementation(minSdk = CUR_DEVELOPMENT)
protected void revalidateByteBuffer(@Nullable ByteBuffer[] buffers, int index, boolean input) {}

/**
* Prevents calling Android-only methods on basic ByteBuffer objects. Replicates existing behavior
* adjusting buffer positions and limits.
*/
@Implementation(minSdk = LOLLIPOP)
@Implementation(minSdk = LOLLIPOP, maxSdk = TIRAMISU)
protected void validateOutputByteBuffer(
@Nullable ByteBuffer[] buffers, int index, @NonNull BufferInfo info) {
if (buffers != null && index >= 0 && index < buffers.length) {
Expand All @@ -430,14 +442,26 @@ protected void validateOutputByteBuffer(
}
}

@Implementation(minSdk = CUR_DEVELOPMENT)
protected void validateOutputByteBufferLocked(
@Nullable ByteBuffer[] buffers, int index, @NonNull BufferInfo info) {
validateOutputByteBuffer(buffers, index, info);
}

/** Prevents calling Android-only methods on basic ByteBuffer objects. */
@Implementation(minSdk = LOLLIPOP)
@Implementation(minSdk = LOLLIPOP, maxSdk = TIRAMISU)
protected void invalidateByteBuffers(@Nullable ByteBuffer[] buffers) {}

@Implementation(minSdk = CUR_DEVELOPMENT)
protected void invalidateByteBuffersLocked(@Nullable ByteBuffer[] buffers) {}

/** Prevents attempting to free non-direct ByteBuffer objects. */
@Implementation(minSdk = LOLLIPOP)
@Implementation(minSdk = LOLLIPOP, maxSdk = TIRAMISU)
protected void freeByteBuffer(@Nullable ByteBuffer buffer) {}

@Implementation(minSdk = CUR_DEVELOPMENT)
protected void freeByteBufferLocked(@Nullable ByteBuffer buffer) {}

/** Shadows CodecBuffer to prevent attempting to free non-direct ByteBuffer objects. */
@Implements(className = "android.media.MediaCodec$BufferMap$CodecBuffer", minSdk = LOLLIPOP)
protected static class ShadowCodecBuffer {
Expand Down

0 comments on commit d6cf9f3

Please sign in to comment.