image_subscriber.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2014, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  *
00029  * image_subscriber.h
00030  *
00031  *  Created on: Oct 30, 2012
00032  *      Author: jkammerl
00033  */
00034 
00035 #ifndef ROS_IMAGE_SUBSCRIBE_H_
00036 #define ROS_IMAGE_SUBSCRIBE_H_
00037 
00038 #include <boost/thread.hpp>
00039 #include <boost/bind.hpp>
00040 
00041 #include <iostream>
00042 #include <string>
00043 #include <vector>
00044 #include <deque>
00045 
00046 
00047 #include "ros/ros.h"
00048 
00049 #include <image_transport/image_transport.h>
00050 #include <image_transport/subscriber_filter.h>
00051 
00052 
00053 namespace ros_http_video_streamer
00054 {
00055 
00057   // This class subscribes to a ROS image publisher
00058   // and manages a queue of received images
00060   class ImageSubscriber
00061   {
00062   public:
00063 
00064     typedef boost::shared_ptr<ImageSubscriber> ptr;
00065 
00066     // Specify ROS topic in constructor
00067     ImageSubscriber(const std::string& topic, const std::string& transport);
00068     virtual ~ImageSubscriber();
00069 
00070     // get image from receiver queue
00071     void getImageFromQueue( sensor_msgs::ImageConstPtr& frame);
00072 
00073     // empty queue
00074     void emptyQueue( );
00075 
00076   private:
00077     // ROS subscriber callback
00078     void image_cb(const sensor_msgs::ImageConstPtr& msg);
00079     // reset connection
00080     void reset();
00081     // subscribe
00082     void subscribe();
00083 
00084     // ROS topic
00085     const std::string topic_;
00086     // ROS transport scheme
00087     const std::string transport_;
00088 
00089     // ROS node handle
00090     ros::NodeHandle nh;
00091     // ROS image transport & subscriber
00092     image_transport::ImageTransport it;
00093     boost::shared_ptr<image_transport::SubscriberFilter> sub;
00094 
00095     // mutex to protect image queue
00096     boost::mutex frame_mutex_;
00097     // image queue
00098     std::deque<sensor_msgs::ImageConstPtr> frame_queue_;
00099 
00100   };
00101 
00102 } // ros_http_video_streamer
00103 
00104 #endif /* ROS_IMAGE_SUBSCRIBE_H_ */


ros_web_video
Author(s): Julius Kammer
autogenerated on Thu Jun 6 2019 21:07:01