@byteplus/react-native-live-push 1.1.3-rc.3 → 1.1.4-rc.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.
Files changed (123) hide show
  1. package/android/src/main/java/com/volcengine/velive/rn/push/VeLivePushModule.java +2 -13
  2. package/android/src/main/java/com/volcengine/velive/rn/push/VeLivePushPackage.java +13 -16
  3. package/android/src/main/java/com/volcengine/velive/rn/push/VeLivePushView.java +0 -16
  4. package/android/src/main/java/com/volcengine/velive/rn/push/VeLivePushViewManager.java +2 -7
  5. package/lib/commonjs/index.js +2126 -2925
  6. package/lib/module/index.js +2128 -2922
  7. package/lib/typescript/codegen/android/api.d.ts +121 -1
  8. package/lib/typescript/codegen/ios/api.d.ts +28 -1
  9. package/lib/typescript/codegen/pack/api.d.ts +133 -1
  10. package/lib/typescript/core/api.d.ts +2 -17
  11. package/lib/typescript/core/keytype.d.ts +0 -15
  12. package/lib/typescript/index.d.ts +0 -1
  13. package/package.json +1 -1
  14. package/android/src/main/java/com/volcengine/velive/rn/push/mixer/MixerManager.java +0 -397
  15. package/android/src/main/java/com/volcengine/velive/rn/push/mixer/MixerView.java +0 -423
  16. package/android/src/main/java/com/volcengine/velive/rn/push/mixer/MixerViewManager.java +0 -79
  17. package/android/src/main/java/com/volcengine/velive/rn/push/mixer/TextureMgr.java +0 -168
  18. package/android/src/main/java/com/volcengine/velive/rn/push/mixer/YuvHelper.java +0 -165
  19. package/ios/VeLiveMixerHelper.h +0 -44
  20. package/ios/VeLiveMixerHelper.m +0 -591
  21. package/ios/VeLiveMixerView.h +0 -69
  22. package/ios/VeLiveMixerView.m +0 -592
  23. package/ios/VeLiveMixerViewManager.m +0 -92
  24. package/lib/commonjs/typescript/android/index.d.ts +0 -47
  25. package/lib/commonjs/typescript/codegen/android/api.d.ts +0 -1527
  26. package/lib/commonjs/typescript/codegen/android/callback.d.ts +0 -91
  27. package/lib/commonjs/typescript/codegen/android/errorcode.d.ts +0 -26
  28. package/lib/commonjs/typescript/codegen/android/index.d.ts +0 -5
  29. package/lib/commonjs/typescript/codegen/android/keytype.d.ts +0 -846
  30. package/lib/commonjs/typescript/codegen/android/types.d.ts +0 -33
  31. package/lib/commonjs/typescript/codegen/ios/api.d.ts +0 -222
  32. package/lib/commonjs/typescript/codegen/ios/callback.d.ts +0 -80
  33. package/lib/commonjs/typescript/codegen/ios/errorcode.d.ts +0 -54
  34. package/lib/commonjs/typescript/codegen/ios/external.d.ts +0 -1
  35. package/lib/commonjs/typescript/codegen/ios/index.d.ts +0 -6
  36. package/lib/commonjs/typescript/codegen/ios/keytype.d.ts +0 -460
  37. package/lib/commonjs/typescript/codegen/ios/types.d.ts +0 -46
  38. package/lib/commonjs/typescript/codegen/pack/api.d.ts +0 -1835
  39. package/lib/commonjs/typescript/codegen/pack/callback.d.ts +0 -400
  40. package/lib/commonjs/typescript/codegen/pack/errorcode.d.ts +0 -35
  41. package/lib/commonjs/typescript/codegen/pack/index.d.ts +0 -5
  42. package/lib/commonjs/typescript/codegen/pack/keytype.d.ts +0 -1392
  43. package/lib/commonjs/typescript/codegen/pack/types.d.ts +0 -68
  44. package/lib/commonjs/typescript/codegen/type-shim.d.ts +0 -6
  45. package/lib/commonjs/typescript/component.d.ts +0 -15
  46. package/lib/commonjs/typescript/core/api.d.ts +0 -17
  47. package/lib/commonjs/typescript/core/callback.d.ts +0 -2
  48. package/lib/commonjs/typescript/core/env.d.ts +0 -29
  49. package/lib/commonjs/typescript/core/errorcode.d.ts +0 -2
  50. package/lib/commonjs/typescript/core/index.d.ts +0 -6
  51. package/lib/commonjs/typescript/core/keytype.d.ts +0 -17
  52. package/lib/commonjs/typescript/core/mixer.d.ts +0 -26
  53. package/lib/commonjs/typescript/core/pusher.d.ts +0 -16
  54. package/lib/commonjs/typescript/index.d.ts +0 -3
  55. package/lib/commonjs/typescript/ios/extends.d.ts +0 -41
  56. package/lib/commonjs/typescript/platforms/android/extends.d.ts +0 -8
  57. package/lib/commonjs/typescript/platforms/android/helper.d.ts +0 -8
  58. package/lib/commonjs/typescript/platforms/android/mixer.d.ts +0 -8
  59. package/lib/commonjs/typescript/platforms/ios/extends.d.ts +0 -17
  60. package/lib/commonjs/typescript/platforms/ios/helper.d.ts +0 -8
  61. package/lib/commonjs/typescript/platforms/ios/mixer.d.ts +0 -9
  62. package/lib/commonjs/typescript/runtime.d.ts +0 -1
  63. package/lib/commonjs/typescript/view/MixView.d.ts +0 -52
  64. package/lib/commonjs/typescript/view/VeImageView.d.ts +0 -19
  65. package/lib/commonjs/typescript/view/VeTextView.d.ts +0 -7
  66. package/lib/commonjs/typescript/view/VeView.d.ts +0 -7
  67. package/lib/commonjs/typescript/view/VeWebView.d.ts +0 -7
  68. package/lib/commonjs/typescript/view/index.d.ts +0 -5
  69. package/lib/module/typescript/android/index.d.ts +0 -47
  70. package/lib/module/typescript/codegen/android/api.d.ts +0 -1527
  71. package/lib/module/typescript/codegen/android/callback.d.ts +0 -91
  72. package/lib/module/typescript/codegen/android/errorcode.d.ts +0 -26
  73. package/lib/module/typescript/codegen/android/index.d.ts +0 -5
  74. package/lib/module/typescript/codegen/android/keytype.d.ts +0 -846
  75. package/lib/module/typescript/codegen/android/types.d.ts +0 -33
  76. package/lib/module/typescript/codegen/ios/api.d.ts +0 -222
  77. package/lib/module/typescript/codegen/ios/callback.d.ts +0 -80
  78. package/lib/module/typescript/codegen/ios/errorcode.d.ts +0 -54
  79. package/lib/module/typescript/codegen/ios/external.d.ts +0 -1
  80. package/lib/module/typescript/codegen/ios/index.d.ts +0 -6
  81. package/lib/module/typescript/codegen/ios/keytype.d.ts +0 -460
  82. package/lib/module/typescript/codegen/ios/types.d.ts +0 -46
  83. package/lib/module/typescript/codegen/pack/api.d.ts +0 -1835
  84. package/lib/module/typescript/codegen/pack/callback.d.ts +0 -400
  85. package/lib/module/typescript/codegen/pack/errorcode.d.ts +0 -35
  86. package/lib/module/typescript/codegen/pack/index.d.ts +0 -5
  87. package/lib/module/typescript/codegen/pack/keytype.d.ts +0 -1392
  88. package/lib/module/typescript/codegen/pack/types.d.ts +0 -68
  89. package/lib/module/typescript/codegen/type-shim.d.ts +0 -6
  90. package/lib/module/typescript/component.d.ts +0 -15
  91. package/lib/module/typescript/core/api.d.ts +0 -17
  92. package/lib/module/typescript/core/callback.d.ts +0 -2
  93. package/lib/module/typescript/core/env.d.ts +0 -29
  94. package/lib/module/typescript/core/errorcode.d.ts +0 -2
  95. package/lib/module/typescript/core/index.d.ts +0 -6
  96. package/lib/module/typescript/core/keytype.d.ts +0 -17
  97. package/lib/module/typescript/core/mixer.d.ts +0 -26
  98. package/lib/module/typescript/core/pusher.d.ts +0 -16
  99. package/lib/module/typescript/index.d.ts +0 -3
  100. package/lib/module/typescript/ios/extends.d.ts +0 -41
  101. package/lib/module/typescript/platforms/android/extends.d.ts +0 -8
  102. package/lib/module/typescript/platforms/android/helper.d.ts +0 -8
  103. package/lib/module/typescript/platforms/android/mixer.d.ts +0 -8
  104. package/lib/module/typescript/platforms/ios/extends.d.ts +0 -17
  105. package/lib/module/typescript/platforms/ios/helper.d.ts +0 -8
  106. package/lib/module/typescript/platforms/ios/mixer.d.ts +0 -9
  107. package/lib/module/typescript/runtime.d.ts +0 -1
  108. package/lib/module/typescript/view/MixView.d.ts +0 -52
  109. package/lib/module/typescript/view/VeImageView.d.ts +0 -19
  110. package/lib/module/typescript/view/VeTextView.d.ts +0 -7
  111. package/lib/module/typescript/view/VeView.d.ts +0 -7
  112. package/lib/module/typescript/view/VeWebView.d.ts +0 -7
  113. package/lib/module/typescript/view/index.d.ts +0 -5
  114. package/lib/typescript/core/mixer.d.ts +0 -26
  115. package/lib/typescript/platforms/android/extends.d.ts +0 -8
  116. package/lib/typescript/platforms/android/mixer.d.ts +0 -8
  117. package/lib/typescript/platforms/ios/mixer.d.ts +0 -9
  118. package/lib/typescript/view/MixView.d.ts +0 -52
  119. package/lib/typescript/view/VeImageView.d.ts +0 -19
  120. package/lib/typescript/view/VeTextView.d.ts +0 -7
  121. package/lib/typescript/view/VeView.d.ts +0 -7
  122. package/lib/typescript/view/VeWebView.d.ts +0 -7
  123. package/lib/typescript/view/index.d.ts +0 -5
@@ -1,591 +0,0 @@
1
- //
2
- // VeLiveMixerHelper.m
3
- // react-native-live-push
4
- //
5
- // Created by ByteDance on 2024/12/09.
6
- //
7
-
8
- #import "VeLiveMixerHelper.h"
9
- #import <TTSDKLivePushRTS/TTSDKLivePushRTS.h>
10
- #import <UIKit/UIKit.h>
11
- #import <mach/mach.h>
12
- #import <mach/task_info.h>
13
- #include <objc/NSObjCRuntime.h>
14
-
15
- static NSString *TAG = @"VeLiveMixerHelper";
16
-
17
- #pragma mark - Forward Declaration
18
-
19
- @class VeLiveMixerBitmapCallback;
20
-
21
- #pragma mark - VeLiveMixerHelper Implementation
22
-
23
- @interface VeLiveMixerHelper ()
24
-
25
- @property(nonatomic, strong)
26
- NSMutableDictionary<NSString *, NSDictionary *> *mixedViewLayout;
27
- @property(nonatomic, strong)
28
- NSMutableDictionary<NSString *, NSNumber *> *viewIdToStreamId;
29
- @property(nonatomic, strong)
30
- NSMutableDictionary<NSString *, NSNumber *> *pendingCallbacks;
31
- @property(nonatomic, strong)
32
- NSMutableDictionary<NSString *, VeLiveMixerBitmapCallback *> *callbacks;
33
- @property(nonatomic, strong) NSTimer *memoryMonitorTimer;
34
-
35
- @end
36
-
37
- #pragma mark - VeLiveMixerBitmapCallback Declaration
38
-
39
- @interface VeLiveMixerBitmapCallback : NSObject <VeLiveBitmapCaptureCallback>
40
- @property(nonatomic, assign) int streamId;
41
- - (instancetype)initWithStreamId:(int)streamId;
42
- @end
43
-
44
- @implementation VeLiveMixerHelper
45
-
46
- // 对齐Android的static cachedMixedViews
47
- static NSMutableDictionary<NSString *, VeLiveMixerUIView *> *_cachedMixedViews =
48
- nil;
49
- static VeLiveMixerHelper *currentInstance = nil; // 强引用,防止被ARC释放
50
-
51
- + (NSMutableDictionary<NSString *, VeLiveMixerUIView *> *)cachedMixedViews {
52
- if (!_cachedMixedViews) {
53
- _cachedMixedViews = [[NSMutableDictionary alloc] init];
54
- }
55
- return _cachedMixedViews;
56
- }
57
-
58
- + (void)setCachedMixedViews:
59
- (NSMutableDictionary<NSString *, VeLiveMixerUIView *> *)cachedMixedViews {
60
- _cachedMixedViews = cachedMixedViews;
61
- }
62
-
63
- - (instancetype)init {
64
- self = [super init];
65
- if (self) {
66
- [self commonInit];
67
- }
68
- return self;
69
- }
70
-
71
- - (instancetype)initWithPusher:(VeLivePusher *)pusher {
72
- self = [super init];
73
- if (self) {
74
- _pusher = pusher;
75
- [self commonInit];
76
- [self startMemoryMonitoring];
77
- }
78
- return self;
79
- }
80
-
81
- - (void)commonInit {
82
- _mixedViewLayout = [[NSMutableDictionary alloc] init];
83
- _viewIdToStreamId = [[NSMutableDictionary alloc] init];
84
- _pendingCallbacks = [[NSMutableDictionary alloc] init];
85
- _callbacks = [[NSMutableDictionary alloc] init];
86
-
87
- currentInstance = self;
88
- }
89
-
90
- #pragma mark - Lazy Loading Properties
91
-
92
- - (NSMutableDictionary *)mixedViewLayout {
93
- if (!_mixedViewLayout) {
94
- _mixedViewLayout = [[NSMutableDictionary alloc] init];
95
- }
96
- return _mixedViewLayout;
97
- }
98
-
99
- - (NSMutableDictionary *)viewIdToStreamId {
100
- if (!_viewIdToStreamId) {
101
- _viewIdToStreamId = [[NSMutableDictionary alloc] init];
102
- }
103
- return _viewIdToStreamId;
104
- }
105
-
106
- - (NSMutableDictionary *)pendingCallbacks {
107
- if (!_pendingCallbacks) {
108
- _pendingCallbacks = [[NSMutableDictionary alloc] init];
109
- }
110
- return _pendingCallbacks;
111
- }
112
-
113
- - (NSMutableDictionary *)callbacks {
114
- if (!_callbacks) {
115
- _callbacks = [[NSMutableDictionary alloc] init];
116
- }
117
- return _callbacks;
118
- }
119
-
120
- #pragma mark - Public Methods
121
-
122
- - (void)setPusher:(VeLivePusher *)pusher {
123
- _pusher = pusher;
124
-
125
- if (currentInstance != self) {
126
- currentInstance = self;
127
- }
128
- }
129
-
130
- - (int)addView:(NSString *)viewId config:(NSDictionary *)viewInfo {
131
- @try {
132
- if (!self.pusher) {
133
- return -1;
134
- }
135
-
136
- VeLiveMixerUIView *view = [VeLiveMixerHelper cachedMixedViews][viewId];
137
- if (![view isKindOfClass:[VeLiveMixerUIView class]]) {
138
- // View not ready, store pending callback
139
- }
140
-
141
- NSNumber *existingStreamId = [self.viewIdToStreamId objectForKey:viewId];
142
- if (existingStreamId != nil) {
143
- return [existingStreamId intValue];
144
- }
145
-
146
- int videoStreamId = [[self.pusher getMixerManager] addVideoStream];
147
-
148
- NSDictionary *layout = @{
149
- @"x" : viewInfo[@"x"] ?: @(0),
150
- @"y" : viewInfo[@"y"] ?: @(0),
151
- @"width" : viewInfo[@"width"] ?: @(0),
152
- @"height" : viewInfo[@"height"] ?: @(0),
153
- @"zOrder" : viewInfo[@"zOrder"] ?: @(1),
154
- @"renderMode" : viewInfo[@"renderMode"] ?: @(0),
155
- @"streamId" : @(videoStreamId)
156
- };
157
-
158
- VeLiveStreamMixDescription *description =
159
- [[VeLiveStreamMixDescription alloc] init];
160
- VeLiveMixVideoLayout *videoLayout = [[VeLiveMixVideoLayout alloc] init];
161
- videoLayout.streamId = videoStreamId;
162
- videoLayout.x = [viewInfo[@"x"] floatValue];
163
- videoLayout.y = [viewInfo[@"y"] floatValue];
164
- videoLayout.width = [viewInfo[@"width"] floatValue];
165
- videoLayout.height = [viewInfo[@"height"] floatValue];
166
- videoLayout.zOrder = [viewInfo[@"zOrder"] intValue];
167
- videoLayout.renderMode = [viewInfo[@"renderMode"] intValue];
168
- description.mixVideoStreams = @[ videoLayout ];
169
- [self.pusher.getMixerManager updateStreamMixDescription:description];
170
-
171
- [self.mixedViewLayout setObject:layout forKey:viewId];
172
- [self.viewIdToStreamId setObject:@(videoStreamId) forKey:viewId];
173
-
174
- if ([view isKindOfClass:[VeLiveMixerUIView class]]) {
175
- [VeLiveMixerHelper setupCallbackForMixerView:view streamId:videoStreamId];
176
- } else {
177
- [self.pendingCallbacks setObject:@(videoStreamId) forKey:viewId];
178
- }
179
-
180
- return videoStreamId;
181
- } @catch (NSException *exception) {
182
- return -1;
183
- }
184
- }
185
-
186
- - (BOOL)updateView:(NSString *)viewId config:(NSDictionary *)viewInfo {
187
- @try {
188
- NSDictionary *layout = [self.mixedViewLayout objectForKey:viewId];
189
- if (!layout) {
190
- return NO;
191
- }
192
-
193
- NSNumber *streamIdNumber = [self.viewIdToStreamId objectForKey:viewId];
194
- int videoStreamId = [streamIdNumber intValue];
195
-
196
- NSMutableDictionary *updatedLayout = [layout mutableCopy];
197
- [updatedLayout setObject:(viewInfo[@"x"] ?: layout[@"x"]) forKey:@"x"];
198
- [updatedLayout setObject:(viewInfo[@"y"] ?: layout[@"y"]) forKey:@"y"];
199
- [updatedLayout setObject:(viewInfo[@"width"] ?: layout[@"width"])
200
- forKey:@"width"];
201
- [updatedLayout setObject:(viewInfo[@"height"] ?: layout[@"height"])
202
- forKey:@"height"];
203
- [updatedLayout setObject:(viewInfo[@"zOrder"] ?: layout[@"zOrder"])
204
- forKey:@"zOrder"];
205
- [updatedLayout setObject:(viewInfo[@"renderMode"] ?: layout[@"renderMode"])
206
- forKey:@"renderMode"];
207
-
208
- VeLiveStreamMixDescription *description =
209
- [[VeLiveStreamMixDescription alloc] init];
210
- VeLiveMixVideoLayout *videoLayout = [[VeLiveMixVideoLayout alloc] init];
211
- videoLayout.streamId = videoStreamId;
212
- videoLayout.x = [updatedLayout[@"x"] floatValue];
213
- videoLayout.y = [updatedLayout[@"y"] floatValue];
214
- videoLayout.width = [updatedLayout[@"width"] floatValue];
215
- videoLayout.height = [updatedLayout[@"height"] floatValue];
216
- videoLayout.zOrder = [updatedLayout[@"zOrder"] intValue];
217
- videoLayout.renderMode = [updatedLayout[@"renderMode"] intValue];
218
- description.mixVideoStreams = @[ videoLayout ];
219
- [self.pusher.getMixerManager updateStreamMixDescription:description];
220
-
221
- [self.mixedViewLayout setObject:updatedLayout forKey:viewId];
222
-
223
- VeLiveMixerUIView *mixerView =
224
- [[VeLiveMixerHelper cachedMixedViews] objectForKey:viewId];
225
- [mixerView performCaptureWithTrigger:@"update"];
226
-
227
- return YES;
228
- } @catch (NSException *exception) {
229
- return NO;
230
- }
231
- }
232
-
233
- - (BOOL)removeView:(NSString *)viewId {
234
- @try {
235
- NSDictionary *layout = [self.mixedViewLayout objectForKey:viewId];
236
- if (!layout) {
237
- return NO;
238
- }
239
-
240
- NSNumber *streamIdNumber = [self.viewIdToStreamId objectForKey:viewId];
241
- if (streamIdNumber) {
242
- int streamId = [streamIdNumber intValue];
243
- [self.pusher.getMixerManager removeVideoStream:streamId];
244
-
245
- NSString *callbackKey = [NSString stringWithFormat:@"%d", streamId];
246
- [self.callbacks removeObjectForKey:callbackKey];
247
- }
248
-
249
- [self.viewIdToStreamId removeObjectForKey:viewId];
250
- [self.pendingCallbacks removeObjectForKey:viewId];
251
-
252
- VeLiveMixerUIView *view =
253
- [[VeLiveMixerHelper cachedMixedViews] objectForKey:viewId];
254
- if ([view isKindOfClass:[VeLiveMixerUIView class]]) {
255
- view.bitmapCaptureCallback = nil;
256
- }
257
-
258
- [self.mixedViewLayout removeObjectForKey:viewId];
259
-
260
- return YES;
261
- } @catch (NSException *exception) {
262
- return NO;
263
- }
264
- }
265
-
266
- - (void)captureView:(NSString *)viewId {
267
- VeLiveMixerUIView *view =
268
- [[VeLiveMixerHelper cachedMixedViews] objectForKey:viewId];
269
- if ([view isKindOfClass:[VeLiveMixerUIView class]]) {
270
- [view performCaptureWithTrigger:@"manual"];
271
- }
272
- }
273
-
274
- #pragma mark - Static Methods
275
-
276
- + (void)setupCallbackForMixerView:(VeLiveMixerUIView *)mixerView
277
- streamId:(int)streamId {
278
- if (mixerView == nil) {
279
- return;
280
- }
281
-
282
- VeLiveMixerHelper *instance = [VeLiveMixerHelper findActiveMixerManager];
283
- if (!instance) {
284
- return;
285
- }
286
-
287
- VeLiveMixerBitmapCallback *callback =
288
- [[VeLiveMixerBitmapCallback alloc] initWithStreamId:streamId];
289
-
290
- NSString *callbackKey = [NSString stringWithFormat:@"%d", streamId];
291
- [instance.callbacks setObject:callback forKey:callbackKey];
292
-
293
- mixerView.bitmapCaptureCallback = callback;
294
-
295
- dispatch_after(
296
- dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)),
297
- dispatch_get_main_queue(), ^{
298
- @try {
299
- if (mixerView && mixerView.bitmapCaptureCallback) {
300
- VeLiveMixerHelper *instance =
301
- [VeLiveMixerHelper findActiveMixerManager];
302
- if (instance && instance.pusher) {
303
- @try {
304
- NSString *viewId = mixerView.viewId;
305
- NSDictionary *layout =
306
- [instance.mixedViewLayout objectForKey:viewId];
307
- if (layout) {
308
- VeLiveStreamMixDescription *description =
309
- [[VeLiveStreamMixDescription alloc] init];
310
- VeLiveMixVideoLayout *videoLayout =
311
- [[VeLiveMixVideoLayout alloc] init];
312
- videoLayout.streamId = streamId;
313
- videoLayout.x = [layout[@"x"] floatValue];
314
- videoLayout.y = [layout[@"y"] floatValue];
315
- videoLayout.width = [layout[@"width"] floatValue];
316
- videoLayout.height = [layout[@"height"] floatValue];
317
- videoLayout.zOrder = [layout[@"zOrder"] intValue];
318
- videoLayout.renderMode = [layout[@"renderMode"] intValue];
319
- description.mixVideoStreams = @[ videoLayout ];
320
- [instance.pusher.getMixerManager
321
- updateStreamMixDescription:description];
322
- }
323
- } @catch (NSException *e) {
324
- // Ignore
325
- }
326
- }
327
-
328
- [mixerView performCaptureWithTrigger:@"update"];
329
- }
330
- } @catch (NSException *exception) {
331
- // Ignore
332
- }
333
- });
334
- }
335
-
336
- + (void)sendBitmapToMixerStatic:(int)streamId bitmap:(UIImage *)bitmap {
337
- VeLiveMixerHelper *instance = [VeLiveMixerHelper findActiveMixerManager];
338
- if (instance && instance.pusher) {
339
- [instance sendBitmapToMixer:streamId bitmap:bitmap];
340
- }
341
- }
342
-
343
- + (VeLiveMixerHelper *)findActiveMixerManager {
344
- return currentInstance;
345
- }
346
-
347
- + (void)onViewReady:(NSString *)viewId
348
- mixerView:(VeLiveMixerUIView *)mixerView {
349
- @try {
350
- VeLiveMixerHelper *instance = [VeLiveMixerHelper findActiveMixerManager];
351
- if (instance != nil) {
352
- NSNumber *streamIdNumber =
353
- [instance.pendingCallbacks objectForKey:viewId];
354
- if (streamIdNumber != nil) {
355
- int streamId = [streamIdNumber intValue];
356
- [instance.pendingCallbacks removeObjectForKey:viewId];
357
- [VeLiveMixerHelper setupCallbackForMixerView:mixerView
358
- streamId:streamId];
359
- }
360
- }
361
- } @catch (NSException *exception) {
362
- // Ignore
363
- }
364
- }
365
-
366
- - (void)cleanup {
367
- [self stopMemoryMonitoring];
368
-
369
- for (NSString *viewId in self.mixedViewLayout.allKeys) {
370
- VeLiveMixerUIView *view =
371
- [[VeLiveMixerHelper cachedMixedViews] objectForKey:viewId];
372
- if ([view isKindOfClass:[VeLiveMixerUIView class]]) {
373
- view.bitmapCaptureCallback = nil;
374
- }
375
- }
376
-
377
- [self.mixedViewLayout removeAllObjects];
378
- [self.pendingCallbacks removeAllObjects];
379
- [self.callbacks removeAllObjects];
380
-
381
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
382
- @autoreleasepool {
383
- [[NSURLCache sharedURLCache] removeAllCachedResponses];
384
- [[NSURLCache sharedURLCache] setMemoryCapacity:0];
385
- [[NSURLCache sharedURLCache] setMemoryCapacity:10 * 1024 * 1024];
386
-
387
- [[NSNotificationCenter defaultCenter]
388
- postNotificationName:UIApplicationDidReceiveMemoryWarningNotification
389
- object:nil];
390
-
391
- dispatch_after(
392
- dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)),
393
- dispatch_get_main_queue(),
394
- ^{
395
- // Final cleanup completed
396
- });
397
- }
398
- });
399
- }
400
-
401
- - (void)dealloc {
402
- [self cleanup];
403
-
404
- if (currentInstance == self) {
405
- currentInstance = nil;
406
- }
407
- }
408
-
409
- #pragma mark - Memory Monitoring
410
-
411
- - (void)startMemoryMonitoring {
412
- self.memoryMonitorTimer =
413
- [NSTimer scheduledTimerWithTimeInterval:30.0
414
- target:self
415
- selector:@selector(checkMemoryUsage)
416
- userInfo:nil
417
- repeats:YES];
418
- }
419
-
420
- - (void)stopMemoryMonitoring {
421
- if (self.memoryMonitorTimer) {
422
- [self.memoryMonitorTimer invalidate];
423
- self.memoryMonitorTimer = nil;
424
- }
425
- }
426
-
427
- - (void)checkMemoryUsage {
428
- @autoreleasepool {
429
- struct task_basic_info info;
430
- mach_msg_type_number_t size = TASK_BASIC_INFO_COUNT;
431
- kern_return_t kerr =
432
- task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &size);
433
-
434
- if (kerr == KERN_SUCCESS) {
435
- double memoryUsageMB = info.resident_size / 1024.0 / 1024.0;
436
-
437
- if (memoryUsageMB > 200.0) {
438
- [self performMemoryCleanup];
439
- }
440
- }
441
- }
442
- }
443
-
444
- - (void)performMemoryCleanup {
445
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
446
- @autoreleasepool {
447
- NSMutableDictionary *cachedViews = [VeLiveMixerHelper cachedMixedViews];
448
- for (NSString *viewId in cachedViews.allKeys) {
449
- VeLiveMixerUIView *view = [cachedViews objectForKey:viewId];
450
- if ([view isKindOfClass:[VeLiveMixerUIView class]]) {
451
- if ([view.captureMode isEqualToString:@"realtime"]) {
452
- [view stopCapture];
453
-
454
- dispatch_after(
455
- dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)),
456
- dispatch_get_main_queue(), ^{
457
- if (view && [cachedViews objectForKey:viewId] == view) {
458
- [view startCapture];
459
- }
460
- });
461
- }
462
- }
463
- }
464
-
465
- [[NSURLCache sharedURLCache] removeAllCachedResponses];
466
- [[NSURLCache sharedURLCache] setMemoryCapacity:5 * 1024 * 1024];
467
-
468
- [[NSNotificationCenter defaultCenter]
469
- postNotificationName:UIApplicationDidReceiveMemoryWarningNotification
470
- object:nil];
471
- }
472
- });
473
- }
474
-
475
- #pragma mark - Private Methods
476
-
477
- - (void)sendBitmapToMixer:(int)streamId bitmap:(UIImage *)bitmap {
478
- @autoreleasepool {
479
- if (!self.pusher || !bitmap) {
480
- return;
481
- }
482
-
483
- CVPixelBufferRef pixelBuffer = NULL;
484
-
485
- @try {
486
- pixelBuffer = [self pixelBufferFromUIImage:bitmap];
487
- if (!pixelBuffer) {
488
- return;
489
- }
490
-
491
- VeLiveVideoFrame *videoFrame = [[VeLiveVideoFrame alloc] init];
492
- videoFrame.bufferType = VeLiveVideoBufferTypePixelBuffer;
493
- videoFrame.pts = CMTimeMakeWithSeconds(CACurrentMediaTime(), 1000000000);
494
- videoFrame.pixelBuffer = pixelBuffer;
495
-
496
- [[self.pusher getMixerManager] sendCustomVideoFrame:videoFrame
497
- streamId:streamId];
498
- CVPixelBufferRelease(pixelBuffer);
499
-
500
- pixelBuffer = NULL;
501
-
502
- } @catch (NSException *exception) {
503
- if (pixelBuffer) {
504
- CVPixelBufferRelease(pixelBuffer);
505
- pixelBuffer = NULL;
506
- }
507
- }
508
- }
509
- }
510
-
511
- #pragma mark - Helper Methods
512
-
513
- - (CVPixelBufferRef)pixelBufferFromUIImage:(UIImage *)image {
514
- if (!image) {
515
- return NULL;
516
- }
517
-
518
- CGImageRef cgImage = image.CGImage;
519
- if (!cgImage) {
520
- return NULL;
521
- }
522
-
523
- CGFloat width = CGImageGetWidth(cgImage);
524
- CGFloat height = CGImageGetHeight(cgImage);
525
-
526
- NSDictionary *options = @{
527
- (NSString *)kCVPixelBufferCGImageCompatibilityKey : @YES,
528
- (NSString *)kCVPixelBufferCGBitmapContextCompatibilityKey : @YES,
529
- (NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{}
530
- };
531
-
532
- CVPixelBufferRef pixelBuffer = NULL;
533
- CVReturn status = CVPixelBufferCreate(
534
- kCFAllocatorDefault, width, height, kCVPixelFormatType_32BGRA,
535
- (__bridge CFDictionaryRef)options, &pixelBuffer);
536
-
537
- if (status != kCVReturnSuccess || !pixelBuffer) {
538
- return NULL;
539
- }
540
-
541
- CVPixelBufferLockBaseAddress(pixelBuffer, 0);
542
-
543
- void *pixelData = CVPixelBufferGetBaseAddress(pixelBuffer);
544
- size_t bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer);
545
-
546
- CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
547
- CGContextRef context = CGBitmapContextCreate(
548
- pixelData, width, height, 8, bytesPerRow, colorSpace,
549
- kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host);
550
-
551
- if (!context) {
552
- CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
553
- CVPixelBufferRelease(pixelBuffer);
554
- CGColorSpaceRelease(colorSpace);
555
- return NULL;
556
- }
557
-
558
- CGContextDrawImage(context, CGRectMake(0, 0, width, height), cgImage);
559
-
560
- CGContextRelease(context);
561
- CGColorSpaceRelease(colorSpace);
562
- CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
563
-
564
- return pixelBuffer;
565
- }
566
-
567
- @end
568
-
569
- #pragma mark - VeLiveMixerBitmapCallback Implementation
570
-
571
- @implementation VeLiveMixerBitmapCallback
572
-
573
- - (instancetype)initWithStreamId:(int)streamId {
574
- self = [super init];
575
- if (self) {
576
- _streamId = streamId;
577
- }
578
- return self;
579
- }
580
-
581
- - (void)onBitmapCaptured:(UIImage *)bitmap {
582
- if (bitmap != nil) {
583
- [VeLiveMixerHelper sendBitmapToMixerStatic:self.streamId bitmap:bitmap];
584
- }
585
- }
586
-
587
- - (void)onCaptureError:(NSString *)error {
588
- // Ignore
589
- }
590
-
591
- @end
@@ -1,69 +0,0 @@
1
- //
2
- // VeLiveMixerView.h
3
- // react-native-live-push
4
- //
5
- // Created by ByteDance on 2025/06/09.
6
- //
7
-
8
- #import <Foundation/Foundation.h>
9
- #import <UIKit/UIKit.h>
10
- #import <React/RCTComponent.h>
11
- #import <CoreVideo/CoreVideo.h>
12
- #import <CoreMedia/CoreMedia.h>
13
-
14
- NS_ASSUME_NONNULL_BEGIN
15
-
16
- // Bitmap捕获回调协议 - 对应Android的BitmapCaptureCallback
17
- @protocol VeLiveBitmapCaptureCallback <NSObject>
18
- - (void)onBitmapCaptured:(UIImage *)bitmap;
19
- - (void)onCaptureError:(NSString *)error;
20
- @end
21
-
22
- // MixerView代理协议
23
- @protocol VeLiveMixerViewDelegate <NSObject>
24
- - (void)onBitmapCaptured:(UIImage *)image viewId:(NSString *)viewId;
25
- - (void)onCaptureError:(NSString *)error viewId:(NSString *)viewId;
26
- @end
27
-
28
- @interface VeLiveMixerUIView : UIView
29
-
30
- // 视图标识
31
- @property (nonatomic, strong) NSString *viewId;
32
-
33
- // 混流配置属性
34
- @property (nonatomic, strong) NSNumber *x;
35
- @property (nonatomic, strong) NSNumber *y;
36
- @property (nonatomic, strong) NSNumber *width;
37
- @property (nonatomic, strong) NSNumber *height;
38
- @property (nonatomic, strong) NSNumber *zOrder;
39
- @property (nonatomic, strong) NSNumber *renderMode;
40
- @property (nonatomic, strong) NSString *captureMode;
41
- @property (nonatomic, strong) NSNumber *captureFramerate;
42
- @property (nonatomic, strong) NSNumber *autoSensitivity;
43
-
44
- // React Native 事件回调
45
- @property (nonatomic, copy) RCTBubblingEventBlock onBitmapCapture;
46
- @property (nonatomic, copy) RCTBubblingEventBlock onCaptureError;
47
-
48
- // 代理
49
- @property (nonatomic, weak) id<VeLiveMixerViewDelegate> delegate;
50
-
51
- // Bitmap捕获回调 - 用于与MixerManager集成
52
- @property (nonatomic, weak) id<VeLiveBitmapCaptureCallback> bitmapCaptureCallback;
53
-
54
- // 控制方法
55
- - (void)startCapture;
56
- - (void)stopCapture;
57
- - (void)performCaptureWithTrigger:(NSString *)trigger;
58
-
59
- // 设置bitmap捕获回调
60
- - (void)setBitmapCaptureCallback:(id<VeLiveBitmapCaptureCallback>)callback;
61
-
62
- // UIView转换方法
63
- - (UIImage *)snapshotIncludeSubviews;
64
- - (CVPixelBufferRef)createPixelBuffer;
65
- - (CMSampleBufferRef)createSampleBuffer;
66
-
67
- @end
68
-
69
- NS_ASSUME_NONNULL_END