rogue
Loading...
Searching...
No Matches
RateDrop.cpp
Go to the documentation of this file.
1
17#include "rogue/Directives.h"
18
20
21#include <stdint.h>
22#include <sys/time.h>
23
24#include <cstdio>
25#include <memory>
26
27#include "rogue/Logging.h"
31
33
34#ifndef NO_PYTHON
35 #include <boost/python.hpp>
36namespace bp = boost::python;
37#endif
38
40ris::RateDropPtr ris::RateDrop::create(bool period, double value) {
41 ris::RateDropPtr p = std::make_shared<ris::RateDrop>(period, value);
42 return (p);
43}
44
46void ris::RateDrop::setup_python() {
47#ifndef NO_PYTHON
48 bp::class_<ris::RateDrop, ris::RateDropPtr, bp::bases<ris::Master, ris::Slave>, boost::noncopyable>(
49 "RateDrop",
50 bp::init<bool, double>());
51#endif
52}
53
55ris::RateDrop::RateDrop(bool period, double value) : ris::Master(), ris::Slave() {
56 struct timeval currTime;
57 uint32_t per;
58
59 if ((!period) || value == 0) {
60 periodFlag_ = false;
61 dropCount_ = static_cast<uint32_t>(value);
62 dropTarget_ = static_cast<uint32_t>(value);
63 } else {
64 periodFlag_ = true;
65
66 per = static_cast<uint32_t>(value * 1e6);
67
68 div_t divResult = div(per, 1000000);
69 timePeriod_.tv_sec = divResult.quot;
70 timePeriod_.tv_usec = divResult.rem;
71
72 gettimeofday(&currTime, NULL);
73 timeradd(&currTime, &timePeriod_, &nextPeriod_);
74 }
75}
76
78ris::RateDrop::~RateDrop() {}
79
81void ris::RateDrop::acceptFrame(ris::FramePtr frame) {
82 struct timeval currTime;
83
84 // Dropping based upon frame count, if countPeriod_ is zero we never drop
85 if (!periodFlag_) {
86 if (dropCount_++ == dropTarget_) {
87 sendFrame(frame);
88 dropCount_ = 0;
89 }
90
91 // Dropping based upon time
92 } else {
93 gettimeofday(&currTime, NULL);
94
95 if (timercmp(&currTime, &(nextPeriod_), >)) {
96 sendFrame(frame);
97 timeradd(&currTime, &timePeriod_, &nextPeriod_);
98 }
99 }
100}
Stream master endpoint.
Definition Master.h:65
Stream slave endpoint and default frame pool.
Definition Slave.h:72
std::shared_ptr< rogue::interfaces::stream::RateDrop > RateDropPtr
Shared pointer alias for RateDrop.
Definition RateDrop.h:98
std::shared_ptr< rogue::interfaces::stream::Frame > FramePtr
Shared pointer alias for Frame.
Definition Frame.h:549