theora_publisher.h
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2012, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
36 #include <cv_bridge/cv_bridge.h>
37 #include <std_msgs/Header.h>
38 #include <dynamic_reconfigure/server.h>
39 #include <theora_image_transport/TheoraPublisherConfig.h>
40 #include <theora_image_transport/Packet.h>
41 
42 #include <theora/codec.h>
43 #include <theora/theoraenc.h>
44 #include <theora/theoradec.h>
45 
47 
48 class TheoraPublisher : public image_transport::SimplePublisherPlugin<theora_image_transport::Packet>
49 {
50 public:
52 
54 
55  // Return the system unique string representing the theora transport type
56  virtual std::string getTransportName() const { return "theora"; }
57 
58 protected:
59  // Overridden to tweak arguments and set up reconfigure server
60  virtual void advertiseImpl(ros::NodeHandle &nh, const std::string &base_topic, uint32_t queue_size,
61  const image_transport::SubscriberStatusCallback &user_connect_cb,
62  const image_transport::SubscriberStatusCallback &user_disconnect_cb,
63  const ros::VoidPtr &tracked_object, bool latch);
64 
65  // Callback to send header packets to new clients
66  virtual void connectCallback(const ros::SingleSubscriberPublisher& pub);
67 
68  // Main publish function
69  virtual void publish(const sensor_msgs::Image& message,
70  const PublishFn& publish_fn) const;
71 
72  // Dynamic reconfigure support
73  typedef theora_image_transport::TheoraPublisherConfig Config;
74  typedef dynamic_reconfigure::Server<Config> ReconfigureServer;
77 
78  void configCb(Config& config, uint32_t level);
79 
80  // Utility functions
81  bool ensureEncodingContext(const sensor_msgs::Image& image, const PublishFn& publish_fn) const;
82  void oggPacketToMsg(const std_msgs::Header& header, const ogg_packet &oggpacket,
83  theora_image_transport::Packet &msg) const;
84  void updateKeyframeFrequency() const;
85 
86  // Some data is preserved across calls to publish(), but from the user's perspective publish() is
87  // "logically const"
89  mutable th_info encoder_setup_;
90  mutable ogg_uint32_t keyframe_frequency_;
92  mutable std::vector<theora_image_transport::Packet> stream_header_;
93 };
94 
95 } //namespace compressed_image_transport
theora_image_transport::TheoraPublisher::advertiseImpl
virtual void advertiseImpl(ros::NodeHandle &nh, const std::string &base_topic, uint32_t queue_size, const image_transport::SubscriberStatusCallback &user_connect_cb, const image_transport::SubscriberStatusCallback &user_disconnect_cb, const ros::VoidPtr &tracked_object, bool latch)
Definition: theora_publisher.cpp:72
theora_image_transport::TheoraPublisher::ReconfigureServer
dynamic_reconfigure::Server< Config > ReconfigureServer
Definition: theora_publisher.h:138
theora_image_transport::TheoraPublisher::ensureEncodingContext
bool ensureEncodingContext(const sensor_msgs::Image &image, const PublishFn &publish_fn) const
Definition: theora_publisher.cpp:251
theora_image_transport::TheoraPublisher::reconfigure_server_
boost::shared_ptr< ReconfigureServer > reconfigure_server_
Definition: theora_publisher.h:139
boost::shared_ptr< void >
theora_image_transport::TheoraPublisher::encoding_context_
boost::shared_ptr< th_enc_ctx > encoding_context_
Definition: theora_publisher.h:155
theora_image_transport
Definition: theora_publisher.h:46
theora_image_transport::TheoraPublisher::configCb
void configCb(Config &config, uint32_t level)
Definition: theora_publisher.cpp:91
theora_image_transport::TheoraPublisher::Config
theora_image_transport::TheoraPublisherConfig Config
Definition: theora_publisher.h:137
theora_image_transport::TheoraPublisher::getTransportName
virtual std::string getTransportName() const
Definition: theora_publisher.h:120
theora_image_transport::TheoraPublisher::keyframe_frequency_
ogg_uint32_t keyframe_frequency_
Definition: theora_publisher.h:154
theora_image_transport::TheoraPublisher::TheoraPublisher
TheoraPublisher()
Definition: theora_publisher.cpp:48
ros::SingleSubscriberPublisher
theora_image_transport::TheoraPublisher::~TheoraPublisher
~TheoraPublisher()
Definition: theora_publisher.cpp:67
theora_image_transport::TheoraPublisher::updateKeyframeFrequency
void updateKeyframeFrequency() const
Definition: theora_publisher.cpp:304
image_transport::SimplePublisherPlugin< theora_image_transport::Packet >::PublishFn
boost::function< void(const M &)> PublishFn
simple_publisher_plugin.h
theora_image_transport::TheoraPublisher::img_image_
cv_bridge::CvImage img_image_
Definition: theora_publisher.h:152
theora_image_transport::TheoraPublisher::encoder_setup_
th_info encoder_setup_
Definition: theora_publisher.h:153
image_transport::SimplePublisherPlugin< theora_image_transport::Packet >::nh
const ros::NodeHandle & nh() const
image_transport::SimplePublisherPlugin
cv_bridge.h
cv_bridge::CvImage
theora_image_transport::TheoraPublisher::config_
Config config_
Definition: theora_publisher.h:140
theora_image_transport::TheoraPublisher::connectCallback
virtual void connectCallback(const ros::SingleSubscriberPublisher &pub)
Definition: theora_publisher.cpp:141
image_transport::SubscriberStatusCallback
boost::function< void(const SingleSubscriberPublisher &)> SubscriberStatusCallback
theora_image_transport::TheoraPublisher::oggPacketToMsg
void oggPacketToMsg(const std_msgs::Header &header, const ogg_packet &oggpacket, theora_image_transport::Packet &msg) const
Definition: theora_publisher.cpp:292
theora_image_transport::TheoraPublisher::publish
virtual void publish(const sensor_msgs::Image &message, const PublishFn &publish_fn) const
Definition: theora_publisher.cpp:157
theora_image_transport::TheoraPublisher::stream_header_
std::vector< theora_image_transport::Packet > stream_header_
Definition: theora_publisher.h:156
theora_image_transport::TheoraPublisher
Definition: theora_publisher.h:80
ros::NodeHandle


theora_image_transport
Author(s): Julius Kammerl, Patrick Mihelich, Ethan Dreyfuss
autogenerated on Sat Jan 27 2024 03:31:07