From 53eb4db64c50229bb0d87778cc9b083d80c2d996 Mon Sep 17 00:00:00 2001 From: Austin Osagie Date: Wed, 11 Dec 2024 15:38:22 -0800 Subject: [PATCH 1/3] Add switch to disable progressive support 1. Adds a runtime switch "--disable_progressive_playback" that will prevent progressive media playback. When set, Cobalt will reject CanPlayType() queries for progressive formats, or will report an error before a ProgressiveDemuxer is constructed. 2. Rearranges methods in `CanPlayTypeHandlerStarboard` to match the declaration order in `CanPlayTypeHandler`. b/382791540 --- cobalt/browser/browser_module.cc | 4 ++ cobalt/browser/switches.cc | 5 +++ cobalt/browser/switches.h | 1 + cobalt/media/can_play_type_handler.h | 1 + cobalt/media/media_module.cc | 47 +++++++++++--------- cobalt/media/player/web_media_player_impl.cc | 11 +++++ 6 files changed, 49 insertions(+), 20 deletions(-) diff --git a/cobalt/browser/browser_module.cc b/cobalt/browser/browser_module.cc index 75a27b117a44..70ff6dc75aa5 100644 --- a/cobalt/browser/browser_module.cc +++ b/cobalt/browser/browser_module.cc @@ -398,6 +398,10 @@ BrowserModule::BrowserModule(const GURL& url, base::Unretained(this)))); } + if (command_line->HasSwitch(switches::kDisableProgressivePlayback)) { + can_play_type_handler_->DisableProgressiveSupport(); + } + // Set the fallback splash screen url to the default fallback url. fallback_splash_screen_url_ = options.fallback_splash_screen_url; diff --git a/cobalt/browser/switches.cc b/cobalt/browser/switches.cc index 7a3b5026324e..161b13f750e4 100644 --- a/cobalt/browser/switches.cc +++ b/cobalt/browser/switches.cc @@ -333,6 +333,10 @@ const char kOmitDeviceAuthenticationQueryParametersHelp[] = "When set, no device authentication parameters will be appended to the" "initial URL."; +const char kDisableProgressivePlayback[] = "disable_progressive_playback"; +const char kDisableProgressivePlaybackHelp[] = + "Setting this switch disables support for progressive media playback"; + const char kProxy[] = "proxy"; const char kProxyHelp[] = "Specifies a proxy to use for network connections. " @@ -507,6 +511,7 @@ std::string HelpMessage() { {kOffscreenTargetCacheSizeInBytes, kOffscreenTargetCacheSizeInBytesHelp}, {kOmitDeviceAuthenticationQueryParameters, kOmitDeviceAuthenticationQueryParametersHelp}, + {kDisableProgressivePlayback, kDisableProgressivePlaybackHelp}, {kProxy, kProxyHelp}, {kQrCodeOverlay, kQrCodeOverlayHelp}, {kRemoteTypefaceCacheSizeInBytes, kRemoteTypefaceCacheSizeInBytesHelp}, diff --git a/cobalt/browser/switches.h b/cobalt/browser/switches.h index 982389104553..4cfeb24877f5 100644 --- a/cobalt/browser/switches.h +++ b/cobalt/browser/switches.h @@ -131,6 +131,7 @@ extern const char kOffscreenTargetCacheSizeInBytes[]; extern const char kOffscreenTargetCacheSizeInBytesHelp[]; extern const char kOmitDeviceAuthenticationQueryParameters[]; extern const char kOmitDeviceAuthenticationQueryParametersHelp[]; +extern const char kDisableProgressivePlayback[]; extern const char kProxy[]; extern const char kProxyHelp[]; extern const char kQrCodeOverlay[]; diff --git a/cobalt/media/can_play_type_handler.h b/cobalt/media/can_play_type_handler.h index cc9734b22665..906b44749831 100644 --- a/cobalt/media/can_play_type_handler.h +++ b/cobalt/media/can_play_type_handler.h @@ -33,6 +33,7 @@ class CanPlayTypeHandler { virtual void SetDisabledMediaCodecs(const std::string& codecs) = 0; virtual void SetDisabledMediaEncryptionSchemes( const std::string& disabled_encryption_schemes) = 0; + virtual void DisableProgressiveSupport() = 0; protected: CanPlayTypeHandler() {} diff --git a/cobalt/media/media_module.cc b/cobalt/media/media_module.cc index f245ac43a9e3..f1d74cd897f2 100644 --- a/cobalt/media/media_module.cc +++ b/cobalt/media/media_module.cc @@ -93,24 +93,6 @@ static std::string ExtractEncryptionScheme(const std::string& key_system) { class CanPlayTypeHandlerStarboard : public CanPlayTypeHandler { public: - void SetDisabledMediaCodecs( - const std::string& disabled_media_codecs) override { - disabled_media_codecs_ = - base::SplitString(disabled_media_codecs, ";", base::TRIM_WHITESPACE, - base::SPLIT_WANT_NONEMPTY); - LOG(INFO) << "Disabled media codecs \"" << disabled_media_codecs - << "\" from console/command line."; - } - - void SetDisabledMediaEncryptionSchemes( - const std::string& disabled_encryption_schemes) override { - disabled_encryption_schemes_ = - base::SplitString(disabled_encryption_schemes, ";", - base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); - LOG(INFO) << "Disabled encryption scheme(s) \"" - << disabled_encryption_schemes << "\" from command line."; - } - SbMediaSupportType CanPlayProgressive( const std::string& mime_type) const override { // |mime_type| is something like: @@ -122,8 +104,9 @@ class CanPlayTypeHandlerStarboard : public CanPlayTypeHandler { // progressive. SbMediaSupportType support_type; media::FormatSupportQueryMetrics metrics; - if (strstr(mime_type.c_str(), "video/mp4") == 0 && - strstr(mime_type.c_str(), "application/x-mpegURL") == 0) { + if (disable_progressive_support_ || + (strstr(mime_type.c_str(), "video/mp4") == 0 && + strstr(mime_type.c_str(), "application/x-mpegURL") == 0)) { support_type = kSbMediaSupportTypeNotSupported; } else { support_type = CanPlayType(mime_type, ""); @@ -145,6 +128,29 @@ class CanPlayTypeHandlerStarboard : public CanPlayTypeHandler { return support_type; } + void SetDisabledMediaCodecs( + const std::string& disabled_media_codecs) override { + disabled_media_codecs_ = + base::SplitString(disabled_media_codecs, ";", base::TRIM_WHITESPACE, + base::SPLIT_WANT_NONEMPTY); + LOG(INFO) << "Disabled media codecs \"" << disabled_media_codecs + << "\" from console/command line."; + } + + void SetDisabledMediaEncryptionSchemes( + const std::string& disabled_encryption_schemes) override { + disabled_encryption_schemes_ = + base::SplitString(disabled_encryption_schemes, ";", + base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); + LOG(INFO) << "Disabled encryption scheme(s) \"" + << disabled_encryption_schemes << "\" from command line."; + } + + void DisableProgressiveSupport() override { + disable_progressive_support_ = true; + LOG(INFO) << "Disabled progressive playback support from command line"; + } + private: SbMediaSupportType CanPlayType(const std::string& mime_type, const std::string& key_system) const { @@ -181,6 +187,7 @@ class CanPlayTypeHandlerStarboard : public CanPlayTypeHandler { // List of disabled DRM encryption schemes that will be treated as // unsupported. std::vector disabled_encryption_schemes_; + bool disable_progressive_support_ = false; }; } // namespace diff --git a/cobalt/media/player/web_media_player_impl.cc b/cobalt/media/player/web_media_player_impl.cc index 62189b7b3061..4360aa372ea0 100644 --- a/cobalt/media/player/web_media_player_impl.cc +++ b/cobalt/media/player/web_media_player_impl.cc @@ -32,6 +32,8 @@ #include "media/base/limits.h" #include "media/base/timestamp_constants.h" #include "media/filters/chunk_demuxer.h" +#include "starboard/shared/starboard/application.h" +#include "starboard/shared/starboard/command_line.h" #include "starboard/system.h" #include "starboard/types.h" #include "ui/gfx/geometry/rect.h" @@ -270,6 +272,15 @@ void WebMediaPlayerImpl::LoadProgressive( DCHECK_EQ(task_runner_, base::SequencedTaskRunner::GetCurrentDefault()); UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(url), kMaxURLScheme); + auto command_line = + starboard::shared::starboard::Application::Get()->GetCommandLine(); + if (command_line->HasSwitch("disable_progressive_playback")) { + LOG(INFO) << "Disabled progressive playback support from command line"; + SetNetworkError(WebMediaPlayer::kNetworkStateFormatError, + "Disabled progressive playback support from command line"); + return; + } + LOG(INFO) << "Start PROGRESSIVE playback"; // Handle any volume changes that occurred before load(). From 789eeac3ca52b38ec794c18a61977022dbb137df Mon Sep 17 00:00:00 2001 From: Austin Osagie Date: Thu, 12 Dec 2024 11:14:46 -0800 Subject: [PATCH 2/3] Add h5vcc switch --- cobalt/media/media_module.cc | 7 ++++++- cobalt/media/media_module.h | 2 ++ cobalt/media/player/web_media_player_impl.cc | 14 +++++++++----- cobalt/media/player/web_media_player_impl.h | 3 +++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/cobalt/media/media_module.cc b/cobalt/media/media_module.cc index f1d74cd897f2..0e0ed2062d69 100644 --- a/cobalt/media/media_module.cc +++ b/cobalt/media/media_module.cc @@ -254,6 +254,11 @@ bool MediaModule::SetConfiguration(const std::string& name, int32 value) { return true; } } + } else if (name == "DisableProgressivePlayback") { + disable_progressive_playback_ = value; + LOG(INFO) << "Progressive playback is " << (value ? "disabled" : "enabled") + << "."; + return true; } return false; @@ -275,7 +280,7 @@ std::unique_ptr MediaModule::CreateWebMediaPlayer( #if SB_API_VERSION >= 15 audio_write_duration_local_, audio_write_duration_remote_, #endif // SB_API_VERSION >= 15 - &media_log_)); + disable_progressive_playback_, &media_log_)); } void MediaModule::Suspend() { diff --git a/cobalt/media/media_module.h b/cobalt/media/media_module.h index f29973a1f615..73283348ebb7 100644 --- a/cobalt/media/media_module.h +++ b/cobalt/media/media_module.h @@ -141,6 +141,8 @@ class MediaModule : public WebMediaPlayerFactory, #endif // SB_API_VERSION >= 15 DecoderBufferAllocator decoder_buffer_allocator_; + + bool disable_progressive_playback_ = false; }; } // namespace media diff --git a/cobalt/media/player/web_media_player_impl.cc b/cobalt/media/player/web_media_player_impl.cc index 4360aa372ea0..6a683b685437 100644 --- a/cobalt/media/player/web_media_player_impl.cc +++ b/cobalt/media/player/web_media_player_impl.cc @@ -117,7 +117,7 @@ WebMediaPlayerImpl::WebMediaPlayerImpl( base::TimeDelta audio_write_duration_local, base::TimeDelta audio_write_duration_remote, #endif // SB_API_VERSION >= 15 - ::media::MediaLog* const media_log) + bool disable_progressive_playback, ::media::MediaLog* const media_log) : pipeline_thread_("media_pipeline"), network_state_(WebMediaPlayer::kNetworkStateEmpty), ready_state_(WebMediaPlayer::kReadyStateHaveNothing), @@ -128,6 +128,7 @@ WebMediaPlayerImpl::WebMediaPlayerImpl( max_audio_samples_per_write_(max_audio_samples_per_write), force_punch_out_by_default_(force_punch_out_by_default), proxy_(new WebMediaPlayerProxy(task_runner_, this)), + disable_progressive_playback_(disable_progressive_playback), media_log_(media_log), is_local_source_(false), suppress_destruction_errors_(false), @@ -274,10 +275,13 @@ void WebMediaPlayerImpl::LoadProgressive( UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(url), kMaxURLScheme); auto command_line = starboard::shared::starboard::Application::Get()->GetCommandLine(); - if (command_line->HasSwitch("disable_progressive_playback")) { - LOG(INFO) << "Disabled progressive playback support from command line"; - SetNetworkError(WebMediaPlayer::kNetworkStateFormatError, - "Disabled progressive playback support from command line"); + if (disable_progressive_playback_ || + command_line->HasSwitch("disable_progressive_playback")) { + LOG(INFO) + << "Disabled progressive playback support via command line or H5vcc"; + SetNetworkError( + WebMediaPlayer::kNetworkStateFormatError, + "Disabled progressive playback support via command line or H5vcc"); return; } diff --git a/cobalt/media/player/web_media_player_impl.h b/cobalt/media/player/web_media_player_impl.h index 6d4c55f39f9c..213b964b4403 100644 --- a/cobalt/media/player/web_media_player_impl.h +++ b/cobalt/media/player/web_media_player_impl.h @@ -116,6 +116,7 @@ class WebMediaPlayerImpl : public WebMediaPlayer, base::TimeDelta audio_write_duration_local, base::TimeDelta audio_write_duration_remote, #endif // SB_API_VERSION >= 15 + bool disable_progressive_playback, ::media::MediaLog* const media_log); ~WebMediaPlayerImpl() override; @@ -329,6 +330,8 @@ class WebMediaPlayerImpl : public WebMediaPlayer, bool is_resuming_from_background_mode_ = false; + const bool disable_progressive_playback_; + DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); }; From 0c3a9d3727f501ba36a8e39ef7f81e417450bed1 Mon Sep 17 00:00:00 2001 From: Austin Osagie Date: Tue, 17 Dec 2024 14:24:29 -0800 Subject: [PATCH 3/3] Use base::CommandLine --- cobalt/media/player/web_media_player_impl.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cobalt/media/player/web_media_player_impl.cc b/cobalt/media/player/web_media_player_impl.cc index 6a683b685437..c08109989f1e 100644 --- a/cobalt/media/player/web_media_player_impl.cc +++ b/cobalt/media/player/web_media_player_impl.cc @@ -13,6 +13,7 @@ #include "base/bind.h" #include "base/bind_helpers.h" +#include "base/command_line.h" #include "base/metrics/histogram.h" #include "base/metrics/histogram_macros.h" #include "base/strings/string_number_conversions.h" @@ -22,6 +23,7 @@ #include "base/task/sequenced_task_runner.h" #include "base/trace_event/trace_event.h" #include "cobalt/base/instance_counter.h" +#include "cobalt/browser/switches.h" #include "cobalt/media/base/drm_system.h" #include "cobalt/media/base/metrics_provider.h" #include "cobalt/media/base/sbplayer_pipeline.h" @@ -32,8 +34,6 @@ #include "media/base/limits.h" #include "media/base/timestamp_constants.h" #include "media/filters/chunk_demuxer.h" -#include "starboard/shared/starboard/application.h" -#include "starboard/shared/starboard/command_line.h" #include "starboard/system.h" #include "starboard/types.h" #include "ui/gfx/geometry/rect.h" @@ -273,10 +273,9 @@ void WebMediaPlayerImpl::LoadProgressive( DCHECK_EQ(task_runner_, base::SequencedTaskRunner::GetCurrentDefault()); UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(url), kMaxURLScheme); - auto command_line = - starboard::shared::starboard::Application::Get()->GetCommandLine(); + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); if (disable_progressive_playback_ || - command_line->HasSwitch("disable_progressive_playback")) { + command_line->HasSwitch(browser::switches::kDisableProgressivePlayback)) { LOG(INFO) << "Disabled progressive playback support via command line or H5vcc"; SetNetworkError(