我已经使用来自Google代码库的libjingle.so和PeerConnectionClient.java等在我的Android应用程序中成功运行了WebRTC一段时间。但是,我现在遇到一个问题,即用户仅以音频方式启动连接(即音频呼叫),但随后切换视频。我在PeerConnectionClient中扩充了现有的setVideoEnabled():
public void setVideoEnabled(final boolean enable) {
executor.execute(new Runnable() {
@Override
public void run() {
renderVideo = enable;
if (localVideoTrack != null) {
localVideoTrack.setEnabled(renderVideo);
} else {
if (renderVideo) {
//AC: create a video track
String cameraDeviceName = VideoCapturerAndroid.getDeviceName(0);
String frontCameraDeviceName =
VideoCapturerAndroid.getNameOfFrontFacingDevice();
if (numberOfCameras > 1 && frontCameraDeviceName != null) {
cameraDeviceName = frontCameraDeviceName;
}
Log.i(TAG, "Opening camera: " + cameraDeviceName);
videoCapturer = VideoCapturerAndroid.create(cameraDeviceName);
if (createVideoTrack(videoCapturer) != null) {
mediaStream.addTrack(localVideoTrack);
localVideoTrack.setEnabled(renderVideo);
peerConnection.addStream(mediaStream);
} else {
Log.d(TAG, "Local video track is still null");
}
} else {
Log.d(TAG, "Local video track is null");
}
}
if (remoteVideoTrack != null) {
remoteVideoTrack.setEnabled(renderVideo);
} else {
Log.d(TAG,"Remote video track is null");
}
}
});
}
这允许我成功查看设备的摄像机的本地插图,但它不会将视频发送到删除客户端。我认为peerConnection.addStream()调用会这样做,但也许我错过了其他的东西?
答案 0 :(得分:1)
为了避免在对等体之间建立外部通信机制,这将涉及来自第二对等体的可以添加新流的应答,您始终可以从现有(但有时是空的)视频流开始。现在只需要在(如果有必要的话)填充内容时填写内容。