@@ -141,9 +141,9 @@ void data_collector::save_data_to_file(const string& out_filename)
141141 }
142142}
143143
144- void data_collector::collect_frame_attributes (rs2::frame f, std::chrono::time_point<std::chrono::high_resolution_clock> start_time )
144+ void data_collector::collect_frame_attributes (rs2::frame f)
145145{
146- auto arrival_time = std::chrono::duration<double , std::milli>(chrono::high_resolution_clock::now () - start_time );
146+ auto arrival_time = std::chrono::duration<double , std::milli>(chrono::high_resolution_clock::now () - _start_time );
147147 auto stream_uid = std::make_pair (f.get_profile ().stream_type (), f.get_profile ().stream_index ());
148148
149149 if (data_collection[stream_uid].size () < _max_frames)
@@ -173,13 +173,13 @@ void data_collector::collect_frame_attributes(rs2::frame f, std::chrono::time_po
173173 }
174174}
175175
176- bool data_collector::collecting (std::chrono::time_point<std::chrono::high_resolution_clock> start_time )
176+ bool data_collector::collecting ()
177177{
178178 bool timed_out = false ;
179179
180180 if (_time_out_sec > 0 )
181181 {
182- timed_out = (chrono::high_resolution_clock::now () - start_time ) > std::chrono::seconds (_time_out_sec);
182+ timed_out = (chrono::high_resolution_clock::now () - _start_time ) > std::chrono::seconds (_time_out_sec);
183183 // When the timeout is the only option is specified, disregard frame number
184184 if (stop_on_timeout == _stop_cond)
185185 return !timed_out;
@@ -234,6 +234,7 @@ bool data_collector::parse_configuration(const std::string& line, const std::vec
234234// Assign the user configuration to the selected device
235235bool data_collector::configure_sensors ()
236236{
237+ _start_time = chrono::high_resolution_clock::now ();
237238 bool succeed = false ;
238239 requests_to_go = user_requests;
239240 std::vector<rs2::stream_profile> matches;
@@ -278,6 +279,7 @@ bool data_collector::configure_sensors()
278279 {
279280 std::copy (matches.begin (), matches.end (), std::back_inserter (selected_stream_profiles));
280281 sensor.open (matches);
282+ sensor.start ([this ](rs2::frame f) { collect_frame_attributes (f); }); // start right after open sensor, required on DDS to avoid reverting to default
281283 active_sensors.emplace_back (sensor);
282284 matches.clear ();
283285 }
@@ -361,28 +363,18 @@ int main(int argc, char** argv) try
361363
362364 dc.parse_and_configure (config_file);
363365
364- // data_collection buffer;
365- auto start_time = chrono::high_resolution_clock::now ();
366-
367- // Start streaming
368- for (auto && sensor : dc.selected_sensors ())
369- sensor.start ([&dc,&start_time](rs2::frame f)
370- {
371- dc.collect_frame_attributes (f,start_time);
372- });
373-
374366 std::cout << " \n Data collection started.... \n " << std::endl;
375367
376- while (dc.collecting (start_time ))
368+ while (dc.collecting ())
377369 {
378370 std::this_thread::sleep_for (std::chrono::seconds (1 ));
379371 std::cout << " Collecting data for "
380- << chrono::duration_cast<chrono::seconds>( chrono::high_resolution_clock::now () - start_time). count ()
372+ << dc. time_passed ()
381373 << " sec" << std::endl;
382374 }
383375
384376 // Stop & flush all active sensors
385- for (auto && sensor : dc.selected_sensors () )
377+ for (auto && sensor : dc.active_sensors )
386378 {
387379 sensor.stop ();
388380 sensor.close ();
0 commit comments