00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _QUICKTIME_FILE_SINK_HH
00022 #define _QUICKTIME_FILE_SINK_HH
00023
00024 #ifndef _MEDIA_SESSION_HH
00025 #include "MediaSession.hh"
00026 #endif
00027
00028 class QuickTimeFileSink: public Medium {
00029 public:
00030 static QuickTimeFileSink* 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 Boolean syncStreams = False,
00039 Boolean generateHintTracks = False,
00040 Boolean generateMP4Format = False);
00041
00042 typedef void (afterPlayingFunc)(void* clientData);
00043 Boolean startPlaying(afterPlayingFunc* afterFunc,
00044 void* afterClientData);
00045
00046 unsigned numActiveSubsessions() const { return fNumSubsessions; }
00047
00048 private:
00049 QuickTimeFileSink(UsageEnvironment& env, MediaSession& inputSession,
00050 char const* outputFileName, unsigned bufferSize,
00051 unsigned short movieWidth, unsigned short movieHeight,
00052 unsigned movieFPS, Boolean packetLossCompensate,
00053 Boolean syncStreams, Boolean generateHintTracks,
00054 Boolean generateMP4Format);
00055
00056 virtual ~QuickTimeFileSink();
00057
00058 Boolean continuePlaying();
00059 static void afterGettingFrame(void* clientData, unsigned frameSize,
00060 unsigned numTruncatedBytes,
00061 struct timeval presentationTime,
00062 unsigned durationInMicroseconds);
00063 static void onSourceClosure(void* clientData);
00064 void onSourceClosure1();
00065 static void onRTCPBye(void* clientData);
00066 void completeOutputFile();
00067
00068 private:
00069 friend class SubsessionIOState;
00070 MediaSession& fInputSession;
00071 FILE* fOutFid;
00072 unsigned fBufferSize;
00073 Boolean fPacketLossCompensate;
00074 Boolean fSyncStreams, fGenerateMP4Format;
00075 struct timeval fNewestSyncTime, fFirstDataTime;
00076 Boolean fAreCurrentlyBeingPlayed;
00077 afterPlayingFunc* fAfterFunc;
00078 void* fAfterClientData;
00079 unsigned fAppleCreationTime;
00080 unsigned fLargestRTPtimestampFrequency;
00081 unsigned fNumSubsessions, fNumSyncedSubsessions;
00082 struct timeval fStartTime;
00083 Boolean fHaveCompletedOutputFile;
00084
00085 private:
00087
00088 unsigned addWord(unsigned word);
00089 unsigned addHalfWord(unsigned short halfWord);
00090 unsigned addByte(unsigned char byte) {
00091 putc(byte, fOutFid);
00092 return 1;
00093 }
00094 unsigned addZeroWords(unsigned numWords);
00095 unsigned add4ByteString(char const* str);
00096 unsigned addArbitraryString(char const* str,
00097 Boolean oneByteLength = True);
00098 unsigned addAtomHeader(char const* atomName);
00099
00100 void setWord(unsigned filePosn, unsigned size);
00101
00102 unsigned movieTimeScale() const {return fLargestRTPtimestampFrequency;}
00103
00104
00105 #define _atom(name) unsigned addAtom_##name()
00106 _atom(ftyp);
00107 _atom(moov);
00108 _atom(mvhd);
00109 _atom(iods);
00110 _atom(trak);
00111 _atom(tkhd);
00112 _atom(edts);
00113 _atom(elst);
00114 _atom(tref);
00115 _atom(hint);
00116 _atom(mdia);
00117 _atom(mdhd);
00118 _atom(hdlr);
00119 _atom(minf);
00120 _atom(smhd);
00121 _atom(vmhd);
00122 _atom(gmhd);
00123 _atom(gmin);
00124 unsigned addAtom_hdlr2();
00125 _atom(dinf);
00126 _atom(dref);
00127 _atom(alis);
00128 _atom(stbl);
00129 _atom(stsd);
00130 unsigned addAtom_genericMedia();
00131 unsigned addAtom_soundMediaGeneral();
00132 _atom(ulaw);
00133 _atom(alaw);
00134 _atom(Qclp);
00135 _atom(wave);
00136 _atom(frma);
00137 _atom(Fclp);
00138 _atom(Hclp);
00139 _atom(mp4a);
00140
00141
00142 _atom(esds);
00143 _atom(srcq);
00144 _atom(h263);
00145 _atom(avc1);
00146 _atom(avcC);
00147 _atom(mp4v);
00148 _atom(rtp);
00149 _atom(tims);
00150 _atom(stts);
00151 _atom(stsc);
00152 _atom(stsz);
00153 _atom(stco);
00154 _atom(udta);
00155 _atom(name);
00156 _atom(hnti);
00157 _atom(sdp);
00158 _atom(hinf);
00159 _atom(totl);
00160 _atom(npck);
00161 _atom(tpay);
00162 _atom(trpy);
00163 _atom(nump);
00164 _atom(tpyl);
00165 _atom(dmed);
00166 _atom(dimm);
00167 _atom(drep);
00168 _atom(tmin);
00169 _atom(tmax);
00170 _atom(pmax);
00171 _atom(dmax);
00172 _atom(payt);
00173 unsigned addAtom_dummy();
00174
00175 private:
00176 unsigned short fMovieWidth, fMovieHeight;
00177 unsigned fMovieFPS;
00178 unsigned fMDATposition;
00179 unsigned fMVHD_durationPosn;
00180 unsigned fMaxTrackDurationM;
00181 class SubsessionIOState* fCurrentIOState;
00182 };
00183
00184 #endif