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

feat: Add getFetchedPlaybackInfo method #7074

Merged
merged 1 commit into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,38 @@ shaka.extern.MetadataRawFrame;
shaka.extern.MetadataFrame;


/**
* @typedef {{
* video: ?shaka.extern.PlaybackStreamInfo,
* audio: ?shaka.extern.PlaybackStreamInfo,
* text: ?shaka.extern.PlaybackStreamInfo
* }}
*
* @description Represents the state of the current variant and text.
* @property {?shaka.extern.PlaybackStreamInfo} video
* @property {?shaka.extern.PlaybackStreamInfo} audio
* @property {?shaka.extern.PlaybackStreamInfo} text
* @exportDoc
*/
shaka.extern.PlaybackInfo;


/**
* @typedef {{
* codecs: string,
* mimeType: string,
* bandwidth: number
* }}
*
* @description Represents the state of the given stream.
* @property {string} codecs
* @property {string} mimeType
* @property {number} bandwidth
* @exportDoc
*/
shaka.extern.PlaybackStreamInfo;


/**
* @typedef {{
* startTime: number,
Expand Down
42 changes: 42 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -6227,6 +6227,48 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
return this.parserFactory_;
}

/**
* Gets information about the currently fetched video, audio, and text.
* In the case of a multi-codec or multi-mimeType manifest, this can let you
* determine the exact codecs and mimeTypes being fetched at the moment.
*
* @return {!shaka.extern.PlaybackInfo}
*/
getFetchedPlaybackInfo() {
const output = /** @type {!shaka.extern.PlaybackInfo} */ ({
'video': null,
'audio': null,
'text': null,
});
if (this.loadMode_ != shaka.Player.LoadMode.MEDIA_SOURCE) {
return output;
}
const ContentType = shaka.util.ManifestParserUtils.ContentType;
const variant = this.streamingEngine_.getCurrentVariant();
const textStream = this.streamingEngine_.getCurrentTextStream();
const currentTime = this.video_.currentTime;
for (const stream of [variant.video, variant.audio, textStream]) {
if (!stream || !stream.segmentIndex) {
continue;
}
const position = stream.segmentIndex.find(currentTime);
const reference = stream.segmentIndex.get(position);
const info = /** @type {!shaka.extern.PlaybackStreamInfo} */ ({
'codecs': reference.codecs || stream.codecs,
'mimeType': reference.mimeType || stream.mimeType,
'bandwidth': stream.bandwidth,
});
if (stream.type == ContentType.VIDEO) {
output['video'] = info;
} else if (stream.type == ContentType.AUDIO) {
output['audio'] = info;
} else if (stream.type == ContentType.TEXT) {
output['text'] = info;
}
}
return output;
}

/**
* @param {shaka.extern.Variant} variant
* @param {boolean} fromAdaptation
Expand Down
1 change: 1 addition & 0 deletions test/cast/cast_utils_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('CastUtils', () => {
'destroyAllPreloads',
'getNonDefaultConfiguration',
'addFont',
'getFetchedPlaybackInfo',

// Test helper methods (not @export'd)
'createDrmEngine',
Expand Down
Loading