node-mac-recorder 2.18.3 → 2.18.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.
@@ -9,7 +9,8 @@
9
9
  "WebFetch(domain:stackoverflow.com)",
10
10
  "Bash(timeout:*)",
11
11
  "Bash(grep:*)",
12
- "Bash(./test-cleanup.sh:*)"
12
+ "Bash(./test-cleanup.sh:*)",
13
+ "Bash(FORCE_AVFOUNDATION=1 node test-avfoundation-dpr.js)"
13
14
  ],
14
15
  "deny": [],
15
16
  "ask": []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-mac-recorder",
3
- "version": "2.18.3",
3
+ "version": "2.18.4",
4
4
  "description": "Native macOS screen recording package for Node.js applications",
5
5
  "main": "index.js",
6
6
  "keywords": [
@@ -6,6 +6,83 @@
6
6
  #import <AppKit/AppKit.h>
7
7
  #include <string>
8
8
 
9
+ // Advanced display scaling detection (same algorithm as cursor_tracker.mm)
10
+ NSDictionary* getAdvancedDisplayScalingInfo(CGDirectDisplayID displayID) {
11
+ @try {
12
+ CGRect displayBounds = CGDisplayBounds(displayID);
13
+ CGSize logicalSize = displayBounds.size;
14
+
15
+ NSLog(@"🔍 Advanced scaling detection for display %u:", displayID);
16
+ NSLog(@" Logical bounds: %.0fx%.0f", logicalSize.width, logicalSize.height);
17
+
18
+ // CRITICAL FIX: Get REAL physical dimensions using multiple detection methods
19
+ // Method 1: CGDisplayCreateImage (may be scaled on some systems)
20
+ CGImageRef testImage = CGDisplayCreateImage(displayID);
21
+ CGSize imageSize = CGSizeMake(CGImageGetWidth(testImage), CGImageGetHeight(testImage));
22
+ CGImageRelease(testImage);
23
+
24
+ // Method 2: Native display mode detection for true physical resolution
25
+ CGSize actualPhysicalSize = imageSize;
26
+ CFArrayRef displayModes = CGDisplayCopyAllDisplayModes(displayID, NULL);
27
+ if (displayModes) {
28
+ CFIndex modeCount = CFArrayGetCount(displayModes);
29
+ CGSize maxResolution = CGSizeMake(0, 0);
30
+
31
+ // Find the highest resolution mode (native resolution)
32
+ for (CFIndex i = 0; i < modeCount; i++) {
33
+ CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(displayModes, i);
34
+ CGSize modeSize = CGSizeMake(CGDisplayModeGetWidth(mode), CGDisplayModeGetHeight(mode));
35
+
36
+ if (modeSize.width > maxResolution.width ||
37
+ (modeSize.width == maxResolution.width && modeSize.height > maxResolution.height)) {
38
+ maxResolution = modeSize;
39
+ }
40
+ }
41
+
42
+ // Use the max resolution if it's significantly higher than image size
43
+ if (maxResolution.width > imageSize.width * 1.5 || maxResolution.height > imageSize.height * 1.5) {
44
+ actualPhysicalSize = maxResolution;
45
+ NSLog(@" Using display mode detection: %.0fx%.0f (was %.0fx%.0f)",
46
+ maxResolution.width, maxResolution.height, imageSize.width, imageSize.height);
47
+ } else {
48
+ actualPhysicalSize = imageSize;
49
+ NSLog(@" Using image size detection: %.0fx%.0f", imageSize.width, imageSize.height);
50
+ }
51
+
52
+ CFRelease(displayModes);
53
+ } else {
54
+ actualPhysicalSize = imageSize;
55
+ }
56
+
57
+ CGSize reportedPhysicalSize = CGSizeMake(CGDisplayPixelsWide(displayID), CGDisplayPixelsHigh(displayID));
58
+
59
+ NSLog(@"🔍 ADVANCED scaling info:");
60
+ NSLog(@" Logical: %.0fx%.0f", logicalSize.width, logicalSize.height);
61
+ NSLog(@" Reported physical: %.0fx%.0f", reportedPhysicalSize.width, reportedPhysicalSize.height);
62
+ NSLog(@" ACTUAL physical: %.0fx%.0f", actualPhysicalSize.width, actualPhysicalSize.height);
63
+
64
+ CGFloat scaleX = actualPhysicalSize.width / logicalSize.width;
65
+ CGFloat scaleY = actualPhysicalSize.height / logicalSize.height;
66
+ CGFloat scaleFactor = MAX(scaleX, scaleY);
67
+
68
+ NSLog(@"🔍 ADVANCED scale factors: X=%.2f, Y=%.2f, Final=%.2f", scaleX, scaleY, scaleFactor);
69
+
70
+ return @{
71
+ @"displayID": @(displayID),
72
+ @"logicalSize": [NSValue valueWithSize:NSMakeSize(logicalSize.width, logicalSize.height)],
73
+ @"physicalSize": [NSValue valueWithSize:NSMakeSize(actualPhysicalSize.width, actualPhysicalSize.height)],
74
+ @"reportedPhysicalSize": [NSValue valueWithSize:NSMakeSize(reportedPhysicalSize.width, reportedPhysicalSize.height)],
75
+ @"scaleFactor": @(scaleFactor),
76
+ @"scaleX": @(scaleX),
77
+ @"scaleY": @(scaleY),
78
+ @"displayBounds": [NSValue valueWithRect:NSMakeRect(displayBounds.origin.x, displayBounds.origin.y, displayBounds.size.width, displayBounds.size.height)]
79
+ };
80
+ } @catch (NSException *exception) {
81
+ NSLog(@"❌ Advanced scaling detection failed: %@", exception);
82
+ return nil;
83
+ }
84
+ }
85
+
9
86
  static AVAssetWriter *g_avWriter = nil;
10
87
  static AVAssetWriterInput *g_avVideoInput = nil;
11
88
  static AVAssetWriterInputPixelBufferAdaptor *g_avPixelBufferAdaptor = nil;
@@ -53,23 +130,35 @@ extern "C" bool startAVFoundationRecording(const std::string& outputPath,
53
130
  return false;
54
131
  }
55
132
 
56
- // Get display dimensions with proper scaling for macOS 14/13 compatibility
57
- CGRect displayBounds = CGDisplayBounds(displayID);
58
-
59
- // Get both logical (bounds) and physical (pixels) dimensions
60
- CGSize logicalSize = displayBounds.size;
61
- CGSize physicalSize = CGSizeMake(CGDisplayPixelsWide(displayID), CGDisplayPixelsHigh(displayID));
62
-
63
- // Calculate scale factor
64
- CGFloat scaleX = physicalSize.width / logicalSize.width;
65
- CGFloat scaleY = physicalSize.height / logicalSize.height;
66
- CGFloat scaleFactor = MAX(scaleX, scaleY); // Use max to handle non-uniform scaling
67
-
68
- // CRITICAL FIX: Use actual captured image dimensions for pixel buffer
69
- // CGDisplayCreateImage returns physical pixels on Retina displays
70
- CGImageRef testImage = CGDisplayCreateImage(displayID);
71
- CGSize actualImageSize = CGSizeMake(CGImageGetWidth(testImage), CGImageGetHeight(testImage));
72
- CGImageRelease(testImage);
133
+ // CRITICAL FIX: Use advanced scaling detection (same as cursor_tracker.mm)
134
+ NSDictionary *advancedScalingInfo = getAdvancedDisplayScalingInfo(displayID);
135
+
136
+ CGSize logicalSize;
137
+ CGSize actualImageSize;
138
+ CGFloat scaleFactor;
139
+
140
+ if (advancedScalingInfo) {
141
+ // Use advanced detection results
142
+ NSSize logicalSizeValue = [[advancedScalingInfo objectForKey:@"logicalSize"] sizeValue];
143
+ NSSize physicalSizeValue = [[advancedScalingInfo objectForKey:@"physicalSize"] sizeValue];
144
+
145
+ logicalSize = CGSizeMake(logicalSizeValue.width, logicalSizeValue.height);
146
+ actualImageSize = CGSizeMake(physicalSizeValue.width, physicalSizeValue.height);
147
+ scaleFactor = [[advancedScalingInfo objectForKey:@"scaleFactor"] doubleValue];
148
+
149
+ NSLog(@"✅ Using ADVANCED scaling detection for AVFoundation");
150
+ } else {
151
+ // Fallback to old method
152
+ NSLog(@"⚠️ Advanced scaling detection failed, using fallback");
153
+ CGRect displayBounds = CGDisplayBounds(displayID);
154
+ logicalSize = displayBounds.size;
155
+
156
+ CGImageRef testImage = CGDisplayCreateImage(displayID);
157
+ actualImageSize = CGSizeMake(CGImageGetWidth(testImage), CGImageGetHeight(testImage));
158
+ CGImageRelease(testImage);
159
+
160
+ scaleFactor = MAX(actualImageSize.width / logicalSize.width, actualImageSize.height / logicalSize.height);
161
+ }
73
162
 
74
163
  // CRITICAL FIX: Use actual image dimensions to match what CGDisplayCreateImage returns
75
164
  // This prevents the "1/4 recording area" bug on Retina displays
@@ -85,18 +174,18 @@ extern "C" bool startAVFoundationRecording(const std::string& outputPath,
85
174
  recordingSize = actualImageSize;
86
175
  }
87
176
 
88
- NSLog(@"🎯 CRITICAL: Logical %.0fx%.0f → Actual image %.0fx%.0f",
177
+ NSLog(@"🎯 ADVANCED: Logical %.0fx%.0f → Actual image %.0fx%.0f",
89
178
  logicalSize.width, logicalSize.height, actualImageSize.width, actualImageSize.height);
90
-
179
+
91
180
  NSLog(@"🖥️ Display bounds (logical): %.0fx%.0f", logicalSize.width, logicalSize.height);
92
- NSLog(@"🖥️ Display pixels (physical): %.0fx%.0f", physicalSize.width, physicalSize.height);
93
-
181
+ NSLog(@"🖥️ Display actual physical: %.0fx%.0f", actualImageSize.width, actualImageSize.height);
182
+
94
183
  if (scaleFactor > 1.5) {
95
- NSLog(@"🔍 Scale factor: %.1fx → Retina display detected (macOS 14/13 scaling fix applied)", scaleFactor);
184
+ NSLog(@"🔍 ADVANCED Scale factor: %.2fx → Retina display detected", scaleFactor);
96
185
  } else if (scaleFactor > 1.1) {
97
- NSLog(@"🔍 Scale factor: %.1fx → Non-standard scaling detected", scaleFactor);
186
+ NSLog(@"🔍 ADVANCED Scale factor: %.2fx → Non-standard scaling detected", scaleFactor);
98
187
  } else {
99
- NSLog(@"🔍 Scale factor: %.1fx → Standard display", scaleFactor);
188
+ NSLog(@"🔍 ADVANCED Scale factor: %.2fx → Standard display", scaleFactor);
100
189
  }
101
190
 
102
191
  NSLog(@"🎯 Recording size: %.0fx%.0f (using actual physical dimensions for Retina fix)", recordingSize.width, recordingSize.height);