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

7 args TextTrackCue constructor #643

Closed

Conversation

jozefchutka
Copy link
Contributor

@jozefchutka jozefchutka commented Jan 4, 2017

Toshiba dTV seems to have a different set of constructor arguments for TextTrackCue, just like the ones used here
http://www.w3schools.com/TAGs/av_met_addtexttrack.asp . Not sure what are the extra arguments but empty strings and true did the job. This also solves #635

@joeyparrish
Copy link
Member

I'm sorry, but the Toshiba dTV is not up to spec. If you can detect and fix it with a polyfill, that would be an acceptable solution. But we won't put platform-specific hacks into the main codebase for a user agent that doesn't follow specs.

Try checking TextTrackCue.length. That should allow you to detect the number of arguments it takes and polyfill it to the correct behavior.

@joeyparrish joeyparrish self-assigned this Jan 4, 2017
@jozefchutka
Copy link
Contributor Author

Do you have any recommendation how to polyfill this? As TextTrackCue exist on window object but requires arguments just like these:
http://www.w3schools.com/TAGs/av_met_addtexttrack.asp
https://www.w3.org/WAI/GL/wiki/Using_the_TextTrack_API_to_provide_captions_dynamically
and I am not able to find other specs that would define official constructor and its arguments.

@joeyparrish
Copy link
Member

In an earlier draft of the spec, TextTrackCue was all there was. IE11 and Edge only have this 3-argument TextTrackCue. Later, VTTCue was introduced as a concrete implementation, at which point TextTrackCue became an abstract interface. Therefore you will not find a TextTrackCue constructor in the specs now.

I recommend you detect the 7-argument TextTrackCue and implement a standard VTTCue constructor instead. Here's the spec: https://w3c.github.io/webvtt/#the-vttcue-interface

Your implementation of VTTCue can then reorder the arguments and call your 7-arg TextTrackCue. It may not be obvious, but you can return an object from a constructor in JavaScript. For example:

function FakeArray() {
  return new Array();
}
var x = new FakeArray();
console.log('x is Array?', x instanceof Array);

@joeyparrish joeyparrish added the type: enhancement New feature or request label Jan 4, 2017
@jozefchutka
Copy link
Contributor Author

jozefchutka commented Jan 5, 2017

TextTrackCue.prototype.constructor.length doesnt return 7 but 1, and so there is no other reliable way of detecting constructor argument count. We will implement polyfill on project level as this (most probably) will not get approved.

@jozefchutka jozefchutka closed this Jan 5, 2017
*/
shaka.polyfill.VTTCue.from7ArgsTextTrackCue_ = function(startTime, endTime,
text) {
return new window['TextTrackCue'](text, startTime, endTime, '', '', '', true);
Copy link
Member

Choose a reason for hiding this comment

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

I assume you're quoting the access here to avoid the compiler complaining about the "wrong" arguments/types. Please add a comment to that effect.


/**
* Draft spec TextTrackCue with 7 constructor arguments.
* See {@link https://goo.gl/CSPvbz Using the TextTrack API} and examples.
Copy link
Member

Choose a reason for hiding this comment

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

This link doesn't specify the 7 arguments or their meaning. It gives an example with 4 arguments, and the examples have the text in argument 4, not argument 1 as you have below.

I tracked down the history as best I could.

Here we had the first appearance of TextTrackCue in draft 20110113 (no constructor).

In draft 20120329, we had the first constructor on TextTrackCue (6 arguments, not 7).

In draft 20121025, the constructor was changed to 3 arguments (as implemented by IE11 and Edge today).

In draft 20121217, we have the final appearance of a TextTrackCue constructor. After this, it became abstract.

Are you sure it's 7 on Toshiba and not 6?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

righ I used wrong link in the comment, this one is the one with 7 args http://www.w3schools.com/TAGs/av_met_addtexttrack.asp just like on Toshiba

@joeyparrish
Copy link
Member

@jozefchutka, let's not give up just yet. You've done all the rest of the work, so I think we can find another way to do the detection. Here are a couple more options:

  1. Parse navigator.userAgent and detect the Toshiba. The down side is that similar platforms, if there are any, would miss out on the polyfill.
  2. Detect TextTrackCue.length == 1. I did some testing, and no currently supported desktop browser looks like this today. Here's a table:
browser TextTrackCue.length VTTCue.length
Chrome, Opera, Firefox 0 (abstract, can't be called) 3
Safari 3 3
IE11, Edge 0 (concrete, can still be called) (VTTCue does not exist)

@joeyparrish joeyparrish reopened this Jan 5, 2017
@jozefchutka
Copy link
Contributor Author

what would you say if I try catch constructing TextTrackCue with 3 and 7 args as a part of polyfill?

@joeyparrish
Copy link
Member

I would prefer detecting either TextTrackCue.length or navigator.userAgent. Catching exceptions can be expensive, so that should never be part of a success path. If we are parsing a VTT file with thousands of cues, running a loop over each cue in which we catch an exception and try again with different args would really hurt performance.

@jozefchutka
Copy link
Contributor Author

Surely I do not want exceptions during real playback, but only during initial polyfill install phase. Once correct construction is detected, the polyfill would reference the right one.

@joeyparrish
Copy link
Member

Okay, sounds good. One caught exception at install time is no big deal.

@jozefchutka
Copy link
Contributor Author

jozefchutka commented Jan 13, 2017

hi Joey,
I have updated the PR. As I do not have the device by hand for test, please keep this PR open until confirmed its working. You were right about TextTrackCue.length returning 6 on Toshiba (the tests I was doing using TextTrackCue.prototype.constructor.length were unnecessary/invalid). With this polyfill in place, max one exception will be handled during install phase in potential rare case (IE/EDGE).

}

if (!window.TextTrackCue) {
shaka.log.info('VTTCue not available.');
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't happen, since all the browsers we support have either VTTCue or TextTrackCue. So we probably don't need a no-op polyfill for this case.

But if this were to happen, we would throw at new VTTCue in TextEngine, so this message should at least be upgraded to shaka.log.error.

return;
}

var constructorLength = window.TextTrackCue.length;
Copy link
Member

Choose a reason for hiding this comment

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

You can drop window here now that TextTrackCue is sure to exist.

@joeyparrish
Copy link
Member

I just had a couple small comments on the code. I'll wait for those revisions, and for you to test on the Toshiba.

It looks really good, and it looks like it cleans things up for non-Toshiba platforms as well. Thanks for contributing!

@jozefchutka
Copy link
Contributor Author

@joeyparrish this is confirmed working on Toshiba, ready to merge from my side

@joeyparrish
Copy link
Member

Great, I'll test it on the build bot and on all the browsers in our test lab.

@shaka-bot
Copy link
Collaborator

Testing in progress...

@shaka-bot
Copy link
Collaborator

Failure:

Chrome_55_0_2883_(Linux_0_0_0).VttTextParser VttTextParser supports align setting FAILED
  Expected 'middle' to be 'center'.
      at verifyHelper (test/media/vtt_text_parser_unit.js:456:33)
      at Object.<anonymous> (test/media/vtt_text_parser_unit.js:267:5)
  
Chrome_55_0_2883_(Linux_0_0_0).VttTextParser VttTextParser supports multiple settings FAILED
  Expected 'middle' to be 'center'.
      at verifyHelper (test/media/vtt_text_parser_unit.js:456:33)
      at Object.<anonymous> (test/media/vtt_text_parser_unit.js:277:5)
  
Chrome_55_0_2883_(Linux_0_0_0).VttTextParser VttTextParser supports timestamps with one-digit hour at start time FAILED
  Expected 'middle' to be 'center'.
      at verifyHelper (test/media/vtt_text_parser_unit.js:456:33)
      at Object.<anonymous> (test/media/vtt_text_parser_unit.js:294:5)
  
Chrome_55_0_2883_(Linux_0_0_0).VttTextParser VttTextParser supports timestamps with one-digit hour at end time FAILED
  Expected 'middle' to be 'center'.
      at verifyHelper (test/media/vtt_text_parser_unit.js:456:33)
      at Object.<anonymous> (test/media/vtt_text_parser_unit.js:311:5)
  
Chrome_55_0_2883_(Linux_0_0_0).VttTextParser VttTextParser supports stamps with one-digit hours at start & end time FAILED
  Expected 'middle' to be 'center'.
      at verifyHelper (test/media/vtt_text_parser_unit.js:456:33)
      at Object.<anonymous> (test/media/vtt_text_parser_unit.js:328:5)
  
Chrome_55_0_2883_(Linux_0_0_0).VttTextParser VttTextParser uses relative timestamps if configured to FAILED
  Expected 'middle' to be 'center'.
      at verifyHelper (test/media/vtt_text_parser_unit.js:456:33)
      at Object.<anonymous> (test/media/vtt_text_parser_unit.js:345:5)
  

Failed 6 tests, passed 947, skipped 41

@joeyparrish
Copy link
Member

There are some tests that modify shaka.media.TextEngine.CueConstructor to simulate various behaviors from the platform. Looks like they will need to be updated to work on VTTCue now that CueConstructor is gone.

@joeyparrish
Copy link
Member

I have verified that these substitutions in test/media/ttml_text_parser_unit.js and test/media/vtt_text_parser_unit.js fix the issue:

originalCueConstructor => originalVTTCue
shaka.media.TextEngine.CueConstructor => window.VTTCue

I'll make these changes and manually merge. Thanks!

@joeyparrish
Copy link
Member

Merged as ca299b2.

joeyparrish pushed a commit that referenced this pull request Jan 17, 2017
This adds a VTTCue polyfill for IE/Edge (3-arg TextTrackCue) and
Toshiba dTV (6-arg TextTrackCue).

Closes #635
joeyparrish pushed a commit that referenced this pull request Jan 19, 2017
This adds a VTTCue polyfill for IE/Edge (3-arg TextTrackCue) and
Toshiba dTV (6-arg TextTrackCue).

Closes #635
@joeyparrish joeyparrish added the platform: TV/STB Issues affecting smart TV or set-top box platforms label Jul 17, 2018
@github-actions github-actions bot added the status: archived Archived and locked; will not be updated label Jul 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform: TV/STB Issues affecting smart TV or set-top box platforms status: archived Archived and locked; will not be updated type: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants