Skip to content

Commit

Permalink
Support playback and audio track switching of audio-only stream with …
Browse files Browse the repository at this point in the history
…main audio and alt audio
  • Loading branch information
Rob Walch committed Jun 9, 2020
1 parent c0d73ce commit dd6c926
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/controller/buffer-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,17 @@ class BufferController extends EventHandler {
}
}

onManifestParsed (data: { altAudio: boolean }) {
// in case of alt audio 2 BUFFER_CODECS events will be triggered, one per stream controller
onManifestParsed (data: { altAudio: boolean, audio: boolean, video: boolean }) {
// in case of alt audio (where all tracks have urls) 2 BUFFER_CODECS events will be triggered, one per stream controller
// sourcebuffers will be created all at once when the expected nb of tracks will be reached
// in case alt audio is not used, only one BUFFER_CODEC event will be fired from main stream controller
// it will contain the expected nb of source buffers, no need to compute it
this.bufferCodecEventsExpected = this._bufferCodecEventsTotal = data.altAudio ? 2 : 1;
let codecEvents: number = 2;
if (data.audio && !data.video || !data.altAudio) {
codecEvents = 1;
}
this.bufferCodecEventsExpected = this._bufferCodecEventsTotal = codecEvents;

logger.log(`${this.bufferCodecEventsExpected} bufferCodec event(s) expected`);
}

Expand Down
7 changes: 5 additions & 2 deletions src/remux/mp4-remuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class MP4Remuxer {
typeSupported = this.typeSupported,
container = 'audio/mp4',
tracks = {},
data = { tracks: tracks },
data = { tracks },
computePTSDTS = (this._initPTS === undefined),
initPTS, initDTS;

Expand Down Expand Up @@ -165,8 +165,11 @@ class MP4Remuxer {
if (computePTSDTS) {
initPTS = Math.min(initPTS, videoSamples[0].pts - inputTimeScale * timeOffset);
initDTS = Math.min(initDTS, videoSamples[0].dts - inputTimeScale * timeOffset);
this.observer.trigger(Event.INIT_PTS_FOUND, { initPTS: initPTS });
this.observer.trigger(Event.INIT_PTS_FOUND, { initPTS });
}
} else if (computePTSDTS && tracks.audio) {
// initPTS found for audio-only stream with main and alt audio
this.observer.trigger(Event.INIT_PTS_FOUND, { initPTS });
}

if (Object.keys(tracks).length) {
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/controller/buffer-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ describe('BufferController tests', function () {
expect(bufferController.bufferCodecEventsExpected).to.equal(2);
});

it('expects one bufferCodec event if altAudio is signaled with audio only', function () {
bufferController.onManifestParsed({ altAudio: true, audio: true, video: false });
expect(bufferController.bufferCodecEventsExpected).to.equal(1);
});

it('creates sourceBuffers when no more BUFFER_CODEC events are expected', function () {
bufferController.pendingTracks = { video: {} };

Expand Down

0 comments on commit dd6c926

Please sign in to comment.