{"version":3,"sources":["../src/video_source.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type {\n  CaptureVideoFrameResponse,\n  NewVideoSourceResponse,\n  VideoSourceInfo,\n} from '@livekit/rtc-ffi-bindings';\nimport {\n  CaptureVideoFrameRequest,\n  NewVideoSourceRequest,\n  VideoRotation,\n  VideoSourceType,\n} from '@livekit/rtc-ffi-bindings';\nimport { FfiClient, FfiHandle } from './ffi_client.js';\nimport type { VideoFrame } from './video_frame.js';\n\nexport class VideoSource {\n  /** @internal */\n  info?: VideoSourceInfo;\n  /** @internal */\n  ffiHandle: FfiHandle;\n  /** @internal */\n  closed = false;\n\n  width: number;\n  height: number;\n\n  constructor(width: number, height: number) {\n    this.width = width;\n    this.height = height;\n\n    const req = new NewVideoSourceRequest({\n      type: VideoSourceType.VIDEO_SOURCE_NATIVE,\n      resolution: {\n        width: width,\n        height: height,\n      },\n    });\n\n    const res = FfiClient.instance.request<NewVideoSourceResponse>({\n      message: {\n        case: 'newVideoSource',\n        value: req,\n      },\n    });\n\n    this.info = res.source?.info;\n    this.ffiHandle = new FfiHandle(res.source!.handle!.id!);\n  }\n\n  captureFrame(\n    frame: VideoFrame,\n    timestampUs = BigInt(0),\n    rotation = VideoRotation.VIDEO_ROTATION_0,\n  ) {\n    if (this.closed) {\n      throw new Error('VideoSource is closed');\n    }\n    const req = new CaptureVideoFrameRequest({\n      sourceHandle: this.ffiHandle.handle,\n      buffer: frame.protoInfo(),\n      rotation,\n      timestampUs,\n    });\n\n    FfiClient.instance.request<CaptureVideoFrameResponse>({\n      message: { case: 'captureVideoFrame', value: req },\n    });\n  }\n\n  async close() {\n    this.ffiHandle.dispose();\n    this.closed = true;\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,8BAKO;AACP,wBAAqC;AAG9B,MAAM,YAAY;AAAA,EAWvB,YAAY,OAAe,QAAgB;AAL3C;AAAA,kBAAS;AAvBX;AA6BI,SAAK,QAAQ;AACb,SAAK,SAAS;AAEd,UAAM,MAAM,IAAI,8CAAsB;AAAA,MACpC,MAAM,wCAAgB;AAAA,MACtB,YAAY;AAAA,QACV;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAC;AAED,UAAM,MAAM,4BAAU,SAAS,QAAgC;AAAA,MAC7D,SAAS;AAAA,QACP,MAAM;AAAA,QACN,OAAO;AAAA,MACT;AAAA,IACF,CAAC;AAED,SAAK,QAAO,SAAI,WAAJ,mBAAY;AACxB,SAAK,YAAY,IAAI,4BAAU,IAAI,OAAQ,OAAQ,EAAG;AAAA,EACxD;AAAA,EAEA,aACE,OACA,cAAc,OAAO,CAAC,GACtB,WAAW,sCAAc,kBACzB;AACA,QAAI,KAAK,QAAQ;AACf,YAAM,IAAI,MAAM,uBAAuB;AAAA,IACzC;AACA,UAAM,MAAM,IAAI,iDAAyB;AAAA,MACvC,cAAc,KAAK,UAAU;AAAA,MAC7B,QAAQ,MAAM,UAAU;AAAA,MACxB;AAAA,MACA;AAAA,IACF,CAAC;AAED,gCAAU,SAAS,QAAmC;AAAA,MACpD,SAAS,EAAE,MAAM,qBAAqB,OAAO,IAAI;AAAA,IACnD,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,QAAQ;AACZ,SAAK,UAAU,QAAQ;AACvB,SAAK,SAAS;AAAA,EAChB;AACF;","names":[]}