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

FileHandler Class Reference

#include <filehandler.h>

Inheritance diagram for FileHandler:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 FileHandler ()
virtual ~FileHandler ()
virtual bool GetAutoSplit () const
virtual bool GetTimeStamp () const
virtual string GetBaseName () const
virtual string GetExtension () const
virtual int GetMaxFrameCount () const
virtual off_t GetMaxFileSize () const
virtual off_t GetFileSize ()=0
virtual int GetTotalFrames ()=0
virtual string GetFilename () const
virtual void SetAutoSplit (bool)
virtual void SetTimeStamp (bool)
virtual void SetBaseName (const string &base)
virtual void SetMaxFrameCount (int)
virtual void SetEveryNthFrame (int)
virtual void SetMaxFileSize (off_t)
virtual void SetSampleFrame (const Frame &sample)
virtual bool WriteFrame (const Frame &frame)
virtual bool FileIsOpen ()=0
virtual bool Create (const string &filename)=0
virtual int Write (const Frame &frame)=0
virtual int Close ()=0
virtual bool Done (void)
virtual bool Open (const char *s)=0
virtual int GetFrame (Frame &frame, int frameNum)=0
int GetFramesWritten () const

Protected Attributes

bool done
bool autoSplit
bool timeStamp
int maxFrameCount
int framesWritten
int everyNthFrame
int framesToSkip
off_t maxFileSize
string base
string extension
string filename

Constructor & Destructor Documentation

FileHandler::FileHandler  ) 
 

Definition at line 109 of file filehandler.cc.

00109                          : done( false ), autoSplit( false ), maxFrameCount( 999999 ),
00110         framesWritten( 0 ), filename( "" )
00111 {
00112     /* empty body */
00113 }

FileHandler::~FileHandler  )  [virtual]
 

Definition at line 116 of file filehandler.cc.

00117 {
00118     /* empty body */
00119 }


Member Function Documentation

virtual int FileHandler::Close  )  [pure virtual]
 

Implemented in RawHandler, and AVIHandler.

Referenced by ExportAVI::doExport(), PageCapture::stopCapture(), and WriteFrame().

virtual bool FileHandler::Create const string &  filename  )  [pure virtual]
 

Implemented in RawHandler, and AVIHandler.

Referenced by WriteFrame().

bool FileHandler::Done void   )  [virtual]
 

Definition at line 208 of file filehandler.cc.

References done.

00209 {
00210     return done;
00211 }

virtual bool FileHandler::FileIsOpen  )  [pure virtual]
 

Implemented in RawHandler, and AVIHandler.

Referenced by ExportAVI::doExport(), and WriteFrame().

bool FileHandler::GetAutoSplit  )  const [virtual]
 

Definition at line 122 of file filehandler.cc.

References autoSplit.

Referenced by WriteFrame().

00123 {
00124     return autoSplit;
00125 }

string FileHandler::GetBaseName  )  const [virtual]
 

Definition at line 134 of file filehandler.cc.

References base.

Referenced by WriteFrame().

00135 {
00136     return base;
00137 }

string FileHandler::GetExtension  )  const [virtual]
 

Definition at line 140 of file filehandler.cc.

References extension.

Referenced by KinoCommon::showFrameMoreInfo(), and WriteFrame().

00141 {
00142     return extension;
00143 }

string FileHandler::GetFilename  )  const [virtual]
 

Definition at line 156 of file filehandler.cc.

References filename.

Referenced by KinoCommon::showFrameMoreInfo(), PageCapture::startCapture(), and videoThread().

00157 {
00158     return filename;
00159 }

virtual off_t FileHandler::GetFileSize  )  [pure virtual]
 

Implemented in RawHandler, and AVIHandler.

Referenced by WriteFrame().

virtual int FileHandler::GetFrame Frame frame,
int  frameNum
[pure virtual]
 

Implemented in RawHandler, and AVIHandler.

Referenced by PlayList::AutoSplit(), convertFramesToSmilTime(), convertSmilTimeToFrames(), generate_file_preview(), PlayList::GetFrame(), and SrtContext::printEntry().

int FileHandler::GetFramesWritten  )  const [inline]
 

Definition at line 99 of file filehandler.h.

References framesWritten.

Referenced by videoThread().

00100     {
00101         return framesWritten;
00102     }

off_t FileHandler::GetMaxFileSize  )  const [virtual]
 

Definition at line 151 of file filehandler.cc.

References maxFileSize.

Referenced by WriteFrame().

00152 {
00153     return maxFileSize;
00154 }

int FileHandler::GetMaxFrameCount  )  const [virtual]
 

Definition at line 146 of file filehandler.cc.

References maxFrameCount.

Referenced by WriteFrame().

00147 {
00148     return maxFrameCount;
00149 }

bool FileHandler::GetTimeStamp  )  const [virtual]
 

Definition at line 128 of file filehandler.cc.

References timeStamp.

Referenced by WriteFrame().

00129 {
00130     return timeStamp;
00131 }

virtual int FileHandler::GetTotalFrames  )  [pure virtual]
 

Implemented in RawHandler, and AVIHandler.

Referenced by generate_file_preview(), PlayList::GetFrame(), PlayList::LoadMediaObject(), and PageTrim::loadScene().

virtual bool FileHandler::Open const char *  s  )  [pure virtual]
 

Implemented in RawHandler, and AVIHandler.

Referenced by fillMap(), generate_file_preview(), and PlayList::LoadMediaObject().

void FileHandler::SetAutoSplit bool   )  [virtual]
 

Definition at line 162 of file filehandler.cc.

References autoSplit.

Referenced by ExportAVI::doExport(), and PageCapture::startCapture().

00163 {
00164     autoSplit = flag;
00165 }

void FileHandler::SetBaseName const string &  base  )  [virtual]
 

Definition at line 174 of file filehandler.cc.

References base.

Referenced by ExportAVI::doExport(), and PageCapture::startCapture().

00175 {
00176     base = s;
00177 }

void FileHandler::SetEveryNthFrame int   )  [virtual]
 

Definition at line 187 of file filehandler.cc.

References everyNthFrame.

Referenced by ExportAVI::doExport(), and PageCapture::startCapture().

00188 {
00189     assert ( every > 0 );
00190 
00191     everyNthFrame = every;
00192 }

void FileHandler::SetMaxFileSize off_t   )  [virtual]
 

Definition at line 195 of file filehandler.cc.

References maxFileSize.

Referenced by ExportAVI::doExport(), and PageCapture::startCapture().

00196 {
00197     assert ( size >= 0 );
00198     maxFileSize = size;
00199 }

void FileHandler::SetMaxFrameCount int   )  [virtual]
 

Definition at line 180 of file filehandler.cc.

References maxFrameCount.

Referenced by ExportAVI::doExport(), and PageCapture::startCapture().

00181 {
00182     assert( count >= 0 );
00183     maxFrameCount = count;
00184 }

void FileHandler::SetSampleFrame const Frame sample  )  [virtual]
 

Reimplemented in AVIHandler.

Definition at line 202 of file filehandler.cc.

Referenced by WriteFrame().

00203 {
00204     /* empty body */
00205 }

void FileHandler::SetTimeStamp bool   )  [virtual]
 

Definition at line 168 of file filehandler.cc.

References timeStamp.

Referenced by ExportAVI::doExport(), and PageCapture::startCapture().

00169 {
00170     timeStamp = flag;
00171 }

virtual int FileHandler::Write const Frame frame  )  [pure virtual]
 

Implemented in RawHandler, and AVIHandler.

Referenced by WriteFrame().

bool FileHandler::WriteFrame const Frame frame  )  [virtual]
 

Definition at line 214 of file filehandler.cc.

References Close(), Create(), done, everyNthFrame, FileIsOpen(), filename, framesToSkip, framesWritten, Frame::GetAudioInfo(), GetAutoSplit(), GetBaseName(), GetExtension(), GetFileSize(), Frame::GetFrameSize(), GetMaxFileSize(), GetMaxFrameCount(), Frame::GetRecordingDate(), Frame::GetTimeCode(), GetTimeStamp(), info, Frame::IsNewRecording(), AudioInfo::samples, TimeCode::sec, SetSampleFrame(), and Write().

Referenced by captureThread(), ExportAVI::doExport(), and PageCapture::startCapture().

00215 {
00216     static TimeCode prevTimeCode = { 0, 0, -1, 0 };
00217     TimeCode timeCode;
00218 
00219     /* If the user wants autosplit, start a new file if a
00220        new recording is detected. */
00221     frame.GetTimeCode( timeCode );
00222     int time_diff = timeCode.sec - prevTimeCode.sec;
00223     bool discontinuity = prevTimeCode.sec != -1 && ( time_diff > 1 || ( time_diff < 0 && time_diff > -59 ) );
00224     if ( FileIsOpen() && GetAutoSplit() == true && ( frame.IsNewRecording() || discontinuity ) )
00225     {
00226         Close();
00227     }
00228 
00229     if ( FileIsOpen() == false )
00230     {
00231 
00232         string filename;
00233         static int counter = 0;
00234 
00235         if ( GetTimeStamp() == true )
00236         {
00237             ostringstream sb, sb2;
00238             struct tm   date;
00239             string  recDate;
00240 
00241             if ( ! frame.GetRecordingDate( date ) )
00242             {
00243                 struct timeval tv;
00244                 struct timezone tz;
00245                 gettimeofday( &tv, &tz );
00246                 localtime_r( static_cast< const time_t * >( &tv.tv_sec ), &date );
00247             }
00248             sb << setfill( '0' )
00249             << setw( 4 ) << date.tm_year + 1900 << '.'
00250             << setw( 2 ) << date.tm_mon + 1 << '.'
00251             << setw( 2 ) << date.tm_mday << '_'
00252             << setw( 2 ) << date.tm_hour << '-'
00253             << setw( 2 ) << date.tm_min << '-'
00254             << setw( 2 ) << date.tm_sec;
00255             recDate = sb.str();
00256             sb2 << GetBaseName() << recDate << GetExtension();
00257             filename = sb2.str();
00258             cerr << ">>> Trying " << filename << endl;
00259         }
00260         else
00261         {
00262             struct stat stats;
00263             do
00264             {
00265                 ostringstream sb;
00266                 sb << GetBaseName() << setfill( '0' ) << setw( 3 ) << ++ counter << GetExtension();
00267                 filename = sb.str();
00268                 cerr << ">>> Trying " << filename << endl;
00269             }
00270             while ( stat( filename.c_str(), &stats ) == 0 );
00271         }
00272 
00273         SetSampleFrame( frame );
00274         if ( Create( filename ) == false )
00275         {
00276             cerr << ">>> Error creating file!" << endl;
00277             return false;
00278         }
00279         framesWritten = 0;
00280         framesToSkip = 0;
00281     }
00282 
00283     /* write frame */
00284 
00285     if ( framesToSkip == 0 )
00286     {
00287         if ( 0 > Write( frame ) )
00288         {
00289             cerr << ">>> Error writing frame!" << endl;
00290             return false;
00291         }
00292         framesToSkip = everyNthFrame;
00293         ++framesWritten;
00294     }
00295     framesToSkip--;
00296 
00297     /* If the frame count is exceeded, close the current file.
00298        If the autosplit flag is set, a new file will be created in the next iteration.
00299        If the flag is not set, we are done. */
00300 
00301     if ( ( GetMaxFrameCount() > 0 ) &&
00302             ( framesWritten >= GetMaxFrameCount() ) )
00303     {
00304         Close();
00305         done = !GetAutoSplit();
00306     }
00307 
00308     /* If the file size could be exceeded by another frame, close the current file.
00309        If the autosplit flag is set, a new file will be created on the next iteration.
00310        If the flag is not set, we are done. */
00311     /* not exact, but should be good enough to prevent going over. */
00312     if ( FileIsOpen() )
00313     {
00314         AudioInfo info;
00315         frame.GetAudioInfo( info );
00316         if ( ( GetFileSize() > 0 ) && ( GetMaxFileSize() > 0 ) &&
00317                 ( GetFileSize() + frame.GetFrameSize() + info.samples * 4 + 12 )
00318                 >= GetMaxFileSize() )
00319         {                     // 12 = sizeof chunk metadata
00320             Close();
00321             done = !GetAutoSplit();
00322         }
00323     }
00324     prevTimeCode.sec = timeCode.sec;
00325     return true;
00326 }


Member Data Documentation

bool FileHandler::autoSplit [protected]
 

Definition at line 106 of file filehandler.h.

Referenced by GetAutoSplit(), and SetAutoSplit().

string FileHandler::base [protected]
 

Definition at line 113 of file filehandler.h.

Referenced by GetBaseName(), and SetBaseName().

bool FileHandler::done [protected]
 

Definition at line 105 of file filehandler.h.

Referenced by Done(), and WriteFrame().

int FileHandler::everyNthFrame [protected]
 

Definition at line 110 of file filehandler.h.

Referenced by SetEveryNthFrame(), and WriteFrame().

string FileHandler::extension [protected]
 

Definition at line 114 of file filehandler.h.

Referenced by AVIHandler::AVIHandler(), GetExtension(), and RawHandler::RawHandler().

string FileHandler::filename [protected]
 

Definition at line 115 of file filehandler.h.

Referenced by GetFilename(), AVIHandler::Open(), RawHandler::Open(), and WriteFrame().

int FileHandler::framesToSkip [protected]
 

Definition at line 111 of file filehandler.h.

Referenced by WriteFrame().

int FileHandler::framesWritten [protected]
 

Definition at line 109 of file filehandler.h.

Referenced by GetFramesWritten(), and WriteFrame().

off_t FileHandler::maxFileSize [protected]
 

Definition at line 112 of file filehandler.h.

Referenced by GetMaxFileSize(), and SetMaxFileSize().

int FileHandler::maxFrameCount [protected]
 

Definition at line 108 of file filehandler.h.

Referenced by GetMaxFrameCount(), and SetMaxFrameCount().

bool FileHandler::timeStamp [protected]
 

Definition at line 107 of file filehandler.h.

Referenced by GetTimeStamp(), and SetTimeStamp().


The documentation for this class was generated from the following files:
Generated on Sun Mar 11 22:12:54 2007 for Kino by  doxygen 1.4.2