Skip to content

Commit

Permalink
Add type info for test scheme metadata types
Browse files Browse the repository at this point in the history
These metadata types were never defined, and the old compiler would
allow this.  The newer compiler is more strict, so this adds typedefs
for the metadata we use to generate manifests and streams for tests.

This also fixes a bug where we didn't correctly set the mimeType field
of the resulting streams.

This was caught by a compiler upgrade.

Issue shaka-project#2528

Change-Id: Id16606b5c118793ee17dcf28942bf04d0ee22ba9
  • Loading branch information
joeyparrish committed Apr 29, 2020
1 parent 41fd008 commit 8200751
Showing 1 changed file with 50 additions and 11 deletions.
61 changes: 50 additions & 11 deletions test/test/util/test_scheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,46 @@
goog.provide('shaka.test.TestScheme');


/**
* @typedef {{
* initSegmentUri: string,
* mdhdOffset: number,
* segmentUri: string,
* tfdtOffset: number,
* segmentDuration: number,
* mimeType: string,
* codecs: string,
* delaySetup: (boolean|undefined),
* language: (string|undefined),
* closedCaptions: (!Map.<string, string>|undefined),
* initData: (string|undefined)
* }}
*/
let AVMetadataType;

/**
* @typedef {{
* uri: string,
* mimeType: string,
* codecs: string,
* language: (string|undefined)
* }}
*/
let TextMetadataType;

/**
* @typedef {{
* video: AVMetadataType,
* audio: AVMetadataType,
* text: TextMetadataType,
* duration: number,
* licenseServers: !Object.<string, string>,
* licenseRequestHeaders: !Object.<string, string>
* }}
*/
let MetadataType;


shaka.test.TestScheme = class {
/**
* A plugin that handles fake network requests. This will serve both segments
Expand Down Expand Up @@ -118,13 +158,12 @@ shaka.test.TestScheme = class {
const windowShaka = window['shaka'];

/**
* @param {Object} metadata
* @return {shaka.test.IStreamGenerator}
* @param {AVMetadataType} metadata
* @return {!shaka.test.IStreamGenerator}
*/
function createStreamGenerator(metadata) {
if (metadata.segmentUri.includes('.ts')) {
return new windowShaka.test.TSVodStreamGenerator(
metadata.segmentUri);
return new windowShaka.test.TSVodStreamGenerator(metadata.segmentUri);
}
return new windowShaka.test.Mp4VodStreamGenerator(
metadata.initSegmentUri, metadata.mdhdOffset, metadata.segmentUri,
Expand All @@ -136,12 +175,12 @@ shaka.test.TestScheme = class {
*
* @param {!shaka.test.ManifestGenerator.Stream} stream
* @param {!shaka.test.ManifestGenerator.Variant} variant
* @param {Object} data
* @param {MetadataType} data
* @param {shaka.util.ManifestParserUtils.ContentType} contentType
* @param {string} name
*/
function addStreamInfo(stream, variant, data, contentType, name) {
stream.mime = data[contentType].mimeType;
stream.mimeType = data[contentType].mimeType;
stream.codecs = data[contentType].codecs;
stream.setInitSegmentReference(
['test:' + name + '/' + contentType + '/init'], 0, null);
Expand Down Expand Up @@ -172,7 +211,7 @@ shaka.test.TestScheme = class {
}

/**
* @param {!Object} data
* @param {MetadataType} data
* @return {string}
*/
function getAbsoluteUri(data) {
Expand Down Expand Up @@ -222,7 +261,7 @@ shaka.test.TestScheme = class {

if (data.text) {
manifest.addTextStream(3, (stream) => {
stream.mime = data.text.mimeType;
stream.mimeType = data.text.mimeType;
stream.codecs = data.text.codecs;
stream.textStream(getAbsoluteUri(data));

Expand Down Expand Up @@ -285,14 +324,14 @@ shaka.test.TestScheme = class {

manifest.addTextStream(idCount++, (stream) => {
stream.language = 'zh';
stream.mime = data.text.mimeType;
stream.mimeType = data.text.mimeType;
stream.codecs = data.text.codecs;
stream.textStream(getAbsoluteUri(data));
});

manifest.addTextStream(idCount++, (stream) => {
stream.language = 'fr';
stream.mime = data.text.mimeType;
stream.mimeType = data.text.mimeType;
stream.codecs = data.text.codecs;
stream.textStream(getAbsoluteUri(data));
});
Expand All @@ -318,7 +357,7 @@ shaka.test.TestScheme.GENERATORS = {};
// general MP4 box parser. We could eliminate these hard-coded offsets and use
// our box parser to find the boxes at runtime after we load the segments.

/** @const */
/** @const {!Object.<string, MetadataType>} */
shaka.test.TestScheme.DATA = {
'sintel': {
video: {
Expand Down

0 comments on commit 8200751

Please sign in to comment.