Skip to content

Commit

Permalink
debug added
Browse files Browse the repository at this point in the history
  • Loading branch information
remibettan committed Dec 12, 2024
1 parent 09696f9 commit 9827237
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 28 deletions.
89 changes: 64 additions & 25 deletions examples/capture/rs-capture.cpp
Original file line number Diff line number Diff line change
@@ -1,39 +1,77 @@
// License: Apache 2.0. See LICENSE file in root directory.
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2017 Intel Corporation. All Rights Reserved.

#include <librealsense2/rs.hpp> // Include RealSense Cross Platform API
#include "example.hpp" // Include short list of convenience functions for rendering
#include <iostream>
#include <rsutils/string/from.h>

std::ostream & operator<<( std::ostream & ss, const rs2::frame & self )
{
ss << rs2_format_to_string( self.get_profile().format() );
ss << " #" << self.get_frame_number();
ss << " @" << rsutils::string::from( self.get_timestamp() );
return ss;
}

std::string print_frameset(rs2::frame f)
{
std::ostringstream ss;
ss << "frame";
if (auto fs = f.as<rs2::frameset>())
{
ss << "set";
for(auto sf : fs)
{
ss << " " << sf;
}
}
else
{
ss << " " << f;
}
return ss.str();
}

void run_and_verify_frame_received(rs2::pipeline& pipe)
{
auto start = std::chrono::high_resolution_clock().now();
pipe.start();
auto frameset = pipe.wait_for_frames();
auto stop = std::chrono::high_resolution_clock().now();
auto duration_ms = std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count();
/*auto depth_frame = frameset.get_depth_frame();
if( depth_frame)
{
std::cout << "D";
}
auto color_frame = frameset.get_color_frame();
if( color_frame)
{
std::cout << "C";
}
std::cout << std::endl;*/
std::ostringstream ss;
ss << "After " << duration_ms << "[msec], got first frame of " << print_frameset(frameset);
std::cout << ss.str() << std::endl;
pipe.stop();
}

// Capture Example demonstrates how to
// capture depth and color video streams and render them to the screen
int main(int argc, char * argv[]) try
{
rs2::log_to_console(RS2_LOG_SEVERITY_ERROR);
// Create a simple OpenGL window for rendering:
window app(1280, 720, "RealSense Capture Example");
rs2::log_to_file(RS2_LOG_SEVERITY_DEBUG, "mylog.txt");

// Declare depth colorizer for pretty visualization of depth data
rs2::colorizer color_map;
// Declare rates printer for showing streaming rates of the enabled streams.
rs2::rates_printer printer;
auto ctx = rs2::context();
auto dev = ctx.query_devices().front();
rs2::pipeline pipe(ctx);
pipe.set_device(&dev);

// Declare RealSense pipeline, encapsulating the actual device and sensors
rs2::pipeline pipe;

// Start streaming with default recommended configuration
// The default video configuration contains Depth and Color streams
// If a device is capable to stream IMU data, both Gyro and Accelerometer are enabled by default
pipe.start();

while (app) // Application still alive?
int iterations = 0;
while (++iterations < 500) // Application still alive?
{
rs2::frameset data = pipe.wait_for_frames(). // Wait for next set of frames from the camera
apply_filter(printer). // Print each enabled stream frame rate
apply_filter(color_map); // Find and colorize the depth data

// The show method, when applied on frameset, break it to frames and upload each frame into a gl textures
// Each texture is displayed on different viewport according to it's stream unique id
app.show(data);
std::cout << "iteration no" << iterations << std::endl;
run_and_verify_frame_received(pipe);
}

return EXIT_SUCCESS;
Expand All @@ -48,3 +86,4 @@ catch (const std::exception& e)
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}

1 change: 1 addition & 0 deletions src/linux/backend-v4l2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2098,6 +2098,7 @@ namespace librealsense

++pixel_format.index;
}
LOG_WARNING("GET_PROFILES() - results_size = " << results.size());
return results;
}

Expand Down
1 change: 1 addition & 0 deletions src/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2307,6 +2307,7 @@ NOEXCEPT_RETURN(, pipe)
rs2_pipeline_profile* rs2_pipeline_start(rs2_pipeline* pipe, rs2_error ** error) BEGIN_API_CALL
{
VALIDATE_NOT_NULL(pipe);
LOG_WARNING("PIPELINE START");
return new rs2_pipeline_profile{ pipe->pipeline->start(std::make_shared<pipeline::config>()) };
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, pipe)
Expand Down
8 changes: 5 additions & 3 deletions unit-tests/live/frames/test-pipeline-start-stop.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# License: Apache 2.0. See LICENSE file in root directory.
# Copyright(c) 2023-2024 Intel Corporation. All Rights Reserved.

# test:donotrun:!nightly

# Currently, we exclude D457 as it's failing
# test:device each(D400*) !D457
# On D455 and other units with IMU it takes ~4 seconds per iteration
# test:timeout 220
# test:timeout 500

import pyrealsense2 as rs
from rspy.stopwatch import Stopwatch
from rspy import test, log
import time

rs.log_to_file(rs.log_severity.debug, "pipeine_test_log.log")

# Run multiple start stop of all streams and verify we get a frame for each once
ITERATIONS_COUNT = 50
ITERATIONS_COUNT = 500

dev, ctx = test.find_first_device_or_exit()
pipe = rs.pipeline(ctx)
Expand Down

0 comments on commit 9827237

Please sign in to comment.