【问题标题】:new PeerConnectionFactory() gives error on androidnew PeerConnectionFactory() 在 android 上给出错误
【发布时间】:2015-06-12 12:43:25
【问题描述】:

我正在尝试在 Android 上实现 WebRTC DataChannel。我想创建一个简单的 peerconnection 对象,它将打开 DataChannel 以使用 WebRTC 通过网络发送数据。尝试创建 PeerConnection 对象时出现错误。我了解到我们使用工厂使用factory.createPeerConnection() 创建对等连接对象。

为此,我必须先创建 PeerConnectionFactory 对象。在此之后,我可以使用它来创建 PeerConnection 对象。当我尝试创建 PeerConnectionFactory 对象时,我收到错误 Could not find method android.media.MediaCodec.setParametersFatal Signal 11 (SIGSEGV) at 0x00000000 (code=1)。我还用PeerConnectionFactory.initializeAndroidGlobals(this, false, false, false); 尝试了以下代码,这就是我想要做的:

PeerConnectionFactory factory = new PeerConnectionFactory();

peer = new Peer();

这就是我的 Peer 对象的样子:

public class Peer implements SdpObserver, PeerConnection.Observer, DataChannel.Observer {

    private PeerConnection pc;
    private DataChannel dc;

    public Peer() {

      this.pc = factory.createPeerConnection(RTCConfig.getIceServer(), 
              RTCConfig.getMediaConstraints(), this);

      dc = this.pc.createDataChannel("sendDataChannel", new DataChannel.Init());

    }

    @Override
    public void onAddStream(MediaStream arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onDataChannel(DataChannel dataChannel) {
        this.dc = dataChannel;

    }

    @Override
    public void onIceCandidate(final IceCandidate candidate) {
        try {
            JSONObject payload = new JSONObject();
            payload.put("type", "candidate");
            payload.put("label", candidate.sdpMLineIndex);
            payload.put("id", candidate.sdpMid);
            payload.put("candidate", candidate.sdp);

            sendSocketMessageDataChannel(payload.toString());


          } catch (JSONException e) {
            e.printStackTrace();
          }

    }

    @Override
    public void onIceConnectionChange(IceConnectionState iceConnectionState) {

    }

    @Override
    public void onIceGatheringChange(IceGatheringState arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onRemoveStream(MediaStream arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onRenegotiationNeeded() {
        // TODO Auto-generated method stub

    }

    @Override
    public void onSignalingChange(SignalingState arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onCreateFailure(String msg) {
        Toast.makeText(getApplicationContext(),
                msg, Toast.LENGTH_SHORT)
                .show();

    }

    @Override
    public void onCreateSuccess(SessionDescription sdp) {
        try {

            JSONObject payload = new JSONObject();
            payload.put("type", sdp.type.canonicalForm());
            payload.put("sdp", sdp.description);

            sendSocketMessageDataChannel(payload.toString());

            pc.setLocalDescription(FilePeer.this, sdp);

          } catch (JSONException e) {
            e.printStackTrace();
          }

    }

    @Override
    public void onSetFailure(String arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onSetSuccess() {
        // TODO Auto-generated method stub

    }

    @Override
    public void onMessage(Buffer data) {
        Log.w("FILE", data.toString());

    }

    @Override
    public void onStateChange() {

        Toast.makeText(getApplicationContext(),
                "State Got Changed", Toast.LENGTH_SHORT)
                .show();

        /*
         byte[] bytes = new byte[10];

         bytes[0] = 0;
         bytes[1] = 1;
         bytes[2] = 2;
         bytes[3] = 3;
         bytes[4] = 4;
         bytes[5] = 5;
         bytes[6] = 6;
         bytes[7] = 7;
         bytes[8] = 8;
         bytes[9] = 9;

         ByteBuffer buf = ByteBuffer.wrap(bytes);



         Buffer b = new Buffer(buf, true);

         dc.send(b);
        */
    }

}

谁能指出我在 Android 上实现 DataChannel 的任何示例源代码?如果我没有以正确的方式做这件事,也请告诉我。我找不到说明如何操作的 Android Native WebRTC 文档。我正在尝试实现我从在 Web 上使用 WebRTC 中学到的任何东西。

如果我的问题不清楚,请告诉我。

【问题讨论】:

  • 你能做到吗?
  • 正在进行中。但是,我能够解决上述问题。我仍然需要一些示例应用程序来完成使用 Android 中的 DataChannel 发送文件。如果你能提供一个简单的示例代码,那将会很有帮助。谢谢。
  • 我也尝试为 DataChannels 构建一个 Hello World 应用程序,但到目前为止没有运气。

标签: android webrtc rtcdatachannel


【解决方案1】:

PeerConnectionFactory 不再需要初始化音频和视频引擎才能启用。

PeerConnectionFactory.initializeAndroidGlobals(this, false, false, false);

现在您将能够禁用音频和视频,并使用数据通道

【讨论】:

    【解决方案2】:

    这是 Android 的 WebRTC 代码中的一个已知错误。以下线程更多地讨论了这个错误:

    https://code.google.com/p/webrtc/issues/detail?id=3416 https://code.google.com/p/webrtc/issues/detail?id=3234

    该错误目前处于打开状态。但是,有一个可用的解决方法,现在可以使用。在 Android Globals 中,我们需要将音频和视频参数作为 true 传递:

    PeerConnectionFactory.initializeAndroidGlobals(getApplicationContext(), true, true, VideoRendererGui.getEGLContext());
    

    【讨论】:

    • 从@cutiehulk2329 的回答中,这个错误现在已经解决了。
    【解决方案3】:

    改用这个PeerConnectionFactory.initializeAndroidGlobals(acontext, TRUE, false, false, NULL);

    然后创建工厂。 factory = new PeerConnectionFactory();

    然后在您的 Peer 类中创建对等连接,如下所示:factory.createPeerConnection(iceServers, sdpMediaConstraints, this);

    这对我来说只为视频流建立了没有 EGLContext 的 DataChannel。

    更新:如果您仍然有此错误,请转到更新的版本!这是非常不推荐使用的。

    【讨论】:

      猜你喜欢
      • 2018-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多