Skip to content

feat(DASH): Add DVB Font downloads #6971

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

Merged
merged 1 commit into from
Jul 2, 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
35 changes: 35 additions & 0 deletions demo/common/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ shakaAssets.Source = {
EZDRM: 'EZDRM',
THEO_PLAYER: 'THEOplayer',
JWPLAYER: 'JW Player',
BBC: 'BBC',
};


Expand Down Expand Up @@ -1686,5 +1687,39 @@ shakaAssets.testAssets = [
defaultVrProjectionMode: 'equirectangular',
}),
// }}}

// BBC assets {{{
/* BBC Contents */
new ShakaDemoAssetInfo(
/* name= */ 'On-demand Testcard - WOFF Font Download signalled with supplemental property descriptor',
/* iconUri= */ '',
/* manifestUri= */ 'https://rdmedia.bbc.co.uk/testcard/vod/manifests/avc-ctv-stereo-en-sfdt-woff.mpd',
/* source= */ shakaAssets.Source.BBC)
.addFeature(shakaAssets.Feature.HIGH_DEFINITION)
.addFeature(shakaAssets.Feature.MP4),
new ShakaDemoAssetInfo(
/* name= */ 'On-demand Testcard - WOFF Font Download signalled with essential property descriptor',
/* iconUri= */ '',
/* manifestUri= */ 'https://rdmedia.bbc.co.uk/testcard/vod/manifests/avc-ctv-stereo-en-efdt-woff.mpd',
/* source= */ shakaAssets.Source.BBC)
.addFeature(shakaAssets.Feature.HIGH_DEFINITION)
.addFeature(shakaAssets.Feature.MP4),
new ShakaDemoAssetInfo(
/* name= */ 'Live Testcard - WOFF Font Download signalled with supplemental property descriptor',
/* iconUri= */ '',
/* manifestUri= */ 'https://rdmedia.bbc.co.uk/testcard/simulcast/manifests/avc-ctv-stereo-en-sfdt-woff.mpd',
/* source= */ shakaAssets.Source.BBC)
.addFeature(shakaAssets.Feature.HIGH_DEFINITION)
.addFeature(shakaAssets.Feature.MP4)
.addFeature(shakaAssets.Feature.LIVE),
new ShakaDemoAssetInfo(
/* name= */ 'Live Testcard - WOFF Font Download signalled with essential property descriptor',
/* iconUri= */ '',
/* manifestUri= */ 'https://rdmedia.bbc.co.uk/testcard/simulcast/manifests/avc-ctv-stereo-en-efdt-woff.mpd',
/* source= */ shakaAssets.Source.BBC)
.addFeature(shakaAssets.Feature.HIGH_DEFINITION)
.addFeature(shakaAssets.Feature.MP4)
.addFeature(shakaAssets.Feature.LIVE),
// }}}
];
/* eslint-enable max-len */
17 changes: 17 additions & 0 deletions externs/font_face_set.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @fileoverview Externs for FontFaceSet which were missing in the
* Closure compiler.
*
* @externs
*/

/**
* @return {!Array.<FontFace>}
*/
FontFaceSet.prototype.values = function() {};
5 changes: 4 additions & 1 deletion externs/shaka/manifest_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ shaka.extern.ManifestParser = class {
* getBandwidthEstimate: function():number,
* onMetadata: function(string, number, ?number,
* !Array.<shaka.extern.MetadataFrame>),
* disableStream: function(!shaka.extern.Stream)
* disableStream: function(!shaka.extern.Stream),
* addFont: function(string, string)
* }}
*
* @description
Expand Down Expand Up @@ -184,6 +185,8 @@ shaka.extern.ManifestParser = class {
* @property {function(!shaka.extern.Stream)} disableStream
* Called to temporarily disable a stream i.e. disabling all variant
* containing said stream.
* @property {function(string, string)} addFont
* Called when a new font needs to be added.
* @exportDoc
*/
shaka.extern.ManifestParser.PlayerInterface;
Expand Down
12 changes: 12 additions & 0 deletions lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,12 @@ shaka.dash.DashParser = class {
} else if (schemeId == 'urn:mpeg:dash:ssr:2023' &&
this.config_.dash.enableFastSwitching) {
isFastSwitching = true;
} else if (schemeId == 'urn:dvb:dash:fontdownload:2014') {
const fontFamily = prop.attributes['dvb:fontFamily'];
const fontUrl = prop.attributes['dvb:url'];
if (fontFamily && fontUrl) {
this.playerInterface_.addFont(fontFamily, fontUrl);
}
} else {
unrecognizedEssentialProperty = true;
}
Expand All @@ -1693,6 +1699,12 @@ shaka.dash.DashParser = class {
colorGamut = getColorGamutFromColourPrimariesCICP(
parseInt(prop.attributes['value'], 10),
);
} else if (schemeId == 'urn:dvb:dash:fontdownload:2014') {
const fontFamily = prop.attributes['dvb:fontFamily'];
const fontUrl = prop.attributes['dvb:url'];
if (fontFamily && fontUrl) {
this.playerInterface_.addFont(fontFamily, fontUrl);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/offline/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,7 @@ shaka.offline.Storage = class {
getBandwidthEstimate: () => config.abr.defaultBandwidthEstimate,
onMetadata: () => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};

parser.configure(config.manifest);
Expand Down
25 changes: 25 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2109,6 +2109,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
},
disableStream: (stream) => this.disableStream(
stream, this.config_.streaming.maxDisabledTime),
addFont: (name, url) => this.addFont(name, url),
};
const regionTimeline =
new shaka.media.RegionTimeline(() => this.seekRange());
Expand Down Expand Up @@ -7322,6 +7323,30 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
}
}

/**
* Load a new font on the page. If the font was already loaded, it does
* nothing.
*
* @param {string} name
* @param {string} url
*/
async addFont(name, url) {
if ('fonts' in document && 'FontFace' in window ) {
await document.fonts.ready;
if (!('values' in document.fonts)) {
return;
}
for (const fontFace of document.fonts.values()) {
if (fontFace.family == name && fontFace.display == 'swap') {
// Font already loaded.
return;
}
}
const fontFace = new FontFace(name, `url(${url})`, {display: 'swap'});
document.fonts.add(fontFace);
}
}

/**
* When we fire region events, we need to copy the information out of the
* region to break the connection with the player's internal data. We do the
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 @@ -33,6 +33,7 @@ describe('CastUtils', () => {
'preload',
'destroyAllPreloads',
'getNonDefaultConfiguration',
'addFont',

// Test helper methods (not @export'd)
'createDrmEngine',
Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_content_protection_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('DashParser ContentProtection', () => {
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};

const actual = await dashParser.start(
Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_live_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('DashParser Live', () => {
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
});

Expand Down
39 changes: 39 additions & 0 deletions test/dash/dash_parser_manifest_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ describe('DashParser Manifest', () => {
let parser;
/** @type {!jasmine.Spy} */
let onEventSpy;
/** @type {!jasmine.Spy} */
let addFontSpy;
/** @type {shaka.extern.ManifestParser.PlayerInterface} */
let playerInterface;
/** @type {!ArrayBuffer} */
Expand All @@ -40,6 +42,7 @@ describe('DashParser Manifest', () => {
fakeNetEngine = new shaka.test.FakeNetworkingEngine();
parser = shaka.test.Dash.makeDashParser();
onEventSpy = jasmine.createSpy('onEvent');
addFontSpy = jasmine.createSpy('addFont');
playerInterface = {
networkingEngine: fakeNetEngine,
modifyManifestRequest: (request, manifestInfo) => {},
Expand All @@ -58,6 +61,7 @@ describe('DashParser Manifest', () => {
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
disableStream: (stream) => {},
addFont: shaka.test.Util.spyFunc(addFontSpy),
};
});

Expand Down Expand Up @@ -3190,4 +3194,39 @@ describe('DashParser Manifest', () => {
const manifest = await parser.start('dummy://foo', playerInterface);
expect(manifest.gapCount).toBe(1);
});

it('supports dvb fonts', async () => {
const manifestText = [
'<MPD type="static">',
' <Period id="1" duration="PT30S">',
' <AdaptationSet id="2" mimeType="video/mp4">',
' <SupplementalProperty',
' schemeIdUri="urn:dvb:dash:fontdownload:2014"',
' value="1" dvb:url="foo.woff"',
' dvb:mimeType="application/font-woff" dvb:fontFamily="foo"/>',
' <Representation id="video" bandwidth="1">',
' <SegmentBase indexRange="100-200" />',
' </Representation>',
' </AdaptationSet>',
' </Period>',
' <Period id="2" start="PT31S" duration="PT30S">',
' <AdaptationSet id="2" mimeType="video/mp4">',
' <EssentialProperty schemeIdUri="urn:dvb:dash:fontdownload:2014"',
' value="1" dvb:url="foo2.woff"',
' dvb:mimeType="application/font-woff" dvb:fontFamily="foo2"/>',
' <Representation id="video" bandwidth="1">',
' <SegmentBase indexRange="100-200" />',
' </Representation>',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');

fakeNetEngine.setResponseText('dummy://foo', manifestText);

await parser.start('dummy://foo', playerInterface);
expect(addFontSpy).toHaveBeenCalledTimes(2);
expect(addFontSpy).toHaveBeenCalledWith('foo', 'foo.woff');
expect(addFontSpy).toHaveBeenCalledWith('foo2', 'foo2.woff');
});
});
1 change: 1 addition & 0 deletions test/dash/dash_parser_patch_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('DashParser Patch', () => {
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
Date.now = () => publishTime.getTime() + 10;

Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_segment_base_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('DashParser SegmentBase', () => {
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
});

Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_segment_list_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ describe('DashParser SegmentList', () => {
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
try {
const manifest = await dashParser.start('dummy://foo', playerInterface);
Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_segment_template_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('DashParser SegmentTemplate', () => {
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
});

Expand Down
1 change: 1 addition & 0 deletions test/hls/hls_live_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ describe('HlsParser live', () => {
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};

parser = new shaka.hls.HlsParser();
Expand Down
1 change: 1 addition & 0 deletions test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ describe('HlsParser', () => {
getBandwidthEstimate: () => 1e6,
onMetadata: shaka.test.Util.spyFunc(onMetadataSpy),
disableStream: (stream) => {},
addFont: (name, url) => {},
};

parser = new shaka.hls.HlsParser();
Expand Down
1 change: 1 addition & 0 deletions test/mss/mss_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ describe('MssParser Manifest', () => {
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
});

Expand Down
2 changes: 2 additions & 0 deletions test/test/util/dash_parser_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ shaka.test.Dash = class {
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
try {
const manifest = await dashParser.start('dummy://foo', playerInterface);
Expand Down Expand Up @@ -93,6 +94,7 @@ shaka.test.Dash = class {
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};

try {
Expand Down
2 changes: 2 additions & 0 deletions test/test/util/mss_parser_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ shaka.test.Mss = class {
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
const manifest = await mssParser.start('dummy://foo', playerInterface);
const stream = manifest.variants[0].audio;
Expand Down Expand Up @@ -89,6 +90,7 @@ shaka.test.Mss = class {
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
const p = mssParser.start('dummy://foo', playerInterface);
await expectAsync(p).toBeRejectedWith(
Expand Down
1 change: 1 addition & 0 deletions test/util/content_steering_manager_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('ContentSteeringManager', () => {
getBandwidthEstimate: () => 1e6,
onMetadata: () => {},
disableStream: (stream) => {},
addFont: (name, url) => {},
};
const config = shaka.util.PlayerConfiguration.createDefault().manifest;
manager = new shaka.util.ContentSteeringManager(playerInterface);
Expand Down
Loading