Skip to content

Commit 84e40e2

Browse files
committed
Add Thumbnail tracks update
1 parent c6b53e6 commit 84e40e2

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed

src/manifest/classes/__tests__/update_period_in_place.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ describe("Manifest - updatePeriodInPlace", () => {
308308
start: 5,
309309
end: 15,
310310
duration: 10,
311+
thumbnailTracks: [],
311312
adaptations: {
312313
video: [oldVideoAdaptation1, oldVideoAdaptation2],
313314
audio: [oldAudioAdaptation],
@@ -335,6 +336,7 @@ describe("Manifest - updatePeriodInPlace", () => {
335336
start: 500,
336337
end: 520,
337338
duration: 20,
339+
thumbnailTracks: [],
338340
adaptations: {
339341
video: [newVideoAdaptation1, newVideoAdaptation2],
340342
audio: [newAudioAdaptation],
@@ -355,6 +357,9 @@ describe("Manifest - updatePeriodInPlace", () => {
355357
);
356358

357359
expect(res).toEqual({
360+
addedThumbnailTracks: [],
361+
updatedThumbnailTracks: [],
362+
removedThumbnailTracks: [],
358363
addedAdaptations: [],
359364
removedAdaptations: [],
360365
updatedAdaptations: [
@@ -464,6 +469,7 @@ describe("Manifest - updatePeriodInPlace", () => {
464469
start: 5,
465470
end: 15,
466471
duration: 10,
472+
thumbnailTracks: [],
467473
adaptations: {
468474
video: [oldVideoAdaptation1, oldVideoAdaptation2],
469475
audio: [oldAudioAdaptation],
@@ -491,6 +497,7 @@ describe("Manifest - updatePeriodInPlace", () => {
491497
start: 500,
492498
end: 520,
493499
duration: 20,
500+
thumbnailTracks: [],
494501
adaptations: {
495502
video: [newVideoAdaptation1, newVideoAdaptation2],
496503
audio: [newAudioAdaptation],
@@ -510,6 +517,9 @@ describe("Manifest - updatePeriodInPlace", () => {
510517
MANIFEST_UPDATE_TYPE.Partial,
511518
);
512519
expect(res).toEqual({
520+
addedThumbnailTracks: [],
521+
updatedThumbnailTracks: [],
522+
removedThumbnailTracks: [],
513523
addedAdaptations: [],
514524
removedAdaptations: [],
515525
updatedAdaptations: [
@@ -614,6 +624,7 @@ describe("Manifest - updatePeriodInPlace", () => {
614624
start: 5,
615625
end: 15,
616626
duration: 10,
627+
thumbnailTracks: [],
617628
adaptations: {
618629
video: [oldVideoAdaptation1],
619630
audio: [oldAudioAdaptation],
@@ -644,6 +655,7 @@ describe("Manifest - updatePeriodInPlace", () => {
644655
start: 500,
645656
end: 520,
646657
duration: 20,
658+
thumbnailTracks: [],
647659
adaptations: {
648660
video: [newVideoAdaptation1, newVideoAdaptation2],
649661
audio: [newAudioAdaptation],
@@ -663,6 +675,9 @@ describe("Manifest - updatePeriodInPlace", () => {
663675
MANIFEST_UPDATE_TYPE.Full,
664676
);
665677
expect(res).toEqual({
678+
addedThumbnailTracks: [],
679+
updatedThumbnailTracks: [],
680+
removedThumbnailTracks: [],
666681
addedAdaptations: [newVideoAdaptation2.getMetadataSnapshot()],
667682
removedAdaptations: [],
668683
updatedAdaptations: [
@@ -709,6 +724,7 @@ describe("Manifest - updatePeriodInPlace", () => {
709724
start: 5,
710725
end: 15,
711726
duration: 10,
727+
thumbnailTracks: [],
712728
adaptations: {
713729
video: [oldVideoAdaptation1],
714730
audio: [oldAudioAdaptation],
@@ -736,6 +752,7 @@ describe("Manifest - updatePeriodInPlace", () => {
736752
start: 500,
737753
end: 520,
738754
duration: 20,
755+
thumbnailTracks: [],
739756
adaptations: {
740757
video: [newVideoAdaptation1, newVideoAdaptation2],
741758
audio: [newAudioAdaptation],
@@ -755,6 +772,9 @@ describe("Manifest - updatePeriodInPlace", () => {
755772
MANIFEST_UPDATE_TYPE.Partial,
756773
);
757774
expect(res).toEqual({
775+
addedThumbnailTracks: [],
776+
updatedThumbnailTracks: [],
777+
removedThumbnailTracks: [],
758778
addedAdaptations: [newVideoAdaptation2.getMetadataSnapshot()],
759779
removedAdaptations: [],
760780
updatedAdaptations: [
@@ -806,6 +826,7 @@ describe("Manifest - updatePeriodInPlace", () => {
806826
start: 5,
807827
end: 15,
808828
duration: 10,
829+
thumbnailTracks: [],
809830
adaptations: {
810831
video: [oldVideoAdaptation1, oldVideoAdaptation2],
811832
audio: [oldAudioAdaptation],
@@ -828,6 +849,7 @@ describe("Manifest - updatePeriodInPlace", () => {
828849
start: 500,
829850
end: 520,
830851
duration: 20,
852+
thumbnailTracks: [],
831853
adaptations: {
832854
video: [newVideoAdaptation1],
833855
audio: [newAudioAdaptation],
@@ -847,6 +869,9 @@ describe("Manifest - updatePeriodInPlace", () => {
847869
MANIFEST_UPDATE_TYPE.Full,
848870
);
849871
expect(res).toEqual({
872+
addedThumbnailTracks: [],
873+
updatedThumbnailTracks: [],
874+
removedThumbnailTracks: [],
850875
addedAdaptations: [],
851876
removedAdaptations: [
852877
{
@@ -903,6 +928,7 @@ describe("Manifest - updatePeriodInPlace", () => {
903928
start: 5,
904929
end: 15,
905930
duration: 10,
931+
thumbnailTracks: [],
906932
adaptations: {
907933
video: [oldVideoAdaptation1, oldVideoAdaptation2],
908934
audio: [oldAudioAdaptation],
@@ -925,6 +951,7 @@ describe("Manifest - updatePeriodInPlace", () => {
925951
start: 500,
926952
end: 520,
927953
duration: 20,
954+
thumbnailTracks: [],
928955
adaptations: {
929956
video: [newVideoAdaptation1],
930957
audio: [newAudioAdaptation],
@@ -944,6 +971,9 @@ describe("Manifest - updatePeriodInPlace", () => {
944971
MANIFEST_UPDATE_TYPE.Partial,
945972
);
946973
expect(res).toEqual({
974+
addedThumbnailTracks: [],
975+
updatedThumbnailTracks: [],
976+
removedThumbnailTracks: [],
947977
addedAdaptations: [],
948978
removedAdaptations: [
949979
{
@@ -995,6 +1025,7 @@ describe("Manifest - updatePeriodInPlace", () => {
9951025
start: 5,
9961026
end: 15,
9971027
duration: 10,
1028+
thumbnailTracks: [],
9981029
adaptations: {
9991030
video: [oldVideoAdaptation1],
10001031
audio: [oldAudioAdaptation],
@@ -1018,6 +1049,7 @@ describe("Manifest - updatePeriodInPlace", () => {
10181049
start: 500,
10191050
end: 520,
10201051
duration: 20,
1052+
thumbnailTracks: [],
10211053
adaptations: {
10221054
video: [newVideoAdaptation1],
10231055
audio: [newAudioAdaptation],
@@ -1037,6 +1069,9 @@ describe("Manifest - updatePeriodInPlace", () => {
10371069
MANIFEST_UPDATE_TYPE.Full,
10381070
);
10391071
expect(res).toEqual({
1072+
addedThumbnailTracks: [],
1073+
updatedThumbnailTracks: [],
1074+
removedThumbnailTracks: [],
10401075
addedAdaptations: [],
10411076
removedAdaptations: [],
10421077
updatedAdaptations: [
@@ -1079,6 +1114,7 @@ describe("Manifest - updatePeriodInPlace", () => {
10791114
start: 5,
10801115
end: 15,
10811116
duration: 10,
1117+
thumbnailTracks: [],
10821118
adaptations: {
10831119
video: [oldVideoAdaptation1],
10841120
audio: [oldAudioAdaptation],
@@ -1102,6 +1138,7 @@ describe("Manifest - updatePeriodInPlace", () => {
11021138
start: 500,
11031139
end: 520,
11041140
duration: 20,
1141+
thumbnailTracks: [],
11051142
adaptations: {
11061143
video: [newVideoAdaptation1],
11071144
audio: [newAudioAdaptation],
@@ -1121,6 +1158,9 @@ describe("Manifest - updatePeriodInPlace", () => {
11211158
MANIFEST_UPDATE_TYPE.Partial,
11221159
);
11231160
expect(res).toEqual({
1161+
addedThumbnailTracks: [],
1162+
updatedThumbnailTracks: [],
1163+
removedThumbnailTracks: [],
11241164
addedAdaptations: [],
11251165
removedAdaptations: [],
11261166
updatedAdaptations: [
@@ -1163,6 +1203,7 @@ describe("Manifest - updatePeriodInPlace", () => {
11631203
start: 500,
11641204
end: 520,
11651205
duration: 20,
1206+
thumbnailTracks: [],
11661207
adaptations: {
11671208
video: [oldVideoAdaptation1],
11681209
audio: [oldAudioAdaptation],
@@ -1185,6 +1226,7 @@ describe("Manifest - updatePeriodInPlace", () => {
11851226
start: 5,
11861227
end: 15,
11871228
duration: 10,
1229+
thumbnailTracks: [],
11881230
adaptations: {
11891231
video: [newVideoAdaptation1],
11901232
audio: [newAudioAdaptation],
@@ -1204,6 +1246,9 @@ describe("Manifest - updatePeriodInPlace", () => {
12041246
MANIFEST_UPDATE_TYPE.Full,
12051247
);
12061248
expect(res).toEqual({
1249+
addedThumbnailTracks: [],
1250+
updatedThumbnailTracks: [],
1251+
removedThumbnailTracks: [],
12071252
addedAdaptations: [],
12081253
removedAdaptations: [],
12091254
updatedAdaptations: [
@@ -1246,6 +1291,7 @@ describe("Manifest - updatePeriodInPlace", () => {
12461291
start: 500,
12471292
end: 520,
12481293
duration: 20,
1294+
thumbnailTracks: [],
12491295
adaptations: {
12501296
video: [oldVideoAdaptation1],
12511297
audio: [oldAudioAdaptation],
@@ -1268,6 +1314,7 @@ describe("Manifest - updatePeriodInPlace", () => {
12681314
start: 5,
12691315
end: 15,
12701316
duration: 10,
1317+
thumbnailTracks: [],
12711318
adaptations: {
12721319
video: [newVideoAdaptation1],
12731320
audio: [newAudioAdaptation],
@@ -1287,6 +1334,9 @@ describe("Manifest - updatePeriodInPlace", () => {
12871334
MANIFEST_UPDATE_TYPE.Partial,
12881335
);
12891336
expect(res).toEqual({
1337+
addedThumbnailTracks: [],
1338+
updatedThumbnailTracks: [],
1339+
removedThumbnailTracks: [],
12901340
addedAdaptations: [],
12911341
removedAdaptations: [],
12921342
updatedAdaptations: [

src/manifest/classes/update_period_in_place.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import log from "../../log";
1818
import type { IAdaptationMetadata, IRepresentationMetadata } from "../../manifest";
1919
import type { ITrackType } from "../../public_types";
2020
import arrayFindIndex from "../../utils/array_find_index";
21+
import type { IThumbnailTrackMetadata } from "../types";
2122
import type Period from "./period";
2223
import { MANIFEST_UPDATE_TYPE } from "./types";
2324

@@ -38,12 +39,68 @@ export default function updatePeriodInPlace(
3839
updatedAdaptations: [],
3940
removedAdaptations: [],
4041
addedAdaptations: [],
42+
updatedThumbnailTracks: [],
43+
removedThumbnailTracks: [],
44+
addedThumbnailTracks: [],
4145
};
4246
oldPeriod.start = newPeriod.start;
4347
oldPeriod.end = newPeriod.end;
4448
oldPeriod.duration = newPeriod.duration;
4549
oldPeriod.streamEvents = newPeriod.streamEvents;
4650

51+
const oldThumbnailTracks = oldPeriod.thumbnailTracks;
52+
const newThumbnailTracks = newPeriod.thumbnailTracks;
53+
for (let j = 0; j < oldThumbnailTracks.length; j++) {
54+
const oldThumbnailTrack = oldThumbnailTracks[j];
55+
const newThumbnailTrackIdx = arrayFindIndex(
56+
newThumbnailTracks,
57+
(a) => a.id === oldThumbnailTrack.id,
58+
);
59+
60+
if (newThumbnailTrackIdx === -1) {
61+
log.warn(
62+
'Manifest: ThumbnailTrack "' +
63+
oldThumbnailTracks[j].id +
64+
'" not found when merging.',
65+
);
66+
const [removed] = oldThumbnailTracks.splice(j, 1);
67+
j--;
68+
res.removedThumbnailTracks.push({
69+
id: removed.id,
70+
});
71+
} else {
72+
const [newThumbnailTrack] = newThumbnailTracks.splice(newThumbnailTrackIdx, 1);
73+
oldThumbnailTrack.mimeType = newThumbnailTrack.mimeType;
74+
oldThumbnailTrack.height = newThumbnailTrack.height;
75+
oldThumbnailTrack.width = newThumbnailTrack.width;
76+
oldThumbnailTrack.horizontalTiles = newThumbnailTrack.horizontalTiles;
77+
oldThumbnailTrack.verticalTiles = newThumbnailTrack.verticalTiles;
78+
oldThumbnailTrack.cdnMetadata = newThumbnailTrack.cdnMetadata;
79+
if (updateType === MANIFEST_UPDATE_TYPE.Full) {
80+
oldThumbnailTrack.index._replace(newThumbnailTrack.index);
81+
} else {
82+
oldThumbnailTrack.index._update(newThumbnailTrack.index);
83+
}
84+
res.updatedThumbnailTracks.push({
85+
id: oldThumbnailTrack.id,
86+
mimeType: oldThumbnailTrack.mimeType,
87+
height: oldThumbnailTrack.height,
88+
width: oldThumbnailTrack.width,
89+
horizontalTiles: oldThumbnailTrack.horizontalTiles,
90+
verticalTiles: oldThumbnailTrack.verticalTiles,
91+
});
92+
}
93+
}
94+
95+
if (newThumbnailTracks.length > 0) {
96+
log.warn(
97+
`Manifest: ${newThumbnailTracks.length} new Thumbnail tracks ` +
98+
"found when merging.",
99+
);
100+
res.addedThumbnailTracks.push(...newThumbnailTracks);
101+
oldPeriod.thumbnailTracks.push(...newThumbnailTracks);
102+
}
103+
47104
const oldAdaptations = oldPeriod.getAdaptations();
48105
const newAdaptations = newPeriod.getAdaptations();
49106

@@ -160,4 +217,13 @@ export interface IUpdatedPeriodResult {
160217
}>;
161218
/** Adaptation that have been added to the Period. */
162219
addedAdaptations: IAdaptationMetadata[];
220+
221+
/** Information on Thumbnail Tracks that have been updated. */
222+
updatedThumbnailTracks: IThumbnailTrackMetadata[];
223+
/** Thumbnail tracks that have been removed from the Period. */
224+
removedThumbnailTracks: Array<{
225+
id: string;
226+
}>;
227+
/** Thumbnail tracks that have been added to the Period. */
228+
addedThumbnailTracks: IThumbnailTrackMetadata[];
163229
}

0 commit comments

Comments
 (0)