From 4eb5dc4138ab384af32b7b332ccf682db65be5e7 Mon Sep 17 00:00:00 2001 From: Razican Date: Sat, 29 Aug 2015 20:11:48 +0200 Subject: [PATCH] Fixed #39 --- camera/Camera.cc | 18 ++++++++++++++++++ camera/Camera.h | 1 + 2 files changed, 19 insertions(+) diff --git a/camera/Camera.cc b/camera/Camera.cc index 495c1e2..06ce96c 100644 --- a/camera/Camera.cc +++ b/camera/Camera.cc @@ -167,6 +167,13 @@ bool Camera::stop() return true; } this->logger->log("Error stopping video recording."); + + if ( ! this->is_really_recording()) + { + this->logger->log("Warning: error was already stopped."); + this->recording = false; + return true; + } return false; #else this->logger->log("Test mode. Video recording stop simulated."); @@ -175,6 +182,17 @@ bool Camera::stop() #endif } +bool Camera::is_really_recording() const +{ + FILE* process = popen("pgrep raspivid", "r"); + char response[5]; + fgets(response, 5, process); + pclose(process); + + if (process == NULL) this->logger->log("Error checking if raspivid is really recording"); + return (process != NULL && response != NULL); +} + int os::get_file_count(const string& path) { DIR *dp; diff --git a/camera/Camera.h b/camera/Camera.h index bbd1fca..e2c00c2 100644 --- a/camera/Camera.h +++ b/camera/Camera.h @@ -17,6 +17,7 @@ namespace os { bool recording = false; Camera(); void record_thread(int time); + bool is_really_recording() const; public: Camera(Camera& copy) = delete; ~Camera();