Skip to content

Commit

Permalink
Merge pull request #1364 from jwplayer/upstream/feature/support-aac-w…
Browse files Browse the repository at this point in the history
…ithout-id3

Allow AAC streams without ID3 to play
  • Loading branch information
mangui committed Sep 22, 2017
2 parents 04caab6 + fe34627 commit 67c6959
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
41 changes: 22 additions & 19 deletions src/demux/aacdemuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,35 @@ class AACDemuxer {
}

static probe(data) {
// check if data contains ID3 timestamp and ADTS sync word
var offset, length;
let id3Data = ID3.getID3Data(data, 0);
if (id3Data && ID3.getTimeStamp(id3Data) !== undefined) {
// Look for ADTS header | 1111 1111 | 1111 X00X | where X can be either 0 or 1
// Layer bits (position 14 and 15) in header should be always 0 for ADTS
// More info https://wiki.multimedia.cx/index.php?title=ADTS
for (offset = id3Data.length, length = Math.min(data.length - 1, offset + 100); offset < length; offset++) {
if (ADTS.probe(data, offset)) {
logger.log('ADTS sync word found !');
return true;
}
if (!data) {
return false;
}
// Check for the ADTS sync word
// Look for ADTS header | 1111 1111 | 1111 X00X | where X can be either 0 or 1
// Layer bits (position 14 and 15) in header should be always 0 for ADTS
// More info https://wiki.multimedia.cx/index.php?title=ADTS
const id3Data = ID3.getID3Data(data, 0) || [];
let offset = id3Data.length;

for (let length = data.length; offset < length; offset++) {
if (ADTS.probe(data, offset)) {
logger.log('ADTS sync word found !');
return true;
}
}
return false;
}

// feed incoming data to the front of the parsing pipeline
append(data, timeOffset, contiguous, accurateTimeOffset) {
var track = this._audioTrack,
id3Data = ID3.getID3Data(data, 0),
pts = 90 * ID3.getTimeStamp(id3Data),
frameIndex = 0,
stamp = pts,
length = data.length,
offset = id3Data.length;
let track = this._audioTrack;
let id3Data = ID3.getID3Data(data, 0) || [];
let timestamp = ID3.getTimeStamp(id3Data);
let pts = timestamp ? 90 * timestamp : timeOffset * 90000;
let frameIndex = 0;
let stamp = pts;
let length = data.length;
let offset = id3Data.length;

let id3Samples = [{ pts: stamp, dts: stamp, data: id3Data }];

Expand Down
12 changes: 7 additions & 5 deletions src/demux/demuxer-inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ class DemuxerInline {
const observer = this.observer;
const typeSupported = this.typeSupported;
const config = this.config;
// probing order is AAC/MP3/TS/MP4
const muxConfig = [{ demux: AACDemuxer, remux: MP4Remuxer },
{ demux: MP3Demuxer, remux: MP4Remuxer },
{ demux: TSDemuxer, remux: MP4Remuxer },
{ demux: MP4Demuxer, remux: PassThroughRemuxer }];
// probing order is TS/AAC/MP3/MP4
const muxConfig = [
{ demux: TSDemuxer, remux: MP4Remuxer },
{ demux: AACDemuxer, remux: MP4Remuxer },
{ demux: MP3Demuxer, remux: MP4Remuxer },
{ demux: MP4Demuxer, remux: PassThroughRemuxer }
];

// probe for content type
for (let i = 0, len = muxConfig.length; i < len; i++) {
Expand Down

0 comments on commit 67c6959

Please sign in to comment.