Skip to content

Commit

Permalink
Fix errors found by clang
Browse files Browse the repository at this point in the history
Signed-off-by: Evan Flynn <[email protected]>
  • Loading branch information
flynneva committed Feb 9, 2025
1 parent e09ea1d commit 9abc84b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 36 deletions.
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ rclcpp_components_register_node(${PROJECT_NAME}_node
EXECUTABLE ${PROJECT_NAME}_node_exe
)

# To fix `DSO missing from command line` error with clang
target_link_libraries(${PROJECT_NAME}_node_exe stdc++)

if(SANITIZE)
target_compile_options(${PROJECT_NAME} PUBLIC -fsanitize=address -fsanitize=leak)
target_link_libraries(${PROJECT_NAME} -fsanitize=address -fsanitize=leak)
Expand All @@ -81,11 +84,11 @@ if(BUILD_TESTING)
ament_add_gtest(test_usb_cam_utils
test/test_usb_cam_utils.cpp)
target_link_libraries(test_usb_cam_utils
${PROJECT_NAME})
${PROJECT_NAME} m stdc++)
ament_add_gtest(test_pixel_formats
test/test_pixel_formats.cpp)
target_link_libraries(test_pixel_formats
${PROJECT_NAME})
${PROJECT_NAME} m stdc++)
if(INTEGRATION_TESTS)
ament_add_gtest(test_usb_cam_lib
test/test_usb_cam_lib.cpp)
Expand Down
2 changes: 0 additions & 2 deletions include/usb_cam/formats/mjpeg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ class MJPEG2RGB : public pixel_format_base
size_t m_avframe_rgb_size;
char * m_averror_str;
int m_result = 0;
int m_counter = 0;
const int * m_linesize;

const int m_align = 32;
};
Expand Down
12 changes: 7 additions & 5 deletions include/usb_cam/formats/pixel_format_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ namespace formats
/// arguments for future pixel format(s) that are added.
typedef struct
{
std::string name = "";
int width = 640;
int height = 480;
size_t pixels = 640 * 480;
std::string av_device_format_str = "AV_PIX_FMT_YUV422P";
std::string name;
int width;
int height;
size_t pixels;
std::string av_device_format_str;
} format_arguments_t;


Expand All @@ -74,6 +74,8 @@ class pixel_format_base
m_requires_conversion(requires_conversion)
{}

virtual ~pixel_format_base() {}

/// @brief Name of pixel format. Used in the parameters file to select this format
/// @return
inline std::string name() {return m_name;}
Expand Down
76 changes: 49 additions & 27 deletions include/usb_cam/usb_cam.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,38 +96,63 @@ std::vector<std::shared_ptr<pixel_format_base>> driver_supported_formats(
return fmts;
}

typedef struct
typedef struct capture_format_t
{
struct v4l2_fmtdesc format;
struct v4l2_frmivalenum v4l2_fmt;
} capture_format_t;

typedef struct
typedef struct parameters_t
{
std::string camera_name = "usb_cam"; // can be anything
std::string device_name = "/dev/video0"; // usually /dev/video0 or something similiar
std::string frame_id = "camera";
std::string io_method_name = "mmap";
std::string camera_info_url = "package://usb_cam/config/camera_info.yaml";
std::string pixel_format_name = "yuyv2rgb";
std::string av_device_format = "YUV422P";
int image_width = 600;
int image_height = 400;
int framerate = 30.0;
int brightness = -1;
int contrast = -1;
int saturation = -1;
int sharpness = -1;
int gain = -1;
int white_balance = -1;
int exposure = -1;
int focus = -1;
bool auto_white_balance = true;
bool autoexposure = true;
bool autofocus = false;
std::string camera_name;
std::string device_name;
std::string frame_id;
std::string io_method_name;
std::string camera_info_url;
std::string pixel_format_name;
std::string av_device_format;
int image_width;
int image_height;
int framerate;
int brightness;
int contrast;
int saturation;
int sharpness;
int gain;
int white_balance;
int exposure;
int focus;
bool auto_white_balance;
bool autoexposure;
bool autofocus;

parameters_t()
: camera_name("usb_cam"),
device_name("/dev/video0"),
frame_id("camera"),
io_method_name("mmap"),
camera_info_url("package://usb_cam/config/camera_info.yaml"),
pixel_format_name("yuyv2rgb"),
av_device_format("YUV422P"),
image_width(600),
image_height(480),
framerate(30.0),
brightness(-1),
contrast(-1),
saturation(-1),
sharpness(-1),
gain(-1),
white_balance(-1),
exposure(-1),
focus(-1),
auto_white_balance(true),
autoexposure(true),
autofocus(false)
{
}
} parameters_t;

typedef struct
typedef struct image_t
{
char * data;
size_t width;
Expand Down Expand Up @@ -396,13 +421,10 @@ class UsbCam
image_t m_image;

AVFrame * m_avframe;
int m_avframe_size;
AVCodec * m_avcodec;
AVCodecID m_codec_id;
AVDictionary * m_avoptions;
AVCodecContext * m_avcodec_context;

int64_t m_buffer_time_us;
bool m_is_capturing;
int m_framerate;
const time_t m_epoch_time_shift_us;
Expand Down

0 comments on commit 9abc84b

Please sign in to comment.