HttpOutputStream.C

Go to the documentation of this file.
00001 /*!@file Media/HttpOutputStream.C Write frames to movie files */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00005 // by the University of Southern California (USC) and the iLab at USC.  //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Lior Elazary
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Media/HttpOutputStream.C $
00035 // $Id: HttpOutputStream.C 12962 2010-03-06 02:13:53Z irock $
00036 //
00037 
00038 #ifndef MEDIA_HTTPOUTPUTSTREAM_C_DEFINED
00039 #define MEDIA_HTTPOUTPUTSTREAM_C_DEFINED
00040 
00041 #include "Media/HttpOutputStream.H"
00042 
00043 
00044 #include "Component/ModelOptionDef.H"
00045 #include "Image/Image.H"
00046 #include "Image/Pixels.H"
00047 #include "Media/HttpEncoder.H"
00048 #include "Raster/GenericFrame.H"
00049 #include "Transport/TransportOpts.H"
00050 #include "Util/Assert.H"
00051 #include "Util/log.H"
00052 #include "rutz/shared_ptr.h"
00053 #include "rutz/trace.h"
00054 
00055 #include <map>
00056 #include <string>
00057 
00058 #ifdef INVT_HAVE_AVCODEC
00059 // private command-line option defs
00060 
00061 // Used by: OutputHttpStream
00062 const ModelOptionDef OPT_OutputHttpStreamFrameRate =
00063   { MODOPT_ARG(int), "OutputHttpStreamFrameRate", &MOC_OUTPUT, OPTEXP_CORE,
00064     "The frame rate, in frames-per-second, for output mpeg streams",
00065     "output-http-framerate", '\0', "<frames-per-second>", "25" };
00066 
00067 // Used by: OutputStream
00068 const ModelOptionDef OPT_OutputHttpStreamBitRate =
00069   { MODOPT_ARG(int), "OutputHttpStreamBitRate", &MOC_OUTPUT, OPTEXP_CORE,
00070     "The bit rate for output mpeg streams",
00071     // FIXME it's not clear from the ffmpeg docs whether the bitrate
00072     // is bits-per-second or bits-per-frame
00073     "output-http-bitrate", '\0', "<bits-per-?>", "750000" };
00074 
00075 // Used by: OutputHttpStream
00076 const ModelOptionDef OPT_OutputHttpStreamBufSize =
00077   { MODOPT_ARG(ByteCount), "OutputHttpStreamBufSize", &MOC_OUTPUT, OPTEXP_CORE,
00078     "The size, in bytes, of the per-frame output buffer for output "
00079     "mpeg streams (you can try increasing the buffer size if you "
00080     "are seeing warnings like 'encoded frame too large')",
00081     "output-http-bufsize", '\0', "<bytes>", "2MiB" };
00082 
00083 // Used by: OutputHttpStream
00084 static const ModelOptionDef OPT_OutputHttpStreamCodec =
00085   { MODOPT_ARG_STRING, "OutputHttpStreamCodec", &MOC_OUTPUT, OPTEXP_CORE,
00086     "Type of video output codec to use (use value 'List' to see list of "
00087     "available codecs on your system)",
00088     "output-http-codec", '\0', "<List|name>", "mpeg1video" };
00089 
00090 // ######################################################################
00091 OutputHttpStream::OutputHttpStream(OptionManager& mgr,
00092                                    const std::string& descrName,
00093                                    const std::string& tagName)
00094   :
00095   LowLevelEncoderMap(mgr, descrName, tagName),
00096         itsHttpServer(new HttpServer(mgr)),
00097   itsFrameRate(&OPT_OutputHttpStreamFrameRate, this),
00098   itsFrameRateBase(tagName+"FrameRateBase", this, 1),
00099   itsBitRate(&OPT_OutputHttpStreamBitRate, this),
00100   itsBufSize(&OPT_OutputHttpStreamBufSize, this),
00101   itsCodecName(&OPT_OutputHttpStreamCodec, this),
00102   itsStem()
00103 {
00104         addSubComponent(itsHttpServer);
00105 }
00106 
00107 // ######################################################################
00108 void OutputHttpStream::setConfigInfo(const std::string& filestem)
00109 {
00110   // NOTE: if you modify any behavior here, then please update the
00111   // corresponding documentation for the global "--out" option inside
00112   // the OPT_OutputFrameSink definition in Media/MediaOpts.C
00113 
00114   this->setFileStem(filestem);
00115 }
00116 
00117 // ######################################################################
00118 void OutputHttpStream::setFileStem(const std::string& s)
00119 {
00120 GVX_TRACE(__PRETTY_FUNCTION__);
00121   itsStem = s;
00122 }
00123 
00124 
00125 #include "Media/MediaOpts.H"
00126 #include "Media/FrameRange.H"
00127 #include "Component/ModelManager.H"
00128 
00129 // ######################################################################
00130 rutz::shared_ptr<LowLevelEncoder>
00131 OutputHttpStream::makeEncoder(const GenericFrameSpec& spec,
00132                               const std::string& shortname,
00133                               const FrameInfo& auxinfo)
00134 {
00135   // NOTE: for now, we just ignore the FrameInfo auxinfo here; could
00136   // we use it to embed a comment in the mpeg file, though?
00137 
00138   return rutz::shared_ptr<HttpEncoder>
00139     (new HttpEncoder(itsHttpServer,
00140                      itsStem+shortname,
00141                      itsCodecName.getVal(),
00142                      itsBitRate.getVal(),
00143                      itsFrameRate.getVal(),
00144                      itsFrameRateBase.getVal(),
00145                      spec.dims,
00146                      itsBufSize.getVal().bytes()));
00147 }
00148 
00149 #endif // HAVE_FFMPEG_AVCODEC_H
00150 
00151 // ######################################################################
00152 /* So things look consistent in everyone's emacs... */
00153 /* Local Variables: */
00154 /* mode: c++ */
00155 /* indent-tabs-mode: nil */
00156 /* End: */
00157 
00158 #endif // MEDIA_HTTPOUTPUTSTREAM_C_DEFINED
Generated on Sun May 8 08:41:01 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3