Skip to content

Commit

Permalink
Add Thumbnail tracks update
Browse files Browse the repository at this point in the history
  • Loading branch information
peaBerberian committed Sep 9, 2024
1 parent c6b53e6 commit 84e40e2
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/manifest/classes/__tests__/update_period_in_place.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 5,
end: 15,
duration: 10,
thumbnailTracks: [],
adaptations: {
video: [oldVideoAdaptation1, oldVideoAdaptation2],
audio: [oldAudioAdaptation],
Expand Down Expand Up @@ -335,6 +336,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 500,
end: 520,
duration: 20,
thumbnailTracks: [],
adaptations: {
video: [newVideoAdaptation1, newVideoAdaptation2],
audio: [newAudioAdaptation],
Expand All @@ -355,6 +357,9 @@ describe("Manifest - updatePeriodInPlace", () => {
);

expect(res).toEqual({
addedThumbnailTracks: [],
updatedThumbnailTracks: [],
removedThumbnailTracks: [],
addedAdaptations: [],
removedAdaptations: [],
updatedAdaptations: [
Expand Down Expand Up @@ -464,6 +469,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 5,
end: 15,
duration: 10,
thumbnailTracks: [],
adaptations: {
video: [oldVideoAdaptation1, oldVideoAdaptation2],
audio: [oldAudioAdaptation],
Expand Down Expand Up @@ -491,6 +497,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 500,
end: 520,
duration: 20,
thumbnailTracks: [],
adaptations: {
video: [newVideoAdaptation1, newVideoAdaptation2],
audio: [newAudioAdaptation],
Expand All @@ -510,6 +517,9 @@ describe("Manifest - updatePeriodInPlace", () => {
MANIFEST_UPDATE_TYPE.Partial,
);
expect(res).toEqual({
addedThumbnailTracks: [],
updatedThumbnailTracks: [],
removedThumbnailTracks: [],
addedAdaptations: [],
removedAdaptations: [],
updatedAdaptations: [
Expand Down Expand Up @@ -614,6 +624,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 5,
end: 15,
duration: 10,
thumbnailTracks: [],
adaptations: {
video: [oldVideoAdaptation1],
audio: [oldAudioAdaptation],
Expand Down Expand Up @@ -644,6 +655,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 500,
end: 520,
duration: 20,
thumbnailTracks: [],
adaptations: {
video: [newVideoAdaptation1, newVideoAdaptation2],
audio: [newAudioAdaptation],
Expand All @@ -663,6 +675,9 @@ describe("Manifest - updatePeriodInPlace", () => {
MANIFEST_UPDATE_TYPE.Full,
);
expect(res).toEqual({
addedThumbnailTracks: [],
updatedThumbnailTracks: [],
removedThumbnailTracks: [],
addedAdaptations: [newVideoAdaptation2.getMetadataSnapshot()],
removedAdaptations: [],
updatedAdaptations: [
Expand Down Expand Up @@ -709,6 +724,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 5,
end: 15,
duration: 10,
thumbnailTracks: [],
adaptations: {
video: [oldVideoAdaptation1],
audio: [oldAudioAdaptation],
Expand Down Expand Up @@ -736,6 +752,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 500,
end: 520,
duration: 20,
thumbnailTracks: [],
adaptations: {
video: [newVideoAdaptation1, newVideoAdaptation2],
audio: [newAudioAdaptation],
Expand All @@ -755,6 +772,9 @@ describe("Manifest - updatePeriodInPlace", () => {
MANIFEST_UPDATE_TYPE.Partial,
);
expect(res).toEqual({
addedThumbnailTracks: [],
updatedThumbnailTracks: [],
removedThumbnailTracks: [],
addedAdaptations: [newVideoAdaptation2.getMetadataSnapshot()],
removedAdaptations: [],
updatedAdaptations: [
Expand Down Expand Up @@ -806,6 +826,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 5,
end: 15,
duration: 10,
thumbnailTracks: [],
adaptations: {
video: [oldVideoAdaptation1, oldVideoAdaptation2],
audio: [oldAudioAdaptation],
Expand All @@ -828,6 +849,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 500,
end: 520,
duration: 20,
thumbnailTracks: [],
adaptations: {
video: [newVideoAdaptation1],
audio: [newAudioAdaptation],
Expand All @@ -847,6 +869,9 @@ describe("Manifest - updatePeriodInPlace", () => {
MANIFEST_UPDATE_TYPE.Full,
);
expect(res).toEqual({
addedThumbnailTracks: [],
updatedThumbnailTracks: [],
removedThumbnailTracks: [],
addedAdaptations: [],
removedAdaptations: [
{
Expand Down Expand Up @@ -903,6 +928,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 5,
end: 15,
duration: 10,
thumbnailTracks: [],
adaptations: {
video: [oldVideoAdaptation1, oldVideoAdaptation2],
audio: [oldAudioAdaptation],
Expand All @@ -925,6 +951,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 500,
end: 520,
duration: 20,
thumbnailTracks: [],
adaptations: {
video: [newVideoAdaptation1],
audio: [newAudioAdaptation],
Expand All @@ -944,6 +971,9 @@ describe("Manifest - updatePeriodInPlace", () => {
MANIFEST_UPDATE_TYPE.Partial,
);
expect(res).toEqual({
addedThumbnailTracks: [],
updatedThumbnailTracks: [],
removedThumbnailTracks: [],
addedAdaptations: [],
removedAdaptations: [
{
Expand Down Expand Up @@ -995,6 +1025,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 5,
end: 15,
duration: 10,
thumbnailTracks: [],
adaptations: {
video: [oldVideoAdaptation1],
audio: [oldAudioAdaptation],
Expand All @@ -1018,6 +1049,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 500,
end: 520,
duration: 20,
thumbnailTracks: [],
adaptations: {
video: [newVideoAdaptation1],
audio: [newAudioAdaptation],
Expand All @@ -1037,6 +1069,9 @@ describe("Manifest - updatePeriodInPlace", () => {
MANIFEST_UPDATE_TYPE.Full,
);
expect(res).toEqual({
addedThumbnailTracks: [],
updatedThumbnailTracks: [],
removedThumbnailTracks: [],
addedAdaptations: [],
removedAdaptations: [],
updatedAdaptations: [
Expand Down Expand Up @@ -1079,6 +1114,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 5,
end: 15,
duration: 10,
thumbnailTracks: [],
adaptations: {
video: [oldVideoAdaptation1],
audio: [oldAudioAdaptation],
Expand All @@ -1102,6 +1138,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 500,
end: 520,
duration: 20,
thumbnailTracks: [],
adaptations: {
video: [newVideoAdaptation1],
audio: [newAudioAdaptation],
Expand All @@ -1121,6 +1158,9 @@ describe("Manifest - updatePeriodInPlace", () => {
MANIFEST_UPDATE_TYPE.Partial,
);
expect(res).toEqual({
addedThumbnailTracks: [],
updatedThumbnailTracks: [],
removedThumbnailTracks: [],
addedAdaptations: [],
removedAdaptations: [],
updatedAdaptations: [
Expand Down Expand Up @@ -1163,6 +1203,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 500,
end: 520,
duration: 20,
thumbnailTracks: [],
adaptations: {
video: [oldVideoAdaptation1],
audio: [oldAudioAdaptation],
Expand All @@ -1185,6 +1226,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 5,
end: 15,
duration: 10,
thumbnailTracks: [],
adaptations: {
video: [newVideoAdaptation1],
audio: [newAudioAdaptation],
Expand All @@ -1204,6 +1246,9 @@ describe("Manifest - updatePeriodInPlace", () => {
MANIFEST_UPDATE_TYPE.Full,
);
expect(res).toEqual({
addedThumbnailTracks: [],
updatedThumbnailTracks: [],
removedThumbnailTracks: [],
addedAdaptations: [],
removedAdaptations: [],
updatedAdaptations: [
Expand Down Expand Up @@ -1246,6 +1291,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 500,
end: 520,
duration: 20,
thumbnailTracks: [],
adaptations: {
video: [oldVideoAdaptation1],
audio: [oldAudioAdaptation],
Expand All @@ -1268,6 +1314,7 @@ describe("Manifest - updatePeriodInPlace", () => {
start: 5,
end: 15,
duration: 10,
thumbnailTracks: [],
adaptations: {
video: [newVideoAdaptation1],
audio: [newAudioAdaptation],
Expand All @@ -1287,6 +1334,9 @@ describe("Manifest - updatePeriodInPlace", () => {
MANIFEST_UPDATE_TYPE.Partial,
);
expect(res).toEqual({
addedThumbnailTracks: [],
updatedThumbnailTracks: [],
removedThumbnailTracks: [],
addedAdaptations: [],
removedAdaptations: [],
updatedAdaptations: [
Expand Down
66 changes: 66 additions & 0 deletions src/manifest/classes/update_period_in_place.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import log from "../../log";
import type { IAdaptationMetadata, IRepresentationMetadata } from "../../manifest";
import type { ITrackType } from "../../public_types";
import arrayFindIndex from "../../utils/array_find_index";
import type { IThumbnailTrackMetadata } from "../types";
import type Period from "./period";
import { MANIFEST_UPDATE_TYPE } from "./types";

Expand All @@ -38,12 +39,68 @@ export default function updatePeriodInPlace(
updatedAdaptations: [],
removedAdaptations: [],
addedAdaptations: [],
updatedThumbnailTracks: [],
removedThumbnailTracks: [],
addedThumbnailTracks: [],
};
oldPeriod.start = newPeriod.start;
oldPeriod.end = newPeriod.end;
oldPeriod.duration = newPeriod.duration;
oldPeriod.streamEvents = newPeriod.streamEvents;

const oldThumbnailTracks = oldPeriod.thumbnailTracks;
const newThumbnailTracks = newPeriod.thumbnailTracks;
for (let j = 0; j < oldThumbnailTracks.length; j++) {
const oldThumbnailTrack = oldThumbnailTracks[j];
const newThumbnailTrackIdx = arrayFindIndex(
newThumbnailTracks,
(a) => a.id === oldThumbnailTrack.id,
);

if (newThumbnailTrackIdx === -1) {
log.warn(
'Manifest: ThumbnailTrack "' +
oldThumbnailTracks[j].id +
'" not found when merging.',
);
const [removed] = oldThumbnailTracks.splice(j, 1);
j--;
res.removedThumbnailTracks.push({
id: removed.id,
});
} else {
const [newThumbnailTrack] = newThumbnailTracks.splice(newThumbnailTrackIdx, 1);
oldThumbnailTrack.mimeType = newThumbnailTrack.mimeType;
oldThumbnailTrack.height = newThumbnailTrack.height;
oldThumbnailTrack.width = newThumbnailTrack.width;
oldThumbnailTrack.horizontalTiles = newThumbnailTrack.horizontalTiles;
oldThumbnailTrack.verticalTiles = newThumbnailTrack.verticalTiles;
oldThumbnailTrack.cdnMetadata = newThumbnailTrack.cdnMetadata;
if (updateType === MANIFEST_UPDATE_TYPE.Full) {
oldThumbnailTrack.index._replace(newThumbnailTrack.index);
} else {
oldThumbnailTrack.index._update(newThumbnailTrack.index);
}
res.updatedThumbnailTracks.push({
id: oldThumbnailTrack.id,
mimeType: oldThumbnailTrack.mimeType,
height: oldThumbnailTrack.height,
width: oldThumbnailTrack.width,
horizontalTiles: oldThumbnailTrack.horizontalTiles,
verticalTiles: oldThumbnailTrack.verticalTiles,
});
}
}

if (newThumbnailTracks.length > 0) {
log.warn(
`Manifest: ${newThumbnailTracks.length} new Thumbnail tracks ` +
"found when merging.",
);
res.addedThumbnailTracks.push(...newThumbnailTracks);
oldPeriod.thumbnailTracks.push(...newThumbnailTracks);
}

const oldAdaptations = oldPeriod.getAdaptations();
const newAdaptations = newPeriod.getAdaptations();

Expand Down Expand Up @@ -160,4 +217,13 @@ export interface IUpdatedPeriodResult {
}>;
/** Adaptation that have been added to the Period. */
addedAdaptations: IAdaptationMetadata[];

/** Information on Thumbnail Tracks that have been updated. */
updatedThumbnailTracks: IThumbnailTrackMetadata[];
/** Thumbnail tracks that have been removed from the Period. */
removedThumbnailTracks: Array<{
id: string;
}>;
/** Thumbnail tracks that have been added to the Period. */
addedThumbnailTracks: IThumbnailTrackMetadata[];
}
Loading

0 comments on commit 84e40e2

Please sign in to comment.