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

Feat: change remux after initial creation #276

Merged
merged 2 commits into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
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
25 changes: 23 additions & 2 deletions lib/mp4/transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var AdtsStream = require('../codecs/adts.js');
var H264Stream = require('../codecs/h264').H264Stream;
var AacStream = require('../aac');
var isLikelyAacData = require('../aac/utils').isLikelyAacData;
var ONE_SECOND_IN_TS = require('../utils/clock').ONE_SECOND_IN_TS;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a required change but we use it this way in most other files. I think I missed this during the original rebase.


var ONE_SECOND_IN_TS = 90000; // 90kHz clock

// constants
var AUDIO_PROPERTIES = [
Expand Down Expand Up @@ -709,14 +709,21 @@ CoalesceStream = function(options, metadataStream) {
// important information required for the construction of
// the final segment
this.pendingTracks.push(output.track);
this.pendingBoxes.push(output.boxes);
this.pendingBytes += output.boxes.byteLength;

// TODO: is there an issue for this against chrome?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what caused the test change, and a lot of the headache I was seeing getting this to work

// We unshift audio and push video because
// as of Chrome 75 when switching from
// one init segment to another if the video
// mdat does not appear after the audio mdat
// only audio will play for the duration of our transmux.
if (output.track.type === 'video') {
this.videoTrack = output.track;
this.pendingBoxes.push(output.boxes);
}
if (output.track.type === 'audio') {
this.audioTrack = output.track;
this.pendingBoxes.unshift(output.boxes);
}
};
};
Expand Down Expand Up @@ -867,6 +874,10 @@ CoalesceStream.prototype.flush = function(flushSource) {
this.emittedTracks = 0;
}
};

CoalesceStream.prototype.setRemux = function(val) {
this.remuxTracks = val;
};
/**
* A Stream that expects MP2T binary data as input and produces
* corresponding media segments, suitable for use with Media Source
Expand Down Expand Up @@ -1119,6 +1130,16 @@ Transmuxer = function(options) {
}
};

this.setRemux = function(val) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows us to set the remux option after the transmuxer is created.

var pipeline = this.transmuxPipeline_;

options.remux = val;

if (pipeline && pipeline.coalesceStream) {
pipeline.coalesceStream.setRemux(val);
}
};

this.alignGopsWith = function(gopsToAlignWith) {
if (videoTrack && this.transmuxPipeline_.videoSegmentStream) {
this.transmuxPipeline_.videoSegmentStream.alignGopsWith(gopsToAlignWith);
Expand Down
3 changes: 1 addition & 2 deletions lib/partial/audio-segment-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var Stream = require('../utils/stream.js');
var mp4 = require('../mp4/mp4-generator.js');
var audioFrameUtils = require('../mp4/audio-frame-utils');
var trackInfo = require('../mp4/track-decode-info.js');
var ONE_SECOND_IN_TS = require('../utils/clock').ONE_SECOND_IN_TS;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a required change but we use it this way in most other files. I think I missed this during the original rebase.


// constants
var AUDIO_PROPERTIES = [
Expand All @@ -14,8 +15,6 @@ var AUDIO_PROPERTIES = [
'samplesize'
];

var ONE_SECOND_IN_TS = 90000; // 90kHz clock

/**
* Constructs a single-track, ISO BMFF media segment from AAC data
* events. The output of this stream can be fed to a SourceBuffer
Expand Down
9 changes: 9 additions & 0 deletions lib/partial/transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,15 @@ var Transmuxer = function(options) {
}
};

this.setRemux = function(val) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently this won't do anything as we don't have a coalesceStream for the partial transmuxer. This also means fmp4 and ts content will not work with the partial transmuxer right now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it was intentional that there is no coalesceStream for the partial transmuxer in order to reduce the time to return data

options.remux = val;

if (pipeline && pipeline.coalesceStream) {
pipeline.coalesceStream.setRemux(val);
}
};


this.setAudioAppendStart = function(audioAppendStart) {
if (!pipeline || !pipeline.tracks.audio || !pipeline.audioSegmentStream) {
return;
Expand Down
7 changes: 4 additions & 3 deletions test/transmuxer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3738,7 +3738,7 @@ validateTrackFragment = function(track, segment, metadata, type) {
QUnit.test('parses an example mp2t file and generates combined media segments', function() {
var
segments = [],
i, j, boxes, mfhd, trackType = 'video', trackId = 256, baseOffset = 0, initSegment;
i, j, boxes, mfhd, trackType = 'audio', trackId = 257, baseOffset = 0, initSegment;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we now always output video first, this test had to be changed.


transmuxer.on('data', function(segment) {
if (segment.type === 'combined') {
Expand Down Expand Up @@ -3780,15 +3780,16 @@ QUnit.test('parses an example mp2t file and generates combined media segments',
}

validateTrackFragment(boxes[i].boxes[1], segments[0].data, {
trackId: trackId++,
trackId: trackId,
width: 388,
height: 300,
baseOffset: baseOffset,
mdatOffset: boxes[i].size
}, trackType);

trackId--;
baseOffset = 0;
trackType = 'audio';
trackType = 'video';
}
}
});
Expand Down