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

Encoding picker #14

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions include/rviz_camera_stream/camera_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ private Q_SLOTS:
void updateTopic();
virtual void updateQueueSize();
virtual void updateFrameRate();
virtual void updateEncoding();

private:
void subscribe();
Expand All @@ -128,6 +129,7 @@ private Q_SLOTS:
DisplayGroupVisibilityProperty* visibility_property_;
IntProperty* queue_size_property_;
FloatProperty* frame_rate_property_;
EnumProperty* encoding_property_;

sensor_msgs::CameraInfo::ConstPtr current_caminfo_;
boost::mutex caminfo_mutex_;
Expand Down
40 changes: 30 additions & 10 deletions src/camera_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class VideoPublisher
}

// bool publishFrame(Ogre::RenderWindow * render_object, const std::string frame_id)
bool publishFrame(Ogre::RenderTexture * render_object, const std::string frame_id)
bool publishFrame(Ogre::RenderTexture * render_object, const std::string frame_id, std::string requested_encoding)
{
if (pub_.getTopic() == "")
{
Expand Down Expand Up @@ -121,14 +121,7 @@ class VideoPublisher
image.height = height;
image.width = width;
image.step = pixelsize * width;
if (pixelsize == 3)
image.encoding = sensor_msgs::image_encodings::RGB8; // would break if pf changes
else if (pixelsize == 4)
image.encoding = sensor_msgs::image_encodings::RGBA8; // would break if pf changes
else
{
ROS_ERROR_STREAM("unknown pixe format " << pixelsize << " " << pf);
}
image.encoding = requested_encoding;
image.is_bigendian = (OGRE_ENDIAN == OGRE_ENDIAN_BIG);
image.data.resize(datasize);
memcpy(&image.data[0], data, datasize);
Expand Down Expand Up @@ -190,6 +183,8 @@ CameraPub::CameraPub()
"trigger single images with the /rviz_camera_trigger service.",
this, SLOT(updateFrameRate()));
frame_rate_property_->setMin(-1);

encoding_property_ = new EnumProperty("Encoding", "", "Sets the encoding.", this, SLOT(updateEncoding()));
}

CameraPub::~CameraPub()
Expand Down Expand Up @@ -300,8 +295,9 @@ void CameraPub::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
frame_id = current_caminfo_->header.frame_id;
}

std::string requested_encoding = encoding_property_->getStdString();
// render_texture_->update();
video_publisher_->publishFrame(render_texture_, frame_id);
video_publisher_->publishFrame(render_texture_, frame_id, requested_encoding);
}

void CameraPub::onEnable()
Expand Down Expand Up @@ -374,6 +370,10 @@ void CameraPub::updateFrameRate()
{
}

void CameraPub::updateEncoding()
{
}

void CameraPub::clear()
{
force_render_ = true;
Expand Down Expand Up @@ -602,6 +602,26 @@ void CameraPub::reset()
{
Display::reset();
clear();
encoding_property_->clearOptions();

Ogre::PixelFormat pf = render_texture_->suggestPixelFormat();
uint pixelsize = Ogre::PixelUtil::getNumElemBytes(pf);
if (pixelsize == 3)
{
encoding_property_->setValue("rgb8");
encoding_property_->addOptionStd("rgb8", 1);
encoding_property_->addOptionStd("bgr8", 2);
}
else if (pixelsize == 4)
{
encoding_property_->setValue("rgba8");
encoding_property_->addOptionStd("rgba8", 3);
encoding_property_->addOptionStd("bgra8", 4);
}
else
{
ROS_WARN("Unsupported pixel size: %d! Could not find image encoding!", pixelsize);
}
}

} // namespace rviz
Expand Down