filehandler.h

Go to the documentation of this file.
00001 /*
00002 * filehandler.h
00003 * Copyright (C) 2000 Arne Schirmacher <arne@schirmacher.de>
00004 *
00005 * This program is free software; you can redistribute it and/or modify
00006 * it under the terms of the GNU General Public License as published by
00007 * the Free Software Foundation; either version 2 of the License, or
00008 * (at your option) any later version.
00009 *
00010 * This program is distributed in the hope that it will be useful,
00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 * GNU General Public License for more details.
00014 *
00015 * You should have received a copy of the GNU General Public License
00016 * along with this program; if not, write to the Free Software Foundation,
00017 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #ifndef _FILEHANDLER_H
00021 #define _FILEHANDLER_H
00022 
00023  enum { PAL_FORMAT, NTSC_FORMAT, AVI_DV1_FORMAT, AVI_DV2_FORMAT, QT_FORMAT, RAW_FORMAT, TEST_FORMAT, UNDEFINED };
00024 
00025 #include <vector>
00026 using std::vector;
00027 
00028 #include <string>
00029 using std::string;
00030 
00031 //#include "preferences.h"
00032 #include "frame.h"
00033 #include "riff.h"
00034 #include "avi.h"
00035 #include <sys/types.h>
00036 #include <stdint.h>
00037 
00038 enum FileCaptureMode {
00039     CAPTURE_IGNORE,
00040     CAPTURE_FRAME_APPEND,
00041     CAPTURE_FRAME_INSERT,
00042     CAPTURE_MOVIE_APPEND
00043 };
00044 
00045 class FileTracker
00046 {
00047 protected:
00048         FileTracker();
00049         ~FileTracker();
00050 public:
00051         static FileTracker &GetInstance( );
00052         void SetMode( FileCaptureMode );
00053         FileCaptureMode GetMode( );
00054         unsigned int Size();
00055         char *Get( int );
00056         void Add( const char * );
00057         void Clear( );
00058 private:
00059         static FileTracker *instance;
00060         vector <char *> list;
00061         FileCaptureMode mode;
00062 };
00063 
00064 class FileHandler
00065 {
00066 public:
00067 
00068         FileHandler();
00069         virtual ~FileHandler();
00070 
00071         virtual bool GetAutoSplit() const;
00072         virtual bool GetTimeStamp() const;
00073         virtual string GetBaseName() const;
00074         virtual string GetExtension() const;
00075         virtual int GetMaxFrameCount() const;
00076         virtual off_t GetMaxFileSize() const;
00077         virtual off_t GetFileSize() = 0;
00078         virtual int GetTotalFrames() = 0;
00079         virtual string GetFilename() const;
00080 
00081         virtual void SetAutoSplit( bool );
00082         virtual void SetTimeStamp( bool );
00083         virtual void SetBaseName( const string& base );
00084         virtual void SetMaxFrameCount( int );
00085         virtual void SetEveryNthFrame( int );
00086         virtual void SetMaxFileSize( off_t );
00087         virtual void SetSampleFrame( const Frame& sample );
00088 
00089         virtual bool WriteFrame( const Frame& frame );
00090         virtual bool FileIsOpen() = 0;
00091         virtual bool Create( const string& filename ) = 0;
00092         virtual int Write( const Frame& frame ) = 0;
00093         virtual int Close() = 0;
00094         virtual bool Done( void );
00095 
00096         virtual bool Open( const char *s ) = 0;
00097         virtual int GetFrame( Frame &frame, int frameNum ) = 0;
00098         int GetFramesWritten() const
00099         {
00100                 return framesWritten;
00101         }
00102 
00103 protected:
00104         bool done;
00105         bool autoSplit;
00106         bool timeStamp;
00107         int maxFrameCount;
00108         int framesWritten;
00109         int everyNthFrame;
00110         int framesToSkip;
00111         off_t maxFileSize;
00112         string base;
00113         string extension;
00114         string filename;
00115 };
00116 
00117 
00118 class RawHandler: public FileHandler
00119 {
00120 public:
00121         int fd;
00122 
00123         RawHandler();
00124         ~RawHandler();
00125 
00126         bool FileIsOpen();
00127         bool Create( const string& filename );
00128         int Write( const Frame& frame );
00129         int Close();
00130         off_t GetFileSize();
00131         int GetTotalFrames();
00132         bool Open( const char *s );
00133         int GetFrame( Frame &frame, int frameNum );
00134 private:
00135         int numBlocks;
00136 };
00137 
00138 
00139 class AVIHandler: public FileHandler
00140 {
00141 public:
00142         AVIHandler( int format = AVI_DV1_FORMAT );
00143         ~AVIHandler();
00144 
00145         void SetSampleFrame( const Frame& sample );
00146         bool FileIsOpen();
00147         bool Create( const string& filename );
00148         int Write( const Frame& frame );
00149         int Close();
00150         off_t GetFileSize();
00151         int GetTotalFrames();
00152         bool Open( const char *s );
00153         int GetFrame( Frame &frame, int frameNum );
00154         bool GetOpenDML() const;
00155         void SetOpenDML( bool );
00156         int GetFormat() const
00157         {
00158                 return aviFormat;
00159         }
00160 
00161 protected:
00162         AVIFile *avi;
00163         int aviFormat;
00164         AudioInfo audioInfo;
00165         VideoInfo videoInfo;
00166         bool isOpenDML;
00167         DVINFO dvinfo;
00168         FOURCC  fccHandler;
00169         int channels;
00170         bool isFullyInitialized;
00171         int16_t *audioBuffer;
00172         int16_t *audioChannels[ 4 ];
00173 };
00174 
00175 
00176 #ifdef HAVE_LIBQUICKTIME
00177 #include <quicktime/quicktime.h>
00178 
00179 class QtHandler: public FileHandler
00180 {
00181 public:
00182         QtHandler();
00183         ~QtHandler();
00184 
00185         bool FileIsOpen();
00186         bool Create( const string& filename );
00187         int Write( const Frame& frame );
00188         int Close();
00189         off_t GetFileSize();
00190         int GetTotalFrames();
00191         bool Open( const char *s );
00192         int GetFrame( Frame &frame, int frameNum );
00193         void AllocateAudioBuffers();
00194 
00195 private:
00196         quicktime_t *fd;
00197         long samplingRate;
00198         int samplesPerBuffer;
00199         int channels;
00200         bool isFullyInitialized;
00201         unsigned int audioBufferSize;
00202         int16_t *audioBuffer;
00203         short int** audioChannelBuffer;
00204 
00205         void Init();
00206         inline void DeinterlaceStereo16( void* pInput, int iBytes, void* pLOutput, void* pROutput );
00207 
00208 };
00209 #endif
00210 
00211 #endif

Generated on Tue Jan 22 17:07:29 2008 for MUAN by  doxygen 1.4.7