我正在使用 android 应用 native 代码,并且正在使用一些音频文件和音频处理。我需要将音频数据(原始音频帧)发送到 webRTC。但是我找不到任何 webRTC API 来添加自定义音频源(不是像麦克风这样的默认音频源)。
我知道我需要添加 AudioTrackInterface,为此我需要添加 AudioSourceInterface。
最佳答案
此方法适用于 WebRTC 66 版本。它不是那么简单,也许不是很清楚,但它确实有效。我尝试解释主要思想:
我继承了 webrtc::AudioDeviceModule
并覆盖了一些方法来模拟“虚拟音频设备”以进行虚拟播放和录制。在调用时,我只调用标准的 AudioDeviceModule
基本方法并进行一些修改:
int16_t PlayoutDevices()
=> call base method, but return base + 1
int16_t RecordingDevices()
=> return base + 1
int32_t PlayoutDeviceName
=> return my virtual device name and GUID
int32_t RecordingDeviceName
=> return my virtual device name and GUID
void SendFrameP
=> return my virtual device audio data
void ReceiveFrameP
=> use received audio data by my virtual deviceetc methods => just look at
webrtc::AudioDeviceModule
implementation.
然后你可以使用你自己的AudioDeviceModule
作为webrtc::CreatePeerConnectionFactory
函数的参数,提供音频数据作为录音设备,接收数据作为播放设备。
关于c++ - webRTC c++ 中是否有自定义音频源的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54203421/