video.h
Go to the documentation of this file.
00001 /* This file is part of the Pangolin Project.
00002  * http://github.com/stevenlovegrove/Pangolin
00003  *
00004  * Copyright (c) 2011 Steven Lovegrove
00005  *
00006  * Permission is hereby granted, free of charge, to any person
00007  * obtaining a copy of this software and associated documentation
00008  * files (the "Software"), to deal in the Software without
00009  * restriction, including without limitation the rights to use,
00010  * copy, modify, merge, publish, distribute, sublicense, and/or sell
00011  * copies of the Software, and to permit persons to whom the
00012  * Software is furnished to do so, subject to the following
00013  * conditions:
00014  *
00015  * The above copyright notice and this permission notice shall be
00016  * included in all copies or substantial portions of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00019  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00020  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00021  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00022  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00023  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00024  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00025  * OTHER DEALINGS IN THE SOFTWARE.
00026  */
00027 
00028 #ifndef PANGOLIN_VIDEO_H
00029 #define PANGOLIN_VIDEO_H
00030 
00031 #include "pangolin.h"
00032 
00033 // Pangolin video supports various cameras and file formats through
00034 // different 3rd party libraries.
00035 //
00036 // Video URI's take the following form:
00037 //  scheme:[param1=value1,param2=value2,...]//device
00038 //
00039 // scheme = file | dc1394 | v4l | convert | mjpeg
00040 //
00041 // file/files - read PVN file format (pangolin video) or other formats using ffmpeg
00042 //  e.g. "file:[realtime=1]///home/user/video/movie.pvn"
00043 //  e.g. "file:[stream=1]///home/user/video/movie.avi"
00044 //  e.g. "files:///home/user/seqiemce/foo%03d.jpeg"
00045 //
00046 // dc1394 - capture video through a firewire camera
00047 //  e.g. "dc1394:[fmt=RGB24,size=640x480,fps=30,iso=400,dma=10]//0"
00048 //  e.g. "dc1394:[fmt=FORMAT7_1,size=640x480,pos=2+2,iso=400,dma=10]//0"
00049 //
00050 // v4l - capture video from a Video4Linux (USB) camera (normally YUVY422 format)
00051 //  e.g. "v4l:///dev/video0"
00052 //
00053 // convert - use FFMPEG to convert between video pixel formats
00054 //  e.g. "convert:[fmt=RGB24]//v4l:///dev/video0"
00055 //
00056 // mjpeg - capture from (possibly networked) motion jpeg stream using FFMPEG
00057 //  e.g. "mjpeg://http://127.0.0.1/?action=stream"
00058 
00059 namespace pangolin
00060 {
00061 struct VideoException : std::exception
00062 {
00063     VideoException(std::string str) : desc(str) {}
00064     VideoException(std::string str, std::string detail)
00065     {
00066         desc = str + "\n\t" + detail;
00067     }
00068     ~VideoException() throw() {}
00069     const char* what() const throw()
00070     {
00071         return desc.c_str();
00072     }
00073     std::string desc;
00074 };
00075 
00076 struct VideoPixelFormat
00077 {
00078     std::string format;
00079     unsigned int channels;
00080     unsigned int channel_bits[4];
00081     unsigned int bpp;
00082     bool planar;
00083 };
00084 
00085 struct Uri
00086 {
00087     std::string scheme;
00088     std::string url;
00089     std::map<std::string,std::string> params;
00090 };
00091 
00094 VideoPixelFormat VideoFormatFromString(const std::string& format);
00095 
00097 struct VideoInterface
00098 {
00099     virtual ~VideoInterface() {}
00100     virtual unsigned Width() const = 0;
00101     virtual unsigned Height() const = 0;
00102     virtual size_t SizeBytes() const = 0;
00103 
00104     virtual std::string PixFormat() const = 0;
00105 
00106     virtual void Start() = 0;
00107     virtual void Stop() = 0;
00108 
00112     virtual bool GrabNext( unsigned char* image, bool wait = true ) = 0;
00113 
00118     virtual bool GrabNewest( unsigned char* image, bool wait = true ) = 0;
00119 };
00120 
00121 struct VideoInput : public VideoInterface
00122 {
00123     VideoInput();
00124     VideoInput(std::string uri);
00125     ~VideoInput();
00126 
00127     void Open(std::string uri);
00128     void Reset();
00129 
00130     unsigned Width() const;
00131     unsigned Height() const;
00132     size_t SizeBytes() const;
00133     std::string PixFormat() const;
00134 
00135     void Start();
00136     void Stop();
00137     bool GrabNext( unsigned char* image, bool wait = true );
00138     bool GrabNewest( unsigned char* image, bool wait = true );
00139 
00140 protected:
00141     std::string uri;
00142     VideoInterface* video;
00143 };
00144 
00146 VideoInterface* OpenVideo(std::string uri);
00147 
00149 Uri ParseUri(std::string str_uri);
00150 }
00151 
00152 #endif // PANGOLIN_VIDEO_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


pangolin_wrapper
Author(s): Todor Stoyanov
autogenerated on Wed Feb 13 2013 14:03:25