在Android中构建视频聊天应用程序

时间:2018-06-24 12:53:17

标签: android rtsp

大家好,希望您过得愉快。我正在尝试在基于xmpp的应用程序中实现视频聊天。

我尝试使用的方法是:

客户端A>服务器(泵)>客户端B

经过数周的信息收集和测试,我最终得到了以下信息:

  • 大多数移动用户都位于对称NAT之后,因此实现udp服务器毫无意义

  • TCP连接不会逐帧发送数据,因此客户端B不知道如何使用它们

  • 数据需要使用H264 NAL压缩,并且可能需要4个字节的TCP标头,因此您必须让客户端B知道它们

我尝试实现RTSP服务器,但是默认情况下它使用udp,我不知道如何配置客户端和服务器以切换到TCP

 else if (request.method.equalsIgnoreCase("SETUP")) {
                Pattern p;
                Matcher m;
                int p2, p1, ssrc, trackId, src[];
                String destination;

                p = Pattern.compile("trackID=(\\w+)", 
Pattern.CASE_INSENSITIVE);
                m = p.matcher(request.uri);

                if (!m.find()) {
                    Log.i("bbbb","bad request");
                    response.status = Response.STATUS_BAD_REQUEST;
                    return response;
                }

                trackId = Integer.parseInt(m.group(1));

                if (!mSession.trackExists(trackId)) {
                    Log.i("bbbb","track exists");
                    response.status = Response.STATUS_NOT_FOUND;
                    return response;
                }

                p = Pattern.compile("client_port=(\\d+)-(\\d+)", 
Pattern.CASE_INSENSITIVE);
                m = p.matcher(request.headers.get("transport"));

                if (!m.find()) {
                    int[] ports = 
mSession.getTrack(trackId).getDestinationPorts();
                    p1 = ports[0];
                    p2 = ports[1];
                } else {
                    p1 = Integer.parseInt(m.group(1));
                    p2 = Integer.parseInt(m.group(2));
                }

                ssrc = mSession.getTrack(trackId).getSSRC();
                src = mSession.getTrack(trackId).getLocalPorts();
                destination = mSession.getDestination();

                mSession.getTrack(trackId).setDestinationPorts(p1, p2);

                boolean streaming = isStreaming();
                Log.i("oooo",""+mSession.getAudioTrack());
                mSession.syncStart(trackId);

                if (!streaming && isStreaming()) {
                    postMessage(MESSAGE_STREAMING_STARTED);
                }

                Log.i("bbbb","destination "+destination);

                response.attributes = "Transport: RTP/AVP/UDP;" + 
(InetAddress.getByName(destination).isMulticastAddress() ? "multicast" : 
"unicast") +
                        ";destination=" + mSession.getDestination() +
                        ";client_port=" + p1 + "-" + p2 +
                        ";server_port=" + src[0] + "-" + src[1] +
                        ";ssrc=" + Integer.toHexString(ssrc) +
                        ";mode=play\r\n" +
                        "Session: " + "1185d20035702ca" + "\r\n" +
                        "Cache-Control: no-cache\r\n";
                response.status = Response.STATUS_OK;

                Log.i("bbbb",response.attributes);


                response.status = Response.STATUS_OK;
//this is some sort of UDP hole punching , can we do that?
            }

所以我不知道如何完成此操作(我不在乎使用公共协议) 我已经尝试了好几个星期,但我什至不知道从哪里开始,请你们分享一下您的一些经验吗?多谢

0 个答案:

没有答案