liveMedia/include/AVIFileSink.hh

Go to the documentation of this file.
00001 /**********
00002 This library is free software; you can redistribute it and/or modify it under
00003 the terms of the GNU Lesser General Public License as published by the
00004 Free Software Foundation; either version 2.1 of the License, or (at your
00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
00006 
00007 This library is distributed in the hope that it will be useful, but WITHOUT
00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
00010 more details.
00011 
00012 You should have received a copy of the GNU Lesser General Public License
00013 along with this library; if not, write to the Free Software Foundation, Inc.,
00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // "liveMedia"
00017 // Copyright (c) 1996-2012 Live Networks, Inc.  All rights reserved.
00018 // A sink that generates an AVI file from a composite media session
00019 // C++ header
00020 
00021 #ifndef _AVI_FILE_SINK_HH
00022 #define _AVI_FILE_SINK_HH
00023 
00024 #ifndef _MEDIA_SESSION_HH
00025 #include "MediaSession.hh"
00026 #endif
00027 
00028 class AVIFileSink: public Medium {
00029 public:
00030   static AVIFileSink* createNew(UsageEnvironment& env,
00031                                 MediaSession& inputSession,
00032                                 char const* outputFileName,
00033                                 unsigned bufferSize = 20000,
00034                                 unsigned short movieWidth = 240,
00035                                 unsigned short movieHeight = 180,
00036                                 unsigned movieFPS = 15,
00037                                 Boolean packetLossCompensate = False);
00038 
00039   typedef void (afterPlayingFunc)(void* clientData);
00040   Boolean startPlaying(afterPlayingFunc* afterFunc,
00041                        void* afterClientData);
00042 
00043   unsigned numActiveSubsessions() const { return fNumSubsessions; }
00044 
00045 private:
00046   AVIFileSink(UsageEnvironment& env, MediaSession& inputSession,
00047               char const* outputFileName, unsigned bufferSize,
00048               unsigned short movieWidth, unsigned short movieHeight,
00049               unsigned movieFPS, Boolean packetLossCompensate);
00050       // called only by createNew()
00051   virtual ~AVIFileSink();
00052 
00053   Boolean continuePlaying();
00054   static void afterGettingFrame(void* clientData, unsigned frameSize,
00055                                 unsigned numTruncatedBytes,
00056                                 struct timeval presentationTime,
00057                                 unsigned durationInMicroseconds);
00058   static void onSourceClosure(void* clientData);
00059   void onSourceClosure1();
00060   static void onRTCPBye(void* clientData);
00061   void completeOutputFile();
00062 
00063 private:
00064   friend class AVISubsessionIOState;
00065   MediaSession& fInputSession;
00066   FILE* fOutFid;
00067   unsigned fBufferSize;
00068   Boolean fPacketLossCompensate;
00069   Boolean fAreCurrentlyBeingPlayed;
00070   afterPlayingFunc* fAfterFunc;
00071   void* fAfterClientData;
00072   unsigned fNumSubsessions;
00073   unsigned fNumBytesWritten;
00074   struct timeval fStartTime;
00075   Boolean fHaveCompletedOutputFile;
00076 
00077 private:
00079 
00080   unsigned addWord(unsigned word); // outputs "word" in little-endian order
00081   unsigned addHalfWord(unsigned short halfWord);
00082   unsigned addByte(unsigned char byte) {
00083     putc(byte, fOutFid);
00084     return 1;
00085   }
00086   unsigned addZeroWords(unsigned numWords);
00087   unsigned add4ByteString(char const* str);
00088   void setWord(unsigned filePosn, unsigned size);
00089 
00090   // Define member functions for outputting various types of file header:
00091 #define _header(name) unsigned addFileHeader_##name()
00092   _header(AVI);
00093       _header(hdrl);
00094           _header(avih);
00095           _header(strl);
00096               _header(strh);
00097               _header(strf);
00098               _header(JUNK);
00099 //        _header(JUNK);
00100       _header(movi);
00101 private:
00102   unsigned short fMovieWidth, fMovieHeight;
00103   unsigned fMovieFPS;
00104   unsigned fRIFFSizePosition, fRIFFSizeValue;
00105   unsigned fAVIHMaxBytesPerSecondPosition;
00106   unsigned fAVIHFrameCountPosition;
00107   unsigned fMoviSizePosition, fMoviSizeValue;
00108   class AVISubsessionIOState* fCurrentIOState;
00109   unsigned fJunkNumber;
00110 };
00111 
00112 #endif

Generated on Thu May 17 07:11:45 2012 for live by  doxygen 1.5.2