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

[Story video] Add cached sources with different qualities to amp-video #32337

Closed
mszylkowski opened this issue Feb 1, 2021 · 0 comments · Fixed by #32366
Closed

[Story video] Add cached sources with different qualities to amp-video #32337

mszylkowski opened this issue Feb 1, 2021 · 0 comments · Fixed by #32366

Comments

@mszylkowski
Copy link
Contributor

mszylkowski commented Feb 1, 2021

Create sources with different bitrates for amp-video cached sources.

<amp-video>
  <source src="cache?amp_quality=high" data-bitrate="hardcoded_value">
  <source src="cache?amp_quality=medium" data-bitrate="hardcoded_value">
  <source src="cache?amp_quality=low" data-bitrate="hardcoded_value">
  <source src="origin">
</amp-video>

Pointers:

propagateCachedSources_() {
devAssert(this.video_);
const sources = toArray(childElementsByTag(this.element, 'source'));
// if the `src` of `amp-video` itself is cached, move it to <source>
if (this.element.hasAttribute('src') && this.isCachedByCDN_(this.element)) {
const src = this.element.getAttribute('src');
const type = this.element.getAttribute('type');
const srcSource = this.createSourceElement_(src, type);
const ampOrigSrc = this.element.getAttribute('amp-orig-src');
srcSource.setAttribute('amp-orig-src', ampOrigSrc);
// Also make sure src is removed from amp-video since Stories media-pool

/**
* AMP Cache may selectively cache certain video sources (based on various
* heuristics such as video type, extensions, etc...).
* When AMP Cache does so, it rewrites the `src` for `amp-video` and
* `source` children that are cached and adds a `amp-orig-src` attribute
* pointing to the original source.
*
* There are two separate runtime concerns that we handle here:
*
* 1) Handling 404s
* Eventhough AMP Cache rewrites the `src` to point to the CDN, the actual
* video may not be ready in the cache yet, in those cases the CDN will
* return a 404.
* AMP Cache also rewrites Urls for all sources and returns 404 for types
* that are not supported to be cached.
*
* Runtime handles this situation by appending an additional
* <source> pointing to the original src AFTER the cached source so browser
* will automatically proceed to the next source if one fails.
* Original sources are added only when page becomes visible and not during
* prerender mode.
*
* 2) Prerendering
* Now that some sources might be cached, we can preload them during prerender
* phase. Runtime handles this by adding any cached sources to the <video>
* element during prerender and automatically sets the `preload` to `auto`
* so browsers (based on their own heuristics) can start fetching the cached
* videos. If `preload` is specified by the author, then it takes precedence.
*
* Note that this flag does not impact prerendering of the `poster` as poster
* is fetched (and is always cached) during `buildCallback` which is not
* dependent on the value of `prerenderAllowed()`.
*
* @override
*/

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

Successfully merging a pull request may close this issue.

1 participant