diff --git a/src/zm_analysis_thread.cpp b/src/zm_analysis_thread.cpp index 261f0e18f..94ed09d03 100644 --- a/src/zm_analysis_thread.cpp +++ b/src/zm_analysis_thread.cpp @@ -11,11 +11,15 @@ AnalysisThread::~AnalysisThread() { } int AnalysisThread::run() { + Debug(2, "In run"); useconds_t analysis_rate = monitor->GetAnalysisRate(); + Debug(2, "after getanalysisrate"); unsigned int analysis_update_delay = monitor->GetAnalysisUpdateDelay(); + Debug(2, "after getanalysisUpdateDelay"); time_t last_analysis_update_time, cur_time; monitor->UpdateAdaptiveSkip(); + Debug(2, "after UpdateAdaptiveSkip"); last_analysis_update_time = time(0); Debug(2, "THREAD: Getting ref image"); diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index b562125d3..4f9f42fea 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -206,10 +206,6 @@ int FfmpegCamera::PostCapture() { int FfmpegCamera::OpenFfmpeg() { Debug ( 2, "OpenFfmpeg called." ); - uint32_t last_event_id = monitor->GetLastEventId() ; - uint32_t video_writer_event_id = monitor->GetVideoWriterEventId(); - Debug(2, "last_event(%d), our current (%d)", last_event_id, video_writer_event_id ); - int ret; mOpenStart = time(NULL); @@ -221,10 +217,12 @@ int FfmpegCamera::OpenFfmpeg() { if ( av_open_input_file( &mFormatContext, mPath.c_str(), NULL, 0, NULL ) != 0 ) #else // Handle options - AVDictionary *opts = 0; + AVDictionary *opts = NULL; ret = av_dict_parse_string(&opts, Options().c_str(), "=", ",", 0); if ( ret < 0 ) { - Warning("Could not parse ffmpeg input options list '%s'\n", Options().c_str()); + Warning("Could not parse ffmpeg input options list '%s'", Options().c_str()); + } else { + Debug(2,"Could not parse ffmpeg input options list '%s'", Options().c_str()); } // Set transport method as specified by method field, rtpUni is default @@ -243,25 +241,12 @@ int FfmpegCamera::OpenFfmpeg() { Warning("Could not set rtsp_transport method '%s'\n", method.c_str()); } - Debug ( 1, "Calling avformat_open_input for %s", mPath.c_str() ); + Debug ( 1, "Calling avformat_alloc_context for %s", mPath.c_str() ); - last_event_id = monitor->GetLastEventId() ; - video_writer_event_id = monitor->GetVideoWriterEventId(); - Debug(2, "last_event(%d), our current (%d), mpath (%s)", last_event_id, video_writer_event_id, mPath.c_str() ); mFormatContext = avformat_alloc_context( ); - last_event_id = monitor->GetLastEventId() ; - video_writer_event_id = monitor->GetVideoWriterEventId(); - Debug(2, "last_event(%d), our current (%d), mpath (%s)", last_event_id, video_writer_event_id, mPath.c_str() ); - //mFormatContext->interrupt_callback.callback = FfmpegInterruptCallback; - //mFormatContext->interrupt_callback.opaque = this; - // Speed up find_stream_info - //FIXME can speed up initial analysis but need sensible parameters... - //mFormatContext->probesize = 32; - //mFormatContext->max_analyze_duration = 32; - last_event_id = monitor->GetLastEventId() ; - video_writer_event_id = monitor->GetVideoWriterEventId(); - Debug(2, "last_event(%d), our current (%d), mpath (%s)", last_event_id, video_writer_event_id, mPath.c_str() ); + monitor->GetLastEventId() ; + Debug(2, "before avformat_open_input" ); if ( avformat_open_input( &mFormatContext, mPath.c_str(), NULL, &opts ) != 0 ) #endif @@ -270,15 +255,15 @@ int FfmpegCamera::OpenFfmpeg() { Error( "Unable to open input %s due to: %s", mPath.c_str(), strerror(errno) ); return -1; } + Debug(2, "afte avformat_open_input" ); + monitor->GetLastEventId() ; AVDictionaryEntry *e = NULL; while ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != NULL ) { Warning( "Option %s not recognized by ffmpeg", e->key); } - last_event_id = monitor->GetLastEventId() ; - video_writer_event_id = monitor->GetVideoWriterEventId(); - Debug(2, "last_event(%d), our current (%d)", last_event_id, video_writer_event_id ); + monitor->GetLastEventId() ; mIsOpening = false; Debug ( 1, "Opened input" ); @@ -397,12 +382,13 @@ int FfmpegCamera::OpenFfmpeg() { } else { Debug(1, "Video Found decoder"); zm_dump_stream_format(mFormatContext, mVideoStreamId, 0, 0); - // Open the codec + + // Open the codec #if !LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 8, 0) - Debug ( 1, "Calling avcodec_open" ); - if ( avcodec_open(mVideoCodecContext, mVideoCodec) < 0 ){ + Debug ( 1, "Calling avcodec_open" ); + if ( avcodec_open(mVideoCodecContext, mVideoCodec) < 0 ){ #else - Debug ( 1, "Calling avcodec_open2" ); + Debug ( 1, "Calling video avcodec_open2" ); if ( avcodec_open2(mVideoCodecContext, mVideoCodec, &opts) < 0 ) { #endif AVDictionaryEntry *e = NULL; diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 2b2af06b9..8fe1e0d1e 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -769,10 +769,11 @@ uint32_t Monitor::GetLastEventId() const { // This function is crap. double Monitor::GetFPS() const { int index1 = shared_data->last_write_index; - if ( index1 == image_buffer_count ) { + if ( index1 >= image_buffer_count ) { // last_write_index only has this value on startup before capturing anything. return 0.0; } + Debug(2, "index1(%d)", index1); ZMPacket *snap1 = &image_buffer[index1]; if ( !snap1->timestamp->tv_sec ) { // This should be impossible @@ -783,6 +784,7 @@ double Monitor::GetFPS() const { int image_count = image_buffer_count; int index2 = (index1+1)%image_buffer_count; + Debug(2, "index2(%d)", index2); ZMPacket *snap2 = &image_buffer[index2]; // the timestamp pointers are initialized on connection, so that's redundant // tv_sec is probably only zero during the first loop of capturing, so this basically just counts the unused images. diff --git a/src/zm_thread.cpp b/src/zm_thread.cpp index 1232ac5f0..fe0b9ecb1 100644 --- a/src/zm_thread.cpp +++ b/src/zm_thread.cpp @@ -263,6 +263,7 @@ void *Thread::mThreadFunc( void *arg ) thisPtr->mThreadCondition.signal(); thisPtr->mThreadMutex.unlock(); thisPtr->mRunning = true; + Debug(2,"Runnning"); thisPtr->status = thisPtr->run(); thisPtr->mRunning = false; Debug( 2, "Exiting thread, status %p", (void *)&(thisPtr->status) );