vp8_streamer.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  *
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2014, Worcester Polytechnic Institute
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/or other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of the Worcester Polytechnic Institute nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  *********************************************************************/
00036 
00037 #include "web_video_server/vp8_streamer.h"
00038 
00039 namespace web_video_server
00040 {
00041 
00042 Vp8Streamer::Vp8Streamer(const async_web_server_cpp::HttpRequest& request,
00043                          async_web_server_cpp::HttpConnectionPtr connection, ros::NodeHandle& nh) :
00044     LibavStreamer(request, connection, nh, "webm", "libvpx", "video/webm")
00045 {
00046   quality_ = request.get_query_param_value_or_default("quality", "realtime");
00047 }
00048 Vp8Streamer::~Vp8Streamer()
00049 {
00050 }
00051 
00052 void Vp8Streamer::initializeEncoder()
00053 {
00054   typedef std::map<std::string, std::string> AvOptMap;
00055   AvOptMap av_opt_map;
00056   av_opt_map["quality"] = quality_;
00057   av_opt_map["deadline"] = "1";
00058   av_opt_map["auto-alt-ref"] = "0";
00059   av_opt_map["lag-in-frames"] = "1";
00060   av_opt_map["rc_lookahead"] = "1";
00061   av_opt_map["drop_frame"] = "1";
00062   av_opt_map["error-resilient"] = "1";
00063 
00064   for (AvOptMap::iterator itr = av_opt_map.begin(); itr != av_opt_map.end(); ++itr)
00065   {
00066     av_opt_set(codec_context_->priv_data, itr->first.c_str(), itr->second.c_str(), 0);
00067   }
00068 
00069   // Buffering settings
00070   int bufsize = 10;
00071   codec_context_->rc_buffer_size = bufsize;
00072   codec_context_->rc_initial_buffer_occupancy = bufsize; //bitrate/3;
00073   av_opt_set_int(codec_context_->priv_data, "bufsize", bufsize, 0);
00074   av_opt_set_int(codec_context_->priv_data, "buf-initial", bufsize, 0);
00075   av_opt_set_int(codec_context_->priv_data, "buf-optimal", bufsize, 0);
00076   av_opt_set_int(codec_context_->priv_data, "skip_threshold", 10, 0);
00077 }
00078 
00079 Vp8StreamerType::Vp8StreamerType() :
00080     LibavStreamerType("webm", "libvpx", "video/webm")
00081 {
00082 }
00083 
00084 boost::shared_ptr<ImageStreamer> Vp8StreamerType::create_streamer(const async_web_server_cpp::HttpRequest& request,
00085                                                                   async_web_server_cpp::HttpConnectionPtr connection,
00086                                                                   ros::NodeHandle& nh)
00087 {
00088   return boost::shared_ptr<ImageStreamer>(new Vp8Streamer(request, connection, nh));
00089 }
00090 
00091 }


web_video_server
Author(s): Mitchell Wills
autogenerated on Thu Jun 6 2019 18:02:48