Skip to content

Commit faccfcd

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 faccfcd

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

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

Lines changed: 9 additions & 13 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();
@@ -792,10 +789,9 @@ private int queueSecureInputBuffer(
792789
return MediaCodecStatus.ERROR;
793790
}
794791

795-
int flags = 0;
796-
if (isDecodeOnly(presentationTimeUs)) {
797-
flags |= MediaCodec.BUFFER_FLAG_DECODE_ONLY;
798-
}
792+
int flags = isDecodeOnly(presentationTimeUs, decodeOnlyExperiment)
793+
? MediaCodec.BUFFER_FLAG_DECODE_ONLY
794+
: 0;
799795
mMediaCodec.get().queueSecureInputBuffer(index, offset, cryptoInfo, presentationTimeUs, flags);
800796
} catch (MediaCodec.CryptoException e) {
801797
int errorCode = e.getErrorCode();

starboard/android/shared/media_codec_bridge.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -314,15 +314,13 @@ jint MediaCodecBridge::QueueInputBuffer(jint index,
314314
jlong presentation_time_microseconds,
315315
jint flags) {
316316
JNIEnv* env = AttachCurrentThread();
317-
if (starboard::features::FeatureList::IsEnabled(
318-
starboard::features::kStarboardBufferFlagDecodeOnlyExperiment)) {
319-
SB_LOG(INFO) << "Feature has been enabled";
320-
} else {
321-
SB_LOG(INFO) << "Feature is not enabled";
322-
}
317+
318+
bool enable_decode_only_experiment =
319+
starboard::features::FeatureList::IsEnabled(
320+
starboard::features::kStarboardBufferFlagDecodeOnlyExperiment);
323321
return Java_MediaCodecBridge_queueInputBuffer(
324322
env, j_media_codec_bridge_, index, offset, size,
325-
presentation_time_microseconds, flags);
323+
presentation_time_microseconds, flags, enable_decode_only_experiment);
326324
}
327325

328326
jint MediaCodecBridge::QueueSecureInputBuffer(
@@ -362,10 +360,15 @@ jint MediaCodecBridge::QueueSecureInputBuffer(
362360
blocks_to_skip = drm_sample_info.encryption_pattern.skip_byte_block;
363361
}
364362

363+
jboolean enable_decode_only_experiment =
364+
starboard::features::FeatureList::IsEnabled(
365+
features::kStarboardBufferFlagDecodeOnlyExperiment);
366+
365367
return Java_MediaCodecBridge_queueSecureInputBuffer(
366368
env, j_media_codec_bridge_, index, offset, j_iv, j_key_id, j_clear_bytes,
367369
j_encrypted_bytes, subsample_count, cipher_mode, blocks_to_encrypt,
368-
blocks_to_skip, presentation_time_microseconds);
370+
blocks_to_skip, presentation_time_microseconds,
371+
enable_decode_only_experiment);
369372
}
370373

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

0 commit comments

Comments
 (0)