@@ -169,38 +169,43 @@ bool stream_outlet_impl::wait_for_consumers(double timeout) {
169169 return send_buffer_->wait_for_consumers (timeout);
170170}
171171
172- void stream_outlet_impl::push_timestamp_sync (const double ×tamp) {
172+ void stream_outlet_impl::push_timestamp_sync (double timestamp) {
173+ static_assert (TAG_TRANSMITTED_TIMESTAMP == 2 , " Unexpected TAG_TRANSMITTED_TIMESTAMP" );
174+ const uint64_t ENDIAN_SAFE_TAG_TRANSMITTED = (2LL << 28 ) | 2LL ;
173175 if (timestamp == DEDUCED_TIMESTAMP) {
174- sync_buffs_.emplace_back (asio::buffer ( &TAG_DEDUCED_TIMESTAMP, 1 ) );
176+ sync_buffs_.emplace_back (&TAG_DEDUCED_TIMESTAMP, 1 );
175177 } else {
176- sync_buffs_.emplace_back (asio::buffer (&TAG_TRANSMITTED_TIMESTAMP, 1 ));
177- sync_buffs_.emplace_back (asio::buffer (×tamp, sizeof (timestamp)));
178+ sync_timestamps_.emplace_back (ENDIAN_SAFE_TAG_TRANSMITTED, timestamp);
179+ // add a pointer to the memory region containing |TAG_TRANSMITTED_TIMESTAMP|timestamp
180+ // one byte for the tag, 8 for the timestamp
181+ sync_buffs_.emplace_back (reinterpret_cast <const char *>(&sync_timestamps_.back ()) + 7 , 9 );
178182 }
179183}
180184
181185void stream_outlet_impl::pushthrough_sync () {
182186 // LOG_F(INFO, "Pushing %u buffers.", sync_buffs_.size());
183187 tcp_server_->write_all_blocking (sync_buffs_);
184188 sync_buffs_.clear ();
189+ sync_timestamps_.clear ();
185190}
186191
187192void stream_outlet_impl::enqueue_sync (
188- asio::const_buffer buff, const double & timestamp, bool pushthrough) {
193+ asio::const_buffer buff, double timestamp, bool pushthrough) {
189194 push_timestamp_sync (timestamp);
190195 sync_buffs_.push_back (buff);
191196 if (pushthrough) pushthrough_sync ();
192197}
193198
194199template <class T >
195200void stream_outlet_impl::enqueue (const T *data, double timestamp, bool pushthrough) {
196- if (lsl::api_config::get_instance ()->force_default_timestamps ()) timestamp = 0.0 ;
197- sample_p smp (
198- sample_factory_->new_sample (timestamp == 0.0 ? lsl_clock () : timestamp, pushthrough));
201+ if (timestamp == 0.0 || lsl::api_config::get_instance ()->force_default_timestamps ()) timestamp = lsl_local_clock ();
199202 if (!do_sync_) {
203+ sample_p smp (
204+ sample_factory_->new_sample (timestamp, pushthrough));
200205 smp->assign_typed (data);
201206 send_buffer_->push_sample (smp);
202207 } else {
203- enqueue_sync (asio::buffer (data, smp ->datasize ()), smp-> timestamp , smp-> pushthrough );
208+ enqueue_sync (asio::buffer (data, sample_factory_ ->datasize ()), timestamp, pushthrough);
204209 }
205210}
206211
0 commit comments