Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rs2_get_video_stream_intrinsics no longer reports errors if not intrinsics available #13004

Merged
merged 3 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ namespace librealsense
}
};

// Provide a way for the API to denote something as output, so it's not shown on error
// Output arguments are always pointers
struct output_arg
{
void const * pointer;
output_arg( void const * pv ) : pointer( pv ) {}
};

// Next we define type trait for testing if *t for some T* is streamable
template<typename T>
class is_streamable
Expand Down Expand Up @@ -101,6 +109,16 @@ namespace librealsense
arg_streamer<T, is_streamable<T>::value> s;
s.stream_arg(out, last, true);
}
inline void stream_args( std::ostream & out, const char * names, const output_arg & last )
{
while( *names++ != '(' ); // skip "output_arg("
while( *names == ' ' ) ++names; // skip "(" and any spaces
while( *names != ')' && *names != ' ' ) out << *names++;
out << ":";
if( ! last.pointer )
out << "nullptr";
out << "(out)";
}
template<class T, class... U> void stream_args(std::ostream & out, const char * names, const T & first, const U &... rest)
{
while (*names && *names != ',') out << *names++;
Expand All @@ -109,6 +127,12 @@ namespace librealsense
while (*names && (*names == ',' || isspace(*names))) ++names;
stream_args(out, names, rest...);
}
template<class... U> void stream_args( std::ostream & out, const char * names, const output_arg & first, const U &... rest )
{
stream_args( out, names, first );
out << ", ";
stream_args( out, names, rest... );
}



Expand Down Expand Up @@ -403,6 +427,18 @@ return __p.invoke(func);\

#define BEGIN_API_CALL try
#define NOEXCEPT_RETURN(R, ...) catch(...) { std::ostringstream ss; librealsense::stream_args(ss, #__VA_ARGS__, __VA_ARGS__); rs2_error* e; librealsense::translate_exception(__FUNCTION__, ss.str(), &e); LOG_WARNING(rs2_get_error_message(e)); rs2_free_error(e); return R; }
// If you want to avoid any errors being reported because an exception an expected API behavior:
#define EXPECTED_EXCEPTION( E, R, ... ) \
catch( E const & e ) \
{ \
if( error ) \
{ \
std::ostringstream ss; \
librealsense::stream_args( ss, #__VA_ARGS__, __VA_ARGS__ ); \
*error = new rs2_error{ e.what(), __FUNCTION__, ss.str(), RS2_EXCEPTION_TYPE_COUNT }; \
} \
return R; \
}
#define HANDLE_EXCEPTIONS_AND_RETURN(R, ...) catch(...) { std::ostringstream ss; librealsense::stream_args(ss, #__VA_ARGS__, __VA_ARGS__); librealsense::translate_exception(__FUNCTION__, ss.str(), error); return R; }
#define NOARGS_HANDLE_EXCEPTIONS_AND_RETURN(R) catch(...) { librealsense::translate_exception(__FUNCTION__, "", error); return R; }
#define NOARGS_HANDLE_EXCEPTIONS_AND_RETURN_VOID() catch(...) { librealsense::translate_exception(__FUNCTION__, "", error); }
Expand Down
33 changes: 29 additions & 4 deletions src/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,16 +464,41 @@ void rs2_delete_stream_profiles_list(rs2_stream_profile_list* list) BEGIN_API_CA
}
NOEXCEPT_RETURN(, list)

void rs2_get_video_stream_intrinsics(const rs2_stream_profile* from, rs2_intrinsics* intr, rs2_error** error) BEGIN_API_CALL

std::ostream & operator<<( std::ostream & os, rs2_stream_profile const & p )
{
VALIDATE_NOT_NULL(from);
if( ! p.profile )
{
os << "NULL";
}
else
{
os << "[ " << librealsense::get_abbr_string( p.profile->get_stream_type() );
os << " " << librealsense::get_string( p.profile->get_format() );
os << " " << p.profile->get_stream_index();
if( auto vsp = As< video_stream_profile, stream_profile_interface >( p.profile ) )
{
os << " " << vsp->get_width();
os << "x" << vsp->get_height();
}
os << " @ " << p.profile->get_framerate();
os << " ]";
}
return os;
}


void rs2_get_video_stream_intrinsics(const rs2_stream_profile* profile, rs2_intrinsics* intr, rs2_error** error) BEGIN_API_CALL
{
VALIDATE_NOT_NULL( profile );
VALIDATE_NOT_NULL(intr);

auto vid = VALIDATE_INTERFACE(from->profile, librealsense::video_stream_profile_interface);
auto vid = VALIDATE_INTERFACE( profile->profile, librealsense::video_stream_profile_interface);

*intr = vid->get_intrinsics();
}
HANDLE_EXCEPTIONS_AND_RETURN( , from, intr )
EXPECTED_EXCEPTION( not_implemented_exception, , profile, output_arg( intr ) ) // only accepted way of checking if profile has intrinsics
HANDLE_EXCEPTIONS_AND_RETURN(, profile, output_arg( intr ) )

// librealsense wrapper around a C function
class calibration_change_callback : public rs2_calibration_change_callback
Expand Down
Loading