react-native-skia 3.0.3 → 3.0.5
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.
- package/android/CMakeLists.txt +0 -2
- package/android/build.gradle +15 -7
- package/android/cpp/jni/JniPlatformContext.cpp +0 -24
- package/android/cpp/jni/include/JniPlatformContext.h +0 -2
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +0 -140
- package/android/src/main/java/com/reactnative/skia/BackingViewKind.java +24 -0
- package/android/src/main/java/com/reactnative/skia/FrameScheduler.java +104 -0
- package/android/src/main/java/com/reactnative/skia/PlatformContext.java +0 -5
- package/android/src/main/java/com/reactnative/skia/SkiaView.java +55 -44
- package/android/src/test/java/com/reactnative/skia/FrameSchedulerTest.java +186 -0
- package/apple/RNSkApplePlatformContext.h +0 -10
- package/apple/RNSkApplePlatformContext.mm +0 -182
- package/cpp/api/JsiGPUTexture.h +48 -0
- package/cpp/api/JsiSkApi.h +1 -16
- package/cpp/api/JsiSkImage.h +0 -12
- package/cpp/api/JsiSkImageFactory.h +36 -57
- package/cpp/api/JsiSkSurface.h +3 -10
- package/cpp/api/JsiSkSurfaceFactory.h +13 -18
- package/cpp/rnskia/RNDawnContext.h +5 -113
- package/cpp/rnskia/RNDawnUtils.h +33 -0
- package/cpp/rnskia/RNSkPlatformContext.h +0 -54
- package/cpp/rnskia/RNSkView.h +10 -7
- package/lib/commonjs/external/reanimated/index.d.ts +0 -1
- package/lib/commonjs/external/reanimated/index.js +0 -11
- package/lib/commonjs/external/reanimated/index.js.map +1 -1
- package/lib/commonjs/mock/index.js +1 -2
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/skia/types/GPUTexture.d.ts +11 -0
- package/lib/commonjs/skia/types/GPUTexture.js +2 -0
- package/lib/commonjs/skia/types/GPUTexture.js.map +1 -0
- package/lib/commonjs/skia/types/Image/Image.d.ts +0 -10
- package/lib/commonjs/skia/types/Image/Image.js.map +1 -1
- package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +25 -48
- package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/commonjs/skia/types/Skia.d.ts +0 -4
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/types/Surface/Surface.d.ts +3 -14
- package/lib/commonjs/skia/types/Surface/Surface.js.map +1 -1
- package/lib/commonjs/skia/types/Surface/SurfaceFactory.d.ts +10 -9
- package/lib/commonjs/skia/types/Surface/SurfaceFactory.js.map +1 -1
- package/lib/commonjs/skia/types/index.d.ts +1 -2
- package/lib/commonjs/skia/types/index.js +11 -22
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImage.d.ts +0 -1
- package/lib/commonjs/skia/web/JsiSkImage.js +0 -4
- package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +4 -5
- package/lib/commonjs/skia/web/JsiSkImageFactory.js +6 -10
- package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkSurface.d.ts +0 -1
- package/lib/commonjs/skia/web/JsiSkSurface.js +0 -4
- package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkSurfaceFactory.d.ts +2 -2
- package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js +1 -1
- package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +0 -4
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/external/reanimated/index.d.ts +0 -1
- package/lib/module/external/reanimated/index.js +0 -1
- package/lib/module/external/reanimated/index.js.map +1 -1
- package/lib/module/mock/index.js +1 -2
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/skia/types/GPUTexture.d.ts +11 -0
- package/lib/module/skia/types/GPUTexture.js +2 -0
- package/lib/module/skia/types/GPUTexture.js.map +1 -0
- package/lib/module/skia/types/Image/Image.d.ts +0 -10
- package/lib/module/skia/types/Image/Image.js.map +1 -1
- package/lib/module/skia/types/Image/ImageFactory.d.ts +25 -48
- package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/module/skia/types/Skia.d.ts +0 -4
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/types/Surface/Surface.d.ts +3 -14
- package/lib/module/skia/types/Surface/Surface.js.map +1 -1
- package/lib/module/skia/types/Surface/SurfaceFactory.d.ts +10 -9
- package/lib/module/skia/types/Surface/SurfaceFactory.js.map +1 -1
- package/lib/module/skia/types/index.d.ts +1 -2
- package/lib/module/skia/types/index.js +1 -2
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/module/skia/web/JsiSkImage.d.ts +0 -1
- package/lib/module/skia/web/JsiSkImage.js +0 -4
- package/lib/module/skia/web/JsiSkImage.js.map +1 -1
- package/lib/module/skia/web/JsiSkImageFactory.d.ts +4 -5
- package/lib/module/skia/web/JsiSkImageFactory.js +6 -10
- package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkSurface.d.ts +0 -1
- package/lib/module/skia/web/JsiSkSurface.js +0 -4
- package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
- package/lib/module/skia/web/JsiSkSurfaceFactory.d.ts +2 -2
- package/lib/module/skia/web/JsiSkSurfaceFactory.js +1 -1
- package/lib/module/skia/web/JsiSkSurfaceFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +0 -4
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/typescript/src/external/reanimated/index.d.ts +0 -1
- package/lib/typescript/src/skia/types/GPUTexture.d.ts +11 -0
- package/lib/typescript/src/skia/types/Image/Image.d.ts +0 -10
- package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +25 -48
- package/lib/typescript/src/skia/types/Skia.d.ts +0 -4
- package/lib/typescript/src/skia/types/Surface/Surface.d.ts +3 -14
- package/lib/typescript/src/skia/types/Surface/SurfaceFactory.d.ts +10 -9
- package/lib/typescript/src/skia/types/index.d.ts +1 -2
- package/lib/typescript/src/skia/web/JsiSkImage.d.ts +0 -1
- package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +4 -5
- package/lib/typescript/src/skia/web/JsiSkSurface.d.ts +0 -1
- package/lib/typescript/src/skia/web/JsiSkSurfaceFactory.d.ts +2 -2
- package/package.json +1 -1
- package/src/external/reanimated/index.ts +0 -1
- package/src/mock/index.ts +0 -1
- package/src/skia/types/GPUTexture.ts +9 -0
- package/src/skia/types/Image/Image.ts +0 -11
- package/src/skia/types/Image/ImageFactory.ts +25 -55
- package/src/skia/types/Skia.ts +0 -4
- package/src/skia/types/Surface/Surface.ts +3 -15
- package/src/skia/types/Surface/SurfaceFactory.ts +11 -9
- package/src/skia/types/index.ts +1 -2
- package/src/skia/web/JsiSkImage.ts +0 -5
- package/src/skia/web/JsiSkImageFactory.ts +16 -16
- package/src/skia/web/JsiSkSurface.ts +0 -5
- package/src/skia/web/JsiSkSurfaceFactory.ts +2 -2
- package/src/skia/web/JsiSkia.ts +0 -4
- package/android/cpp/rnskia-android/AHardwareBufferUtils.cpp +0 -31
- package/android/cpp/rnskia-android/AHardwareBufferUtils.h +0 -13
- package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +0 -200
- package/android/cpp/rnskia-android/RNSkAndroidVideo.h +0 -44
- package/android/src/main/java/com/reactnative/skia/RNSkVideo.java +0 -320
- package/apple/RNSkAppleVideo.h +0 -78
- package/apple/RNSkAppleVideo.mm +0 -292
- package/cpp/api/JsiNativeBuffer.h +0 -56
- package/cpp/api/JsiTextureInfo.h +0 -53
- package/cpp/api/JsiVideo.h +0 -101
- package/cpp/rnskia/RNSkVideo.h +0 -31
- package/lib/commonjs/external/reanimated/useVideo.d.ts +0 -21
- package/lib/commonjs/external/reanimated/useVideo.js +0 -150
- package/lib/commonjs/external/reanimated/useVideo.js.map +0 -1
- package/lib/commonjs/external/reanimated/useVideoLoading.d.ts +0 -4
- package/lib/commonjs/external/reanimated/useVideoLoading.js +0 -40
- package/lib/commonjs/external/reanimated/useVideoLoading.js.map +0 -1
- package/lib/commonjs/external/reanimated/useVideoLoading.web.d.ts +0 -4
- package/lib/commonjs/external/reanimated/useVideoLoading.web.js +0 -20
- package/lib/commonjs/external/reanimated/useVideoLoading.web.js.map +0 -1
- package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.d.ts +0 -29
- package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js +0 -15
- package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js.map +0 -1
- package/lib/commonjs/skia/types/NativeBuffer/index.d.ts +0 -1
- package/lib/commonjs/skia/types/NativeBuffer/index.js +0 -17
- package/lib/commonjs/skia/types/NativeBuffer/index.js.map +0 -1
- package/lib/commonjs/skia/types/Video/Video.d.ts +0 -20
- package/lib/commonjs/skia/types/Video/Video.js +0 -6
- package/lib/commonjs/skia/types/Video/Video.js.map +0 -1
- package/lib/commonjs/skia/types/Video/index.d.ts +0 -1
- package/lib/commonjs/skia/types/Video/index.js +0 -17
- package/lib/commonjs/skia/types/Video/index.js.map +0 -1
- package/lib/commonjs/skia/web/CanvasKitWebGLBufferImpl.d.ts +0 -9
- package/lib/commonjs/skia/web/CanvasKitWebGLBufferImpl.js +0 -30
- package/lib/commonjs/skia/web/CanvasKitWebGLBufferImpl.js.map +0 -1
- package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.d.ts +0 -9
- package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js +0 -48
- package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js.map +0 -1
- package/lib/commonjs/skia/web/JsiVideo.d.ts +0 -28
- package/lib/commonjs/skia/web/JsiVideo.js +0 -96
- package/lib/commonjs/skia/web/JsiVideo.js.map +0 -1
- package/lib/module/external/reanimated/useVideo.d.ts +0 -21
- package/lib/module/external/reanimated/useVideo.js +0 -142
- package/lib/module/external/reanimated/useVideo.js.map +0 -1
- package/lib/module/external/reanimated/useVideoLoading.d.ts +0 -4
- package/lib/module/external/reanimated/useVideoLoading.js +0 -33
- package/lib/module/external/reanimated/useVideoLoading.js.map +0 -1
- package/lib/module/external/reanimated/useVideoLoading.web.d.ts +0 -4
- package/lib/module/external/reanimated/useVideoLoading.web.js +0 -13
- package/lib/module/external/reanimated/useVideoLoading.web.js.map +0 -1
- package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.d.ts +0 -29
- package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js +0 -5
- package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js.map +0 -1
- package/lib/module/skia/types/NativeBuffer/index.d.ts +0 -1
- package/lib/module/skia/types/NativeBuffer/index.js +0 -2
- package/lib/module/skia/types/NativeBuffer/index.js.map +0 -1
- package/lib/module/skia/types/Video/Video.d.ts +0 -20
- package/lib/module/skia/types/Video/Video.js +0 -2
- package/lib/module/skia/types/Video/Video.js.map +0 -1
- package/lib/module/skia/types/Video/index.d.ts +0 -1
- package/lib/module/skia/types/Video/index.js +0 -2
- package/lib/module/skia/types/Video/index.js.map +0 -1
- package/lib/module/skia/web/CanvasKitWebGLBufferImpl.d.ts +0 -9
- package/lib/module/skia/web/CanvasKitWebGLBufferImpl.js +0 -23
- package/lib/module/skia/web/CanvasKitWebGLBufferImpl.js.map +0 -1
- package/lib/module/skia/web/JsiSkNativeBufferFactory.d.ts +0 -9
- package/lib/module/skia/web/JsiSkNativeBufferFactory.js +0 -41
- package/lib/module/skia/web/JsiSkNativeBufferFactory.js.map +0 -1
- package/lib/module/skia/web/JsiVideo.d.ts +0 -28
- package/lib/module/skia/web/JsiVideo.js +0 -88
- package/lib/module/skia/web/JsiVideo.js.map +0 -1
- package/lib/typescript/src/external/reanimated/useVideo.d.ts +0 -21
- package/lib/typescript/src/external/reanimated/useVideoLoading.d.ts +0 -4
- package/lib/typescript/src/external/reanimated/useVideoLoading.web.d.ts +0 -4
- package/lib/typescript/src/skia/types/NativeBuffer/NativeBufferFactory.d.ts +0 -29
- package/lib/typescript/src/skia/types/NativeBuffer/index.d.ts +0 -1
- package/lib/typescript/src/skia/types/Video/Video.d.ts +0 -20
- package/lib/typescript/src/skia/types/Video/index.d.ts +0 -1
- package/lib/typescript/src/skia/web/CanvasKitWebGLBufferImpl.d.ts +0 -9
- package/lib/typescript/src/skia/web/JsiSkNativeBufferFactory.d.ts +0 -9
- package/lib/typescript/src/skia/web/JsiVideo.d.ts +0 -28
- package/src/external/reanimated/useVideo.ts +0 -161
- package/src/external/reanimated/useVideoLoading.ts +0 -39
- package/src/external/reanimated/useVideoLoading.web.ts +0 -17
- package/src/skia/types/NativeBuffer/NativeBufferFactory.ts +0 -52
- package/src/skia/types/NativeBuffer/index.ts +0 -1
- package/src/skia/types/Video/Video.ts +0 -19
- package/src/skia/types/Video/index.ts +0 -1
- package/src/skia/web/CanvasKitWebGLBufferImpl.ts +0 -25
- package/src/skia/web/JsiSkNativeBufferFactory.ts +0 -51
- package/src/skia/web/JsiVideo.ts +0 -113
package/apple/RNSkAppleVideo.mm
DELETED
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
#include <memory>
|
|
2
|
-
#include <string>
|
|
3
|
-
|
|
4
|
-
#pragma clang diagnostic push
|
|
5
|
-
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
6
|
-
|
|
7
|
-
#include "include/core/SkImage.h"
|
|
8
|
-
|
|
9
|
-
#pragma clang diagnostic pop
|
|
10
|
-
|
|
11
|
-
#include "RNSkAppleVideo.h"
|
|
12
|
-
#include <AVFoundation/AVFoundation.h>
|
|
13
|
-
#include <CoreVideo/CoreVideo.h>
|
|
14
|
-
|
|
15
|
-
#if !TARGET_OS_OSX
|
|
16
|
-
// Helper class to bridge CADisplayLink callback to C++
|
|
17
|
-
@interface RNSkDisplayLinkTarget : NSObject
|
|
18
|
-
@property(nonatomic, assign) RNSkia::RNSkAppleVideo *video;
|
|
19
|
-
- (void)displayLinkFired:(CADisplayLink *)sender;
|
|
20
|
-
@end
|
|
21
|
-
|
|
22
|
-
@implementation RNSkDisplayLinkTarget
|
|
23
|
-
- (void)displayLinkFired:(CADisplayLink *)sender {
|
|
24
|
-
if (_video) {
|
|
25
|
-
_video->onDisplayLink();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
@end
|
|
29
|
-
#endif
|
|
30
|
-
|
|
31
|
-
namespace RNSkia {
|
|
32
|
-
|
|
33
|
-
RNSkAppleVideo::RNSkAppleVideo(std::string url, RNSkPlatformContext *context)
|
|
34
|
-
: _url(std::move(url)), _context(context) {
|
|
35
|
-
setupPlayer();
|
|
36
|
-
setupDisplayLink();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
RNSkAppleVideo::~RNSkAppleVideo() {
|
|
40
|
-
#if !TARGET_OS_OSX
|
|
41
|
-
if (_displayLink) {
|
|
42
|
-
[_displayLink invalidate];
|
|
43
|
-
_displayLink = nullptr;
|
|
44
|
-
}
|
|
45
|
-
if (_displayLinkTarget) {
|
|
46
|
-
[_displayLinkTarget setVideo:nullptr];
|
|
47
|
-
_displayLinkTarget = nullptr;
|
|
48
|
-
}
|
|
49
|
-
#else
|
|
50
|
-
if (_displayLink) {
|
|
51
|
-
CVDisplayLinkStop(_displayLink);
|
|
52
|
-
CVDisplayLinkRelease(_displayLink);
|
|
53
|
-
_displayLink = nullptr;
|
|
54
|
-
}
|
|
55
|
-
#endif
|
|
56
|
-
if (_endObserver) {
|
|
57
|
-
[[NSNotificationCenter defaultCenter] removeObserver:_endObserver];
|
|
58
|
-
_endObserver = nullptr;
|
|
59
|
-
}
|
|
60
|
-
if (_player) {
|
|
61
|
-
[_player pause];
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
void RNSkAppleVideo::setupPlayer() {
|
|
66
|
-
NSURL *videoURL = [NSURL URLWithString:@(_url.c_str())];
|
|
67
|
-
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:videoURL];
|
|
68
|
-
_player = [AVPlayer playerWithPlayerItem:playerItem];
|
|
69
|
-
_playerItem = playerItem;
|
|
70
|
-
_player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
|
|
71
|
-
|
|
72
|
-
NSDictionary *outputSettings = getOutputSettings();
|
|
73
|
-
_videoOutput =
|
|
74
|
-
[[AVPlayerItemVideoOutput alloc] initWithOutputSettings:outputSettings];
|
|
75
|
-
[playerItem addOutput:_videoOutput];
|
|
76
|
-
|
|
77
|
-
CMTime time = playerItem.asset.duration;
|
|
78
|
-
if (time.timescale != 0) {
|
|
79
|
-
_duration = CMTimeGetSeconds(time) * 1000; // Store duration in milliseconds
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
AVAssetTrack *videoTrack =
|
|
83
|
-
[[playerItem.asset tracksWithMediaType:AVMediaTypeVideo] firstObject];
|
|
84
|
-
if (videoTrack) {
|
|
85
|
-
_framerate = videoTrack.nominalFrameRate;
|
|
86
|
-
_preferredTransform = videoTrack.preferredTransform;
|
|
87
|
-
CGSize videoSize = videoTrack.naturalSize;
|
|
88
|
-
_videoWidth = videoSize.width;
|
|
89
|
-
_videoHeight = videoSize.height;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Set up end-of-playback observer
|
|
93
|
-
__weak AVPlayer *weakPlayer = _player;
|
|
94
|
-
_endObserver = [[NSNotificationCenter defaultCenter]
|
|
95
|
-
addObserverForName:AVPlayerItemDidPlayToEndTimeNotification
|
|
96
|
-
object:playerItem
|
|
97
|
-
queue:[NSOperationQueue mainQueue]
|
|
98
|
-
usingBlock:^(NSNotification *note) {
|
|
99
|
-
if (_isLooping) {
|
|
100
|
-
[weakPlayer seekToTime:kCMTimeZero
|
|
101
|
-
toleranceBefore:kCMTimeZero
|
|
102
|
-
toleranceAfter:kCMTimeZero
|
|
103
|
-
completionHandler:nil];
|
|
104
|
-
} else {
|
|
105
|
-
_isPlaying = false;
|
|
106
|
-
}
|
|
107
|
-
}];
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
void RNSkAppleVideo::setupDisplayLink() {
|
|
111
|
-
#if !TARGET_OS_OSX
|
|
112
|
-
_displayLinkTarget = [[RNSkDisplayLinkTarget alloc] init];
|
|
113
|
-
[_displayLinkTarget setVideo:this];
|
|
114
|
-
|
|
115
|
-
_displayLink =
|
|
116
|
-
[CADisplayLink displayLinkWithTarget:_displayLinkTarget
|
|
117
|
-
selector:@selector(displayLinkFired:)];
|
|
118
|
-
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop]
|
|
119
|
-
forMode:NSRunLoopCommonModes];
|
|
120
|
-
_displayLink.paused = YES; // Start paused, will unpause when play() is called
|
|
121
|
-
#else
|
|
122
|
-
// Create CVDisplayLink for macOS
|
|
123
|
-
CVDisplayLinkCreateWithActiveCGDisplays(&_displayLink);
|
|
124
|
-
CVDisplayLinkSetOutputCallback(_displayLink, &displayLinkCallback, this);
|
|
125
|
-
_displayLinkRunning = false;
|
|
126
|
-
#endif
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
void RNSkAppleVideo::onDisplayLink() {
|
|
130
|
-
CMTime outputItemTime =
|
|
131
|
-
[_videoOutput itemTimeForHostTime:CACurrentMediaTime()];
|
|
132
|
-
|
|
133
|
-
if ([_videoOutput hasNewPixelBufferForItemTime:outputItemTime]) {
|
|
134
|
-
CMTime actualItemTime = kCMTimeZero;
|
|
135
|
-
CVPixelBufferRef pixelBuffer =
|
|
136
|
-
[_videoOutput copyPixelBufferForItemTime:outputItemTime
|
|
137
|
-
itemTimeForDisplay:&actualItemTime];
|
|
138
|
-
if (pixelBuffer) {
|
|
139
|
-
_lastImage = _context->makeImageFromNativeBuffer((void *)pixelBuffer);
|
|
140
|
-
_lastFrameTimeMs = CMTimeGetSeconds(actualItemTime) * 1000;
|
|
141
|
-
CVPixelBufferRelease(pixelBuffer);
|
|
142
|
-
|
|
143
|
-
if (_waitingForFrame) {
|
|
144
|
-
_waitingForFrame = false;
|
|
145
|
-
// If paused and we got the frame we were waiting for, pause the display
|
|
146
|
-
// link
|
|
147
|
-
if (!_isPlaying) {
|
|
148
|
-
#if !TARGET_OS_OSX
|
|
149
|
-
_displayLink.paused = YES;
|
|
150
|
-
#else
|
|
151
|
-
stopDisplayLink();
|
|
152
|
-
#endif
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
void RNSkAppleVideo::expectFrame() {
|
|
160
|
-
_waitingForFrame = true;
|
|
161
|
-
#if !TARGET_OS_OSX
|
|
162
|
-
_displayLink.paused = NO;
|
|
163
|
-
#else
|
|
164
|
-
startDisplayLink();
|
|
165
|
-
#endif
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
#if TARGET_OS_OSX
|
|
169
|
-
CVReturn RNSkAppleVideo::displayLinkCallback(CVDisplayLinkRef displayLink,
|
|
170
|
-
const CVTimeStamp *now,
|
|
171
|
-
const CVTimeStamp *outputTime,
|
|
172
|
-
CVOptionFlags flagsIn,
|
|
173
|
-
CVOptionFlags *flagsOut,
|
|
174
|
-
void *context) {
|
|
175
|
-
RNSkAppleVideo *video = static_cast<RNSkAppleVideo *>(context);
|
|
176
|
-
// Dispatch to main thread since video operations need to happen there
|
|
177
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
178
|
-
video->onDisplayLink();
|
|
179
|
-
});
|
|
180
|
-
return kCVReturnSuccess;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
void RNSkAppleVideo::startDisplayLink() {
|
|
184
|
-
if (_displayLink && !_displayLinkRunning) {
|
|
185
|
-
CVDisplayLinkStart(_displayLink);
|
|
186
|
-
_displayLinkRunning = true;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
void RNSkAppleVideo::stopDisplayLink() {
|
|
191
|
-
if (_displayLink && _displayLinkRunning) {
|
|
192
|
-
CVDisplayLinkStop(_displayLink);
|
|
193
|
-
_displayLinkRunning = false;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
#endif
|
|
197
|
-
|
|
198
|
-
sk_sp<SkImage> RNSkAppleVideo::nextImage(double *timeStamp) {
|
|
199
|
-
if (timeStamp) {
|
|
200
|
-
*timeStamp = CMTimeGetSeconds([_player currentTime]);
|
|
201
|
-
}
|
|
202
|
-
return _lastImage;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
NSDictionary *RNSkAppleVideo::getOutputSettings() {
|
|
206
|
-
return @{
|
|
207
|
-
(id)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_32BGRA),
|
|
208
|
-
(id)kCVPixelBufferMetalCompatibilityKey : @YES
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
float RNSkAppleVideo::getRotationInDegrees() {
|
|
213
|
-
CGFloat rotationAngle = 0.0;
|
|
214
|
-
auto transform = _preferredTransform;
|
|
215
|
-
if (transform.a == 0 && transform.b == 1 && transform.c == -1 &&
|
|
216
|
-
transform.d == 0) {
|
|
217
|
-
rotationAngle = 90;
|
|
218
|
-
} else if (transform.a == 0 && transform.b == -1 && transform.c == 1 &&
|
|
219
|
-
transform.d == 0) {
|
|
220
|
-
rotationAngle = 270;
|
|
221
|
-
} else if (transform.a == -1 && transform.b == 0 && transform.c == 0 &&
|
|
222
|
-
transform.d == -1) {
|
|
223
|
-
rotationAngle = 180;
|
|
224
|
-
}
|
|
225
|
-
return rotationAngle;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
void RNSkAppleVideo::seek(double timeInMilliseconds) {
|
|
229
|
-
CMTime seekTime =
|
|
230
|
-
CMTimeMakeWithSeconds(timeInMilliseconds / 1000.0, NSEC_PER_SEC);
|
|
231
|
-
CMTime previousTime = [_player currentTime];
|
|
232
|
-
|
|
233
|
-
[_player seekToTime:seekTime
|
|
234
|
-
toleranceBefore:kCMTimeZero
|
|
235
|
-
toleranceAfter:kCMTimeZero
|
|
236
|
-
completionHandler:^(BOOL finished) {
|
|
237
|
-
if (finished &&
|
|
238
|
-
CMTimeCompare([_player currentTime], previousTime) != 0) {
|
|
239
|
-
// Ensure a frame is extracted after seek, even when paused
|
|
240
|
-
expectFrame();
|
|
241
|
-
}
|
|
242
|
-
}];
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
void RNSkAppleVideo::play() {
|
|
246
|
-
if (_player) {
|
|
247
|
-
[_player play];
|
|
248
|
-
_isPlaying = true;
|
|
249
|
-
#if !TARGET_OS_OSX
|
|
250
|
-
_displayLink.paused = NO;
|
|
251
|
-
#else
|
|
252
|
-
startDisplayLink();
|
|
253
|
-
#endif
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
void RNSkAppleVideo::pause() {
|
|
258
|
-
if (_player) {
|
|
259
|
-
[_player pause];
|
|
260
|
-
_isPlaying = false;
|
|
261
|
-
// Only pause display link if not waiting for a frame
|
|
262
|
-
if (!_waitingForFrame) {
|
|
263
|
-
#if !TARGET_OS_OSX
|
|
264
|
-
_displayLink.paused = YES;
|
|
265
|
-
#else
|
|
266
|
-
stopDisplayLink();
|
|
267
|
-
#endif
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
double RNSkAppleVideo::duration() { return _duration; }
|
|
273
|
-
|
|
274
|
-
double RNSkAppleVideo::framerate() { return _framerate; }
|
|
275
|
-
|
|
276
|
-
double RNSkAppleVideo::currentTime() {
|
|
277
|
-
// Return the timestamp of the last captured frame for accurate
|
|
278
|
-
// synchronization
|
|
279
|
-
return _lastFrameTimeMs;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
SkISize RNSkAppleVideo::getSize() {
|
|
283
|
-
return SkISize::Make(_videoWidth, _videoHeight);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
void RNSkAppleVideo::setVolume(float volume) { _player.volume = volume; }
|
|
287
|
-
|
|
288
|
-
void RNSkAppleVideo::setLooping(bool looping) { _isLooping = looping; }
|
|
289
|
-
|
|
290
|
-
bool RNSkAppleVideo::isPlaying() { return _isPlaying; }
|
|
291
|
-
|
|
292
|
-
} // namespace RNSkia
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <memory>
|
|
4
|
-
#include <utility>
|
|
5
|
-
|
|
6
|
-
#include <jsi/jsi.h>
|
|
7
|
-
|
|
8
|
-
#include "JsiSkImage.h"
|
|
9
|
-
#include "JsiSkNativeObjects.h"
|
|
10
|
-
|
|
11
|
-
namespace RNSkia {
|
|
12
|
-
|
|
13
|
-
namespace jsi = facebook::jsi;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
Implementation of the ParagraphBuilderFactory for making ParagraphBuilder JSI
|
|
17
|
-
object
|
|
18
|
-
*/
|
|
19
|
-
class JsiNativeBufferFactory
|
|
20
|
-
: public JsiSkNativeObject<JsiNativeBufferFactory> {
|
|
21
|
-
public:
|
|
22
|
-
static constexpr const char *CLASS_NAME = "NativeBufferFactory";
|
|
23
|
-
|
|
24
|
-
// Native buffer pointers travel as BigInts, which the void* converter
|
|
25
|
-
// produces/consumes.
|
|
26
|
-
void *MakeFromImage(sk_sp<SkImage> image) {
|
|
27
|
-
image->makeNonTextureImage();
|
|
28
|
-
uint64_t pointer = getContext()->makeNativeBuffer(image);
|
|
29
|
-
return reinterpret_cast<void *>(pointer);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
void *MakeTestBuffer(int width, int height) {
|
|
33
|
-
uint64_t pointer = getContext()->makeTestNativeBuffer(width, height);
|
|
34
|
-
return reinterpret_cast<void *>(pointer);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
void Release(void *pointer) {
|
|
38
|
-
getContext()->releaseNativeBuffer(reinterpret_cast<uintptr_t>(pointer));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
42
|
-
installMethod(runtime, prototype, "Release",
|
|
43
|
-
&JsiNativeBufferFactory::Release);
|
|
44
|
-
installMethod(runtime, prototype, "MakeFromImage",
|
|
45
|
-
&JsiNativeBufferFactory::MakeFromImage);
|
|
46
|
-
installMethod(runtime, prototype, "MakeTestBuffer",
|
|
47
|
-
&JsiNativeBufferFactory::MakeTestBuffer);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
size_t getMemoryPressure() override { return 1024; }
|
|
51
|
-
|
|
52
|
-
explicit JsiNativeBufferFactory(std::shared_ptr<RNSkPlatformContext> context)
|
|
53
|
-
: JsiSkNativeObject<JsiNativeBufferFactory>(std::move(context)) {}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
} // namespace RNSkia
|
package/cpp/api/JsiTextureInfo.h
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <jsi/jsi.h>
|
|
4
|
-
|
|
5
|
-
#include "rnskia/RNSkPlatformContext.h"
|
|
6
|
-
|
|
7
|
-
namespace jsi = facebook::jsi;
|
|
8
|
-
namespace react = facebook::react;
|
|
9
|
-
|
|
10
|
-
namespace RNSkia {
|
|
11
|
-
|
|
12
|
-
namespace JsiTextureInfo {
|
|
13
|
-
|
|
14
|
-
inline jsi::Value toValue(jsi::Runtime &runtime, const TextureInfo &texInfo) {
|
|
15
|
-
jsi::Object textureInfo(runtime);
|
|
16
|
-
textureInfo.setProperty(
|
|
17
|
-
runtime, "mtlTexture",
|
|
18
|
-
jsi::BigInt::fromUint64(runtime,
|
|
19
|
-
reinterpret_cast<uint64_t>(texInfo.mtlTexture)));
|
|
20
|
-
textureInfo.setProperty(runtime, "glTarget",
|
|
21
|
-
static_cast<int>(texInfo.glTarget));
|
|
22
|
-
textureInfo.setProperty(runtime, "glID", static_cast<int>(texInfo.glID));
|
|
23
|
-
textureInfo.setProperty(runtime, "glFormat",
|
|
24
|
-
static_cast<int>(texInfo.glFormat));
|
|
25
|
-
textureInfo.setProperty(runtime, "glProtected",
|
|
26
|
-
static_cast<int>(texInfo.glProtected));
|
|
27
|
-
return textureInfo;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
inline TextureInfo fromValue(jsi::Runtime &runtime, const jsi::Value &value) {
|
|
31
|
-
auto object = value.getObject(runtime);
|
|
32
|
-
TextureInfo texInfo;
|
|
33
|
-
if (object.hasProperty(runtime, "mtlTexture")) {
|
|
34
|
-
texInfo.mtlTexture =
|
|
35
|
-
reinterpret_cast<const void *>(object.getProperty(runtime, "mtlTexture")
|
|
36
|
-
.asBigInt(runtime)
|
|
37
|
-
.asUint64(runtime));
|
|
38
|
-
}
|
|
39
|
-
if (object.hasProperty(runtime, "glID")) {
|
|
40
|
-
texInfo.glTarget = static_cast<unsigned int>(
|
|
41
|
-
object.getProperty(runtime, "glTarget").asNumber());
|
|
42
|
-
texInfo.glID = static_cast<unsigned int>(
|
|
43
|
-
object.getProperty(runtime, "glID").asNumber());
|
|
44
|
-
texInfo.glFormat = static_cast<unsigned int>(
|
|
45
|
-
object.getProperty(runtime, "glFormat").asNumber());
|
|
46
|
-
texInfo.glProtected =
|
|
47
|
-
object.getProperty(runtime, "glProtected").asNumber() != 0;
|
|
48
|
-
}
|
|
49
|
-
return texInfo;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
} // namespace JsiTextureInfo
|
|
53
|
-
} // namespace RNSkia
|
package/cpp/api/JsiVideo.h
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <memory>
|
|
4
|
-
#include <utility>
|
|
5
|
-
#include <variant>
|
|
6
|
-
|
|
7
|
-
#include "JsiSkNativeObjects.h"
|
|
8
|
-
#include <jsi/jsi.h>
|
|
9
|
-
|
|
10
|
-
#include "JsiSkConverters.h"
|
|
11
|
-
#include "JsiSkImage.h"
|
|
12
|
-
|
|
13
|
-
#include "rnskia/RNSkVideo.h"
|
|
14
|
-
|
|
15
|
-
namespace RNSkia {
|
|
16
|
-
|
|
17
|
-
namespace jsi = facebook::jsi;
|
|
18
|
-
|
|
19
|
-
class JsiVideo
|
|
20
|
-
: public JsiSkWrappingSharedPtrNativeObject<JsiVideo, RNSkVideo> {
|
|
21
|
-
public:
|
|
22
|
-
static constexpr const char *CLASS_NAME = "Video";
|
|
23
|
-
|
|
24
|
-
std::variant<std::nullptr_t, std::shared_ptr<JsiSkImage>> nextImage() {
|
|
25
|
-
double timestamp = 0;
|
|
26
|
-
auto image = getObject()->nextImage(×tamp);
|
|
27
|
-
if (!image) {
|
|
28
|
-
return nullptr;
|
|
29
|
-
}
|
|
30
|
-
return std::make_shared<JsiSkImage>(getContext(), std::move(image));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
double duration() { return getObject()->duration(); }
|
|
34
|
-
|
|
35
|
-
double framerate() { return getObject()->framerate(); }
|
|
36
|
-
|
|
37
|
-
double currentTime() { return getObject()->currentTime(); }
|
|
38
|
-
|
|
39
|
-
bool isPlaying() { return getObject()->isPlaying(); }
|
|
40
|
-
|
|
41
|
-
void seek(double timestamp) { getObject()->seek(timestamp); }
|
|
42
|
-
|
|
43
|
-
double rotation() {
|
|
44
|
-
return static_cast<double>(getObject()->getRotationInDegrees());
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
SkISize size() { return getObject()->getSize(); }
|
|
48
|
-
|
|
49
|
-
void play() { getObject()->play(); }
|
|
50
|
-
|
|
51
|
-
void pause() { getObject()->pause(); }
|
|
52
|
-
|
|
53
|
-
void setVolume(double volume) {
|
|
54
|
-
getObject()->setVolume(static_cast<float>(volume));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
void setLooping(bool looping) { getObject()->setLooping(looping); }
|
|
58
|
-
|
|
59
|
-
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
60
|
-
installCommon(runtime, prototype);
|
|
61
|
-
installMethod(runtime, prototype, "nextImage", &JsiVideo::nextImage);
|
|
62
|
-
installMethod(runtime, prototype, "duration", &JsiVideo::duration);
|
|
63
|
-
installMethod(runtime, prototype, "framerate", &JsiVideo::framerate);
|
|
64
|
-
installMethod(runtime, prototype, "currentTime", &JsiVideo::currentTime);
|
|
65
|
-
installMethod(runtime, prototype, "isPlaying", &JsiVideo::isPlaying);
|
|
66
|
-
installMethod(runtime, prototype, "seek", &JsiVideo::seek);
|
|
67
|
-
installMethod(runtime, prototype, "rotation", &JsiVideo::rotation);
|
|
68
|
-
installMethod(runtime, prototype, "size", &JsiVideo::size);
|
|
69
|
-
installMethod(runtime, prototype, "play", &JsiVideo::play);
|
|
70
|
-
installMethod(runtime, prototype, "pause", &JsiVideo::pause);
|
|
71
|
-
installMethod(runtime, prototype, "setVolume", &JsiVideo::setVolume);
|
|
72
|
-
installMethod(runtime, prototype, "setLooping", &JsiVideo::setLooping);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
JsiVideo(std::shared_ptr<RNSkPlatformContext> context,
|
|
76
|
-
std::shared_ptr<RNSkVideo> video)
|
|
77
|
-
: JsiSkWrappingSharedPtrNativeObject<JsiVideo, RNSkVideo>(
|
|
78
|
-
std::move(context), std::move(video)) {}
|
|
79
|
-
|
|
80
|
-
size_t getMemoryPressure() override { return 32768; }
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Creates the function for construction a new instance of the SkFont
|
|
84
|
-
* wrapper
|
|
85
|
-
* @param context Platform context
|
|
86
|
-
* @return A function for creating a new host object wrapper for the SkFont
|
|
87
|
-
* class
|
|
88
|
-
*/
|
|
89
|
-
static const jsi::HostFunctionType
|
|
90
|
-
createCtor(std::shared_ptr<RNSkPlatformContext> context) {
|
|
91
|
-
return JSI_HOST_FUNCTION_LAMBDA {
|
|
92
|
-
auto url = arguments[0].asString(runtime).utf8(runtime);
|
|
93
|
-
auto video = context->createVideo(url);
|
|
94
|
-
// Return the newly constructed object
|
|
95
|
-
return makeJsiObject(runtime, std::make_shared<JsiVideo>(
|
|
96
|
-
std::move(context), std::move(video)));
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
} // namespace RNSkia
|
package/cpp/rnskia/RNSkVideo.h
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <string>
|
|
4
|
-
|
|
5
|
-
#pragma clang diagnostic push
|
|
6
|
-
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
7
|
-
|
|
8
|
-
#include "include/core/SkImage.h"
|
|
9
|
-
|
|
10
|
-
#pragma clang diagnostic pop
|
|
11
|
-
|
|
12
|
-
namespace RNSkia {
|
|
13
|
-
|
|
14
|
-
class RNSkVideo {
|
|
15
|
-
public:
|
|
16
|
-
virtual ~RNSkVideo() = default;
|
|
17
|
-
virtual sk_sp<SkImage> nextImage(double *timeStamp = nullptr) = 0;
|
|
18
|
-
virtual double duration() = 0;
|
|
19
|
-
virtual double framerate() = 0;
|
|
20
|
-
virtual double currentTime() = 0;
|
|
21
|
-
virtual void seek(double timestamp) = 0;
|
|
22
|
-
virtual float getRotationInDegrees() = 0;
|
|
23
|
-
virtual SkISize getSize() = 0;
|
|
24
|
-
virtual void play() = 0;
|
|
25
|
-
virtual void pause() = 0;
|
|
26
|
-
virtual void setVolume(float volume) = 0;
|
|
27
|
-
virtual void setLooping(bool looping) = 0;
|
|
28
|
-
virtual bool isPlaying() = 0;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
} // namespace RNSkia
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { SharedValue } from "react-native-reanimated";
|
|
2
|
-
import type { SkImage } from "../../skia/types";
|
|
3
|
-
type MaybeAnimated<T> = SharedValue<T> | T;
|
|
4
|
-
interface PlaybackOptions {
|
|
5
|
-
looping: MaybeAnimated<boolean>;
|
|
6
|
-
paused: MaybeAnimated<boolean>;
|
|
7
|
-
seek: MaybeAnimated<number | null>;
|
|
8
|
-
volume: MaybeAnimated<number>;
|
|
9
|
-
}
|
|
10
|
-
export declare const useVideo: (source: string | null, userOptions?: Partial<PlaybackOptions>) => {
|
|
11
|
-
currentFrame: SharedValue<SkImage | null>;
|
|
12
|
-
currentTime: SharedValue<number>;
|
|
13
|
-
duration: number;
|
|
14
|
-
framerate: number;
|
|
15
|
-
rotation: import("../../skia/types").VideoRotation;
|
|
16
|
-
size: {
|
|
17
|
-
width: number;
|
|
18
|
-
height: number;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
export {};
|