diff --git a/rtc/CaptureController/CaptureController.cpp b/rtc/CaptureController/CaptureController.cpp index 87461f6fde4..1ea0e0cd0a2 100644 --- a/rtc/CaptureController/CaptureController.cpp +++ b/rtc/CaptureController/CaptureController.cpp @@ -24,6 +24,8 @@ static const char* capturecontroller_spec[] = "language", "C++", "lang_type", "compile", // Configuration variables + "conf.default.frameRate", "1", + "conf.default.initialMode", "sleep", "" }; @@ -37,7 +39,6 @@ CaptureController::CaptureController(RTC::Manager* manager) m_CameraCaptureServicePort("CameraCaptureService"), m_CameraCaptureService(this), // - m_mode(SLEEP), dummy(0) { } @@ -53,6 +54,8 @@ RTC::ReturnCode_t CaptureController::onInitialize() std::cout << m_profile.instance_name << ": onInitialize()" << std::endl; // // Bind variables and configuration variable + bindParameter("frameRate", m_frameRate, "1"); + bindParameter("initialMode", m_initialMode, "sleep"); // @@ -105,6 +108,14 @@ RTC::ReturnCode_t CaptureController::onShutdown(RTC::UniqueId ec_id) RTC::ReturnCode_t CaptureController::onActivated(RTC::UniqueId ec_id) { std::cout << m_profile.instance_name<< ": onActivated(" << ec_id << ")" << std::endl; + m_tOld = (double)(coil::gettimeofday()); + if (m_initialMode == "continuous"){ + m_mode = CONTINUOUS; + }else if(m_initialMode == "oneshot"){ + m_mode = ONESHOT; + }else{ + m_mode = SLEEP; + } return RTC::RTC_OK; } @@ -117,11 +128,13 @@ RTC::ReturnCode_t CaptureController::onDeactivated(RTC::UniqueId ec_id) RTC::ReturnCode_t CaptureController::onExecute(RTC::UniqueId ec_id) { //std::cout << m_profile.instance_name<< ": onExecute(" << ec_id << ")" << m_data.data << std::endl; - - if (m_mode != SLEEP && m_imageIn.isNew()){ + double tNew = (double)(coil::gettimeofday()); + double dt = (double)(tNew - m_tOld); + if (m_mode != SLEEP && dt > 1.0/m_frameRate && m_imageIn.isNew()){ m_imageIn.read(); m_imageOut.write(); if (m_mode == ONESHOT) m_mode = SLEEP; + m_tOld = tNew; } return RTC::RTC_OK; diff --git a/rtc/CaptureController/CaptureController.h b/rtc/CaptureController/CaptureController.h index 0e183a6a4f1..bfde52e6ac3 100644 --- a/rtc/CaptureController/CaptureController.h +++ b/rtc/CaptureController/CaptureController.h @@ -139,6 +139,9 @@ class CaptureController private: typedef enum {SLEEP, ONESHOT, CONTINUOUS} mode; mode m_mode; + int m_frameRate; + double m_tOld; + std::string m_initialMode; int dummy; }; diff --git a/rtc/VideoCapture/VideoCapture.cpp b/rtc/VideoCapture/VideoCapture.cpp index d95d9ddb1b2..c3df077ed14 100644 --- a/rtc/VideoCapture/VideoCapture.cpp +++ b/rtc/VideoCapture/VideoCapture.cpp @@ -29,6 +29,7 @@ static const char* videocapture_spec[] = "conf.default.devIds", "0", "conf.default.width", "640", "conf.default.height", "480", + "conf.default.frameRate", "1", "" }; @@ -62,6 +63,7 @@ RTC::ReturnCode_t VideoCapture::onInitialize() bindParameter("devIds", m_devIds, "0"); bindParameter("width", m_width, "640"); bindParameter("height", m_height, "480"); + bindParameter("frameRate", m_frameRate, "1"); // @@ -113,6 +115,7 @@ RTC::ReturnCode_t VideoCapture::onShutdown(RTC::UniqueId ec_id) RTC::ReturnCode_t VideoCapture::onActivated(RTC::UniqueId ec_id) { std::cout << m_profile.instance_name<< ": onActivated(" << ec_id << ")" << std::endl; + m_tOld = (double)(coil::gettimeofday()); if (m_initialMode == "continuous"){ m_mode = CONTINUOUS; }else{ @@ -158,6 +161,14 @@ RTC::ReturnCode_t VideoCapture::onExecute(RTC::UniqueId ec_id) //std::cout << m_profile.instance_name<< ": onExecute(" << ec_id << ")" << std::endl; capture(); + double tNew = (double)(coil::gettimeofday()); + double dt = (double)(tNew - m_tOld); + if (dt > 1.0/m_frameRate){ + m_tOld = tNew; + }else{ + return RTC::RTC_OK; + } + if (m_mode == SLEEP) return RTC::RTC_OK; if (m_cameras.size() == 1){ diff --git a/rtc/VideoCapture/VideoCapture.h b/rtc/VideoCapture/VideoCapture.h index 9a30ca821f5..0db2e12e84a 100644 --- a/rtc/VideoCapture/VideoCapture.h +++ b/rtc/VideoCapture/VideoCapture.h @@ -145,7 +145,8 @@ class VideoCapture std::string m_initialMode; std::vector m_devIds; std::vector < v4l_capture * > m_cameras; - int m_width, m_height; + int m_width, m_height, m_frameRate; + double m_tOld; };