// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Microsoft Software License Terms for the Azure Communications Services, Azure CPaaS, MICROSOFT AZURE COMMUNICATION CALLING EFFECTS
// See LICENSE file for license information.

import{EventEmitterImpl as e}from"./a3496b.js";import{CapabilityChecker as t}from"./93bb86.js";import{ACSEffectsConfigProvider as r}from"./164f58.js";import{WebCVProvider as i}from"./b079de.js";import{stringifyObject as o}from"./cd7b0b.js";import{getSdkInternalVersion as n,getSdkVersion as s}from"./8fdf2a.js";var __awaiter=function(e,t,r,i){function adopt(e){return e instanceof r?e:new r((function(t){t(e)}))}return new(r||(r=Promise))((function(r,o){function fulfilled(e){try{step(i.next(e))}catch(e){o(e)}}function rejected(e){try{step(i.throw(e))}catch(e){o(e)}}function step(e){e.done?r(e.value):adopt(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())}))};class VideoEffectInternalBase{constructor(o,n){this.effectName=o,this.logger=n,this.eventEmitter=new e(this.logger),this._acsEffectsConfigProvider=new r(this.eventEmitter,this.logger.createChild("VE:ACSEffConfigProvider"),this.effectName),this._capabilityChecker=new t(this._acsEffectsConfigProvider,this.logger.createChild("VE:CapabilityChecker")),this.webcvProvider=new i(this.logger.createChild(this.name)),this.logger.info("VideoEffectsBase ctor success")}get name(){return this.effectName}get capabilityChecker(){return this._capabilityChecker}get configProvider(){return this._acsEffectsConfigProvider}setConfig(e){return __awaiter(this,void 0,void 0,(function*(){this.configProvider.updateConfig(Object.assign(Object.assign({},this.configProvider.config),{videoEffects:Object.assign({},e)}))}))}dispose(){var e,t;return __awaiter(this,void 0,void 0,(function*(){this.eventEmitter.removeAllListeners(),yield null===(t=null===(e=this.webcvProvider)||void 0===e?void 0:e.webcvVideoEffectProvider)||void 0===t?void 0:t.disposeAsync(),this.webcvProvider=null}))}processFrame(e){return __awaiter(this,void 0,void 0,(function*(){return e}))}getStats(){return this.webcvProvider?this.webcvProvider.webcvVideoEffectProvider.getStats():(this.logger.debug("Effect provider not found, cannot collect stats."),null)}getVersion(e){return e?n():s()}on(e,t){if("processingStarted"!==e&&"processingStopped"!==e&&"processingError"!==e&&"configUpdated"!==e)throw new Error(`Not able to subscribe to event ${e}, unknown event name`);this.eventEmitter.on(e,t)}off(e,t){if("processingStarted"!==e&&"processingStopped"!==e&&"processingError"!==e&&"configUpdated"!==e)throw new Error(`Not able to unsubscribe to event ${e}, unknown event name`);this.eventEmitter.off(e,t)}handleProcessingError(e){this.logger.error(o(e)),this.eventEmitter.emit("processingError",e)}}export{VideoEffectInternalBase};
