Skip to content
This repository has been archived by the owner on Jan 29, 2019. It is now read-only.

Start using remote TextTracks because they can be properly removed #118

Merged
merged 3 commits into from
Nov 18, 2016

Conversation

imbcmdth
Copy link
Member

We were using videojs.addTextTrack which creates TextTrack objects in memory and associates them with a video element. These are not removable from the video element once added. This PR switches to videojs.addRemoteTextTrackand then carefully removes them whenever the MediaSource is closed (in the Html5 case) or the HLS sourceHandler is disposed of (in the Flash case).

@@ -36,6 +37,12 @@ export default class FlashMediaSource extends videojs.EventTarget {
}
});

if (this.tech_.hls) {
this.tech_.hls.on('dispose', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that it looks like video.js' tech doesn't trigger dispose, but maybe we should consider adding it later, so we don't have to check for HLS specifically (or listening to a different type of event).

Copy link
Member Author

Choose a reason for hiding this comment

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

Techs do have a dispose but they are only dispose when switching techs (html->flash) but sourceHandlers have a dispose too and they trigger it whenever the source changes (their dispose gets triggered via HLSHandler's superclass in Component#dispose).

So while I agree that this line is kind of cludgy, it would be necessary since video.js will properly clean up remote text tracks whenever the source changes. This is just insurance that they get cleaned up even if using an older version of video.js.

});
sourceBuffer.segmentParser_.trigger('done');

QUnit.equal(addedTracks.length, 2, 'created two remote TextTracks');
Copy link
Contributor

Choose a reason for hiding this comment

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

We should check which ones were created.

Copy link
Member Author

Choose a reason for hiding this comment

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

We have tests that catch this scenario already and make sure the proper tracks are created for captions and metadata individually but it is a good idea to check that here for completeness.


QUnit.equal(addedTracks.length, 2, 'created two remote TextTracks');
this.player.tech_.hls.trigger('dispose');
QUnit.equal(removedTracks.length, 2, 'removed both TextTracks');
Copy link
Contributor

Choose a reason for hiding this comment

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

Same for checking which ones removed.

Copy link
Member Author

Choose a reason for hiding this comment

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

We have tests that catch this scenario already and make sure the proper tracks are created for captions and metadata individually but it is a good idea to check that here for completeness.

sourceBuffer.transmuxer_.onmessage(createDataMessage('video', new Uint8Array(1), {
metadata
}));
sourceBuffer.transmuxer_.onmessage(createDataMessage('video', new Uint8Array(1), {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we check in-between these two messages?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nah, in fact I should just collapse the two messages into one. No reason to keep both. Thanks for pointing that out.

@@ -11,18 +12,27 @@
* @private
*/
const createTextTracksIfNecessary = function(sourceBuffer, mediaSource, segment) {
Copy link
Contributor

Choose a reason for hiding this comment

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

May be worth adding tests for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is tested already in several places but what isn't tested right now is the removeExistingTrack behavior which is new. Good point.

QUnit.equal(addedTracks.length, 2, 'created two text tracks');
QUnit.equal(addedTracks.filter(t => ['captions', 'metadata'].indexOf(t.kind) === -1).length,
0,
'created only the expected two remote TextTracks');
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's overboard, since the remove should be fine, but it might be worth checking to verify that the newly created tracks are the new ones.

@imbcmdth imbcmdth merged commit 24e0177 into master Nov 18, 2016
@imbcmdth imbcmdth deleted the use-remote-text-tracks branch November 18, 2016 20:31
imbcmdth added a commit that referenced this pull request Dec 5, 2016
)

* Start using remote TextTracks because they can be properly removed and are better in every way.

* Added tests for the flash and html5 text track cleanup scenarios

* Added and improved some tests for text tracks changes
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants