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

Smooth Streaming Support : TTML Captions #1878

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
3 changes: 2 additions & 1 deletion src/mss/parser/MssParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ function MssParser(config) {
manifest.timeShiftBufferDepth = parseFloat(smoothStreamingMedia.getAttribute('DVRWindowLength')) / TIME_SCALE_100_NANOSECOND_UNIT;
manifest.mediaPresentationDuration = (parseFloat(smoothStreamingMedia.getAttribute('Duration')) === 0) ? Infinity : parseFloat(smoothStreamingMedia.getAttribute('Duration')) / TIME_SCALE_100_NANOSECOND_UNIT;
manifest.minBufferTime = mediaPlayerModel.getStableBufferTime();
manifest.ttmlTimeIsRelative = true;

// In case of live streams, set availabilityStartTime property according to DVRWindowLength
if (manifest.type === 'dynamic') {
Expand Down Expand Up @@ -597,4 +598,4 @@ function MssParser(config) {
}

MssParser.__dashjs_factory_name = 'MssParser';
export default FactoryMaker.getClassFactory(MssParser);
export default FactoryMaker.getClassFactory(MssParser);
1 change: 1 addition & 0 deletions src/streaming/MediaPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1928,6 +1928,7 @@ function MediaPlayer() {
textController = TextController(context).getInstance();
textController.setConfig({
errHandler: errHandler,
manifestModel: ManifestModel(context).getInstance(),
dashManifestModel: dashManifestModel,
mediaController: mediaController,
streamController: streamController,
Expand Down
5 changes: 5 additions & 0 deletions src/streaming/text/TextController.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function TextController() {
let allTracksAreDisabled,
errHandler,
dashManifestModel,
manifestModel,
mediaController,
videoModel,
streamController,
Expand Down Expand Up @@ -71,6 +72,9 @@ function TextController() {
if (config.dashManifestModel) {
dashManifestModel = config.dashManifestModel;
}
if (config.manifestModel) {
manifestModel = config.manifestModel;
}
if (config.mediaController) {
mediaController = config.mediaController;
}
Expand All @@ -94,6 +98,7 @@ function TextController() {
textSourceBuffer.setConfig({
errHandler: errHandler,
dashManifestModel: dashManifestModel,
manifestModel: manifestModel,
mediaController: mediaController,
videoModel: videoModel,
streamController: streamController,
Expand Down
9 changes: 8 additions & 1 deletion src/streaming/text/TextSourceBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function TextSourceBuffer() {
boxParser,
errHandler,
dashManifestModel,
manifestModel,
mediaController,
parser,
vttParser,
Expand Down Expand Up @@ -203,6 +204,9 @@ function TextSourceBuffer() {
if (config.dashManifestModel) {
dashManifestModel = config.dashManifestModel;
}
if (config.manifestModel) {
manifestModel = config.manifestModel;
}
if (config.mediaController) {
mediaController = config.mediaController;
}
Expand Down Expand Up @@ -328,7 +332,10 @@ function TextSourceBuffer() {
subOffset += sample.subSizes[j];
}
try {
result = parser.parse(ccContent, sampleStart / timescale, (sampleStart + sample.duration) / timescale, images);
// Only used for Miscrosoft Smooth Streaming support - caption time is relative to sample time. In this case, we apply an offset.
let manifest = manifestModel.getValue();
let offsetTime = manifest.ttmlTimeIsRelative ? sampleStart / timescale : 0;
result = parser.parse(ccContent, sampleStart / timescale, (sampleStart + sample.duration) / timescale, images, offsetTime);
textTracks.addCaptions(currFragmentedTrackIdx, firstSubtitleStart / timescale, result);
} catch (e) {
log('TTML parser error: ' + e.message);
Expand Down
10 changes: 6 additions & 4 deletions src/streaming/utils/TTMLParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,11 @@ function TTMLParser() {
* If intervalStart and intervalEnd defined, use them to clip the interval.
* Return null if no overlap with interval
*/
function getClippedInterval(entity, intervalStart, intervalEnd) {
function getClippedInterval(entity, intervalStart, intervalEnd, offsetTime) {
let startTime = parseTimings(entity.begin);
let endTime = parseTimings(entity.end);
startTime += offsetTime;
endTime += offsetTime;
startTime = clipStartTime(startTime, intervalStart);
endTime = clipEndTime(endTime, intervalEnd);
if (typeof intervalStart !== 'undefined' && typeof intervalEnd !== 'undefined') {
Expand Down Expand Up @@ -207,9 +209,9 @@ function TTMLParser() {
* @param {number} intervalStart
* @param {number} intervalEnd
* @param {array} imageArray - images represented as binary strings
* @param {number} offsetTime - offset time to apply to cue time
*/

function parse(data, intervalStart, intervalEnd, imageArray) {
function parse(data, intervalStart, intervalEnd, imageArray, offsetTime) {
let tt, // Top element
head, // head in tt
body, // body in tt
Expand Down Expand Up @@ -364,7 +366,7 @@ function TTMLParser() {
// The timing may either be on paragraph or span level.
if (paragraph.hasOwnProperty('begin') && paragraph.hasOwnProperty('end')) {
// Timing on paragraph level
let clippedInterval = getClippedInterval(paragraph, intervalStart, intervalEnd);
let clippedInterval = getClippedInterval(paragraph, intervalStart, intervalEnd, offsetTime);
if (clippedInterval !== null) {
cueIntervals.push(clippedInterval);
}
Expand Down