{"version":3,"file":"decoder-e1MoKcpb.mjs","names":[],"sources":["../src/video/decoder/decoder.ts"],"sourcesContent":["/* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD */\n/* SPDX-License-Identifier: Apache-2.0 */\n\n/**\n * Video decoder service module for JS apps — wraps `brookesia_service_video` decoder RPC.\n *\n * @example\n * import decoder from '@brookesia/service/video/decoder';\n * if (decoder.available()) {\n *   decoder.open({ source_format: 'MJPEG', enable_stream_mode: true });\n *   decoder.start();\n *   decoder.feedFrame(new Uint8Array([0, 1, 2]));\n *   decoder.stop();\n *   decoder.close();\n * }\n */\n\nimport {\n  closeDecoder,\n  closeVideoDecoder,\n  feedDecoderFrame,\n  isVideoDecoderAvailable,\n  openDecoder,\n  openVideoDecoder,\n  startDecoder,\n  stopDecoder,\n  type VideoDecoderClientOptions,\n  type VideoDecoderHandle,\n} from './decoder-client.ts';\nimport type {\n  VideoDecoderConfig,\n  VideoDecoderDisplayConfig,\n  VideoDecoderFrame,\n  VideoDecoderSinkFormat,\n  VideoDecoderSourceFormat,\n  VideoDecoderState,\n} from './decoder-types.ts';\n\nexport type {\n  VideoDecoderConfig,\n  VideoDecoderDisplayConfig,\n  VideoDecoderFrame,\n  VideoDecoderSinkFormat,\n  VideoDecoderSourceFormat,\n  VideoDecoderState,\n};\n\nexport type VideoDecoderModuleOptions = VideoDecoderClientOptions;\n\ntype State = {\n  handle: VideoDecoderHandle | null;\n  options: VideoDecoderModuleOptions;\n};\n\nconst state: State = { handle: null, options: {} };\n\nfunction handle(): VideoDecoderHandle {\n  if (state.handle !== null) {\n    return state.handle;\n  }\n  if (!isVideoDecoderAvailable(state.options)) {\n    throw new Error('Video decoder service is not available');\n  }\n  state.handle = openVideoDecoder(state.options);\n  return state.handle;\n}\n\n/**\n * Inject a mock RPC host and reset the cached service handle (vitest / Node only).\n *\n * @param options - Client options, typically `{ host }` from `@brookesia/service/hosts/video-decoder`\n */\nexport function configure(options: VideoDecoderModuleOptions): void {\n  if (state.handle !== null) {\n    closeVideoDecoder(state.handle, state.options);\n  }\n  state.handle = null;\n  state.options = options;\n}\n\nconst decoder = {\n  /** @returns `true` when video decoder service is registered */\n  available(): boolean {\n    return isVideoDecoderAvailable(state.options);\n  },\n\n  /** Release the video decoder service binding. */\n  close(): void {\n    if (state.handle === null) {\n      return;\n    }\n    closeVideoDecoder(state.handle, state.options);\n    state.handle = null;\n  },\n\n  /**\n   * Open a decoding session.\n   *\n   * @param config - `{ source_format: 'MJPEG' | 'H264', enable_stream_mode, enable_hw_acceleration }`\n   */\n  open(config: VideoDecoderConfig): void {\n    openDecoder(handle(), config, state.options);\n  },\n\n  /** Close the active decoding session (keeps service handle). */\n  closeDecoder(): void {\n    closeDecoder(handle(), state.options);\n  },\n\n  /** Start the decoder pipeline. */\n  start(): void {\n    startDecoder(handle(), state.options);\n  },\n\n  /** Stop the decoder pipeline. */\n  stop(): void {\n    stopDecoder(handle(), state.options);\n  },\n\n  /**\n   * Feed one compressed frame into the decoder.\n   *\n   * @param frame - `Uint8Array` of JPEG/H264 NAL data\n   */\n  feedFrame(frame: VideoDecoderFrame): void {\n    feedDecoderFrame(handle(), frame, state.options);\n  },\n};\n\nexport default decoder;\n"],"mappings":";;;;;;;;;;;;;;;AAsDA,MAAM,QAAe;CAAE,QAAQ;CAAM,SAAS,CAAC;AAAE;AAEjD,SAAS,SAA6B;CACpC,IAAI,MAAM,WAAW,MACnB,OAAO,MAAM;CAEf,IAAI,CAAC,wBAAwB,MAAM,OAAO,GACxC,MAAM,IAAI,MAAM,wCAAwC;CAE1D,MAAM,SAAS,iBAAiB,MAAM,OAAO;CAC7C,OAAO,MAAM;AACf;;;;;;AAOA,SAAgB,UAAU,SAA0C;CAClE,IAAI,MAAM,WAAW,MACnB,kBAAkB,MAAM,QAAQ,MAAM,OAAO;CAE/C,MAAM,SAAS;CACf,MAAM,UAAU;AAClB;AAEA,MAAM,UAAU;;CAEd,YAAqB;EACnB,OAAO,wBAAwB,MAAM,OAAO;CAC9C;;CAGA,QAAc;EACZ,IAAI,MAAM,WAAW,MACnB;EAEF,kBAAkB,MAAM,QAAQ,MAAM,OAAO;EAC7C,MAAM,SAAS;CACjB;;;;;;CAOA,KAAK,QAAkC;EACrC,YAAY,OAAO,GAAG,QAAQ,MAAM,OAAO;CAC7C;;CAGA,eAAqB;EACnB,aAAa,OAAO,GAAG,MAAM,OAAO;CACtC;;CAGA,QAAc;EACZ,aAAa,OAAO,GAAG,MAAM,OAAO;CACtC;;CAGA,OAAa;EACX,YAAY,OAAO,GAAG,MAAM,OAAO;CACrC;;;;;;CAOA,UAAU,OAAgC;EACxC,iBAAiB,OAAO,GAAG,OAAO,MAAM,OAAO;CACjD;AACF"}