Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

filehandler.h

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

Generated on Sun Mar 11 22:11:45 2007 for Kino by  doxygen 1.4.2