react-native-suuqencode 0.1.4 → 0.1.6

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 +30 -6
  2. package/package.json +1 -1
package/ios/Suuqencode.mm CHANGED
@@ -108,6 +108,8 @@ void compressionOutputCallback(void *outputCallbackRefCon,
108
108
  }
109
109
 
110
110
  Suuqencode *encoder = (__bridge Suuqencode *)outputCallbackRefCon;
111
+ const uint8_t startCode[] = {0x00, 0x00, 0x00, 0x01};
112
+ size_t startCodeSize = sizeof(startCode);
111
113
 
112
114
  bool isKeyFrame = !CFDictionaryContainsKey(
113
115
  (CFDictionaryRef)CFArrayGetValueAtIndex(
@@ -127,11 +129,15 @@ void compressionOutputCallback(void *outputCallbackRefCon,
127
129
  CMVideoFormatDescriptionGetH264ParameterSetAtIndex(
128
130
  format, 1, &pparameterSet, &pparameterSetSize, &pparameterSetCount, 0);
129
131
 
130
- NSData *sps = [NSData dataWithBytes:sparameterSet length:sparameterSetSize];
131
- NSData *pps = [NSData dataWithBytes:pparameterSet length:pparameterSetSize];
132
+ NSMutableData *spsData = [NSMutableData dataWithBytes:startCode
133
+ length:startCodeSize];
134
+ [spsData appendBytes:sparameterSet length:sparameterSetSize];
135
+ [encoder sendEncodedData:spsData];
132
136
 
133
- [encoder sendEncodedData:sps];
134
- [encoder sendEncodedData:pps];
137
+ NSMutableData *ppsData = [NSMutableData dataWithBytes:startCode
138
+ length:startCodeSize];
139
+ [ppsData appendBytes:pparameterSet length:pparameterSetSize];
140
+ [encoder sendEncodedData:ppsData];
135
141
  }
136
142
 
137
143
  CMBlockBufferRef dataBuffer = CMSampleBufferGetDataBuffer(sampleBuffer);
@@ -140,8 +146,26 @@ void compressionOutputCallback(void *outputCallbackRefCon,
140
146
  CMBlockBufferGetDataPointer(dataBuffer, 0, &length, &totalLength,
141
147
  &dataPointer);
142
148
 
143
- NSData *naluData = [NSData dataWithBytes:dataPointer length:length];
144
- [encoder sendEncodedData:naluData];
149
+ // Parse AVCC NAL units and convert to Annex B
150
+ size_t bufferOffset = 0;
151
+ static const int AVCCHeaderLength = 4;
152
+
153
+ while (bufferOffset < totalLength - AVCCHeaderLength) {
154
+ uint32_t NALUnitLength = 0;
155
+ memcpy(&NALUnitLength, dataPointer + bufferOffset, AVCCHeaderLength);
156
+
157
+ // Convert big-endian length to host endianness
158
+ NALUnitLength = CFSwapInt32BigToHost(NALUnitLength);
159
+
160
+ NSMutableData *naluData = [NSMutableData dataWithBytes:startCode
161
+ length:startCodeSize];
162
+ [naluData appendBytes:(dataPointer + bufferOffset + AVCCHeaderLength)
163
+ length:NALUnitLength];
164
+
165
+ [encoder sendEncodedData:naluData];
166
+
167
+ bufferOffset += AVCCHeaderLength + NALUnitLength;
168
+ }
145
169
  }
146
170
 
147
171
  - (void)sendEncodedData:(NSData *)data {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-suuqencode",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
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",