Skip to content

Commit

Permalink
feat: Add getFetchedPlaybackInfo method (#7074)
Browse files Browse the repository at this point in the history
Related to #6825
  • Loading branch information
avelad authored Jul 20, 2024
1 parent 8e13e91 commit ef02763
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
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

0 comments on commit ef02763

Please sign in to comment.