基于Webrtc的视频通话录制功能-Android实现

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值