Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

avstream.hh

Go to the documentation of this file.
00001 /*
00002  * PIAVE - PIAVE Is A Video Editor
00003  *
00004  * Copyright (C) 2002 Rolf Dubitzky, rolf@dubitzky.de
00005  *
00006  */
00007 
00008 /*
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software Foundation,
00021  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00022  */
00023 
00024 
00029 #if ! defined( AVSTREAM_HH )
00030 #define AVSTREAM_HH
00031 
00032 // stdc
00033 #include <signal.h>
00034 #include <unistd.h>
00035 #include <fcntl.h>
00036 #include <sys/stat.h>
00037 
00038 // stdc++
00039 #include <string>
00040 #include <map>
00041 
00042 // PIAVE
00043 #include "piave_base.hh"
00044 #include "exception.hh"
00045 #include "videoformat.hh"
00046 #include "plugin.hh"
00047 
00048 namespace PIAVE {
00049 
00050     class Frame;
00051 
00052     class Stream : public PluginBase
00053     {
00054       public:
00055         enum StreamState {
00056             state_closed,
00057             state_open,
00058             state_error
00059         };
00060 
00061       public:
00062         Stream() : PluginBase(), _state( state_closed ) {}
00063         virtual ~Stream() {}
00064 
00065         StreamState getState() const { return _state; }
00066 
00067         void setState( StreamState s ) { _state = s; }
00068 
00069       private:
00070         StreamState _state;
00071     };
00072 
00079     class InAVStreamIFace : public Stream
00080     {
00081       public:
00082         InAVStreamIFace();
00083         virtual ~InAVStreamIFace();
00084         virtual Frame getFrame( Time t ) = 0;
00085         virtual void decodeMetaData( Frame & f ) {}
00086         virtual void decodeVideo( Frame & f, uint8_t * dest = 0 ) = 0;
00087         virtual void decodeAudio( Frame & f, uint8_t * dest = 0 ) = 0;
00088 
00089         void setVideoFmt( VideoFmt v ) { _videoFmt = v; }
00090         VideoFmt getVideoFmt() const { return _videoFmt; }
00091 
00092       private:
00093         VideoFmt  _videoFmt;
00094         
00095       protected:
00096         int       _deliveredFrames;
00097         PropertyNode * _frameProperties;
00098     };
00099 
00104     class OutAVStreamIFace : public Stream
00105     {
00106       public:
00107         OutAVStreamIFace() : 
00108           Stream(), _recievedFrames( 0 ) {}
00109         virtual ~OutAVStreamIFace();
00110 
00111         virtual void putFrame( Frame & f ) = 0;
00112 
00113         void setVideoFmt( VideoFmt v ) { _videoFmt = v; }
00114         VideoFmt getVideoFmt() const { return _videoFmt; }
00115 
00116       private:
00117         VideoFmt  _videoFmt;
00118 
00119       protected:
00120         int       _recievedFrames;
00121     };
00122 
00127     class InAudioStreamIFace : public Stream
00128     {
00129       public:
00130         InAudioStreamIFace() : Stream() {}
00131         virtual ~InAudioStreamIFace() {}
00132         virtual Frame getFrame( Time t ) = 0;
00133         virtual void decodeMetaData( Frame & f ) {}
00134         virtual void decodeAudio( Frame & f, uint8_t * dest = 0  ) = 0;
00135     };
00136 
00141     class OutAudioStreamIFace  : public Stream
00142     {
00143       public:
00144         OutAudioStreamIFace() : Stream() {}
00145         virtual void putFrame( Frame & f ) = 0;
00146     };
00147 
00148 
00149     /***
00150      * \class InFileStream
00151      *      defines interface for streams from files
00152      *
00153      *  \todo   others might come from v4l grabber devices, etc.
00154      *  \todo   handle buffered IO - FILE
00155      *  \todo : 
00156      *    -  mpeg, avi, streams ... ? via libavcodev 
00157      *    -  pure audio streams ... ? lame ? SDL ?
00158      *    -  pure image streams, i.e. .png for overlay ? glib ? imagemagick ?
00159      */ 
00160     class InFileStream
00161     {
00162       public:
00163         InFileStream( const std::string& fileName );
00164         virtual ~InFileStream();
00165 
00166         void                 seek( Time t ) { _pos=t; }
00167         Time                 length() const { return _length; };
00168         const std::string    getFileName() const { return _fileName; };
00169         virtual off_t        getFileSize();
00170 
00171       protected:
00172         void setLength( Time t ) { _length = t; };
00173 
00174       protected:
00175         int             _fd;
00176 
00177       private:
00178         std::string     _fileName;
00179         Time            _length;     // length in seconds
00180         Time            _pos;        // pos in seconds
00181         struct stat     _stat;
00182         
00183     };
00184 
00185     class OutFileStream
00186     {
00187       public:
00188         OutFileStream( const std::string& fileName );
00189         virtual ~OutFileStream();
00190 
00191         const std::string  getFileName() const { return _fileName; };
00192 
00193         virtual void closeFD();
00194 
00195       protected:
00196         int             _fd;
00197 
00198       private:
00199         std::string   _fileName;
00200     };
00201 
00202 
00208     class InAVFStream : public InFileStream, public InAVStreamIFace
00209     {
00210       public:
00211         InAVFStream( const std::string& fileName ) :
00212           InFileStream( fileName ), InAVStreamIFace() {}
00213     };
00214 
00220     class OutAVFStream : public OutFileStream, public OutAVStreamIFace
00221     {
00222       public:
00223         OutAVFStream( const std::string& fileName ) :
00224           OutFileStream( fileName ), OutAVStreamIFace() {}
00225         virtual ~OutAVFStream() { INFO( "~OutAVFStream" ); }
00226     };
00227 
00228 
00229     /*
00230      *  interface for decoders and encoders
00231      *
00232      */
00233     class CodecIFace : public PluginBase
00234     {
00235       public:
00236         CodecIFace() : PluginBase(), _videoFmt(), _initialized( false ) {}
00237         double getFPS()  const { return _videoFmt.fps; }
00238         int    getWidth()  const { return _videoFmt.width; }
00239         int    getHeight() const { return _videoFmt.height; }
00240         double getAspect() const { return _videoFmt.aspect; }
00241         int    getSizePixels() const { return _videoFmt.width * _videoFmt.height; }
00242         int    isInitialized() const { return _initialized; }
00243 
00244         void   setFPS( double fps ) { _videoFmt.fps = fps; }
00245         void   setWidth( int width ) { _videoFmt.width = width; }
00246         void   setHeight( int height ) { _videoFmt.height = height; }
00247         void   setAspect( double aspect ) { _videoFmt.aspect = aspect; }
00248         void   setInitialized( bool i ) { _initialized = i; }
00249         void      setVideoFmt( VideoFmt v ) { _videoFmt = v; }
00250         VideoFmt  getVideoFmt() const { return _videoFmt; }
00251 
00252         virtual bool init( uint8_t * data = 0 ) throw (exception) = 0;
00253 
00254         virtual PropertyNode * getFrameProperties( PropertyNode * node ) { return 0; };
00255 
00256       private:
00257         VideoFmt           _videoFmt;
00258         bool               _initialized;
00259     };
00260 
00261     class AVDecoderIFace : public CodecIFace
00262     {
00263       public:
00264         virtual void decodeMetaData( Frame & f, PropertyNode * p ) {};
00265         virtual void decodeVideo( Frame & f, uint8_t * dest = 0 ) = 0;
00266         virtual void decodeAudio( Frame & f, uint8_t * dest = 0 ) = 0;
00267     };
00268 
00269     class AVEncoderIFace : public CodecIFace
00270     {
00271       public:
00272 //        virtual void encodeMetaData( Frame & f, PropertyNode * p ) {};
00273         virtual void encodeVideo( Frame & f, uint8_t * dest = 0 ) = 0;
00274         virtual void encodeAudio( Frame & f, uint8_t * dest = 0 ) = 0;
00275     };
00276 
00277 };
00278 
00279 #endif

Generated on Tue Oct 14 20:45:36 2003 for piave by doxygen1.2.18