UNPKG

tav-media

Version:

Cross platform media editing framework

86 lines (85 loc) 3.91 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { tav } from '../tav'; import { allowCallNativeAnytime } from '../types/tav-object'; import { Dispatcher } from '../utils/dispatcher'; /** * A audio reader used to obtain the audio frames of a media. * @category Engine */ export class TAVAudioReader { constructor(ref) { this.ref = ref; } /** * Make a audio reader from a media clip. */ static MakeFrom(root, sampleRate, sampleCount, channels, isRecycle) { return __awaiter(this, void 0, void 0, function* () { const rootNative = yield root.build(); if (!rootNative) return null; const native = yield tav.webAssemblyQueue.exec(tav.TAVAudioReader.MakeFrom, tav.TAVAudioReader, rootNative, sampleRate, sampleCount, channels, isRecycle); if (!native) return null; return new TAVAudioReader(native); }); } /** * Sets the current frame to the specified time. * @param targetTime The target time to seek to. * @returns seeked or not. */ seekTo(targetTime) { return __awaiter(this, void 0, void 0, function* () { return TAVAudioReader.dispatcher.queue(() => __awaiter(this, void 0, void 0, function* () { var _a, _b; if (tav.webAssemblyQueue) { const result = yield tav.webAssemblyQueue.exec((_a = this.ref) === null || _a === void 0 ? void 0 : _a.seekTo, this.ref, targetTime); return result; } return yield ((_b = this.ref) === null || _b === void 0 ? void 0 : _b.seekTo(targetTime)); }), 'seekTo'); }); } /** * Reads the next audio frame for the output. */ readNextFrame() { return __awaiter(this, void 0, void 0, function* () { yield TAVAudioReader.dispatcher.queue(() => __awaiter(this, void 0, void 0, function* () { var _a, _b; if (tav.webAssemblyQueue) { yield tav.webAssemblyQueue.exec((_a = this.ref) === null || _a === void 0 ? void 0 : _a.readNextFrame, this.ref); } else { return yield ((_b = this.ref) === null || _b === void 0 ? void 0 : _b.readNextFrame()); } }), 'readNextFrame'); }); } build() { return this.ref; } release() { var _a; return (_a = this.ref) === null || _a === void 0 ? void 0 : _a.delete(); } } TAVAudioReader.dispatcher = new Dispatcher(); __decorate([ allowCallNativeAnytime ], TAVAudioReader.prototype, "release", null);