@@ -168,38 +168,43 @@ bool stream_outlet_impl::wait_for_consumers(double timeout) {
168
168
return send_buffer_->wait_for_consumers (timeout);
169
169
}
170
170
171
- void stream_outlet_impl::push_timestamp_sync (const double ×tamp) {
171
+ void stream_outlet_impl::push_timestamp_sync (double timestamp) {
172
+ static_assert (TAG_TRANSMITTED_TIMESTAMP == 2 , " Unexpected TAG_TRANSMITTED_TIMESTAMP" );
173
+ const uint64_t ENDIAN_SAFE_TAG_TRANSMITTED = (2LL << 28 ) | 2LL ;
172
174
if (timestamp == DEDUCED_TIMESTAMP) {
173
- sync_buffs_.emplace_back (asio::buffer ( &TAG_DEDUCED_TIMESTAMP, 1 ) );
175
+ sync_buffs_.emplace_back (&TAG_DEDUCED_TIMESTAMP, 1 );
174
176
} else {
175
- sync_buffs_.emplace_back (asio::buffer (&TAG_TRANSMITTED_TIMESTAMP, 1 ));
176
- sync_buffs_.emplace_back (asio::buffer (×tamp, sizeof (timestamp)));
177
+ sync_timestamps_.emplace_back (ENDIAN_SAFE_TAG_TRANSMITTED, timestamp);
178
+ // add a pointer to the memory region containing |TAG_TRANSMITTED_TIMESTAMP|timestamp
179
+ // one byte for the tag, 8 for the timestamp
180
+ sync_buffs_.emplace_back (reinterpret_cast <const char *>(&sync_timestamps_.back ()) + 7 , 9 );
177
181
}
178
182
}
179
183
180
184
void stream_outlet_impl::pushthrough_sync () {
181
185
// LOG_F(INFO, "Pushing %u buffers.", sync_buffs_.size());
182
186
tcp_server_->write_all_blocking (sync_buffs_);
183
187
sync_buffs_.clear ();
188
+ sync_timestamps_.clear ();
184
189
}
185
190
186
191
void stream_outlet_impl::enqueue_sync (
187
- asio::const_buffer buff, const double & timestamp, bool pushthrough) {
192
+ asio::const_buffer buff, double timestamp, bool pushthrough) {
188
193
push_timestamp_sync (timestamp);
189
194
sync_buffs_.push_back (buff);
190
195
if (pushthrough) pushthrough_sync ();
191
196
}
192
197
193
198
template <class T >
194
199
void stream_outlet_impl::enqueue (const T *data, double timestamp, bool pushthrough) {
195
- if (lsl::api_config::get_instance ()->force_default_timestamps ()) timestamp = 0.0 ;
196
- sample_p smp (
197
- sample_factory_->new_sample (timestamp == 0.0 ? lsl_clock () : timestamp, pushthrough));
200
+ if (timestamp == 0.0 || lsl::api_config::get_instance ()->force_default_timestamps ()) timestamp = lsl_local_clock ();
198
201
if (!do_sync_) {
202
+ sample_p smp (
203
+ sample_factory_->new_sample (timestamp, pushthrough));
199
204
smp->assign_typed (data);
200
205
send_buffer_->push_sample (smp);
201
206
} else {
202
- enqueue_sync (asio::buffer (data, smp ->datasize ()), smp-> timestamp , smp-> pushthrough );
207
+ enqueue_sync (asio::buffer (data, sample_factory_ ->datasize ()), timestamp, pushthrough);
203
208
}
204
209
}
205
210
0 commit comments