Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Implement ExoPlayer-based SbPlayer #5037

Draft
wants to merge 3 commits into
base: 25.lts.1+
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion cobalt/media/base/sbplayer_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -816,12 +816,16 @@ void SbPlayerBridge::CreatePlayer() {
LOG(INFO) << "Playing in punch-out mode.";
}

LOG(INFO) << "Set output with decode target provider";
decode_target_provider_->SetOutputMode(
ToVideoFrameProviderOutputMode(output_mode_));
LOG(INFO) << "Set bounds helper";
set_bounds_helper_->SetPlayerBridge(this);

base::AutoLock auto_lock(lock_);
LOG(INFO) << "Calling update bounds";
UpdateBounds_Locked();
LOG(INFO) << "Ending update bounds";
}

void SbPlayerBridge::WriteNextBuffersFromCache(DemuxerStream::Type type,
Expand Down Expand Up @@ -1031,14 +1035,18 @@ void SbPlayerBridge::GetInfo_Locked(uint32* video_frames_decoded,
void SbPlayerBridge::UpdateBounds_Locked() {
lock_.AssertAcquired();
DCHECK(SbPlayerIsValid(player_));
LOG(INFO) << "Called update bounds";

if (!set_bounds_z_index_ || !set_bounds_rect_) {
LOG(INFO) << "returning early";
return;
}

auto& rect = *set_bounds_rect_;
LOG(INFO) << "Calling interface setbounds";
sbplayer_interface_->SetBounds(player_, *set_bounds_z_index_, rect.x(),
rect.y(), rect.width(), rect.height());
LOG(INFO) << "Ending interface setbounds";
}

void SbPlayerBridge::ClearDecoderBufferCache() {
Expand Down Expand Up @@ -1108,8 +1116,9 @@ void SbPlayerBridge::OnPlayerStatus(SbPlayer player, SbPlayerState state,
TRACE_EVENT1("cobalt::media", "SbPlayerBridge::OnPlayerStatus", "state",
state);
DCHECK(task_runner_->RunsTasksInCurrentSequence());

LOG(INFO) << "Called OnPlayerStatus";
if (player_ != player) {
LOG(INFO) << "Returning early due to player mismatch";
return;
}

Expand All @@ -1121,13 +1130,17 @@ void SbPlayerBridge::OnPlayerStatus(SbPlayer player, SbPlayerState state,

if (state == kSbPlayerStateInitialized) {
if (ticket_ == SB_PLAYER_INITIAL_TICKET) {
LOG(INFO) << "Initial ticket";
++ticket_;
}
if (sb_player_state_initialized_time_.is_null()) {
sb_player_state_initialized_time_ = Time::Now();
}
LOG(INFO) << "Calling interface seek";
sbplayer_interface_->Seek(player_, preroll_timestamp_, ticket_);
LOG(INFO) << "Setting volume";
SetVolume(volume_);
LOG(INFO) << "Setting Playback rate";
sbplayer_interface_->SetPlaybackRate(player_, playback_rate_);
return;
}
Expand Down
4 changes: 3 additions & 1 deletion cobalt/media/base/sbplayer_pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -873,19 +873,21 @@ void SbPlayerPipeline::CreatePlayer(SbDrmSystem drm_system) {
this, set_bounds_helper_.get(), allow_resume_after_suspend_,
default_output_mode_, decode_target_provider_, max_video_capabilities_,
max_video_input_size_, pipeline_identifier_));
LOG(INFO) << "Done creating SbPlayerBridge";
if (player_bridge_->IsValid()) {
#if SB_API_VERSION >= 15
// TODO(b/267678497): When `player_bridge_->GetAudioConfigurations()`
// returns no audio configurations, update the write durations again
// before the SbPlayer reaches `kSbPlayerStatePresenting`.
LOG(INFO) << "Requesting audio configurations";
audio_write_duration_for_preroll_ = audio_write_duration_ =
HasRemoteAudioOutputs(player_bridge_->GetAudioConfigurations())
? audio_write_duration_remote_
: audio_write_duration_local_;
LOG(INFO) << "SbPlayerBridge created, with audio write duration at "
<< audio_write_duration_for_preroll_;
#endif // SB_API_VERSION >= 15

LOG(INFO) << "About to set playback rate";
SetPlaybackRateTask(playback_rate_);
SetVolumeTask(volume_);
} else {
Expand Down
3 changes: 3 additions & 0 deletions starboard/android/apk/apk_sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ apk_sources = [
"//starboard/android/apk/app/src/main/java/dev/cobalt/libraries/services/clientloginfo/ClientLogInfoModule.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/media/AudioOutputManager.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/media/AudioTrackBridge.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/media/CobaltMediaSource.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/media/CobaltSampleStream.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/media/ExoPlayerBridge.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/media/Log.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaCodecBridge.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaCodecBridgeBuilder.java",
Expand Down
2 changes: 2 additions & 0 deletions starboard/android/apk/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ dependencies {
implementation 'com.google.android.gms:play-services-auth:18.0.0'
implementation 'com.google.protobuf:protobuf-lite:3.0.1'

implementation 'androidx.media3:media3-exoplayer:1.2.0'

testImplementation 'junit:junit:4.12'
testImplementation "com.google.truth:truth:1.1.3"
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import android.view.accessibility.CaptioningManager;
import androidx.annotation.Nullable;
import dev.cobalt.media.AudioOutputManager;
import dev.cobalt.media.ExoPlayerBridge;
import dev.cobalt.util.DisplayUtil;
import dev.cobalt.util.Holder;
import dev.cobalt.util.Log;
Expand Down Expand Up @@ -73,6 +74,7 @@ public interface HostApplication {
private AdvertisingId advertisingId;
private VolumeStateReceiver volumeStateReceiver;
private CrashContextUpdateHandler crashContextUpdateHandler;
private ExoPlayerBridge exoPlayerBridge;

static {
// Even though NativeActivity already loads our library from C++,
Expand Down Expand Up @@ -139,6 +141,7 @@ public StarboardBridge(
this.advertisingId = new AdvertisingId(appContext);
this.volumeStateReceiver = new VolumeStateReceiver(appContext);
this.isAmatiDevice = appContext.getPackageManager().hasSystemFeature(AMATI_EXPERIENCE_FEATURE);
this.exoPlayerBridge = new ExoPlayerBridge(appContext);
}

private native boolean nativeInitialize();
Expand Down Expand Up @@ -641,6 +644,12 @@ AudioOutputManager getAudioOutputManager() {
return audioOutputManager;
}

@SuppressWarnings("unused")
@UsedByNative
ExoPlayerBridge getExoPlayerBridge() {
return exoPlayerBridge;
}

/** Returns Java layer implementation for AudioPermissionRequester */
@SuppressWarnings("unused")
@UsedByNative
Expand Down
Loading
Loading