mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-17 16:26:39 +03:00
64896d70b0
This reflects changes in Google's policy on JavaScript license headers, which should be smaller to avoid increasing the size of the binary unnecessarily. This also updates the company name from "Google, Inc" to "Google LLC". Change-Id: I3f8b9ed3700b6351f43173d50c94d35c333e82b4
112 lines
2.8 KiB
JavaScript
112 lines
2.8 KiB
JavaScript
/** @license
|
|
* Copyright 2016 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
goog.provide('shaka.media.ActiveStreamMap');
|
|
|
|
|
|
/**
|
|
* A structure used to track which streams were last used in any given period.
|
|
*
|
|
* @final
|
|
*/
|
|
shaka.media.ActiveStreamMap = class {
|
|
constructor() {
|
|
/**
|
|
* A mapping between a period and the content last streamed in that period.
|
|
*
|
|
* @private {!Map.<shaka.extern.Period, !shaka.media.ActiveStreamMap.Frame>}
|
|
*/
|
|
this.history_ = new Map();
|
|
}
|
|
|
|
/**
|
|
* Clear the history.
|
|
*/
|
|
clear() {
|
|
// Clear the map to release references to the periods (the key). This
|
|
// assumes that the references will be broken by doing this.
|
|
this.history_.clear();
|
|
}
|
|
|
|
/**
|
|
* Set the variant that was last playing in |period|. Setting it to |null| is
|
|
* the same as saying "we were playing no variant in this period".
|
|
*
|
|
* @param {shaka.extern.Period} period
|
|
* @param {?shaka.extern.Variant} variant
|
|
*/
|
|
useVariant(period, variant) {
|
|
this.getFrameFor_(period).variant = variant;
|
|
}
|
|
|
|
/**
|
|
* Set the text stream that was last displayed in |period|. Setting it to
|
|
* |null| is the same as saying "we were displaying no text in this period".
|
|
*
|
|
* @param {shaka.extern.Period} period
|
|
* @param {?shaka.extern.Stream} stream
|
|
*/
|
|
useText(period, stream) {
|
|
this.getFrameFor_(period).text = stream;
|
|
}
|
|
|
|
/**
|
|
* Get the variant that was playing in the given period. If no variant was
|
|
* playing this period or the period had not started playing, then |null| will
|
|
* be returned.
|
|
*
|
|
* @param {shaka.extern.Period} period
|
|
* @return {?shaka.extern.Variant}
|
|
*/
|
|
getVariant(period) {
|
|
return this.getFrameFor_(period).variant;
|
|
}
|
|
|
|
/**
|
|
* Get the text stream that was playing in the given period. If no text
|
|
* stream was playing this period or the period had not started playing, then
|
|
* |null| will be returned.
|
|
*
|
|
* @param {shaka.extern.Period} period
|
|
* @return {?shaka.extern.Stream}
|
|
*/
|
|
getText(period) {
|
|
return this.getFrameFor_(period).text;
|
|
}
|
|
|
|
/**
|
|
* Get the frame for a period. This will ensure that a frame exists for the
|
|
* given period.
|
|
*
|
|
* @param {shaka.extern.Period} period
|
|
* @return {!shaka.media.ActiveStreamMap.Frame}
|
|
* @private
|
|
*/
|
|
getFrameFor_(period) {
|
|
if (!this.history_.has(period)) {
|
|
const frame = new shaka.media.ActiveStreamMap.Frame();
|
|
this.history_.set(period, frame);
|
|
}
|
|
|
|
return this.history_.get(period);
|
|
}
|
|
};
|
|
|
|
|
|
/**
|
|
* A structure used to track which streams were played during a specific
|
|
* time frame.
|
|
*
|
|
* @final
|
|
*/
|
|
shaka.media.ActiveStreamMap.Frame = class {
|
|
constructor() {
|
|
/** @type {?shaka.extern.Variant} */
|
|
this.variant = null;
|
|
/** @type {?shaka.extern.Stream} */
|
|
this.text = null;
|
|
}
|
|
};
|