Android本机WebRTC:在已连接后添加视频 [英] Android native webrtc: add video after already connected

查看:662
本文介绍了Android本机WebRTC:在已连接后添加视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Google的代码库中的libjingle.so和PeerConnectionClient.java等,我已经在Android应用程序中成功运行WebRTC一段时间了.但是,我现在遇到一个问题,即用户仅以音频(即音频呼叫)开始连接,然后打开视频.我像这样在PeerConnectionClient中扩充了现有的setVideoEnabled():

I have successfully been running WebRTC in my Android app for a while, using libjingle.so and PeerConnectionClient.java, etc., from Google's code library. However, I am now running into a problem where a user starts a connection as audio only (i.e., an audio call), but then toggles video on. I augmented the existing setVideoEnabled() in PeerConnectionClient as such:

 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()调用可以做到这一点,但也许我还缺少其他东西?

This allows me successfully see a local inset of the device's video camera, but it doesn't send the video to the remove client. I thought the peerConnection.addStream() call would do that, but perhaps I am missing something else?

推荐答案

为避免在对等体之间建立一种外部通信机制,该机制涉及第二个对等体的回答,即可以添加新流,因此您始终可以从现有的开始(但有时是空的)视频流.现在,只需要在必要时(并在必要时)用内容填充此流即可.

To avoid building an external mechanism of communication between peers that will involve an answer from the second peer that the new stream can be added, you can always start with existing (but sometimes empty) video stream. Now it is just the matter of filling this stream with content when (and if) necessary.

这篇关于Android本机WebRTC:在已连接后添加视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆