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

Allow for other media sources and destinations (i.e encapsulate MSE concerns into buffer controller only) #60

Merged
merged 12 commits into from Nov 20, 2015

Conversation

tchakabam
Copy link
Collaborator

OK so this is my first PR on the project, it might not be a great fix or a big improvement, but its a start. Some things we need to get straight first from my perspective ..

There are several concerns:

  1. It should not only be for video element but any HTML5 Media DOM, so also audio. That would work in principle, but I needed to change the name of functions and attributes still. Will add audio-only stream to tests asap.
  2. All the MSE concerns should be encapsulated imho. There should be a sane seperation between what is HLS client (downloading, and buffering data) and what is further down the line: demuxing and playing the data "somehow" (MSE is only one option).
  3. We would want to use something else maybe to process the data further, so optionally one could inject another BufferController than the default one. That could be for example something that works like a Node stream and represents some processing pipeline (which could be terminated or not by MSE or something else).

It would be great if hls.js could extend to these architectural ideas and not narrowing down to one API (MSE) but have "one input many outputs".

Then I hope in the future I can also contribute "real features" ;)

…cerns into MSE-specialized buffer-controller 3. Renames functions and attribute names from video to media (as it can also be audio DOM elements used)
@tchakabam
Copy link
Collaborator Author

@mangui Would be great if you could check this out whenever you find time :)

@mangui
Copy link
Member

mangui commented Nov 11, 2015

@tchakabam
regarding 1, I understand that we can use MSE for HTML audio and video, thus for sake of clarity we can rename all video related stuff to media
s/attachVideo/attachMedia .... in most cases s/video/media ...

regarding 2, that would bring a bunch of refactoring. could you elaborate with another use case ?
also in that case you should remove MSE_ATTACHED/MSE_DETACHED, and you should introduce MEDIA_ATTACHING/MEDIA_ATTACHED and MEDIA_DETACHING/MEDIA_DETACHED event
*ING events being fired by src/hls.js, *ED events being fired by *buffer_controller.js

@tchakabam
Copy link
Collaborator Author

@mangui On certain platforms, MSE might not be the (only / available) way to decode a stream. We might use WebAudio or other means as well. That's why I'd like to be able to get the HLS payload with a client independent of the media sink :)

That'll also enable to integrate it with open JS codecs implementations (where we will play stuff onto a canvas / web audio sink eventually but MSE is not involved).

Also you might just want to download HLS data without actually playing it, just for means of prefetching or offline synchronization.

It makes sense to decouple the concerns here.

Furthermore architecturally, I think it would make more sense to chain the elements in a stream-like way.
That said, the HLS client (it's TS or elementary stream output) should be a readable stream that would feed a writable stream that is the MP4 remuxer (but only if needed) and that could be then fed into any sink (MSE or software decoders + WebGL/WebAudio) depending on the nature of the stream and the capabilities of the device you d have to build a different pipeline.

HLS is a protocol that provides data to a player, lets not make the implementation dependent what technology the player is using to play that data :)

@tchakabam
Copy link
Collaborator Author

And not to be forgotten: custom encryption modes, custom integration with DRM services and/or EME (Encrypted Media Extensions), where you will want to take the media payload and write your own coupling around these APIs (EME & MSE) or something custom. It could even be fed into Flash - essentially the great thing here is to have a transport implementation of HLS in JavaScript and to be able to leverage it onto any existing or future playback technology.

@mangui
Copy link
Member

mangui commented Nov 12, 2015

understood @tchakabam
it is true that MSE concern can easily be moved to buffer-controller.js, hence moving this file to a mse subfolder would make sense
also to keep events generic, we could

  • s/MSE_ATTACHED/MEDIA_ATTACHED
  • s/MSE_DETACHED/MEDIA_DETACHED
  • s/MSE_DETACHING/MEDIA_DETACHING
  • introduce a new event MEDIA_ATTACHING, that would be dispatched by src/hls.js on hls.attachMedia(). this new event would be listened by mse/buffer-controller. upon MEDIA_ATTACHING, mse/buffer-controller would instantiate the MSE related stuff (thus we can remove the MediaSource stuff from src/hls.js to mse/buffer-controller)

you can remove SOURCE_ATTACHED/SOURCE_DETACHED

the doc (API ...) should be updated as well to reflect those changes

@tchakabam
Copy link
Collaborator Author

OK cool 👍

I know its a bit of a refactoring but on the long run I think it makes a lot of sense. There was already the "StreamBufferController" on the branch I was working on but I removed it for now because it's still in development and it would make this PR a mess. But I will push this soon when we have merged this, and you'll see what the idea was :) Anyway its already possible to substitute the "standard" MSEBufferController by an own implementation by passing it in the config now. But I refrained from putting the latter class in an own directory for now since its the only actual implementation of this component at this day.

Ideally i think it also needs only one implementation, but it could be decoupled from MSE and simply push data to downstream components like the demuxer and decoder, eventually the sink will be MSE. That should also make it simpler to use different demuxers, like integrating with mux.js or other stuff for example if it would be necessary.

Looks good from your side with the latest changes now?

@@ -35,6 +35,7 @@
},
"dependencies": {
"babelify": "^6.1.2",
"stream-browserify": "^2.0.1",
Copy link
Member

Choose a reason for hiding this comment

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

not needed ?

@mangui
Copy link
Member

mangui commented Nov 17, 2015

yes @tchakabam , looks good !
could you rebase your PR and remove the dependency on stream-browserify (any reason to include it?). so that i could merge

@tchakabam
Copy link
Collaborator Author

@mangui OK done.

reason why i had stream-browserify in there is that this is what I use to implement another BufferController that will expose a Stream.Readable from which we can pipe the media data to wherever.

@mangui
Copy link
Member

mangui commented Nov 17, 2015

there are still some reference to attachMediaElement/detachMediaElement
it should be attachMedia/detachMedia

@tchakabam
Copy link
Collaborator Author

k should be good now ;)

@@ -96,49 +97,21 @@ class Hls {
this.bufferController.destroy();
//this.fpsController.destroy();
this.url = null;
this.detachVideo();
this.detachMediaElement();
Copy link
Member

Choose a reason for hiding this comment

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

are you sure ? 😄

@mangui
Copy link
Member

mangui commented Nov 18, 2015

perfect, will test and merge tomorrow.
just one thing, finally IMHO bufferController would be better named as MediaController ...
as it is reacting to MEDIA__TACH_ events
in that case mse/MediaController
you can rename the file if you want, or i will do it later on after merging this PR

@tchakabam
Copy link
Collaborator Author

@mangui I think that makes perfect sense as a name! but i'll let you do the renaming now ;)

@tchakabam
Copy link
Collaborator Author

🍻

@mangui
Copy link
Member

mangui commented Nov 19, 2015

will check tomorrow finally

@mangui mangui merged commit a3ef212 into video-dev:master Nov 20, 2015
johnBartos pushed a commit that referenced this pull request Jun 27, 2018
Fix exception thrown from log when start pos is not immediately known
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants