-
Notifications
You must be signed in to change notification settings - Fork 602
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
84b6357
Added av_device_format parameter
eaaa13d
Updated example YAML files to av_device_format
1f9bec2
Added feature to access raw mjpeg stream and publish directly on comp…
9125832
Merge branch 'ros-drivers:ros2' into ros2
341cb79
Refactored use of av_device_format
03635d0
Merge branch 'ros2' into raw-mjpeg-stream
b13c521
Fix seg fault when unref av_packet using av_codec < 58.133.100
671a942
Merge branch 'ros2' into raw-mjpeg-stream
3012b2e
fixed cppcheck and uncrustify errors
021ffb7
Merge branch 'ros2' of https://github.com/boitumeloruf/usb_cam into ros2
423f4a2
Merge branch 'ros2' into raw-mjpeg-stream
af35709
fixed minor build issues
d3c4c55
Merge branch 'ros2' into raw-mjpeg-stream
7ad056f
Introduced funtions get_..._from_av_format, fixed code style errors
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -38,6 +38,8 @@ extern "C" { | |||||||||||||
#include "libavutil/pixfmt.h" | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
#include "usb_cam/constants.hpp" | ||||||||||||||
|
||||||||||||||
#define stringify(name) #name | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
|
@@ -958,6 +960,152 @@ inline AVPixelFormat get_av_pixel_format_from_string(const std::string & str) | |||||||||||||
return STR_2_AVPIXFMT.find(fullFmtStr)->second; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/// @brief Get ROS PixelFormat from AVPixelFormat. | ||||||||||||||
/// @param avPixelFormat AVPixelFormat | ||||||||||||||
/// @return String specifying the ROS pixel format. | ||||||||||||||
inline std::string get_ros_pixel_format_from_av_format(const AVPixelFormat & avPixelFormat) | ||||||||||||||
{ | ||||||||||||||
std::string ros_format = ""; | ||||||||||||||
|
||||||||||||||
switch (avPixelFormat) { | ||||||||||||||
default: | ||||||||||||||
{ | ||||||||||||||
ros_format = usb_cam::constants::UNKNOWN; | ||||||||||||||
} | ||||||||||||||
break; | ||||||||||||||
|
||||||||||||||
case AVPixelFormat::AV_PIX_FMT_RGB24: | ||||||||||||||
{ | ||||||||||||||
ros_format = usb_cam::constants::RGB8; | ||||||||||||||
} | ||||||||||||||
break; | ||||||||||||||
Comment on lines
+977
to
+981
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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_RGBA: | ||||||||||||||
{ | ||||||||||||||
ros_format = usb_cam::constants::RGBA8; | ||||||||||||||
} | ||||||||||||||
break; | ||||||||||||||
|
||||||||||||||
case AVPixelFormat::AV_PIX_FMT_BGR24: | ||||||||||||||
{ | ||||||||||||||
ros_format = usb_cam::constants::BGR8; | ||||||||||||||
} | ||||||||||||||
break; | ||||||||||||||
|
||||||||||||||
case AVPixelFormat::AV_PIX_FMT_BGRA: | ||||||||||||||
{ | ||||||||||||||
ros_format = usb_cam::constants::BGRA8; | ||||||||||||||
} | ||||||||||||||
break; | ||||||||||||||
|
||||||||||||||
case AVPixelFormat::AV_PIX_FMT_GRAY8: | ||||||||||||||
{ | ||||||||||||||
ros_format = usb_cam::constants::MONO8; | ||||||||||||||
} | ||||||||||||||
break; | ||||||||||||||
|
||||||||||||||
case AVPixelFormat::AV_PIX_FMT_GRAY16BE: | ||||||||||||||
{ | ||||||||||||||
ros_format = usb_cam::constants::MONO16; | ||||||||||||||
} | ||||||||||||||
break; | ||||||||||||||
|
||||||||||||||
case AVPixelFormat::AV_PIX_FMT_YUV422P: | ||||||||||||||
{ | ||||||||||||||
ros_format = usb_cam::constants::YUV422; | ||||||||||||||
} | ||||||||||||||
break; | ||||||||||||||
|
||||||||||||||
case AVPixelFormat::AV_PIX_FMT_YUV420P: | ||||||||||||||
{ | ||||||||||||||
ros_format = usb_cam::constants::NV21; | ||||||||||||||
} | ||||||||||||||
break; | ||||||||||||||
|
||||||||||||||
case AVPixelFormat::AV_PIX_FMT_YUV444P: | ||||||||||||||
{ | ||||||||||||||
ros_format = usb_cam::constants::NV24; | ||||||||||||||
} | ||||||||||||||
break; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
return ros_format; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/// @brief Get the number of channels from AVPixelFormat. | ||||||||||||||
/// @param avPixelFormat AVPixelFormat | ||||||||||||||
/// @return Number of channels as uint8 | ||||||||||||||
inline uint8_t get_channels_from_av_format(const AVPixelFormat & avPixelFormat) | ||||||||||||||
{ | ||||||||||||||
uint8_t channels = 1; | ||||||||||||||
|
||||||||||||||
switch (avPixelFormat) { | ||||||||||||||
default: | ||||||||||||||
case AVPixelFormat::AV_PIX_FMT_GRAY8: | ||||||||||||||
case AVPixelFormat::AV_PIX_FMT_GRAY16BE: | ||||||||||||||
{ | ||||||||||||||
channels = 1; | ||||||||||||||
} | ||||||||||||||
break; | ||||||||||||||
|
||||||||||||||
case AVPixelFormat::AV_PIX_FMT_YUV422P: | ||||||||||||||
case AVPixelFormat::AV_PIX_FMT_YUV420P: | ||||||||||||||
case AVPixelFormat::AV_PIX_FMT_YUV444P: | ||||||||||||||
{ | ||||||||||||||
channels = 2; | ||||||||||||||
} | ||||||||||||||
break; | ||||||||||||||
|
||||||||||||||
case AVPixelFormat::AV_PIX_FMT_RGB24: | ||||||||||||||
case AVPixelFormat::AV_PIX_FMT_BGR24: | ||||||||||||||
{ | ||||||||||||||
channels = 3; | ||||||||||||||
} | ||||||||||||||
break; | ||||||||||||||
|
||||||||||||||
case AVPixelFormat::AV_PIX_FMT_RGBA: | ||||||||||||||
case AVPixelFormat::AV_PIX_FMT_BGRA: | ||||||||||||||
{ | ||||||||||||||
channels = 4; | ||||||||||||||
} | ||||||||||||||
break; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
return channels; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/// @brief Get the pixel bit depth from AVPixelFormat. | ||||||||||||||
/// @param avPixelFormat AVPixelFormat | ||||||||||||||
/// @return Bit depth as uint8 | ||||||||||||||
inline uint8_t get_bit_depth_from_av_format(const AVPixelFormat & avPixelFormat) | ||||||||||||||
{ | ||||||||||||||
uint8_t bit_depth = 8; | ||||||||||||||
|
||||||||||||||
switch (avPixelFormat) { | ||||||||||||||
default: | ||||||||||||||
case AVPixelFormat::AV_PIX_FMT_GRAY8: | ||||||||||||||
case AVPixelFormat::AV_PIX_FMT_RGB24: | ||||||||||||||
case AVPixelFormat::AV_PIX_FMT_BGR24: | ||||||||||||||
case AVPixelFormat::AV_PIX_FMT_RGBA: | ||||||||||||||
case AVPixelFormat::AV_PIX_FMT_BGRA: | ||||||||||||||
case AVPixelFormat::AV_PIX_FMT_YUV422P: | ||||||||||||||
case AVPixelFormat::AV_PIX_FMT_YUV420P: | ||||||||||||||
case AVPixelFormat::AV_PIX_FMT_YUV444P: | ||||||||||||||
{ | ||||||||||||||
bit_depth = 8; | ||||||||||||||
} | ||||||||||||||
break; | ||||||||||||||
|
||||||||||||||
case AVPixelFormat::AV_PIX_FMT_GRAY16BE: | ||||||||||||||
{ | ||||||||||||||
bit_depth = 16; | ||||||||||||||
} | ||||||||||||||
break; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
return bit_depth; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
} // namespace formats | ||||||||||||||
} // namespace usb_cam | ||||||||||||||
|
||||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 thebreak
then from each of the default cases