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

Add persistent storage flag for ALLM #4600

Merged
merged 5 commits into from
Jan 6, 2025
Merged
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
2 changes: 2 additions & 0 deletions cobalt/browser/browser_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,8 @@ void BrowserModule::InitializeComponents() {
} else {
options_.media_module_options.allow_resume_after_suspend =
SbSystemSupportsResume();
options_.media_module_options.persistent_settings =
options_.persistent_settings;
media_module_.reset(new media::MediaModule(system_window_.get(),
GetResourceProvider(),
options_.media_module_options));
Expand Down
15 changes: 15 additions & 0 deletions cobalt/h5vcc/h5vcc_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const {
const char kHTTP2[] = "HTTP2";
const char kHTTP3[] = "HTTP3";
const char kSkiaRasterizer[] = "SkiaRasterizer";
const char kSetPreferMinimalPostProcessing[] =
"SetPreferMinimalPostProcessing";

#if SB_IS(EVERGREEN)
const char kUpdaterMinFreeSpaceBytes[] = "Updater.MinFreeSpaceBytes";
Expand All @@ -81,6 +83,19 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const {
: false;
}

if (name.compare(kSetPreferMinimalPostProcessing) == 0 &&
value.IsType<int32>()) {
if (!persistent_settings_ || !media_module_) {
return false;
} else {
persistent_settings_->Set(
media::kPreferMinimalPostProcessingPersistentSettingsKey,
base::Value(value.AsType<int32>() == 1));
media_module_->SetPreferMinimalPostProcessingFromPersistentSettings();
return true;
}
}

if (name.compare(kNavigatorUAData) == 0 && value.IsType<int32>() &&
value.AsType<int32>() == 1) {
global_environment_->BindTo("userAgentData", user_agent_data_, "navigator");
Expand Down
1 change: 1 addition & 0 deletions cobalt/media/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ component("media") {
"//cobalt/loader:origin",
"//cobalt/math",
"//cobalt/network",
"//cobalt/persistent_storage:persistent_settings",
"//cobalt/render_tree:render_tree",
"//cobalt/system_window:system_window",
"//media",
Expand Down
37 changes: 37 additions & 0 deletions cobalt/media/media_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,20 @@ class CanPlayTypeHandlerStarboard : public CanPlayTypeHandler {

} // namespace

MediaModule::MediaModule(system_window::SystemWindow* system_window,
render_tree::ResourceProvider* resource_provider,
const Options& options)
: sbplayer_interface_(new DefaultSbPlayerInterface),
options_(options),
system_window_(system_window),
resource_provider_(resource_provider) {
Initialize();
}

void MediaModule::Initialize() {
SetPreferMinimalPostProcessingFromPersistentSettings();
}

bool MediaModule::SetConfiguration(const std::string& name, int32 value) {
if (name == "MaxAudioSamplesPerWrite" && value > 0) {
max_audio_samples_per_write_ = value;
Expand Down Expand Up @@ -264,6 +278,29 @@ bool MediaModule::SetConfiguration(const std::string& name, int32 value) {
return false;
}

void MediaModule::SetPreferMinimalPostProcessingFromPersistentSettings() {
// Called on initialization and when the persistent setting is changed.
if (options_.persistent_settings == nullptr) {
return;
}

base::Value value;
options_.persistent_settings->Get(
kPreferMinimalPostProcessingPersistentSettingsKey, &value);
bool prefer_minimal_post_processing = value.GetIfBool().value_or(false);

const StarboardExtensionMediaSettingsApi* media_settings_api =
static_cast<const StarboardExtensionMediaSettingsApi*>(
SbSystemGetExtension(kStarboardExtensionMediaSettingsName));
if (media_settings_api &&
std::string(media_settings_api->name) ==
kStarboardExtensionMediaSettingsName &&
media_settings_api->version >= 3) {
media_settings_api->SetPreferMinimalPostProcessing(
prefer_minimal_post_processing);
}
}

std::unique_ptr<WebMediaPlayer> MediaModule::CreateWebMediaPlayer(
WebMediaPlayerClient* client) {
SbWindow window = kSbWindowInvalid;
Expand Down
16 changes: 10 additions & 6 deletions cobalt/media/media_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "cobalt/media/player/web_media_player_delegate.h"
#include "cobalt/media/player/web_media_player_impl.h"
#include "cobalt/media/web_media_player_factory.h"
#include "cobalt/persistent_storage/persistent_settings.h"
#include "cobalt/render_tree/image.h"
#include "cobalt/render_tree/resource_provider.h"
#include "cobalt/system_window/system_window.h"
Expand All @@ -42,13 +43,17 @@
namespace cobalt {
namespace media {

const char kPreferMinimalPostProcessingPersistentSettingsKey[] =
"PreferMinimalPostProcessing";

class MediaModule : public WebMediaPlayerFactory,
public WebMediaPlayerDelegate {
public:
struct Options {
Options() {}
Options() : persistent_settings(nullptr) {}

bool allow_resume_after_suspend = true;
persistent_storage::PersistentSettings* persistent_settings;
};

typedef render_tree::Image Image;
Expand All @@ -59,16 +64,13 @@ class MediaModule : public WebMediaPlayerFactory,

MediaModule(system_window::SystemWindow* system_window,
render_tree::ResourceProvider* resource_provider,
const Options& options = Options())
: sbplayer_interface_(new DefaultSbPlayerInterface),
options_(options),
system_window_(system_window),
resource_provider_(resource_provider) {}
const Options& options = Options());

// Returns true when the setting is set successfully or if the setting has
// already been set to the expected value. Returns false when the setting is
// invalid or not set to the expected value.
bool SetConfiguration(const std::string& name, int32 value);
void SetPreferMinimalPostProcessingFromPersistentSettings();

const DecoderBufferAllocator* GetDecoderBufferAllocator() const {
return &decoder_buffer_allocator_;
Expand Down Expand Up @@ -98,6 +100,8 @@ class MediaModule : public WebMediaPlayerFactory,
}

private:
void Initialize();

void RegisterDebugState(WebMediaPlayer* player);
void DeregisterDebugState();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.content.pm.PackageManager.NameNotFoundException;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Pair;
import android.view.View;
Expand Down Expand Up @@ -421,4 +422,22 @@ public void onLowMemory() {
public long getAppStartTimestamp() {
return timeInNanoseconds;
}

public void setPreferMinimalPostProcessing(boolean value) {
if (Build.VERSION.SDK_INT < 30) {
return;
}

Runnable runnable =
new Runnable() {
@Override
public void run() {
if (getDisplay().isMinimalPostProcessingSupported()) {
kaidokert marked this conversation as resolved.
Show resolved Hide resolved
getWindow().setPreferMinimalPostProcessing(value);
}
}
};

runOnUiThread(runnable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -827,4 +827,13 @@ protected long getPlayServicesVersion() {
return 0;
}
}

@SuppressWarnings("unused")
@UsedByNative
protected void setPreferMinimalPostProcessing(boolean value) {
Activity activity = activityHolder.get();
if (activity instanceof CobaltActivity) {
((CobaltActivity) activity).setPreferMinimalPostProcessing(value);
}
}
}
10 changes: 9 additions & 1 deletion starboard/android/shared/media_settings_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include "starboard/android/shared/media_settings_api.h"
#include "starboard/android/shared/jni_env_ext.h"
#include "starboard/android/shared/media_codec_bridge_eradicator.h"
#include "starboard/extension/media_settings.h"

Expand All @@ -33,11 +34,18 @@ void SetAsyncReleaseMediaCodecBridgeTimeoutSeconds(int timeout_seconds) {
MediaCodecBridgeEradicator::GetInstance()->SetTimeoutSeconds(timeout_seconds);
}

void SetPreferMinimalPostProcessing(bool value) {
JniEnvExt* env = JniEnvExt::Get();
env->CallStarboardVoidMethodOrAbort("setPreferMinimalPostProcessing", "(Z)V",
static_cast<jboolean>(value));
}

const StarboardExtensionMediaSettingsApi kMediaSettingsApi = {
kStarboardExtensionMediaSettingsName,
2, // API version that's implemented.
3, // API version that's implemented.
&EnableAsyncReleaseMediaCodecBridge,
&SetAsyncReleaseMediaCodecBridgeTimeoutSeconds,
&SetPreferMinimalPostProcessing,
};

} // namespace
Expand Down
4 changes: 4 additions & 0 deletions starboard/extension/media_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ typedef struct StarboardExtensionMediaSettingsApi {
// Android TV.
void (*SetAsyncReleaseMediaCodecBridgeTimeoutSeconds)(int timeout);

// This API passes the boolean through to
// Window.setPreferMinimalPostProcessing on Android TV.
// Added in extension version 3.
void (*SetPreferMinimalPostProcessing)(bool value);
} StarboardExtensionMediaSettingsApi;

#ifdef __cplusplus
Expand Down
Loading