OggFileSink.hh 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. // 'Ogg' File Sink (recording a single media track only)
  17. // C++ header
  18. #ifndef _OGG_FILE_SINK_HH
  19. #define _OGG_FILE_SINK_HH
  20. #ifndef _FILE_SINK_HH
  21. #include "FileSink.hh"
  22. #endif
  23. class OggFileSink: public FileSink {
  24. public:
  25. static OggFileSink* createNew(UsageEnvironment& env, char const* fileName,
  26. unsigned samplingFrequency = 0, // used for granule_position
  27. char const* configStr = NULL,
  28. // "configStr" is an optional 'SDP format' string (Base64-encoded)
  29. // representing 'packed configuration headers' ("identification", "comment", "setup")
  30. // to prepend to the output. (For 'Vorbis" audio and 'Theora' video.)
  31. unsigned bufferSize = 100000,
  32. Boolean oneFilePerFrame = False);
  33. // See "FileSink.hh" for a description of these parameters.
  34. protected:
  35. OggFileSink(UsageEnvironment& env, FILE* fid, unsigned samplingFrequency, char const* configStr,
  36. unsigned bufferSize, char const* perFrameFileNamePrefix);
  37. // called only by createNew()
  38. virtual ~OggFileSink();
  39. protected: // redefined virtual functions:
  40. virtual Boolean continuePlaying();
  41. virtual void addData(unsigned char const* data, unsigned dataSize,
  42. struct timeval presentationTime);
  43. virtual void afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes,
  44. struct timeval presentationTime);
  45. private:
  46. static void ourOnSourceClosure(void* clientData);
  47. void ourOnSourceClosure();
  48. private:
  49. unsigned fSamplingFrequency;
  50. char const* fConfigStr;
  51. Boolean fHaveWrittenFirstFrame, fHaveSeenEOF;
  52. struct timeval fFirstPresentationTime;
  53. int64_t fGranulePosition;
  54. int64_t fGranulePositionAdjustment; // used to ensure that "fGranulePosition" stays monotonic
  55. u_int32_t fPageSequenceNumber;
  56. u_int8_t fPageHeaderBytes[27];
  57. // the header of each Ogg page, through the "number_page_segments" byte
  58. // Special fields used for Theora video:
  59. Boolean fIsTheora;
  60. u_int64_t fGranuleIncrementPerFrame; // == 1 << KFGSHIFT
  61. // Because the last Ogg page before EOF needs to have a special 'eos' bit set in the header,
  62. // we need to defer the writing of each incoming frame. To do this, we maintain a 2nd buffer:
  63. unsigned char* fAltBuffer;
  64. unsigned fAltFrameSize, fAltNumTruncatedBytes;
  65. struct timeval fAltPresentationTime;
  66. };
  67. #endif