@byteplus/react-native-rtc 1.0.2 → 1.0.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 (26) hide show
  1. package/README.md +313 -5
  2. package/android/build.gradle +14 -33
  3. package/android/src/main/java/com/volcengine/reactnative/vertc/VertcViewManager.java +1 -1
  4. package/android/src/main/java/com/volcengine/reactnative/vertc/events/ClassHelper.java +149 -0
  5. package/android/src/main/java/com/volcengine/reactnative/vertc/vod/VertcVod.java +29 -13
  6. package/android/src/main/java/com/volcengine/reactnative/vertc/vod/VideoAudioProcessor.java +9 -11
  7. package/android/src/main/java/com/volcengine/reactnative/vertc/vod/VodMock.java +17 -6
  8. package/android/src/main/java/com/volcengine/reactnative/vertc/vod/VodVideoEngineCallbackProxy.java +94 -0
  9. package/ios/VertcView.m +1 -1
  10. package/ios/VertcViewManager.m +1 -1
  11. package/ios/vod/VertcVod.m +20 -5
  12. package/ios/vod/VodAudioProcessor.h +6 -1
  13. package/ios/vod/VodAudioProcessor.mm +9 -1
  14. package/ios/vod/VodVideoProcessor.h +3 -1
  15. package/ios/vod/VodVideoProcessor.m +22 -2
  16. package/lib/commonjs/index.js +132 -17
  17. package/lib/module/index.js +132 -17
  18. package/lib/typescript/codegen/pack/keytype.d.ts +3 -3
  19. package/lib/typescript/component.d.ts +9 -2
  20. package/lib/typescript/core/rtc-video.d.ts +8 -1
  21. package/lib/typescript/platforms/android/vod.d.ts +2 -2
  22. package/package.json +1 -1
  23. package/react-native-rtc.podspec +39 -16
  24. package/android/src/main/java/com/volcengine/reactnative/vertc/vod/VodAudioProxy.java +0 -44
  25. package/android/src/main/java/com/volcengine/reactnative/vertc/vod/VodAudioVoiceWrapperObject.java +0 -355
  26. package/android/src/main/java/com/volcengine/reactnative/vertc/vod/VodVideoProxy.java +0 -97
@@ -1,355 +0,0 @@
1
- // Copyright © 2022 BytePlusRTC All rights reserved.
2
- // SPDX-License-Identifier: MIT
3
-
4
- package com.volcengine.reactnative.vertc.vod;
5
-
6
- import android.app.Service;
7
- import android.content.Context;
8
- import android.media.AudioFormat;
9
- import android.media.AudioManager;
10
- import android.media.AudioTrack;
11
- import android.os.Build;
12
- import android.util.Log;
13
-
14
- import com.ss.bytertc.engine.RTCVideo;
15
- import com.ss.bytertc.engine.data.AudioChannel;
16
- import com.ss.bytertc.engine.data.AudioSampleRate;
17
- import com.ss.bytertc.engine.utils.AudioFrame;
18
- import com.ss.ttm.player.TraitObject;
19
- import com.ss.ttm.player.VoiceTrait;
20
-
21
- import java.lang.reflect.Method;
22
- import java.nio.ByteBuffer;
23
-
24
- public class VodAudioVoiceWrapperObject extends VoiceTrait {
25
- private String TAG = "VodAudioVoiceWrapperObject";
26
- private VodAudioProcessor mAudioProcessor;
27
-
28
- private final static int kNoSettingVolume = -1;
29
- private Context mContext = null;
30
- private AudioManager mAudioManager = null;
31
- private AudioTrack mAudioTrack = null;
32
- private Method getLatencyMethod = null;
33
- private float mLeftVolume = kNoSettingVolume;
34
- private int mMaxVolume = 0;
35
- private volatile boolean mStoped = true;
36
- private int mChannels = 0;
37
- private int mSampleBytes = 2;
38
- private int mSampleRate = 0;
39
- private int mFrameSampleNB = 0;
40
- private int mBytePerSample = 0;
41
- private int mFormat = -1;
42
- private boolean mIsPacked = false;
43
- private int mTrackBufferSize = 0;
44
- private int mSessionId = -1;
45
- private int mStreamType = AudioManager.STREAM_MUSIC;
46
- private int mChannelsLayout = AudioFormat.CHANNEL_INVALID;
47
- private int mAudioFormat = AudioFormat.ENCODING_PCM_16BIT;
48
- private RTCVideo mRTCVideo;
49
-
50
- public VodAudioVoiceWrapperObject() {
51
- super(TraitObject.ExtVoice, VoiceTrait.Version0, 0);
52
-
53
- }
54
- public VodAudioVoiceWrapperObject(Context context, RTCVideo rtcVideo) {
55
- this();
56
- mContext = context;
57
- mRTCVideo = rtcVideo;
58
- mAudioProcessor = new VodAudioProcessor(rtcVideo);
59
- }
60
-
61
- public int audioOpen(AudioMediaInfo info) {
62
- if (info == null) {
63
- return -1;
64
- }
65
-
66
- mAudioProcessor.audioOpen(info.mSampleRate, info.mChannels);
67
-
68
- mChannels = info.mChannels;
69
- mSampleRate = info.mSampleRate;
70
- mFrameSampleNB = info.mFrameSampleNB;
71
- mBytePerSample = info.mBytePerSample;
72
- mFormat = info.mFormat;
73
- mIsPacked = info.mIsPacked == 1;
74
- // ret = reconfigure();
75
- // if (ret == -1) {
76
- // return -1;
77
- // }
78
- // if(mLeftVolume == kNoSettingVolume) {
79
- // mLeftVolume = mMaxVolume / 2;
80
- // }
81
- // setAudioVolume(mLeftVolume);
82
- // try {
83
- // getLatencyMethod =
84
- // AudioTrack.class.getMethod("getLatency", (Class<?>[]) null);
85
- // } catch (NoSuchMethodException e) {
86
- // // There's no guarantee this method exists. Do nothing.
87
- // }
88
- // mStoped = false;
89
- // mAudioTrack.play();
90
- Log.d(TAG, "audio open success");
91
- return 0;
92
- }
93
-
94
- @Override
95
- public int audioWrite(AudioFrameInfo frame) {
96
- // mAudioProcessor.audioProcess(frame.mBuffers, frame.mSamples, frame.mTimestamp);
97
- // return 0;
98
- // int ret = -1;
99
- // if (frame == null || frame.mBuffers == null) {
100
- // return ret;
101
- // }
102
- //
103
- // int wSize= 0;
104
- // synchronized (mAudioTrack) {
105
- // if (mStoped) {
106
- // return 0;
107
- // }
108
- // try {
109
- // byte[] tmpBuffer = getAudioBuffer(frame);
110
- // wSize = mAudioTrack.write(tmpBuffer, 0, tmpBuffer.length);
111
- // ret = 0;
112
- // AudioFrame audioFrame = buildAudioFrame(frame);
113
- // this.mRTCVideo.pushScreenAudioFrame(audioFrame);
114
- // } catch (Exception e) {
115
- // Log.d(TAG, "write fail = " + e);
116
- // e.printStackTrace();
117
- // return -1;
118
- // }
119
- // }
120
- //
121
- // if(wSize < 0) {
122
- // Log.e(TAG, "write failed : ret: " + wSize + ", size = " + frame.mBuffers[0].array().length);
123
- // return wSize;
124
- // }
125
- // Log.d(TAG, "audio write success");
126
- // mWrittenPcmBytes += wSize;
127
- AudioFrame audioFrame = buildAudioFrame(frame);
128
- this.mRTCVideo.pushScreenAudioFrame(audioFrame);
129
- return 0;
130
- }
131
-
132
- private AudioFrame buildAudioFrame(AudioFrameInfo info) {
133
- var buffer = getAudioBuffer(info);
134
- var mAudioSampleRate = getAudioSampleRate();
135
- var mAudioChannel = getAudioChannel();
136
- return new AudioFrame(
137
- buffer,
138
- info.mSamples,
139
- mAudioSampleRate,
140
- mAudioChannel
141
- );
142
- }
143
-
144
- private AudioSampleRate getAudioSampleRate() {
145
- if (mSampleRate == AudioSampleRate.AUDIO_SAMPLE_RATE_48000.value()) {
146
- return AudioSampleRate.AUDIO_SAMPLE_RATE_48000;
147
- }
148
-
149
- if (mSampleRate == AudioSampleRate.AUDIO_SAMPLE_RATE_44100.value()) {
150
- return AudioSampleRate.AUDIO_SAMPLE_RATE_44100;
151
- }
152
-
153
- if (mSampleRate == AudioSampleRate.AUDIO_SAMPLE_RATE_32000.value()) {
154
- return AudioSampleRate.AUDIO_SAMPLE_RATE_32000;
155
- }
156
-
157
- if (mSampleRate == AudioSampleRate.AUDIO_SAMPLE_RATE_16000.value()) {
158
- return AudioSampleRate.AUDIO_SAMPLE_RATE_16000;
159
- }
160
-
161
- if (mSampleRate == AudioSampleRate.AUDIO_SAMPLE_RATE_8000.value()) {
162
- return AudioSampleRate.AUDIO_SAMPLE_RATE_8000;
163
- }
164
-
165
- return AudioSampleRate.AUDIO_SAMPLE_RATE_AUTO;
166
- }
167
-
168
- private AudioChannel getAudioChannel() {
169
- if (mChannels == AudioChannel.AUDIO_CHANNEL_MONO.value()) {
170
- return AudioChannel.AUDIO_CHANNEL_MONO;
171
- }
172
-
173
- if (mChannels == AudioChannel.AUDIO_CHANNEL_STEREO.value()) {
174
- return AudioChannel.AUDIO_CHANNEL_STEREO;
175
- }
176
-
177
- return AudioChannel.AUDIO_CHANNEL_AUTO;
178
- }
179
-
180
- private byte[] getAudioBuffer(AudioFrameInfo frame) {
181
- byte[] buffer = null;
182
- if (frame == null || frame.mBuffers == null) {
183
- return null;
184
- }
185
- int bufferSize = frame.mBuffers[0].limit();
186
- if (!mIsPacked) {
187
- bufferSize = bufferSize * mChannels;
188
- }
189
- buffer = new byte[bufferSize];
190
- int bytePerSample = mBytePerSample;
191
- int readSize = bytePerSample * mChannels;
192
- if (!mIsPacked) {
193
- readSize = bytePerSample;
194
- }
195
- for (int i = 0;i < mChannels;i++) {
196
- ByteBuffer tmpBuffer = frame.mBuffers[i];
197
- if (tmpBuffer == null) {
198
- break;
199
- }
200
- for (int j = 0; j < frame.mSamples;j++) {
201
- tmpBuffer.get(buffer,j * mChannels * bytePerSample + i * bytePerSample, readSize);
202
- }
203
- }
204
- return buffer;
205
- }
206
-
207
- @Override
208
- public void audioPause() {
209
- if (mAudioTrack == null) {
210
- return;
211
- }
212
- mAudioTrack.pause();
213
- }
214
-
215
- @Override
216
- public void audioResume() {
217
- if (mAudioTrack == null) {
218
- return;
219
- }
220
- mAudioTrack.play();
221
- }
222
-
223
- @Override
224
- public void audioFlush() {
225
- if (mAudioTrack == null) {
226
- return;
227
- }
228
- mAudioTrack.flush();
229
- }
230
-
231
- @Override
232
- public void audioClose() {
233
- if (mAudioTrack == null) {
234
- return;
235
- }
236
- mAudioTrack.pause();
237
- mStoped = true;
238
- }
239
-
240
- @Override
241
- public int getLatency() {
242
- int latency = 0;
243
- if (mAudioTrack == null) {
244
- return latency;
245
- }
246
- if (getLatencyMethod != null) {
247
- try {
248
- // Compute the audio track latency, excluding the latency due to the buffer (leaving
249
- // latency due to the mixer and audio hardware driver).
250
- latency = (Integer) getLatencyMethod.invoke(mAudioTrack, (Object[]) null);
251
- } catch (Exception e) {
252
- latency = 0;
253
- getLatencyMethod = null;
254
- }
255
- }
256
- return latency;
257
- }
258
-
259
- private int reconfigure() {
260
- int ret = -1;
261
- if (mContext == null) {
262
- return ret;
263
- }
264
- mAudioManager = (AudioManager)mContext.getSystemService(Service.AUDIO_SERVICE);
265
- if(mAudioManager != null) {
266
- mMaxVolume = mAudioManager.getStreamMaxVolume( mStreamType ); //
267
- }
268
- mChannelsLayout = getAudioTrackChannelConfig(mChannels);
269
- if (mChannelsLayout == AudioFormat.CHANNEL_INVALID) {
270
- return ret;
271
- }
272
- if (mSampleBytes == 1) {
273
- mAudioFormat = AudioFormat.ENCODING_PCM_8BIT;
274
- } else if(mSampleBytes == 2) {
275
- mAudioFormat = AudioFormat.ENCODING_PCM_16BIT;
276
- } else {
277
- return ret;
278
- }
279
- int minBufSize = AudioTrack.getMinBufferSize(mSampleRate, mChannelsLayout, mAudioFormat);
280
- if (minBufSize <= 0) {
281
- Log.e(TAG, "getMinBufferSize failed, trace: sampleRate = " + mSampleRate + ", " +
282
- "mChannelsLayout = " + mChannelsLayout + ", mAudioFormat = " + mAudioFormat);
283
- return minBufSize;
284
- }
285
- try {
286
- if (mSessionId == -1) {
287
- mAudioTrack = new AudioTrack(mStreamType, mSampleRate, mChannelsLayout, mAudioFormat, minBufSize, AudioTrack.MODE_STREAM);
288
- } else {
289
- mAudioTrack = new AudioTrack(mStreamType, mSampleRate, mChannelsLayout, mAudioFormat, minBufSize, AudioTrack.MODE_STREAM, mSessionId);
290
- }
291
- } catch (Throwable e) {
292
- Log.e(TAG, "create audio track failed ,detail = " + e);
293
- return ret;
294
- }
295
- int state = mAudioTrack.getState();
296
- if (state != AudioTrack.STATE_INITIALIZED) {
297
- try {
298
- mAudioTrack.release();
299
- } catch (Exception e) {
300
- // The track has already failed to initialize, so it wouldn't be that surprising if release
301
- // were to fail too. Swallow the exception.
302
- } finally {
303
- mAudioTrack = null;
304
- Log.e(TAG, "create audiotrack but failed to initialize");
305
- return AudioTrack.ERROR_INVALID_OPERATION;
306
- }
307
- }
308
- return 0;
309
- }
310
-
311
- public void setAudioVolume(float leftVolume) {
312
- try{
313
- if(mMaxVolume < leftVolume) {
314
- leftVolume = mMaxVolume;
315
- }
316
- if(mAudioManager != null) {
317
- // Log.i("ttmn", "setVolume system lv"+leftVolume + "rv:"+rightVolume + "mv:"+mAudioManager.getStreamMaxVolume( AudioManager.STREAM_MUSIC ));
318
- mAudioManager.setStreamVolume(mStreamType, (int)leftVolume, 0);
319
- }
320
- mLeftVolume = leftVolume;
321
- } catch (Exception e) {
322
- }
323
- }
324
-
325
- public static int getAudioTrackChannelConfig(int channelCount) {
326
- switch(channelCount) {
327
- case 1:
328
- return 4;
329
- case 2:
330
- return 12;
331
- case 3:
332
- return 28;
333
- case 4:
334
- return 204;
335
- case 5:
336
- return 220;
337
- case 6:
338
- return 252;
339
- case 7:
340
- return 1276;
341
- case 8:
342
- if (Build.VERSION.SDK_INT >= 23) {
343
- return 6396;
344
- } else {
345
- if (Build.VERSION.SDK_INT >= 21) {
346
- return 6396;
347
- }
348
-
349
- return 0;
350
- }
351
- default:
352
- return 0;
353
- }
354
- }
355
- }
@@ -1,97 +0,0 @@
1
- // Copyright © 2022 BytePlusRTC All rights reserved.
2
- // SPDX-License-Identifier: MIT
3
-
4
- package com.volcengine.reactnative.vertc.vod;
5
-
6
- import android.graphics.SurfaceTexture;
7
- import android.opengl.EGLContext;
8
- import android.util.Log;
9
- import android.view.Surface;
10
-
11
- import com.ss.bytertc.engine.RTCVideo;
12
- import com.ss.bytertc.engine.data.ColorSpace;
13
- import com.ss.bytertc.engine.data.ReturnStatus;
14
- import com.ss.bytertc.engine.data.StreamIndex;
15
- import com.ss.bytertc.engine.data.VideoPixelFormat;
16
- import com.ss.bytertc.engine.data.VideoRotation;
17
- import com.ss.bytertc.engine.data.VideoSourceType;
18
- import com.ss.bytertc.engine.video.VideoFrame;
19
- import com.ss.bytertc.engine.video.builder.GLTextureVideoFrameBuilder;
20
- import com.ss.ttvideoengine.TTVideoEngine;
21
- import com.ss.ttvideoengine.VideoEngineCallback;
22
-
23
- public class VodVideoProxy {
24
- private String TAG = "VodVideoProxy";
25
-
26
- private TTVideoEngine mVideoEngine;
27
- private RTCVideo mRTCVideo;
28
-
29
- private OESTextureProcessor mOESTextureProcessor;
30
-
31
- private final OESTextureProcessor.IProcessorCallback mProcessorCallback = new OESTextureProcessor.IProcessorCallback() {
32
- @Override
33
- public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
34
- TTVideoEngine videoEngine = mVideoEngine;
35
- if (videoEngine != null) {
36
- videoEngine.setSurface(new Surface(surface));
37
- }
38
- }
39
-
40
- @Override
41
- public void onSurfaceTextureDestroyed(SurfaceTexture surface) {
42
- TTVideoEngine videoEngine = mVideoEngine;
43
- if (videoEngine != null) {
44
- videoEngine.setSurface(null);
45
- }
46
- }
47
-
48
- @Override
49
- public void onFrameAvailable(EGLContext eglContext, int oesTextureId, float[] transformMatrix, int width, int height, long timestamp) {
50
- GLTextureVideoFrameBuilder builder = new GLTextureVideoFrameBuilder(VideoPixelFormat.TEXTURE_OES)
51
- .setTextureID(oesTextureId)
52
- .setWidth(width)
53
- .setHeight(height)
54
- .setRotation(VideoRotation.VIDEO_ROTATION_0)
55
- .setTextureMatrix(transformMatrix)
56
- // .setTimeStampUs(timestamp)
57
- .setTimeStampUs(System.nanoTime())
58
- .setColorSpace(ColorSpace.UNKNOWN)
59
- .setEGLContext(eglContext);
60
- VideoFrame frame = builder.build();
61
- // frame.retain();
62
- // Log.d(TAG, "pushScreenVideoFrame: " + frame));
63
- int ret_status = mRTCVideo.pushScreenVideoFrame(frame);
64
- boolean result = ret_status == ReturnStatus.RETURN_STATUS_SUCCESS.value()
65
- || ret_status == ReturnStatus.RETURN_STATUS_VIDEO_TIMESTAMP_WARNING.value();
66
- if (!result) {
67
- Log.d(TAG, "pushScreenVideoFrame fail: " + ret_status);
68
- }
69
- }
70
- };
71
-
72
- public void initEngine(TTVideoEngine videoEngine, RTCVideo rtcEngine) {
73
- OESTextureProcessor textureProcessor = mOESTextureProcessor;
74
- if (textureProcessor != null) {
75
- textureProcessor.destroy();
76
- }
77
-
78
- mVideoEngine = videoEngine;
79
- mRTCVideo = rtcEngine;
80
- mOESTextureProcessor = new OESTextureProcessor();
81
-
82
- // var width = mVideoEngine.getVideoWidth();
83
- // var height = mVideoEngine.getVideoWidth();
84
- var width = 1920;
85
- var height = 1080;
86
- mRTCVideo.setVideoSourceType(StreamIndex.STREAM_INDEX_SCREEN, VideoSourceType.VIDEO_SOURCE_TYPE_EXTERNAL);
87
- mOESTextureProcessor.initSurfaceTexture(width, height, mProcessorCallback);
88
- }
89
-
90
- public void release() {
91
- if (mOESTextureProcessor != null) {
92
- mOESTextureProcessor.destroy();
93
- mOESTextureProcessor = null;
94
- }
95
- mVideoEngine = null;
96
- }
97
- }