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: Allow add extra features to MediaSource.addSourceBuffer #4527

Merged
merged 3 commits into from
Sep 30, 2022
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
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
20 changes: 20 additions & 0 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,23 @@ 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.
joeyparrish marked this conversation as resolved.
Show resolved Hide resolved
* This string is ultimately appended to MIME types in addSourceBuffer().
* @exportDoc
*/
shaka.extern.MediaSourceConfiguration;


/**
* @typedef {{
* enabled: boolean,
Expand Down Expand Up @@ -1185,6 +1202,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 +1230,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
3 changes: 3 additions & 0 deletions test/cast/cast_utils_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ describe('CastUtils', () => {
video,
new shaka.test.FakeClosedCaptionParser(),
new shaka.test.FakeTextDisplayer());
const config =
shaka.util.PlayerConfiguration.createDefault().mediaSource;
mediaSourceEngine.configure(config);

const ContentType = shaka.util.ManifestParserUtils.ContentType;
const initObject = new Map();
Expand Down
3 changes: 3 additions & 0 deletions test/media/drm_engine_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ describe('DrmEngine', () => {
video,
new shaka.test.FakeClosedCaptionParser(),
new shaka.test.FakeTextDisplayer());
const mediaSourceConfig =
shaka.util.PlayerConfiguration.createDefault().mediaSource;
mediaSourceEngine.configure(mediaSourceConfig);

const expectedObject = new Map();
expectedObject.set(ContentType.AUDIO, audioStream);
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/media/streaming_engine_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ describe('StreamingEngine', () => {
video,
new shaka.test.FakeClosedCaptionParser(),
new shaka.test.FakeTextDisplayer());
const mediaSourceConfig =
shaka.util.PlayerConfiguration.createDefault().mediaSource;
mediaSourceEngine.configure(mediaSourceConfig);
waiter.setMediaSourceEngine(mediaSourceEngine);
});

Expand Down
1 change: 1 addition & 0 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ describe('Player', () => {
streamingEngine = new shaka.test.FakeStreamingEngine();
mediaSourceEngine = {
init: jasmine.createSpy('init').and.returnValue(Promise.resolve()),
configure: jasmine.createSpy('configure'),
open: jasmine.createSpy('open').and.returnValue(Promise.resolve()),
destroy:
jasmine.createSpy('destroy').and.returnValue(Promise.resolve()),
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 @@ -54,6 +54,9 @@ shaka.test.FakeMediaSourceEngine = class {
/** @type {!jasmine.Spy} */
this.open = jasmine.createSpy('open').and.returnValue(Promise.resolve());

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

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

Expand Down