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

fix: Fix metadata timing when using TS #7478

Merged
merged 1 commit into from
Oct 23, 2024
Merged
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
27 changes: 13 additions & 14 deletions lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -806,13 +806,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 @@ -826,15 +825,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 @@ -875,13 +874,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 @@ -987,8 +982,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 @@ -1050,6 +1045,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
Loading