react-native-suuqencode 0.1.3 → 0.1.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 (2) hide show
  1. package/ios/Suuqencode.mm +16 -2
  2. package/package.json +1 -1
package/ios/Suuqencode.mm CHANGED
@@ -29,11 +29,19 @@ RCT_EXPORT_METHOD(startEncode) {
29
29
  void *buf = [DMABuf buf];
30
30
  int width = [DMABuf width];
31
31
  int height = [DMABuf height];
32
+ int bytesPerRow = [DMABuf bytesPerRow];
32
33
 
33
34
  if (!buf) {
34
35
  return;
35
36
  }
36
37
 
38
+ size_t bufferSize = bytesPerRow * height;
39
+ void *bufferCopy = malloc(bufferSize);
40
+ if (!bufferCopy) {
41
+ return;
42
+ }
43
+ memcpy(bufferCopy, buf, bufferSize);
44
+
37
45
  dispatch_async(self.encodeQueue, ^{
38
46
  if (!self.compressionSession) {
39
47
  [self setupCompressionSessionWithWidth:width height:height];
@@ -41,11 +49,13 @@ RCT_EXPORT_METHOD(startEncode) {
41
49
 
42
50
  CVPixelBufferRef pixelBuffer = NULL;
43
51
  CVReturn status = CVPixelBufferCreateWithBytes(
44
- kCFAllocatorDefault, width, height, kCVPixelFormatType_32BGRA, buf,
45
- width * 4, NULL, NULL, NULL, &pixelBuffer);
52
+ kCFAllocatorDefault, width, height, kCVPixelFormatType_32BGRA,
53
+ bufferCopy, bytesPerRow, releasePixelBufferCallback, NULL, NULL,
54
+ &pixelBuffer);
46
55
 
47
56
  if (status != kCVReturnSuccess) {
48
57
  NSLog(@"Failed to create CVPixelBuffer");
58
+ free(bufferCopy);
49
59
  return;
50
60
  }
51
61
 
@@ -80,6 +90,10 @@ RCT_EXPORT_METHOD(startEncode) {
80
90
  VTCompressionSessionPrepareToEncodeFrames(_compressionSession);
81
91
  }
82
92
 
93
+ void releasePixelBufferCallback(void *releaseRefCon, const void *baseAddress) {
94
+ free((void *)baseAddress);
95
+ }
96
+
83
97
  void compressionOutputCallback(void *outputCallbackRefCon,
84
98
  void *sourceFrameRefCon, OSStatus status,
85
99
  VTEncodeInfoFlags infoFlags,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-suuqencode",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "h264 hardware encode support for iOS, developed by Suuqe Llc.",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",