webrtc本身并不支持视频通话的录制。webrtc的sdk只是暴露了视频数据给开发者,而音频数据并没有向外暴露。因此如果要进行视频通话的录制,需要修改webrtc的sdk,将音频数据暴露出来。
webrtc的下载和编译可参考之前的文章:[WebRtc下载和编译]
一、修改SDK,引出音频数据
1. 音频采集数据的提取(mic输入,本地声音)
webrtc的音频数据的采集在audio_device_java.jar包中,具体类为WebRtcAudioRecord,其对应源码中的位置为:
src/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java
a) 在该类中添加如下代码:
// tanghongfeng add begin
private static WebRtcAudioRecordCallback mWebRtcAudioRecordCallback;
public static void setWebRtcAudioRecordCallback(WebRtcAudioRecordCallback callback) {
Logging.d("WebRtcAudioRecord", "Set record callback");
mWebRtcAudioRecordCallback = callback;
}
public interface WebRtcAudioRecordCallback {
void onWebRtcAudioRecordInit(int audioSource, int audioFormat,
int sampleRate, int channels, int bitPerSample,
int bufferPerSecond, int bufferSizeInBytes);
void onWebRtcAudioRecordStart();
void onWebRtcAudioRecording(ByteBuffer buffer, int bufferSize,
boolean microphoneMute);
void onWebRtcAudioRecordStop();
}
// tanghongfeng add end
b) 在initRecording方法中添加如下代码:
private int initRecording(int sampleRate, int channels) { ......
logMainParameters();
logMainParametersExtended(); // tanghongfeng add begin
if (mWebRtcAudioRecordCallback != null) {
mWebRtcAudioRecordCallback
.onWebRtcAudioRecordInit(audioSource, 2, sampleRate,
channels, 16, 100, bufferSizeInBytes); } // tanghongfeng add end return framesPerBuffer; }
c) 在startRecording方法中添加如下代码:
pr