From 1527fc6b45f1057a5c9bd4b4485a147b957351c1 Mon Sep 17 00:00:00 2001 From: sanbornhnewyyz Date: Tue, 7 Feb 2017 16:30:18 -0500 Subject: [PATCH] Don't ignore InbandEventStreams at the Representation level Closes #686 --- lib/dash/dash_parser.js | 35 +++++++++- test/dash/dash_parser_manifest_unit.js | 91 ++++++++++++++++++-------- 2 files changed, 95 insertions(+), 31 deletions(-) diff --git a/lib/dash/dash_parser.js b/lib/dash/dash_parser.js index 45c1da6e85..cb92985850 100644 --- a/lib/dash/dash_parser.js +++ b/lib/dash/dash_parser.js @@ -904,8 +904,7 @@ shaka.dash.DashParser.prototype.parseAdaptationSet_ = function(context, elem) { // InbandEventStream indicates that a segment contains inband // information. - var eventStream = XmlUtils.findChild(elem, 'InbandEventStream'); - var containsInband = eventStream != null; + var containsInband = this.inBandEventStreamIsPresent_(elem); var essentialProperties = XmlUtils.findChildren(elem, 'EssentialProperty'); // ID of real AdaptationSet if this is a trick mode set: @@ -991,6 +990,38 @@ shaka.dash.DashParser.prototype.parseAdaptationSet_ = function(context, elem) { }; +/** + * Indicates whether an InbandEventStream element is present at the Adaption + * Set or Representation level. + * + * @param {!Element} elem The AdaptationSet element. + * @return {boolean} Whether the InbandEventStream element is present. + * @private + */ +shaka.dash.DashParser.prototype.inBandEventStreamIsPresent_ = function(elem) { + var XmlUtils = shaka.util.XmlUtils; + + var adaptationEventStream = XmlUtils.findChild(elem, 'InbandEventStream'); + if (adaptationEventStream != null) { + return true; + } + + var representations = XmlUtils.findChildren(elem, 'Representation'); + var representationEventStream = null; + if (representations.length > 0) { + for (var i = 0; i < representations.length; i++) { + representationEventStream = + XmlUtils.findChild(representations[i], 'InbandEventStream'); + + if (representationEventStream) + return true; + } + } + + return false; +}; + + /** * Parses a Representation XML element. * diff --git a/test/dash/dash_parser_manifest_unit.js b/test/dash/dash_parser_manifest_unit.js index c5a970bbd0..1c36527864 100644 --- a/test/dash/dash_parser_manifest_unit.js +++ b/test/dash/dash_parser_manifest_unit.js @@ -751,35 +751,46 @@ describe('DashParser Manifest', function() { .then(done); }); - it('updates manifest when emsg box is present', function(done) { - var manifestText = [ - '', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - '' - ].join('\n'); - - fakeNetEngine.setResponseMapAsText({'dummy://foo': manifestText}); - parser.start('dummy://foo', playerInterface) - .then(function() { - expect(fakeNetEngine.registerResponseFilter).toHaveBeenCalled(); - var filter = - fakeNetEngine.registerResponseFilter.calls.mostRecent().args[0]; - var type = shaka.net.NetworkingEngine.RequestType.SEGMENT; - var response = {data: emsgUpdate.buffer}; - fakeNetEngine.request.calls.reset(); - filter(type, response); - expect(fakeNetEngine.request).toHaveBeenCalled(); - }) - .catch(fail) - .then(done); - }); + it('updates manifest when emsg box is present on AdaptationSet', + function(done) { + var manifestText = [ + '', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + '' + ].join('\n'); + + emsgBoxPresenceHelper(manifestText, emsgUpdate, done); + }); + + it('updates manifest when emsg box is present on Representation', + function(done) { + var manifestText = [ + '', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + '' + ].join('\n'); + + emsgBoxPresenceHelper(manifestText, emsgUpdate, done); + }); it('dispatches an event on non-typical emsg content', function(done) { var manifestText = [ @@ -969,4 +980,26 @@ describe('DashParser Manifest', function() { .catch(fail) .then(done); }); + + /** + * @param {string} manifestText + * @param {Uint8Array} emsgUpdate + * @param {Function} done + */ + function emsgBoxPresenceHelper(manifestText, emsgUpdate, done) { + fakeNetEngine.setResponseMapAsText({'dummy://foo': manifestText}); + parser.start('dummy://foo', playerInterface) + .then(function() { + expect(fakeNetEngine.registerResponseFilter).toHaveBeenCalled(); + var filter = + fakeNetEngine.registerResponseFilter.calls.mostRecent().args[0]; + var type = shaka.net.NetworkingEngine.RequestType.SEGMENT; + var response = {data: emsgUpdate.buffer}; + fakeNetEngine.request.calls.reset(); + filter(type, response); + expect(fakeNetEngine.request).toHaveBeenCalled(); + }) + .catch(fail) + .then(done); + } });