mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 02:43:48 +02:00
Add SourceRef system to keep track of used Sources (fixes #332)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { expect, test } from 'vitest';
|
||||
import { Reader } from '../../src/reader.js';
|
||||
import { BufferSource } from '../../src/source.js';
|
||||
import { createAesDecryptStream } from '../../src/aes.js';
|
||||
import { createAes128CbcDecryptStream } from '../../src/aes.js';
|
||||
|
||||
// getRandomValues is length-limited, so let's just do this
|
||||
export const fillRandom = <T extends Uint8Array>(buffer: T) => {
|
||||
@@ -27,7 +27,7 @@ test('createAesDecryptStream', async () => {
|
||||
const source = new BufferSource(ciphertext);
|
||||
const reader = new Reader(source);
|
||||
|
||||
const stream = createAesDecryptStream(reader, () => ({ key, iv }));
|
||||
const stream = createAes128CbcDecryptStream(reader, () => ({ key, iv }));
|
||||
const streamReader = stream.getReader();
|
||||
|
||||
const chunks: Uint8Array[] = [];
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { expect, test } from 'vitest';
|
||||
import { FilePathSource } from '../../src/source.js';
|
||||
import path from 'node:path';
|
||||
import { Input } from '../../src/input.js';
|
||||
import { ALL_FORMATS, MP4 } from '../../src/input-format.js';
|
||||
|
||||
const __dirname = new URL('.', import.meta.url).pathname;
|
||||
|
||||
test('Direct source disposal', async () => {
|
||||
const filePath = path.join(__dirname, '../public/video.mp4');
|
||||
const source = new FilePathSource(filePath);
|
||||
|
||||
expect(!source._disposed);
|
||||
|
||||
const ref = source.ref();
|
||||
ref.free();
|
||||
expect(source._disposed);
|
||||
});
|
||||
|
||||
test('Implicit source disposal', async () => {
|
||||
const filePath = path.join(__dirname, '../public/video.mp4');
|
||||
const source = new FilePathSource(filePath);
|
||||
|
||||
const input = new Input({
|
||||
source,
|
||||
formats: ALL_FORMATS,
|
||||
});
|
||||
expect(await input.getFormat()).toBe(MP4);
|
||||
|
||||
expect(!source._disposed);
|
||||
input.dispose();
|
||||
expect(source._disposed);
|
||||
});
|
||||
|
||||
test('Implicit source disposal, double input', async () => {
|
||||
const filePath = path.join(__dirname, '../public/video.mp4');
|
||||
const source = new FilePathSource(filePath);
|
||||
|
||||
const input1 = new Input({
|
||||
source,
|
||||
formats: ALL_FORMATS,
|
||||
});
|
||||
const input2 = new Input({
|
||||
source,
|
||||
formats: ALL_FORMATS,
|
||||
});
|
||||
|
||||
expect(await input1.getFormat()).toBe(MP4);
|
||||
expect(await input2.getFormat()).toBe(MP4);
|
||||
|
||||
expect(!source._disposed);
|
||||
input1.dispose();
|
||||
expect(!source._disposed);
|
||||
input2.dispose();
|
||||
expect(source._disposed);
|
||||
});
|
||||
Reference in New Issue
Block a user