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

fix: video/audio playing on custom stream protocols #22955

Merged

Conversation

pfrazee
Copy link
Contributor

@pfrazee pfrazee commented Apr 3, 2020

Description of Change

Currently, <video> and <audio> tags fail to play for custom streaming protocols. 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 PR includes a chromium patch which adds a list of "streaming protocols" in order to allow other protocols to register their streaming behavior. MultibufferDataSource::AssumeFullyBuffered() then refers to the registry so that it can correctly determine the data source's settings.

Reference issue: #21018 (comment)

Checklist

Release Notes

Notes: Added {stream:} option to registerSchemeAsPrivileged to enable custom protocols to stream video and audio

@pfrazee pfrazee requested a review from a team as a code owner April 3, 2020 15:16
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Apr 3, 2020
&GetSchemeRegistryWithoutLocking()->standard_schemes);
}

+void AddStreamingScheme(const char* new_scheme) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argument SchemeType is not defined here, hence undefined symbols with overloaded functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, I'll give that a fix.

@@ -173,6 +178,11 @@ ProtocolError Protocol::RegisterProtocol(ProtocolType type,
const std::string& scheme,
const ProtocolHandler& handler) {
bool added = protocol_registry_->RegisterProtocol(type, scheme, handler);
if (added) {
if (type == ProtocolType::kHttp || type == ProtocolType::kStream) {
g_streaming_schemes.push_back(scheme);
Copy link
Member

@deepak1556 deepak1556 Apr 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Necessary review, this call assumes that registerSchemeAsPrivileged will be called after , but we document users to make the registerSchemeAsPrivileged as the first call in the app as early as possible before app ready due to threading constraints in //url.

The right way would be to provide a new option stream: true in the registerSchemeAsPrivileged api and go from there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My assumption was that we should automatically register known-streaming protocols, but I guess you're saying that's not an option due to when registerProtocol() is called?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you're saying that's not an option due to when registerProtocol() is called?

Yup

@codebytere codebytere changed the title Fix video/audio playing on custom stream protocols fix: video/audio playing on custom stream protocols Apr 3, 2020
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Apr 4, 2020
@pfrazee pfrazee force-pushed the custom-streaming-protocol-videofix branch from 08c49ae to eb40f0a Compare April 4, 2020 21:33
@pfrazee
Copy link
Contributor Author

pfrazee commented Apr 4, 2020

@deepak1556 The PR has been fixed and updated with your suggestions. You can find a test fiddle here (be sure to update the video path in main.js): https://gist.github.com/283332286b015993700cabf1262ff6d4

Per @nornagon's suggestion, I'm going to submit the chromium patch to chromium to see if they'll upstream it. I'll keep this PR updated with progress on that front.


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

@deepak1556 deepak1556 Apr 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also provide a way to register via ContentClient::AddAdditionalSchemes https://source.chromium.org/chromium/chromium/src/+/master:content/public/common/content_client.h;l=117-148 so that we can register the scheme in ElectronContentClient::AddAdditionalSchemes that will help the network service process understand the scheme.

This is needed if there is a check in the network service for streaming. I am not familiar with that code, but once you upstream the patch, chromium folks will advice if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@pfrazee
Copy link
Contributor Author

pfrazee commented Apr 9, 2020

Issue opened in Chromium tracker: https://bugs.chromium.org/p/chromium/issues/detail?id=1068034#c3

@pfrazee
Copy link
Contributor Author

pfrazee commented Apr 22, 2020

@ahallicks
Copy link

Just to note that the notes read:

Fix to video/audio playblack on custom stream protocols

I think you mean playback.

@pfrazee
Copy link
Contributor Author

pfrazee commented Apr 23, 2020

Ah, yes. Whoops, thanks for the correction

@pfrazee
Copy link
Contributor Author

pfrazee commented Apr 24, 2020

Chromium just closed as wontfix https://bugs.chromium.org/p/chromium/issues/detail?id=1068034#c7

Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather see this accomplished without patching //url. It seems like we could get away with a more specific patch that just targets MultibufferDataSource::AssumeFullyBuffered.

@pfrazee pfrazee force-pushed the custom-streaming-protocol-videofix branch from 2219d69 to 9024668 Compare April 28, 2020 22:44
@pfrazee
Copy link
Contributor Author

pfrazee commented Apr 28, 2020

@nornagon Okay! I've rewritten the PR so that the chromium patch adds the "streaming protocols" list to the media namespace (in the MultibufferDataSource code). Let me know if that's looking better to you.

@pfrazee
Copy link
Contributor Author

pfrazee commented Apr 30, 2020

Okay looks like the builds are failing because of something related to my patch. I'll check into that.

I'll also add a test and improve the docs a bit.

@pfrazee pfrazee force-pushed the custom-streaming-protocol-videofix branch 2 times, most recently from f97d7f1 to bd86687 Compare April 30, 2020 19:40
@pfrazee
Copy link
Contributor Author

pfrazee commented Apr 30, 2020

Test and more docs are added. Also rebased onto master. Let's see how the builds go...

@pfrazee
Copy link
Contributor Author

pfrazee commented Apr 30, 2020

A note about the test: I found that very small videos will play correctly even without the fix in this PR. The included video is the smallest I could find which still triggers the behavior (63kb)

@pfrazee pfrazee force-pushed the custom-streaming-protocol-videofix branch from bd86687 to 654ca9d Compare May 7, 2020 16:24
@pfrazee
Copy link
Contributor Author

pfrazee commented May 7, 2020

Pushed an update as requested, questions remaining on 2 items

@pfrazee pfrazee force-pushed the custom-streaming-protocol-videofix branch from 654ca9d to c0c20ec Compare May 8, 2020 21:11
@pfrazee
Copy link
Contributor Author

pfrazee commented May 8, 2020

Pushed an update (hopefully) resolving issues

Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor changes to the patch. Otherwise LGTM! That webm generator is pretty nifty.

@pfrazee pfrazee force-pushed the custom-streaming-protocol-videofix branch from c0c20ec to e68e3c8 Compare May 11, 2020 21:52
@pfrazee
Copy link
Contributor Author

pfrazee commented Jun 5, 2020

Hey I hope yall don't mind the bump, just wanted to see if we can get this merged!

@nornagon
Copy link
Member

nornagon commented Jun 5, 2020

@pfrazee looks like there are merge conflicts, would you mind resolving them?

@pfrazee
Copy link
Contributor Author

pfrazee commented Jun 5, 2020

Sure thing

@pfrazee pfrazee force-pushed the custom-streaming-protocol-videofix branch from 69a2e97 to 8a5e184 Compare June 5, 2020 17:35
@pfrazee
Copy link
Contributor Author

pfrazee commented Jun 5, 2020

Okay still waiting on the tests but I think the conflicts are all set

@pfrazee
Copy link
Contributor Author

pfrazee commented Jun 6, 2020

Ugh why are the builds failing now. Testing locally.

@pfrazee pfrazee force-pushed the custom-streaming-protocol-videofix branch from 8a5e184 to 4120d63 Compare June 6, 2020 15:34
@pfrazee
Copy link
Contributor Author

pfrazee commented Jun 6, 2020

Appveyor is failing with

ERROR at //electron/shell/renderer/renderer_client_base.cc:23:11: Can't include this header from here.
#include "media/blink/multibuffer_data_source.h"
          ^------------------------------------
The target:
  //electron:electron_lib
is including a file from the target:
  //media/blink:blink
It's usually best to depend directly on the destination target.

But my build does not. Trying to diagnose...

@pfrazee
Copy link
Contributor Author

pfrazee commented Jun 6, 2020

Okay I can't sort out why online builds are failing over this but not in my local env. I hate to punt but do yall have any pointers on why this might be happening?

@deepak1556
Copy link
Member

@pfrazee for linux and mac we have that failing step you see on appveyor as a separate pipeline which also fails linux-x64-testing-gn-check

The check thats failing is basically https://gn.googlesource.com/gn/+/master/docs/reference.md#cmd_check which is to validate that included headers match the build dependency graph and makes sure that appropriate targets are being built. Its a pre-build sanity check.

If you look at the full output, it reads

ERROR at //electron/shell/renderer/renderer_client_base.cc:23:11: Can't include this header from here.
#include "media/blink/multibuffer_data_source.h"
          ^------------------------------------
The target:
  //electron:electron_lib
is including a file from the target:
  //media/blink:blink

It's usually best to depend directly on the destination target.
In some cases, the destination target is considered a subcomponent
of an intermediate target. In this case, the intermediate target
should depend publicly on the destination to forward the ability
to include headers.

Dependency chain (there may also be others):
  //electron:electron_lib -->
  //content/public/app:app --[private]-->
  //content/public/renderer:renderer_sources --[private]-->
  //content/renderer:renderer --[private]-->
  //media/blink:blink

//media/blink:blink is built via a transitive private dependency, and you are trying to depend on a header from that target directly, its always possible that one of the transitive targets can remove this dependency at some point, at which your compilation is gonna fail. In this case, the fix is add //media/blink:blink to deps of //electron:electron_lib. Ofcourse these errors will always be caught during link step, thats why I said its a pre-build sanity check which is quite useful on a target with nearly 30000 sources.

@pfrazee pfrazee force-pushed the custom-streaming-protocol-videofix branch from 4120d63 to b0234b4 Compare June 6, 2020 22:57
@pfrazee
Copy link
Contributor Author

pfrazee commented Jun 6, 2020

@deepak1556 I guess you could say I was in the deps of despair. Appreciate the explanation. I'll look a little more closely next time -- if I had noticed which command that was failing, I might have been able to trace the meaning of the error.

Just pushed again, I'll ping if we're all-clear.

@pfrazee
Copy link
Contributor Author

pfrazee commented Jun 7, 2020

Appears one (presumably unrelated) test in windows failed due to a timeout. Otherwise all clear.

@nornagon nornagon merged commit c6c022d into electron:master Jun 8, 2020
@release-clerk
Copy link

release-clerk bot commented Jun 8, 2020

Release Notes Persisted

Added {stream:} option to registerSchemeAsPrivileged to enable custom protocols to stream video and audio

@nornagon nornagon removed the wip ⚒ label Jun 8, 2020
@pfrazee
Copy link
Contributor Author

pfrazee commented Jun 8, 2020

🎉 Thanks again for all the help with this PR

@obsius
Copy link

obsius commented Jun 9, 2020

I recently ran into this issue on Friday, and what lucky timing with this PR. Now that this code is merged, will it be in the next bugfix release of 9, or will this be scheduled for a later release?

@nornagon
Copy link
Member

nornagon commented Jun 9, 2020

This PR has not been targeted to be backported to any previous version, so with no further action it will be available in v11.

This is a new feature, so backporting it to an old version would mean bumping the minor version and require approval from the Releases WG. See https://github.com/electron/governance/tree/master/wg-releases#feature-backport-requests for more details on the process for requesting feature backports.

@pfrazee
Copy link
Contributor Author

pfrazee commented Jun 16, 2020

Sorry to be a pest but this didn't make it into today's 10 beta.3, what's the plan? Is it just in the backlog?

@pfrazee
Copy link
Contributor Author

pfrazee commented Jun 16, 2020

Oh man I'm so sorry, I must have had a cached page or something because I didn't see @nornagon's reponse. I hate being a pest on merges to begin with so now I really feel bad 😅 See you in v11!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants