Skip to content

Commit

Permalink
Two fixes in the RTSP client (RtspClient.java) proposed by Magnus Joh…
Browse files Browse the repository at this point in the history
…nsson.
  • Loading branch information
fyhertz committed Aug 9, 2015
1 parent 39ead53 commit c3b707a
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions src/net/majorkernelpanic/streaming/rtsp/RtspClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011-2014 GUIGUI Simon, [email protected]
* Copyright (C) 2011-2015 GUIGUI Simon, [email protected]
*
* This file is part of Spydroid (http://code.google.com/p/spydroid-ipcamera/)
*
Expand Down Expand Up @@ -186,9 +186,9 @@ public void setServerAddress(String host, int port) {
}

/**
* If authentication is enabled on the server, you need to call this with a valid username/password pair.
* If authentication is enabled on the server, you need to call this with a valid login/password pair.
* Only implements Digest Access Authentication according to RFC 2069.
* @param username The username
* @param username The login
* @param password The password
*/
public void setCredentials(String username, String password) {
Expand Down Expand Up @@ -219,7 +219,7 @@ public boolean isStreaming() {

/**
* Connects to the RTSP server to publish the stream, and the effectively starts streaming.
* You need to call {@link #setServerAddress(String, int)} and optionnally {@link #setSession(Session)}
* You need to call {@link #setServerAddress(String, int)} and optionally {@link #setSession(Session)}
* and {@link #setCredentials(String, String)} before calling this.
* Should be called of the main thread !
*/
Expand Down Expand Up @@ -323,7 +323,7 @@ private void sendRequestAnnounce() throws IllegalStateException, SocketException
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" +
"Content-Type: application/sdp\r\n\r\n" +
body;
Log.i(TAG,request.substring(0, request.indexOf("\r\n")));

Expand All @@ -337,12 +337,14 @@ private void sendRequestAnnounce() throws IllegalStateException, SocketException
Log.v(TAG,"RTSP server name unknown");
}

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);
if (response.headers.containsKey("session")) {
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);
}
}

if (response.status == 401) {
Expand Down Expand Up @@ -371,7 +373,7 @@ private void sendRequestAnnounce() throws IllegalStateException, SocketException
"Content-Length: " + body.length() + "\r\n" +
"Authorization: " + mAuthorization + "\r\n" +
"Session: " + mSessionID + "\r\n" +
"Content-Type: application/sdp \r\n\r\n" +
"Content-Type: application/sdp\r\n\r\n" +
body;

Log.i(TAG,request.substring(0, request.indexOf("\r\n")));
Expand Down Expand Up @@ -407,6 +409,17 @@ private void sendRequestSetup() throws IllegalStateException, SocketException, I
mOutputStream.flush();
Response response = Response.parseResponse(mBufferedReader);
Matcher m;

if (response.headers.containsKey("session")) {
try {
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);
}
}

if (mParameters.transport == TRANSPORT_UDP) {
try {
m = Response.rexegTransport.matcher(response.headers.get("transport")); m.find();
Expand Down

1 comment on commit c3b707a

@dhirajtiwari1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to use this lib class ?

Please sign in to comment.