-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
User hooks for hls parser #1998
Closed
anuragkalia
wants to merge
5
commits into
shaka-project:main
from
anuragkalia:user-hooks-for-hls-parser
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
27049ac
Issue-1983: Add user hooks into HLS parser plugin
d794b4a
Add unit tests for onSegmentParsed
df301ce
Refactoring and documentation
1540464
Added type jsdoc + Changed SegmentParsedEvent
b83c2db
Fix: Build errors because of jsdoc
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,6 +266,21 @@ goog.require('shaka.util.StreamUtils'); | |
* @exportDoc | ||
*/ | ||
|
||
/** | ||
* @event shaka.Player.SegmentParsedEvent | ||
* @description Optionally fired from inside a manifest parser plugin if a newly | ||
* parsed segment has some extra metadata. | ||
* @property {string} type | ||
* 'segmentparsed' | ||
* @property {string} mimeType | ||
* Mime type of the manifest parser. | ||
* @property {number} streamId | ||
* Id of the stream that segment belonged to. | ||
* @property {*} segmentData | ||
* Its format depends on the manifest parser. | ||
* @exportDoc | ||
anuragkalia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
|
||
|
||
/** | ||
* @event shaka.Player.StreamingEvent | ||
|
@@ -1451,6 +1466,11 @@ shaka.Player = class extends shaka.util.FakeEventTarget { | |
// manifest). | ||
onTimelineRegionAdded: (region) => this.regionTimeline_.addRegion(region), | ||
|
||
// Called to signal new segment metadata upon parsing in the manifest | ||
// segment metadata can vary depending on mimeType and streamId | ||
onSegmentParsed: (mimeType, streamId, segment) => this.onSegmentParsed_( | ||
mimeType, streamId, segment), | ||
|
||
onEvent: (event) => this.dispatchEvent(event), | ||
onError: (error) => this.onError_(error), | ||
}; | ||
|
@@ -4249,6 +4269,26 @@ shaka.Player = class extends shaka.util.FakeEventTarget { | |
} | ||
} | ||
|
||
/** | ||
* Callback from player | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a method on Player, so this comment can't be right. |
||
* | ||
* @param {string} mimeType Mime type of the manifest parser. | ||
* @param {number} streamId Id of the stream that segment belonged to. | ||
* @param {*} segmentData Its format depends on the manifest parser. | ||
* @private | ||
*/ | ||
onSegmentParsed_(mimeType, streamId, segmentData) { | ||
const eventData = { | ||
mimeType, | ||
streamId, | ||
segmentData, | ||
}; | ||
|
||
this.dispatchEvent( | ||
new shaka.util.FakeEvent('segmentparsed', eventData) | ||
anuragkalia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
} | ||
|
||
/** | ||
* Callback from AbrManager. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,12 +124,22 @@ describe('HlsParser live', () => { | |
onError: fail, | ||
onEvent: fail, | ||
onTimelineRegionAdded: fail, | ||
onSegmentParsed: fail, | ||
}; | ||
|
||
parser = new shaka.hls.HlsParser(); | ||
parser.configure(config); | ||
}); | ||
|
||
/** @type {!jasmine.Spy} */ | ||
let onSegmentParsedSpy; | ||
|
||
beforeEach(() => { | ||
onSegmentParsedSpy = jasmine.createSpy('onSegmentParsed'); | ||
playerInterface.onSegmentParsed = | ||
shaka.test.Util.spyFunc(onSegmentParsedSpy); | ||
}); | ||
|
||
afterEach(() => { | ||
// HLS parser stop is synchronous. | ||
parser.stop(); | ||
|
@@ -555,6 +565,67 @@ describe('HlsParser live', () => { | |
master, media, [ref1], mediaWithAdditionalSegment, [ref1, ref2]); | ||
}); | ||
|
||
it('triggers segment parsed callbacks as segments appear', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for adding tests! |
||
const mediaWithAdditionalSegment = [ | ||
'#EXTM3U\n', | ||
'#EXT-X-PLAYLIST-TYPE:EVENT\n', | ||
'#EXT-X-TARGETDURATION:5\n', | ||
'#EXT-X-MAP:URI="init.mp4",BYTERANGE="616@0"\n', | ||
'#EXTINF:2,\n', | ||
'main.mp4\n', | ||
'#EXT-X-CUE:DURATION="201.467",ID="0",TYPE="SpliceOut",', | ||
'TIME="414.171"\n', | ||
'#EXTINF:2,\n', | ||
'main2.mp4\n', | ||
].join(''); | ||
|
||
fakeNetEngine | ||
.setResponseText('test:/master', master) | ||
.setResponseText('test:/video', media) | ||
.setResponseValue('test:/init.mp4', initSegmentData) | ||
.setResponseValue('test:/main.mp4', segmentData); | ||
|
||
const spy = jasmine.createSpy('start'); | ||
parser.start('test:/master', playerInterface) | ||
.then(Util.spyFunc(spy), fail); | ||
PromiseMock.flush(); | ||
|
||
expect(onSegmentParsedSpy).toHaveBeenCalledTimes(1); | ||
expect(onSegmentParsedSpy).toHaveBeenCalledWith( | ||
'application/vnd.apple.mpegurl', | ||
1, | ||
new shaka.hls.Segment( | ||
'test:/main.mp4', | ||
[ | ||
new shaka.hls.Tag(/* id */ 1, 'EXTINF', [], '2'), | ||
]) | ||
); | ||
|
||
// Replace the entries with the updated values. | ||
fakeNetEngine | ||
.setResponseText('test:/video', mediaWithAdditionalSegment); | ||
|
||
delayForUpdatePeriod(); | ||
|
||
expect(onSegmentParsedSpy).toHaveBeenCalledTimes(2); | ||
expect(onSegmentParsedSpy).toHaveBeenCalledWith( | ||
'application/vnd.apple.mpegurl', | ||
1, | ||
new shaka.hls.Segment( | ||
'test:/main2.mp4', | ||
[ | ||
new shaka.hls.Tag(/* id */ 1, 'EXTINF', [], '2'), | ||
new shaka.hls.Tag(/* id */ 2, 'EXT-X-CUE', [ | ||
new shaka.hls.Attribute('DURATION', '201.467'), | ||
new shaka.hls.Attribute('ID', '0'), | ||
new shaka.hls.Attribute('TYPE', 'SpliceOut'), | ||
new shaka.hls.Attribute('TIME', '414.171'), | ||
]), | ||
] | ||
) | ||
); | ||
}); | ||
|
||
it('evicts removed segments', () => { | ||
const ref1 = ManifestParser.makeReference('test:/main.mp4', | ||
0, 2, 4); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This seems particularly problematic to me. For one, it's not obvious what the DASH equivalent is to the HLS type you're sending through here. For another, the HLS type you're sending through here is an internal object, the format of which we should be free to change and the compiler should be free to rename. So I wouldn't want to send that outside the Player to the app.
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 am still in the beginning of how DASH spec but, from my limited understanding,
emsg
is the equivalent in DASH. (I saw thatemsg
is handled separately in code right now). I would like to be corrected on this one. Moreover, given shaka does not intend to be restricted to HLS and DASH but intends to support any manifest, is it not good to provide a general purpose function for extracting custom data from the manifest?I completely agree with the fact that right now we are sending an internal object directly. I did not account for the fact that users of the method could possibly mutate the object.
Thank you for your time and looking forward to your thoughts.
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.
After thinking a little more about it, I realized that a user can always write their own parser if they have to read the custom data from the manifest. That exactly is something I wanted to avoid and thus came up with this PR.
Also, though
emsg
indicates segment specific details, it seems to be a feature of mp4 rather than DASH. Am I correct here?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.
The 'emsg' box is an MP4 box, but it came out of the DASH spec if I remember correctly. There is a schema specified in DASH that means "reload the manifest when you see this". Shaka Player handles that directly, and passes any other schema up to the application.