react-native-skia-webgpu-video 0.0.0-stage → 0.1.0-beta.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 (237) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +303 -2
  3. package/android/BUILD_VALIDATION.md +62 -0
  4. package/android/CMakeLists.txt +99 -0
  5. package/android/build-validation.json +262 -0
  6. package/android/build.gradle +185 -0
  7. package/android/cpp/EncoderTargets.cpp +226 -0
  8. package/android/cpp/EncoderTargets.h +70 -0
  9. package/android/cpp/JNIHelpers.cpp +15 -0
  10. package/android/cpp/JNIHelpers.h +20 -0
  11. package/android/cpp/NativeEventDispatcher.cpp +59 -0
  12. package/android/cpp/NativeEventDispatcher.h +31 -0
  13. package/android/cpp/NativeHardwareBuffer.cpp +397 -0
  14. package/android/cpp/NativeHardwareBuffer.h +34 -0
  15. package/android/cpp/NativeRgbaBuffer.cpp +45 -0
  16. package/android/cpp/NativeRgbaBuffer.h +9 -0
  17. package/android/cpp/ReturnedVideoFrames.h +37 -0
  18. package/android/cpp/RgbaFrameLease.h +53 -0
  19. package/android/cpp/VideoCapabilities.cpp +87 -0
  20. package/android/cpp/VideoCapabilities.h +44 -0
  21. package/android/cpp/VideoComposition.cpp +170 -0
  22. package/android/cpp/VideoComposition.h +36 -0
  23. package/android/cpp/VideoCompositionFramesExtractor.cpp +82 -0
  24. package/android/cpp/VideoCompositionFramesExtractor.h +48 -0
  25. package/android/cpp/VideoCompositionFramesExtractorHostObject.cpp +230 -0
  26. package/android/cpp/VideoCompositionFramesExtractorHostObject.h +42 -0
  27. package/android/cpp/VideoCompositionFramesExtractorSyncHostObject.cpp +133 -0
  28. package/android/cpp/VideoCompositionFramesExtractorSyncHostObject.h +46 -0
  29. package/android/cpp/VideoEncoderHostObject.cpp +318 -0
  30. package/android/cpp/VideoEncoderHostObject.h +76 -0
  31. package/android/cpp/VideoFrame.cpp +293 -0
  32. package/android/cpp/VideoFrame.h +27 -0
  33. package/android/cpp/VideoPlayer.cpp +96 -0
  34. package/android/cpp/VideoPlayer.h +52 -0
  35. package/android/cpp/VideoPlayerHostObject.cpp +225 -0
  36. package/android/cpp/VideoPlayerHostObject.h +43 -0
  37. package/android/cpp/cpp-adapter.cpp +316 -0
  38. package/android/gradle.properties +5 -0
  39. package/android/instrumentation-inventory.json +178 -0
  40. package/android/proguard-rules.pro +4 -0
  41. package/android/src/main/AndroidManifest.xml +2 -0
  42. package/android/src/main/java/com/azzapp/rnskv/AudioCompositionExporter.java +537 -0
  43. package/android/src/main/java/com/azzapp/rnskv/AudioCompositionPlayer.java +321 -0
  44. package/android/src/main/java/com/azzapp/rnskv/BufferLifetime.java +55 -0
  45. package/android/src/main/java/com/azzapp/rnskv/DecodeRequests.java +100 -0
  46. package/android/src/main/java/com/azzapp/rnskv/DecoderWindow.java +55 -0
  47. package/android/src/main/java/com/azzapp/rnskv/DisplayVsyncPeriod.java +72 -0
  48. package/android/src/main/java/com/azzapp/rnskv/EGLResourcesHolder.java +132 -0
  49. package/android/src/main/java/com/azzapp/rnskv/EGLUtils.java +225 -0
  50. package/android/src/main/java/com/azzapp/rnskv/FrameSize.java +50 -0
  51. package/android/src/main/java/com/azzapp/rnskv/GLFrameExtractor.java +510 -0
  52. package/android/src/main/java/com/azzapp/rnskv/JNIHelpers.java +12 -0
  53. package/android/src/main/java/com/azzapp/rnskv/NativeEventDispatcher.java +25 -0
  54. package/android/src/main/java/com/azzapp/rnskv/NativeHardwareBuffer.java +62 -0
  55. package/android/src/main/java/com/azzapp/rnskv/NativeRgbaBuffer.java +43 -0
  56. package/android/src/main/java/com/azzapp/rnskv/ReactNativeSkiaVideoModule.java +45 -0
  57. package/android/src/main/java/com/azzapp/rnskv/ReactNativeSkiaVideoPackage.java +43 -0
  58. package/android/src/main/java/com/azzapp/rnskv/ReactNativeSkiaVideoSpec.java +9 -0
  59. package/android/src/main/java/com/azzapp/rnskv/RgbaBufferAllocator.java +114 -0
  60. package/android/src/main/java/com/azzapp/rnskv/RgbaLayout.java +33 -0
  61. package/android/src/main/java/com/azzapp/rnskv/SurfaceOutputPolicy.java +13 -0
  62. package/android/src/main/java/com/azzapp/rnskv/TextureRenderer.java +150 -0
  63. package/android/src/main/java/com/azzapp/rnskv/TimeHelpers.java +11 -0
  64. package/android/src/main/java/com/azzapp/rnskv/VideoCapabilities.java +354 -0
  65. package/android/src/main/java/com/azzapp/rnskv/VideoComposition.java +147 -0
  66. package/android/src/main/java/com/azzapp/rnskv/VideoCompositionDecoder.java +779 -0
  67. package/android/src/main/java/com/azzapp/rnskv/VideoCompositionFramesExtractor.java +463 -0
  68. package/android/src/main/java/com/azzapp/rnskv/VideoCompositionFramesExtractorSync.java +241 -0
  69. package/android/src/main/java/com/azzapp/rnskv/VideoCompositionItemDecoder.java +492 -0
  70. package/android/src/main/java/com/azzapp/rnskv/VideoEncoder.java +639 -0
  71. package/android/src/main/java/com/azzapp/rnskv/VideoFrame.java +74 -0
  72. package/android/src/main/java/com/azzapp/rnskv/VideoPlayer.java +361 -0
  73. package/cpp/RNSVCheckedSizes.h +54 -0
  74. package/cpp/RNSVEventEmitter.cpp +199 -0
  75. package/cpp/RNSVEventEmitter.h +31 -0
  76. package/cpp/RNSVHostObject.cpp +79 -0
  77. package/cpp/RNSVHostObject.h +67 -0
  78. package/cpp/RNSVMemoryBudget.cpp +68 -0
  79. package/cpp/RNSVMemoryBudget.h +100 -0
  80. package/cpp/RNSVRuntimeLifecycleMonitor.cpp +88 -0
  81. package/cpp/RNSVRuntimeLifecycleMonitor.h +33 -0
  82. package/docs/ANDROID_DEVICE_306.md +95 -0
  83. package/docs/ANDROID_EXPORT_CACHE_306.md +48 -0
  84. package/docs/ANDROID_MEMORY_RETENTION_306.md +67 -0
  85. package/docs/BENCHMARKS.md +368 -0
  86. package/docs/IOS_DEVICE_TESTS.md +115 -0
  87. package/docs/IOS_SIMULATOR_TESTS.md +74 -0
  88. package/docs/MIGRATION.md +82 -0
  89. package/docs/NATIVE_MEMORY_INVESTIGATION_306.md +88 -0
  90. package/docs/PERFORMANCE_AB_IPHONE_303.md +196 -0
  91. package/docs/PERFORMANCE_AB_SIMULATOR.md +135 -0
  92. package/docs/PERFORMANCE_AB_SOAK_SIMULATOR.md +84 -0
  93. package/docs/PERFORMANCE_IPHONE_306_OPTIMIZATION.md +76 -0
  94. package/docs/PERFORMANCE_SIMULATOR.md +89 -0
  95. package/docs/PERFORMANCE_SIMULATOR_INITIAL.md +96 -0
  96. package/docs/PERFORMANCE_SOAK_IPHONE_303.md +41 -0
  97. package/docs/UPSTREAM_NOTES.md +188 -0
  98. package/docs/assets/banner.svg +26 -0
  99. package/examples/webgpu-overlay.ts +147 -0
  100. package/ios/AVAssetTrackUtils.h +24 -0
  101. package/ios/AudioCompositionUtils.h +27 -0
  102. package/ios/AudioCompositionUtils.mm +113 -0
  103. package/ios/DecoderWindow.h +52 -0
  104. package/ios/NativeResourceStats.h +32 -0
  105. package/ios/RNSVColorSpace.h +50 -0
  106. package/ios/RNSVJSIUtils.h +46 -0
  107. package/ios/RNSVScopedPixelBuffer.h +17 -0
  108. package/ios/RNSVVideoPlayer.h +46 -0
  109. package/ios/RNSVVideoPlayer.mm +410 -0
  110. package/ios/ReactNativeSkiaVideo.h +8 -0
  111. package/ios/ReactNativeSkiaVideo.mm +310 -0
  112. package/ios/SeekPolicy.h +27 -0
  113. package/ios/VideoComposition.h +148 -0
  114. package/ios/VideoCompositionFramesExtractorHostObject.h +105 -0
  115. package/ios/VideoCompositionFramesExtractorHostObject.mm +686 -0
  116. package/ios/VideoCompositionFramesExtractorSyncHostObject.h +37 -0
  117. package/ios/VideoCompositionFramesExtractorSyncHostObject.mm +168 -0
  118. package/ios/VideoCompositionItemDecoder.h +60 -0
  119. package/ios/VideoCompositionItemDecoder.mm +480 -0
  120. package/ios/VideoEncoderHostObject.h +83 -0
  121. package/ios/VideoEncoderHostObject.mm +706 -0
  122. package/ios/VideoFrame.h +66 -0
  123. package/ios/VideoFrame.mm +108 -0
  124. package/ios/VideoPlayerHostObject.h +52 -0
  125. package/ios/VideoPlayerHostObject.mm +332 -0
  126. package/lib/module/NativeReactNativeSkiaVideo.js +5 -0
  127. package/lib/module/NativeReactNativeSkiaVideo.js.map +1 -0
  128. package/lib/module/RNSkiaVideoModule.js +20 -0
  129. package/lib/module/RNSkiaVideoModule.js.map +1 -0
  130. package/lib/module/canvas.js +18 -0
  131. package/lib/module/canvas.js.map +1 -0
  132. package/lib/module/exportCache.js +22 -0
  133. package/lib/module/exportCache.js.map +1 -0
  134. package/lib/module/exportFrames.js +338 -0
  135. package/lib/module/exportFrames.js.map +1 -0
  136. package/lib/module/exportQueue.js +52 -0
  137. package/lib/module/exportQueue.js.map +1 -0
  138. package/lib/module/exportTarget.js +137 -0
  139. package/lib/module/exportTarget.js.map +1 -0
  140. package/lib/module/exportVideoComposition.js +492 -0
  141. package/lib/module/exportVideoComposition.js.map +1 -0
  142. package/lib/module/frameInterop.js +532 -0
  143. package/lib/module/frameInterop.js.map +1 -0
  144. package/lib/module/gpu.js +222 -0
  145. package/lib/module/gpu.js.map +1 -0
  146. package/lib/module/gpuDevice.js +54 -0
  147. package/lib/module/gpuDevice.js.map +1 -0
  148. package/lib/module/index.js +36 -0
  149. package/lib/module/index.js.map +1 -0
  150. package/lib/module/memory.js +38 -0
  151. package/lib/module/memory.js.map +1 -0
  152. package/lib/module/package.json +1 -0
  153. package/lib/module/previewLifecycle.js +52 -0
  154. package/lib/module/previewLifecycle.js.map +1 -0
  155. package/lib/module/runtimeYield.js +10 -0
  156. package/lib/module/runtimeYield.js.map +1 -0
  157. package/lib/module/types.js +4 -0
  158. package/lib/module/types.js.map +1 -0
  159. package/lib/module/utils/useEventListener.js +18 -0
  160. package/lib/module/utils/useEventListener.js.map +1 -0
  161. package/lib/module/videoCompositionPlayer.js +368 -0
  162. package/lib/module/videoCompositionPlayer.js.map +1 -0
  163. package/lib/module/videoFrameImage.js +185 -0
  164. package/lib/module/videoFrameImage.js.map +1 -0
  165. package/lib/module/videoPlayer.js +172 -0
  166. package/lib/module/videoPlayer.js.map +1 -0
  167. package/lib/module/yuvBlit.js +299 -0
  168. package/lib/module/yuvBlit.js.map +1 -0
  169. package/lib/typescript/package.json +1 -0
  170. package/lib/typescript/src/NativeReactNativeSkiaVideo.d.ts +7 -0
  171. package/lib/typescript/src/NativeReactNativeSkiaVideo.d.ts.map +1 -0
  172. package/lib/typescript/src/RNSkiaVideoModule.d.ts +4 -0
  173. package/lib/typescript/src/RNSkiaVideoModule.d.ts.map +1 -0
  174. package/lib/typescript/src/canvas.d.ts +4 -0
  175. package/lib/typescript/src/canvas.d.ts.map +1 -0
  176. package/lib/typescript/src/exportCache.d.ts +6 -0
  177. package/lib/typescript/src/exportCache.d.ts.map +1 -0
  178. package/lib/typescript/src/exportFrames.d.ts +57 -0
  179. package/lib/typescript/src/exportFrames.d.ts.map +1 -0
  180. package/lib/typescript/src/exportQueue.d.ts +5 -0
  181. package/lib/typescript/src/exportQueue.d.ts.map +1 -0
  182. package/lib/typescript/src/exportTarget.d.ts +28 -0
  183. package/lib/typescript/src/exportTarget.d.ts.map +1 -0
  184. package/lib/typescript/src/exportVideoComposition.d.ts +68 -0
  185. package/lib/typescript/src/exportVideoComposition.d.ts.map +1 -0
  186. package/lib/typescript/src/frameInterop.d.ts +17 -0
  187. package/lib/typescript/src/frameInterop.d.ts.map +1 -0
  188. package/lib/typescript/src/gpu.d.ts +39 -0
  189. package/lib/typescript/src/gpu.d.ts.map +1 -0
  190. package/lib/typescript/src/gpuDevice.d.ts +11 -0
  191. package/lib/typescript/src/gpuDevice.d.ts.map +1 -0
  192. package/lib/typescript/src/index.d.ts +21 -0
  193. package/lib/typescript/src/index.d.ts.map +1 -0
  194. package/lib/typescript/src/memory.d.ts +25 -0
  195. package/lib/typescript/src/memory.d.ts.map +1 -0
  196. package/lib/typescript/src/previewLifecycle.d.ts +22 -0
  197. package/lib/typescript/src/previewLifecycle.d.ts.map +1 -0
  198. package/lib/typescript/src/runtimeYield.d.ts +4 -0
  199. package/lib/typescript/src/runtimeYield.d.ts.map +1 -0
  200. package/lib/typescript/src/types.d.ts +631 -0
  201. package/lib/typescript/src/types.d.ts.map +1 -0
  202. package/lib/typescript/src/utils/useEventListener.d.ts +5 -0
  203. package/lib/typescript/src/utils/useEventListener.d.ts.map +1 -0
  204. package/lib/typescript/src/videoCompositionPlayer.d.ts +105 -0
  205. package/lib/typescript/src/videoCompositionPlayer.d.ts.map +1 -0
  206. package/lib/typescript/src/videoFrameImage.d.ts +60 -0
  207. package/lib/typescript/src/videoFrameImage.d.ts.map +1 -0
  208. package/lib/typescript/src/videoPlayer.d.ts +99 -0
  209. package/lib/typescript/src/videoPlayer.d.ts.map +1 -0
  210. package/lib/typescript/src/yuvBlit.d.ts +50 -0
  211. package/lib/typescript/src/yuvBlit.d.ts.map +1 -0
  212. package/package.json +155 -4
  213. package/patches/react-native-skia+3.7.0.patch +502 -0
  214. package/react-native-skia-webgpu-video.podspec +35 -0
  215. package/scripts/apply-skia-canvas-patch.mjs +48 -0
  216. package/scripts/skia-canvas-patch.json +291 -0
  217. package/src/NativeReactNativeSkiaVideo.ts +8 -0
  218. package/src/RNSkiaVideoModule.ts +27 -0
  219. package/src/canvas.ts +22 -0
  220. package/src/exportCache.ts +27 -0
  221. package/src/exportFrames.ts +421 -0
  222. package/src/exportQueue.ts +65 -0
  223. package/src/exportTarget.ts +179 -0
  224. package/src/exportVideoComposition.ts +718 -0
  225. package/src/frameInterop.ts +684 -0
  226. package/src/gpu.ts +290 -0
  227. package/src/gpuDevice.ts +80 -0
  228. package/src/index.tsx +45 -0
  229. package/src/memory.ts +48 -0
  230. package/src/previewLifecycle.ts +60 -0
  231. package/src/runtimeYield.ts +6 -0
  232. package/src/types.ts +661 -0
  233. package/src/utils/useEventListener.ts +22 -0
  234. package/src/videoCompositionPlayer.ts +568 -0
  235. package/src/videoFrameImage.ts +205 -0
  236. package/src/videoPlayer.ts +318 -0
  237. package/src/yuvBlit.ts +331 -0
@@ -0,0 +1,532 @@
1
+ "use strict";
2
+
3
+ import { getVideoCanvas } from "./canvas.js";
4
+ import { Platform } from "react-native";
5
+ import { AlphaType, BlendMode, ColorType, Skia } from "react-native-skia";
6
+ import { getVideoGpuDevice, createNativeVideoGpuFrame, nativeVideoTextureUsage, rgbaVideoTextureUsage } from "./gpuDevice.js";
7
+ import { frameByteSize, releaseVideoMemory, reserveVideoMemory } from "./memory.js";
8
+ import { blitYuvFrame, releaseYuvImports, yuvFrameOrigin } from "./yuvBlit.js";
9
+ // Capture a scalar on the RN runtime instead of importing Platform inside a
10
+ // worklet. iOS keeps its existing native-buffer and RGBA compatibility paths.
11
+ const uploadAndroidRgba = Platform.OS === "android";
12
+ const getCache = () => {
13
+ "worklet";
14
+
15
+ const runtime = globalThis;
16
+ if (!runtime.__rnskwgpuFrames) {
17
+ runtime.__rnskwgpuFrames = {
18
+ images: new Map(),
19
+ stage: null,
20
+ canvas: null,
21
+ width: 0,
22
+ height: 0,
23
+ format: null,
24
+ uploadTexture: null,
25
+ uploadReservation: 0,
26
+ cpuPixels: null,
27
+ cpuReservation: 0,
28
+ cpuBytesPerRow: 0,
29
+ pendingSources: [],
30
+ yuvImports: new Map()
31
+ };
32
+ }
33
+ return runtime.__rnskwgpuFrames;
34
+ };
35
+ const clearEntry = (cache, producer) => {
36
+ "worklet";
37
+
38
+ const entry = cache.images.get(producer);
39
+ if (entry) {
40
+ entry.image?.dispose();
41
+ entry.image = null;
42
+ releaseVideoMemory(entry.reservation);
43
+ cache.images.delete(producer);
44
+ }
45
+ };
46
+
47
+ /** Release only the current Skia view, never the shared texture it wraps.
48
+ * The caller has either not submitted a copy or has completed its GPU fence. */
49
+ const clearSurfaceView = cache => {
50
+ "worklet";
51
+
52
+ cache.canvas?.dispose();
53
+ cache.canvas = null;
54
+ cache.stage?.dispose();
55
+ cache.stage = null;
56
+ };
57
+ const clearCpuPixels = cache => {
58
+ "worklet";
59
+
60
+ cache.cpuPixels = null;
61
+ releaseVideoMemory(cache.cpuReservation);
62
+ cache.cpuReservation = 0;
63
+ cache.cpuBytesPerRow = 0;
64
+ };
65
+ const clearStagingSurface = cache => {
66
+ "worklet";
67
+
68
+ cache.stage?.flush(true);
69
+ clearSurfaceView(cache);
70
+ cache.uploadTexture?.destroy();
71
+ cache.uploadTexture = null;
72
+ releaseVideoMemory(cache.uploadReservation);
73
+ cache.uploadReservation = 0;
74
+ clearCpuPixels(cache);
75
+ cache.width = cache.height = 0;
76
+ cache.format = null;
77
+ };
78
+
79
+ /** Record explicit recovery work after a possibly submitted external copy.
80
+ * Clearing scratch cannot modify an already owned snapshot. The checked fence
81
+ * must succeed before either native lease or the texture can be released. */
82
+ const drainNativeCopies = cache => {
83
+ "worklet";
84
+
85
+ if (!cache.stage || !cache.canvas) throw new Error("Video import drain surface is unavailable");
86
+ cache.canvas.drawColor(Skia.Color("#00000000"), BlendMode.Clear);
87
+ cache.stage.flush(true);
88
+ };
89
+
90
+ /** Clear a runtime's imported images after ending all its producers.
91
+ * Do not clear a paused producer's current frame: its native source has
92
+ * already been released, and the owned snapshot is its remaining pixels. */
93
+ export const clearVideoFrameImages = (releaseStagingSurface = false) => {
94
+ "worklet";
95
+
96
+ const cache = getCache();
97
+ if (cache.pendingSources.length) {
98
+ // A failed drain retains leases; only a successful fence can release them.
99
+ if (cache.pendingSources.some(source => source.needsDrain)) {
100
+ drainNativeCopies(cache);
101
+ for (const source of cache.pendingSources) source.needsDrain = false;
102
+ }
103
+ while (cache.pendingSources.length) {
104
+ const source = cache.pendingSources[0];
105
+ source.owned?.dispose();
106
+ source.owned = null;
107
+ source.nativeSource?.release();
108
+ source.nativeSource = null;
109
+ if (!source.sourceReleased) {
110
+ source.frame.dispose?.();
111
+ source.sourceReleased = true;
112
+ }
113
+ releaseVideoMemory(source.reservation);
114
+ cache.pendingSources.shift();
115
+ }
116
+ }
117
+ clearSurfaceView(cache);
118
+ for (const producer of cache.images.keys()) clearEntry(cache, producer);
119
+ if (releaseStagingSurface) {
120
+ clearStagingSurface(cache);
121
+ // Every import's last frame completed: the queue drained above.
122
+ releaseYuvImports(cache.yuvImports);
123
+ }
124
+ };
125
+
126
+ /** Release an item which has left a composition or a producer being closed. */
127
+ export const releaseVideoFrameImage = frame => {
128
+ "worklet";
129
+
130
+ // Synthetic processor images without decoder identities belong to their
131
+ // GPU scope. They must not evict the fallback native producer cache.
132
+ if (frame.producerId === undefined && frame.id === undefined && frame.texture?.kind === "skia-image") return;
133
+ const producer = frame.producerId ?? frame.id ?? -1;
134
+ const cache = getCache();
135
+ const entry = cache.images.get(producer);
136
+ if (entry && entry.id === (frame.id ?? -1)) clearEntry(cache, producer);
137
+ // Each import ends with a checked flush; after a failed one, only the
138
+ // drain in clearVideoFrameImages may release the decoder buffers.
139
+ if (!cache.pendingSources.length) releaseYuvImports(cache.yuvImports, producer);
140
+ if (cache.images.size === 0) clearVideoFrameImages(true);
141
+ };
142
+
143
+ /** Returns immutable, owned pixels. WebGPU uploads Android RGBA pixels or blits
144
+ * native buffers into one reusable texture, then snapshots a fresh Skia view.
145
+ * Graphite-backed snapshots bypass the raster ImageProvider's image-count LRU.
146
+ * Wait for completion before releasing sources or rewriting the scratch texture. */
147
+ export const imageFromVideoFrame = frame => {
148
+ "worklet";
149
+
150
+ const cache = getCache();
151
+ const producer = frame.producerId ?? frame.id;
152
+ if (producer !== undefined && frame.id !== undefined) {
153
+ const existing = cache.images.get(producer);
154
+ if (existing?.id === frame.id && existing.image) {
155
+ // Android can issue a fresh lease for the same paused picture. The
156
+ // snapshot already owns its pixels, so close that unused native lease.
157
+ // Weak tracking avoids retaining raw buffers or closing one wrapper twice.
158
+ if (!existing.releasedSources.has(frame)) {
159
+ frame.dispose?.();
160
+ existing.releasedSources.add(frame);
161
+ }
162
+ return existing.image;
163
+ }
164
+ }
165
+ let reservation = 0;
166
+ let image = null;
167
+ let copyPending = false;
168
+ let ownsSurfaceView = false;
169
+ let nativeSource = null;
170
+ let sourceDrained = false;
171
+ let releaseSource = true;
172
+ let importFailed = false;
173
+ try {
174
+ if (cache.pendingSources.length) {
175
+ // A caller may retry the same native frame (or an alias of its stable
176
+ // identity). Its existing pending entry still owns both leases; do not
177
+ // let this rejected re-entry revoke the original decoder reservation.
178
+ if (cache.pendingSources.some(source => source.frame === frame || frame.id !== undefined && source.frame.id === frame.id && source.frame.producerId === frame.producerId)) releaseSource = false;
179
+ throw new Error("Previous video import could not drain its GPU work; restart the native runtime");
180
+ }
181
+ const texture = frame.texture;
182
+ if (!texture) return null;
183
+ if (texture.kind === "skia-image") return texture.image;
184
+ if (texture.kind !== "rgba" && texture.kind !== "native-buffer") {
185
+ throw new Error("Unsupported frame transport; use the Skia 3 video backend");
186
+ }
187
+ const bytes = frameByteSize(frame.width, frame.height);
188
+ // Keep the published image valid until its replacement has succeeded.
189
+ // Account for the replacement's peak memory rather than evict paused pixels.
190
+ const key = producer ?? -1;
191
+ if (!cache.images.has(key) && cache.images.size >= 32) {
192
+ throw new Error("Too many cached video producers; close unused extractors");
193
+ }
194
+ let rgbaPixels = null;
195
+ let requiredRgbaBytes = 0;
196
+ let copyRgbaPixels = false;
197
+ if (texture.kind === "rgba") {
198
+ const required = texture.bytesPerRow * frame.height;
199
+ if (!Number.isSafeInteger(texture.bytesPerRow) || !Number.isSafeInteger(required) || texture.bytesPerRow < frame.width * 4 || uploadAndroidRgba && (texture.bytesPerRow > 0xffffffff || texture.bytesPerRow % 4 !== 0)) {
200
+ throw new Error("Invalid RGBA video frame storage");
201
+ }
202
+ requiredRgbaBytes = required;
203
+ // Native Android data is lazy. Inspect the optional copy protocol before
204
+ // reading that getter, which would otherwise retain a Java backing per
205
+ // external ArrayBuffer until Hermes and ART have both collected it.
206
+ copyRgbaPixels = uploadAndroidRgba && typeof texture.copyPixelsTo === "function";
207
+ if (!copyRgbaPixels) {
208
+ const pixels = new Uint8Array(texture.data);
209
+ if (pixels.byteLength < required) throw new Error("Invalid RGBA video frame storage");
210
+ if (uploadAndroidRgba) {
211
+ // Exclude unused trailing storage without another pixel copy.
212
+ rgbaPixels = new Uint8Array(texture.data, 0, required);
213
+ } else {
214
+ // Preserve the iOS compatibility raster path.
215
+ reservation = reserveVideoMemory(pixels.byteLength, "owned video image");
216
+ const data = Skia.Data.fromBytes(pixels);
217
+ try {
218
+ image = Skia.Image.MakeRasterImage({
219
+ width: frame.width,
220
+ height: frame.height,
221
+ colorType: ColorType.RGBA_8888,
222
+ alphaType: AlphaType.Opaque
223
+ }, data, texture.bytesPerRow);
224
+ } finally {
225
+ data.dispose();
226
+ }
227
+ }
228
+ }
229
+ }
230
+ if (texture.kind === "native-buffer" || rgbaPixels || copyRgbaPixels) {
231
+ const device = getVideoGpuDevice();
232
+ const uploadRgba = texture.kind === "rgba";
233
+ if (uploadRgba || uploadAndroidRgba) {
234
+ const extentLimit = device.limits.maxTextureDimension2D;
235
+ if (!Number.isSafeInteger(extentLimit) || extentLimit <= 0 || frame.width > extentLimit || frame.height > extentLimit) throw new Error("Video frame exceeds the WebGPU texture extent limit");
236
+ }
237
+ const format = uploadRgba || uploadAndroidRgba ? "rgba8unorm" : "bgra8unorm";
238
+ reservation = reserveVideoMemory(bytes, "owned video image");
239
+ if (!cache.uploadTexture || cache.width !== frame.width || cache.height !== frame.height || cache.format !== format) {
240
+ clearStagingSurface(cache);
241
+ cache.uploadReservation = reserveVideoMemory(bytes, uploadRgba ? "RGBA frame WebGPU upload texture" : "native frame WebGPU upload texture");
242
+ try {
243
+ // One scratch texture per runtime. COPY_SRC lets Graphite snapshot
244
+ // it with a GPU blit rather than draw into another staging target.
245
+ cache.uploadTexture = device.createTexture({
246
+ size: {
247
+ width: frame.width,
248
+ height: frame.height
249
+ },
250
+ format,
251
+ // Android AHB and CPU frames share the RGBA scratch. Include
252
+ // COPY_DST even for a first AHB frame, so a later CPU fallback
253
+ // cannot reuse a texture that forbids writeTexture.
254
+ usage: uploadRgba || uploadAndroidRgba ? rgbaVideoTextureUsage : nativeVideoTextureUsage,
255
+ label: uploadRgba ? "video RGBA frame upload" : "video native frame upload"
256
+ });
257
+ cache.width = frame.width;
258
+ cache.height = frame.height;
259
+ cache.format = format;
260
+ } catch (error) {
261
+ try {
262
+ clearStagingSurface(cache);
263
+ } catch {
264
+ /* unfinished cleanup/accounting stays reachable */
265
+ }
266
+ throw error;
267
+ }
268
+ }
269
+ if (copyRgbaPixels && texture.kind === "rgba") {
270
+ if (!cache.cpuPixels || cache.cpuPixels.byteLength !== requiredRgbaBytes || cache.cpuBytesPerRow !== texture.bytesPerRow) {
271
+ clearCpuPixels(cache);
272
+ cache.cpuReservation = reserveVideoMemory(requiredRgbaBytes, "RGBA frame CPU upload buffer");
273
+ try {
274
+ cache.cpuPixels = new Uint8Array(new ArrayBuffer(requiredRgbaBytes));
275
+ cache.cpuBytesPerRow = texture.bytesPerRow;
276
+ } catch (error) {
277
+ try {
278
+ clearCpuPixels(cache);
279
+ } catch {
280
+ /* unfinished accounting stays reachable */
281
+ }
282
+ throw error;
283
+ }
284
+ }
285
+ // The host function finishes memcpy synchronously. The private buffer
286
+ // is never exposed as texture.data and is rewritten only after the
287
+ // preceding import's checked fence. Saved raw aliases remain separate.
288
+ texture.copyPixelsTo(cache.cpuPixels.buffer);
289
+ rgbaPixels = cache.cpuPixels;
290
+ } else {
291
+ // Native AHB frames and raw compatibility frames need no private CPU
292
+ // scratch. This also closes CPU scratch on same-format RGBA -> AHB.
293
+ clearCpuPixels(cache);
294
+ }
295
+ clearSurfaceView(cache);
296
+ // WebGPU writes do not invalidate SkSurface's cached snapshot. A fresh
297
+ // surface wrapper for every frame prevents stale pixels without another
298
+ // GPU allocation or a write through Skia that would overwrite the input.
299
+ cache.stage = Skia.Surface.MakeFromGPUTexture(cache.uploadTexture);
300
+ if (!cache.stage) throw new Error("Cannot wrap video upload texture");
301
+ ownsSurfaceView = true;
302
+ cache.canvas = getVideoCanvas(cache.stage);
303
+ if (rgbaPixels && texture.kind === "rgba") {
304
+ // Dawn consumes this typed-array view synchronously. Keep the source
305
+ // alive through the checked fence, including a throw after enqueue.
306
+ copyPending = true;
307
+ device.queue.writeTexture({
308
+ texture: cache.uploadTexture
309
+ }, rgbaPixels, {
310
+ offset: 0,
311
+ bytesPerRow: texture.bytesPerRow,
312
+ rowsPerImage: frame.height
313
+ }, {
314
+ width: frame.width,
315
+ height: frame.height,
316
+ depthOrArrayLayers: 1
317
+ });
318
+ } else if (texture.kind === "native-buffer") {
319
+ nativeSource = createNativeVideoGpuFrame(texture.nativeBuffer);
320
+ const region = texture.region;
321
+ const rotation = texture.rotation ?? 0;
322
+ let origin = {
323
+ x: 0,
324
+ y: 0
325
+ };
326
+ if (region) {
327
+ // An Android codec buffer: padded, YUV, in encoded orientation. The
328
+ // blit converts, crops and turns it into the display-sized scratch,
329
+ // as the GL path's SurfaceTexture transform did. RN WebGPU labels
330
+ // driver-defined YUV formats "bgra8", yet Dawn imports them as YUV:
331
+ // the native side checked the format, so the label is not read.
332
+ origin = yuvFrameOrigin(region, rotation, nativeSource, frame);
333
+ } else if (
334
+ // RN WebGPU labels a single-plane Android RGBA AHB "bgra8". Dawn
335
+ // reads the actual AHB format; the string distinguishes RGB from
336
+ // NV12 and must not be read as Android's physical byte order.
337
+ nativeSource.width !== frame.width || nativeSource.height !== frame.height || nativeSource.pixelFormat !== "bgra8") {
338
+ throw new Error("Native video buffer dimensions or BGRA layout mismatch");
339
+ }
340
+ // The native call can throw after submitting; retain leases until a
341
+ // checked queue drain even when it does not return normally.
342
+ copyPending = true;
343
+ if (region) {
344
+ // copyExternalImageToTexture would also convert the video's
345
+ // transfer function and primaries to sRGB (see yuvBlit.ts).
346
+ blitYuvFrame(device, cache.yuvImports, key, nativeSource, rotation, origin, frame.width, frame.height, cache.uploadTexture);
347
+ } else {
348
+ // Keep decoded orientation: drawVideoFrame applies rotation once.
349
+ device.queue.copyExternalImageToTexture({
350
+ source: nativeSource,
351
+ rotation: 0,
352
+ mirrored: false,
353
+ flipY: false
354
+ }, {
355
+ texture: cache.uploadTexture,
356
+ premultipliedAlpha: false
357
+ }, {
358
+ width: frame.width,
359
+ height: frame.height
360
+ });
361
+ }
362
+ }
363
+ // Snapshot records an independent texture copy and submits it after
364
+ // the external blit on the shared queue. The wrapper never draws.
365
+ image = cache.stage.makeImageSnapshot();
366
+ cache.stage.flush(true);
367
+ sourceDrained = true;
368
+ }
369
+ if (!image) throw new Error("Cannot create a video frame image");
370
+ // Complete the native handoff before replacing published pixels. A failed
371
+ // source close must not evict a paused image or leave an unpublished cache
372
+ // entry behind when the caller receives an import error.
373
+ if (ownsSurfaceView) {
374
+ clearSurfaceView(cache);
375
+ ownsSurfaceView = false;
376
+ }
377
+ nativeSource?.release();
378
+ nativeSource = null;
379
+ frame.dispose?.();
380
+ releaseSource = false;
381
+ clearEntry(cache, key);
382
+ cache.images.set(key, {
383
+ id: frame.id ?? -1,
384
+ image,
385
+ reservation,
386
+ releasedSources: new WeakSet([frame])
387
+ });
388
+ return image;
389
+ } catch (error) {
390
+ importFailed = true;
391
+ if (copyPending && !sourceDrained) {
392
+ try {
393
+ drainNativeCopies(cache);
394
+ } catch {
395
+ cache.pendingSources.push({
396
+ nativeSource,
397
+ owned: image,
398
+ reservation,
399
+ frame,
400
+ needsDrain: true,
401
+ sourceReleased: false
402
+ });
403
+ nativeSource = null;
404
+ image = null;
405
+ reservation = 0;
406
+ releaseSource = false;
407
+ }
408
+ }
409
+ try {
410
+ // Failed drains retain the view along with its texture and source.
411
+ if (releaseSource && ownsSurfaceView) {
412
+ clearSurfaceView(cache);
413
+ ownsSurfaceView = false;
414
+ }
415
+ image?.dispose();
416
+ image = null;
417
+ releaseVideoMemory(reservation);
418
+ } catch {
419
+ cache.pendingSources.push({
420
+ nativeSource,
421
+ owned: image,
422
+ reservation,
423
+ frame,
424
+ needsDrain: false,
425
+ sourceReleased: false
426
+ });
427
+ nativeSource = null;
428
+ releaseSource = false;
429
+ }
430
+ throw error;
431
+ } finally {
432
+ if (releaseSource) {
433
+ try {
434
+ nativeSource?.release();
435
+ nativeSource = null;
436
+ frame.dispose?.();
437
+ } catch (error) {
438
+ cache.pendingSources.push({
439
+ nativeSource,
440
+ owned: null,
441
+ reservation: 0,
442
+ frame,
443
+ needsDrain: false,
444
+ sourceReleased: false
445
+ });
446
+ if (!importFailed) throw error;
447
+ }
448
+ }
449
+ }
450
+ };
451
+
452
+ /** Stage all issued frames, including items a callback currently hides.
453
+ * This releases decoder leases promptly instead of waiting for JS GC. */
454
+ export const ownVideoFrames = frames => {
455
+ "worklet";
456
+
457
+ const owned = {};
458
+ const visited = new Set();
459
+ const failed = {
460
+ value: false,
461
+ error: undefined
462
+ };
463
+ try {
464
+ // Two different pictures from one producer would invalidate the first
465
+ // owned image while importing the second. Reject before allocating, and
466
+ // permit aliases of the same stable native frame.
467
+ const producers = new Map();
468
+ for (const frame of Object.values(frames)) {
469
+ if (frame.texture?.kind === "skia-image") continue;
470
+ const producer = frame.producerId ?? frame.id ?? -1;
471
+ const previous = producers.get(producer);
472
+ if (previous && previous !== frame && (frame.id === undefined || previous.id === undefined || previous.id !== frame.id)) {
473
+ throw new Error("Composition yielded different frames for one producer; stable native frame identities are required");
474
+ }
475
+ producers.set(producer, frame);
476
+ }
477
+ for (const [key, frame] of Object.entries(frames)) {
478
+ visited.add(frame);
479
+ const image = imageFromVideoFrame(frame);
480
+ if (image) owned[key] = {
481
+ width: frame.width,
482
+ height: frame.height,
483
+ rotation: frame.rotation,
484
+ crop: frame.crop,
485
+ // Synthetic processor images belong to their GPU scope. Raw anonymous
486
+ // input uses the fallback cache, which still needs a releasable key.
487
+ id: frame.id ?? (frame.texture?.kind === "skia-image" ? undefined : -1),
488
+ producerId: frame.producerId ?? frame.id ?? (frame.texture?.kind === "skia-image" ? undefined : -1),
489
+ texture: {
490
+ kind: "skia-image",
491
+ image
492
+ }
493
+ };
494
+ }
495
+ return owned;
496
+ } catch (error) {
497
+ failed.value = true;
498
+ failed.error = error;
499
+ for (const frame of Object.values(owned)) {
500
+ try {
501
+ releaseVideoFrameImage(frame);
502
+ } catch {
503
+ /* retained/accounted by cache */
504
+ }
505
+ }
506
+ throw error;
507
+ } finally {
508
+ // Idempotent native dispose covers untouched frames after an import fails.
509
+ const pending = getCache().pendingSources;
510
+ for (const frame of Object.values(frames)) {
511
+ if (visited.has(frame)) continue;
512
+ // Do not undo the failed-drain retention established by the importer.
513
+ try {
514
+ if (!pending.some(source => source.frame === frame || frame.id !== undefined && source.frame.id === frame.id && source.frame.producerId === frame.producerId)) frame.dispose?.();
515
+ } catch (error) {
516
+ // Keep an unsuccessful native close reachable for retry, but continue
517
+ // releasing every independent untouched item and preserve import error.
518
+ pending.push({
519
+ owned: null,
520
+ reservation: 0,
521
+ frame,
522
+ needsDrain: false,
523
+ sourceReleased: false
524
+ });
525
+ if (!failed.value) failed.error = error;
526
+ failed.value = true;
527
+ }
528
+ }
529
+ if (failed.value) throw failed.error;
530
+ }
531
+ };
532
+ //# sourceMappingURL=frameInterop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getVideoCanvas","Platform","AlphaType","BlendMode","ColorType","Skia","getVideoGpuDevice","createNativeVideoGpuFrame","nativeVideoTextureUsage","rgbaVideoTextureUsage","frameByteSize","releaseVideoMemory","reserveVideoMemory","blitYuvFrame","releaseYuvImports","yuvFrameOrigin","uploadAndroidRgba","OS","getCache","runtime","globalThis","__rnskwgpuFrames","images","Map","stage","canvas","width","height","format","uploadTexture","uploadReservation","cpuPixels","cpuReservation","cpuBytesPerRow","pendingSources","yuvImports","clearEntry","cache","producer","entry","get","image","dispose","reservation","delete","clearSurfaceView","clearCpuPixels","clearStagingSurface","flush","destroy","drainNativeCopies","Error","drawColor","Color","Clear","clearVideoFrameImages","releaseStagingSurface","length","some","source","needsDrain","owned","nativeSource","release","sourceReleased","frame","shift","keys","releaseVideoFrameImage","producerId","undefined","id","texture","kind","size","imageFromVideoFrame","existing","releasedSources","has","add","copyPending","ownsSurfaceView","sourceDrained","releaseSource","importFailed","bytes","key","rgbaPixels","requiredRgbaBytes","copyRgbaPixels","required","bytesPerRow","Number","isSafeInteger","copyPixelsTo","pixels","Uint8Array","data","byteLength","Data","fromBytes","Image","MakeRasterImage","colorType","RGBA_8888","alphaType","Opaque","device","uploadRgba","extentLimit","limits","maxTextureDimension2D","createTexture","usage","label","error","ArrayBuffer","buffer","Surface","MakeFromGPUTexture","queue","writeTexture","offset","rowsPerImage","depthOrArrayLayers","nativeBuffer","region","rotation","origin","x","y","pixelFormat","copyExternalImageToTexture","mirrored","flipY","premultipliedAlpha","makeImageSnapshot","set","WeakSet","push","ownVideoFrames","frames","visited","Set","failed","value","producers","Object","values","previous","entries","crop","pending"],"sourceRoot":"../../src","sources":["frameInterop.ts"],"mappings":";;AAAA,SAASA,cAAc,QAAQ,aAAU;AACzC,SAASC,QAAQ,QAAQ,cAAc;AACvC,SAASC,SAAS,EAAEC,SAAS,EAAEC,SAAS,EAAEC,IAAI,QAAQ,mBAAmB;AAIzE,SACEC,iBAAiB,EACjBC,yBAAyB,EACzBC,uBAAuB,EACvBC,qBAAqB,QAChB,gBAAa;AACpB,SACEC,aAAa,EACbC,kBAAkB,EAClBC,kBAAkB,QACb,aAAU;AACjB,SAASC,YAAY,EAAEC,iBAAiB,EAAEC,cAAc,QAAQ,cAAW;AAkD3E;AACA;AACA,MAAMC,iBAAiB,GAAGf,QAAQ,CAACgB,EAAE,KAAK,SAAS;AAEnD,MAAMC,QAAQ,GAAGA,CAAA,KAAa;EAC5B,SAAS;;EACT,MAAMC,OAAO,GAAGC,UAEf;EACD,IAAI,CAACD,OAAO,CAACE,gBAAgB,EAAE;IAC7BF,OAAO,CAACE,gBAAgB,GAAG;MACzBC,MAAM,EAAE,IAAIC,GAAG,CAAC,CAAC;MACjBC,KAAK,EAAE,IAAI;MACXC,MAAM,EAAE,IAAI;MACZC,KAAK,EAAE,CAAC;MACRC,MAAM,EAAE,CAAC;MACTC,MAAM,EAAE,IAAI;MACZC,aAAa,EAAE,IAAI;MACnBC,iBAAiB,EAAE,CAAC;MACpBC,SAAS,EAAE,I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