From 478539c51ac5126942efe082c4fc61830ce0e4ac Mon Sep 17 00:00:00 2001 From: Paul Berberian Date: Mon, 21 Jun 2021 13:28:03 +0200 Subject: [PATCH] Fix remaining async parsing code in VideoThumbnailLoader --- .../get_initialized_source_buffer.ts | 35 +++++++++--------- .../tools/VideoThumbnailLoader/push_data.ts | 36 +++++++++---------- .../tools/VideoThumbnailLoader/types.ts | 1 - 3 files changed, 32 insertions(+), 40 deletions(-) diff --git a/src/experimental/tools/VideoThumbnailLoader/get_initialized_source_buffer.ts b/src/experimental/tools/VideoThumbnailLoader/get_initialized_source_buffer.ts index 642e8a9f58..bffa8d35d7 100644 --- a/src/experimental/tools/VideoThumbnailLoader/get_initialized_source_buffer.ts +++ b/src/experimental/tools/VideoThumbnailLoader/get_initialized_source_buffer.ts @@ -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 }); }) ); } diff --git a/src/experimental/tools/VideoThumbnailLoader/push_data.ts b/src/experimental/tools/VideoThumbnailLoader/push_data.ts index 7092d74cb1..b647f4039e 100644 --- a/src/experimental/tools/VideoThumbnailLoader/push_data.ts +++ b/src/experimental/tools/VideoThumbnailLoader/push_data.ts @@ -2,7 +2,6 @@ import { EMPTY, Observable, } from "rxjs"; -import { mergeMap } from "rxjs/operators"; import { AudioVideoSegmentBuffer } from "../../../core/segment_buffers/implementations"; import Manifest, { Adaptation, @@ -32,26 +31,23 @@ export default function pushData( responseData: Uint8Array, videoSourceBuffer: AudioVideoSegmentBuffer ): Observable { - 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 }); } diff --git a/src/experimental/tools/VideoThumbnailLoader/types.ts b/src/experimental/tools/VideoThumbnailLoader/types.ts index a73421965f..4b37891687 100644 --- a/src/experimental/tools/VideoThumbnailLoader/types.ts +++ b/src/experimental/tools/VideoThumbnailLoader/types.ts @@ -33,5 +33,4 @@ export type ILoaders = Partial>; export type IThumbnailLoaderSegmentParser = ISegmentParser;