diff --git a/src/main.cpp b/src/main.cpp index b38c43e..dfc8e5e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,7 +44,7 @@ typedef struct Attachment { typedef struct SubtitleFragment { int streamIndex; bool isHeader; - emscripten::val data; + std::string data; std::string language; std::string title; long start; @@ -384,7 +384,7 @@ class Remuxer { // We handle subtitles separately if (in_codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { // It's a subtitle header - SubtitleFragment subtitle_fragment; + SubtitleFragment subtitle_fragment = SubtitleFragment(); subtitle_fragment.streamIndex = i; subtitle_fragment.isHeader = true; subtitle_fragment.start = 0; @@ -395,16 +395,10 @@ class Remuxer { AVDictionaryEntry* title = av_dict_get(in_stream->metadata, "title", NULL, 0); if (title) subtitle_fragment.title = title->value; // The extradata is the "header" - std::string subtitle_data; subtitle_data.assign((char*)in_codecpar->extradata, in_codecpar->extradata_size); + subtitle_fragment.data = subtitle_data; - subtitle_fragment.data = emscripten::val( - emscripten::typed_memory_view( - subtitle_data.size(), - subtitle_data.data() - ) - ); subtitles.push_back(subtitle_fragment); // Mark not to be remuxed in the output container (mp4) streams_list[i] = -1; @@ -560,19 +554,7 @@ class Remuxer { break; } - if (packet->stream_index >= number_of_streams - || streams_list[packet->stream_index] < 0) { - // not an included stream, drop - av_packet_free(&packet); - continue; - } - AVStream* in_stream = input_format_context->streams[packet->stream_index]; - if (packet->stream_index >= number_of_streams - || streams_list[packet->stream_index] < 0) { - // not an included stream, drop - continue; - } // If it's a subtitle packet if (in_stream->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { @@ -582,13 +564,24 @@ class Remuxer { subtitle_fragment.start = packet->pts; subtitle_fragment.end = subtitle_fragment.start + packet->duration; // The actual subtitle data - subtitle_fragment.data = emscripten::val( - emscripten::typed_memory_view( - packet->size, - packet->data - ) - ); - subtitles.push_back(std::move(subtitle_fragment)); + std::string subtitle_data; + subtitle_data.assign((char*)packet->data, packet->size); + subtitle_fragment.data = subtitle_data; + + subtitles.push_back(subtitle_fragment); + continue; + } + + if (packet->stream_index >= number_of_streams + || streams_list[packet->stream_index] < 0) { + // not an included stream, drop + av_packet_free(&packet); + continue; + } + + if (packet->stream_index >= number_of_streams + || streams_list[packet->stream_index] < 0) { + // not an included stream, drop continue; } diff --git a/src/utils.ts b/src/utils.ts index e2850b0..4d1657b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -32,34 +32,6 @@ export function debounceImmediateAndLatest any>( return debouncedFunction as T; } -// https://github.com/sindresorhus/throttleit/blob/main/index.js -export const throttle = (wait: number, fn: Function) => { - if (typeof fn !== 'function') { - throw new TypeError(`Expected the first argument to be a \`function\`, got \`${typeof fn}\`.`) - } - - let timeoutId: number - let lastCallTime = 0 - - return function throttled(...args: any[]) { - clearTimeout(timeoutId) - - const now = Date.now() - const timeSinceLastCall = now - lastCallTime - const delayForNextCall = wait - timeSinceLastCall - - if (delayForNextCall <= 0) { - lastCallTime = now - fn(args) - } else { - timeoutId = setTimeout(() => { - lastCallTime = Date.now() - fn(args) - }, delayForNextCall) - } - } -} - export const queuedThrottleWithLastCall = any>(time: number, func: T) => { let runningFunction: Promise> | undefined let lastCall: Promise> | undefined diff --git a/src/worker/index.ts b/src/worker/index.ts index 0024726..3c42c90 100644 --- a/src/worker/index.ts +++ b/src/worker/index.ts @@ -206,7 +206,7 @@ const resolvers = { return { ...subtitle, type: 'header', - content: new TextDecoder().decode(data) + content: data } }), info: { @@ -240,7 +240,7 @@ const resolvers = { return { ...subtitle, type: 'dialogue', - content: new TextDecoder().decode(data) + content: data } }), offset: result.offset, @@ -262,7 +262,7 @@ const resolvers = { return { ...subtitle, type: 'dialogue', - content: new TextDecoder().decode(data) + content: data } }), offset: result.offset,