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 switch to disable progressive support #4564

Merged
merged 4 commits into from
Dec 18, 2024
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
4 changes: 4 additions & 0 deletions cobalt/browser/browser_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions cobalt/browser/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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. "
Expand Down Expand Up @@ -507,6 +511,7 @@ std::string HelpMessage() {
{kOffscreenTargetCacheSizeInBytes, kOffscreenTargetCacheSizeInBytesHelp},
{kOmitDeviceAuthenticationQueryParameters,
kOmitDeviceAuthenticationQueryParametersHelp},
{kDisableProgressivePlayback, kDisableProgressivePlaybackHelp},
{kProxy, kProxyHelp},
{kQrCodeOverlay, kQrCodeOverlayHelp},
{kRemoteTypefaceCacheSizeInBytes, kRemoteTypefaceCacheSizeInBytesHelp},
Expand Down
1 change: 1 addition & 0 deletions cobalt/browser/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
1 change: 1 addition & 0 deletions cobalt/media/can_play_type_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
54 changes: 33 additions & 21 deletions cobalt/media/media_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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, "");
Expand All @@ -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 {
Expand Down Expand Up @@ -181,6 +187,7 @@ class CanPlayTypeHandlerStarboard : public CanPlayTypeHandler {
// List of disabled DRM encryption schemes that will be treated as
// unsupported.
std::vector<std::string> disabled_encryption_schemes_;
bool disable_progressive_support_ = false;
};

} // namespace
Expand Down Expand Up @@ -247,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;
Expand All @@ -268,7 +280,7 @@ std::unique_ptr<WebMediaPlayer> 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() {
Expand Down
2 changes: 2 additions & 0 deletions cobalt/media/media_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ class MediaModule : public WebMediaPlayerFactory,
#endif // SB_API_VERSION >= 15

DecoderBufferAllocator decoder_buffer_allocator_;

bool disable_progressive_playback_ = false;
};

} // namespace media
Expand Down
16 changes: 15 additions & 1 deletion cobalt/media/player/web_media_player_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -115,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),
Expand All @@ -126,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),
Expand Down Expand Up @@ -270,6 +273,17 @@ void WebMediaPlayerImpl::LoadProgressive(
DCHECK_EQ(task_runner_, base::SequencedTaskRunner::GetCurrentDefault());

UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(url), kMaxURLScheme);
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (disable_progressive_playback_ ||
command_line->HasSwitch(browser::switches::kDisableProgressivePlayback)) {
sideb0ard marked this conversation as resolved.
Show resolved Hide resolved
LOG(INFO)
<< "Disabled progressive playback support via command line or H5vcc";
SetNetworkError(
WebMediaPlayer::kNetworkStateFormatError,
"Disabled progressive playback support via command line or H5vcc");
return;
}

LOG(INFO) << "Start PROGRESSIVE playback";

// Handle any volume changes that occurred before load().
Expand Down
3 changes: 3 additions & 0 deletions cobalt/media/player/web_media_player_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
};

Expand Down
Loading