Skip to content

Commit

Permalink
feat(MSS): Add support for MediaQualityInfo events
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Jun 27, 2024
1 parent 8825af7 commit 0d80bc3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
24 changes: 24 additions & 0 deletions lib/media/quality_observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,30 @@ shaka.media.QualityObserver = class extends shaka.util.FakeEventTarget {
contentTypeState.qualityChangePositions = [];
}
}

/**
* Create a MediaQualityInfo object from a stream object.
*
* @param {!shaka.extern.Stream} stream
* @return {!shaka.extern.MediaQualityInfo}
*/
static createQualityInfo(stream) {
return {
bandwidth: stream.bandwidth || 0,
audioSamplingRate: stream.audioSamplingRate,
codecs: stream.codecs,
contentType: stream.type,
frameRate: stream.frameRate || null,
height: stream.height || null,
mimeType: stream.mimeType,
channelsCount: stream.channelsCount,
pixelAspectRatio: stream.pixelAspectRatio || null,
width: stream.width || null,
label: stream.label || null,
roles: stream.roles,
language: stream.language,
};
}
};

/**
Expand Down
7 changes: 5 additions & 2 deletions lib/mss/mss_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ goog.require('shaka.log');
goog.require('shaka.media.InitSegmentReference');
goog.require('shaka.media.ManifestParser');
goog.require('shaka.media.PresentationTimeline');
goog.require('shaka.media.QualityObserver');
goog.require('shaka.media.SegmentIndex');
goog.require('shaka.media.SegmentReference');
goog.require('shaka.mss.ContentProtection');
Expand Down Expand Up @@ -708,12 +709,14 @@ shaka.mss.MssParser = class {
initSegmentData = mp4Generator.initSegment();
this.initSegmentDataByStreamId_.set(stream.id, initSegmentData);
}
const qualityInfo =
shaka.media.QualityObserver.createQualityInfo(stream);
const initSegmentRef = new shaka.media.InitSegmentReference(
() => [],
/* startByte= */ 0,
/* endByte= */ null,
/* mediaQuality= */ null,
/* timescale= */ undefined,
qualityInfo,
stream.mssPrivateData.timescale,
initSegmentData);

const segments = this.createSegments_(initSegmentRef,
Expand Down
4 changes: 2 additions & 2 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ goog.requireType('shaka.media.PresentationTimeline');
* @description Fired when the media quality changes at the playhead.
* That may be caused by an adaptation change or a DASH period transition.
* Separate events are emitted for audio and video contentTypes.
* This is supported for only DASH streams at this time.
* This is supported for only DASH and MSS streams at this time.
* @property {string} type
* 'mediaqualitychanged'
* @property {shaka.extern.MediaQualityInfo} mediaQuality
Expand All @@ -188,7 +188,7 @@ goog.requireType('shaka.media.PresentationTimeline');
* @event shaka.Player.AudioTrackChangedEvent
* @description Fired when the audio track changes at the playhead.
* That may be caused by a user requesting to chang audio tracks.
* This is supported for only DASH streams at this time.
* This is supported for only DASH and MSS streams at this time.
* @property {string} type
* 'audiotrackchanged'
* @property {shaka.extern.MediaQualityInfo} mediaQuality
Expand Down

0 comments on commit 0d80bc3

Please sign in to comment.