コード例 #1
0
  private int newSendRequestAnnounce() throws IOException, InterruptedException {
    String body = mParameters.session.getSessionDescription();
    String request =
        "ANNOUNCE rtsp://"
            + mParameters.host
            + ":"
            + mParameters.port
            + mParameters.path
            + " RTSP/1.0\r\n"
            + "CSeq: "
            + (++mCSeq)
            + "\r\n"
            + "Content-Length: "
            + body.length()
            + "\r\n"
            + "Content-Type: application/sdp \r\n\r\n"
            + body;
    log.info(request.substring(0, request.indexOf("\r\n")));

    Response response = mRtpThread.requestWithResponse(request);
    if (response == null) {
      throw new IOException("response of announce is null!");
    }
    return response.status;
  }
コード例 #2
0
 private int newSendRequestPlay() throws IOException, InterruptedException {
   String request =
       "PLAY rtsp://"
           + mParameters.host
           + ":"
           + mParameters.port
           + mParameters.path
           + " RTSP/1.0\r\n"
           + "Range: npt=0.000-\r\n"
           + addHeaders();
   log.info(request.substring(0, request.indexOf("\r\n")));
   Response response = mRtpThread.requestWithResponse(request);
   if (response == null) {
     throw new IOException("response of play is null!");
   }
   return response.status;
 }
コード例 #3
0
  private void newSendRequestSetup() throws IOException, InterruptedException {
    int interleaved = 0;
    for (int i = 0; i < 2; i++) {
      Stream stream = mParameters.session.getTrack(i);
      if (stream != null) {
        String tcp_inter =
            "/TCP;unicast;mode=receive;interleaved="
                + 2 * interleaved
                + "-"
                + (2 * interleaved + 1);
        String params =
            mParameters.transport == TRANSPORT_TCP
                ? tcp_inter
                : (";unicast;mode=record;client_port=" + (5000 + 2 * i) + "-" + (5000 + 2 * i + 1));
        String request =
            "SETUP rtsp://"
                + mParameters.host
                + ":"
                + mParameters.port
                + mParameters.path
                + "/trackID="
                + i
                + " RTSP/1.0\r\n"
                + "Transport: RTP/AVP"
                + params
                + "\r\n"
                + addHeaders();

        log.info(request.substring(0, request.indexOf("\r\n")));

        Response response = mRtpThread.requestWithResponse(request);
        if (response == null) {
          throw new IOException("response of setup is null!");
        }
        try {
          Matcher m = Response.rexegSession.matcher(response.headers.get("session"));
          m.find();
          mSessionID = m.group(1);
        } catch (Exception e) {
          // throw new
          // IOException("Invalid response from server. Session id: "+mSessionID);
          // mSessionID = "0";
          e.printStackTrace();
        }

        Matcher m;
        if (mParameters.transport == TRANSPORT_UDP) {
          try {
            m = Response.rexegTransport.matcher(response.headers.get("transport"));
            m.find();
            stream.setDestinationPorts(Integer.parseInt(m.group(3)), Integer.parseInt(m.group(4)));
            // log.debug("Setting destination ports: " + Integer.parseInt(m.group(3)) + ", " +
            // Integer.parseInt(m.group(4)));
          } catch (Exception e) {
            e.printStackTrace();
            int[] ports = stream.getDestinationPorts();
            // log.debug("Server did not specify ports, using default ports: " + ports[0] + "-" +
            // ports[1]);
          }
        } else {
          stream.setConsumer(mRtpThread, (byte) (2 * interleaved));
        }
        interleaved++;
      }
    }
  }