本文介绍了如何实现3路电话会议视频聊天WebRTC技术原住民code为Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用(即不使用的WebView)。我已经写了使用Node.js的一个信令服务器,并使用里面的客户端应用程序连接到服务器,交换SDP数据包,并建立了2路视频聊天连接。

I'm trying to implement 3-way video chat inside an Android app using the WebRTC Native Code package for Android (i.e. not using a WebView). I've written a signalling server using node.js and used the Gottox socket.io java client library inside the client app to connect to the server, exchange SDP packets and establish a 2-way video chat connection.

不过我现在有点问题,超越了一个3方通话。自带的原生WebRTC技术code包AppRTCDemo应用演示仅2路通话(如果第三方试图加入一个房间一个满屋子的返回消息)。

However now I'm having problems going beyond that to a 3-way call. The AppRTCDemo app that comes with the WebRTC native code package demonstrates 2-way calls only (if a 3rd party attempts to join a room a "room full" message is returned).

据this回答(不涉及具体的Andr​​oid),我应该通过创建多个PeerConnections做到这一点,所以每个参与者的聊天将连接到2其他参与者。

According to this answer (which doesn't relate to Android specifically), I'm supposed to do it by creating multiple PeerConnections, so each chat participant will connect to the 2 other participants.

然而,当我创建多个PeerConnectionClient(其中封装了PeerConection,这是在libjingle_peerconnection_so.so本机端实现的Java类),有来自以两者的冲突所造成的库中抛出的异常他们试图访问摄像头:

However, when I create more than one PeerConnectionClient (a Java class which wraps a PeerConection, which is implemented on the native side in libjingle_peerconnection_so.so), there is an exception thrown from inside the library resulting from a conflict with both of them trying to access the camera:

E/VideoCapturerAndroid(21170): startCapture failed
E/VideoCapturerAndroid(21170): java.lang.RuntimeException: Fail to connect to camera service
E/VideoCapturerAndroid(21170):  at android.hardware.Camera.native_setup(Native Method)
E/VideoCapturerAndroid(21170):  at android.hardware.Camera.<init>(Camera.java:548)
E/VideoCapturerAndroid(21170):  at android.hardware.Camera.open(Camera.java:389)
E/VideoCapturerAndroid(21170):  at org.webrtc.VideoCapturerAndroid.startCaptureOnCameraThread(VideoCapturerAndroid.java:528)
E/VideoCapturerAndroid(21170):  at org.webrtc.VideoCapturerAndroid.access$11(VideoCapturerAndroid.java:520)
E/VideoCapturerAndroid(21170):  at org.webrtc.VideoCapturerAndroid$6.run(VideoCapturerAndroid.java:514)
E/VideoCapturerAndroid(21170):  at android.os.Handler.handleCallback(Handler.java:733)
E/VideoCapturerAndroid(21170):  at android.os.Handler.dispatchMessage(Handler.java:95)
E/VideoCapturerAndroid(21170):  at android.os.Looper.loop(Looper.java:136)
E/VideoCapturerAndroid(21170):  at org.webrtc.VideoCapturerAndroid$CameraThread.run(VideoCapturerAndroid.java:484)

这甚至发生在试图建立一个连接,所以它没有涉及到node.js的初始化之前在本地客户端时,socket.io或任何信令服务器上的东西。

This happens when initializing the local client even before attempting to establish a connection so it's not related to node.js, socket.io or any of the signalling server stuff.

我如何得到多个PeerConnections分享相机,使我可以把相同的视频到多个同行?

How do I get multiple PeerConnections to share the camera so that I can send the same video to more than one peer?

我有一个想法是实现某种单相机类来代替,可以多个连接之间共享VideoCapturerAndroid,但我甚至不能确定,将工作,我想知道是否有办法做3路呼叫使用API​​之前,我开始在馆内四处黑客

One idea I had was to implement some kind of singleton camera class to replace VideoCapturerAndroid that could be shared between multiple connections, but I'm not even sure that would work and I'd like to know if there is a way to do 3-way calls using the API before I start hacking around inside the library.

是否有可能,如果是这样,怎么样?

Is it possible and if so, how?

更新:

我试过共享多个PeerConnectionClients之间的VideoCapturerAndroid对象,只有第一个连接创建并把它传递到了后续的初始化函数,而导致这种捕食者只能服用一次!例外创建从VideoCapturer对象的第二VideoTrack第二对等连接时:

I tried sharing a VideoCapturerAndroid object between multiple PeerConnectionClients, creating it for the first connection only and passing it into the initialization function for the subsequent ones, but that resulted in this "Capturer can only be taken once!" exception when creating a second VideoTrack from the VideoCapturer object for the second peer connection:

E/AndroidRuntime(18956): FATAL EXCEPTION: Thread-1397
E/AndroidRuntime(18956): java.lang.RuntimeException: Capturer can only be taken once!
E/AndroidRuntime(18956):    at org.webrtc.VideoCapturer.takeNativeVideoCapturer(VideoCapturer.java:52)
E/AndroidRuntime(18956):    at org.webrtc.PeerConnectionFactory.createVideoSource(PeerConnectionFactory.java:113)
E/AndroidRuntime(18956):    at com.example.rtcapp.PeerConnectionClient.createVideoTrack(PeerConnectionClient.java:720)
E/AndroidRuntime(18956):    at com.example.rtcapp.PeerConnectionClient.createPeerConnectionInternal(PeerConnectionClient.java:482)
E/AndroidRuntime(18956):    at com.example.rtcapp.PeerConnectionClient.access$20(PeerConnectionClient.java:433)
E/AndroidRuntime(18956):    at com.example.rtcapp.PeerConnectionClient$2.run(PeerConnectionClient.java:280)
E/AndroidRuntime(18956):    at android.os.Handler.handleCallback(Handler.java:733)
E/AndroidRuntime(18956):    at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime(18956):    at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime(18956):    at com.example.rtcapp.LooperExecutor.run(LooperExecutor.java:56)

试图共享VideoTrack对象之间PeerConnectionClients导致从本机code这个错误:

Attempting to share the VideoTrack object between PeerConnectionClients resulted in this error from the native code:

E/libjingle(19884): Local fingerprint does not match identity.
E/libjingle(19884): P2PTransportChannel::Connect: The ice_ufrag_ and the ice_pwd_ are not set.
E/libjingle(19884): Local fingerprint does not match identity.
E/libjingle(19884): Failed to set local offer sdp: Failed to push down transport description: Local fingerprint does not match identity.

共享PeerConnectionClients结果之间的MediaStream可在应用程序关闭突然,没有出现在任何logcat中的错误消息。

Sharing the MediaStream between PeerConnectionClients results in the app abruptly closing, without any error message appearing in the Logcat.

推荐答案

您所遇到的问题是,PeerConnectionClient是的不可以周围PeerConnection这一个包装它的包含 PeerConnection等。

The problem you are having is that PeerConnectionClient is not a wrapper around PeerConnection it contains a PeerConnection.

我注意到这个问题不好回答,所以我想看看我能不能帮了一点。我看着源$ C ​​$ c和PeerConnectionClient是一个遥控器等非常辛苦codeD。您需要创建对象PeerConnection等的集合,而不是这一行:

I noticed this question wasn't answered so I wanted to see if I could help out a bit. I looked into the source code and PeerConnectionClient is very much hard coded for a single remote peer. You would need to create a collection of PeerConnection objects rather then this line:

private PeerConnection peerConnection;

如果你看看周围多一点,你会发现它变得更复杂一些的话

If you look around a bit more you would notice that it gets a bit more complicated then that.

在createPeerConnectionInternal的媒体流的逻辑只能做一次,你需要你的对象PeerConnection等之间共享数据流是这样的:

The mediaStream logic in createPeerConnectionInternal should only be done once and you need to share the stream between your PeerConnection objects like this:

peerConnection.addStream(mediaStream);

您可以咨询或看看此stackoverflow问题,以确认该PeerConnection等类型被设计为仅处理一个对等体。它也有些隐约暗示。

You can consult the WebRTC spec or take a look at this stackoverflow question to confirm that the PeerConnection type was designed to only handle one peer. It is also somewhat vaguely implied here.

所以,你只维护一个媒体流的对象:

So you only maintain one mediaStream object:

private MediaStream mediaStream;

所以,再一次的主要想法是MediaStream可对象和PeerConnection等众多对象作为你要连接到同行。所以,你将不会被使用多个PeerConnectionClient对象,而是修改单PeerConnectionClient封装多客户端的处理。如果你想要去的不管什么原因,你就只需要抽象的媒体流的逻辑(这只能一次创建的任何支持的类型)出来的多个PeerConnectionClient对象的设计。

So again the main idea is one MediaStream object and as many PeerConnection objects as you have peers you want to connect to. So you will not be using multiple PeerConnectionClient objects, but rather modify the single PeerConnectionClient to encapsulate the multi-client handling. If you do want to go with a design of multiple PeerConnectionClient objects for whatever reason you would just have to abstract the media stream logic (and any support types that should only be created once) out of it.

您还需要维护多个远程视频轨道而不是在现有的:

You will also need to maintain multiple remote video tracks rather then the existing one:

private VideoTrack remoteVideoTrack;

您显然只关心呈现一个本地的摄像头和远程连接创建多个渲染器。

You would obviously only care to render the one local camera and create multiple renderers for the remote connections.

我希望这是足够的信息让你回到正轨。

I hope this is enough information to get you back on track.

这篇关于如何实现3路电话会议视频聊天WebRTC技术原住民code为Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 02:08