Skip to content

Commit

Permalink
fix: Fix metadata timing when using TS (#7478)
Browse files Browse the repository at this point in the history
Fixes #7473
  • Loading branch information
avelad committed Oct 24, 2024
1 parent 0462d1b commit 3b27c13
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,13 +784,12 @@ shaka.media.MediaSourceEngine = class {
* @param {?shaka.media.SegmentReference} reference The segment reference
* we are appending, or null for init segments
* @param {!string} mimeType
* @param {!number} timestampOffset
* @return {?number}
* @return {{timestamp: ?number, metadata: !Array.<shaka.extern.ID3Metadata>}}
* @private
*/
getTimestampAndDispatchMetadata_(contentType, data, reference, mimeType,
timestampOffset) {
getTimestampAndDispatchMetadata_(contentType, data, reference, mimeType) {
let timestamp = null;
let metadata = [];

const uint8ArrayData = shaka.util.BufferUtils.toUint8(data);
if (shaka.util.MimeUtils.RAW_FORMATS.includes(mimeType)) {
Expand All @@ -804,15 +803,15 @@ shaka.media.MediaSourceEngine = class {
timestamp = Math.round(metadataTimestamp.data) / 1000;
}
/** @private {shaka.extern.ID3Metadata} */
const metadata = {
const id3Metadata = {
cueTime: reference.startTime,
data: uint8ArrayData,
frames: frames,
dts: reference.startTime,
pts: reference.startTime,
};
this.playerInterface_.onMetadata(
[metadata], /* offset= */ 0, reference.endTime);
[id3Metadata], /* offset= */ 0, reference.endTime);
}
} else if (mimeType.includes('/mp4') &&
reference && reference.timestampOffset == 0 &&
Expand Down Expand Up @@ -852,13 +851,9 @@ shaka.media.MediaSourceEngine = class {
if (startTime != null) {
timestamp = startTime;
}
const metadata = tsParser.getMetadata();
if (metadata.length) {
this.playerInterface_.onMetadata(metadata, timestampOffset,
reference ? reference.endTime : null);
}
metadata = tsParser.getMetadata();
}
return timestamp;
return {timestamp, metadata};
}

/**
Expand Down Expand Up @@ -922,8 +917,8 @@ shaka.media.MediaSourceEngine = class {
mimeType = this.transmuxers_[contentType].getOriginalMimeType();
}
if (reference) {
const timestamp = this.getTimestampAndDispatchMetadata_(
contentType, data, reference, mimeType, timestampOffset);
const {timestamp, metadata} = this.getTimestampAndDispatchMetadata_(
contentType, data, reference, mimeType);
if (timestamp != null) {
if (this.firstVideoTimestamp_ == null &&
contentType == ContentType.VIDEO) {
Expand Down Expand Up @@ -985,6 +980,10 @@ shaka.media.MediaSourceEngine = class {
this.textSequenceModeOffset_.resolve(timestampOffset);
}
}
if (metadata.length) {
this.playerInterface_.onMetadata(metadata, timestampOffset,
reference ? reference.endTime : null);
}
}
if (hasClosedCaptions && contentType == ContentType.VIDEO) {
if (!this.textEngine_) {
Expand Down

0 comments on commit 3b27c13

Please sign in to comment.