UNPKG

tav-media

Version:

Cross platform media editing framework

299 lines (298 loc) 10.5 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()); }); }; var PAGPlayer_1; import { PAGModule } from './pag-module'; import { PAGFile } from './pag-file'; import { PAGSurface } from './pag-surface'; import { wasmAwaitRewind, wasmAsyncMethod, destroyVerify } from './utils/decorators'; import { getWasmIns, layer2typeLayer, proxyVector } from './utils/type-utils'; import { Matrix } from './core/matrix'; import { PAGComposition } from './pag-composition'; let PAGPlayer = PAGPlayer_1 = class PAGPlayer { constructor(wasmIns) { this.isDestroyed = false; this.wasmIns = wasmIns; } static create() { const wasmIns = new PAGModule._PAGPlayer(); if (!wasmIns) throw new Error('Create PAGPlayer fail!'); return new PAGPlayer_1(wasmIns); } /** * Set the progress of play position, the value is from 0.0 to 1.0. */ setProgress(progress) { this.wasmIns._setProgress(progress); } /** * Apply all pending changes to the target surface immediately. Returns true if the content has * changed. */ flush() { return __awaiter(this, void 0, void 0, function* () { return PAGModule.webAssemblyQueue.exec(this.wasmIns._flush, this.wasmIns); }); } /** * [Internal] Apply all pending changes to the target surface immediately. Returns true if the content has * changed. */ flushInternal(callback) { return __awaiter(this, void 0, void 0, function* () { return PAGModule.webAssemblyQueue.exec(() => __awaiter(this, void 0, void 0, function* () { const res = yield this.wasmIns._flush(); callback(res); return res; }), this.wasmIns); }); } /** * The duration of current composition in microseconds. */ duration() { return this.wasmIns._duration(); } /** * Returns the current progress of play position, the value is from 0.0 to 1.0. */ getProgress() { return this.wasmIns._getProgress(); } /** * If set to false, the player skips rendering for video composition. */ videoEnabled() { return this.wasmIns._videoEnabled(); } /** * Set the value of videoEnabled property. */ setVideoEnabled(enabled) { this.wasmIns._setVideoEnabled(enabled); } /** * If set to true, PAGPlayer caches an internal bitmap representation of the static content for each * layer. This caching can increase performance for layers that contain complex vector content. The * execution speed can be significantly faster depending on the complexity of the content, but it * requires extra graphics memory. The default value is true. */ cacheEnabled() { return this.wasmIns._cacheEnabled(); } /** * Set the value of cacheEnabled property. */ setCacheEnabled(enabled) { this.wasmIns._setCacheEnabled(enabled); } /** * This value defines the scale factor for internal graphics caches, ranges from 0.0 to 1.0. The * scale factors less than 1.0 may result in blurred output, but it can reduce the usage of graphics * memory which leads to better performance. The default value is 1.0. */ cacheScale() { return this.wasmIns._cacheScale(); } /** * Set the value of cacheScale property. */ setCacheScale(value) { this.wasmIns._setCacheScale(value); } /** * The maximum frame rate for rendering, ranges from 1 to 60. If set to a value less than the actual * frame rate from composition, it drops frames but increases performance. Otherwise, it has no * effect. The default value is 60. */ maxFrameRate() { return this.wasmIns._maxFrameRate(); } /** * Set the maximum frame rate for rendering. */ setMaxFrameRate(value) { this.wasmIns._setMaxFrameRate(value); } /** * Returns the current scale mode. */ scaleMode() { return this.wasmIns._scaleMode(); } /** * Specifies the rule of how to scale the pag content to fit the surface size. The matrix * changes when this method is called. */ setScaleMode(value) { this.wasmIns._setScaleMode(value); } /** * Set the PAGSurface object for PAGPlayer to render onto. */ setSurface(pagSurface) { this.wasmIns._setSurface(getWasmIns(pagSurface)); } /** * * Returns the current PAGComposition for PAGPlayer to render as content. */ getComposition() { const wasmIns = this.wasmIns._getComposition(); if (!wasmIns) throw new Error('Get composition fail!'); if (wasmIns._isPAGFile()) { return new PAGFile(wasmIns); } return new PAGComposition(wasmIns); } /** * * Sets a new PAGComposition for PAGPlayer to render as content. */ setComposition(pagComposition) { this.wasmIns._setComposition(getWasmIns(pagComposition)); } /** * Returns the PAGSurface object for PAGPlayer to render onto. */ getSurface() { const wasmIns = this.wasmIns._getSurface(); if (!wasmIns) throw new Error('Get surface fail!'); return new PAGSurface(wasmIns); } /** * Returns a copy of current matrix. */ matrix() { const wasmIns = this.wasmIns._matrix(); if (!wasmIns) throw new Error('Get matrix fail!'); return new Matrix(wasmIns); } /** * Set the transformation which will be applied to the composition. The scaleMode property * will be set to PAGScaleMode::None when this method is called. */ setMatrix(matrix) { this.wasmIns._setMatrix(matrix.wasmIns); } /** * Set the progress of play position to next frame. It is applied only when the composition is not * null. */ nextFrame() { this.wasmIns._nextFrame(); } /** * Set the progress of play position to previous frame. It is applied only when the composition is * not null. */ preFrame() { this.wasmIns._preFrame(); } /** * If true, PAGPlayer clears the whole content of PAGSurface before drawing anything new to it. * The default value is true. */ autoClear() { return this.wasmIns._autoClear(); } /** * Sets the autoClear property. */ setAutoClear(value) { this.wasmIns._setAutoClear(value); } /** * Returns a rectangle that defines the original area of the layer, which is not transformed by * the matrix. */ getBounds(pagLayer) { return this.wasmIns._getBounds(pagLayer.wasmIns); } /** * Returns an array of layers that lie under the specified point. The point is in pixels and from * * this PAGComposition's local coordinates. */ getLayersUnderPoint(localX, localY) { const wasmIns = this.wasmIns._getLayersUnderPoint(localX, localY); if (!wasmIns) throw new Error(`Get layers under point, x: ${localX} y:${localY} fail!`); return proxyVector(wasmIns, layer2typeLayer); } /** * Evaluates the PAGLayer to see if it overlaps or intersects with the specified point. The point * * is in the coordinate space of the PAGSurface, not the PAGComposition that contains the * PAGLayer. It always returns false if the PAGLayer or its parent (or parent's parent...) has not * been added to this PAGPlayer. The pixelHitTest parameter indicates whether or not to check * against the actual pixels of the object (true) or the bounding box (false). Returns true if the * PAGLayer overlaps or intersects with the specified point. */ hitTestPoint(pagLayer, surfaceX, surfaceY, pixelHitTest = false) { return this.wasmIns._hitTestPoint(pagLayer.wasmIns, surfaceX, surfaceY, pixelHitTest); } /** * The time cost by rendering in microseconds. */ renderingTime() { return this.wasmIns._renderingTime(); } /** * The time cost by image decoding in microseconds. */ imageDecodingTime() { return this.wasmIns._imageDecodingTime(); } /** * The time cost by presenting in microseconds. */ presentingTime() { return this.wasmIns._presentingTime(); } /** * The memory cost by graphics in bytes. */ graphicsMemory() { return this.wasmIns._graphicsMemory(); } /** * Prepares the player for the next flush() call. It collects all CPU tasks from the current * progress of the composition and runs them asynchronously in parallel. It is usually used for * speeding up the first frame rendering. */ prepare() { return PAGModule.webAssemblyQueue.exec(this.wasmIns._prepare, this.wasmIns); } destroy() { this.wasmIns.delete(); this.isDestroyed = true; } }; __decorate([ wasmAsyncMethod ], PAGPlayer.prototype, "flush", null); __decorate([ wasmAsyncMethod ], PAGPlayer.prototype, "flushInternal", null); PAGPlayer = PAGPlayer_1 = __decorate([ destroyVerify, wasmAwaitRewind ], PAGPlayer); export { PAGPlayer };