Skip to content

Commit

Permalink
add elementary stream type enum
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkim9 committed Jan 11, 2018
1 parent ed89ce5 commit 3cdffb8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/controller/audio-stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {logger} from '../utils/logger';
import { findFragWithCC } from '../utils/discontinuities';
import TaskLoop from '../task-loop';
import {FragmentState} from '../helper/fragment-tracker';
import Fragment from '../loader/fragment';

const State = {
STOPPED : 'STOPPED',
Expand Down Expand Up @@ -645,7 +646,7 @@ class AudioStreamController extends TaskLoop {
data.endDTS = data.startDTS + fragCurrent.duration;
}

fragCurrent.addElementaryStream(data.type);
fragCurrent.addElementaryStream(Fragment.ElementaryStreamTypes.AUDIO);

logger.log(`parsed ${data.type},PTS:[${data.startPTS.toFixed(3)},${data.endPTS.toFixed(3)}],DTS:[${data.startDTS.toFixed(3)}/${data.endDTS.toFixed(3)}],nb:${data.nb}`);
LevelHelper.updateFragPTSDTS(track.details,fragCurrent,data.startPTS,data.endPTS);
Expand Down
9 changes: 8 additions & 1 deletion src/controller/stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import BufferHelper from '../helper/buffer-helper';
import Demuxer from '../demux/demuxer';
import Event from '../events';
import {FragmentState} from '../helper/fragment-tracker';
import Fragment from '../loader/fragment';
import * as LevelHelper from '../helper/level-helper';
import TimeRanges from '../utils/timeRanges';
import {ErrorTypes, ErrorDetails} from '../errors';
Expand Down Expand Up @@ -1090,7 +1091,13 @@ class StreamController extends TaskLoop {
data.endDTS = data.startDTS + fragCurrent.duration;
}

frag.addElementaryStream(data.type);
if(data.hasAudio === true) {
frag.addElementaryStream(Fragment.ElementaryStreamTypes.AUDIO);
}

if(data.hasVideo === true) {
frag.addElementaryStream(Fragment.ElementaryStreamTypes.VIDEO);
}

logger.log(`Parsed ${data.type},PTS:[${data.startPTS.toFixed(3)},${data.endPTS.toFixed(3)}],DTS:[${data.startDTS.toFixed(3)}/${data.endDTS.toFixed(3)}],nb:${data.nb},dropped:${data.dropped || 0}`);

Expand Down
24 changes: 19 additions & 5 deletions src/loader/fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,23 @@ export default class Fragment {
this._decryptdata = null;
this.tagList = [];

// Holds the type of data this fragment contains(eg. video/audio)
// Set is used because the elements should not repeat
this._elementaryStreams = new Set();
// Holds the types of data this fragment supports
this._elementaryStreams = {
[Fragment.ElementaryStreamTypes.AUDIO] : false,
[Fragment.ElementaryStreamTypes.VIDEO] : false
};
}

/**
* `type` property for this._elementaryStreams
*
* @enum
*/
static get ElementaryStreamTypes() {
return {
AUDIO: 'audio',
VIDEO: 'video'
};
}

get url() {
Expand Down Expand Up @@ -77,11 +91,11 @@ export default class Fragment {
* @param {ElementaryStreamType}
*/
addElementaryStream(type) {
this._elementaryStreams.add(type);
this._elementaryStreams[type] = true;
}

hasElementaryStream(type) {
return this._elementaryStreams.has(type) === true;
return this._elementaryStreams[type] === true;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/remux/mp4-remuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ class MP4Remuxer {
startDTS: firstDTS / timeScale,
endDTS: this.nextAvcDts / timeScale,
type: 'video',
hasAudio: false,
hasVideo: true,
nb: outputSamples.length,
dropped : dropped
};
Expand Down Expand Up @@ -674,6 +676,8 @@ class MP4Remuxer {
startDTS: start,
endDTS: end,
type: 'audio',
hasAudio: true,
hasVideo: false,
nb: nbSamples
};
this.observer.trigger(Event.FRAG_PARSING_DATA, audioData);
Expand Down
2 changes: 2 additions & 0 deletions src/remux/passthrough-remuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class PassThroughRemuxer {
startPTS: timeOffset,
startDTS: timeOffset,
type: streamType,
hasAudio: !!audioTrack,
hasVideo: !!videoTrack,
nb: 1,
dropped : 0
});
Expand Down

0 comments on commit 3cdffb8

Please sign in to comment.