Skip to content

Commit

Permalink
feat: Add AC-3 and EC-3 support in Mp4Generator
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed May 16, 2023
1 parent 82e905b commit 428a89b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/mss/mss_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ shaka.mss.MssParser = class {
timescale: stream.mssPrivateData.timescale,
duration: stream.mssPrivateData.duration,
videoNalus: videoNalus,
audioConfig: new Uint8Array([]),
data: null, // Data is not necessary for init segement.
stream: stream,
};
Expand Down
1 change: 1 addition & 0 deletions lib/transmuxer/mp3_transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ shaka.transmuxer.Mp3Transmuxer = class {
timescale: sampleRate,
duration: duration,
videoNalus: [],
audioConfig: new Uint8Array([]),
data: {
sequenceNumber: this.frameIndex_,
baseMediaDecodeTime: baseMediaDecodeTime,
Expand Down
40 changes: 40 additions & 0 deletions lib/util/mp4_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ shaka.util.Mp4Generator = class {
/** @private {!Array.<string>} */
this.videoNalus_ = streamInfo.videoNalus;

/** @private {!Uint8Array} */
this.audioConfig_ = streamInfo.audioConfig;

/** @private {number} */
this.sequenceNumber_ = 0;

Expand Down Expand Up @@ -310,6 +313,10 @@ shaka.util.Mp4Generator = class {
this.stream_.codecs.includes('mp3') ||
this.stream_.codecs.includes('mp4a.40.34')) {
bytes = this.mp3_();
} else if (this.stream_.codecs.includes('ac-3')) {
bytes = this.dac3_();
} else if (this.stream_.codecs.includes('ec-3')) {
bytes = this.dec3_();
} else {
bytes = this.mp4a_();
}
Expand Down Expand Up @@ -471,6 +478,36 @@ shaka.util.Mp4Generator = class {
return Mp4Generator.box('.mp3', this.audioStsd_());
}

/**
* Generate a DAC3 box
*
* @return {!Uint8Array}
* @private
*/
dac3_() {
const Mp4Generator = shaka.util.Mp4Generator;
let boxName = 'dac3';
if (this.stream_.encrypted) {
boxName = 'enca';
}
return Mp4Generator.box(boxName, this.audioStsd_(), this.audioConfig_);
}

/**
* Generate a DEC3 box
*
* @return {!Uint8Array}
* @private
*/
dec3_() {
const Mp4Generator = shaka.util.Mp4Generator;
let boxName = 'dec3';
if (this.stream_.encrypted) {
boxName = 'enca';
}
return Mp4Generator.box(boxName, this.audioStsd_(), this.audioConfig_);
}

/**
* Generate a MP4A box
*
Expand Down Expand Up @@ -1147,6 +1184,7 @@ shaka.util.Mp4Generator.DINF_ = new Uint8Array([]);
* timescale: number,
* duration: number,
* videoNalus: !Array.<string>,
* audioConfig: !Uint8Array,
* data: ?shaka.util.Mp4Generator.Data,
* stream: !shaka.extern.Stream
* }}
Expand All @@ -1157,6 +1195,8 @@ shaka.util.Mp4Generator.DINF_ = new Uint8Array([]);
* The Stream's duration.
* @property {!Array.<string>} videoNalus
* The stream's video nalus.
* @property {!Uint8Array} audioConfig
* The stream's audio config.
* @property {?shaka.util.Mp4Generator.Data} data
* The stream's data.
* @property {!shaka.extern.Stream} stream
Expand Down

0 comments on commit 428a89b

Please sign in to comment.