Skip to content

Commit

Permalink
fix: do not wait for audio appends for muxed segments (#894)
Browse files Browse the repository at this point in the history
Co-authored-by: Garrett Singer <gesinger@gmail.com>
  • Loading branch information
brandonocasey and gesinger committed Jul 10, 2020
1 parent 8690c78 commit 406cbcd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
7 changes: 3 additions & 4 deletions src/media-segment-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ const transmuxAndNotify = ({
});
trackInfoFn = null;

if (probeResult.hasAudio) {
if (probeResult.hasAudio && !isMuxed) {
audioStartFn(probeResult.audioStart);
}
if (probeResult.hasVideo) {
Expand Down Expand Up @@ -411,7 +411,6 @@ const handleSegmentBytes = ({

if (tracks.video && tracks.audio) {
trackInfo.isMuxed = true;
trackInfo.hasAudio = false;
}

// since we don't support appending fmp4 data on progress, we know we have the full
Expand All @@ -425,7 +424,7 @@ const handleSegmentBytes = ({
// decoding).
const timingInfo = mp4probe.startTime(segment.map.timescales, bytesAsUint8Array);

if (trackInfo.hasAudio) {
if (trackInfo.hasAudio && !trackInfo.isMuxed) {
timingInfoFn(segment, 'audio', 'start', timingInfo);
}

Expand All @@ -438,7 +437,7 @@ const handleSegmentBytes = ({
// for it to be audio only. See `tracks.video && tracks.audio` if statement
// above.
// we make sure to use segment.bytes here as that
dataFn(segment, {data: bytes, type: trackInfo.hasAudio ? 'audio' : 'video'});
dataFn(segment, {data: bytes, type: trackInfo.hasAudio && !trackInfo.isMuxed ? 'audio' : 'video'});
if (captions && captions.length) {
captionsFn(segment, captions);
}
Expand Down
17 changes: 11 additions & 6 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,9 @@ export default class SegmentLoader extends videojs.EventTarget {
}

if (this.loaderType_ === 'main') {
const { hasAudio, hasVideo } = this.startingMedia_;
const { hasAudio, hasVideo, isMuxed } = this.startingMedia_;

if (hasVideo && hasAudio && !this.audioDisabled_) {
if (hasVideo && hasAudio && !this.audioDisabled_ && !isMuxed) {
return this.sourceUpdater_.buffered();
}

Expand Down Expand Up @@ -1684,11 +1684,14 @@ export default class SegmentLoader extends videojs.EventTarget {
}

if (!this.handlePartialData_) {
if (this.startingMedia_.hasVideo && !segmentInfo.videoTimingInfo) {
const {hasAudio, hasVideo, isMuxed} = this.startingMedia_;

if (hasVideo && !segmentInfo.videoTimingInfo) {
return false;
}

if (this.startingMedia_.hasAudio && !segmentInfo.audioTimingInfo) {
// muxed content only relies on video timing information for now.
if (hasAudio && !this.audioDisabled_ && !isMuxed && !segmentInfo.audioTimingInfo) {
return false;
}
}
Expand Down Expand Up @@ -2336,8 +2339,10 @@ export default class SegmentLoader extends videojs.EventTarget {
// Although transmuxing is done, appends may not yet be finished. Throw a marker
// on each queue this loader is responsible for to ensure that the appends are
// complete.
const waitForVideo = this.loaderType_ === 'main' && this.startingMedia_.hasVideo;
const waitForAudio = !this.audioDisabled_ && this.startingMedia_.hasAudio;
const {hasAudio, hasVideo, isMuxed} = this.startingMedia_;
const waitForVideo = this.loaderType_ === 'main' && hasVideo;
// TODO: does this break partial support for muxed content?
const waitForAudio = !this.audioDisabled_ && hasAudio && !isMuxed;

segmentInfo.waitingOnAppends = 0;

Expand Down
2 changes: 1 addition & 1 deletion test/master-playlist-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2930,7 +2930,7 @@ QUnit.test('parses codec from muxed fmp4 init segment', function(assert) {
'parsed video codec'
);
assert.deepEqual(loader.startingMedia_, {
hasAudio: false,
hasAudio: true,
hasVideo: true,
videoCodec: 'avc1.42c00d',
audioCodec: 'mp4a.40.2',
Expand Down

0 comments on commit 406cbcd

Please sign in to comment.