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

MSE-in-Workers: Consider (eventually) transitioning attached element to error upon termination of MediaSource's worker/what should media element do? #277

Open
wolenetz opened this issue Jun 17, 2021 · 4 comments
Assignees
Labels
TPAC2024 Topic for discussion at TPAC 2024
Milestone

Comments

@wolenetz
Copy link
Member

MSE-in-Workers feature issue is #175

This issue tracks discussing whether or not the HTMLMediaElement should do any error transition upon the termination of the DedicatedWorkerGlobalScope that owns the attached MediaSource.

The Chromium experimental implementation just leaves the element's readyState, networkState and error attributes as they were prior to the termination, and simply forces the element's seekable and buffered attributes to each return an empty TimeRange. This is sufficient to prevent unexpected playback of a resource that is no longer available. Note that the termination of the worker is typically caused either by worker.terminate() or DedicatedWorkerGlobalScope.close() from the application side, or as part of teardown of the dedicated workers owned by a Window that is terminating.

There may be important edge cases where the app may not know the MediaSource's worker scope is terminated, when it needs to. Hence this issue to discuss and see if an explicit error transition on the element would be useful in this case.

Note that such error transition might not occur until sometime after the termination of the worker has completed, since the termination steps are run in parallel with whatever is running on the element's context, so there will still be a window of time where the app might get empty buffered or seekable TimeRanges and not immediately know why, even if there were some eventual error transition of the element later due to the worker's termination.

@wolenetz
Copy link
Member Author

Note, this corresponds to the discussion on the feature issue (#175) beginning at #175 (comment) -- specifically, this issue tracks the first question:

If the DedicatedWorker MediaSource's context is terminated (e.g. worker.terminate()), then the main thread element still remains connected, but seekable and buffered range information reset. There is no other immediate error exposed to the main-thread media element. Would you prefer other behavior in this scenario?

@wolenetz wolenetz changed the title MSE-in-Workers: Consider transitioning attached element to error upon termination of MediaSource's worker MSE-in-Workers: Consider (eventually) transitioning attached element to error upon termination of MediaSource's worker Jun 17, 2021
wolenetz added a commit to wolenetz/media-source that referenced this issue Jun 17, 2021
wolenetz added a commit to wolenetz/media-source that referenced this issue Jun 18, 2021
wolenetz added a commit to wolenetz/media-source that referenced this issue Jun 30, 2021
wolenetz added a commit to wolenetz/media-source that referenced this issue Jun 30, 2021
wolenetz added a commit to wolenetz/media-source that referenced this issue Jul 26, 2021
Specifies expansion of MSE API to usage from DedicatedWorker contexts.

This is an MSEv2 feature tracked by issue w3c#175.

See also earlier WICG explainer [1].

This is a squashed commit of 23 original commits, notably:
* Adds `closing` issue and link to w3c#276.
* Adds the `github:` respecConfig key and an issues-summary appendix.
* Removes redundant 'Repository' otherLinks config (addition of 'github'
  to respecConfig has make the manual enumeration in the 'Repository'
  otherLinks portion of respecConfig redundant.)
* Adds subsections for each of the extended HTMLMediaElement's .seekable
  and .buffered attributes.
* Adds more normative detail to the .buffered extension.
* Specifies what .seekable and .buffered do when worker has terminated,
  and references w3c#277 for further discussion.
* Describes cross-context track object aliasing. AudioTrack, VideoTrack,
  TextTrack extensions' sourceBuffer attribute must be null in the
  Window context's alias of the track if the track is an alias to a
  worker-created track from MSE-in-Worker. This is to prevent any
  assumption that cross-context object references are somehow now
  allowed in MSE or HTMLMediaElement+MSE.
* Describes a MessageChannel-based cross-context communication mechanism
  in a new section, including how MessagePorts on that channel are given
  to each side (media element, MediaSource) for communicating state
  needed by algorithms. Updates multiple algorithms and methods to use
  this mechanism where necessary. Resolves w3c#279.
* Specifies how to detect this feature using new
  `canConstructInDedicatedWorker` attribute without requiring the
  detection happening in a DedicatedWorker context.
* Modernizes to use respec's new variable syntax (`|...|` with types
  inlined)) for related lines. Wider modernization is an editorial item
  that is out of scope of this feature.
* Modernizes to use internal slots for the new cross-context
  communication mechanism's channel and ports. Wider modernization is an
  editorial item out of scope of this feature.o

Note, multiple simultaneous changes to track's `selected`, `enabled` or
`hidden`/`showing` states could be in-flight from window to worker, and
from worker to window. A non-normative note might be good to add here to
warn API users of this possibility. See w3c#278.

Note, {Audio,Video,Track}{,List} IDL need to be exposed in
DedicatedWorker. This might need to be directly in the media element
spec. See w3c#280.

Note, a reference to an MSE-in-Worker example/demo would be good in
the merged PR. Such a demo exists already at [2].
[1] https://github.com/wicg/media-source/blob/mse-in-workers-using-handle/mse-in-workers-using-handle-explainer.md
[2] https://wolenetz.github.io/mse-in-workers-demo/mse-in-workers-demo.html
wolenetz added a commit that referenced this issue Aug 31, 2021
Specifies expansion of MSE API to usage from DedicatedWorker contexts.

This is an MSEv2 feature tracked by issue #175.

See also earlier WICG explainer [1].

This is a squashed commit of 23 original commits, notably:
* Adds `closing` issue and link to #276.
* Adds the `github:` respecConfig key and an issues-summary appendix.
* Removes redundant 'Repository' otherLinks config (addition of 'github'
  to respecConfig has make the manual enumeration in the 'Repository'
  otherLinks portion of respecConfig redundant.)
* Adds subsections for each of the extended HTMLMediaElement's .seekable
  and .buffered attributes.
* Adds more normative detail to the .buffered extension.
* Specifies what .seekable and .buffered do when worker has terminated,
  and references #277 for further discussion.
* Describes cross-context track object aliasing. AudioTrack, VideoTrack,
  TextTrack extensions' sourceBuffer attribute must be null in the
  Window context's alias of the track if the track is an alias to a
  worker-created track from MSE-in-Worker. This is to prevent any
  assumption that cross-context object references are somehow now
  allowed in MSE or HTMLMediaElement+MSE.
* Describes a MessageChannel-based cross-context communication mechanism
  in a new section, including how MessagePorts on that channel are given
  to each side (media element, MediaSource) for communicating state
  needed by algorithms. Updates multiple algorithms and methods to use
  this mechanism where necessary. Resolves #279.
* Specifies how to detect this feature using new
  `canConstructInDedicatedWorker` attribute without requiring the
  detection happening in a DedicatedWorker context.
* Modernizes to use respec's new variable syntax (`|...|` with types
  inlined)) for related lines. Wider modernization is an editorial item
  that is out of scope of this feature.
* Modernizes to use internal slots for the new cross-context
  communication mechanism's channel and ports. Wider modernization is an
  editorial item out of scope of this feature.o

Note, multiple simultaneous changes to track's `selected`, `enabled` or
`hidden`/`showing` states could be in-flight from window to worker, and
from worker to window. A non-normative note might be good to add here to
warn API users of this possibility. See #278.

Note, {Audio,Video,Track}{,List} IDL need to be exposed in
DedicatedWorker. This might need to be directly in the media element
spec. See #280.

There were some still unresolved cosmetic comments on this PR during
later portion of review that I'll follow-up on in a later PR.

Note, a reference to an MSE-in-Worker example/demo would be good in
the merged PR. Such a demo exists already at [2].
[1] https://github.com/wicg/media-source/blob/mse-in-workers-using-handle/mse-in-workers-using-handle-explainer.md
[2] https://wolenetz.github.io/mse-in-workers-demo/mse-in-workers-demo.html
@wolenetz wolenetz changed the title MSE-in-Workers: Consider (eventually) transitioning attached element to error upon termination of MediaSource's worker MSE-in-Workers: Consider (eventually) transitioning attached element to error upon termination of MediaSource's worker/what should media element do? Sep 3, 2021
@wolenetz
Copy link
Member Author

wolenetz commented Sep 3, 2021

Due to mitigating security issues related to over-optimized cross-context communication in the Chromium experimental implementation, it will soon instead cache a recent value of each of seekable and buffered.

Edited: This doesn't fully enable the media element to continue to operate on previously buffered state after the attached MediaSource's execution context has been terminated: the experimental Chromium implementation of this removes the underlying track buffers associated with each SourceBuffer of a MSE-in-Worker whose worker context has destructed while still attached to a not-yet-destructed media element and media element's context is still alive. As such, even though the mitigation caches seekable and buffered, it will still respond with empty ranges if the worker's context has been destroyed.

The question remains:

  • Give some error eventually to the media element (if it's still considering itself attached to the objectUrl of the MediaSource that was attached but whose context has been destroyed)?
  • Or retain the underlying track_buffers of such a MediaSource (and continue to report the cached seekable and buffered values) until detachment?
  • Or continue with the approach of the current experimental Chromium implementation (silently report nothing buffered nor seekable once worker context is gone)?

@wolenetz wolenetz self-assigned this Sep 3, 2021
@wolenetz wolenetz added this to the V2 milestone Sep 3, 2021
@wolenetz wolenetz added the agenda Topic should be discussed in a group call label Sep 3, 2021
@wolenetz
Copy link
Member Author

wolenetz commented Sep 3, 2021

Requesting this be discussed at Sept 14 Media WG meeting.

@dalecurtis dalecurtis modified the milestones: V3, V2 Mar 14, 2023
@chrisn
Copy link
Member

chrisn commented Apr 5, 2023

Minutes from 14 Sep 2021 meeting: https://www.w3.org/2021/09/14-mediawg-minutes.html#t05

@chrisn chrisn removed the agenda Topic should be discussed in a group call label Apr 5, 2023
@chrisn chrisn added the TPAC2024 Topic for discussion at TPAC 2024 label Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TPAC2024 Topic for discussion at TPAC 2024
Projects
None yet
Development

No branches or pull requests

3 participants