Skip to content

Commit

Permalink
feat: add {stream} opt to custom protocol registry to configure media…
Browse files Browse the repository at this point in the history
… player
  • Loading branch information
pfrazee committed Apr 30, 2020
1 parent 096c799 commit f97d7f1
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/api/structures/custom-scheme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
* `allowServiceWorkers` Boolean (optional) - Default false.
* `supportFetchAPI` Boolean (optional) - Default false.
* `corsEnabled` Boolean (optional) - Default false.
* `stream` Boolean (optional) - Default false.
1 change: 1 addition & 0 deletions patches/chromium/.patches
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@ feat_add_onclose_to_messageport.patch
fix_account_for_print_preview_disabled_when_printing_to_pdf.patch
web_contents.patch
ui_gtk_public_header.patch
feat_add_streaming-protocol_registry_to_multibuffer_data_source.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Paul Frazee <pfrazee@gmail.com>
Date: Tue, 28 Apr 2020 17:32:18 -0500
Subject: feat: add streaming-protocol registry to multibuffer_data_source

blink::WebMediaPlayerImpl - which provides the <video> and <audio> behaviors - needs to know
whether a data source will stream or fully buffer the response. It determines this behavior
with MultibufferDataSource::AssumeFullyBuffered() which has http/s hardwired. An incorrect
determination will cause the video/audio to fail playing.

This patch adds a list of "streaming protocols" to the MultibufferDataSource in order to allow
other protocols to register their streaming behavior. MultibufferDataSource::AssumeFullyBuffered()
then refers to the list so that it can correctly determine the data source's settings.

diff --git a/media/blink/multibuffer_data_source.cc b/media/blink/multibuffer_data_source.cc
index 0f6ae1fb8b4ff9f24ce3f407b7359e016fc6de5f..3f7469376b70b0fb9ab623cc5b415a69a5640cf0 100644
--- a/media/blink/multibuffer_data_source.cc
+++ b/media/blink/multibuffer_data_source.cc
@@ -65,10 +65,20 @@ const int kUpdateBufferSizeFrequency = 32;
// How long to we delay a seek after a read?
constexpr base::TimeDelta kSeekDelay = base::TimeDelta::FromMilliseconds(20);

+// Schemes that can stream their responses.
+std::vector<std::string> streaming_schemes = {
+ url::kHttpsScheme,
+ url::kHttpScheme
+};
+
} // namespace

namespace media {

+void AddStreamingScheme(const char* new_scheme) {
+ streaming_schemes.push_back(new_scheme);
+}
+
class MultibufferDataSource::ReadOperation {
public:
ReadOperation(int64_t position,
@@ -158,7 +168,14 @@ bool MultibufferDataSource::media_has_played() const {

bool MultibufferDataSource::AssumeFullyBuffered() const {
DCHECK(url_data_);
- return !url_data_->url().SchemeIsHTTPOrHTTPS();
+
+ const std::string scheme = url_data_->url().scheme();
+ for (const std::string& streaming_scheme : streaming_schemes) {
+ if (base::LowerCaseEqualsASCII(scheme, streaming_scheme)) {
+ return false;
+ }
+ }
+ return true;
}

void MultibufferDataSource::SetReader(MultiBufferReader* reader) {
diff --git a/media/blink/multibuffer_data_source.h b/media/blink/multibuffer_data_source.h
index 3da5a7bba5e7cc0f54998a81649f4dd9d78aa7be..938ae6ebc92315b3a75019c3bc8c9058106f7695 100644
--- a/media/blink/multibuffer_data_source.h
+++ b/media/blink/multibuffer_data_source.h
@@ -30,6 +30,8 @@ class BufferedDataSourceHost;
class MediaLog;
class MultiBufferReader;

+void MEDIA_BLINK_EXPORT AddStreamingScheme(const char* new_scheme);
+
// A data source capable of loading URLs and buffering the data using an
// in-memory sliding window.
//
10 changes: 10 additions & 0 deletions shell/browser/api/electron_api_protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ namespace {
// List of registered custom standard schemes.
std::vector<std::string> g_standard_schemes;

// List of registered custom streaming schemes.
std::vector<std::string> g_streaming_schemes;

struct SchemeOptions {
bool standard = false;
bool secure = false;
bool bypassCSP = false;
bool allowServiceWorkers = false;
bool supportFetchAPI = false;
bool corsEnabled = false;
bool stream = false;
};

struct CustomScheme {
Expand Down Expand Up @@ -66,6 +70,7 @@ struct Converter<CustomScheme> {
opt.Get("allowServiceWorkers", &(out->options.allowServiceWorkers));
opt.Get("supportFetchAPI", &(out->options.supportFetchAPI));
opt.Get("corsEnabled", &(out->options.corsEnabled));
opt.Get("stream", &(out->options.stream));
}
return true;
}
Expand Down Expand Up @@ -119,6 +124,9 @@ void RegisterSchemesAsPrivileged(gin_helper::ErrorThrower thrower,
if (custom_scheme.options.allowServiceWorkers) {
service_worker_schemes.push_back(custom_scheme.scheme);
}
if (custom_scheme.options.stream) {
g_streaming_schemes.push_back(custom_scheme.scheme);
}
}

const auto AppendSchemesToCmdLine = [](const char* switch_name,
Expand All @@ -138,6 +146,8 @@ void RegisterSchemesAsPrivileged(gin_helper::ErrorThrower thrower,
service_worker_schemes);
AppendSchemesToCmdLine(electron::switches::kStandardSchemes,
g_standard_schemes);
AppendSchemesToCmdLine(electron::switches::kStreamingSchemes,
g_streaming_schemes);
}

namespace {
Expand Down
3 changes: 2 additions & 1 deletion shell/browser/electron_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,8 @@ void ElectronBrowserClient::AppendExtraCommandLineSwitches(
switches::kStandardSchemes, switches::kEnableSandbox,
switches::kSecureSchemes, switches::kBypassCSPSchemes,
switches::kCORSSchemes, switches::kFetchSchemes,
switches::kServiceWorkerSchemes, switches::kEnableApiFilteringLogging};
switches::kServiceWorkerSchemes, switches::kEnableApiFilteringLogging,
switches::kStreamingSchemes};
command_line->CopySwitchesFrom(*base::CommandLine::ForCurrentProcess(),
kCommonSwitchNames,
base::size(kCommonSwitchNames));
Expand Down
3 changes: 3 additions & 0 deletions shell/common/options_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ const char kFetchSchemes[] = "fetch-schemes";
// Register schemes as CORS enabled.
const char kCORSSchemes[] = "cors-schemes";

// Register schemes as streaming responses.
const char kStreamingSchemes[] = "streaming-schemes";

// The browser process app model ID
const char kAppUserModelId[] = "app-user-model-id";

Expand Down
1 change: 1 addition & 0 deletions shell/common/options_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ extern const char kSecureSchemes[];
extern const char kBypassCSPSchemes[];
extern const char kFetchSchemes[];
extern const char kCORSSchemes[];
extern const char kStreamingSchemes[];
extern const char kAppUserModelId[];
extern const char kAppPath[];
extern const char kEnableApiFilteringLogging[];
Expand Down
9 changes: 9 additions & 0 deletions shell/renderer/renderer_client_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
#include "shell/renderer/extensions/electron_extensions_renderer_client.h"
#endif // BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)

namespace media {
void AddStreamingScheme(const char*);
}

namespace electron {

namespace {
Expand All @@ -107,6 +111,11 @@ RendererClientBase::RendererClientBase() {
ParseSchemesCLISwitch(command_line, switches::kCORSSchemes);
for (const std::string& scheme : cors_schemes_list)
url::AddCorsEnabledScheme(scheme.c_str());
// Parse --streaming-schemes=scheme1,scheme2
std::vector<std::string> streaming_schemes_list =
ParseSchemesCLISwitch(command_line, switches::kStreamingSchemes);
for (const std::string& scheme : streaming_schemes_list)
media::AddStreamingScheme(scheme.c_str());
isolated_world_ = base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kContextIsolation);
// We rely on the unique process host id which is notified to the
Expand Down

0 comments on commit f97d7f1

Please sign in to comment.