ffmpeg_encoder.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  *
00030  * ffmpeg_encoder.h
00031  *
00032  *  Created on: Oct 30, 2012
00033  *      Author: jkammerl
00034  */
00035 
00036 #ifndef FFMPEG_ENCODER_H_
00037 #define FFMPEG_ENCODER_H_
00038 
00039 #define DEPTH_TO_RGB_AVERAGE
00040 
00041 #include <iostream>
00042 #include <string>
00043 #include <vector>
00044 
00045 #include <boost/thread.hpp>
00046 
00047 #include <sensor_msgs/image_encodings.h>
00048 
00049 #include "ffmpeg_wrapper.h"
00050 #include "image_subscriber.h"
00051 #include "server_configuration.h"
00052 
00053 namespace ros_http_video_streamer
00054 {
00055 
00056 class FFMPEGEncoder
00057 {
00058 public:
00059 
00060   typedef boost::shared_ptr<FFMPEGEncoder> ptr;
00061 
00062   FFMPEGEncoder(const std::string& refID,
00063                 const std::string& topic,
00064                 const ServerConfiguration& config);
00065 
00066   virtual ~FFMPEGEncoder();
00067 
00068   // receive header data
00069   // this method blocks until the header data is availble from the codec
00070   int initEncoding(std::vector<uint8_t>& buf);
00071 
00072   // retrieve reverence string
00073   const std::string& getRefID();
00074 
00075   // stop encoding
00076   void start();
00077 
00078   // stop encoding
00079   void stop();
00080 
00081   // encode frame
00082   void getVideoPacket(std::vector<uint8_t>& buf);
00083 
00084 private:
00085 
00086   // method to convert floating point image to 8-bit monochrome image
00087   void convertFloatingPointImageToMono8(float* input,
00088                                         const std::size_t width,
00089                                         const std::size_t height,
00090                                         std::vector<uint8_t>& output);
00091 
00092   // encoding thread running?
00093   bool doEncoding_;
00094 
00095   // reference ID used for registration
00096   const std::string refID_;
00097 
00098   // ROS topic
00099   const std::string topic_;
00100 
00101   // server&encoder configuration
00102   const ServerConfiguration& config_;
00103 
00104   // ROS image subscriber class
00105   ImageSubscriber subscriber_;
00106 
00107   // current frame ID
00108   unsigned frameID_;
00109   // init flag
00110   bool init_;
00111 
00112   boost::posix_time::ptime last_tick;
00113 
00114   // ffmpeg wrapper instance
00115   FFMPEG_Wrapper* ffmpeg_;
00116 
00117 };
00118 
00119 } // ros_http_video_streamer
00120 
00121 #endif /* FFMPEG_ENCODER_H_ */


ros_web_video
Author(s): Julius Kammer
autogenerated on Fri Aug 28 2015 12:38:36