@@ -168,38 +168,43 @@ bool stream_outlet_impl::wait_for_consumers(double timeout) {
168168 return send_buffer_->wait_for_consumers (timeout);
169169}
170170
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 ;
172174 if (timestamp == DEDUCED_TIMESTAMP) {
173- sync_buffs_.emplace_back (asio::buffer ( &TAG_DEDUCED_TIMESTAMP, 1 ) );
175+ sync_buffs_.emplace_back (&TAG_DEDUCED_TIMESTAMP, 1 );
174176 } 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 );
177181 }
178182}
179183
180184void stream_outlet_impl::pushthrough_sync () {
181185 // LOG_F(INFO, "Pushing %u buffers.", sync_buffs_.size());
182186 tcp_server_->write_all_blocking (sync_buffs_);
183187 sync_buffs_.clear ();
188+ sync_timestamps_.clear ();
184189}
185190
186191void stream_outlet_impl::enqueue_sync (
187- asio::const_buffer buff, const double & timestamp, bool pushthrough) {
192+ asio::const_buffer buff, double timestamp, bool pushthrough) {
188193 push_timestamp_sync (timestamp);
189194 sync_buffs_.push_back (buff);
190195 if (pushthrough) pushthrough_sync ();
191196}
192197
193198template <class T >
194199void 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 ();
198201 if (!do_sync_) {
202+ sample_p smp (
203+ sample_factory_->new_sample (timestamp, pushthrough));
199204 smp->assign_typed (data);
200205 send_buffer_->push_sample (smp);
201206 } else {
202- enqueue_sync (asio::buffer (data, smp ->datasize ()), smp-> timestamp , smp-> pushthrough );
207+ enqueue_sync (asio::buffer (data, sample_factory_ ->datasize ()), timestamp, pushthrough);
203208 }
204209}
205210
0 commit comments