react-native-skia-webgpu-video 0.1.0-beta.2 → 0.1.0-beta.4

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 (86) hide show
  1. package/LICENSE +0 -1
  2. package/README.md +62 -34
  3. package/android/BUILD_VALIDATION.md +1 -1
  4. package/android/CMakeLists.txt +3 -2
  5. package/android/cpp/ExportHintSession.cpp +114 -0
  6. package/android/cpp/ExportHintSession.h +35 -0
  7. package/android/cpp/VideoComposition.cpp +12 -0
  8. package/android/cpp/VideoCompositionFramesExtractor.cpp +6 -0
  9. package/android/cpp/VideoCompositionFramesExtractor.h +1 -0
  10. package/android/cpp/VideoCompositionFramesExtractorHostObject.cpp +1 -1
  11. package/android/cpp/VideoEncoderHostObject.cpp +76 -101
  12. package/android/cpp/VideoEncoderHostObject.h +14 -9
  13. package/android/cpp/VideoFrame.cpp +3 -5
  14. package/android/cpp/cpp-adapter.cpp +7 -4
  15. package/android/src/main/java/com/azzapp/rnskv/GLFrameExtractor.java +3 -9
  16. package/android/src/main/java/com/azzapp/rnskv/PreviewFrameRateVote.java +104 -0
  17. package/android/src/main/java/com/azzapp/rnskv/VideoComposition.java +4 -0
  18. package/android/src/main/java/com/azzapp/rnskv/VideoCompositionDecoder.java +8 -9
  19. package/android/src/main/java/com/azzapp/rnskv/VideoCompositionFramesExtractor.java +32 -0
  20. package/android/src/main/java/com/azzapp/rnskv/VideoEncoder.java +68 -28
  21. package/docs/FRAME_PIXEL_FORMAT.md +124 -0
  22. package/docs/MIGRATION.md +1 -1
  23. package/docs/UPSTREAM_NOTES.md +15 -2
  24. package/docs/VERIFICATION_0.1.0-beta.3.md +147 -0
  25. package/ios/NativeResourceStats.h +9 -0
  26. package/ios/RNSVColorSpace.h +35 -4
  27. package/ios/ReactNativeSkiaVideo.mm +4 -0
  28. package/ios/VideoComposition.h +20 -0
  29. package/ios/VideoCompositionFramesExtractorHostObject.h +5 -0
  30. package/ios/VideoCompositionFramesExtractorHostObject.mm +31 -2
  31. package/ios/VideoCompositionItemDecoder.mm +21 -8
  32. package/ios/VideoFrame.mm +6 -0
  33. package/lib/module/canvas.js +3 -5
  34. package/lib/module/canvas.js.map +1 -1
  35. package/lib/module/exportFrames.js +25 -20
  36. package/lib/module/exportFrames.js.map +1 -1
  37. package/lib/module/exportTarget.js +183 -40
  38. package/lib/module/exportTarget.js.map +1 -1
  39. package/lib/module/exportVideoComposition.js +53 -12
  40. package/lib/module/exportVideoComposition.js.map +1 -1
  41. package/lib/module/frameInterop.js +15 -12
  42. package/lib/module/frameInterop.js.map +1 -1
  43. package/lib/module/gpu.js +0 -2
  44. package/lib/module/gpu.js.map +1 -1
  45. package/lib/module/gpuDevice.js +12 -0
  46. package/lib/module/gpuDevice.js.map +1 -1
  47. package/lib/module/previewLifecycle.js +0 -1
  48. package/lib/module/previewLifecycle.js.map +1 -1
  49. package/lib/module/videoCompositionPlayer.js +13 -5
  50. package/lib/module/videoCompositionPlayer.js.map +1 -1
  51. package/lib/module/yuvBlit.js +98 -21
  52. package/lib/module/yuvBlit.js.map +1 -1
  53. package/lib/typescript/src/canvas.d.ts.map +1 -1
  54. package/lib/typescript/src/exportFrames.d.ts +11 -10
  55. package/lib/typescript/src/exportFrames.d.ts.map +1 -1
  56. package/lib/typescript/src/exportTarget.d.ts +53 -14
  57. package/lib/typescript/src/exportTarget.d.ts.map +1 -1
  58. package/lib/typescript/src/exportVideoComposition.d.ts +2 -1
  59. package/lib/typescript/src/exportVideoComposition.d.ts.map +1 -1
  60. package/lib/typescript/src/frameInterop.d.ts.map +1 -1
  61. package/lib/typescript/src/gpu.d.ts.map +1 -1
  62. package/lib/typescript/src/gpuDevice.d.ts +5 -1
  63. package/lib/typescript/src/gpuDevice.d.ts.map +1 -1
  64. package/lib/typescript/src/previewLifecycle.d.ts.map +1 -1
  65. package/lib/typescript/src/types.d.ts +36 -5
  66. package/lib/typescript/src/types.d.ts.map +1 -1
  67. package/lib/typescript/src/videoCompositionPlayer.d.ts.map +1 -1
  68. package/lib/typescript/src/yuvBlit.d.ts +26 -14
  69. package/lib/typescript/src/yuvBlit.d.ts.map +1 -1
  70. package/package.json +6 -6
  71. package/patches/react-native-skia+3.7.4.patch +146 -0
  72. package/scripts/skia-canvas-patch.json +22 -258
  73. package/src/canvas.ts +3 -7
  74. package/src/exportFrames.ts +53 -36
  75. package/src/exportTarget.ts +217 -56
  76. package/src/exportVideoComposition.ts +87 -26
  77. package/src/frameInterop.ts +26 -11
  78. package/src/gpu.ts +0 -2
  79. package/src/gpuDevice.ts +26 -1
  80. package/src/previewLifecycle.ts +0 -1
  81. package/src/types.ts +37 -5
  82. package/src/videoCompositionPlayer.ts +14 -4
  83. package/src/yuvBlit.ts +108 -27
  84. package/android/cpp/EncoderTargets.cpp +0 -226
  85. package/android/cpp/EncoderTargets.h +0 -70
  86. package/patches/react-native-skia+3.7.1.patch +0 -502
@@ -1,6 +1,7 @@
1
1
  #include "VideoCompositionFramesExtractorHostObject.h"
2
2
 
3
3
  #import "AVAssetTrackUtils.h"
4
+ #import "NativeResourceStats.h"
4
5
  #import "AudioCompositionUtils.h"
5
6
  #import "RNSVJSIUtils.h"
6
7
  #include "RNSVCheckedSizes.h"
@@ -117,6 +118,8 @@ jsi::Value VideoCompositionFramesExtractorHostObject::get(
117
118
  }
118
119
  if (initialized && lastAppliedSeekGeneration == seekGeneration) {
119
120
  auto currentTime = getCurrentTime();
121
+ framesTime = currentTime;
122
+ framesTimeHost = CACurrentMediaTime();
120
123
  bool changed = false;
121
124
  for (const auto& entry : itemDecoders) {
122
125
  auto itemId = entry.first;
@@ -189,7 +192,7 @@ jsi::Value VideoCompositionFramesExtractorHostObject::get(
189
192
  return jsi::Value::undefined();
190
193
  });
191
194
  } else if (propName == "currentTime") {
192
- return jsi::Value(released.test() ? 0 : CMTimeGetSeconds(getCurrentTime()));
195
+ return jsi::Value(released.test() ? 0 : CMTimeGetSeconds(getPresentedTime()));
193
196
  } else if (propName == "framesVersion") {
194
197
  return jsi::Value(released.test() ? 0 : (double)framesVersion);
195
198
  } else if (propName == "isLooping") {
@@ -218,8 +221,12 @@ void VideoCompositionFramesExtractorHostObject::set(
218
221
  void VideoCompositionFramesExtractorHostObject::prepare() {
219
222
  @synchronized(lock) {
220
223
  if (released.test() || decoderQueue) return;
224
+ // User-interactive: the queue feeds the display at every vsync. At utility,
225
+ // a warm iPhone parked it on the efficiency cores: 60 fps clips froze for
226
+ // 300-500 ms at a time while the decoder caught up, and a 4K 60 fps preview
227
+ // showed one frame in six.
221
228
  dispatch_queue_attr_t attr = dispatch_queue_attr_make_with_qos_class(
222
- DISPATCH_QUEUE_SERIAL, QOS_CLASS_UTILITY, 0);
229
+ DISPATCH_QUEUE_SERIAL, QOS_CLASS_USER_INTERACTIVE, 0);
223
230
  decoderQueue = dispatch_queue_create("ReactNativeVideoCompositionItemDecoder", attr);
224
231
  dispatch_queue_set_specific(decoderQueue, this, this, NULL);
225
232
  std::weak_ptr<VideoCompositionFramesExtractorHostObject> weak =
@@ -252,7 +259,10 @@ void VideoCompositionFramesExtractorHostObject::scheduleDecode() {
252
259
  std::atomic<bool>& flag;
253
260
  ~PendingGuard() { flag.store(false); }
254
261
  } pendingGuard{owner->decoderTickPending};
262
+ CFTimeInterval tickStart = CACurrentMediaTime();
255
263
  owner->decodeTick();
264
+ PreviewStats::decodeTicks++;
265
+ if (CACurrentMediaTime() - tickStart > 0.016) PreviewStats::slowDecodeTicks++;
256
266
  }
257
267
  // A seek arriving during decoding was coalesced into this task. Queue
258
268
  // its latest position after releasing the pending flag, so it cannot
@@ -453,6 +463,7 @@ void VideoCompositionFramesExtractorHostObject::init() {
453
463
  void VideoCompositionFramesExtractorHostObject::play() {
454
464
  @synchronized(lock) {
455
465
  if (released.test() || isPlaying) return;
466
+ framesTime = kCMTimeInvalid;
456
467
  // A completed paused clock stays at the end until play explicitly restarts
457
468
  // it. Rewind the readers through the same serial seek generation as seekTo.
458
469
  if (CMTimeGetSeconds(pausePosition) >= composition->duration) {
@@ -480,6 +491,7 @@ void VideoCompositionFramesExtractorHostObject::pause() {
480
491
  }
481
492
  pausePosition = getCurrentTime();
482
493
  isPlaying = false;
494
+ framesTime = kCMTimeInvalid;
483
495
  if (audioPlayer) {
484
496
  [audioPlayer pause];
485
497
  }
@@ -490,6 +502,7 @@ void VideoCompositionFramesExtractorHostObject::seekTo(CMTime time) {
490
502
  @synchronized(lock) {
491
503
  if (released.test()) return;
492
504
  seekPending = true;
505
+ framesTime = kCMTimeInvalid;
493
506
  if (isPlaying) {
494
507
  startDate = [NSDate dateWithTimeIntervalSinceNow:-CMTimeGetSeconds(time)];
495
508
  } else {
@@ -594,6 +607,22 @@ void VideoCompositionFramesExtractorHostObject::openDecoders(
594
607
  }
595
608
  }
596
609
 
610
+ // The time drawFrame draws at: the clock the frames it gets were picked at,
611
+ // rather than the clock when it reads the time, after the frames' import (a
612
+ // few milliseconds of GPU work). Read later, the time ran ahead of the frames,
613
+ // and at 60 fps a frame's start could fall in between on every frame: the
614
+ // time said frame n while the frames held n - 1. The live clock once play,
615
+ // pause or a seek has moved it, or without a recent pick (no preview).
616
+ CMTime VideoCompositionFramesExtractorHostObject::getPresentedTime() {
617
+ @synchronized(lock) {
618
+ if (isPlaying && CMTIME_IS_VALID(framesTime) &&
619
+ CACurrentMediaTime() - framesTimeHost < 0.1) {
620
+ return framesTime;
621
+ }
622
+ return getCurrentTime();
623
+ }
624
+ }
625
+
597
626
  CMTime VideoCompositionFramesExtractorHostObject::getCurrentTime() {
598
627
  @synchronized(lock) {
599
628
  if (isPlaying) {
@@ -123,13 +123,24 @@ void VideoCompositionItemDecoder::setupReader(CMTime initialTime) {
123
123
  // AVAssetReaderTrackOutput takes pixel buffer attributes and video settings
124
124
  // in the same dictionary, so the color properties travel with them: an HDR
125
125
  // track is tone-mapped to Rec.709 by AVFoundation before we ever see it
126
- // (see RNSVColorSpace.h).
127
- NSDictionary* pixBuffAttributes = @{
128
- (id)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_32BGRA),
126
+ // (see RNSVColorSpace.h), in either format.
127
+ //
128
+ // NV12 is the decoder's own format, 1.5 bytes a pixel against BGRA's 4: the
129
+ // queue's byte budget then holds five 4K frames ahead rather than one or
130
+ // two. The GPU converts it to RGB when the frame is drawn (yuvBlit.ts),
131
+ // with the matrix each buffer carries; only HDR needs AVFoundation's
132
+ // conversion first (see TrackNeedsSDRConversion). BGRA is converted by
133
+ // VideoToolbox, and a GPU export samples it in place.
134
+ NSMutableDictionary* pixBuffAttributes = [@{
135
+ (id)kCVPixelBufferPixelFormatTypeKey :
136
+ @(item->yuvFrames ? kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
137
+ : kCVPixelFormatType_32BGRA),
129
138
  (id)kCVPixelBufferIOSurfacePropertiesKey : @{},
130
139
  (id)kCVPixelBufferMetalCompatibilityKey : @YES,
131
- AVVideoColorPropertiesKey : SDRColorProperties(),
132
- };
140
+ } mutableCopy];
141
+ if (!item->yuvFrames || TrackNeedsSDRConversion(videoTrack)) {
142
+ pixBuffAttributes[AVVideoColorPropertiesKey] = SDRColorProperties();
143
+ }
133
144
  CGSize resolution = item->resolution;
134
145
  /*
135
146
  * No explicit size asked for, but a cap on the longest side: scale the
@@ -156,8 +167,6 @@ void VideoCompositionItemDecoder::setupReader(CMTime initialTime) {
156
167
  }
157
168
  }
158
169
  if (resolution.width > 0 && resolution.height > 0) {
159
- pixBuffAttributes =
160
- [NSMutableDictionary dictionaryWithDictionary:pixBuffAttributes];
161
170
  [pixBuffAttributes setValue:@(resolution.width)
162
171
  forKey:(id)kCVPixelBufferWidthKey];
163
172
  [pixBuffAttributes setValue:@(resolution.height)
@@ -333,7 +342,10 @@ void VideoCompositionItemDecoder::advanceDecoder(CMTime currentTime) {
333
342
  std::shared_ptr<VideoFrame>
334
343
  VideoCompositionItemDecoder::acquireFrameForTime(CMTime currentTime,
335
344
  bool force) {
336
- if (!frameRing.canAcquire()) return nullptr;
345
+ if (!frameRing.canAcquire()) {
346
+ PreviewStats::ringRefusals++;
347
+ return nullptr;
348
+ }
337
349
  CMSampleBufferRef nextFrame = nil;
338
350
  // advanceDecoder appends to the frame lists from a decoding thread while
339
351
  // this runs on the UI thread: every access to the lists goes through the
@@ -377,6 +389,7 @@ VideoCompositionItemDecoder::acquireFrameForTime(CMTime currentTime,
377
389
  break;
378
390
  }
379
391
  }
392
+ if (!nextFrame && decodedFrames.empty()) PreviewStats::emptyQueues++;
380
393
  }
381
394
  if (nextFrame) {
382
395
  CVPixelBufferRef buffer = CMSampleBufferGetImageBuffer(nextFrame);
package/ios/VideoFrame.mm CHANGED
@@ -101,6 +101,12 @@ jsi::Value VideoFrame::get(jsi::Runtime& runtime,
101
101
  descriptor.setProperty(runtime, "kind",
102
102
  jsi::String::createFromAscii(runtime, "native-buffer"));
103
103
  descriptor.setProperty(runtime, "nativeBuffer", pointer);
104
+ // Read without importing the buffer: NV12 frames are converted to RGB on
105
+ // the GPU, BGRA ones sampled as they are.
106
+ bool nv12 = CVPixelBufferGetPixelFormatType(pixelBuffer) ==
107
+ kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange;
108
+ descriptor.setProperty(runtime, "format",
109
+ jsi::String::createFromAscii(runtime, nv12 ? "nv12" : "bgra8"));
104
110
  return descriptor;
105
111
  }
106
112
  return jsi::Value::undefined();
@@ -9,10 +9,8 @@ export const getVideoCanvas = surface => {
9
9
  throw new Error("Skia checked submission patch is missing from the native binary. Apply the patch and rebuild the native app.");
10
10
  }
11
11
  checked.enableCheckedSubmissions();
12
- const canvas = surface.getCanvas();
13
- if (typeof canvas.dispose !== "function") {
14
- throw new Error("Skia canvas lifecycle patch is missing from the native binary. Apply the patch and rebuild the native app.");
15
- }
16
- return canvas;
12
+ // Owned by the surface: its dispose() detaches the canvas, and drawing on
13
+ // it throws from then on.
14
+ return surface.getCanvas();
17
15
  };
18
16
  //# sourceMappingURL=canvas.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getVideoCanvas","surface","checked","enableCheckedSubmissions","Error","canvas","getCanvas","dispose"],"sourceRoot":"../../src","sources":["canvas.ts"],"mappings":";;AAEA;AACA,OAAO,MAAMA,cAAc,GAAIC,OAAkB,IAAe;EAC9D,SAAS;;EACT,MAAMC,OAAO,GAAGD,OAEf;EACD,IAAI,OAAOC,OAAO,CAACC,wBAAwB,KAAK,UAAU,EAAE;IAC1D,MAAM,IAAIC,KAAK,CACb,8GACF,CAAC;EACH;EACAF,OAAO,CAACC,wBAAwB,CAAC,CAAC;EAClC,MAAME,MAAM,GAAGJ,OAAO,CAACK,SAAS,CAAC,CAAC;EAClC,IAAI,OAAOD,MAAM,CAACE,OAAO,KAAK,UAAU,EAAE;IACxC,MAAM,IAAIH,KAAK,CACb,4GACF,CAAC;EACH;EACA,OAAOC,MAAM;AACf,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["getVideoCanvas","surface","checked","enableCheckedSubmissions","Error","getCanvas"],"sourceRoot":"../../src","sources":["canvas.ts"],"mappings":";;AAEA;AACA,OAAO,MAAMA,cAAc,GAAIC,OAAkB,IAAe;EAC9D,SAAS;;EACT,MAAMC,OAAO,GAAGD,OAEf;EACD,IAAI,OAAOC,OAAO,CAACC,wBAAwB,KAAK,UAAU,EAAE;IAC1D,MAAM,IAAIC,KAAK,CACb,8GACF,CAAC;EACH;EACAF,OAAO,CAACC,wBAAwB,CAAC,CAAC;EAClC;EACA;EACA,OAAOF,OAAO,CAACI,SAAS,CAAC,CAAC;AAC5B,CAAC","ignoreList":[]}
@@ -5,14 +5,14 @@ import { Platform } from "react-native";
5
5
  import { BlendMode, Skia } from "react-native-skia";
6
6
  import { createNativeVideoGpuFrame, getVideoGpuDevice, nativeVideoTextureUsage } from "./gpuDevice.js";
7
7
  import { frameByteSize, releaseVideoMemory, reserveVideoMemory } from "./memory.js";
8
- import { blitYuvFrame, releaseYuvImports, yuvFrameOrigin } from "./yuvBlit.js";
8
+ import { blitNv12Frame, blitYuvFrame, releaseYuvImports, yuvFrameRegion } from "./yuvBlit.js";
9
9
 
10
- /** A decoded frame sampled in place, without an owned snapshot: on iOS its
11
- * IOSurface, on Android its producer's RGBA texture, which the decoder
12
- * buffer was just converted into. The decoder lease stays open while the
13
- * image is in use. */
10
+ /** A decoded frame sampled in place, without an owned snapshot: a BGRA
11
+ * frame's IOSurface on iOS, or for a YUV frame (Android, iOS NV12) its
12
+ * producer's RGBA texture, which the decoder buffer was just converted into.
13
+ * The decoder lease stays open while the image is in use. */
14
14
 
15
- /** Android: the texture a producer's decoded frames are converted into. */
15
+ /** The texture a producer's YUV frames are converted into. */
16
16
 
17
17
  /** Per export session, keyed by producer. `enabled` turns off after a first
18
18
  * failed import, before any frame was sampled in place. */
@@ -65,8 +65,8 @@ export const releaseExportFrame = entry => {
65
65
  entry.frame.dispose?.();
66
66
  };
67
67
 
68
- /** Android: releases a producer's texture and decoder buffer imports. Call
69
- * only once its last frame's GPU work has completed. */
68
+ /** Releases a producer's texture and decoder buffer imports. Call only once
69
+ * its last frame's GPU work has completed. */
70
70
  const releaseProducerTexture = (imports, producer) => {
71
71
  "worklet";
72
72
 
@@ -79,10 +79,11 @@ const releaseProducerTexture = (imports, producer) => {
79
79
  }
80
80
  };
81
81
 
82
- /** Android: converts a decoded ImageReader frame into its producer's RGBA
83
- * texture, wrapped as a Skia image. The conversion is submitted ahead of the
84
- * frame's drawing, on the same queue; the export's checked flush waits for
85
- * both before the lease or the texture is reused. */
82
+ /** Converts a decoded YUV frame (an Android ImageReader buffer, or an iOS
83
+ * NV12 one) into its producer's RGBA texture, wrapped as a Skia image. The
84
+ * conversion is submitted ahead of the frame's drawing, on the same queue;
85
+ * the export's checked flush waits for both before the lease or the texture
86
+ * is reused. */
86
87
  const importYuvExportFrame = (imports, frame) => {
87
88
  "worklet";
88
89
 
@@ -102,7 +103,10 @@ const importYuvExportFrame = (imports, frame) => {
102
103
  try {
103
104
  entry.nativeFrame = createNativeVideoGpuFrame(source.nativeBuffer);
104
105
  const rotation = source.rotation ?? 0;
105
- const origin = yuvFrameOrigin(source.region, rotation, entry.nativeFrame, frame);
106
+ // iOS NV12: the whole buffer, in decoded orientation.
107
+ const nv12 = source.format === "nv12";
108
+ if (nv12 && (entry.nativeFrame.width !== frame.width || entry.nativeFrame.height !== frame.height)) throw new Error("Native video buffer dimensions mismatch");
109
+ const region = nv12 ? null : yuvFrameRegion(source.region, rotation, entry.nativeFrame);
106
110
  const device = getVideoGpuDevice();
107
111
  target = imports.textures.get(producer);
108
112
  if (target && (target.texture.width !== frame.width || target.texture.height !== frame.height)) {
@@ -134,7 +138,7 @@ const importYuvExportFrame = (imports, frame) => {
134
138
  }
135
139
  // Can throw after submitting: drain below before giving the lease back.
136
140
  submitted = true;
137
- blitYuvFrame(device, imports.yuv, producer, entry.nativeFrame, rotation, origin, frame.width, frame.height, target.texture);
141
+ if (nv12) blitNv12Frame(device, entry.nativeFrame, target.texture);else blitYuvFrame(device, imports.yuv, producer, entry.nativeFrame, rotation, region, target.texture);
138
142
  entry.image = Skia.Image.MakeImageFromGPUTexture(target.texture);
139
143
  if (!entry.image) throw new Error("Cannot wrap the decoded frame");
140
144
  return entry;
@@ -158,13 +162,13 @@ const importYuvExportFrame = (imports, frame) => {
158
162
  };
159
163
 
160
164
  /** Wraps a decoded BGRA CVPixelBuffer's IOSurface as a Skia image, read-only.
161
- * The decoder already finished writing it; no producer fence is needed. On
162
- * Android, converts the decoded YUV frame instead (see importYuvExportFrame). */
165
+ * The decoder already finished writing it; no producer fence is needed. A
166
+ * YUV frame (Android, iOS NV12) is converted instead (see importYuvExportFrame). */
163
167
  export const importExportFrame = (frame, imports) => {
164
168
  "worklet";
165
169
 
166
- if (convertsYuv) {
167
- if (!imports) throw new Error("Android in-place frames need their imports");
170
+ if (convertsYuv || frame.texture.format === "nv12") {
171
+ if (!imports) throw new Error("YUV in-place frames need their imports");
168
172
  return importYuvExportFrame(imports, frame);
169
173
  }
170
174
  const entry = {
@@ -230,8 +234,9 @@ export const releaseExportFrames = imports => {
230
234
 
231
235
  /** The export counterpart of ownVideoFrames on iOS: decoded frames are drawn
232
236
  * in place, and a producer's previous frame is released once its next one is
233
- * imported, since every exported frame ends with a checked GPU wait. Other
234
- * frames, or every frame after a first failed import, use `fallback`. */
237
+ * imported, since the export waits for the GPU to complete a frame before it
238
+ * imports the next one. Other frames, or every frame after a first failed
239
+ * import, use `fallback`. */
235
240
  export const ownExportFrames = (imports, decoded, fallback) => {
236
241
  "worklet";
237
242
 
@@ -1 +1 @@
1
- {"version":3,"names":["Platform","BlendMode","Skia","createNativeVideoGpuFrame","getVideoGpuDevice","nativeVideoTextureUsage","frameByteSize","releaseVideoMemory","reserveVideoMemory","blitYuvFrame","releaseYuvImports","yuvFrameOrigin","convertsYuv","OS","createExportFrameImports","entries","Map","producers","Set","enabled","imported","textures","yuv","canImportInPlace","frame","texture","kind","id","undefined","region","releaseExportFrame","entry","image","dispose","accessing","memory","ended","endAccess","state","fences","fence","destroy","nativeFrame","release","releaseProducerTexture","imports","producer","target","get","reservation","delete","importYuvExportFrame","producerId","source","submitted","nativeBuffer","rotation","origin","device","width","height","createTexture","size","format","usage","label","error","set","Image","MakeImageFromGPUTexture","Error","drain","Surface","MakeFromGPUTexture","getCanvas","drawColor","Color","Clear","flush","importExportFrame","pixelFormat","importSharedTextureMemory","handle","beginAccess","releaseExportFrames","keys","ownExportFrames","decoded","fallback","owned","held","current","key","Object","seen","next","console","warn","String","add","aliases","WeakSet","has","crop","values","rest","copying"],"sourceRoot":"../../src","sources":["exportFrames.ts"],"mappings":";;AAAA;AACA,SAASA,QAAQ,QAAQ,cAAc;AACvC,SAASC,SAAS,EAAEC,IAAI,QAAQ,mBAAmB;AAOnD,SACEC,yBAAyB,EACzBC,iBAAiB,EACjBC,uBAAuB,QAClB,gBAAa;AACpB,SACEC,aAAa,EACbC,kBAAkB,EAClBC,kBAAkB,QACb,aAAU;AAEjB,SAASC,YAAY,EAAEC,iBAAiB,EAAEC,cAAc,QAAQ,cAAW;;AAG3E;AACA;AACA;AACA;;AA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iF,IAAI,CAACb,GAAG,CAAC,GAAGpE,KAAK;IACjBkF,OAAO,GAAG,IAAI;EAChB;EACA,OAAOA,OAAO,GAAG;IAAE,GAAGjB,KAAK;IAAE,GAAGD,QAAQ,CAACiB,IAAI;EAAE,CAAC,GAAGhB,KAAK;AAC1D,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["Platform","BlendMode","Skia","createNativeVideoGpuFrame","getVideoGpuDevice","nativeVideoTextureUsage","frameByteSize","releaseVideoMemory","reserveVideoMemory","blitNv12Frame","blitYuvFrame","releaseYuvImports","yuvFrameRegion","convertsYuv","OS","createExportFrameImports","entries","Map","producers","Set","enabled","imported","textures","yuv","canImportInPlace","frame","texture","kind","id","undefined","region","releaseExportFrame","entry","image","dispose","accessing","memory","ended","endAccess","state","fences","fence","destroy","nativeFrame","release","releaseProducerTexture","imports","producer","target","get","reservation","delete","importYuvExportFrame","producerId","source","submitted","nativeBuffer","rotation","nv12","format","width","height","Error","device","createTexture","size","usage","label","error","set","Image","MakeImageFromGPUTexture","drain","Surface","MakeFromGPUTexture","getCanvas","drawColor","Color","Clear","flush","importExportFrame","pixelFormat","importSharedTextureMemory","handle","beginAccess","releaseExportFrames","keys","ownExportFrames","decoded","fallback","owned","held","current","key","Object","seen","next","console","warn","String","add","aliases","WeakSet","has","crop","values","rest","copying"],"sourceRoot":"../../src","sources":["exportFrames.ts"],"mappings":";;AAAA;AACA,SAASA,QAAQ,QAAQ,cAAc;AACvC,SAASC,SAAS,EAAEC,IAAI,QAAQ,mBAAmB;AAOnD,SACEC,yBAAyB,EACzBC,iBAAiB,EACjBC,uBAAuB,QAClB,gBAAa;AACpB,SACEC,aAAa,EACbC,kBAAkB,EAClBC,kBAAkB,QACb,aAAU;AAEjB,SACEC,aAAa,EACbC,YAAY,EACZC,iBAAiB,EACjBC,cAAc,QACT,cAAW;;AAGlB;AACA;AACA;AACA;;AAaA;;AAGA;AACA;;AA4BA;AACA;AACA,MAAMC,WAAW,GAAGb,QAAQ,CA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ACFH,KAAK,CAACS,OAAO,GAAG,CAAC;MACnB,CAAC,CAAC,MAAM;QACN;MAAA;IAEJ;IACA,MAAMkC,KAAK;EACb;EACA;EACA,MAAMsC,IAAgC,GAAG,CAAC,CAAC;EAC3C,IAAIC,OAAO,GAAG,KAAK;EACnB,KAAK,MAAM,CAACd,GAAG,EAAEpE,KAAK,CAAC,IAAIqE,MAAM,CAAC9E,OAAO,CAACwE,OAAO,CAAC,EAAE;IAClD,IAAIG,IAAI,CAACY,GAAG,CAAC9E,KAAK,CAAC,EAAE;IACrBiF,IAAI,CAACb,GAAG,CAAC,GAAGpE,KAAK;IACjBkF,OAAO,GAAG,IAAI;EAChB;EACA,OAAOA,OAAO,GAAG;IAAE,GAAGjB,KAAK;IAAE,GAAGD,QAAQ,CAACiB,IAAI;EAAE,CAAC,GAAGhB,KAAK;AAC1D,CAAC","ignoreList":[]}
@@ -1,16 +1,23 @@
1
1
  "use strict";
2
2
 
3
3
  /// <reference types="@webgpu/types" />
4
- import { Platform } from "react-native";
5
4
  import { BlendMode, Skia } from "react-native-skia";
6
5
  import { getVideoCanvas } from "./canvas.js";
7
- import { createNativeVideoGpuFrame, getVideoGpuDevice } from "./gpuDevice.js";
6
+ import { createNativeVideoGpuFrame, createNativeWindowGpuContext, encoderWindowTextureUsage, getVideoGpuDevice, nativeVideoTextureUsage } from "./gpuDevice.js";
7
+ import { frameByteSize, releaseVideoMemory, reserveVideoMemory } from "./memory.js";
8
8
 
9
- /** An encoder pool buffer that Skia draws into through WebGPU. */
9
+ /** A texture Skia draws an exported frame into through WebGPU: a lent
10
+ * encoder pool buffer on iOS, one of the encoder window's own textures on
11
+ * Android. */
10
12
 
11
- // Captured on the RN runtime. iOS lends CVPixelBuffers, imported through
12
- // their IOSurface; Android lends the AHardwareBuffer itself.
13
- const lendsPixelBuffers = Platform.OS === "ios";
13
+ /** Android: a canvas context presenting to the codec's input Surface. Skia
14
+ * draws each frame into one of two textures of our own, which a GPU copy then
15
+ * puts into the window's texture. The window's textures are the codec's
16
+ * input buffers: the copy waits on the GPU for the codec to hand one back,
17
+ * while the export goes on with the next frame, rather than the frame's
18
+ * checked wait. */
19
+
20
+ const windowSlots = 2;
14
21
  export const supportsEncoderTargets = encoder => {
15
22
  "worklet";
16
23
 
@@ -18,35 +25,20 @@ export const supportsEncoderTargets = encoder => {
18
25
  };
19
26
 
20
27
  // Declared before its callers: worklets capture their closure on creation.
21
- /** Ends GPU access; the lent buffer stays with the caller, to encode or
22
- * release. Call only after a checked flush(true) of its surface. With
23
- * `encoding`, Android keeps the access's sync-fds in `target.fences` for the
24
- * encoder, which owns and closes them: ending an AHB access submits a
25
- * release that flush(true) has not waited for. */
26
- export const closeEncoderTarget = (target, encoding = false) => {
28
+ /** iOS: ends GPU access; the lent buffer stays with the caller, to encode or
29
+ * release. Call only after a checked flush(true) of its surface. */
30
+ export const closeEncoderTarget = target => {
27
31
  "worklet";
28
32
 
29
- target.canvas?.dispose();
33
+ // Disposing the surface detaches its canvas.
30
34
  target.canvas = null;
31
35
  target.surface?.dispose();
32
36
  target.surface = null;
33
37
  if (target.accessing && target.memory && target.texture) {
34
38
  const ended = target.memory.endAccess(target.texture);
35
39
  target.accessing = false;
36
- for (const state of ended?.fences ?? []) {
37
- try {
38
- if (encoding && !lendsPixelBuffers) {
39
- const exported = state.fence.export();
40
- // Unreachable when negotiated: AHB interop requires the device's
41
- // only shared-fence feature to be sync-fd (see gpuDevice.ts).
42
- if (exported.type !== "sync-fd") throw new Error("GPU export needs sync-fd fences");
43
- target.fences.push(exported.handle);
44
- }
45
- } finally {
46
- // iOS: already waited for. The wrapper is released either way.
47
- state.fence.destroy();
48
- }
49
- }
40
+ // Already waited for. The wrappers are released either way.
41
+ for (const state of ended?.fences ?? []) state.fence.destroy();
50
42
  }
51
43
  target.accessing = false;
52
44
  target.texture?.destroy();
@@ -60,13 +52,12 @@ export const closeEncoderTarget = (target, encoding = false) => {
60
52
  target.frame = null;
61
53
  };
62
54
 
63
- /** Lends the next pool buffer and wraps it as a Skia surface. */
55
+ /** iOS: lends the next pool buffer and wraps it as a Skia surface. */
64
56
  export const acquireEncoderTarget = (encoder, width, height) => {
65
57
  "worklet";
66
58
 
67
59
  const target = {
68
60
  pointer: encoder.acquireFrameBuffer(),
69
- fences: [],
70
61
  frame: null,
71
62
  memory: null,
72
63
  texture: null,
@@ -75,24 +66,19 @@ export const acquireEncoderTarget = (encoder, width, height) => {
75
66
  canvas: null
76
67
  };
77
68
  try {
78
- if (lendsPixelBuffers) {
79
- target.frame = createNativeVideoGpuFrame(target.pointer);
80
- if (target.frame.width !== width || target.frame.height !== height || target.frame.pixelFormat !== "bgra8") {
81
- throw new Error("Encoder buffer dimensions or BGRA layout mismatch");
82
- }
69
+ target.frame = createNativeVideoGpuFrame(target.pointer);
70
+ if (target.frame.width !== width || target.frame.height !== height || target.frame.pixelFormat !== "bgra8") {
71
+ throw new Error("Encoder buffer dimensions or BGRA layout mismatch");
83
72
  }
84
73
  const device = getVideoGpuDevice();
85
74
  if (typeof device.importSharedTextureMemory !== "function") {
86
75
  throw new Error("WebGPU shared texture memory is unavailable");
87
76
  }
88
77
  target.memory = device.importSharedTextureMemory({
89
- handle: target.frame ? target.frame.handle : target.pointer,
78
+ handle: target.frame.handle,
90
79
  label: "video export frame"
91
80
  });
92
81
  target.texture = target.memory.createTexture();
93
- if (!lendsPixelBuffers && (target.texture.width !== width || target.texture.height !== height || target.texture.format !== "rgba8unorm")) {
94
- throw new Error("Encoder buffer dimensions or RGBA layout mismatch");
95
- }
96
82
  // Uninitialized: every frame starts with a full clear.
97
83
  target.memory.beginAccess(target.texture, false);
98
84
  target.accessing = true;
@@ -111,8 +97,9 @@ export const acquireEncoderTarget = (encoder, width, height) => {
111
97
  }
112
98
  };
113
99
 
114
- /** Clears one lent buffer on the GPU, then returns it unencoded. Returns the
115
- * failure, or null when this device can export through encoder targets. */
100
+ /** iOS: clears one lent buffer on the GPU, then returns it unencoded.
101
+ * Returns the failure, or null when this device can export through encoder
102
+ * targets. */
116
103
  export const probeEncoderTarget = (encoder, width, height) => {
117
104
  "worklet";
118
105
 
@@ -134,4 +121,160 @@ export const probeEncoderTarget = (encoder, width, height) => {
134
121
  encoder.releaseFrameBuffer();
135
122
  return failure;
136
123
  };
124
+
125
+ /** Android: the window's next texture, checked against the export size. */
126
+ const windowTexture = (window, width, height) => {
127
+ "worklet";
128
+
129
+ const texture = window.pending ?? window.context.getCurrentTexture();
130
+ window.pending = null;
131
+ if (texture.width !== width || texture.height !== height || texture.format !== "rgba8unorm") {
132
+ throw new Error("Encoder window dimensions or RGBA layout mismatch");
133
+ }
134
+ return texture;
135
+ };
136
+
137
+ /** Android: the slot the next frame draws into. Its previous copy completed:
138
+ * the checked wait the export makes before each frame's import covers the
139
+ * queue before it. */
140
+ export const acquireWindowTarget = window => {
141
+ "worklet";
142
+
143
+ return window.slots[window.next];
144
+ };
145
+
146
+ /** Android: copies the slot Skia drew into to the window's next texture and
147
+ * hands it to the encoder, with its time. Call once the slot's surface was
148
+ * flushed: the copy follows the drawing on the same queue. */
149
+ export const presentWindowTarget = (encoder, window, target, time) => {
150
+ "worklet";
151
+
152
+ const source = target.texture;
153
+ const destination = windowTexture(window, source.width, source.height);
154
+ const commands = window.device.createCommandEncoder({
155
+ label: "video export window copy"
156
+ });
157
+ commands.copyTextureToTexture({
158
+ texture: source
159
+ }, {
160
+ texture: destination
161
+ }, {
162
+ width: source.width,
163
+ height: source.height
164
+ });
165
+ window.device.queue.submit([commands.finish()]);
166
+ window.next = (window.next + 1) % window.slots.length;
167
+ // The encoder sets the frame's time on the window, then presents.
168
+ encoder.encodeFrame({
169
+ kind: "window",
170
+ present: () => window.context.present()
171
+ }, time);
172
+ };
173
+
174
+ /** Android: the swapchain gives the codec its buffers back at once, rather
175
+ * than once the context is collected. Call before disposing the encoder. */
176
+ export const closeEncoderWindow = window => {
177
+ "worklet";
178
+
179
+ window.pending = null;
180
+ if (!window.configured) return;
181
+ window.context.unconfigure();
182
+ window.configured = false;
183
+ };
184
+
185
+ /** Android: frees the window's own textures. Call once their last recording
186
+ * was submitted: a copy still in flight keeps its source alive. */
187
+ export const releaseEncoderWindow = window => {
188
+ "worklet";
189
+
190
+ while (window.slots.length) {
191
+ const slot = window.slots[window.slots.length - 1];
192
+ // Disposing the surface detaches its canvas.
193
+ slot.canvas = null;
194
+ slot.surface?.dispose();
195
+ slot.surface = null;
196
+ slot.texture?.destroy();
197
+ slot.texture = null;
198
+ window.slots.pop();
199
+ }
200
+ while (window.reservations.length) {
201
+ releaseVideoMemory(window.reservations[window.reservations.length - 1]);
202
+ window.reservations.pop();
203
+ }
204
+ };
205
+
206
+ /** Android: opens a canvas context on the encoder's input window with its
207
+ * slots, acquires the window's first texture and draws a clear into the
208
+ * first slot: nothing reaches the encoder. Returns the window, or the
209
+ * failure, after which the window is closed and the export can fall back to
210
+ * readback. */
211
+ export const probeEncoderWindow = (encoder, width, height) => {
212
+ "worklet";
213
+
214
+ let window = null;
215
+ let failure = null;
216
+ try {
217
+ if (typeof encoder.acquireInputWindow !== "function") throw new Error("Encoder cannot present through its input window");
218
+ const device = getVideoGpuDevice();
219
+ window = {
220
+ context: createNativeWindowGpuContext(encoder.acquireInputWindow(), width, height),
221
+ device,
222
+ configured: false,
223
+ slots: [],
224
+ next: 0,
225
+ reservations: [],
226
+ pending: null
227
+ };
228
+ // Presented in FIFO order, opaque: every frame reaches the codec.
229
+ window.context.configure({
230
+ device,
231
+ format: "rgba8unorm",
232
+ usage: encoderWindowTextureUsage
233
+ });
234
+ window.configured = true;
235
+ for (let i = 0; i < windowSlots; i++) {
236
+ window.reservations.push(reserveVideoMemory(frameByteSize(width, height), "export window slot"));
237
+ const slot = {
238
+ pointer: null,
239
+ frame: null,
240
+ memory: null,
241
+ texture: device.createTexture({
242
+ label: "video export window slot",
243
+ size: {
244
+ width,
245
+ height
246
+ },
247
+ format: "rgba8unorm",
248
+ usage: nativeVideoTextureUsage
249
+ }),
250
+ accessing: false,
251
+ surface: null,
252
+ canvas: null
253
+ };
254
+ window.slots.push(slot);
255
+ slot.surface = Skia.Surface.MakeFromGPUTexture(slot.texture);
256
+ if (!slot.surface) throw new Error("Cannot wrap the export frame");
257
+ slot.canvas = getVideoCanvas(slot.surface);
258
+ }
259
+ window.pending = windowTexture(window, width, height);
260
+ const target = acquireWindowTarget(window);
261
+ target.canvas.drawColor(Skia.Color("#00000000"), BlendMode.Clear);
262
+ target.surface.flush(true);
263
+ } catch (error) {
264
+ failure = error ?? new Error("GPU export probe failed");
265
+ }
266
+ if (failure === null) return {
267
+ window,
268
+ failure
269
+ };
270
+ if (window) {
271
+ // Not caught: a window still drawn by WebGPU cannot fall back to EGL.
272
+ closeEncoderWindow(window);
273
+ releaseEncoderWindow(window);
274
+ }
275
+ return {
276
+ window: null,
277
+ failure
278
+ };
279
+ };
137
280
  //# sourceMappingURL=exportTarget.js.map