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 addWord64(u_int64_t word);
00089 unsigned addWord(unsigned word);
00090 unsigned addHalfWord(unsigned short halfWord);
00091 unsigned addByte(unsigned char byte) {
00092 putc(byte, fOutFid);
00093 return 1;
00094 }
00095 unsigned addZeroWords(unsigned numWords);
00096 unsigned add4ByteString(char const* str);
00097 unsigned addArbitraryString(char const* str,
00098 Boolean oneByteLength = True);
00099 unsigned addAtomHeader(char const* atomName);
00100 unsigned addAtomHeader64(char const* atomName);
00101
00102 void setWord(int64_t filePosn, unsigned size);
00103 void setWord64(int64_t filePosn, u_int64_t size);
00104
00105 unsigned movieTimeScale() const {return fLargestRTPtimestampFrequency;}
00106
00107
00108 #define _atom(name) unsigned addAtom_##name()
00109 _atom(ftyp);
00110 _atom(moov);
00111 _atom(mvhd);
00112 _atom(iods);
00113 _atom(trak);
00114 _atom(tkhd);
00115 _atom(edts);
00116 _atom(elst);
00117 _atom(tref);
00118 _atom(hint);
00119 _atom(mdia);
00120 _atom(mdhd);
00121 _atom(hdlr);
00122 _atom(minf);
00123 _atom(smhd);
00124 _atom(vmhd);
00125 _atom(gmhd);
00126 _atom(gmin);
00127 unsigned addAtom_hdlr2();
00128 _atom(dinf);
00129 _atom(dref);
00130 _atom(alis);
00131 _atom(stbl);
00132 _atom(stsd);
00133 unsigned addAtom_genericMedia();
00134 unsigned addAtom_soundMediaGeneral();
00135 _atom(ulaw);
00136 _atom(alaw);
00137 _atom(Qclp);
00138 _atom(wave);
00139 _atom(frma);
00140 _atom(Fclp);
00141 _atom(Hclp);
00142 _atom(mp4a);
00143
00144
00145 _atom(esds);
00146 _atom(srcq);
00147 _atom(h263);
00148 _atom(avc1);
00149 _atom(avcC);
00150 _atom(mp4v);
00151 _atom(rtp);
00152 _atom(tims);
00153 _atom(stts);
00154 _atom(stss);
00155 _atom(stsc);
00156 _atom(stsz);
00157 _atom(co64);
00158 _atom(udta);
00159 _atom(name);
00160 _atom(hnti);
00161 _atom(sdp);
00162 _atom(hinf);
00163 _atom(totl);
00164 _atom(npck);
00165 _atom(tpay);
00166 _atom(trpy);
00167 _atom(nump);
00168 _atom(tpyl);
00169 _atom(dmed);
00170 _atom(dimm);
00171 _atom(drep);
00172 _atom(tmin);
00173 _atom(tmax);
00174 _atom(pmax);
00175 _atom(dmax);
00176 _atom(payt);
00177 unsigned addAtom_dummy();
00178
00179 private:
00180 unsigned short fMovieWidth, fMovieHeight;
00181 unsigned fMovieFPS;
00182 int64_t fMDATposition;
00183 int64_t fMVHD_durationPosn;
00184 unsigned fMaxTrackDurationM;
00185 class SubsessionIOState* fCurrentIOState;
00186 };
00187
00188 #endif