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

Publish raw mjpeg stream directly via compressed image topic #270

Merged
merged 14 commits into from
Nov 13, 2023

Conversation

boitumeloruf
Copy link
Contributor

Hi @flynneva,

I have another PR. At this point, however, I prefer it as a feature idea and suggestion for a possible implementation of the same. I am not too happy with my implementation yet (especially in usb_cam_node.cpp), thus, I would instead use it as a basis for discussion.

Since most of the USB cameras directly provide a MJPEG stream, it would be most efficient not to let the driver do the decoding but rather publish it via the compressed image topic (this is also suggested here). In this way, any node that uses the image_transport plugin can directly connect to the MJPEG stream. Furthermore, if the camera is connected to an edge device the decoding can be transferred to a more powerful device while at the same time having the benefit of an efficient data transfer using MJPEG.

What are your thoughts on this? My implementation allows selecting a raw MJPEG stream by setting the pixel_format in the config YAML to 'mjpeg'. I have tested it successfully by subscribing to '/image_raw/compressed' using rqt_image_view, as well as a custom subscription node.

8,
false)
{
switch(avDeviceFormat)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boitumeloruf this switch should be moved to its own function. input is the avDeviceFormat, output would be the corresponding ROS format. Should probably split it into two separate functions - one for the ROS format, the other for the channels.

Something like get_ros_format_from_av_format(const AVPixelFormat & avDeviceFormat) and then same thing for the channels.

@flynneva
Copy link
Collaborator

flynneva commented Nov 5, 2023

@boitumeloruf apologies this took so long for me to get to but I like this idea a lot. If youre up for coming back to this I'd be happy to merge it after rebasing / the one suggestion I had above. We can iterate / improve on it once its merged

@boitumeloruf
Copy link
Contributor Author

Hello @flynneva, Yes, I am happy to implement your suggestions. :)

@boitumeloruf
Copy link
Contributor Author

Hi @flynneva, I have implemented your suggestions. I also fixed some build issues and code style issues. Let me know if there is stuff left to do.

Copy link
Collaborator

@flynneva flynneva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boitumeloruf I only could see two minor suggestions / nits so I'll go ahead and approve and merge this. We can tackle those comments in another PR if we really want to 👍🏼

Comment on lines +971 to +975
default:
{
ros_format = usb_cam::constants::UNKNOWN;
}
break;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boitumeloruf I know its not necessary, but could you move the default cases for the switches here to be last? You could also remove the break then from each of the default cases

Comment on lines +977 to +981
case AVPixelFormat::AV_PIX_FMT_RGB24:
{
ros_format = usb_cam::constants::RGB8;
}
break;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boitumeloruf writing each case like this will make the code much more read-able I think (and a lot less clutter)

Suggested change
case AVPixelFormat::AV_PIX_FMT_RGB24:
{
ros_format = usb_cam::constants::RGB8;
}
break;
case AVPixelFormat::AV_PIX_FMT_RGB24: ros_format = usb_cam::constants::RGB8; break;

@flynneva flynneva merged commit aa11493 into ros-drivers:ros2 Nov 13, 2023
5 checks passed
@boitumeloruf boitumeloruf deleted the raw-mjpeg-stream branch November 13, 2023 06:49
@boitumeloruf
Copy link
Contributor Author

Great, Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants