Some cleanups in disconnect
This commit is contained in:
parent
a56d78bb04
commit
a82247b105
|
@ -1021,16 +1021,13 @@ bool Monitor::connect() {
|
||||||
} // Monitor::connect
|
} // Monitor::connect
|
||||||
|
|
||||||
bool Monitor::disconnect() {
|
bool Monitor::disconnect() {
|
||||||
if ( !mem_ptr )
|
if (mem_ptr == nullptr)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
#if ZM_MEM_MAPPED
|
#if ZM_MEM_MAPPED
|
||||||
if ( mem_ptr > (void *)0 ) {
|
|
||||||
msync(mem_ptr, mem_size, MS_ASYNC);
|
msync(mem_ptr, mem_size, MS_ASYNC);
|
||||||
munmap(mem_ptr, mem_size);
|
munmap(mem_ptr, mem_size);
|
||||||
}
|
if (map_fd >= 0) close(map_fd);
|
||||||
if ( map_fd >= 0 )
|
|
||||||
close(map_fd);
|
|
||||||
|
|
||||||
map_fd = -1;
|
map_fd = -1;
|
||||||
mem_ptr = nullptr;
|
mem_ptr = nullptr;
|
||||||
|
@ -1062,10 +1059,7 @@ bool Monitor::disconnect() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif // ZM_MEM_MAPPED
|
#endif // ZM_MEM_MAPPED
|
||||||
if ( event ) {
|
|
||||||
Info( "%s: image_count:%d - Closing event %" PRIu64 ", shutting down", name, image_count, event->Id() );
|
|
||||||
closeEvent();
|
|
||||||
}
|
|
||||||
if (image_buffer) {
|
if (image_buffer) {
|
||||||
for ( int i = 0; i < image_buffer_count; i++ ) {
|
for ( int i = 0; i < image_buffer_count; i++ ) {
|
||||||
// We delete the image because it is an object pointing to space that won't be free'd.
|
// We delete the image because it is an object pointing to space that won't be free'd.
|
||||||
|
@ -1078,34 +1072,29 @@ bool Monitor::disconnect() {
|
||||||
image_buffer = nullptr;
|
image_buffer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} // end bool Monitor::disconnect()
|
} // end bool Monitor::disconnect()
|
||||||
|
|
||||||
Monitor::~Monitor() {
|
Monitor::~Monitor() {
|
||||||
Close();
|
Close();
|
||||||
|
|
||||||
if ( mem_ptr ) {
|
if (mem_ptr != nullptr) {
|
||||||
|
std::lock_guard<std::mutex> lck(event_mutex);
|
||||||
if (event) {
|
if (event) {
|
||||||
Info("%s: image_count:%d - Closing event %" PRIu64 ", shutting down", name, image_count, event->Id());
|
Info("%s: image_count:%d - Closing event %" PRIu64 ", shutting down", name, image_count, event->Id());
|
||||||
closeEvent();
|
closeEvent();
|
||||||
}
|
}
|
||||||
if ( purpose == ANALYSIS ) {
|
if (purpose != QUERY) {
|
||||||
shared_data->state = state = IDLE;
|
shared_data->state = state = IDLE;
|
||||||
// I think we set it to the count so that it is technically 1 behind capture, which starts at 0
|
|
||||||
shared_data->last_read_index = image_buffer_count;
|
shared_data->last_read_index = image_buffer_count;
|
||||||
shared_data->last_read_time = 0;
|
shared_data->last_read_time = 0;
|
||||||
|
|
||||||
if ( Event::PreAlarmCount() )
|
|
||||||
Event::EmptyPreAlarmFrames();
|
|
||||||
} else if ( purpose == CAPTURE ) {
|
|
||||||
shared_data->valid = false;
|
shared_data->valid = false;
|
||||||
memset(mem_ptr, 0, mem_size);
|
memset(mem_ptr, 0, mem_size);
|
||||||
if ( (deinterlacing & 0xff) == 4 ) {
|
if ( (deinterlacing & 0xff) == 4 ) {
|
||||||
delete next_buffer.image;
|
delete next_buffer.image;
|
||||||
delete next_buffer.timestamp;
|
delete next_buffer.timestamp;
|
||||||
}
|
}
|
||||||
}
|
} // end if purpose != query
|
||||||
disconnect();
|
disconnect();
|
||||||
} // end if mem_ptr
|
} // end if mem_ptr
|
||||||
|
|
||||||
|
@ -2950,18 +2939,10 @@ int Monitor::PrimeCapture() {
|
||||||
int Monitor::PreCapture() const { return camera->PreCapture(); }
|
int Monitor::PreCapture() const { return camera->PreCapture(); }
|
||||||
int Monitor::PostCapture() const { return camera->PostCapture(); }
|
int Monitor::PostCapture() const { return camera->PostCapture(); }
|
||||||
int Monitor::Close() {
|
int Monitor::Close() {
|
||||||
if (camera)
|
if (camera) camera->Close();
|
||||||
camera->Close();
|
|
||||||
packetqueue.clear();
|
packetqueue.clear();
|
||||||
#if 0
|
|
||||||
if ( packetqueue ) {
|
|
||||||
delete packetqueue;
|
|
||||||
packetqueue = nullptr;
|
|
||||||
analysis_it = nullptr; // deleted by packetqueue
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return 1;
|
return 1;
|
||||||
};
|
}
|
||||||
Monitor::Orientation Monitor::getOrientation() const { return orientation; }
|
Monitor::Orientation Monitor::getOrientation() const { return orientation; }
|
||||||
|
|
||||||
// Wait for camera to get an image, and then assign it as the base reference image.
|
// Wait for camera to get an image, and then assign it as the base reference image.
|
||||||
|
|
Loading…
Reference in New Issue