react-native-suuqencode 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Suuqe Llc.
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # react-native-suuqencode
2
+
3
+ h264 hardware encode support for iOS, developed by Suuqe Llc.
4
+
5
+ ## Installation
6
+
7
+
8
+ ```sh
9
+ npm install react-native-suuqencode
10
+ ```
11
+
12
+
13
+ ## Usage
14
+
15
+
16
+ ```js
17
+ import { multiply } from 'react-native-suuqencode';
18
+
19
+ // ...
20
+
21
+ const result = multiply(3, 7);
22
+ ```
23
+
24
+
25
+ ## Contributing
26
+
27
+ - [Development workflow](CONTRIBUTING.md#development-workflow)
28
+ - [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
29
+ - [Code of conduct](CODE_OF_CONDUCT.md)
30
+
31
+ ## License
32
+
33
+ MIT
34
+
35
+ ---
36
+
37
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -0,0 +1,22 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "Suuqencode"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => min_ios_version_supported }
14
+ s.source = { :git => "https://github.com/Negawo11/react-native-suuqencode.git", :tag => "#{s.version}" }
15
+
16
+ s.source_files = "ios/**/*.{h,m,mm,cpp}"
17
+ s.private_header_files = "ios/**/*.h"
18
+ s.frameworks = "VideoToolbox", "CoreMedia", "CoreFoundation"
19
+
20
+
21
+ install_modules_dependencies(s)
22
+ end
@@ -0,0 +1,7 @@
1
+ #import <React/RCTEventEmitter.h>
2
+ #import <AVFoundation/AVFoundation.h>
3
+ #import <VideoToolbox/VideoToolbox.h>
4
+
5
+ @interface Suuqencode : RCTEventEmitter
6
+
7
+ @end
@@ -0,0 +1,124 @@
1
+ #import "Suuqencode.h"
2
+
3
+ @interface Suuqencode()
4
+
5
+ @property (nonatomic) VTCompressionSessionRef compressionSession;
6
+ @property (nonatomic) dispatch_queue_t encodeQueue;
7
+ @property (nonatomic) int frameCount;
8
+
9
+ @end
10
+
11
+ @implementation Suuqencode
12
+
13
+ RCT_EXPORT_MODULE()
14
+
15
+ - (instancetype)init
16
+ {
17
+ self = [super init];
18
+ if (self) {
19
+ _encodeQueue = dispatch_queue_create("com.suuqencode.encodequeue", DISPATCH_QUEUE_SERIAL);
20
+ }
21
+ return self;
22
+ }
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
+ }
36
+
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");
41
+ return;
42
+ }
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
+ });
55
+ }
56
+
57
+ - (void)setupCompressionSessionWithWidth:(int)width height:(int)height {
58
+ VTCompressionSessionCreate(NULL, width, height, kCMVideoCodecType_H264, NULL, NULL, NULL, compressionOutputCallback, (__bridge void *)(self), &_compressionSession);
59
+
60
+ VTSessionSetProperty(_compressionSession, kVTCompressionPropertyKey_RealTime, kCFBooleanTrue);
61
+ VTSessionSetProperty(_compressionSession, kVTCompressionPropertyKey_ProfileLevel, kVTProfileLevel_H264_Baseline_AutoLevel);
62
+ VTSessionSetProperty(_compressionSession, kVTCompressionPropertyKey_AverageBitRate, (__bridge CFTypeRef)@(width * height * 10));
63
+ VTSessionSetProperty(_compressionSession, kVTCompressionPropertyKey_MaxKeyFrameInterval, (__bridge CFTypeRef)@(20));
64
+
65
+ VTCompressionSessionPrepareToEncodeFrames(_compressionSession);
66
+ }
67
+
68
+ void compressionOutputCallback(void *outputCallbackRefCon, void *sourceFrameRefCon, OSStatus status, VTEncodeInfoFlags infoFlags, CMSampleBufferRef sampleBuffer) {
69
+ if (status != noErr) {
70
+ NSLog(@"Error encoding frame: %d", (int)status);
71
+ return;
72
+ }
73
+
74
+ if (!CMSampleBufferDataIsReady(sampleBuffer)) {
75
+ return;
76
+ }
77
+
78
+ Suuqencode *encoder = (__bridge Suuqencode *)outputCallbackRefCon;
79
+
80
+ bool isKeyFrame = !CFDictionaryContainsKey( (CFDictionaryRef)CFArrayGetValueAtIndex(CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, true), 0), (const void *)kCMSampleAttachmentKey_NotSync);
81
+
82
+ if (isKeyFrame)
83
+ {
84
+ CMFormatDescriptionRef format = CMSampleBufferGetFormatDescription(sampleBuffer);
85
+ const uint8_t *sparameterSet;
86
+ size_t sparameterSetSize, sparameterSetCount;
87
+ CMVideoFormatDescriptionGetH264ParameterSetAtIndex(format, 0, &sparameterSet, &sparameterSetSize, &sparameterSetCount, 0 );
88
+
89
+ const uint8_t *pparameterSet;
90
+ size_t pparameterSetSize, pparameterSetCount;
91
+ CMVideoFormatDescriptionGetH264ParameterSetAtIndex(format, 1, &pparameterSet, &pparameterSetSize, &pparameterSetCount, 0 );
92
+
93
+ NSData *sps = [NSData dataWithBytes:sparameterSet length:sparameterSetSize];
94
+ NSData *pps = [NSData dataWithBytes:pparameterSet length:pparameterSetSize];
95
+
96
+ [encoder sendEncodedData:sps];
97
+ [encoder sendEncodedData:pps];
98
+ }
99
+
100
+ CMBlockBufferRef dataBuffer = CMSampleBufferGetDataBuffer(sampleBuffer);
101
+ size_t length, totalLength;
102
+ char *dataPointer;
103
+ CMBlockBufferGetDataPointer(dataBuffer, 0, &length, &totalLength, &dataPointer);
104
+
105
+ NSData *naluData = [NSData dataWithBytes:dataPointer length:length];
106
+ [encoder sendEncodedData:naluData];
107
+ }
108
+
109
+ - (void)sendEncodedData:(NSData *)data {
110
+ NSString *base64Encoded = [data base64EncodedStringWithOptions:0];
111
+ [self sendEventWithName:@"onEncodedData" body:base64Encoded];
112
+ }
113
+
114
+ - (NSArray<NSString *> *)supportedEvents
115
+ {
116
+ return @[@"onEncodedData"];
117
+ }
118
+
119
+ + (BOOL)requiresMainQueueSetup
120
+ {
121
+ return NO;
122
+ }
123
+
124
+ @end
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ import { TurboModuleRegistry } from 'react-native';
4
+ export default TurboModuleRegistry.getEnforcing('Suuqencode');
5
+ //# sourceMappingURL=NativeSuuqencode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeSuuqencode.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAA0B,cAAc;AAQpE,eAAeA,mBAAmB,CAACC,YAAY,CAAO,YAAY,CAAC","ignoreList":[]}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ import { NativeModules, NativeEventEmitter } from 'react-native';
4
+ const {
5
+ Suuqencode
6
+ } = NativeModules;
7
+ const eventEmitter = new NativeEventEmitter(Suuqencode);
8
+ export function encode(base64Bitmap, width, height) {
9
+ Suuqencode.encode(base64Bitmap, width, height);
10
+ }
11
+ export function addEncodedDataListener(callback) {
12
+ const subscription = eventEmitter.addListener('onEncodedData', data => {
13
+ callback(data);
14
+ });
15
+ return () => {
16
+ subscription.remove();
17
+ };
18
+ }
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeModules","NativeEventEmitter","Suuqencode","eventEmitter","encode","base64Bitmap","width","height","addEncodedDataListener","callback","subscription","addListener","data","remove"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,kBAAkB,QAAQ,cAAc;AAEhE,MAAM;EAAEC;AAAW,CAAC,GAAGF,aAAa;AAEpC,MAAMG,YAAY,GAAG,IAAIF,kBAAkB,CAACC,UAAU,CAAC;AAEvD,OAAO,SAASE,MAAMA,CACpBC,YAAoB,EACpBC,KAAa,EACbC,MAAc,EACR;EACNL,UAAU,CAACE,MAAM,CAACC,YAAY,EAAEC,KAAK,EAAEC,MAAM,CAAC;AAChD;AAEA,OAAO,SAASC,sBAAsBA,CACpCC,QAAgC,EACpB;EACZ,MAAMC,YAAY,GAAGP,YAAY,CAACQ,WAAW,CAC3C,eAAe,EACdC,IAAS,IAAK;IACbH,QAAQ,CAACG,IAAc,CAAC;EAC1B,CACF,CAAC;EACD,OAAO,MAAM;IACXF,YAAY,CAACG,MAAM,CAAC,CAAC;EACvB,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,9 @@
1
+ import { type TurboModule } from 'react-native';
2
+ export interface Spec extends TurboModule {
3
+ encode(base64Bitmap: string, width: number, height: number): void;
4
+ addListener(eventName: string): void;
5
+ removeListeners(count: number): void;
6
+ }
7
+ declare const _default: Spec;
8
+ export default _default;
9
+ //# sourceMappingURL=NativeSuuqencode.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,3 @@
1
+ export declare function encode(base64Bitmap: string, width: number, height: number): void;
2
+ export declare function addEncodedDataListener(callback: (data: string) => void): () => void;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAMA,wBAAgB,MAAM,CACpB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,IAAI,CAEN;AAED,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAC/B,MAAM,IAAI,CAUZ"}
package/package.json ADDED
@@ -0,0 +1,158 @@
1
+ {
2
+ "name": "react-native-suuqencode",
3
+ "version": "0.1.0",
4
+ "description": "h264 hardware encode support for iOS, developed by Suuqe Llc.",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.tsx",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "ios",
19
+ "cpp",
20
+ "*.podspec",
21
+ "react-native.config.js",
22
+ "!ios/build",
23
+ "!**/__tests__",
24
+ "!**/__fixtures__",
25
+ "!**/__mocks__",
26
+ "!**/.*"
27
+ ],
28
+ "scripts": {
29
+ "example": "npm -w react-native-suuqencode-example",
30
+ "test": "jest",
31
+ "typecheck": "tsc",
32
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
33
+ "clean": "del-cli example/ios/build lib",
34
+ "prepare": "bob build",
35
+ "release": "release-it --only-version"
36
+ },
37
+ "keywords": [
38
+ "react-native",
39
+ "ios"
40
+ ],
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/Negawo11/react-native-suuqencode.git"
44
+ },
45
+ "author": "Suuqe Llc. <negawoansha@gmail.com> (https://suuqe.com)",
46
+ "license": "MIT",
47
+ "bugs": {
48
+ "url": "https://github.com/Negawo11/react-native-suuqencode/issues"
49
+ },
50
+ "homepage": "https://github.com/Negawo11/react-native-suuqencode#readme",
51
+ "publishConfig": {
52
+ "registry": "https://registry.npmjs.org/"
53
+ },
54
+ "devDependencies": {
55
+ "@commitlint/config-conventional": "^19.8.1",
56
+ "@eslint/compat": "^1.3.2",
57
+ "@eslint/eslintrc": "^3.3.1",
58
+ "@eslint/js": "^9.35.0",
59
+ "@evilmartians/lefthook": "^1.12.3",
60
+ "@react-native-community/cli": "20.0.1",
61
+ "@react-native/babel-preset": "0.81.1",
62
+ "@react-native/eslint-config": "^0.81.1",
63
+ "@release-it/conventional-changelog": "^10.0.1",
64
+ "@types/jest": "^29.5.14",
65
+ "@types/react": "^19.1.0",
66
+ "@typescript-eslint/eslint-plugin": "^8.46.3",
67
+ "commitlint": "^19.8.1",
68
+ "del-cli": "^6.0.0",
69
+ "eslint": "^9.35.0",
70
+ "eslint-config-prettier": "^10.1.8",
71
+ "eslint-plugin-ft-flow": "^3.0.11",
72
+ "eslint-plugin-jest": "^29.0.1",
73
+ "eslint-plugin-prettier": "^5.5.4",
74
+ "eslint-plugin-react-native": "^5.0.0",
75
+ "jest": "^29.7.0",
76
+ "prettier": "^3.6.2",
77
+ "react": "19.1.0",
78
+ "react-native": "0.81.1",
79
+ "react-native-builder-bob": "^0.40.14",
80
+ "release-it": "^19.0.4",
81
+ "turbo": "^2.5.6",
82
+ "typescript": "^5.9.2"
83
+ },
84
+ "peerDependencies": {
85
+ "react": "*",
86
+ "react-native": "*"
87
+ },
88
+ "workspaces": [
89
+ "example"
90
+ ],
91
+ "packageManager": "yarn@3.6.1",
92
+ "jest": {
93
+ "preset": "react-native",
94
+ "modulePathIgnorePatterns": [
95
+ "<rootDir>/example/node_modules",
96
+ "<rootDir>/lib/"
97
+ ]
98
+ },
99
+ "commitlint": {
100
+ "extends": [
101
+ "@commitlint/config-conventional"
102
+ ]
103
+ },
104
+ "release-it": {
105
+ "git": {
106
+ "commitMessage": "chore: release ${version}",
107
+ "tagName": "v${version}"
108
+ },
109
+ "npm": {
110
+ "publish": true
111
+ },
112
+ "github": {
113
+ "release": true
114
+ },
115
+ "plugins": {
116
+ "@release-it/conventional-changelog": {
117
+ "preset": {
118
+ "name": "angular"
119
+ }
120
+ }
121
+ }
122
+ },
123
+ "prettier": {
124
+ "quoteProps": "consistent",
125
+ "singleQuote": true,
126
+ "tabWidth": 2,
127
+ "trailingComma": "es5",
128
+ "useTabs": false
129
+ },
130
+ "react-native-builder-bob": {
131
+ "source": "src",
132
+ "output": "lib",
133
+ "targets": [
134
+ [
135
+ "module",
136
+ {
137
+ "esm": true
138
+ }
139
+ ],
140
+ [
141
+ "typescript",
142
+ {
143
+ "project": "tsconfig.build.json"
144
+ }
145
+ ]
146
+ ]
147
+ },
148
+ "codegenConfig": {
149
+ "name": "SuuqencodeSpec",
150
+ "type": "modules",
151
+ "jsSrcsDir": "src"
152
+ },
153
+ "create-react-native-library": {
154
+ "languages": "kotlin-objc",
155
+ "type": "turbo-module",
156
+ "version": "0.54.8"
157
+ }
158
+ }
@@ -0,0 +1,9 @@
1
+ import { TurboModuleRegistry, type TurboModule } from 'react-native';
2
+
3
+ export interface Spec extends TurboModule {
4
+ encode(base64Bitmap: string, width: number, height: number): void;
5
+ addListener(eventName: string): void;
6
+ removeListeners(count: number): void;
7
+ }
8
+
9
+ export default TurboModuleRegistry.getEnforcing<Spec>('Suuqencode');
package/src/index.tsx ADDED
@@ -0,0 +1,27 @@
1
+ import { NativeModules, NativeEventEmitter } from 'react-native';
2
+
3
+ const { Suuqencode } = NativeModules;
4
+
5
+ const eventEmitter = new NativeEventEmitter(Suuqencode);
6
+
7
+ export function encode(
8
+ base64Bitmap: string,
9
+ width: number,
10
+ height: number
11
+ ): void {
12
+ Suuqencode.encode(base64Bitmap, width, height);
13
+ }
14
+
15
+ export function addEncodedDataListener(
16
+ callback: (data: string) => void
17
+ ): () => void {
18
+ const subscription = eventEmitter.addListener(
19
+ 'onEncodedData',
20
+ (data: any) => {
21
+ callback(data as string);
22
+ }
23
+ );
24
+ return () => {
25
+ subscription.remove();
26
+ };
27
+ }