AVIFileSink.hh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**********
  2. This library is free software; you can redistribute it and/or modify it under
  3. the terms of the GNU Lesser General Public License as published by the
  4. Free Software Foundation; either version 3 of the License, or (at your
  5. option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
  6. This library is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  9. more details.
  10. You should have received a copy of the GNU Lesser General Public License
  11. along with this library; if not, write to the Free Software Foundation, Inc.,
  12. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  13. **********/
  14. // "liveMedia"
  15. // Copyright (c) 1996-2019 Live Networks, Inc. All rights reserved.
  16. // A sink that generates an AVI file from a composite media session
  17. // C++ header
  18. #ifndef _AVI_FILE_SINK_HH
  19. #define _AVI_FILE_SINK_HH
  20. #ifndef _MEDIA_SESSION_HH
  21. #include "MediaSession.hh"
  22. #endif
  23. class AVIFileSink: public Medium {
  24. public:
  25. static AVIFileSink* createNew(UsageEnvironment& env,
  26. MediaSession& inputSession,
  27. char const* outputFileName,
  28. unsigned bufferSize = 20000,
  29. unsigned short movieWidth = 240,
  30. unsigned short movieHeight = 180,
  31. unsigned movieFPS = 15,
  32. Boolean packetLossCompensate = False);
  33. typedef void (afterPlayingFunc)(void* clientData);
  34. Boolean startPlaying(afterPlayingFunc* afterFunc,
  35. void* afterClientData);
  36. unsigned numActiveSubsessions() const { return fNumSubsessions; }
  37. private:
  38. AVIFileSink(UsageEnvironment& env, MediaSession& inputSession,
  39. char const* outputFileName, unsigned bufferSize,
  40. unsigned short movieWidth, unsigned short movieHeight,
  41. unsigned movieFPS, Boolean packetLossCompensate);
  42. // called only by createNew()
  43. virtual ~AVIFileSink();
  44. Boolean continuePlaying();
  45. static void afterGettingFrame(void* clientData, unsigned frameSize,
  46. unsigned numTruncatedBytes,
  47. struct timeval presentationTime,
  48. unsigned durationInMicroseconds);
  49. static void onSourceClosure(void* clientData);
  50. void onSourceClosure1();
  51. static void onRTCPBye(void* clientData);
  52. void addIndexRecord(class AVIIndexRecord* newIndexRecord);
  53. void completeOutputFile();
  54. private:
  55. friend class AVISubsessionIOState;
  56. MediaSession& fInputSession;
  57. FILE* fOutFid;
  58. class AVIIndexRecord *fIndexRecordsHead, *fIndexRecordsTail;
  59. unsigned fNumIndexRecords;
  60. unsigned fBufferSize;
  61. Boolean fPacketLossCompensate;
  62. Boolean fAreCurrentlyBeingPlayed;
  63. afterPlayingFunc* fAfterFunc;
  64. void* fAfterClientData;
  65. unsigned fNumSubsessions;
  66. unsigned fNumBytesWritten;
  67. struct timeval fStartTime;
  68. Boolean fHaveCompletedOutputFile;
  69. private:
  70. ///// Definitions specific to the AVI file format:
  71. unsigned addWord(unsigned word); // outputs "word" in little-endian order
  72. unsigned addHalfWord(unsigned short halfWord);
  73. unsigned addByte(unsigned char byte) {
  74. putc(byte, fOutFid);
  75. return 1;
  76. }
  77. unsigned addZeroWords(unsigned numWords);
  78. unsigned add4ByteString(char const* str);
  79. void setWord(unsigned filePosn, unsigned size);
  80. // Define member functions for outputting various types of file header:
  81. #define _header(name) unsigned addFileHeader_##name()
  82. _header(AVI);
  83. _header(hdrl);
  84. _header(avih);
  85. _header(strl);
  86. _header(strh);
  87. _header(strf);
  88. _header(JUNK);
  89. // _header(JUNK);
  90. _header(movi);
  91. private:
  92. unsigned short fMovieWidth, fMovieHeight;
  93. unsigned fMovieFPS;
  94. unsigned fRIFFSizePosition, fRIFFSizeValue;
  95. unsigned fAVIHMaxBytesPerSecondPosition;
  96. unsigned fAVIHFrameCountPosition;
  97. unsigned fMoviSizePosition, fMoviSizeValue;
  98. class AVISubsessionIOState* fCurrentIOState;
  99. unsigned fJunkNumber;
  100. };
  101. #endif