Skip to content

Commit

Permalink
Small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
noamr committed Feb 28, 2022
1 parent 9578f54 commit 988d99e
Showing 1 changed file with 55 additions and 33 deletions.
88 changes: 55 additions & 33 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -2492,6 +2492,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li><dfn data-x-href="https://fetch.spec.whatwg.org/#finalize-and-report-timing">finalize and report timing</dfn></li>
<li><dfn data-x="serialize-a-response-url-for-reporting" data-x-href="https://fetch.spec.whatwg.org/#serialize-a-response-url-for-reporting">serialize a response URL for reporting</dfn></li>
<li><dfn data-x="body safely extract" data-x-href="https://fetch.spec.whatwg.org/#bodyinit-safely-extract">safely extracting a body</dfn></li>
<li><dfn data-x="body-incrementally-read" data-x-href="https://fetch.spec.whatwg.org/#body-incrementally-read">incrementally reading a body</dfn></li>
<li><dfn data-x-href="https://fetch.spec.whatwg.org/#process-response-end-of-body">processResponseConsumeBody</dfn></li>
<li><dfn data-x-href="https://fetch.spec.whatwg.org/#fetch-processresponseendofbody">processResponseEndOfBody</dfn></li>
<li>
Expand Down Expand Up @@ -33679,7 +33680,7 @@ interface <dfn interface>HTMLMediaElement</dfn> : <span>HTMLElement</span> {
<p>A <span>media resource</span> has an associated
<dfn data-x="media-resource-origin">origin</dfn>, which is either "<code data-x="">none</code>",
"<code data-x="">multiple</code>", "<code data-x="">rewritten</code>", or an
<span>origin</span>.</p> It is initially set to "<code data-x="">none</code>".
<span>origin</span>. It is initially set to "<code data-x="">none</code>".</p>

<p>A <span>media resource</span> can have multiple audio and video tracks. For the purposes of a
<span>media element</span>, the video data of the <span>media resource</span> is only that of the
Expand Down Expand Up @@ -34495,13 +34496,15 @@ interface <dfn interface>MediaError</dfn> {
</ol>

<p>To <dfn>verify a media response</dfn> given a <span data-x="concept-response">response</span>
<var>response</var>, a <span>media resource</span> <var>resource</var> and a Null or
(number, Null or number) <var>optionalByteRange</var>:</p>
<var>response</var>, a <span>media resource</span> <var>resource</var> and
"<code data-x="">entire resource</code>" or (number, number or "<code data-x="">until end</code>")
<var>optionalByteRange</var>:</p>

<ol>
<li><p>If <var>response</var> is a <span>network error</span>, return false.</p></li>

<li><p>If <var>optionalByteRange</var> is null, return true.</p></li>
<li><p>If <var>optionalByteRange</var> is "<code data-x="">entire resource</code>", return
true.</p></li>

<li><p>Let <var>internalResponse</var> be <var>response</var>'s
<span>unsafe response</span>.</p></li>
Expand All @@ -34520,7 +34523,7 @@ interface <dfn interface>MediaError</dfn> {
<li>
<p>If any of the following conditions are true:</p>
<ul>
<li><var>previousOrigin</var> is "<code data-x="">none</code></li>
<li><var>previousOrigin</var> is "<code data-x="">none</code>"</li>

<li><var>origin</var> and <var>previousOrigin</var> are "<code data-x="">rewritten</code>"</li>

Expand All @@ -34541,11 +34544,12 @@ interface <dfn interface>MediaError</dfn> {
</li>

<li><p>Let (<var>start</var>, <var>end</var>) be the result of
<span data-x="extract content-range values">extracting content range</span> from
<span data-x="extract content-range values">extracting content-range values </span> from
<var>internalResponse</var>.</p></li>

<li><p>If <var>start</var> is not <var>optionalByteRange</var>[0], or if
<var>optionalByteRange</var>[1] is neither null or <var>end</var>, return false.</p></li>
<var>optionalByteRange</var>[1] is neither "<code data-x="">until end</code>" or <var>end</var>,
return false.</p></li>

<li><p>Return true.</p></li>
</ol>
Expand Down Expand Up @@ -34614,7 +34618,7 @@ interface <dfn interface>MediaError</dfn> {
</li>

<li><p>Let <var>destination</var> be "<code data-x="">audio</code>" if the <span>media
element</span> is an <code>audio</code> element and to "<code data-x="">video</code>"
element</span> is an <code>audio</code> element, or "<code data-x="">video</code>"
otherwise.</p>

<li><p>Let <var>request</var> be the result of <span
Expand All @@ -34627,11 +34631,16 @@ interface <dfn interface>MediaError</dfn> {
<span>media element</span>'s <span>node document</span>'s <span>relevant settings
object</span>.</p></li>

<li><p>Let <var>optionalByteRange</var>, which is Null or (number, Null or number) be
the byte range required to satisfy missing data in <span>media data</span>. This value is
<span>implementation-defined</span> and may rely on codec, network conditions or other
heuristics. The user-agent may determine to fetch the resource in full, in which case
<var>optionalByteRange</var> would be null.</p></li>
<li><p>Let <var>optionalByteRange</var>, which is "<code data-x="">entire resource</code>" or
(number, number or "<code data-x="">until end</code>") be the byte range required to satisfy
missing data in <span>media data</span>. This value is <span>implementation-defined</span>
and may rely on codec, network conditions or other heuristics. The user-agent may determine
to fetch the resource in full, in which case <var>optionalByteRange</var> would be
"<code data-x="">entire resource</code>", to fetch from a byte offset until the end,
in which case <var>optionalByteRange</var> would be
(number, "<code data-x="">until end</code>"), or to fetch a range between two byte offsets,
im which case <var>optionalByteRange</var> (number, number) representing the two
offsets.</p></li>

<li><p>If <var>optionalByteRange</var> is not null, then <span>add a range header</span> to
<var>request</var> given <var>optionalByteRange</var>[0] and
Expand All @@ -34641,17 +34650,45 @@ interface <dfn interface>MediaError</dfn> {
<!--FETCH--><p><span data-x="concept-fetch">Fetch</span> <var>request</var>, with
<i data-x="processResponseEndOfBody">processResponseEndOfBody</i> given
<span data-x="concept-response">response</span> set to
<span>finalize and report timing</span> with <var>response</var>,
the <span>media element</span>'s <span>node document</span>'s
<span>relevant global object</span>, and <var>destination</var>

and <i data-x="process response">processResponse</i> set to the following steps given
<span data-x="concept-response">response</span> <var>response</var>:</p>

<ol>
<li><p>Let <var>global</var> be the <span>media element</span>'s
<span>node document</span>'s <span>relevant global object</span>.</p></li>

<li><p>Let <var>updateMedia</var> be to <span>queue a media element task</span> given
the <span>media element</span> to run the first appropriate steps from the
<span>media data processing steps list</span> below. (A new task is used for
this so that the work described below occurs relative to the appropriate
<span>media element event task source</span> rather than using the
<span>networking task source</span>.)</p>

<li><p>Let <var>finalize</var> be to <span>finalize and report timing</span> with
<var>response</var>, <var>global</var>, and <var>destination</var>, and call
<var>updateMedia</var>.</p></li>

<li>
<p>Let <var>processEndOfMedia</var> be the following steps:</p>

<ol>
<li><p>Call <var>finalize</var>.</p>

<li><p>If the fetching process has completes without errors, including decoding the
media data, and if all of the data is available to the user agent without network
access, then, the user agent must move on to the <i>final step</i> below.
This might never happen, e.g. when streaming an infinite resource such as web radio, or
if the resource is longer than the user agent's ability to cache data.</p>
</ol>
</li>

<li><p>If the result of <span data-x="verify a media response">verifying</span>
<var>response</var> given the <var>current media resource</var> and
<var>optionalByteRange</var> is false, then set <var>response</var> to a new
<span>network error</span>.</p></li>
<var>optionalByteRange</var> is false, then set call <var>finalize</var>; Otherwise,
<span data-x="body-incrementally-read">incrementally read</span> <var>response</var>'s
<span data-x="concept-response-body">body</span> given <var>updateMedia</var>,
<var>processEndOfMedia</var>, <var>finalize</var>, and <var>global</var>.</p></li>

<li><p>Update <span>media data</span> with the contents of <var>response</var>'s
<span>unsafe response</span> obtained in this fashion. <var>response</var> can be
Expand Down Expand Up @@ -34718,21 +34755,6 @@ interface <dfn interface>MediaError</dfn> {
given the <span>media element</span> to <span data-x="concept-event-fire">fire an
event</span> named <code data-x="event-media-progress">progress</code> at the element.</p>

<p>The <span>networking task source</span> <span data-x="concept-task">tasks</span> to
process the data as it is being fetched must each <span>immediately</span> <span>queue a
media element task</span> given the <span>media element</span> to run the first appropriate
steps from the <span>media data processing steps list</span> below. (A new task is used for
this so that the work described below occurs relative to the appropriate <span>media element
event task source</span> rather than using the <span>networking task source</span>.)</p>

<p>When the <span>networking task source</span> has <span data-x="queue a
task">queued</span> the last <span data-x="concept-task">task</span> as part of fetching the
<span>media resource</span> (i.e. once the download has completed), if the fetching process
completes without errors, including decoding the media data, and if all of the data is available
to the user agent without network access, then, the user agent must move on to the <i>final step</i> below.
This might never happen, e.g. when streaming an infinite resource such as web radio, or if the
resource is longer than the user agent's ability to cache data.</p>

<p>While the user agent might still need network access to obtain parts of the <span>media
resource</span>, the user agent must remain on this step.</p>

Expand Down

0 comments on commit 988d99e

Please sign in to comment.