Skip to content

Commit 2f0989c

Browse files
committed
Add Starboard Feature Experiment
With the Starboard Features Experiment merged, we are now able to properly implement this experiment feature flag with a starboard feature. Bug: 423927047
1 parent 24e1a05 commit 2f0989c

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

cobalt/android/apk/app/src/main/java/dev/cobalt/media/MediaCodecBridge.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ class MediaCodecBridge {
7272
private int mFps = 30;
7373
private final boolean mIsTunnelingPlayback;
7474

75-
// TODO: (b/423927047) Once the Starboard Extension for Chromium Features
76-
// lands, replace this macro with a starboard features.
77-
private boolean mBufferFlagDecodeOnlyExperiment = false;
78-
7975
private MediaCodec.OnFrameRenderedListener mFrameRendererListener;
8076
private MediaCodec.OnFirstTunnelFrameReadyListener mFirstTunnelFrameReadyListener;
8177

@@ -402,10 +398,10 @@ public static boolean isFrameRenderedCallbackEnabled() {
402398
return Build.VERSION.SDK_INT >= 34;
403399
}
404400

405-
private boolean isDecodeOnly(long presentationTimeUs) {
401+
private boolean isDecodeOnly(long presentationTimeUs, boolean decodeOnlyExperiment) {
406402
// Starting with Android 14, we can use BUFFER_FLAG_DECODE_ONLY to explicitly skip video frames
407403
// before the seek time so that they won't be rendered.
408-
return Build.VERSION.SDK_INT >= 34 && (mBufferFlagDecodeOnlyExperiment) && (presentationTimeUs < mSeekToTime);
404+
return Build.VERSION.SDK_INT >= 34 && (decodeOnlyExperiment) && (presentationTimeUs < mSeekToTime);
409405
}
410406

411407
@CalledByNative
@@ -752,10 +748,10 @@ private ByteBuffer getOutputBuffer(int index) {
752748

753749
@CalledByNative
754750
private int queueInputBuffer(
755-
int index, int offset, int size, long presentationTimeUs, int flags) {
751+
int index, int offset, int size, long presentationTimeUs, int flags, boolean decodeOnlyExperiment) {
756752
resetLastPresentationTimeIfNeeded(presentationTimeUs);
757753
try {
758-
if (isDecodeOnly(presentationTimeUs)) {
754+
if (isDecodeOnly(presentationTimeUs, decodeOnlyExperiment)) {
759755
flags |= MediaCodec.BUFFER_FLAG_DECODE_ONLY;
760756
}
761757
mMediaCodec.get().queueInputBuffer(index, offset, size, presentationTimeUs, flags);
@@ -778,7 +774,8 @@ private int queueSecureInputBuffer(
778774
int cipherMode,
779775
int blocksToEncrypt,
780776
int blocksToSkip,
781-
long presentationTimeUs) {
777+
long presentationTimeUs,
778+
boolean decodeOnlyExperiment) {
782779
resetLastPresentationTimeIfNeeded(presentationTimeUs);
783780
try {
784781
CryptoInfo cryptoInfo = new CryptoInfo();
@@ -793,7 +790,7 @@ private int queueSecureInputBuffer(
793790
}
794791

795792
int flags = 0;
796-
if (isDecodeOnly(presentationTimeUs)) {
793+
if (isDecodeOnly(presentationTimeUs, decodeOnlyExperiment)) {
797794
flags |= MediaCodec.BUFFER_FLAG_DECODE_ONLY;
798795
}
799796
mMediaCodec.get().queueSecureInputBuffer(index, offset, cryptoInfo, presentationTimeUs, flags);

starboard/android/shared/media_codec_bridge.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ jint MediaCodecBridge::QueueInputBuffer(jint index,
314314
jlong presentation_time_microseconds,
315315
jint flags) {
316316
JNIEnv* env = AttachCurrentThread();
317+
318+
bool enable_decode_only_experiment =
319+
starboard::features::FeatureList::IsEnabled(
320+
starboard::features::kStarboardBufferFlagDecodeOnlyExperiment);
321+
317322
if (starboard::features::FeatureList::IsEnabled(
318323
starboard::features::kStarboardBufferFlagDecodeOnlyExperiment)) {
319324
SB_LOG(INFO) << "Feature has been enabled";
@@ -322,7 +327,7 @@ jint MediaCodecBridge::QueueInputBuffer(jint index,
322327
}
323328
return Java_MediaCodecBridge_queueInputBuffer(
324329
env, j_media_codec_bridge_, index, offset, size,
325-
presentation_time_microseconds, flags);
330+
presentation_time_microseconds, flags, enable_decode_only_experiment);
326331
}
327332

328333
jint MediaCodecBridge::QueueSecureInputBuffer(
@@ -362,10 +367,13 @@ jint MediaCodecBridge::QueueSecureInputBuffer(
362367
blocks_to_skip = drm_sample_info.encryption_pattern.skip_byte_block;
363368
}
364369

370+
jboolean decodeOnlyExperiment = starboard::features::FeatureList::IsEnabled(
371+
features::kStarboardBufferFlagDecodeOnlyExperiment);
372+
365373
return Java_MediaCodecBridge_queueSecureInputBuffer(
366374
env, j_media_codec_bridge_, index, offset, j_iv, j_key_id, j_clear_bytes,
367375
j_encrypted_bytes, subsample_count, cipher_mode, blocks_to_encrypt,
368-
blocks_to_skip, presentation_time_microseconds);
376+
blocks_to_skip, presentation_time_microseconds, decodeOnlyExperiment);
369377
}
370378

371379
ScopedJavaLocalRef<jobject> MediaCodecBridge::GetOutputBuffer(jint index) {

0 commit comments

Comments
 (0)