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

Add support for sidx segments #207

Closed
wants to merge 1 commit into from
Closed
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
22 changes: 22 additions & 0 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { TIME_FUDGE_FACTOR, timeUntilRebuffer as timeUntilRebuffer_ } from './ra
import { minRebufferMaxBandwidthSelector } from './playlist-selectors';
import { addCaptionData, createCaptionsTrackIfNotExists } from './util/text-tracks';
import { CaptionParser } from 'mux.js/lib/mp4';
import mp4Inspector from 'mux.js/lib/tools/mp4-inspector.js';
import logger from './util/logger';

// in ms
Expand Down Expand Up @@ -1136,6 +1137,27 @@ export default class SegmentLoader extends videojs.EventTarget {

segmentInfo.endOfAllRequests = simpleSegment.endOfAllRequests;

// See if this segment is a sidx box
if (new TextDecoder('utf-8').decode(segmentInfo.bytes.slice(4,8)) === 'sidx') {
segmentInfo.duration = 0;
var sidx = mp4Inspector.parseSidx(segmentInfo.bytes.slice(8));
var offset = simpleSegment.byterange.length + simpleSegment.byterange.offset;

for (var i = 0; i < sidx.references.length; i++) {
segmentInfo.playlist.segments.push({
byterange: {
length: sidx.references[i].referencedSize,
offset: offset
},
duration: sidx.references[i].referencedSize / sidx.timescale,
uri: simpleSegment.uri,
resolvedUri: simpleSegment.resolvedUri
});

offset += sidx.references[i].referencedSize;
}
}

// This has fmp4 captions, add them to text tracks
if (simpleSegment.fmp4Captions) {
createCaptionsTrackIfNotExists(
Expand Down