@luxonis/visualizer-protobuf 3.1.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/{depth-BJ1GI-lD.js → depth-DlC6A3Te.js} +65 -1
  2. package/dist/{deserialization.worker-CpadaVUC.js → deserialization.worker-iLQYf6dz.js} +229 -157
  3. package/dist/{index-lYAUlgOC.js → index-BFHnSq_D.js} +2 -2
  4. package/dist/{index-BQ8ArLBu.js → index-BGnPWAxp.js} +2 -2
  5. package/dist/{index-DEAiAkuM.js → index-BN1XXU26.js} +2 -2
  6. package/dist/{index-DcciMCSs.js → index-BsCcQbSo.js} +2 -2
  7. package/dist/{index-D2XLTZD6.js → index-BwszuQxy.js} +2 -2
  8. package/dist/{index-kX1V6BdV.js → index-CUGaisTR.js} +2 -2
  9. package/dist/{index-D_329r0B.js → index-CYRDaPyN.js} +2 -2
  10. package/dist/{index-POkmkil6.js → index-CekJcKgK.js} +2 -2
  11. package/dist/{index-JtoOqqNH.js → index-CrP2kJym.js} +2 -2
  12. package/dist/{index-M2eVbe_0.js → index-D5H3iCVT.js} +2 -2
  13. package/dist/{index-DQuS45dq.js → index-DBwLkKPx.js} +61 -28
  14. package/dist/{index-ByH52TmT.js → index-DG1nCi2m.js} +2 -2
  15. package/dist/{index-BoW57zty.js → index-DoxJYKhI.js} +2 -2
  16. package/dist/{index-oMO5wzwz.js → index-DsJRU5mK.js} +2 -2
  17. package/dist/{index-DnF6OLu4.js → index-DslURtpP.js} +2 -2
  18. package/dist/{index-TElhyLth.js → index-VjMojhAJ.js} +3 -3
  19. package/dist/{index-BFuISzq9.js → index-Zjw0dbGD.js} +2 -2
  20. package/dist/{index-ruqK13K_.js → index-mkLEh24H.js} +2 -2
  21. package/dist/{index-B0OcF19n.js → index-tLfWrXcg.js} +2 -2
  22. package/dist/{index-BimzNWm5.js → index-xU2jSCtf.js} +2 -2
  23. package/dist/index.js +2 -2
  24. package/dist/lib/src/components/Panel.d.ts.map +1 -1
  25. package/dist/lib/src/components/Panel.js +3 -1
  26. package/dist/lib/src/components/Panel.js.map +1 -1
  27. package/dist/lib/src/connection/connection.d.ts.map +1 -1
  28. package/dist/lib/src/connection/connection.js +7 -1
  29. package/dist/lib/src/connection/connection.js.map +1 -1
  30. package/dist/lib/src/connection/foxglove-connection.d.ts +6 -0
  31. package/dist/lib/src/connection/foxglove-connection.d.ts.map +1 -1
  32. package/dist/lib/src/connection/foxglove-connection.js +24 -3
  33. package/dist/lib/src/connection/foxglove-connection.js.map +1 -1
  34. package/dist/lib/src/context/VisualizerContext.d.ts +2 -0
  35. package/dist/lib/src/context/VisualizerContext.d.ts.map +1 -1
  36. package/dist/lib/src/context/VisualizerContext.js +7 -0
  37. package/dist/lib/src/context/VisualizerContext.js.map +1 -1
  38. package/dist/lib/src/messaging/deserialization/video/h264.d.ts +2 -1
  39. package/dist/lib/src/messaging/deserialization/video/h264.d.ts.map +1 -1
  40. package/dist/lib/src/messaging/deserialization/video/h264.js +142 -97
  41. package/dist/lib/src/messaging/deserialization/video/h264.js.map +1 -1
  42. package/dist/lib/src/messaging/deserialization/video/h265.d.ts +2 -1
  43. package/dist/lib/src/messaging/deserialization/video/h265.d.ts.map +1 -1
  44. package/dist/lib/src/messaging/deserialization/video/h265.js +57 -16
  45. package/dist/lib/src/messaging/deserialization/video/h265.js.map +1 -1
  46. package/dist/lib/src/messaging/deserialization.worker.d.ts +3 -1
  47. package/dist/lib/src/messaging/deserialization.worker.d.ts.map +1 -1
  48. package/dist/lib/src/messaging/deserialization.worker.js +28 -12
  49. package/dist/lib/src/messaging/deserialization.worker.js.map +1 -1
  50. package/dist/lib/src/utils/error.d.ts +17 -4
  51. package/dist/lib/src/utils/error.d.ts.map +1 -1
  52. package/dist/lib/src/utils/error.js +59 -6
  53. package/dist/lib/src/utils/error.js.map +1 -1
  54. package/package.json +1 -1
@@ -2,7 +2,7 @@
2
2
  import { b as _objectSpread2, P as PointsAnnotationType, p as protobufsBySchema, T as Type, h as Profile } from './protobuf-Be0G3NFz.js';
3
3
  import { e as expose } from './comlink-jf8bdrAf.js';
4
4
  import { t as typescript } from './index-Dqm1x8G2.js';
5
- import { R as parseMessage, e as estimateObjectSize, S as fromMillis, d as dist, U as parsePixelFormat, V as deserializeDepthFrame } from './depth-BJ1GI-lD.js';
5
+ import { U as parseMessage, e as estimateObjectSize, V as fromMillis, W as DecoderRuntimeError, d as dist, X as parsePixelFormat, Y as UnsupportedTopicError, Z as NotInSecureContextError, _ as EncodedStreamNotSupportedError, $ as deserializeDepthFrame } from './depth-DlC6A3Te.js';
6
6
  import { L as Logger } from './logger-Bqy1nuLj.js';
7
7
  import { i as isCapableOfEncodedStream } from './encoding-jXImCIb4.js';
8
8
  import 'react';
@@ -802,64 +802,30 @@ function ensureWebCodecsSupported(target) {
802
802
  // file, You can obtain one at http://mozilla.org/MPL/2.0/
803
803
 
804
804
  const logger$2 = Logger.getLogger();
805
- function bgrxToI420(bgrx, width, height) {
806
- if ((width & 1) !== 0 || (height & 1) !== 0) {
807
- throw new Error("I420 requires even width and height.");
805
+ function closeDecoder$1(decoder) {
806
+ if (!decoder) {
807
+ return;
808
808
  }
809
- const ySize = width * height;
810
- const uvSize = width * height >> 2;
811
- const out = new Uint8Array(ySize + uvSize + uvSize);
812
- const Y = out.subarray(0, ySize);
813
- const U = out.subarray(ySize, ySize + uvSize);
814
- const V = out.subarray(ySize + uvSize);
815
- const stride = width * 4;
816
- const clamp8 = x => x < 0 ? 0 : x > 255 ? 255 : x | 0;
817
- for (let y = 0; y < height; y += 2) {
818
- const row0 = y * stride;
819
- const row1 = (y + 1) * stride;
820
- for (let x = 0; x < width; x += 2) {
821
- const p00 = row0 + x * 4;
822
- const p01 = row0 + (x + 1) * 4;
823
- const p10 = row1 + x * 4;
824
- const p11 = row1 + (x + 1) * 4;
825
- const B00 = bgrx[p00 + 0],
826
- G00 = bgrx[p00 + 1],
827
- R00 = bgrx[p00 + 2];
828
- const B01 = bgrx[p01 + 0],
829
- G01 = bgrx[p01 + 1],
830
- R01 = bgrx[p01 + 2];
831
- const B10 = bgrx[p10 + 0],
832
- G10 = bgrx[p10 + 1],
833
- R10 = bgrx[p10 + 2];
834
- const B11 = bgrx[p11 + 0],
835
- G11 = bgrx[p11 + 1],
836
- R11 = bgrx[p11 + 2];
837
- const Y00 = 77 * R00 + 150 * G00 + 29 * B00 + 128 >> 8;
838
- const Y01 = 77 * R01 + 150 * G01 + 29 * B01 + 128 >> 8;
839
- const Y10 = 77 * R10 + 150 * G10 + 29 * B10 + 128 >> 8;
840
- const Y11 = 77 * R11 + 150 * G11 + 29 * B11 + 128 >> 8;
841
- const yRow0 = y * width + x;
842
- const yRow1 = (y + 1) * width + x;
843
- Y[yRow0 + 0] = Y00;
844
- Y[yRow0 + 1] = Y01;
845
- Y[yRow1 + 0] = Y10;
846
- Y[yRow1 + 1] = Y11;
847
- const Ravg = R00 + R01 + R10 + R11 >> 2;
848
- const Gavg = G00 + G01 + G10 + G11 >> 2;
849
- const Bavg = B00 + B01 + B10 + B11 >> 2;
850
- const Uval = clamp8((-43 * Ravg - 85 * Gavg + 128 * Bavg >> 8) + 128);
851
- const Vval = clamp8((128 * Ravg - 107 * Gavg - 21 * Bavg >> 8) + 128);
852
- const uvCol = x >> 1;
853
- const uvRow = y >> 1;
854
- const uvW = width >> 1;
855
- const uvPos = uvRow * uvW + uvCol;
856
- U[uvPos] = Uval;
857
- V[uvPos] = Vval;
858
- }
809
+ if (decoder.state === "closed") {
810
+ return;
859
811
  }
860
- return out;
812
+ try {
813
+ decoder.close();
814
+ } catch (error) {
815
+ logger$2.warn("Failed to close H264 decoder cleanly.", error);
816
+ }
817
+ }
818
+ function closeTopicDecoder$1(topic, topicDecoders) {
819
+ const decoderInfo = topicDecoders.get(topic);
820
+ closeDecoder$1(decoderInfo === null || decoderInfo === void 0 ? void 0 : decoderInfo.decoder);
821
+ decoderInfo === null || decoderInfo === void 0 || decoderInfo.timing.clear();
822
+ decoderInfo === null || decoderInfo === void 0 || decoderInfo.transformations.clear();
861
823
  }
862
- function bgraToI420(bgra, width, height) {
824
+ function isIgnorableInitialDecodeError(error) {
825
+ const message = error instanceof Error ? error.message : String(error);
826
+ return message.includes("A key frame is required after configure() or flush()");
827
+ }
828
+ function packedToI420(packed, width, height, stride, format, cropLeft = 0, cropTop = 0) {
863
829
  if ((width & 1) !== 0 || (height & 1) !== 0) {
864
830
  throw new Error("I420 requires even width and height.");
865
831
  }
@@ -869,28 +835,29 @@ function bgraToI420(bgra, width, height) {
869
835
  const Y = out.subarray(0, ySize);
870
836
  const U = out.subarray(ySize, ySize + uvSize);
871
837
  const V = out.subarray(ySize + uvSize);
872
- const stride = width * 4;
838
+ const isRgbLayout = format === "RGBX" || format === "RGBA";
873
839
  const clamp8 = x => x < 0 ? 0 : x > 255 ? 255 : x | 0;
874
840
  for (let y = 0; y < height; y += 2) {
875
- const row0 = y * stride;
876
- const row1 = (y + 1) * stride;
841
+ const row0 = (y + cropTop) * stride;
842
+ const row1 = (y + cropTop + 1) * stride;
877
843
  for (let x = 0; x < width; x += 2) {
878
- const p00 = row0 + x * 4;
879
- const p01 = row0 + (x + 1) * 4;
880
- const p10 = row1 + x * 4;
881
- const p11 = row1 + (x + 1) * 4;
882
- const B00 = bgra[p00 + 0],
883
- G00 = bgra[p00 + 1],
884
- R00 = bgra[p00 + 2];
885
- const B01 = bgra[p01 + 0],
886
- G01 = bgra[p01 + 1],
887
- R01 = bgra[p01 + 2];
888
- const B10 = bgra[p10 + 0],
889
- G10 = bgra[p10 + 1],
890
- R10 = bgra[p10 + 2];
891
- const B11 = bgra[p11 + 0],
892
- G11 = bgra[p11 + 1],
893
- R11 = bgra[p11 + 2];
844
+ const srcX = x + cropLeft;
845
+ const p00 = row0 + srcX * 4;
846
+ const p01 = row0 + (srcX + 1) * 4;
847
+ const p10 = row1 + srcX * 4;
848
+ const p11 = row1 + (srcX + 1) * 4;
849
+ const R00 = packed[p00 + (isRgbLayout ? 0 : 2)];
850
+ const G00 = packed[p00 + 1];
851
+ const B00 = packed[p00 + (isRgbLayout ? 2 : 0)];
852
+ const R01 = packed[p01 + (isRgbLayout ? 0 : 2)];
853
+ const G01 = packed[p01 + 1];
854
+ const B01 = packed[p01 + (isRgbLayout ? 2 : 0)];
855
+ const R10 = packed[p10 + (isRgbLayout ? 0 : 2)];
856
+ const G10 = packed[p10 + 1];
857
+ const B10 = packed[p10 + (isRgbLayout ? 2 : 0)];
858
+ const R11 = packed[p11 + (isRgbLayout ? 0 : 2)];
859
+ const G11 = packed[p11 + 1];
860
+ const B11 = packed[p11 + (isRgbLayout ? 2 : 0)];
894
861
  const Y00 = 77 * R00 + 150 * G00 + 29 * B00 + 128 >> 8;
895
862
  const Y01 = 77 * R01 + 150 * G01 + 29 * B01 + 128 >> 8;
896
863
  const Y10 = 77 * R10 + 150 * G10 + 29 * B10 + 128 >> 8;
@@ -916,15 +883,12 @@ function bgraToI420(bgra, width, height) {
916
883
  }
917
884
  return out;
918
885
  }
919
- function convertNv12ToI420(nv12Buffer, width, height, stride) {
920
- const actualStride = stride !== null && stride !== void 0 ? stride : width;
886
+ function convertNv12ToI420(nv12Buffer, width, height, yStride, uvStride, yOffset = 0, uvOffset = yStride * height, cropLeft = 0, cropTop = 0) {
921
887
  const ySize = width * height;
922
888
  const uvSize = ySize / 4;
923
889
  const i420Buffer = new Uint8Array(ySize + 2 * uvSize);
924
-
925
- // Copy Y plane row by row (accounting for stride)
926
890
  for (let row = 0; row < height; row++) {
927
- const srcOffset = row * actualStride;
891
+ const srcOffset = yOffset + (row + cropTop) * yStride + cropLeft;
928
892
  const dstOffset = row * width;
929
893
  i420Buffer.set(nv12Buffer.subarray(srcOffset, srcOffset + width), dstOffset);
930
894
  }
@@ -932,12 +896,12 @@ function convertNv12ToI420(nv12Buffer, width, height, stride) {
932
896
  const vPlaneOffset = ySize + uvSize;
933
897
  const uvHeight = height / 2;
934
898
  const uvWidth = width / 2;
935
-
936
- // De-interleave UV plane row by row (accounting for stride)
899
+ const uvCropLeft = cropLeft >> 1;
900
+ const uvCropTop = cropTop >> 1;
937
901
  for (let row = 0; row < uvHeight; row++) {
938
902
  for (let col = 0; col < uvWidth; col++) {
939
903
  var _nv12Buffer$srcIndex, _nv12Buffer;
940
- const srcIndex = height * actualStride + row * actualStride + col * 2;
904
+ const srcIndex = uvOffset + (row + uvCropTop) * uvStride + (col + uvCropLeft) * 2;
941
905
  const dstIndex = row * uvWidth + col;
942
906
  i420Buffer[uPlaneOffset + dstIndex] = (_nv12Buffer$srcIndex = nv12Buffer[srcIndex]) !== null && _nv12Buffer$srcIndex !== void 0 ? _nv12Buffer$srcIndex : 0; // U
943
907
  i420Buffer[vPlaneOffset + dstIndex] = (_nv12Buffer = nv12Buffer[srcIndex + 1]) !== null && _nv12Buffer !== void 0 ? _nv12Buffer : 0; // V
@@ -945,47 +909,77 @@ function convertNv12ToI420(nv12Buffer, width, height, stride) {
945
909
  }
946
910
  return i420Buffer;
947
911
  }
912
+ function repackI420(source, width, height, yLayout, uLayout, vLayout, cropLeft = 0, cropTop = 0) {
913
+ const ySize = width * height;
914
+ const uvWidth = width >> 1;
915
+ const uvHeight = height >> 1;
916
+ const uvSize = uvWidth * uvHeight;
917
+ const out = new Uint8Array(ySize + uvSize * 2);
918
+ const uvCropLeft = cropLeft >> 1;
919
+ const uvCropTop = cropTop >> 1;
920
+ for (let row = 0; row < height; row++) {
921
+ const srcOffset = yLayout.offset + (row + cropTop) * yLayout.stride + cropLeft;
922
+ out.set(source.subarray(srcOffset, srcOffset + width), row * width);
923
+ }
924
+ for (let row = 0; row < uvHeight; row++) {
925
+ const uSrcOffset = uLayout.offset + (row + uvCropTop) * uLayout.stride + uvCropLeft;
926
+ const vSrcOffset = vLayout.offset + (row + uvCropTop) * vLayout.stride + uvCropLeft;
927
+ const dstOffset = row * uvWidth;
928
+ out.set(source.subarray(uSrcOffset, uSrcOffset + uvWidth), ySize + dstOffset);
929
+ out.set(source.subarray(vSrcOffset, vSrcOffset + uvWidth), ySize + uvSize + dstOffset);
930
+ }
931
+ return out;
932
+ }
948
933
  function createVideoDecoder$1({
949
934
  topic,
950
935
  callback,
951
- topicDecoders
936
+ topicDecoders,
937
+ onError
952
938
  }) {
939
+ let hasProducedFrame = false;
953
940
  return new VideoDecoder({
954
941
  output: async frame => {
955
- var _topicDecoders$get$ti, _topicDecoders$get, _topicDecoders$get2, _topicDecoders$get3;
942
+ var _visibleRect$width, _visibleRect$height, _visibleRect$x, _visibleRect$y, _topicDecoders$get$ti, _topicDecoders$get, _topicDecoders$get2, _topicDecoders$get3;
943
+ hasProducedFrame = true;
944
+ const visibleRect = frame.visibleRect;
945
+ const frameWidth = (_visibleRect$width = visibleRect === null || visibleRect === void 0 ? void 0 : visibleRect.width) !== null && _visibleRect$width !== void 0 ? _visibleRect$width : frame.codedWidth;
946
+ const frameHeight = (_visibleRect$height = visibleRect === null || visibleRect === void 0 ? void 0 : visibleRect.height) !== null && _visibleRect$height !== void 0 ? _visibleRect$height : frame.codedHeight;
947
+ const cropLeft = (_visibleRect$x = visibleRect === null || visibleRect === void 0 ? void 0 : visibleRect.x) !== null && _visibleRect$x !== void 0 ? _visibleRect$x : 0;
948
+ const cropTop = (_visibleRect$y = visibleRect === null || visibleRect === void 0 ? void 0 : visibleRect.y) !== null && _visibleRect$y !== void 0 ? _visibleRect$y : 0;
956
949
  let finalBuffer = new Uint8Array(frame.allocationSize());
950
+ logger$2.warn(`H264 decoder output format: ${frame.format}, coded=${frame.codedWidth}x${frame.codedHeight}, display=${frame.displayWidth}x${frame.displayHeight}, visible=${frameWidth}x${frameHeight}@${cropLeft},${cropTop}`);
957
951
  switch (frame.format) {
958
952
  case "I420":
959
953
  {
960
- finalBuffer = new Uint8Array(frame.allocationSize());
961
- await frame.copyTo(finalBuffer);
954
+ const i420Buffer = new Uint8Array(frame.allocationSize());
955
+ const layouts = await frame.copyTo(i420Buffer);
956
+ const [yLayout, uLayout, vLayout] = layouts;
957
+ finalBuffer = yLayout != undefined && uLayout != undefined && vLayout != undefined ? repackI420(i420Buffer, frameWidth, frameHeight, yLayout, uLayout, vLayout, cropLeft, cropTop) : i420Buffer;
962
958
  break;
963
959
  }
964
960
  case "NV12":
965
961
  {
962
+ var _yLayout$stride, _uvLayout$stride, _yLayout$offset, _uvLayout$offset, _yLayout$stride2;
966
963
  const nv12Buffer = new Uint8Array(frame.allocationSize());
967
- await frame.copyTo(nv12Buffer);
968
- finalBuffer = convertNv12ToI420(nv12Buffer, frame.displayWidth, frame.displayHeight, frame.codedWidth);
964
+ const layouts = await frame.copyTo(nv12Buffer);
965
+ const [yLayout, uvLayout] = layouts;
966
+ finalBuffer = convertNv12ToI420(nv12Buffer, frameWidth, frameHeight, (_yLayout$stride = yLayout === null || yLayout === void 0 ? void 0 : yLayout.stride) !== null && _yLayout$stride !== void 0 ? _yLayout$stride : frame.codedWidth, (_uvLayout$stride = uvLayout === null || uvLayout === void 0 ? void 0 : uvLayout.stride) !== null && _uvLayout$stride !== void 0 ? _uvLayout$stride : frame.codedWidth, (_yLayout$offset = yLayout === null || yLayout === void 0 ? void 0 : yLayout.offset) !== null && _yLayout$offset !== void 0 ? _yLayout$offset : 0, (_uvLayout$offset = uvLayout === null || uvLayout === void 0 ? void 0 : uvLayout.offset) !== null && _uvLayout$offset !== void 0 ? _uvLayout$offset : ((_yLayout$stride2 = yLayout === null || yLayout === void 0 ? void 0 : yLayout.stride) !== null && _yLayout$stride2 !== void 0 ? _yLayout$stride2 : frame.codedWidth) * frame.codedHeight, cropLeft, cropTop);
969
967
  break;
970
968
  }
971
969
  case "RGBX":
970
+ case "RGBA":
972
971
  case "BGRX":
973
- {
974
- const bgrxBuffer = new Uint8Array(frame.allocationSize());
975
- await frame.copyTo(bgrxBuffer);
976
- logger$2.warn("PointCloud decoder received RGBX frame.");
977
- finalBuffer = bgrxToI420(bgrxBuffer, frame.codedWidth, frame.codedHeight);
978
- break;
979
- }
980
972
  case "BGRA":
981
973
  {
982
- const bgraBuffer = new Uint8Array(frame.allocationSize());
983
- await frame.copyTo(bgraBuffer);
984
- finalBuffer = bgraToI420(bgraBuffer, frame.codedWidth, frame.codedHeight);
974
+ var _layout$stride;
975
+ const packedBuffer = new Uint8Array(frame.allocationSize());
976
+ const [layout] = await frame.copyTo(packedBuffer);
977
+ logger$2.warn(`H264 decoder received ${frame.format} frame.`);
978
+ finalBuffer = packedToI420(packedBuffer, frameWidth, frameHeight, (_layout$stride = layout === null || layout === void 0 ? void 0 : layout.stride) !== null && _layout$stride !== void 0 ? _layout$stride : frame.codedWidth * 4, frame.format, cropLeft, cropTop);
985
979
  break;
986
980
  }
987
981
  }
988
- if (frame.format !== "I420" && frame.format !== "NV12" && frame.format !== "RGBX" && frame.format !== "BGRX" && frame.format !== "BGRA") {
982
+ if (frame.format !== "I420" && frame.format !== "NV12" && frame.format !== "RGBX" && frame.format !== "RGBA" && frame.format !== "BGRX" && frame.format !== "BGRA") {
989
983
  logger$2.warn("H264 decoder received unexpected frame format:", frame.format);
990
984
  }
991
985
  const receiveTime = (_topicDecoders$get$ti = (_topicDecoders$get = topicDecoders.get(topic)) === null || _topicDecoders$get === void 0 ? void 0 : _topicDecoders$get.timing.get(frame.timestamp)) !== null && _topicDecoders$get$ti !== void 0 ? _topicDecoders$get$ti : dist.fromMicros(frame.timestamp);
@@ -994,11 +988,11 @@ function createVideoDecoder$1({
994
988
  const foxgloveMessage = {
995
989
  timestamp: receiveTime,
996
990
  frame_id: `h264-${topic}-frame`,
997
- width: frame.displayWidth,
998
- height: frame.displayHeight,
991
+ width: frameWidth,
992
+ height: frameHeight,
999
993
  data: finalBuffer,
1000
994
  encoding: "yuv420p",
1001
- step: frame.displayWidth
995
+ step: frameWidth
1002
996
  };
1003
997
  callback({
1004
998
  topic,
@@ -1010,14 +1004,24 @@ function createVideoDecoder$1({
1010
1004
  });
1011
1005
  frame.close();
1012
1006
  },
1013
- error: logger$2.error
1007
+ error: error => {
1008
+ if (!hasProducedFrame && isIgnorableInitialDecodeError(error)) {
1009
+ logger$2.warn(`Ignoring initial H264 decoder error for topic ${topic}: ${error.message}`);
1010
+ closeTopicDecoder$1(topic, topicDecoders);
1011
+ return;
1012
+ }
1013
+ logger$2.error(error);
1014
+ closeTopicDecoder$1(topic, topicDecoders);
1015
+ onError(new DecoderRuntimeError(topic, error.message));
1016
+ }
1014
1017
  });
1015
1018
  }
1016
1019
  async function deserializeEncodedFrameH264({
1017
1020
  topic,
1018
1021
  message,
1019
1022
  topicDecoders,
1020
- callback
1023
+ callback,
1024
+ onError
1021
1025
  }) {
1022
1026
  const {
1023
1027
  receiveTime
@@ -1026,21 +1030,35 @@ async function deserializeEncodedFrameH264({
1026
1030
  if (!supported) {
1027
1031
  return;
1028
1032
  }
1029
- if (!topicDecoders.has(topic)) {
1033
+ const existingDecoderInfo = topicDecoders.get(topic);
1034
+ if (!existingDecoderInfo || existingDecoderInfo.decoder.state === "closed") {
1030
1035
  const decoder = createVideoDecoder$1({
1031
1036
  topic,
1032
1037
  callback,
1033
- topicDecoders
1034
- });
1035
- decoder.configure({
1036
- codec: "avc1.42001E",
1037
- optimizeForLatency: true
1038
- });
1039
- topicDecoders.set(topic, {
1040
- decoder,
1041
- timing: new Map(),
1042
- transformations: new Map()
1038
+ topicDecoders,
1039
+ onError
1043
1040
  });
1041
+ try {
1042
+ decoder.configure({
1043
+ codec: "avc1.42001E",
1044
+ optimizeForLatency: true
1045
+ });
1046
+ } catch (error) {
1047
+ closeDecoder$1(decoder);
1048
+ onError(new DecoderRuntimeError(topic, error instanceof Error ? error.message : "Failed to configure H.264 decoder."));
1049
+ return;
1050
+ }
1051
+ if (existingDecoderInfo) {
1052
+ existingDecoderInfo.decoder = decoder;
1053
+ existingDecoderInfo.timing.clear();
1054
+ existingDecoderInfo.transformations.clear();
1055
+ } else {
1056
+ topicDecoders.set(topic, {
1057
+ decoder,
1058
+ timing: new Map(),
1059
+ transformations: new Map()
1060
+ });
1061
+ }
1044
1062
  }
1045
1063
  const decoderInfo = topicDecoders.get(topic);
1046
1064
  if (!decoderInfo) {
@@ -1061,8 +1079,13 @@ async function deserializeEncodedFrameH264({
1061
1079
  try {
1062
1080
  const chunk = new EncodedVideoChunk(frame);
1063
1081
  decoderInfo.decoder.decode(chunk);
1064
- } catch (_unused) {
1065
- topicDecoders.delete(topic);
1082
+ } catch (error) {
1083
+ if (isIgnorableInitialDecodeError(error)) {
1084
+ closeTopicDecoder$1(topic, topicDecoders);
1085
+ return;
1086
+ }
1087
+ closeTopicDecoder$1(topic, topicDecoders);
1088
+ onError(new DecoderRuntimeError(topic, error instanceof Error ? error.message : "Failed to decode H.264 frame."));
1066
1089
  }
1067
1090
  }
1068
1091
 
@@ -1071,10 +1094,30 @@ async function deserializeEncodedFrameH264({
1071
1094
  // file, You can obtain one at http://mozilla.org/MPL/2.0/
1072
1095
 
1073
1096
  const logger$1 = Logger.getLogger();
1097
+ function closeDecoder(decoder) {
1098
+ if (!decoder) {
1099
+ return;
1100
+ }
1101
+ if (decoder.state === "closed") {
1102
+ return;
1103
+ }
1104
+ try {
1105
+ decoder.close();
1106
+ } catch (error) {
1107
+ logger$1.warn("Failed to close H265 decoder cleanly.", error);
1108
+ }
1109
+ }
1110
+ function closeTopicDecoder(topic, topicDecoders) {
1111
+ const decoderInfo = topicDecoders.get(topic);
1112
+ closeDecoder(decoderInfo === null || decoderInfo === void 0 ? void 0 : decoderInfo.decoder);
1113
+ decoderInfo === null || decoderInfo === void 0 || decoderInfo.timing.clear();
1114
+ decoderInfo === null || decoderInfo === void 0 || decoderInfo.transformations.clear();
1115
+ }
1074
1116
  function createVideoDecoder({
1075
1117
  topic,
1076
1118
  callback,
1077
- topicDecoders
1119
+ topicDecoders,
1120
+ onError
1078
1121
  }) {
1079
1122
  return new VideoDecoder({
1080
1123
  output: async frame => {
@@ -1104,14 +1147,19 @@ function createVideoDecoder({
1104
1147
  });
1105
1148
  frame.close();
1106
1149
  },
1107
- error: logger$1.error
1150
+ error: error => {
1151
+ logger$1.error(error);
1152
+ closeTopicDecoder(topic, topicDecoders);
1153
+ onError(new DecoderRuntimeError(topic, error.message));
1154
+ }
1108
1155
  });
1109
1156
  }
1110
1157
  async function deserializeEncodedFrameH265({
1111
1158
  topic,
1112
1159
  message,
1113
1160
  topicDecoders,
1114
- callback
1161
+ callback,
1162
+ onError
1115
1163
  }) {
1116
1164
  const {
1117
1165
  receiveTime
@@ -1120,21 +1168,35 @@ async function deserializeEncodedFrameH265({
1120
1168
  if (!supported) {
1121
1169
  return;
1122
1170
  }
1123
- if (!topicDecoders.has(topic)) {
1171
+ const existingDecoderInfo = topicDecoders.get(topic);
1172
+ if (!existingDecoderInfo || existingDecoderInfo.decoder.state === "closed") {
1124
1173
  const decoder = createVideoDecoder({
1125
1174
  topic,
1126
1175
  callback,
1127
- topicDecoders
1128
- });
1129
- decoder.configure({
1130
- codec: "hev1.1.6.L93.B0",
1131
- optimizeForLatency: true
1132
- });
1133
- topicDecoders.set(topic, {
1134
- decoder,
1135
- timing: new Map(),
1136
- transformations: new Map()
1176
+ topicDecoders,
1177
+ onError
1137
1178
  });
1179
+ try {
1180
+ decoder.configure({
1181
+ codec: "hev1.1.6.L93.B0",
1182
+ optimizeForLatency: true
1183
+ });
1184
+ } catch (error) {
1185
+ closeDecoder(decoder);
1186
+ onError(new DecoderRuntimeError(topic, error instanceof Error ? error.message : "Failed to configure H.265 decoder."));
1187
+ return;
1188
+ }
1189
+ if (existingDecoderInfo) {
1190
+ existingDecoderInfo.decoder = decoder;
1191
+ existingDecoderInfo.timing.clear();
1192
+ existingDecoderInfo.transformations.clear();
1193
+ } else {
1194
+ topicDecoders.set(topic, {
1195
+ decoder,
1196
+ timing: new Map(),
1197
+ transformations: new Map()
1198
+ });
1199
+ }
1138
1200
  }
1139
1201
  const decoderInfo = topicDecoders.get(topic);
1140
1202
  if (!decoderInfo) {
@@ -1155,8 +1217,9 @@ async function deserializeEncodedFrameH265({
1155
1217
  try {
1156
1218
  const chunk = new EncodedVideoChunk(frame);
1157
1219
  decoderInfo.decoder.decode(chunk);
1158
- } catch (_unused) {
1159
- topicDecoders.delete(topic);
1220
+ } catch (error) {
1221
+ closeTopicDecoder(topic, topicDecoders);
1222
+ onError(new DecoderRuntimeError(topic, error instanceof Error ? error.message : "Failed to decode H.265 frame."));
1160
1223
  }
1161
1224
  }
1162
1225
 
@@ -1206,23 +1269,18 @@ async function deserializeMJPEGFrame({
1206
1269
  });
1207
1270
  }
1208
1271
 
1209
- class EncodedStreamNotSupportedError extends Error {
1210
- constructor(topicName) {
1211
- super("Encoded stream not supported on this platform");
1212
- this.topicName = void 0;
1213
- this.name = "EncodedStreamNotSupportedError";
1214
- this.errorType = "EncodedStreamNotSupportedError";
1215
- this.topicName = topicName;
1216
- Object.setPrototypeOf(this, EncodedStreamNotSupportedError.prototype);
1217
- }
1218
- }
1219
-
1220
1272
  const logger = Logger.getLogger();
1221
1273
  function errorInstanceToErrorCode(error) {
1274
+ if (error instanceof UnsupportedTopicError) {
1275
+ return "UnsupportedTopic";
1276
+ }
1277
+ if (error instanceof NotInSecureContextError) {
1278
+ return "NotInSecureContext";
1279
+ }
1222
1280
  if (error instanceof EncodedStreamNotSupportedError) {
1223
1281
  return "EncodedStreamNotSupported";
1224
1282
  }
1225
- return "Error";
1283
+ return "DecoderError";
1226
1284
  }
1227
1285
  const topicDecoders = new Map();
1228
1286
  const topicSizes = new Map();
@@ -1230,6 +1288,14 @@ let callback;
1230
1288
  function initCallback(cb) {
1231
1289
  callback = cb;
1232
1290
  }
1291
+ function ensureEncodedStreamSupport(topic) {
1292
+ if (!globalThis.isSecureContext) {
1293
+ throw new NotInSecureContextError(topic);
1294
+ }
1295
+ if (!isCapableOfEncodedStream()) {
1296
+ throw new EncodedStreamNotSupportedError(topic);
1297
+ }
1298
+ }
1233
1299
  function handleMessageToDecode({
1234
1300
  schema,
1235
1301
  buffer,
@@ -1243,12 +1309,14 @@ function handleMessageToDecode({
1243
1309
  // Type information about an error gets lost during transfer from worker to main thread
1244
1310
  // This means that we have to remap the errors based on type here to an 'error enum'
1245
1311
  // Which can then be parsed on the main thread
1246
- errorCallback === null || errorCallback === void 0 || errorCallback(errorInstanceToErrorCode(error), topic, {});
1312
+ errorCallback === null || errorCallback === void 0 || errorCallback(errorInstanceToErrorCode(error), topic, {
1313
+ message: error.message
1314
+ });
1247
1315
  };
1248
1316
  const protobufSchema = protobufsBySchema[schema];
1249
1317
  if (!protobufSchema) {
1250
1318
  logger.warn(`Unsupported message schema "${schema}"`);
1251
- handleDecodingError(new Error(`Unsupported message schema "${schema}"`));
1319
+ handleDecodingError(new UnsupportedTopicError(topic, `Unsupported message schema "${schema}"`));
1252
1320
  return;
1253
1321
  }
1254
1322
  const bufferArray = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
@@ -1268,7 +1336,8 @@ function handleMessageToDecode({
1268
1336
  message,
1269
1337
  callback,
1270
1338
  type: protobufSchema.type,
1271
- maxSteroDepth: stereoDepthMaxValue
1339
+ maxSteroDepth: stereoDepthMaxValue,
1340
+ onError: handleDecodingError
1272
1341
  }).catch(handleDecodingError);
1273
1342
  } catch (error) {
1274
1343
  handleDecodingError(error);
@@ -1283,14 +1352,13 @@ async function deserializeDepthAiMessage(args) {
1283
1352
  message,
1284
1353
  callback,
1285
1354
  topic,
1286
- maxSteroDepth
1355
+ maxSteroDepth,
1356
+ onError
1287
1357
  } = args;
1288
1358
  switch (type) {
1289
1359
  case "encodedFrame":
1290
1360
  {
1291
- if (!isCapableOfEncodedStream()) {
1292
- throw new EncodedStreamNotSupportedError(topic);
1293
- }
1361
+ ensureEncodedStreamSupport(topic);
1294
1362
  topicSizes.set(topic, {
1295
1363
  width: message.width,
1296
1364
  height: message.height
@@ -1300,7 +1368,8 @@ async function deserializeDepthAiMessage(args) {
1300
1368
  topic,
1301
1369
  message,
1302
1370
  topicDecoders,
1303
- callback
1371
+ callback,
1372
+ onError
1304
1373
  });
1305
1374
  } else if (message.profile === Profile.JPEG) {
1306
1375
  await deserializeMJPEGFrame({
@@ -1313,7 +1382,8 @@ async function deserializeDepthAiMessage(args) {
1313
1382
  topic,
1314
1383
  message,
1315
1384
  topicDecoders,
1316
- callback
1385
+ callback,
1386
+ onError
1317
1387
  });
1318
1388
  } else ;
1319
1389
  break;
@@ -1332,11 +1402,13 @@ async function deserializeDepthAiMessage(args) {
1332
1402
  switch (messageType) {
1333
1403
  case Type.BITSTREAM:
1334
1404
  {
1405
+ ensureEncodedStreamSupport(topic);
1335
1406
  await deserializeEncodedFrameH264({
1336
1407
  topic,
1337
1408
  message,
1338
1409
  topicDecoders,
1339
- callback
1410
+ callback,
1411
+ onError
1340
1412
  });
1341
1413
  break;
1342
1414
  }
@@ -1428,7 +1500,7 @@ async function deserializeDepthAiMessage(args) {
1428
1500
  default:
1429
1501
  {
1430
1502
  logger.warn(`Message decoding failed: unsupported type "${type}"`);
1431
- break;
1503
+ throw new UnsupportedTopicError(topic, `Unsupported message type "${type}"`);
1432
1504
  }
1433
1505
  }
1434
1506
  }
@@ -1,8 +1,8 @@
1
1
  'use client';
2
- import { a6 as ContextTracker, Y as ExternalTokenizer, U as styleTags, V as tags, Z as LRParser, W as LRLanguage, Q as indentNodeProp, a4 as delimitedIndent, T as foldNodeProp, a5 as foldInside, X as LanguageSupport, ad as parseMixed } from './index-DQuS45dq.js';
2
+ import { a6 as ContextTracker, Y as ExternalTokenizer, U as styleTags, V as tags, Z as LRParser, W as LRLanguage, Q as indentNodeProp, a4 as delimitedIndent, T as foldNodeProp, a5 as foldInside, X as LanguageSupport, ad as parseMixed } from './index-DBwLkKPx.js';
3
3
  import './protobuf-Be0G3NFz.js';
4
4
  import './logger-Bqy1nuLj.js';
5
- import './depth-BJ1GI-lD.js';
5
+ import './depth-DlC6A3Te.js';
6
6
  import './comlink-jf8bdrAf.js';
7
7
  import 'react';
8
8
  import 'zustand';
@@ -1,8 +1,8 @@
1
1
  'use client';
2
- import { Y as ExternalTokenizer, a6 as ContextTracker, U as styleTags, V as tags, Z as LRParser, a2 as LocalTokenGroup, a7 as snippetCompletion, a1 as syntaxTree, W as LRLanguage, Q as indentNodeProp, R as continuedIndent, a3 as flatIndent, a4 as delimitedIndent, T as foldNodeProp, a5 as foldInside, X as LanguageSupport, $ as ifNotIn, a0 as completeFromList, a8 as IterMode, a9 as NodeWeakMap } from './index-DQuS45dq.js';
2
+ import { Y as ExternalTokenizer, a6 as ContextTracker, U as styleTags, V as tags, Z as LRParser, a2 as LocalTokenGroup, a7 as snippetCompletion, a1 as syntaxTree, W as LRLanguage, Q as indentNodeProp, R as continuedIndent, a3 as flatIndent, a4 as delimitedIndent, T as foldNodeProp, a5 as foldInside, X as LanguageSupport, $ as ifNotIn, a0 as completeFromList, a8 as IterMode, a9 as NodeWeakMap } from './index-DBwLkKPx.js';
3
3
  import './protobuf-Be0G3NFz.js';
4
4
  import './logger-Bqy1nuLj.js';
5
- import './depth-BJ1GI-lD.js';
5
+ import './depth-DlC6A3Te.js';
6
6
  import './comlink-jf8bdrAf.js';
7
7
  import 'react';
8
8
  import 'zustand';
@@ -1,8 +1,8 @@
1
1
  'use client';
2
- import { U as styleTags, V as tags, Z as LRParser, W as LRLanguage, Q as indentNodeProp, R as continuedIndent, a3 as flatIndent, a4 as delimitedIndent, T as foldNodeProp, a5 as foldInside, X as LanguageSupport } from './index-DQuS45dq.js';
2
+ import { U as styleTags, V as tags, Z as LRParser, W as LRLanguage, Q as indentNodeProp, R as continuedIndent, a3 as flatIndent, a4 as delimitedIndent, T as foldNodeProp, a5 as foldInside, X as LanguageSupport } from './index-DBwLkKPx.js';
3
3
  import './protobuf-Be0G3NFz.js';
4
4
  import './logger-Bqy1nuLj.js';
5
- import './depth-BJ1GI-lD.js';
5
+ import './depth-DlC6A3Te.js';
6
6
  import './comlink-jf8bdrAf.js';
7
7
  import 'react';
8
8
  import 'zustand';
@@ -1,8 +1,8 @@
1
1
  'use client';
2
- import { Y as ExternalTokenizer, U as styleTags, V as tags, Z as LRParser, a2 as LocalTokenGroup, W as LRLanguage, Q as indentNodeProp, R as continuedIndent, a3 as flatIndent, a4 as delimitedIndent, T as foldNodeProp, a5 as foldInside, X as LanguageSupport } from './index-DQuS45dq.js';
2
+ import { Y as ExternalTokenizer, U as styleTags, V as tags, Z as LRParser, a2 as LocalTokenGroup, W as LRLanguage, Q as indentNodeProp, R as continuedIndent, a3 as flatIndent, a4 as delimitedIndent, T as foldNodeProp, a5 as foldInside, X as LanguageSupport } from './index-DBwLkKPx.js';
3
3
  import './protobuf-Be0G3NFz.js';
4
4
  import './logger-Bqy1nuLj.js';
5
- import './depth-BJ1GI-lD.js';
5
+ import './depth-DlC6A3Te.js';
6
6
  import './comlink-jf8bdrAf.js';
7
7
  import 'react';
8
8
  import 'zustand';