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

Provide framerate and codecs information on video tracks #533

Merged
merged 8 commits into from
Sep 28, 2016
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Itay Kinnrot <Itay.Kinnrot@Kaltura.com>
Jason Palmer <jason@jason-palmer.com>
Jesper Haug Karsrud <jesper.karsrud@gmail.com>
Johan Sundström <oyasumi@gmail.com>
Jonas Birmé <jonas.birme@eyevinn.se>
JW Player <*@jwplayer.com>
Mattias Wadman <mattias.wadman@gmail.com>
Nick Desaulniers <nick@mozilla.com>
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Jason Palmer <jason@jason-palmer.com>
Jesper Haug Karsrud <jesper.karsrud@gmail.com>
Joey Parrish <joeyparrish@google.com>
Johan Sundström <oyasumi@gmail.com>
Jonas Birmé <jonas.birme@eyevinn.se>
Jono Ward <jonoward@gmail.com>
Mattias Wadman <mattias.wadman@gmail.com>
Natalie Harris <natalieharris@google.com>
Expand Down
4 changes: 4 additions & 0 deletions externs/shaka/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ shakaExtern.GetSegmentReferenceFunction;
* presentationTimeOffset: (number|undefined),
* mimeType: string,
* codecs: string,
* frameRate: (number|undefined),
* bandwidth: (number|undefined),
* width: (number|undefined),
* height: (number|undefined),
Expand Down Expand Up @@ -315,6 +316,9 @@ shakaExtern.GetSegmentReferenceFunction;
* The Stream's codecs, e.g., 'avc1.4d4015' or 'vp9', which must be
* compatible with the Stream's MIME type. <br>
* See {@link https://tools.ietf.org/html/rfc6381}
* @property {(number|undefined)} frameRate
* <i>Video streams only.</i> <br>
* The Stream's framerate in frames per second
* @property {(number|undefined)} bandwidth
* <i>Audio and video streams only.</i> <br>
* The stream's required bandwidth in bits per second.
Expand Down
3 changes: 3 additions & 0 deletions externs/shaka/offline.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ shakaExtern.PeriodDB;
* contentType: string,
* mimeType: string,
* codecs: string,
* frameRate: (number|undefined),
* kind: (string|undefined),
* language: string,
* width: ?number,
Expand All @@ -157,6 +158,8 @@ shakaExtern.PeriodDB;
* The MIME type of the stream.
* @property {string} codecs
* The codecs of the stream.
* @property {(number|undefined)} frameRate
* The Stream's framerate in frames per second
* @property {(string|undefined)} kind
* The kind of text stream; undefined for audio/video.
* @property {string} language
Expand Down
8 changes: 7 additions & 1 deletion externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ shakaExtern.Stats;
* language: string,
* kind: ?string,
* width: ?number,
* height: ?number
* height: ?number,
* frameRate: ?number,
* codecs: ?string
* }}
*
* @description
Expand Down Expand Up @@ -129,6 +131,10 @@ shakaExtern.Stats;
* (only for video tracks) The width of the track in pixels.
* @property {?number} height
* (only for video tracks) The height of the track in pixels.
* @property {?number} frameRate
* The video framerate provided in the manifest, if present.
* @property {?string} codecs
* The audio/video codecs string provided in the manifest, if present.
* @exportDoc
*/
shakaExtern.Track;
Expand Down
11 changes: 10 additions & 1 deletion lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ shaka.dash.DashParser.RequestInitSegmentCallback;
* contentType: string,
* mimeType: string,
* codecs: string,
* frameRate: (number|undefined),
* id: string
* }}
*
Expand All @@ -162,6 +163,8 @@ shaka.dash.DashParser.RequestInitSegmentCallback;
* The inherited MIME type value.
* @property {string} codecs
* The inherited codecs value.
* @property {(number|undefined)} frameRate
* The inherited framerate value.
* @property {string} id
* The ID of the element.
*/
Expand Down Expand Up @@ -906,6 +909,7 @@ shaka.dash.DashParser.prototype.parseRepresentation_ = function(
presentationTimeOffset: streamInfo.presentationTimeOffset,
mimeType: context.representation.mimeType,
codecs: context.representation.codecs,
frameRate: context.representation.frameRate,
bandwidth: context.bandwidth,
width: context.representation.width,
height: context.representation.height,
Expand Down Expand Up @@ -998,15 +1002,19 @@ shaka.dash.DashParser.prototype.createFrame_ = function(
parent = parent || /** @type {shaka.dash.DashParser.InheritanceFrame} */ ({
contentType: '',
mimeType: '',
codecs: ''
codecs: '',
frameRate: undefined
});
baseUris = baseUris || parent.baseUris;

var parseNumber = XmlUtils.parseNonNegativeInt;
var evalDivision = XmlUtils.evalDivision;
var uris = XmlUtils.findChildren(elem, 'BaseURL').map(XmlUtils.getContents);

var contentType = elem.getAttribute('contentType') || parent.contentType;
var mimeType = elem.getAttribute('mimeType') || parent.mimeType;
var frameRate = XmlUtils.parseAttr(elem, 'frameRate',
evalDivision) || parent.frameRate;

if (!contentType) {
contentType = mimeType.split('/')[0];
Expand All @@ -1023,6 +1031,7 @@ shaka.dash.DashParser.prototype.createFrame_ = function(
contentType: contentType,
mimeType: mimeType,
codecs: elem.getAttribute('codecs') || parent.codecs,
frameRate: frameRate,
id: elem.getAttribute('id')
};
};
Expand Down
4 changes: 3 additions & 1 deletion lib/offline/offline_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ shaka.offline.OfflineUtils.getStoredContent = function(manifest) {
language: stream.language,
kind: stream.kind || null,
width: stream.width,
height: stream.height
height: stream.height,
frameRate: stream.frameRate,
codecs: stream.codecs
};
}),
appMetadata: manifest.appMetadata
Expand Down
1 change: 1 addition & 0 deletions lib/offline/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ shaka.offline.Storage.prototype.createStream_ = function(
contentType: streamSet.type,
mimeType: stream.mimeType,
codecs: stream.codecs,
frameRate: stream.frameRate,
kind: stream.kind,
language: streamSet.language,
width: stream.width || null,
Expand Down
4 changes: 3 additions & 1 deletion lib/util/stream_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ shaka.util.StreamUtils.getTracks = function(period, activeStreams) {
language: streamSet.language,
kind: stream.kind || null,
width: stream.width || null,
height: stream.height || null
height: stream.height || null,
frameRate: stream.frameRate || undefined,
codecs: stream.codecs || null
};
});
})
Expand Down
19 changes: 19 additions & 0 deletions lib/util/xml_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,22 @@ shaka.util.XmlUtils.parseFloat = function(floatString) {
};


/**
* Evaluate a division expressed as a string
* @param {string} exprString
* The expression to evaluate, e.g. "200/2". Can also be a single number
* @return {?number} The evaluated expression as floating point number on
* success; otherwise return null.
*/
shaka.util.XmlUtils.evalDivision = function(exprString) {
var res;
var n;
if (res = exprString.match(/^(\d+)\/(\d+)$/)) {
n = Number(res[1] / res[2]);
} else if (res = exprString.match(/^([0-9]\.)$/)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this match, Number(res[1]) is the same as Number(exprString), so I would just drop this else if completely.

n = Number(res[1]);
} else {
n = Number(exprString);
}
return !isNaN(n) ? n : null;
};
4 changes: 3 additions & 1 deletion test/dash/dash_parser_manifest_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('DashParser.Manifest', function() {
],
[
' <AdaptationSet contentType="video" mimeType="video/mp4"',
' codecs="avc1.4d401f" lang="en">',
' codecs="avc1.4d401f" frameRate="1000000/42000" lang="en">',
' <Representation bandwidth="100" width="768" height="576" />',
' <Representation bandwidth="50" width="576" height="432" />',
' </AdaptationSet>',
Expand Down Expand Up @@ -136,13 +136,15 @@ describe('DashParser.Manifest', function() {
.presentationTimeOffset(0)
.mime('video/mp4', 'avc1.4d401f')
.bandwidth(100)
.frameRate(23.80952380952380952380)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The precision here is worrying. Are all of these digits required to get a match out of Jasmine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I haven't tested with a lower precision so I don't know if all of these digits are required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a test and it seems that Jasmine requires full precision here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, then. Please add a comment like:

// TODO: get Jasmine to match with less precision

And my team will work on it later.

.size(768, 576)
.addStream(jasmine.any(Number))
.anySegmentFunctions()
.anyInitSegment()
.presentationTimeOffset(0)
.mime('video/mp4', 'avc1.4d401f')
.bandwidth(50)
.frameRate(23.80952380952380952380)
.size(576, 432)
.addStreamSet('text')
.language('es')
Expand Down
16 changes: 12 additions & 4 deletions test/offline/storage_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,19 @@ describe('Storage', function() {
kind: undefined,
language: '',
width: 1920,
height: 1080
height: 1080,
frameRate: 24,
codecs: 'avc1.4d401f'
},
{
id: 1,
contentType: 'audio',
kind: undefined,
language: 'en',
width: null,
height: null
height: null,
frameRate: undefined,
codecs: 'vorbis'
}
]
}],
Expand Down Expand Up @@ -100,7 +104,9 @@ describe('Storage', function() {
language: '',
kind: null,
width: 1920,
height: 1080
height: 1080,
frameRate: 24,
codecs: 'avc1.4d401f'
},
{
id: 1,
Expand All @@ -110,7 +116,9 @@ describe('Storage', function() {
language: 'en',
kind: null,
width: null,
height: null
height: null,
frameRate: undefined,
codecs: 'vorbis'
}
];
Promise
Expand Down
27 changes: 20 additions & 7 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,8 @@ describe('Player', function() {
.addStream(2).bandwidth(100)
.addStreamSet('video')
.addStream(4).bandwidth(100).size(100, 200)
.addStream(5).bandwidth(200).size(200, 400)
.frameRate(1000000 / 42000)
.addStream(5).bandwidth(200).size(200, 400).frameRate(24)
.addStreamSet('text')
.language('es')
.addStream(6).bandwidth(100).kind('caption')
Expand All @@ -671,7 +672,9 @@ describe('Player', function() {
language: 'en',
kind: null,
width: null,
height: null
height: null,
frameRate: undefined,
codecs: 'avc1.4d401f'
},
{
id: 2,
Expand All @@ -681,7 +684,9 @@ describe('Player', function() {
language: 'en',
kind: null,
width: null,
height: null
height: null,
frameRate: undefined,
codecs: 'avc1.4d401f'
},
{
id: 4,
Expand All @@ -691,7 +696,9 @@ describe('Player', function() {
language: 'und',
kind: null,
width: 100,
height: 200
height: 200,
frameRate: 23.80952380952380952380,
codecs: 'avc1.4d401f'
},
{
id: 5,
Expand All @@ -701,7 +708,9 @@ describe('Player', function() {
language: 'und',
kind: null,
width: 200,
height: 400
height: 400,
frameRate: 24,
codecs: 'avc1.4d401f'
},
{
id: 6,
Expand All @@ -711,7 +720,9 @@ describe('Player', function() {
language: 'es',
kind: 'caption',
width: null,
height: null
height: null,
frameRate: undefined,
codecs: 'avc1.4d401f'
},
{
id: 7,
Expand All @@ -721,7 +732,9 @@ describe('Player', function() {
language: 'en',
kind: 'caption',
width: null,
height: null
height: null,
frameRate: undefined,
codecs: 'avc1.4d401f'
}
];
});
Expand Down
14 changes: 14 additions & 0 deletions test/test/util/manifest_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ shaka.test.ManifestGenerator.prototype.addStream = function(id) {
presentationTimeOffset: 0,
mimeType: 'video/mp4',
codecs: 'avc1.4d401f',
frameRate: undefined,
bandwidth: 100,
width: undefined,
height: undefined,
Expand Down Expand Up @@ -512,6 +513,19 @@ shaka.test.ManifestGenerator.prototype.encrypted = function(encrypted) {
};


/**
* Sets the framerate of the current stream.
*
* @param {number} frameRate
* @return {!shaka.test.ManifestGenerator}
*/
shaka.test.ManifestGenerator.prototype.frameRate = function(frameRate) {
var stream = this.currentStream_();
stream.frameRate = frameRate;
return this;
};


/**
* Sets the key ID of the current stream.
*
Expand Down