From bcb7166b75f92de16abd12c8d38b020f8fa9b888 Mon Sep 17 00:00:00 2001 From: stan Date: Fri, 5 Dec 2008 23:14:37 +0000 Subject: [PATCH] Better handling of RTP stream and thread death. git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@2704 e3e1d417-86f3-4887-817a-d78f3d33393f --- src/zm_remote_camera_rtsp.cpp | 2 ++ src/zm_rtp_data.cpp | 1 + src/zm_rtsp.cpp | 4 ++-- src/zm_rtsp.h | 4 ++++ src/zmc.cpp | 5 ++++- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/zm_remote_camera_rtsp.cpp b/src/zm_remote_camera_rtsp.cpp index c63d20a5f..02f5713c2 100644 --- a/src/zm_remote_camera_rtsp.cpp +++ b/src/zm_remote_camera_rtsp.cpp @@ -173,6 +173,8 @@ int RemoteCameraRtsp::PostCapture( Image &image ) while ( true ) { buffer.clear(); + if ( rtspThread->stopped() ) + break; if ( rtspThread->getFrame( buffer ) ) { Debug( 3, "Read frame %d bytes", buffer.size() ); diff --git a/src/zm_rtp_data.cpp b/src/zm_rtp_data.cpp index 368d876f4..fd7cf6b01 100644 --- a/src/zm_rtp_data.cpp +++ b/src/zm_rtp_data.cpp @@ -87,6 +87,7 @@ int RtpDataThread::run() if ( readable.size() == 0 ) { Error( "RTP timed out" ); + mStop = true; break; } for ( Select::CommsList::iterator iter = readable.begin(); iter != readable.end(); iter++ ) diff --git a/src/zm_rtsp.cpp b/src/zm_rtsp.cpp index 9a24fe3f4..691578b67 100644 --- a/src/zm_rtsp.cpp +++ b/src/zm_rtsp.cpp @@ -487,8 +487,8 @@ int RtspThread::run() rtpDataThread.stop(); rtpCtrlThread.stop(); - rtpDataThread.kill( SIGTERM ); - rtpCtrlThread.kill( SIGTERM ); + //rtpDataThread.kill( SIGTERM ); + //rtpCtrlThread.kill( SIGTERM ); rtpDataThread.join(); rtpCtrlThread.join(); diff --git a/src/zm_rtsp.h b/src/zm_rtsp.h index 73ace9492..b51e81c72 100644 --- a/src/zm_rtsp.h +++ b/src/zm_rtsp.h @@ -124,6 +124,10 @@ public: { mStop = true; } + bool stopped() const + { + return( mStop ); + } }; #endif // ZM_RTSP_H diff --git a/src/zmc.cpp b/src/zmc.cpp index b2f8e0a7c..6176a7444 100644 --- a/src/zmc.cpp +++ b/src/zmc.cpp @@ -211,6 +211,7 @@ int main( int argc, char *argv[] ) alarm_capture_delays[i] = monitors[i]->GetAlarmCaptureDelay(); } + int result = 0; struct timeval now; struct DeltaTimeval delta_time; while( !zm_terminate ) @@ -249,12 +250,14 @@ int main( int argc, char *argv[] ) { Error( "Failed to pre-capture monitor %d", i ); zm_terminate = true; + result = -1; break; } if ( monitors[i]->PostCapture() < 0 ) { Error( "Failed to post-capture monitor %d", i ); zm_terminate = true; + result = -1; break; } @@ -281,5 +284,5 @@ int main( int argc, char *argv[] ) delete [] next_delays; delete [] last_capture_times; - return( 0 ); + return( result ); }