From ba425edd0f4869641ef843c20bb15c2a689f5c33 Mon Sep 17 00:00:00 2001 From: SteveGilvarry Date: Mon, 12 Jan 2015 20:42:17 +1000 Subject: [PATCH] Convert from event_directory to event file as per Video branch --- src/zm_event.cpp | 3 ++- src/zm_event.h | 4 ++-- src/zm_ffmpeg_camera.cpp | 20 ++++++++--------- src/zm_monitor.cpp | 47 ++++++++++++++++++++-------------------- src/zm_monitor.h | 2 +- 5 files changed, 37 insertions(+), 39 deletions(-) diff --git a/src/zm_event.cpp b/src/zm_event.cpp index 72909685b..3908e43f8 100755 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -167,7 +167,8 @@ Event::Event( Monitor *p_monitor, struct timeval p_start_time, const std::string video_name[0] = 0; /* Save as video */ - if ( monitor->GetOptVideoWriter() == 1 ) { + + if ( monitor->GetOptVideoWriter() != 0 ) { int nRet; snprintf( video_name, sizeof(video_name), "%d-%s", id, "video.mp4" ); snprintf( video_file, sizeof(video_file), video_file_format, path, video_name ); diff --git a/src/zm_event.h b/src/zm_event.h index 0393ca9f3..7b1bca24c 100755 --- a/src/zm_event.h +++ b/src/zm_event.h @@ -159,8 +159,8 @@ public: return( Event::getSubPath( localtime( time ) ) ); } - char* getEventDirectory(void){ - return path; + char* getEventFile(void){ + return video_file; } public: diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index c1a247129..156f0793a 100755 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -470,7 +470,7 @@ void *FfmpegCamera::ReopenFfmpegThreadCallback(void *ctx){ } //Function to handle capture and store -int FfmpegCamera::CaptureAndRecord( Image &image, bool recording, char* event_directory ) +int FfmpegCamera::CaptureAndRecord( Image &image, bool recording, char* event_file ) { AVPacket packet; uint8_t* directbuffer; @@ -514,29 +514,27 @@ int FfmpegCamera::CaptureAndRecord( Image &image, bool recording, char* event_di //Video recording if(recording && !wasRecording){ //Instantiate the video storage module - char fileName[4096]; - snprintf(fileName, sizeof(fileName), "%s/event.mp4", event_directory); - videoStore = new VideoStore((const char *)fileName, "mp4", mFormatContext->streams[mVideoStreamId],mAudioStreamId==-1?NULL:mFormatContext->streams[mAudioStreamId],startTime); + + videoStore = new VideoStore((const char *)event_file, "mp4", mFormatContext->streams[mVideoStreamId],mAudioStreamId==-1?NULL:mFormatContext->streams[mAudioStreamId],startTime); wasRecording = true; - strcpy(oldDirectory, event_directory); + strcpy(oldDirectory, event_file); }else if(!recording && wasRecording && videoStore){ - Warning("Deleting videoStore instance"); + Info("Deleting videoStore instance"); delete videoStore; videoStore = NULL; } //The directory we are recording to is no longer tied to the current event. Need to re-init the videostore with the correct directory and start recording again - if(recording && wasRecording && (strcmp(oldDirectory, event_directory)!=0) && (packet.flags & AV_PKT_FLAG_KEY) ){ //don't open new videostore until we're on a key frame..would this require an offset adjustment for the event as a result?...if we store our key frame location with the event will that be enough? + if(recording && wasRecording && (strcmp(oldDirectory, event_file)!=0) && (packet.flags & AV_PKT_FLAG_KEY) ){ //don't open new videostore until we're on a key frame..would this require an offset adjustment for the event as a result?...if we store our key frame location with the event will that be enough? Info("Re-starting video storage module"); if(videoStore){ delete videoStore; videoStore = NULL; } - char fileName[4096]; - snprintf(fileName, sizeof(fileName), "%s/event.mp4", event_directory); - videoStore = new VideoStore((const char *)fileName, "mp4", mFormatContext->streams[mVideoStreamId],mAudioStreamId==-1?NULL:mFormatContext->streams[mAudioStreamId],startTime); - strcpy(oldDirectory, event_directory); + + videoStore = new VideoStore((const char *)event_file, "mp4", mFormatContext->streams[mVideoStreamId],mAudioStreamId==-1?NULL:mFormatContext->streams[mAudioStreamId],startTime); + strcpy(oldDirectory, event_file); } if(videoStore && recording){ diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index fefcb8688..837264360 100755 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -417,7 +417,7 @@ Monitor::Monitor( trigger_data->trigger_showtext[0] = 0; shared_data->valid = true; video_store_data->recording = false; - snprintf(video_store_data->event_directory, sizeof(video_store_data->event_directory), "nothing"); + snprintf(video_store_data->event_file, sizeof(video_store_data->event_file), "nothing"); video_store_data->size = sizeof(VideoStoreData); //video_store_data->frameNumber = 0; } else if ( purpose == ANALYSIS ) { @@ -1397,7 +1397,7 @@ bool Monitor::Analyse() if ( event ) { //TODO: We shouldn't have to do this every time. Not sure why it clears itself if this isn't here?? - snprintf(video_store_data->event_directory, sizeof(video_store_data->event_directory), "%s", event->getEventDirectory()); + snprintf(video_store_data->event_file, sizeof(video_store_data->event_file), "%s", event->getEventFile()); int section_mod = timestamp->tv_sec%section_length; if ( section_mod < last_section_mod ) @@ -1427,7 +1427,7 @@ bool Monitor::Analyse() event = new Event( this, *timestamp, "Continuous", noteSetMap, videoRecording ); shared_data->last_event = event->Id(); //set up video store data - snprintf(video_store_data->event_directory, sizeof(video_store_data->event_directory), "%s", event->getEventDirectory()); + snprintf(video_store_data->event_file, sizeof(video_store_data->event_file), "%s", event->getEventFile()); video_store_data->recording = true; Info( "%s: %03d - Opening new event %d, section start", name, image_count, event->Id() ); @@ -1489,7 +1489,7 @@ bool Monitor::Analyse() event = new Event( this, *(image_buffer[pre_index].timestamp), cause, noteSetMap, videoRecording ); shared_data->last_event = event->Id(); //set up video store data - snprintf(video_store_data->event_directory, sizeof(video_store_data->event_directory), "%s", event->getEventDirectory()); + snprintf(video_store_data->event_file, sizeof(video_store_data->event_file), "%s", event->getEventFile()); video_store_data->recording = true; Info( "%s: %03d - Opening new event %d, alarm start", name, image_count, event->Id() ); @@ -2862,38 +2862,37 @@ Debug( 1, "Got %d for v4l_captures_per_frame", v4l_captures_per_frame ); int Monitor::Capture() { - static int FirstCapture = 1; - int captureResult; + static int FirstCapture = 1; + int captureResult; - int index = image_count%image_buffer_count; - Image* capture_image = image_buffer[index].image; + int index = image_count%image_buffer_count; + Image* capture_image = image_buffer[index].image; - if ( (deinterlacing & 0xff) == 4) { - if ( FirstCapture != 1 ) { - /* Copy the next image into the shared memory */ - capture_image->CopyBuffer(*(next_buffer.image)); - } + if ( (deinterlacing & 0xff) == 4) { + if ( FirstCapture != 1 ) { + /* Copy the next image into the shared memory */ + capture_image->CopyBuffer(*(next_buffer.image)); + } - /* Capture a new next image */ + /* Capture a new next image */ //Check if FFMPEG camera if((GetOptVideoWriter() == 2) && camera->SupportsNativeVideo()){ - captureResult = camera->CaptureAndRecord(*(next_buffer.image), video_store_data->recording, video_store_data->event_directory); + captureResult = camera->CaptureAndRecord(*(next_buffer.image), video_store_data->recording, video_store_data->event_file); }else{ captureResult = camera->Capture(*(next_buffer.image)); } - - - if ( FirstCapture ) { - FirstCapture = 0; - return 0; - } - - } else { + + if ( FirstCapture ) { + FirstCapture = 0; + return 0; + } + + } else { //Check if FFMPEG camera if((GetOptVideoWriter() == 2) && camera->SupportsNativeVideo()){ //Warning("ZMC: Recording: %d", video_store_data->recording); - captureResult = camera->CaptureAndRecord(*capture_image, video_store_data->recording, video_store_data->event_directory); + captureResult = camera->CaptureAndRecord(*capture_image, video_store_data->recording, video_store_data->event_file); }else{ /* Capture directly into image buffer, avoiding the need to memcpy() */ captureResult = camera->Capture(*capture_image); diff --git a/src/zm_monitor.h b/src/zm_monitor.h index 000f9b370..f5099f9c8 100644 --- a/src/zm_monitor.h +++ b/src/zm_monitor.h @@ -159,7 +159,7 @@ protected: typedef struct { uint32_t size; - char event_directory[4096]; + char event_file[4096]; uint32_t recording; //bool arch dependent so use uint32 instead //uint32_t frameNumber;