react-native-suuqencode 0.1.0 → 0.1.1

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.
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
16
16
  s.source_files = "ios/**/*.{h,m,mm,cpp}"
17
17
  s.private_header_files = "ios/**/*.h"
18
18
  s.frameworks = "VideoToolbox", "CoreMedia", "CoreFoundation"
19
-
19
+ s.dependency "SuuqeDMABuf"
20
20
 
21
21
  install_modules_dependencies(s)
22
22
  end
package/ios/Suuqencode.mm CHANGED
@@ -21,37 +21,39 @@ RCT_EXPORT_MODULE()
21
21
  return self;
22
22
  }
23
23
 
24
- RCT_EXPORT_METHOD(encode:(NSString *)base64Bitmap width:(int)width height:(int)height)
25
- {
26
- dispatch_async(_encodeQueue, ^{
27
- if (!self.compressionSession) {
28
- [self setupCompressionSessionWithWidth:width height:height];
29
- }
30
-
31
- NSData *bitmapData = [[NSData alloc] initWithBase64EncodedString:base64Bitmap options:0];
32
- if (!bitmapData) {
33
- NSLog(@"Invalid base64 bitmap string");
34
- return;
35
- }
24
+ #import <SuuqeDMABuf/DMABuf.h>
36
25
 
37
- CVPixelBufferRef pixelBuffer = NULL;
38
- CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, width, height, kCVPixelFormatType_32ARGB, nil, &pixelBuffer);
39
- if (status != kCVReturnSuccess) {
40
- NSLog(@"Failed to create CVPixelBuffer");
26
+ RCT_EXPORT_METHOD(startEncode)
27
+ {
28
+ [DMABuf setFrameChangeCallback:^{
29
+ void *buf = [DMABuf buf];
30
+ int width = [DMABuf width];
31
+ int height = [DMABuf height];
32
+
33
+ if (!buf) {
41
34
  return;
42
35
  }
43
-
44
- CVPixelBufferLockBaseAddress(pixelBuffer, 0);
45
- void *pixelData = CVPixelBufferGetBaseAddress(pixelBuffer);
46
- memcpy(pixelData, [bitmapData bytes], [bitmapData length]);
47
- CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
48
-
49
- CMTime presentationTimeStamp = CMTimeMake(self.frameCount++, 30);
50
- VTEncodeInfoFlags flags;
51
-
52
- VTCompressionSessionEncodeFrame(self.compressionSession, pixelBuffer, presentationTimeStamp, kCMTimeInvalid, NULL, NULL, &flags);
53
- CVPixelBufferRelease(pixelBuffer);
54
- });
36
+
37
+ dispatch_async(self.encodeQueue, ^{
38
+ if (!self.compressionSession) {
39
+ [self setupCompressionSessionWithWidth:width height:height];
40
+ }
41
+
42
+ CVPixelBufferRef pixelBuffer = NULL;
43
+ CVReturn status = CVPixelBufferCreateWithBytes(kCFAllocatorDefault, width, height, kCVPixelFormatType_32BGRA, buf, width * 4, NULL, NULL, NULL, &pixelBuffer);
44
+
45
+ if (status != kCVReturnSuccess) {
46
+ NSLog(@"Failed to create CVPixelBuffer");
47
+ return;
48
+ }
49
+
50
+ CMTime presentationTimeStamp = CMTimeMake(self.frameCount++, 30);
51
+ VTEncodeInfoFlags flags;
52
+
53
+ VTCompressionSessionEncodeFrame(self.compressionSession, pixelBuffer, presentationTimeStamp, kCMTimeInvalid, NULL, NULL, &flags);
54
+ CVPixelBufferRelease(pixelBuffer);
55
+ });
56
+ }];
55
57
  }
56
58
 
57
59
  - (void)setupCompressionSessionWithWidth:(int)width height:(int)height {
@@ -1,6 +1,6 @@
1
1
  import { type TurboModule } from 'react-native';
2
2
  export interface Spec extends TurboModule {
3
- encode(base64Bitmap: string, width: number, height: number): void;
3
+ startEncode(): void;
4
4
  addListener(eventName: string): void;
5
5
  removeListeners(count: number): void;
6
6
  }
@@ -1 +1 @@
1
- {"version":3,"file":"NativeSuuqencode.d.ts","sourceRoot":"","sources":["../../../src/NativeSuuqencode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,MAAM,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAClE,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC;;AAED,wBAAoE"}
1
+ {"version":3,"file":"NativeSuuqencode.d.ts","sourceRoot":"","sources":["../../../src/NativeSuuqencode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,WAAW,IAAI,IAAI,CAAC;IACpB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC;;AAED,wBAAoE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-suuqencode",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
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",
@@ -1,7 +1,7 @@
1
1
  import { TurboModuleRegistry, type TurboModule } from 'react-native';
2
2
 
3
3
  export interface Spec extends TurboModule {
4
- encode(base64Bitmap: string, width: number, height: number): void;
4
+ startEncode(): void;
5
5
  addListener(eventName: string): void;
6
6
  removeListeners(count: number): void;
7
7
  }