node-mac-recorder 2.13.2 → 2.13.3
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/package.json +1 -1
- package/src/mac_recorder.mm +3 -3
- package/src/screen_capture_kit.mm +50 -13
package/package.json
CHANGED
package/src/mac_recorder.mm
CHANGED
|
@@ -168,9 +168,9 @@ Napi::Value StartRecording(const Napi::CallbackInfo& info) {
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
@try {
|
|
171
|
-
//
|
|
172
|
-
NSLog(@"🔍
|
|
173
|
-
if (
|
|
171
|
+
// Phase 4: Pure ScreenCaptureKit with memory-optimized implementation
|
|
172
|
+
NSLog(@"🔍 Phase 4: Pure ScreenCaptureKit with Electron-safe memory optimization");
|
|
173
|
+
if (@available(macOS 12.3, *)) {
|
|
174
174
|
NSLog(@"✅ macOS 12.3+ detected - ScreenCaptureKit should be available");
|
|
175
175
|
if ([ScreenCaptureKitRecorder isScreenCaptureKitAvailable]) {
|
|
176
176
|
NSLog(@"✅ ScreenCaptureKit availability check passed");
|
|
@@ -26,11 +26,13 @@ static BOOL g_writerStarted = NO;
|
|
|
26
26
|
if (error) {
|
|
27
27
|
NSLog(@"❌ Stream stopped with error: %@", error);
|
|
28
28
|
} else {
|
|
29
|
-
NSLog(@"✅ ScreenCaptureKit stream stopped successfully");
|
|
29
|
+
NSLog(@"✅ ScreenCaptureKit stream stopped successfully in delegate");
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
// Finalize video writer
|
|
33
|
+
NSLog(@"🎬 Delegate calling finalizeVideoWriter...");
|
|
33
34
|
[ScreenCaptureKitRecorder finalizeVideoWriter];
|
|
35
|
+
NSLog(@"🎬 Delegate finished calling finalizeVideoWriter");
|
|
34
36
|
}
|
|
35
37
|
@end
|
|
36
38
|
|
|
@@ -55,18 +57,45 @@ static BOOL g_writerStarted = NO;
|
|
|
55
57
|
NSLog(@"✅ Electron-safe video writer started");
|
|
56
58
|
}
|
|
57
59
|
|
|
58
|
-
// Write sample buffer
|
|
60
|
+
// Write sample buffer with improved pixel buffer validation
|
|
59
61
|
if (g_writerStarted && g_assetWriterInput.isReadyForMoreMediaData) {
|
|
60
62
|
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
|
|
63
|
+
|
|
64
|
+
// Validate pixel buffer more thoroughly
|
|
61
65
|
if (pixelBuffer && g_pixelBufferAdaptor) {
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
// Check if pixel buffer has valid dimensions
|
|
67
|
+
size_t width = CVPixelBufferGetWidth(pixelBuffer);
|
|
68
|
+
size_t height = CVPixelBufferGetHeight(pixelBuffer);
|
|
64
69
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
if (width > 0 && height > 0) {
|
|
71
|
+
CMTime presentationTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
|
|
72
|
+
CMTime relativeTime = CMTimeSubtract(presentationTime, g_startTime);
|
|
73
|
+
|
|
74
|
+
BOOL success = [g_pixelBufferAdaptor appendPixelBuffer:pixelBuffer withPresentationTime:relativeTime];
|
|
75
|
+
if (success) {
|
|
76
|
+
g_currentTime = relativeTime;
|
|
77
|
+
static int validFrameCount = 0;
|
|
78
|
+
validFrameCount++;
|
|
79
|
+
if (validFrameCount % 30 == 0) {
|
|
80
|
+
NSLog(@"✅ Successfully wrote %d valid frames (%dx%d)", validFrameCount, (int)width, (int)height);
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
NSLog(@"⚠️ Failed to append valid pixel buffer (%dx%d) at time %f", (int)width, (int)height, CMTimeGetSeconds(relativeTime));
|
|
84
|
+
NSLog(@"Asset writer status: %ld, error: %@", (long)g_assetWriter.status, g_assetWriter.error);
|
|
85
|
+
}
|
|
68
86
|
} else {
|
|
69
|
-
|
|
87
|
+
static int invalidSizeCount = 0;
|
|
88
|
+
invalidSizeCount++;
|
|
89
|
+
if (invalidSizeCount % 50 == 0) {
|
|
90
|
+
NSLog(@"⚠️ Invalid pixel buffer dimensions: %dx%d (%d times)", (int)width, (int)height, invalidSizeCount);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
// Only log occasionally to avoid spam
|
|
95
|
+
static int nullBufferCount = 0;
|
|
96
|
+
nullBufferCount++;
|
|
97
|
+
if (nullBufferCount % 100 == 0) {
|
|
98
|
+
NSLog(@"⚠️ Null pixel buffer (%d times) - adaptor: %p", nullBufferCount, g_pixelBufferAdaptor);
|
|
70
99
|
}
|
|
71
100
|
}
|
|
72
101
|
}
|
|
@@ -153,7 +182,11 @@ static BOOL g_writerStarted = NO;
|
|
|
153
182
|
} else {
|
|
154
183
|
NSLog(@"✅ ScreenCaptureKit stream stopped in completion handler");
|
|
155
184
|
}
|
|
156
|
-
|
|
185
|
+
|
|
186
|
+
// Finalize video since delegate might not be called
|
|
187
|
+
NSLog(@"🎬 Completion handler calling finalizeVideoWriter...");
|
|
188
|
+
[ScreenCaptureKitRecorder finalizeVideoWriter];
|
|
189
|
+
NSLog(@"🎬 Completion handler finished calling finalizeVideoWriter");
|
|
157
190
|
}];
|
|
158
191
|
}
|
|
159
192
|
|
|
@@ -210,25 +243,29 @@ static BOOL g_writerStarted = NO;
|
|
|
210
243
|
}
|
|
211
244
|
|
|
212
245
|
+ (void)finalizeVideoWriter {
|
|
213
|
-
NSLog(@"🎬 Finalizing
|
|
246
|
+
NSLog(@"🎬 Finalizing video writer - writer: %p, started: %d", g_assetWriter, g_writerStarted);
|
|
214
247
|
|
|
215
248
|
if (!g_assetWriter || !g_writerStarted) {
|
|
216
|
-
NSLog(@"⚠️ Video writer not started,
|
|
249
|
+
NSLog(@"⚠️ Video writer not started properly - writer: %p, started: %d", g_assetWriter, g_writerStarted);
|
|
217
250
|
[ScreenCaptureKitRecorder cleanupVideoWriter];
|
|
218
251
|
return;
|
|
219
252
|
}
|
|
220
253
|
|
|
254
|
+
NSLog(@"🎬 Marking input as finished and finalizing...");
|
|
221
255
|
[g_assetWriterInput markAsFinished];
|
|
222
256
|
|
|
223
257
|
[g_assetWriter finishWritingWithCompletionHandler:^{
|
|
258
|
+
NSLog(@"🎬 Finalization completion handler called");
|
|
224
259
|
if (g_assetWriter.status == AVAssetWriterStatusCompleted) {
|
|
225
|
-
NSLog(@"✅
|
|
260
|
+
NSLog(@"✅ Video finalization successful: %@", g_outputPath);
|
|
226
261
|
} else {
|
|
227
|
-
NSLog(@"❌ Video
|
|
262
|
+
NSLog(@"❌ Video finalization failed - status: %ld, error: %@", (long)g_assetWriter.status, g_assetWriter.error);
|
|
228
263
|
}
|
|
229
264
|
|
|
230
265
|
[ScreenCaptureKitRecorder cleanupVideoWriter];
|
|
231
266
|
}];
|
|
267
|
+
|
|
268
|
+
NSLog(@"🎬 Finalization request submitted, waiting for completion...");
|
|
232
269
|
}
|
|
233
270
|
|
|
234
271
|
+ (void)cleanupVideoWriter {
|