Skip to content

Commit

Permalink
fix: Fix gaps produced by the transmuxer (#7822)
Browse files Browse the repository at this point in the history
Fixes #7462
Fixes #7780
  • Loading branch information
avelad authored Jan 3, 2025
1 parent d3238dd commit 934bdff
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 18 deletions.
14 changes: 11 additions & 3 deletions lib/transmuxer/aac_transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ shaka.transmuxer.AacTransmuxer = class {

/** @private {!Map.<string, !Uint8Array>} */
this.initSegments = new Map();

/** @private {?Uint8Array} */
this.lastInitSegment_ = null;
}


Expand Down Expand Up @@ -215,11 +218,16 @@ shaka.transmuxer.AacTransmuxer = class {
} else {
initSegment = this.initSegments.get(initSegmentKey);
}
const appendInitSegment = this.lastInitSegment_ !== initSegment;
const segmentData = mp4Generator.segmentData();

this.lastInitSegment_ = initSegment;
this.frameIndex_++;
const transmuxData = Uint8ArrayUtils.concat(initSegment, segmentData);
return Promise.resolve(transmuxData);
if (appendInitSegment) {
const transmuxData = Uint8ArrayUtils.concat(initSegment, segmentData);
return Promise.resolve(transmuxData);
} else {
return Promise.resolve(segmentData);
}
}
};

Expand Down
14 changes: 11 additions & 3 deletions lib/transmuxer/ac3_transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ shaka.transmuxer.Ac3Transmuxer = class {

/** @private {!Map.<string, !Uint8Array>} */
this.initSegments = new Map();

/** @private {?Uint8Array} */
this.lastInitSegment_ = null;
}


Expand Down Expand Up @@ -203,11 +206,16 @@ shaka.transmuxer.Ac3Transmuxer = class {
} else {
initSegment = this.initSegments.get(initSegmentKey);
}
const appendInitSegment = this.lastInitSegment_ !== initSegment;
const segmentData = mp4Generator.segmentData();

this.lastInitSegment_ = initSegment;
this.frameIndex_++;
const transmuxData = Uint8ArrayUtils.concat(initSegment, segmentData);
return Promise.resolve(transmuxData);
if (appendInitSegment) {
const transmuxData = Uint8ArrayUtils.concat(initSegment, segmentData);
return Promise.resolve(transmuxData);
} else {
return Promise.resolve(segmentData);
}
}
};

Expand Down
14 changes: 11 additions & 3 deletions lib/transmuxer/ec3_transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ shaka.transmuxer.Ec3Transmuxer = class {

/** @private {!Map.<string, !Uint8Array>} */
this.initSegments = new Map();

/** @private {?Uint8Array} */
this.lastInitSegment_ = null;
}


Expand Down Expand Up @@ -203,11 +206,16 @@ shaka.transmuxer.Ec3Transmuxer = class {
} else {
initSegment = this.initSegments.get(initSegmentKey);
}
const appendInitSegment = this.lastInitSegment_ !== initSegment;
const segmentData = mp4Generator.segmentData();

this.lastInitSegment_ = initSegment;
this.frameIndex_++;
const transmuxData = Uint8ArrayUtils.concat(initSegment, segmentData);
return Promise.resolve(transmuxData);
if (appendInitSegment) {
const transmuxData = Uint8ArrayUtils.concat(initSegment, segmentData);
return Promise.resolve(transmuxData);
} else {
return Promise.resolve(segmentData);
}
}
};

Expand Down
14 changes: 11 additions & 3 deletions lib/transmuxer/mp3_transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ shaka.transmuxer.Mp3Transmuxer = class {

/** @private {!Map.<string, !Uint8Array>} */
this.initSegments = new Map();

/** @private {?Uint8Array} */
this.lastInitSegment_ = null;
}


Expand Down Expand Up @@ -196,11 +199,16 @@ shaka.transmuxer.Mp3Transmuxer = class {
} else {
initSegment = this.initSegments.get(initSegmentKey);
}
const appendInitSegment = this.lastInitSegment_ !== initSegment;
const segmentData = mp4Generator.segmentData();

this.lastInitSegment_ = initSegment;
this.frameIndex_++;
const transmuxData = Uint8ArrayUtils.concat(initSegment, segmentData);
return Promise.resolve(transmuxData);
if (appendInitSegment) {
const transmuxData = Uint8ArrayUtils.concat(initSegment, segmentData);
return Promise.resolve(transmuxData);
} else {
return Promise.resolve(segmentData);
}
}
};

Expand Down
14 changes: 11 additions & 3 deletions lib/transmuxer/ts_transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ shaka.transmuxer.TsTransmuxer = class {

/** @private {?shaka.transmuxer.AacTransmuxer} */
this.aacTransmuxer_ = null;

/** @private {?Uint8Array} */
this.lastInitSegment_ = null;
}


Expand Down Expand Up @@ -293,11 +296,16 @@ shaka.transmuxer.TsTransmuxer = class {
} else {
initSegment = this.initSegments.get(initSegmentKey);
}
const appendInitSegment = this.lastInitSegment_ !== initSegment;
const segmentData = mp4Generator.segmentData();

this.lastInitSegment_ = initSegment;
this.frameIndex_++;
const transmuxData = Uint8ArrayUtils.concat(initSegment, segmentData);
return Promise.resolve(transmuxData);
if (appendInitSegment) {
const transmuxData = Uint8ArrayUtils.concat(initSegment, segmentData);
return Promise.resolve(transmuxData);
} else {
return Promise.resolve(segmentData);
}
}


Expand Down
4 changes: 1 addition & 3 deletions test/transmuxer/transmuxer_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,7 @@ describe('Transmuxer Player', () => {
await player.unload();
});

// TODO: Fix the transmuxer for segments that do not start with a keyframe
// https://github.com/shaka-project/shaka-player/issues/7462
xit('H.264+AC3 in TS', async () => {
it('H.264+AC3 in TS', async () => {
if (!await Util.isTypeSupported('audio/mp4; codecs="ac-3"')) {
pending('Codec AC-3 is not supported by the platform.');
}
Expand Down

0 comments on commit 934bdff

Please sign in to comment.