Skip to content

Commit

Permalink
Fix remaining async parsing code in VideoThumbnailLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
peaBerberian committed Jul 27, 2021
1 parent 0796c0b commit 54ba38f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,30 +94,27 @@ function loadAndPushInitData(contentInfos: IContentInfos,
filter((evt): evt is { type: "data"; value: { responseData: Uint8Array } } =>
evt.type === "data"),
mergeMap((evt) => {
return segmentParser({
const parsed = segmentParser({
response: {
data: evt.value.responseData,
isChunked: false,
},
content: inventoryInfos,
}).pipe(
mergeMap((parserEvent) => {
if (parserEvent.type !== "parsed-init-segment") {
return EMPTY;
}
const { initializationData } = parserEvent.value;
const initSegmentData = initializationData instanceof ArrayBuffer ?
new Uint8Array(initializationData) : initializationData;
return sourceBuffer
.pushChunk({ data: { initSegment: initSegmentData,
chunk: null,
appendWindow: [undefined, undefined],
timestampOffset: 0,
codec: contentInfos
.representation.getMimeTypeString() },
inventoryInfos: null });
})
);
});
if (parsed.segmentType !== "init") {
return EMPTY;
}
const { initializationData } = parsed;
const initSegmentData = initializationData instanceof ArrayBuffer ?
new Uint8Array(initializationData) : initializationData;
return sourceBuffer
.pushChunk({ data: { initSegment: initSegmentData,
chunk: null,
appendWindow: [undefined, undefined],
timestampOffset: 0,
codec: contentInfos
.representation.getMimeTypeString() },
inventoryInfos: null });
})
);
}
Expand Down
36 changes: 16 additions & 20 deletions src/experimental/tools/VideoThumbnailLoader/push_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
EMPTY,
Observable,
} from "rxjs";
import { mergeMap } from "rxjs/operators";
import { AudioVideoSegmentBuffer } from "../../../core/segment_buffers/implementations";
import Manifest, {
Adaptation,
Expand Down Expand Up @@ -32,26 +31,23 @@ export default function pushData(
responseData: Uint8Array,
videoSourceBuffer: AudioVideoSegmentBuffer
): Observable<void> {
return segmentParser({
const parsed = segmentParser({
response: { data: responseData,
isChunked: false },
content: inventoryInfos,
}).pipe(
mergeMap((parserEvt) => {
if (parserEvt.type !== "parsed-segment") {
return EMPTY;
}
const { chunkData, appendWindow } = parserEvt.value;
const segmentData = chunkData instanceof ArrayBuffer ?
new Uint8Array(chunkData) : chunkData;
return videoSourceBuffer
.pushChunk({ data: { chunk: segmentData,
timestampOffset: 0,
appendWindow,
initSegment: null,
codec: inventoryInfos
.representation.getMimeTypeString() },
inventoryInfos });
})
);
});
if (parsed.segmentType !== "media") {
return EMPTY;
}
const { chunkData, appendWindow } = parsed;
const segmentData = chunkData instanceof ArrayBuffer ?
new Uint8Array(chunkData) : chunkData;
return videoSourceBuffer
.pushChunk({ data: { chunk: segmentData,
timestampOffset: 0,
appendWindow,
initSegment: null,
codec: inventoryInfos
.representation.getMimeTypeString() },
inventoryInfos });
}
1 change: 0 additions & 1 deletion src/experimental/tools/VideoThumbnailLoader/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ export type ILoaders = Partial<Record<string, ITransportPipelines>>;

export type IThumbnailLoaderSegmentParser =
ISegmentParser<Uint8Array | ArrayBuffer | null,
Uint8Array | ArrayBuffer | null,
Uint8Array | ArrayBuffer | null>;

0 comments on commit 54ba38f

Please sign in to comment.