Skip to content

Commit

Permalink
Small bug fixes in RtspClient & VideoStream
Browse files Browse the repository at this point in the history
  • Loading branch information
fyhertz committed Oct 21, 2013
1 parent 05dd8f7 commit cc38d92
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
42 changes: 18 additions & 24 deletions src/net/majorkernelpanic/streaming/rtsp/RtspClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public class RtspClient {
private String mPath;
private String mSessionID;
private String mAuthorization;
private String mRtspServerName;
private Session mSession;
private BufferedReader mBufferedReader;
private OutputStream mOutputStream;
Expand All @@ -81,6 +80,10 @@ public void setSession(Session session) {
mSession = session;
}

public Session getSession() {
return mSession;
}

/**
* Sets the destination address of the RTSP server.
* @param host The destination address
Expand Down Expand Up @@ -110,8 +113,9 @@ public void setStreamPath(String path) {
mPath = path;
}

public synchronized boolean isRunning() {
return mRunning;
public synchronized boolean isStreaming() {
if (mSession == null) return false;
return mSession.isStreaming();
}

/**
Expand Down Expand Up @@ -159,8 +163,6 @@ public synchronized void startStream(int retries) throws RuntimeException, Illeg
*/
public synchronized void stopStream() {

if (!mRunning) return;

try {
sendRequestTeardown();
} catch (Exception ignore) {}
Expand Down Expand Up @@ -188,7 +190,7 @@ private void sendRequestAnnounce() throws IllegalStateException, SocketException
mOutputStream.write(request.getBytes("UTF-8"));
Response response = Response.parseResponse(mBufferedReader);

mRtspServerName = response.headers.get("server");
Log.v(TAG,"RTSP Server:" + response.headers.get("server"));

try {
Matcher m = Response.rexegSession.matcher(response.headers.get("session"));
Expand Down Expand Up @@ -290,22 +292,10 @@ private void sendRequestTeardown() throws IOException {
}

private String addHeaders() {
String delimiter = "\r\n";
/*if (mRtspServerName != null && mRtspServerName.contains("Wowza")) {
Log.e(TAG,mRtspServerName);
// On certain versions of Wowza it appears that this is necessary
try {
Pattern regex = Pattern.compile("build(\\d+)",Pattern.CASE_INSENSITIVE);
Matcher matcher = regex.matcher(mRtspServerName);
if (Integer.parseInt(matcher.group(1))<5334) {
delimiter = "\r\n\r\n";
}
} catch (Exception ignore) {ignore.printStackTrace();}
}*/
return "CSeq: " + (++mCSeq) + "\r\n" +
"Content-Length: 0\r\n" +
"Session: " + mSessionID + "\r\n" +
"Authorization: " + mAuthorization+ delimiter;
"Authorization: " + mAuthorization + "\r\n\r\n";
}

final protected static char[] hexArray = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
Expand Down Expand Up @@ -360,11 +350,15 @@ public static Response parseResponse(BufferedReader input) throws IOException, I
response.status = Integer.parseInt(matcher.group(1));

// Parsing headers of the request
while ( (line = input.readLine()) != null && line.length()>3 ) {
//Log.e(TAG,line);
matcher = rexegHeader.matcher(line);
matcher.find();
response.headers.put(matcher.group(1).toLowerCase(Locale.US),matcher.group(2));
while ( (line = input.readLine()) != null) {
//Log.e(TAG,"l: "+line.length()+"c: "+line);
if (line.length()>3) {
matcher = rexegHeader.matcher(line);
matcher.find();
response.headers.put(matcher.group(1).toLowerCase(Locale.US),matcher.group(2));
} else {
break;
}
}
if (line==null) throw new SocketException("Connection lost");

Expand Down
7 changes: 2 additions & 5 deletions src/net/majorkernelpanic/streaming/video/VideoStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,8 @@ public synchronized void setPreviewDisplay(SurfaceHolder surfaceHolder) {
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
mSurfaceReady = false;
if (VideoStream.this.mStreaming) {
VideoStream.this.stop();
Log.d(TAG,"Surface destroyed: video streaming stopped.");
}
if (mCamera != null) stopPreview();
stopPreview();
Log.d(TAG,"Surface destroyed !");
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
Expand Down

0 comments on commit cc38d92

Please sign in to comment.