Skip to content

Commit 80b07ae

Browse files
committed
Adjust seen_samples for dejittering when flushing samples from an inlet, i.e. not pulling them (#117)
1 parent 10ba931 commit 80b07ae

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

src/stream_inlet_impl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,11 @@ class stream_inlet_impl {
305305
std::size_t samples_available() { return data_receiver_.samples_available(); }
306306

307307
/// Flush the queue, return the number of dropped samples
308-
uint32_t flush() { return data_receiver_.flush(); }
308+
uint32_t flush() {
309+
int nskipped = data_receiver_.flush();
310+
postprocessor_.skip_samples(nskipped);
311+
return nskipped;
312+
}
309313

310314
/** Query whether the clock was potentially reset since the last call to was_clock_reset().
311315
*

src/time_postprocessor.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ double time_postprocessor::process_timestamp(double value) {
4545
return process_internal(value);
4646
}
4747

48+
void time_postprocessor::skip_samples(uint32_t skipped_samples) {
49+
if (options_ & proc_dejitter && dejitter.smoothing_applicable())
50+
dejitter.samples_since_t0_ += skipped_samples;
51+
}
52+
4853
double time_postprocessor::process_internal(double value) {
4954
// --- clock synchronization ---
5055
if (options_ & proc_clocksync) {

src/time_postprocessor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class time_postprocessor {
6161
/// Override the half-time (forget factor) of the time-stamp smoothing.
6262
void smoothing_halftime(float value) { halftime_ = value; }
6363

64+
/// Inform the post processor some samples were skipped
65+
void skip_samples(uint32_t skipped_samples);
66+
6467
private:
6568
/// Internal function to process a time stamp.
6669
double process_internal(double value);

testing/test_ext_DataType.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <catch2/catch.hpp>
44
#include <cstdint>
55
#include <lsl_cpp.h>
6+
#include <thread>
67

78
TEMPLATE_TEST_CASE(
89
"datatransfer", "[datatransfer][basic]", char, int16_t, int32_t, int64_t, float, double) {
@@ -69,3 +70,35 @@ TEST_CASE("TypeConversion", "[datatransfer][types][basic]") {
6970
CHECK(result == val);
7071
}
7172
}
73+
74+
TEST_CASE("Flush", "[datatransfer][basic]") {
75+
Streampair sp{create_streampair(
76+
lsl::stream_info("FlushTest", "flush", 1, 1, lsl::cf_double64, "FlushTest"))};
77+
sp.in_.set_postprocessing(lsl::post_dejitter);
78+
79+
const int n=20;
80+
81+
std::thread pusher([&](){
82+
double data = lsl::local_clock();
83+
for(int i=0; i<n; ++i) {
84+
sp.out_.push_sample(&data, data, true);
85+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
86+
data+=.1;
87+
}
88+
});
89+
90+
double data_in, ts_in;
91+
ts_in = sp.in_.pull_sample(&data_in, 1.);
92+
REQUIRE(ts_in == Approx(data_in));
93+
std::this_thread::sleep_for(std::chrono::milliseconds(700));
94+
int pulled = sp.in_.flush() + 1;
95+
96+
for(; pulled < n; ++pulled) {
97+
INFO(pulled);
98+
ts_in = sp.in_.pull_sample(&data_in, 1.);
99+
REQUIRE(ts_in == Approx(data_in));
100+
}
101+
102+
pusher.join();
103+
//sp.in_.set_postprocessing(lsl::post_none);
104+
}

0 commit comments

Comments
 (0)