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

feat: Add a Mp4Generator #5127

Merged
merged 3 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/types/core
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
+../../lib/util/media_ready_state_utils.js
+../../lib/util/mime_utils.js
+../../lib/util/mp4_box_parsers.js
+../../lib/util/mp4_generator.js
+../../lib/util/mp4_parser.js
+../../lib/util/multi_map.js
+../../lib/util/networking.js
Expand Down
1 change: 0 additions & 1 deletion build/types/mss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

+../../lib/mss/content_protection.js
+../../lib/mss/mss_parser.js
+../../lib/mss/mss_utils.js

+../../lib/transmuxer/mss_transmuxer.js
40 changes: 26 additions & 14 deletions lib/mss/mss_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ goog.require('shaka.media.PresentationTimeline');
goog.require('shaka.media.SegmentIndex');
goog.require('shaka.media.SegmentReference');
goog.require('shaka.mss.ContentProtection');
goog.require('shaka.mss.MssUtils');
goog.require('shaka.net.NetworkingEngine');
goog.require('shaka.util.Error');
goog.require('shaka.util.ManifestParserUtils');
goog.require('shaka.util.Mp4Generator');
goog.require('shaka.util.OperationManager');
goog.require('shaka.util.Timer');
goog.require('shaka.util.XmlUtils');
goog.require('shaka.dependencies');


/**
Expand Down Expand Up @@ -485,6 +484,13 @@ shaka.mss.MssParser = class {
const audioSamplingRate = XmlUtils.parseAttr(
qualityLevel, 'SamplingRate', XmlUtils.parsePositiveInt);

let duration = context.duration;
if (timeline.length) {
const start = timeline[0].start;
const end = timeline[timeline.length - 1].end;
duration = end - start;
}

/** @type {!shaka.extern.Stream} */
const stream = {
id: id,
Expand Down Expand Up @@ -519,7 +525,7 @@ shaka.mss.MssParser = class {
tilesLayout: undefined,
matchedStreams: [],
mssPrivateData: {
duration: context.duration,
duration: duration,
timescale: context.timescale,
codecPrivateData: null,
},
Expand Down Expand Up @@ -612,7 +618,16 @@ shaka.mss.MssParser = class {
if (this.initSegmentDataByStreamId_.has(stream.id)) {
initSegmentData = this.initSegmentDataByStreamId_.get(stream.id);
} else {
initSegmentData = shaka.mss.MssUtils.generateInitSegment(stream);
const timescale = stream.mssPrivateData.timescale;
const duration = stream.mssPrivateData.duration;
let videoNalus = null;
if (stream.type == ContentType.VIDEO) {
const codecPrivateData = stream.mssPrivateData.codecPrivateData;
videoNalus = codecPrivateData.split('00000001').slice(1);
}
const mp4Generator = new shaka.util.Mp4Generator(
stream, timescale, duration, videoNalus);
initSegmentData = mp4Generator.initSegment();
this.initSegmentDataByStreamId_.set(stream.id, initSegmentData);
}
const initSegmentRef = new shaka.media.InitSegmentReference(
Expand All @@ -624,7 +639,7 @@ shaka.mss.MssParser = class {
initSegmentData);

const segments = this.createSegments_(initSegmentRef,
stream, streamIndex, timeline, context);
stream, streamIndex, timeline);

stream.segmentIndex = new shaka.media.SegmentIndex(segments);
return Promise.resolve();
Expand Down Expand Up @@ -784,11 +799,10 @@ shaka.mss.MssParser = class {
* @param {!shaka.extern.Stream} stream
* @param {!Element} streamIndex
* @param {!Array.<shaka.mss.MssParser.TimeRange>} timeline
* @param {!shaka.mss.MssParser.Context} context
* @return {!Array.<!shaka.media.SegmentReference>}
* @private
*/
createSegments_(initSegmentRef, stream, streamIndex, timeline, context) {
createSegments_(initSegmentRef, stream, streamIndex, timeline) {
const ManifestParserUtils = shaka.util.ManifestParserUtils;
const url = streamIndex.getAttribute('Url');
goog.asserts.assert(url, 'Missing URL for segments');
Expand All @@ -810,7 +824,7 @@ shaka.mss.MssParser = class {
initSegmentRef,
/* timestampOffset= */ 0,
/* appendWindowStart= */ 0,
/* appendWindowEnd= */ context.duration));
/* appendWindowEnd= */ stream.mssPrivateData.duration));
}
return segments;
}
Expand Down Expand Up @@ -1043,9 +1057,7 @@ shaka.mss.MssParser.Context;
*/
shaka.mss.MssParser.TimeRange;

if (shaka.dependencies.isoBoxer()) {
shaka.media.ManifestParser.registerParserByExtension(
'ism', () => new shaka.mss.MssParser());
shaka.media.ManifestParser.registerParserByMime(
'application/vnd.ms-sstr+xml', () => new shaka.mss.MssParser());
}
shaka.media.ManifestParser.registerParserByExtension(
'ism', () => new shaka.mss.MssParser());
shaka.media.ManifestParser.registerParserByMime(
'application/vnd.ms-sstr+xml', () => new shaka.mss.MssParser());
Loading