Skip to content

Commit

Permalink
feat: Allow add extra features to MediaSource.addSourceBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Sep 29, 2022
1 parent c97768b commit 6f168fb
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 2 deletions.
2 changes: 2 additions & 0 deletions demo/common/message_ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ shakaDemo.MessageIds = {
MAX_HEIGHT: 'DEMO_MAX_HEIGHT',
MAX_PIXELS: 'DEMO_MAX_PIXELS',
MAX_WIDTH: 'DEMO_MAX_WIDTH',
MEDIA_SOURCE_SECTION_HEADER: 'DEMO_MEDIA_SOURCE_SECTION_HEADER',
MIN_BANDWIDTH: 'DEMO_MIN_BANDWIDTH',
MIN_BYTES: 'DEMO_MIN_BYTES',
MIN_FRAMERATE: 'DEMO_MIN_FRAMERATE',
Expand All @@ -248,6 +249,7 @@ shakaDemo.MessageIds = {
SESSION_ID: 'DEMO_SESSION_ID',
SHAKA_CONTROLS: 'DEMO_SHAKA_CONTROLS',
SLOW_HALF_LIFE: 'DEMO_SLOW_HALF_LIFE',
SOURCE_BUFFER_EXTRA_FEATURES: 'DEMO_SOURCE_BUFFER_EXTRA_FEATURES',
STALL_DETECTOR_ENABLED: 'DEMO_STALL_DETECTOR_ENABLED',
STALL_THRESHOLD: 'DEMO_STALL_THRESHOLD',
STALL_TIMEOUT: 'DEMO_STALL_TIMEOUT',
Expand Down
10 changes: 10 additions & 0 deletions demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ shakaDemo.Config = class {
this.addOfflineSection_();
this.addDrmSection_();
this.addStreamingSection_();
this.addMediaSourceSection_();
this.addManifestSection_();
this.addRetrictionsSection_('',
shakaDemo.MessageIds.RESTRICTIONS_SECTION_HEADER);
Expand Down Expand Up @@ -428,6 +429,15 @@ shakaDemo.Config = class {
MessageIds.STREAMING_RETRY_SECTION_HEADER);
}

/** @private */
addMediaSourceSection_() {
const MessageIds = shakaDemo.MessageIds;
const docLink = this.resolveExternLink_('.MediaSourceConfiguration');
this.addSection_(MessageIds.MEDIA_SOURCE_SECTION_HEADER, docLink)
.addTextInput_(MessageIds.SOURCE_BUFFER_EXTRA_FEATURES,
'mediaSource.sourceBufferExtraFeatures');
}

/** @private */
addLanguageSection_() {
const MessageIds = shakaDemo.MessageIds;
Expand Down
2 changes: 2 additions & 0 deletions demo/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"DEMO_MAX_HEIGHT": "Max Height",
"DEMO_MAX_PIXELS": "Max Pixels",
"DEMO_MAX_WIDTH": "Max Width",
"DEMO_MEDIA_SOURCE_SECTION_HEADER": "Media source",
"DEMO_METACDN": "MetaCDN",
"DEMO_MICROSOFT": "Microsoft",
"DEMO_MIME_TYPE": "MIME Type",
Expand Down Expand Up @@ -195,6 +196,7 @@
"DEMO_SHAKA_CONTROLS": "Shaka Controls",
"DEMO_SLOW_HALF_LIFE": "Slow half life",
"DEMO_SOURCE": "Source on GitHub",
"DEMO_SOURCE_BUFFER_EXTRA_FEATURES": "Source buffer extra features",
"DEMO_SOURCE_SEARCH": "Source",
"DEMO_STALL_DETECTOR_ENABLED": "Stall Detector Enabled",
"DEMO_STALL_THRESHOLD": "Stall Threshold",
Expand Down
8 changes: 8 additions & 0 deletions demo/locales/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@
"description": "The name of a configuration value.",
"message": "Max Width"
},
"DEMO_MEDIA_SOURCE_SECTION_HEADER": {
"description": "The header for a section of configuration values.",
"message": "Media source"
},
"DEMO_METACDN": {
"description": "Text that describes an asset that comes from the MetaCDN asset library.",
"message": "[PROPER_NAME:MetaCDN]"
Expand Down Expand Up @@ -783,6 +787,10 @@
"description": "A link in the footer, to the Shaka Player source on GitHub.",
"message": "Source on [PROPER_NAME:GitHub]"
},
"DEMO_SOURCE_BUFFER_EXTRA_FEATURES": {
"description": "The name of a configuration value.",
"message": "Source buffer extra features"
},
"DEMO_SOURCE_SEARCH": {
"description": "A header on a search field that filters by the source of the asset.",
"message": "Source"
Expand Down
19 changes: 19 additions & 0 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,22 @@ shaka.extern.ManifestConfiguration;
shaka.extern.StreamingConfiguration;


/**
* @typedef {{
* sourceBufferExtraFeatures: string
* }}
*
* @description
* Media source configuration.
*
* @property {string} sourceBufferExtraFeatures
* Some platforms may need to pass features when initializing the
* sourceBuffer.
* @exportDoc
*/
shaka.extern.MediaSourceConfiguration;


/**
* @typedef {{
* enabled: boolean,
Expand Down Expand Up @@ -1185,6 +1201,7 @@ shaka.extern.OfflineConfiguration;
* drm: shaka.extern.DrmConfiguration,
* manifest: shaka.extern.ManifestConfiguration,
* streaming: shaka.extern.StreamingConfiguration,
* mediaSource: shaka.extern.MediaSourceConfiguration,
* abrFactory: shaka.extern.AbrManager.Factory,
* abr: shaka.extern.AbrConfiguration,
* cmcd: shaka.extern.CmcdConfiguration,
Expand Down Expand Up @@ -1212,6 +1229,8 @@ shaka.extern.OfflineConfiguration;
* Manifest configuration and settings.
* @property {shaka.extern.StreamingConfiguration} streaming
* Streaming configuration and settings.
* @property {shaka.extern.MediaSourceConfiguration} mediaSource
* Media source configuration and settings.
* @property {shaka.extern.AbrManager.Factory} abrFactory
* A factory to construct an abr manager.
* @property {shaka.extern.AbrConfiguration} abr
Expand Down
18 changes: 16 additions & 2 deletions lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ shaka.media.MediaSourceEngine = class {
/** @private {HTMLMediaElement} */
this.video_ = video;

/** @private {?shaka.extern.MediaSourceConfiguration} */
this.config_ = null;

/** @private {shaka.extern.TextDisplayer} */
this.textDisplayer_ = textDisplayer;

Expand Down Expand Up @@ -291,6 +294,7 @@ shaka.media.MediaSourceEngine = class {
this.video_ = null;
}

this.config_ = null;
this.mediaSource_ = null;
this.textEngine_ = null;
this.textDisplayer_ = null;
Expand Down Expand Up @@ -357,8 +361,8 @@ shaka.media.MediaSourceEngine = class {
mimeType =
shaka.media.Transmuxer.convertTsCodecs(contentType, mimeType);
}

const sourceBuffer = this.mediaSource_.addSourceBuffer(mimeType);
const type = mimeType + this.config_.sourceBufferExtraFeatures;
const sourceBuffer = this.mediaSource_.addSourceBuffer(type);

this.eventManager_.listen(
sourceBuffer, 'error',
Expand All @@ -374,6 +378,16 @@ shaka.media.MediaSourceEngine = class {
}
}

/**
* Called by the Player to provide an updated configuration any time it
* changes. Must be called at least once before init().
*
* @param {shaka.extern.MediaSourceConfiguration} config
*/
configure(config) {
this.config_ = config;
}

/**
* Reinitialize the TextEngine for a new text type.
* @param {string} mimeType
Expand Down
2 changes: 2 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
(metadata, offset, endTime) => {
this.processTimedMetadataMediaSrc_(metadata, offset, endTime);
});
mediaSourceEngine.configure(this.config_.mediaSource);
const {segmentRelativeVttTiming} = this.config_.manifest;
mediaSourceEngine.setSegmentRelativeVttTiming(segmentRelativeVttTiming);

Expand Down Expand Up @@ -3084,6 +3085,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
}

if (this.mediaSourceEngine_) {
this.mediaSourceEngine_.configure(this.config_.mediaSource);
const {segmentRelativeVttTiming} = this.config_.manifest;
this.mediaSourceEngine_.setSegmentRelativeVttTiming(
segmentRelativeVttTiming);
Expand Down
5 changes: 5 additions & 0 deletions lib/util/player_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,18 @@ shaka.util.PlayerConfiguration = class {
useHeaders: false,
};

const mediaSource = {
sourceBufferExtraFeatures: '',
};

const AutoShowText = shaka.config.AutoShowText;

/** @type {shaka.extern.PlayerConfiguration} */
const config = {
drm: drm,
manifest: manifest,
streaming: streaming,
mediaSource: mediaSource,
offline: offline,
abrFactory: () => new shaka.abr.SimpleAbrManager(),
abr: abr,
Expand Down
2 changes: 2 additions & 0 deletions test/media/media_source_engine_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ describe('MediaSourceEngine', () => {
video,
new shaka.media.ClosedCaptionParser(),
textDisplayer);
const config = shaka.util.PlayerConfiguration.createDefault().mediaSource;
mediaSourceEngine.configure(config);

mediaSource = /** @type {?} */(mediaSourceEngine)['mediaSource_'];
expect(video.src).toBeTruthy();
Expand Down
2 changes: 2 additions & 0 deletions test/media/media_source_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ describe('MediaSourceEngine', () => {
video,
mockClosedCaptionParser,
mockTextDisplayer);
const config = shaka.util.PlayerConfiguration.createDefault().mediaSource;
mediaSourceEngine.configure(config);
});

afterEach(() => {
Expand Down
3 changes: 3 additions & 0 deletions test/test/util/fake_media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ shaka.test.FakeMediaSourceEngine = class {
/** @type {!jasmine.Spy} */
this.setSegmentRelativeVttTiming =
jasmine.createSpy('setSegmentRelativeVttTiming').and.stub();

/** @type {!jasmine.Spy} */
this.configure = jasmine.createSpy('configure');
}

/** @override */
Expand Down

0 comments on commit 6f168fb

Please sign in to comment.