{"version":3,"file":"index.mjs","names":[],"sources":["../../src/ts/index.ts"],"sourcesContent":["import { join, dirname } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { createRequire } from \"node:module\";\n\n// Get the directory name of the current module\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\n\n// Get the project root directory (two levels up from __dirname)\nconst projectRoot = join(__dirname, \"../../\");\n\nexport type GStreamerPropertyPrimitiveValue = string | number | boolean | bigint;\nexport type GStreamerPropertyValue =\n  | GStreamerPropertyPrimitiveValue\n  | GStreamerPropertyPrimitiveValue[];\n\n// Sample object returned for GST_VALUE_HOLDS_SAMPLE properties\nexport type GStreamerSample = {\n  buffer?: Buffer;\n  flags?: number;\n  caps?: {\n    name?: string;\n    // Additional structure fields (format, width, height, framerate, etc.)\n    [key: string]: GStreamerPropertyValue | undefined;\n  };\n};\n\n// GStreamer message object returned by busPop\nexport type GstMessage = {\n  type: string;\n  srcElementName?: string;\n  timestamp: bigint;\n  structureName?: string;\n  // Structure fields are added dynamically based on message content\n  [key: string]: GStreamerPropertyValue | undefined;\n\n  // Error message specific fields\n  errorMessage?: string;\n  errorDomain?: string;\n  errorCode?: number;\n  debugInfo?: string;\n\n  // Warning message specific fields\n  warningMessage?: string;\n  warningDomain?: string;\n  warningCode?: number;\n\n  // State change message specific fields\n  oldState?: number;\n  newState?: number;\n  pendingState?: number;\n};\n\n// Extended return types including arrays, buffers, and samples\nexport type GStreamerPropertyReturnValue =\n  | GStreamerPropertyValue\n  | Record<string, GStreamerPropertyValue>\n  | Buffer\n  | GStreamerSample\n  | null;\n\nexport type GStreamerPropertyResult =\n  | { type: \"primitive\"; value: GStreamerPropertyPrimitiveValue }\n  | { type: \"array\"; value: GStreamerPropertyPrimitiveValue[] }\n  | { type: \"object\"; value: Record<string, GStreamerPropertyValue> }\n  | { type: \"buffer\"; value: Buffer }\n  | { type: \"sample\"; value: GStreamerSample }\n  | null;\n\n// State change result returned by play(), pause(), and stop()\nexport type StateChangeResult = {\n  result: \"success\" | \"async\" | \"no-preroll\" | \"failure\" | \"unknown\";\n  finalState: number;\n  targetState: number;\n};\n\nexport type RTPData = {\n  timestamp: number;\n  sequence: number;\n  ssrc: number;\n  payloadType: number;\n};\n\nexport type GstPad = {\n  name: string;\n  direction: number; // 0 = unknown, 1 = src, 2 = sink\n  caps: string | null;\n};\n\nexport type BufferData = {\n  // Raw buffer data\n  buffer?: Buffer;\n\n  // Timing information\n  pts?: number; // Presentation timestamp (nanoseconds)\n  dts?: number; // Decode timestamp (nanoseconds)\n  duration?: number; // Buffer duration (nanoseconds)\n  offset?: number;\n  offsetEnd?: number;\n\n  // Buffer flags\n  flags: number;\n\n  // Caps information (stream format)\n  caps?: {\n    name?: string;\n    [key: string]: GStreamerPropertyValue | undefined;\n  };\n\n  // RTP-specific data (only present for RTP streams)\n  rtp?: RTPData;\n};\n\nexport type ElementBase = {\n  getElementProperty: (key: string) => GStreamerPropertyResult;\n  setElementProperty: (key: string, value: GStreamerPropertyValue) => void;\n  addPadProbe: (padName: string, callback: (bufferData: BufferData) => void) => () => void;\n  setPad: (attribute: string, padName: string) => void;\n  getPad: (padName: string) => GstPad | null;\n};\n\ntype Element = {\n  readonly type: \"element\";\n} & ElementBase;\n\nexport type AppSinkElement = {\n  readonly type: \"app-sink-element\";\n  getSample(timeoutMs?: number): Promise<GStreamerSample | null>;\n  onSample(callback: (sample: GStreamerSample) => void): () => void;\n} & ElementBase;\n\nexport type AppSrcElement = {\n  readonly type: \"app-src-element\";\n  push(buffer: Buffer, pts?: Buffer | number): void;\n  endOfStream(): void;\n} & ElementBase;\n\ninterface Pipeline {\n  play(timeoutMs?: number): Promise<StateChangeResult>;\n  pause(timeoutMs?: number): Promise<StateChangeResult>;\n  stop(timeoutMs?: number): Promise<StateChangeResult>;\n  playing(): boolean;\n  getElementByName(name: string): Element | AppSinkElement | AppSrcElement | null;\n  queryPosition(): number;\n  queryDuration(): number;\n  busPop(timeoutMs?: number): Promise<GstMessage | null>;\n  seek(positionSeconds: number): boolean;\n}\n\ninterface PipelineConstructor {\n  new (pipeline: string): Pipeline;\n  elementExists(elementName: string): boolean;\n}\n\n// Define the interface for the native addon\ninterface NativeAddon {\n  Pipeline: PipelineConstructor;\n  GStreamerPropertyValue: GStreamerPropertyValue;\n  GStreamerSample: GStreamerSample;\n  GStreamerPropertyReturnValue: GStreamerPropertyReturnValue;\n}\n\n// Create require function for ESM\nconst require = createRequire(import.meta.url);\n\n// Load the native addon\nconst nativeAddon: NativeAddon = require(join(projectRoot, \"build/Release/gst_kit.node\"));\n\n/**\n * https://gstreamer.freedesktop.org/documentation/gstreamer/gstbuffer.html?gi-language=c#GstBufferFlags\n * */\nexport const GstBufferFlags = {\n  GST_BUFFER_FLAG_LIVE: 16,\n  GST_BUFFER_FLAG_DECODE_ONLY: 32,\n  GST_BUFFER_FLAG_DISCONT: 64,\n  GST_BUFFER_FLAG_RESYNC: 128,\n  GST_BUFFER_FLAG_CORRUPTED: 256,\n  GST_BUFFER_FLAG_MARKER: 512,\n  GST_BUFFER_FLAG_HEADER: 1024,\n  GST_BUFFER_FLAG_GAP: 2048,\n  GST_BUFFER_FLAG_DROPPABLE: 4096,\n  GST_BUFFER_FLAG_DELTA_UNIT: 8192,\n  GST_BUFFER_FLAG_TAG_MEMORY: 16384,\n  GST_BUFFER_FLAG_SYNC_AFTER: 32768,\n  GST_BUFFER_FLAG_NON_DROPPABLE: 65536,\n  GST_BUFFER_FLAG_LAST: 1048576,\n} as const;\n\nconst { Pipeline: PipelineClass } = nativeAddon;\n\nexport { PipelineClass as Pipeline };\n\nexport default { ...nativeAddon, GstBufferFlags };\n"],"mappings":";;;;AASA,MAAM,cAAc,KAHF,QADC,cAAc,OAAO,KAAK,GACV,CAGF,GAAG,QAAQ;AA6J5C,MAAM,cAHU,cAAc,OAAO,KAAK,GAGH,EAAE,KAAK,aAAa,4BAA4B,CAAC;;;;AAKxF,MAAa,iBAAiB;CAC5B,sBAAsB;CACtB,6BAA6B;CAC7B,yBAAyB;CACzB,wBAAwB;CACxB,2BAA2B;CAC3B,wBAAwB;CACxB,wBAAwB;CACxB,qBAAqB;CACrB,2BAA2B;CAC3B,4BAA4B;CAC5B,4BAA4B;CAC5B,4BAA4B;CAC5B,+BAA+B;CAC/B,sBAAsB;AACxB;AAEA,MAAM,EAAE,UAAU,kBAAkB;AAIpC,IAAA,aAAe;CAAE,GAAG;CAAa;AAAe"}