Skip to content

Commit

Permalink
Log and ignore non-standard WebVTT settings instead of erroring out.
Browse files Browse the repository at this point in the history
Closes #509

Change-Id: I1aced2ea8828c4ca6a9afee6ea28b0144a832029
  • Loading branch information
ismena committed Oct 5, 2016
1 parent 5ee5c63 commit addece6
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 28 deletions.
7 changes: 4 additions & 3 deletions lib/media/mp4_vtt_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
goog.provide('shaka.media.Mp4VttParser');

goog.require('goog.asserts');
goog.require('shaka.log');
goog.require('shaka.media.TextEngine');
goog.require('shaka.media.VttTextParser');
goog.require('shaka.util.DataViewReader');
Expand Down Expand Up @@ -169,9 +170,9 @@ shaka.media.Mp4VttParser.parseCue_ = function(
var word = parser.readWord();
while (word) {
if (!shaka.media.VttTextParser.parseSetting(cue, word)) {
throw new shaka.util.Error(
shaka.util.Error.Category.TEXT,
shaka.util.Error.Code.INVALID_TEXT_SETTINGS);
shaka.log.warning('VTT parser encountered an invalid VTT setting: ',
word,
' The setting will be ignored.');
}
parser.skipWhitespace();
word = parser.readWord();
Expand Down
7 changes: 4 additions & 3 deletions lib/media/vtt_text_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

goog.provide('shaka.media.VttTextParser');

goog.require('shaka.log');
goog.require('shaka.media.TextEngine');
goog.require('shaka.util.Error');
goog.require('shaka.util.StringUtils');
Expand Down Expand Up @@ -109,9 +110,9 @@ shaka.media.VttTextParser.parseCue_ = function(text, offset) {
var word = parser.readWord();
while (word) {
if (!shaka.media.VttTextParser.parseSetting(cue, word)) {
throw new shaka.util.Error(
shaka.util.Error.Category.TEXT,
shaka.util.Error.Code.INVALID_TEXT_SETTINGS);
shaka.log.warning('VTT parser encountered an invalid VTT setting: ',
word,
' The setting will be ignored.');
}
parser.skipWhitespace();
word = parser.readWord();
Expand Down
5 changes: 0 additions & 5 deletions lib/util/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,6 @@ shaka.util.Error.Code = {
/** The text parser failed to parse a text stream due to an invalid cue. */
'INVALID_TEXT_CUE': 2001,

/**
* The text parser failed to parse a text stream due to invalid cue settings.
*/
'INVALID_TEXT_SETTINGS': 2002,

/**
* Was unable to detect the encoding of the response text. Suggest adding
* byte-order-markings to the response data.
Expand Down
81 changes: 64 additions & 17 deletions test/media/vtt_text_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

describe('VttTextParser', function() {
var mockCue = false;
var logWarningSpy;

beforeAll(function() {
// Mock out VTTCue if not supported. These tests don't actually need
Expand All @@ -29,6 +30,9 @@ describe('VttTextParser', function() {
this.text = text;
};
}

logWarningSpy = jasmine.createSpy('shaka.log.warning');
shaka.log.warning = logWarningSpy;
});

afterAll(function() {
Expand Down Expand Up @@ -340,23 +344,66 @@ describe('VttTextParser', function() {
'Test');
});

it('rejects invalid settings', function() {
errorHelper(shaka.util.Error.Code.INVALID_TEXT_SETTINGS,
'WEBVTT\n\n00:00.000 --> 00:00.010 vertical:es\nTest');
errorHelper(shaka.util.Error.Code.INVALID_TEXT_SETTINGS,
'WEBVTT\n\n00:00.000 --> 00:00.010 vertical:\nTest');
errorHelper(shaka.util.Error.Code.INVALID_TEXT_SETTINGS,
'WEBVTT\n\n00:00.000 --> 00:00.010 vertical\nTest');
errorHelper(shaka.util.Error.Code.INVALID_TEXT_SETTINGS,
'WEBVTT\n\n00:00.000 --> 00:00.010 line:-3%\nTest');
errorHelper(shaka.util.Error.Code.INVALID_TEXT_SETTINGS,
'WEBVTT\n\n00:00.000 --> 00:00.010 line:105%\nTest');
errorHelper(shaka.util.Error.Code.INVALID_TEXT_SETTINGS,
'WEBVTT\n\n00:00.000 --> 00:00.010 line:45%%\nTest');
errorHelper(shaka.util.Error.Code.INVALID_TEXT_SETTINGS,
'WEBVTT\n\n00:00.000 --> 00:00.010 align:10\nTest');
errorHelper(shaka.util.Error.Code.INVALID_TEXT_SETTINGS,
'WEBVTT\n\n00:00.000 --> 00:00.010 align:foo\nTest');
it('ignores and logs invalid settings', function() {
expect(logWarningSpy.calls.count()).toBe(0);

verifyHelper(
[
{start: 20, end: 40, text: 'Test'}
],
'WEBVTT\n\n' +
'00:00:20.000 --> 00:00:40.000 vertical:es\n' +
'Test\n\n');

verifyHelper(
[
{start: 20, end: 40, text: 'Test'}
],
'WEBVTT\n\n' +
'00:00:20.000 --> 00:00:40.000 vertical:\n' +
'Test\n\n');

verifyHelper(
[
{start: 20, end: 40, text: 'Test'}
],
'WEBVTT\n\n' +
'00:00:20.000 --> 00:00:40.000 vertical\n' +
'Test\n\n');

verifyHelper(
[
{start: 20, end: 40, text: 'Test'}
],
'WEBVTT\n\n' +
'00:00:20.000 --> 00:00:40.000 line:-3%\n' +
'Test\n\n');

verifyHelper(
[
{start: 20, end: 40, text: 'Test'}
],
'WEBVTT\n\n' +
'00:00:20.000 --> 00:00:40.000 line:45%%\n' +
'Test\n\n');

verifyHelper(
[
{start: 20, end: 40, text: 'Test'}
],
'WEBVTT\n\n' +
'00:00:20.000 --> 00:00:40.000 align:10\n' +
'Test\n\n');

verifyHelper(
[
{start: 20, end: 40, text: 'Test'}
],
'WEBVTT\n\n' +
'00:00:20.000 --> 00:00:40.000 align:foo\n' +
'Test\n\n');

expect(logWarningSpy.calls.count()).toBe(7);
});


Expand Down

0 comments on commit addece6

Please sign in to comment.