Skip to content

Commit c3b707a

Browse files
author
fyhertz
committed
Two fixes in the RTSP client (RtspClient.java) proposed by Magnus Johnsson.
1 parent 39ead53 commit c3b707a

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

src/net/majorkernelpanic/streaming/rtsp/RtspClient.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2011-2014 GUIGUI Simon, [email protected]
2+
* Copyright (C) 2011-2015 GUIGUI Simon, [email protected]
33
*
44
* This file is part of Spydroid (http://code.google.com/p/spydroid-ipcamera/)
55
*
@@ -186,9 +186,9 @@ public void setServerAddress(String host, int port) {
186186
}
187187

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

220220
/**
221221
* Connects to the RTSP server to publish the stream, and the effectively starts streaming.
222-
* You need to call {@link #setServerAddress(String, int)} and optionnally {@link #setSession(Session)}
222+
* You need to call {@link #setServerAddress(String, int)} and optionally {@link #setSession(Session)}
223223
* and {@link #setCredentials(String, String)} before calling this.
224224
* Should be called of the main thread !
225225
*/
@@ -323,7 +323,7 @@ private void sendRequestAnnounce() throws IllegalStateException, SocketException
323323
String request = "ANNOUNCE rtsp://"+mParameters.host+":"+mParameters.port+mParameters.path+" RTSP/1.0\r\n" +
324324
"CSeq: " + (++mCSeq) + "\r\n" +
325325
"Content-Length: " + body.length() + "\r\n" +
326-
"Content-Type: application/sdp \r\n\r\n" +
326+
"Content-Type: application/sdp\r\n\r\n" +
327327
body;
328328
Log.i(TAG,request.substring(0, request.indexOf("\r\n")));
329329

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

340-
try {
341-
Matcher m = Response.rexegSession.matcher(response.headers.get("session"));
342-
m.find();
343-
mSessionID = m.group(1);
344-
} catch (Exception e) {
345-
throw new IOException("Invalid response from server. Session id: "+mSessionID);
340+
if (response.headers.containsKey("session")) {
341+
try {
342+
Matcher m = Response.rexegSession.matcher(response.headers.get("session"));
343+
m.find();
344+
mSessionID = m.group(1);
345+
} catch (Exception e) {
346+
throw new IOException("Invalid response from server. Session id: "+mSessionID);
347+
}
346348
}
347349

348350
if (response.status == 401) {
@@ -371,7 +373,7 @@ private void sendRequestAnnounce() throws IllegalStateException, SocketException
371373
"Content-Length: " + body.length() + "\r\n" +
372374
"Authorization: " + mAuthorization + "\r\n" +
373375
"Session: " + mSessionID + "\r\n" +
374-
"Content-Type: application/sdp \r\n\r\n" +
376+
"Content-Type: application/sdp\r\n\r\n" +
375377
body;
376378

377379
Log.i(TAG,request.substring(0, request.indexOf("\r\n")));
@@ -407,6 +409,17 @@ private void sendRequestSetup() throws IllegalStateException, SocketException, I
407409
mOutputStream.flush();
408410
Response response = Response.parseResponse(mBufferedReader);
409411
Matcher m;
412+
413+
if (response.headers.containsKey("session")) {
414+
try {
415+
m = Response.rexegSession.matcher(response.headers.get("session"));
416+
m.find();
417+
mSessionID = m.group(1);
418+
} catch (Exception e) {
419+
throw new IOException("Invalid response from server. Session id: "+mSessionID);
420+
}
421+
}
422+
410423
if (mParameters.transport == TRANSPORT_UDP) {
411424
try {
412425
m = Response.rexegTransport.matcher(response.headers.get("transport")); m.find();

0 commit comments

Comments
 (0)