Android Tencent real-time audio and video TRTC audio conflict, Mike Feng preemption problem, recording failure during real-time audio and video

       I connected to Tencent's real-time audio and video TRTC SDK, and encountered some problems during use. The more serious one is that the local screen recording was performed during the audio and video process, and the recording failed because of the lack of sound.

1. Channel

       The SDK currently provides three control modes for system volume types, namely

(1) TRTCCloudDef#TRTCSystemVolumeTypeAuto : "Call on the microphone, media under the microphone", that is, the anchor uses the call volume when the microphone is on, and the audience uses the media volume when the audience is not on the microphone, which is suitable for online live broadcast scenarios. If the scene you select when enteringRoom is  TRTCCloudDef#TRTC_APP_SCENE_LIVE  or  TRTCCloudDef#TRTC_APP_SCENE_VOICE_CHATROOM , the SDK will automatically select this mode.

(2) TRTCCloudDef#TRTCSystemVolumeTypeVOIP : Use the call volume throughout the call, suitable for multi-person conference scenarios. If the scene you select when enteringRoom is  TRTCCloudDef#TRTC_APP_SCENE_VIDEOCALL  or  TRTCCloudDef#TRTC_APP_SCENE_AUDIOCALL , the SDK will automatically select this mode.

(3) TRTCCloudDef#TRTCSystemVolumeTypeMedia : The media volume is used throughout the call, which is not commonly used, and is suitable for individual application scenarios with special needs (such as an external sound card for the host).

Determine whether it is a call channel or a media channel:

The volume key turns off the volume. If it can be turned off without sound, it is a media channel, and if it cannot be turned off without sound, it is a call channel.

2.Xlog log

      You can check the xlog log if there are problems or exceptions during use, and you can send it to Tencent's customer service to see. The xlog log is in the local file path of the phone.
xlog log: https://cloud.tencent.com/developer/article/1502366

3. Microphone preemption

      Microphone preemption may be related to the underlying implementation attempted by mobile phones. One of the processing methods is to turn off Tencent's real-time audio and video audio, and then use the API provided by it to transmit its own audio data in real time, so that there is no conflict and audio data can be transmitted.

(1)设置tRTCCloud.enableCustomAudioCapture(true)

       Enable audio custom capture mode

      After this mode is enabled, the SDK will not run the original audio capture process, and only retain the encoding and sending capabilities. You need to use sendCustomAudioData() to continuously insert the audio data collected by yourself into the SDK.

parameter

enable Whether to enable true: enable; false: disable, default value: false

(2) Do not call tRTCCloud.startLocalAudio();, if it is called, it needs to be noted. After turning off, there is no audio transmission of Tencent real-time audio and video sdk

(3) Send audio data in real time through tRTCCloud.sendCustomAudioData(mTRTCAudioFrame);

private TRTCCloudDef.TRTCAudioFrame mTRTCAudioFrame = new TRTCCloudDef.TRTCAudioFrame();
mTRTCAudioFrame.data = data; //data为你自己采集到的音频数据
mTRTCAudioFrame.sampleRate = 48000; //采样率需要与自己音频的采样率一样,不与其推荐的一样也可以
mTRTCAudioFrame.channel = 1;  //1-单声道,2-双声道
mTRTCAudioFrame.timestamp = 0; //时间戳设为0即可
if (trtcCloud != null) {
   trtcCloud.sendCustomAudioData(mTRTCAudioFrame);
}

 sendCustomAudioData()

Send the audio data collected by yourself to the SDK

TRTCAudioFrame recommends the following filling methods:

data: Audio frame buffer. The audio frame data must be in PCM format, and 20ms samples per frame are recommended. [48000 sampling rate, mono frame length: 48000 × 0.02s × 1 × 16bit = 15360bit = 1920 bytes].
sampleRate: sampling rate.
channel: the number of channels (if it is stereo, the data is crossed), mono: 1; dual: 2.
timestamp: If the timestamp interval is uneven, it will seriously affect the audio and video synchronization and the quality of the recorded MP4.
Reference documents: custom capture and rendering.

The parameter
frame audio frame. Currently only supports mono and only supports 48K sampling rate. Please refer to TRTCAudioFrame.
Note that
you can set the timestamp in the frame to 0, which is equivalent to letting the SDK set the time stamp by itself, but please control the call interval of sendCustomAudioData "evenly", otherwise the sound will be intermittent.

 

Guess you like

Origin blog.csdn.net/qq_37980878/article/details/111557146