Skip to content

Commit

Permalink
[JW8-8993] Refactor minProbeByteLength to only be enforced on transmu…
Browse files Browse the repository at this point in the history
…xer flush (#215)

* Refactor minProbeByteLength to only be enforced on transmuxer flush JW8-8993
  • Loading branch information
John Bartos authored Jun 6, 2019
1 parent 488eeaf commit 6c88fa6
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 187 deletions.
2 changes: 1 addition & 1 deletion src/controller/audio-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ class AudioStreamController extends BaseStreamController {
// time Offset is accurate if level PTS is known, or if playlist is not sliding (not live)
let accurateTimeOffset = false; // details.PTSKnown || !details.live;
const transmuxIdentifier = { level: frag.level, sn: frag.sn };
transmuxer.push(payload, initSegmentData, audioCodec, '', frag, details.totalduration, accurateTimeOffset, initPTS, transmuxIdentifier);
transmuxer.push(payload, initSegmentData, audioCodec, '', frag, details.totalduration, accurateTimeOffset, transmuxIdentifier, initPTS);
}

onBufferReset () {
Expand Down
1 change: 0 additions & 1 deletion src/controller/stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,6 @@ export default class StreamController extends BaseStreamController {
frag,
details.totalduration,
accurateTimeOffset,
null,
transmuxIdentifier
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/demux/mp4demuxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { findBox, segmentValidRange, appendUint8Array } from '../utils/mp4-tools
import { dummyTrack } from './dummy-demuxed-track';

class MP4Demuxer implements Demuxer {
static readonly minProbeByteLength = 16384; // 16kb;
static readonly minProbeByteLength = 1024;
private remainderData: Uint8Array | null = null;

resetTimeStamp () {
Expand Down
63 changes: 25 additions & 38 deletions src/demux/transmuxer-interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as work from 'webworkify-webpack';
import Event from '../events';
import Transmuxer from '../demux/transmuxer';
import Transmuxer, { TransmuxConfig, TransmuxState } from '../demux/transmuxer';
import { logger } from '../utils/logger';
import { ErrorTypes, ErrorDetails } from '../errors';
import { getMediaSource } from '../utils/mediasource-helper';
Expand Down Expand Up @@ -100,29 +100,28 @@ export default class TransmuxerInterface {
}
}

push (data: Uint8Array, initSegment: any, audioCodec: string, videoCodec: string, frag: Fragment, duration: number, accurateTimeOffset: boolean, defaultInitPTS: number | null, transmuxIdentifier: TransmuxIdentifier): void {
push (data: Uint8Array, initSegment: any, audioCodec: string, videoCodec: string, frag: Fragment, duration: number, accurateTimeOffset: boolean, transmuxIdentifier: TransmuxIdentifier, defaultInitPTS?: number): void {
const { currentTransmuxSession, transmuxer, worker } = this;
const timeOffset = Number.isFinite(frag.startPTS) ? frag.startPTS : frag.start;
const decryptdata = frag.decryptdata;
const lastFrag = this.frag;

let contiguous = true;
let discontinuity = false;
let trackSwitch = false;

if (startingNewTransmuxSession(currentTransmuxSession, transmuxIdentifier)) {
discontinuity = !(lastFrag && (frag.cc === lastFrag.cc));
trackSwitch = !(lastFrag && (frag.level === lastFrag.level));
const nextSN = !!(lastFrag && (frag.sn === (lastFrag.sn as number + 1)));
contiguous = !trackSwitch && nextSN;
const discontinuity = !(lastFrag && (frag.cc === lastFrag.cc));
const trackSwitch = !(lastFrag && (frag.level === lastFrag.level));
const nextSN = !!(lastFrag && (frag.sn === (lastFrag.sn as number + 1)));
const contiguous = !trackSwitch && nextSN;

logger.log(`[transmuxer-interface, ${frag.type}]: Starting new transmux session for fragment ${frag.sn}, of level ${frag.level}:
logger.log(`[transmuxer-interface, ${frag.type}]: Starting new transmux session for fragment ${frag.sn}, of level ${frag.level}:
discontinuity: ${discontinuity}
trackSwitch: ${trackSwitch}
contiguous: ${contiguous}
accurateTimeOffset: ${accurateTimeOffset}
timeOffset: ${timeOffset}`);
this.currentTransmuxSession = transmuxIdentifier;
this.currentTransmuxSession = transmuxIdentifier;
const config = new TransmuxConfig(audioCodec, videoCodec, new Uint8Array(initSegment), duration, defaultInitPTS);
const state = new TransmuxState(discontinuity, contiguous, accurateTimeOffset, trackSwitch, timeOffset);
this.configureTransmuxer(config, state);
}

this.frag = frag;
Expand All @@ -133,34 +132,10 @@ export default class TransmuxerInterface {
cmd: 'demux',
data,
decryptdata,
initSegment,
audioCodec,
videoCodec,
timeOffset,
discontinuity,
trackSwitch,
contiguous,
duration,
accurateTimeOffset,
defaultInitPTS,
transmuxIdentifier
}, data instanceof ArrayBuffer ? [data] : []);
} else if (transmuxer) {
const transmuxResult =
transmuxer.push(data,
decryptdata,
initSegment,
audioCodec,
videoCodec,
timeOffset,
discontinuity,
trackSwitch,
!!contiguous,
duration,
accurateTimeOffset,
defaultInitPTS,
transmuxIdentifier
);
const transmuxResult = transmuxer.push(data, decryptdata, transmuxIdentifier);
if (!transmuxResult) {
return;
}
Expand All @@ -177,7 +152,6 @@ export default class TransmuxerInterface {
}
}

// TODO: handle non-worker flush return
flush (transmuxIdentifier: TransmuxIdentifier) {
const { transmuxer, worker } = this;
if (worker) {
Expand Down Expand Up @@ -231,6 +205,19 @@ export default class TransmuxerInterface {
}
}
}

private configureTransmuxer (config: TransmuxConfig, state: TransmuxState) {
const { worker, transmuxer } = this;
if (worker) {
worker.postMessage({
cmd: 'configure',
config,
state
})
} else if (transmuxer) {
transmuxer.configure(config, state);
}
}
}

function startingNewTransmuxSession (currentIdentifier: TransmuxIdentifier | null, newIdentifier: TransmuxIdentifier) {
Expand Down
21 changes: 5 additions & 16 deletions src/demux/transmuxer-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default function TransmuxerWorker (self) {

self.addEventListener('message', (ev) => {
const data = ev.data;
// console.log('transmuxer cmd:' + data.cmd);
switch (data.cmd) {
case 'init': {
const config = JSON.parse(data.config);
Expand All @@ -39,22 +38,12 @@ export default function TransmuxerWorker (self) {
forwardMessage('init', null);
break;
}
case 'configure': {
self.transmuxer.configure(data.config, data.state);
break;
}
case 'demux': {
const transmuxResult: TransmuxerResult = self.transmuxer.push(data.data,
data.decryptdata,
data.initSegment,
data.audioCodec,
data.videoCodec,
data.timeOffset,
data.discontinuity,
data.trackSwitch,
data.contiguous,
data.duration,
data.accurateTimeOffset,
data.defaultInitPTS,
data.transmuxIdentifier
);

const transmuxResult: TransmuxerResult = self.transmuxer.push(data.data, data.decryptdata, data.transmuxIdentifier);
if (!transmuxResult) {
return;
}
Expand Down
Loading

0 comments on commit 6c88fa6

Please sign in to comment.