Skip to content

Commit

Permalink
[sample][fix]: fix nullptr bug
Browse files Browse the repository at this point in the history
  • Loading branch information
daiyin committed Jun 20, 2024
1 parent f6580c8 commit 2402ac0
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 21 deletions.
17 changes: 11 additions & 6 deletions examples/0.basic.quick_start/quick_start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ int main(void) try {
}

// Get the depth from the frameSet.
auto depthFrame = frameSet->getFrame(OB_FRAME_DEPTH)->as<ob::DepthFrame>();
auto dFrame = frameSet->getFrame(OB_FRAME_DEPTH);
// Get the color from the frameSet.
auto colorFrame = frameSet->getFrame(OB_FRAME_COLOR)->as<ob::ColorFrame>();

if((depthFrame != nullptr) && (colorFrame != nullptr)){
// Render frame in the window.
app.addToRender({colorFrame, depthFrame});
auto cFrame = frameSet->getFrame(OB_FRAME_COLOR);
if(dFrame && cFrame) {
auto depthFrame = dFrame->as<ob::DepthFrame>();
auto colorFrame = cFrame->as<ob::ColorFrame>();

if((depthFrame != nullptr) && (colorFrame != nullptr)){
// Render frame in the window.
app.addToRender({colorFrame, depthFrame});
}
}

}

// Stop the Pipeline, no frame data will be generated
Expand Down
4 changes: 2 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ add_subdirectory(1.stream.imu)
add_subdirectory(1.stream.infrared)
add_subdirectory(1.stream.multi_streams)
# add_subdirectory(2.device.control)
add_subdirectory(2.device.hot_plugin)
add_subdirectory(2.device.net_device)
# add_subdirectory(2.device.hot_plugin)
# add_subdirectory(2.device.net_device)
add_subdirectory(3.advanced.align)
# add_subdirectory(3.advanced.coordinate_convert)
# add_subdirectory(3.advanced.hdr)
Expand Down
36 changes: 29 additions & 7 deletions examples/c_examples/0.c_quick_start/quick_start.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>

#include <openobsdk/ObSensor.h>
#include <stdio.h>
#include "utils.hpp"

#ifdef _WIN32
#include <windows.h>
long long get_current_timestamp_ms() {
FILETIME ft;
LARGE_INTEGER li;
GetSystemTimeAsFileTime(&ft);
li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime;
long long milliseconds = li.QuadPart / 10000LL;
return milliseconds;
}
#else
#include <sys/time.h>
long long get_current_timestamp_ms() {
struct timeval te;
gettimeofday(&te, NULL); // 获取当前时间
long long milliseconds = te.tv_sec * 1000LL + te.tv_usec / 1000; // 计算毫秒
return milliseconds;
}
#endif

#define ESC 27

static float color_count = 0;
Expand Down Expand Up @@ -61,11 +83,11 @@ int main(void) {
if(color_frame != NULL) {
color_count++;
// Get timestamp from color frame.
color_timestamp_current = ob_frame_get_timestamp_us(color_frame, &error);
color_timestamp_current = get_current_timestamp_ms();
uint64_t duration = color_timestamp_current - color_timestamp_last;
if(duration > 3000000) { // 3 seconds
if(duration > 3000) { // 3 seconds
// Print index and rate of color frame.
printf("color frame index: %lld, rate: %f\n", ob_frame_get_index(color_frame, &error), color_count / (duration / 1000000.0));
printf("color frame index: %lld, rate: %f\n", ob_frame_get_index(color_frame, &error), color_count / (duration / 1000.0));
color_count = 0;
color_timestamp_last = color_timestamp_current;
}
Expand All @@ -76,11 +98,11 @@ int main(void) {
if(depth_frame != NULL) {
depth_count++;
// Get timestamp from depth frame.
depth_timestamp_current = ob_frame_get_timestamp_us(depth_frame, &error);
depth_timestamp_current = get_current_timestamp_ms();
uint64_t duration = depth_timestamp_current - depth_timestamp_last;
if(duration > 3000000) { // 3 seconds
if(duration > 3000) { // 3 seconds
// Print index and rate of depth frame.
printf("depth frame index: %lld, rate: %f\n", ob_frame_get_index(depth_frame, &error), depth_count / (duration / 1000000.0));
printf("depth frame index: %lld, rate: %f\n", ob_frame_get_index(depth_frame, &error), depth_count / (duration / 1000.0));
depth_count = 0;
depth_timestamp_last = depth_timestamp_current;
}
Expand Down
9 changes: 7 additions & 2 deletions src/impl/Pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ HANDLE_EXCEPTIONS_NO_RETURN(pipeline)

void ob_pipeline_start_with_config(ob_pipeline *pipeline, ob_config *config, ob_error **error) BEGIN_API_CALL {
VALIDATE_NOT_NULL(pipeline);
VALIDATE_NOT_NULL(config);
pipeline->pipeline->start(config->config);
if (!config) {
ob_pipeline_start(pipeline, error);
}
else {
VALIDATE_NOT_NULL(config);
pipeline->pipeline->start(config->config);
}
}
HANDLE_EXCEPTIONS_NO_RETURN(pipeline)

Expand Down
6 changes: 2 additions & 4 deletions src/shared/envconfig/OrbbecSDKConfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@
<Device>
<EnumerateNetDevice>false</EnumerateNetDevice>


<!--UVC Backend select on Linux; optional values: Auto, V4L2, LibUVC; Auto is the default value-->
<LinuxUVCBackend>LibUVC</LinuxUVCBackend>


<!--The device corresponding to Astra adv is astra+-->
<AstraAdv>
<Depth>
Expand Down Expand Up @@ -1356,7 +1358,6 @@
<DefaultHeartBeat>0</DefaultHeartBeat>
<!--Whether to enable firmware upgrade foolproof by default, only internal version supports-->
<FirmwareUpgradeFoolproof>1</FirmwareUpgradeFoolproof>

<!-- Depth Filter Params -->
<!--
<DepthFilterDDOConfig>./Gemini2_v1.0.json</DepthFilterDDOConfig>
Expand Down Expand Up @@ -2384,7 +2385,6 @@
<Format>Y8</Format>
</IR_RIGHT>
</OrbbecGemini335>

<!--Gemini2RL config-->
<OrbbecGemini335L>
<!--Whether to enable heartbeat by default-->
Expand Down Expand Up @@ -2450,7 +2450,6 @@
<Format>Y8</Format>
</IR_RIGHT>
</OrbbecGemini335L>

<!--Gemini 336 config-->
<OrbbecGemini336>
<!--Whether to enable heartbeat by default-->
Expand Down Expand Up @@ -2516,7 +2515,6 @@
<Format>Y8</Format>
</IR_RIGHT>
</OrbbecGemini336>

<!--Gemini 336L config-->
<OrbbecGemini336L>
<!--Whether to enable heartbeat by default-->
Expand Down

0 comments on commit 2402ac0

Please sign in to comment.