From c3b707a0f441780ec7591a84572279b8cf26acd7 Mon Sep 17 00:00:00 2001 From: fyhertz Date: Sun, 9 Aug 2015 15:00:39 -0400 Subject: [PATCH] Two fixes in the RTSP client (RtspClient.java) proposed by Magnus Johnsson. --- .../streaming/rtsp/RtspClient.java | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/net/majorkernelpanic/streaming/rtsp/RtspClient.java b/src/net/majorkernelpanic/streaming/rtsp/RtspClient.java index d85fd4ec..cf745fb5 100644 --- a/src/net/majorkernelpanic/streaming/rtsp/RtspClient.java +++ b/src/net/majorkernelpanic/streaming/rtsp/RtspClient.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 GUIGUI Simon, fyhertz@gmail.com + * Copyright (C) 2011-2015 GUIGUI Simon, fyhertz@gmail.com * * This file is part of Spydroid (http://code.google.com/p/spydroid-ipcamera/) * @@ -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) { @@ -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 ! */ @@ -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"))); @@ -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) { @@ -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"))); @@ -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();