Skip to content

Commit

Permalink
enables to control frame rate
Browse files Browse the repository at this point in the history
  • Loading branch information
fkanehiro committed Oct 27, 2014
1 parent c889449 commit aa6a20e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
19 changes: 16 additions & 3 deletions rtc/CaptureController/CaptureController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ static const char* capturecontroller_spec[] =
"language", "C++",
"lang_type", "compile",
// Configuration variables
"conf.default.frameRate", "1",
"conf.default.initialMode", "sleep",

""
};
Expand All @@ -37,7 +39,6 @@ CaptureController::CaptureController(RTC::Manager* manager)
m_CameraCaptureServicePort("CameraCaptureService"),
m_CameraCaptureService(this),
// </rtc-template>
m_mode(SLEEP),
dummy(0)
{
}
Expand All @@ -53,6 +54,8 @@ RTC::ReturnCode_t CaptureController::onInitialize()
std::cout << m_profile.instance_name << ": onInitialize()" << std::endl;
// <rtc-template block="bind_config">
// Bind variables and configuration variable
bindParameter("frameRate", m_frameRate, "1");
bindParameter("initialMode", m_initialMode, "sleep");

// </rtc-template>

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions rtc/CaptureController/CaptureController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
11 changes: 11 additions & 0 deletions rtc/VideoCapture/VideoCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",

""
};
Expand Down Expand Up @@ -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");

// </rtc-template>

Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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){
Expand Down
3 changes: 2 additions & 1 deletion rtc/VideoCapture/VideoCapture.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ class VideoCapture
std::string m_initialMode;
std::vector<int> m_devIds;
std::vector < v4l_capture * > m_cameras;
int m_width, m_height;
int m_width, m_height, m_frameRate;
double m_tOld;
};


Expand Down

0 comments on commit aa6a20e

Please sign in to comment.