-
Notifications
You must be signed in to change notification settings - Fork 793
Add a segment-metadata TextTrack that contains cues for the segments currently in the buffer #976
Conversation
src/master-playlist-controller.js
Outdated
|
||
// for now we don't want the audio segment loader to also add cues to the segment | ||
// metadata track | ||
delete segmentLoaderOptions.segmentMetadataTrack; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to create two different objects.
Perhaps using Object.create
to make the mainSegmentLoader_
's object with segmentMetadataTrack
added to the base object.
d19ef4d
to
e490c7f
Compare
src/segment-loader.js
Outdated
end | ||
}; | ||
const Cue = window.WebKitDataCue || window.VTTCue; | ||
const data = JSON.stringify(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be more useful to just merge these properties onto the created cue object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean if say you wanted the uri, accessing it should look like cue.uri
instead of cue.value.uri
?
src/segment-loader.js
Outdated
* @method addSegmentMetadataCue_ | ||
*/ | ||
addSegmentMetadataCue_(segmentInfo) { | ||
if (!this.segmentMetadataTrack_ || !segmentInfo) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we have to be guarding against these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right with not needing a check for segmentInfo
but i think for check for the track is still needed since both the main and audio segment loaders are instances of this class, but the audio segment loader doesnt have a segment metadata track, so we just want this function to be a noop in that case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call on checking for segmentMetadataTrack_
src/segment-loader.js
Outdated
const cue = new Cue(start, end, data); | ||
|
||
value.data = data; | ||
cue.value = value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So cue ends up with a stringified value
for its text, then has a value property which has the value
object, including the stringified value
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and no. It mainly depends on the const Cue = window.WebKitDataCue || window.VTTCue;
line. I was following what is done in contrib-media-sources when adding id3 tags, but WebKitDataCue
is only in safari right now, and there are some small differences between WebKitDataCue
and VTTCue
. Mainly, WebKitDataCue
does not have a text
property but instead a value
. For id3 tags this value
property has a key
and data
property usually. My goal with these lines was to minimize the differences between the two cues so that you can just use cue.value
in all the browsers. After having to explain this, it may just be better to only use VTTCue
and not jump through all these hoops
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think keeping Safari support is a good idea (just in case). Maybe a comment and/or some kind of helper method would help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well VTTCue
is supported in safari, its just that WebKitDataCue
is only supported in safari. Is it best practice to use these types of cues for certain purposes, or are they more general purpose and its not "wrong" to just use the VTTCue
for safari as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deciding to stick with what we do for id3 metadata tags since these cues are another form of metadata
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok to do here since it's fairly simple and we're creating metadata tracks.
test/segment-loader.test.js
Outdated
// verify stats | ||
assert.equal(loader.mediaBytesTransferred, 30, '10 bytes'); | ||
assert.equal(loader.mediaRequests, 3, '1 request'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would also be worth testing the behavior with overlapping times from a different timeline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a test for overlapping segments is definitely a good call. I don't think being on a different timeline makes a different and needs to be tested. At the point of creating the cues, the start and end times have been converted to display time, so the non-congruent timestamps across discontinuities are not a factor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
README.md
Outdated
### Segment Metadata | ||
You can get metadata about the segments currently in the buffer by using the `segment-metadata` | ||
text track. You can get the metadata of the currently rendered segment by looking at the | ||
tracks `activeCues` array. The metadata will be attached to the `cue.value` property and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
track's
README.md
Outdated
|
||
```javascript | ||
cue.value = { | ||
uri: The Segment uri, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually for JS blocks it's good to try to keep it as standard JS. Maybe something like:
cue.value = {
uri, // segment uri
...
};
// or:
let data = cue.value;
data.uri; // the segment uri
...
README.md
Outdated
```javascript | ||
cue.value = { | ||
uri: The Segment uri, | ||
timeline: Timeline of the segment, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be useful to say what the timeline is
src/segment-loader.js
Outdated
return; | ||
} | ||
|
||
const playlist = segmentInfo.playlist; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can get rid of this and just use segmentInfo.playlist.uri
below
b5ad752
to
bac2f7b
Compare
Tested, but with the same code I can't get it working on IE11/Windows 7 (not even getting |
Looks good to me |
Description
Currently, we do not expose or track segment information for the segments that are currently in the actual buffer. Being able to know which segment or rendition is currently being rendered on screen has been a much requested feature. This addition allows users to listen to
cuechange
events on the track and see the segment information for the currently rendered segment in the active cues list.Specific Changes proposed
segment-metadata
Requirements Checklist