Skip to content

Commit fbb4909

Browse files
committed
testing
1 parent 7dfb528 commit fbb4909

6 files changed

Lines changed: 97 additions & 44 deletions

File tree

examples/C/color/rs-color.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ int main()
7474
exit(EXIT_FAILURE);
7575
}
7676

77+
unsigned long long old_frame_number = -1LL;
78+
rs2_time_t old_frame_timestamp = 0;
79+
7780
while (1) // Until user presses Ctrl+C
7881
{
7982
// This call waits until a new composite_frame is available
@@ -86,6 +89,7 @@ int main()
8689
int num_of_frames = rs2_embedded_frames_count(frames, &e);
8790
check_error(e);
8891

92+
8993
int i;
9094
for (i = 0; i < num_of_frames; ++i)
9195
{
@@ -110,17 +114,23 @@ int main()
110114
rs2_metadata_type frame_metadata_time_of_arrival = rs2_get_frame_metadata(frame, RS2_FRAME_METADATA_TIME_OF_ARRIVAL, &e);
111115
check_error(e);
112116

113-
printf("RGB frame arrived.\n");
114-
printf("First 10 bytes: ");
115-
int i;
116-
for(i=0; i < 10; ++i)
117-
printf("%02x ", rgb_frame_data[i]);
118-
119-
printf("\nFrame No: %llu\n", frame_number);
120-
printf("Timestamp: %f\n", frame_timestamp);
121-
printf("Timestamp domain: %s\n", frame_timestamp_domain_str);
122-
printf("Time of arrival: %lld\n\n", frame_metadata_time_of_arrival);
117+
if (!(frame_number%1000)) {
118+
printf("RGB frame arrived.\n");
119+
printf("First 10 bytes: ");
120+
int i;
121+
for(i=0; i < 10; ++i)
122+
printf("%02x ", rgb_frame_data[i]);
123+
124+
printf("\nFrame No: %llu/%llu\n", frame_number, old_frame_number);
125+
printf("Timestamp: %f/%f\n", frame_timestamp, old_frame_timestamp);
126+
printf("Timestamp domain: %s\n", frame_timestamp_domain_str);
127+
printf("Time of arrival: %lld\n\n", frame_metadata_time_of_arrival);
128+
}
123129
rs2_release_frame(frame);
130+
if (old_frame_number == frame_number) exit(1);
131+
if (old_frame_timestamp == frame_timestamp) exit(2);
132+
old_frame_number = frame_number;
133+
old_frame_timestamp = frame_timestamp;
124134
}
125135

126136
rs2_release_frame(frames);

examples/capture/rs-capture.cpp

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,75 @@
1-
// License: Apache 2.0. See LICENSE file in root directory.
2-
// Copyright(c) 2017 RealSense, Inc. All Rights Reserved.
1+
// License: Apache 2.0. See LICENSE file in root directory.
2+
// Copyright(c) 2017 Intel Corporation. All Rights Reserved.
33

4+
#include <chrono>
5+
#include <iostream>
46
#include <librealsense2/rs.hpp> // Include RealSense Cross Platform API
7+
#include <map>
58
#include "example.hpp" // Include short list of convenience functions for rendering
69

710
// Capture Example demonstrates how to
811
// capture depth and color video streams and render them to the screen
912
int main(int argc, char * argv[]) try
1013
{
11-
rs2::log_to_console(RS2_LOG_SEVERITY_ERROR);
14+
std::map<rs2_stream, std::pair<rs2_metadata_type, rs2_metadata_type>> old;
15+
rs2::log_to_file(RS2_LOG_SEVERITY_DEBUG, "rs-capture.log");
1216
// Create a simple OpenGL window for rendering:
13-
window app(1280, 720, "RealSense Capture Example");
14-
15-
// Declare depth colorizer for pretty visualization of depth data
16-
rs2::colorizer color_map;
17-
// Declare rates printer for showing streaming rates of the enabled streams.
18-
rs2::rates_printer printer;
17+
// window app(1280, 720, "RealSense Capture Example");
1918

2019
// Declare RealSense pipeline, encapsulating the actual device and sensors
2120
rs2::pipeline pipe;
22-
rs2::config cfg;
23-
24-
// Enable all camera streams
25-
cfg.enable_all_streams();
2621

2722
// Start streaming with default recommended configuration
2823
// The default video configuration contains Depth and Color streams
2924
// If a device is capable to stream IMU data, both Gyro and Accelerometer are enabled by default
25+
rs2::config cfg;
26+
cfg.enable_stream(RS2_STREAM_DEPTH);
27+
cfg.enable_stream(RS2_STREAM_COLOR);
28+
cfg.enable_stream(RS2_STREAM_INFRARED);
29+
30+
if (argc > 1) {
31+
cfg.enable_device(argv[1]);
32+
}
3033
pipe.start(cfg);
3134

32-
while (app) // Application still alive?
35+
int idx = 1;
36+
while (true) // Application still alive?
3337
{
34-
rs2::frameset data = pipe.wait_for_frames(). // Wait for next set of frames from the camera
35-
apply_filter(printer). // Print each enabled stream frame rate
36-
apply_filter(color_map); // Find and colorize the depth data
38+
//rs2::frameset data = pipe.wait_for_frames(). // Wait for next set of frames from the camera
39+
const rs2::frameset& fset = pipe.wait_for_frames();
40+
// std::cout << std::endl << "----- CLOCK:" << std::chrono::steady_clock::now().time_since_epoch().count() << "ns" << std::endl;
41+
const size_t nf = fset.size();
42+
int i = 1;
43+
44+
fset.foreach_rs([&idx, &old, &i, nf] (const rs2::frame& f) {
45+
static int ne = 0;
46+
auto fs = f.get_profile().stream_type();
47+
auto fc = f.get_frame_metadata(RS2_FRAME_METADATA_FRAME_COUNTER);
48+
auto ft = f.get_frame_metadata(RS2_FRAME_METADATA_FRAME_TIMESTAMP);
49+
// auto fr = f.get_frame_metadata(RS2_FRAME_METADATA_CRC);
50+
//char path[64];
51+
//sprintf(path, "S%d-%d.bin", (int)fs, (int)idx);
52+
if (i == 1) std::cout << std::endl << idx << '.';
53+
std::cout << '\t' << i++ << '/' << nf << '\t' << fs << ':' << fc << '/' << ft;
54+
try {
55+
const auto& ofs = old.at(fs);
56+
if (!(fc > ofs.first && ft > ofs.second)) {
57+
std::cout << std::endl << "!!!/" << ++ne << ":\t\t" << fs << ':' << ofs.first << '/' << ofs.second << std::endl;
58+
// for (const auto& rec:old) std::cout << "\t" << rec.first << ":" << rec.second.first << '/' << rec.second.second;
59+
if (ne > 10) exit(EXIT_FAILURE);
60+
}
61+
} catch(...) {}
62+
old[fs].first = fc;
63+
old[fs].second = ft;
64+
//auto fo = fopen(path, "wb+");
65+
//fwrite(fd, f.get_data_size(), 1, fo);
66+
//fclose(fo);
67+
});
68+
idx++;
3769

3870
// The show method, when applied on frameset, break it to frames and upload each frame into a gl textures
3971
// Each texture is displayed on different viewport according to it's stream unique id
40-
app.show(data);
72+
// app.show(data);
4173
}
4274

4375
return EXIT_SUCCESS;

scripts/rs-enum.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ declare -A camera_names=( [depth]=depth [rgb]=color [ir]=ir [imu]=imu )
8787
camera_vid=("depth" "depth-md" "color" "color-md" "ir" "ir-md" "imu")
8888

8989

90-
mdev=$(${v4l2_util} --list-devices | grep -A1 tegra | grep media)
90+
mdev=$(${v4l2_util} --list-devices | grep media)
9191

9292
# For Jetson we have `simple` method
9393
if [ -n "${mdev}" ]; then

src/sensor.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ void log_callback_end( uint32_t fps,
332332

333333
// update additional data
334334
additional_data.timestamp = timestamp_reader->get_frame_timestamp(fr);
335-
additional_data.last_frame_number = last_frame_number;
336335
additional_data.frame_number = timestamp_reader->get_frame_counter(fr);
337336
fr->additional_data = additional_data;
338337

src/stream.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,17 @@ namespace librealsense
9393
void create_snapshot(std::shared_ptr<stream_profile_interface>& snapshot) const override;
9494
void enable_recording(std::function<void(const stream_profile_interface&)> record_action) override;
9595

96+
rs2_metadata_type getLastFrame() { return _last_frame; }
97+
void setLastFrame(rs2_metadata_type last_frame ) { _last_frame = last_frame; }
98+
99+
rs2_metadata_type getLastTimestamp() { return _last_timestamp; }
100+
void setLastTimestamp(rs2_metadata_type last_timestamp ) { _last_timestamp = last_timestamp; }
96101
private:
97102
int _index = 1;
98103
int _uid = 0;
99104
rs2_stream _type = RS2_STREAM_ANY;
105+
rs2_metadata_type _last_frame = 0;
106+
rs2_metadata_type _last_timestamp = 0;
100107
rs2_format _format = RS2_FORMAT_ANY;
101108
uint32_t _framerate = 0;
102109
int _tag = profile_tag::PROFILE_TAG_ANY;

src/uvc-sensor.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,9 @@ void uvc_sensor::open( const stream_profiles & requests )
116116
auto && req_profile_base = std::dynamic_pointer_cast< stream_profile_base >( req_profile );
117117
try
118118
{
119-
unsigned long long last_frame_number = 0;
120-
rs2_time_t last_timestamp = 0;
121119
_device->probe_and_commit(
122120
req_profile_base->get_backend_profile(),
123-
[this, req_profile_base, req_profile, last_frame_number, last_timestamp](
121+
[this, req_profile_base, req_profile](
124122
platform::stream_profile p,
125123
platform::frame_object f,
126124
std::function< void() > continuation ) mutable
@@ -135,6 +133,9 @@ void uvc_sensor::open( const stream_profiles & requests )
135133
<< f.backend_time << " " << system_time );
136134
return;
137135
}
136+
auto last_frame_number = req_profile_base->getLastFrame();
137+
auto last_timestamp = req_profile_base->getLastTimestamp();
138+
LOG_DEBUG( "[WOJTEK] last_frame_number/" << req_profile_base->get_stream_type() << ": " << last_frame_number);
138139

139140
auto && fr = generate_frame_from_data( f,
140141
system_time,
@@ -160,24 +161,28 @@ void uvc_sensor::open( const stream_profiles & requests )
160161
fr->additional_data.frame_number = ++_accel_counter;
161162
else if( stream_type == 2 ) // 2 == Gyro
162163
fr->additional_data.frame_number = ++_gyro_counter;
164+
LOG_DEBUG( "[WOJTEK] overriding frame counter with motion stream data: " << frame_counter << '/' << fr->additional_data.frame_number);
163165
frame_counter = fr->additional_data.frame_number;
164166
}
165167

166168

167-
LOG_DEBUG( "FrameAccepted,"
168-
<< librealsense::get_string( req_profile_base->get_stream_type() ) << ",Counter,"
169-
<< std::dec << fr->additional_data.frame_number << ",Index,"
170-
<< req_profile_base->get_stream_index() << ",BackEndTS," << std::fixed << f.backend_time
171-
<< ",SystemTime," << std::fixed << system_time << " ,diff_ts[Sys-BE],"
172-
<< system_time - f.backend_time << ",TS," << std::fixed << timestamp << ",TS_Domain,"
173-
<< rs2_timestamp_domain_to_string( timestamp_domain ) << ",last_frame_number,"
174-
<< last_frame_number << ",last_timestamp," << last_timestamp );
169+
LOG_DEBUG( "FrameAccepted:"
170+
<< librealsense::get_string( req_profile_base->get_stream_type() )
171+
<< ", Counter:" << std::dec << fr->additional_data.frame_number
172+
<< ", Index:" << req_profile_base->get_stream_index()
173+
<< ", BackEndTS:" << std::fixed << f.backend_time
174+
<< ", SystemTime:" << std::fixed << system_time
175+
<< ", diff_ts[Sys-BE]:" << system_time - f.backend_time
176+
<< ", TS:" << std::fixed << timestamp
177+
<< ", TS_Domain:" << rs2_timestamp_domain_to_string( timestamp_domain )
178+
<< ", last_frame_number:" << last_frame_number
179+
<< ", last_timestamp:" << last_timestamp );
175180

176181
if( frame_counter <= last_frame_number )
177-
LOG_INFO( "Frame counter reset" );
182+
LOG_INFO( "Frame counter reset: " << last_frame_number << " => " << frame_counter);
178183

179-
last_frame_number = frame_counter;
180-
last_timestamp = timestamp;
184+
req_profile_base->setLastFrame(frame_counter);
185+
req_profile_base->setLastTimestamp(timestamp);
181186

182187
const auto && vsp = As< video_stream_profile, stream_profile_interface >( req_profile );
183188
int width = vsp ? vsp->get_width() : 0;

0 commit comments

Comments
 (0)