新的PeerConnectionFactory()在android上出错

时间:2015-04-07 19:30:27

标签: android webrtc rtcdatachannel

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

为此,我必须首先创建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所学到的一切。

请告诉我,如果我的问题不明确。

3 个答案:

答案 0 :(得分:6)

这是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());

答案 1 :(得分:5)

PeerConnectionFactory不再需要初始化音频&要启用的视频引擎。

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

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

答案 2 :(得分:2)

使用此代替var urlString: String = "https://website.com/åbo_beach.jpg".stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())! guard let url = URL(string: urlString) else { // String can not yield a valid URL; do someting! return } URLSession.shared.dataTask(with: url, completionHandler: { (data, response, error) -> Void in // ... }).resume()

然后创建工厂。 PeerConnectionFactory.initializeAndroidGlobals(acontext, TRUE, false, false, NULL);

然后在你的班级Peer中创建对等连接:factory = new PeerConnectionFactory();

这对我来说只能建立没有用于视频流的EGLContext的DataChannel。

更新:如果您仍有此错误,请转到较新版本!这是非常弃用的。