Skip to content

Commit

Permalink
Work-in-progress: Refine srcObject's MediaSourceHandle behavior
Browse files Browse the repository at this point in the history
Adds text intending to help prevent using one or more
`MediaSourceHandle` for the same underlying `MediaSource` for
simultaneous, concurrent attachments to media elements:

* Updates `MediaSource.getHandle()` to succeed at most once per
  `MediaSource` instance.
* Updates `MediaSourceHandle` transfer section to more clearly indicate
  that transferring a handle out of a context makes that handle
  unavailable for transferring again out of the same context (unless it
  is first transferred back to that context).
* Updates the "attaching to a media element" text to indicate that a
  `MediaSourceHandle` can be attached successfully to at most one media
  element at a time, and with the previous 2 clarifications, ensures
  that the underlying worker context `MediaSource` can only be attached
  successfully to at most one media element at a time.

Note that legacy MSE object URL attachments similarly already achieve
the same intent in existing implementations. The switch to more clear
`srcObject` usage for worker MSE attachment affords the spec an
opportunity to be more clear about this intent.

This refinement originates from discussion on the previous PR with
@karlt: w3c#305
  • Loading branch information
wolenetz committed Mar 30, 2022
1 parent 89bd50e commit 2f7a316
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion media-source-respec.html
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ <h2><dfn>MediaSource</dfn> Object</h2>
<a href="#htmlmediaelement-extensions">HTMLMediaElement Extensions</a> to modify
{{HTMLMediaElement}}.{{HTMLMediaElement/seekable}} behavior.</p>

<p>Each {{MediaSource}} object has a <dfn data-dfn-for="MediaSource">[[\handle already retrieved]]</dfn> internal
slot that is a boolean that keeps track of whether {{MediaSource/getHandle()}} has already created and returned
a {{MediaSourceHandle}} object for the {{MediaSource}} object. It is initialized to false when the
{{MediaSource}} object is created, and is consulted and updated by {{MediaSource/getHandle()}} to prevent
creating multiple distinct {{MediaSourceHandle}} objects for by same {{MediaSource}} object.</p>

<div><pre class="idl">enum ReadyState {
"closed",
"open",
Expand Down Expand Up @@ -650,7 +656,19 @@ <h3>Attributes</h3>
<p class="issue">Consider requiring conforming implementations to let such handle be created on a {{Window}}
{{MediaSource}} object, too?</p>
</li>
<li>Create a new {{MediaSourceHandle}} object and associated resources.</li>
<li>If the {{MediaSource/readyState}} attribute is not {{ReadyState/""closed""}} then throw an
{{InvalidStateError}} exception and abort these steps.</li>
<li>If {{MediaSource/[[handle already retrieved]]}} is true, then throw an {{InvalidStateError}} exception and
abort these steps.</li>
<li>Create a new {{MediaSourceHandle}} object and associated resources, and link it internally to this
{{MediaSource}}.</li>
<li>Set {{MediaSource/[[handle already retrieved]]}} to be true.
<p class="note">This will prevent creation of multiple {{MediaSourceHandle}} objects for this
{{MediaSource}} object, to help prevent this {{MediaSource}} from being attached using distinct handles
simultaneously to distinct media elements. Legacy object URL attachments allow distinct object URLs for
the same {{MediaSource}} object, though simultaneous attachment of the same {{MediaSource}} via those
distinct object URLs to distinct media elements should also succeed for at most one media element.</p>
</li>
<li>Return the new object.</li>
</ol>
<div><em>No parameters.</em></div><div><em>Return type: </em>{{MediaSourceHandle}}</div></dd>
Expand Down Expand Up @@ -770,6 +788,7 @@ <h4><dfn>Attaching to a media element</dfn></h4>
object mentioned there, and the {{MediaSourceHandle}} object is the media provider object.
<p class="issue">MediaSourceHandle needs to be added to HTMLMediaElement's MediaProvider IDL typedef and
related text involving media provider objects.</p>
BIG TODO: add text around preventing using the handle simultaneously for for than one media element.
</li>
</ul>

Expand Down Expand Up @@ -1169,6 +1188,12 @@ <h2><dfn>MediaSourceHandle</dfn> Object</h2>
maintain an implicit internal slot referencing the underlying {{MediaSource}} to enable [=attaching to a media
element=] using {{HTMLMediaElement/srcObject}} and consequent setup of an attachment's [=cross-context
communication model=].

Once transferred out of a context, the handle MUST no longer be usable in that context.
<p class="note">For example, once a worker transfers a {{MediaSourceHandle}} to another context, it cannot
transfer that handle again unless the another context first transfers it back to the worker. This prevents
ability to clone {{MediaSourceHandle}} objects and helps prevent simultaneous attachment to distinct media
elements using handles to the same underlying {{MediaSource}}.</p>
</section>
</section>

Expand Down

0 comments on commit 2f7a316

Please sign in to comment.