FileSink.hh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. // File Sinks
  17. // C++ header
  18. #ifndef _FILE_SINK_HH
  19. #define _FILE_SINK_HH
  20. #ifndef _MEDIA_SINK_HH
  21. #include "MediaSink.hh"
  22. #endif
  23. class FileSink: public MediaSink {
  24. public:
  25. static FileSink* createNew(UsageEnvironment& env, char const* fileName,
  26. unsigned bufferSize = 20000,
  27. Boolean oneFilePerFrame = False);
  28. // "bufferSize" should be at least as large as the largest expected
  29. // input frame.
  30. // "oneFilePerFrame" - if True - specifies that each input frame will
  31. // be written to a separate file (using the presentation time as a
  32. // file name suffix). The default behavior ("oneFilePerFrame" == False)
  33. // is to output all incoming data into a single file.
  34. virtual void addData(unsigned char const* data, unsigned dataSize,
  35. struct timeval presentationTime);
  36. // (Available in case a client wants to add extra data to the output file)
  37. protected:
  38. FileSink(UsageEnvironment& env, FILE* fid, unsigned bufferSize,
  39. char const* perFrameFileNamePrefix);
  40. // called only by createNew()
  41. virtual ~FileSink();
  42. protected: // redefined virtual functions:
  43. virtual Boolean continuePlaying();
  44. protected:
  45. static void afterGettingFrame(void* clientData, unsigned frameSize,
  46. unsigned numTruncatedBytes,
  47. struct timeval presentationTime,
  48. unsigned durationInMicroseconds);
  49. virtual void afterGettingFrame(unsigned frameSize,
  50. unsigned numTruncatedBytes,
  51. struct timeval presentationTime);
  52. FILE* fOutFid;
  53. unsigned char* fBuffer;
  54. unsigned fBufferSize;
  55. char* fPerFrameFileNamePrefix; // used if "oneFilePerFrame" is True
  56. char* fPerFrameFileNameBuffer; // used if "oneFilePerFrame" is True
  57. struct timeval fPrevPresentationTime;
  58. unsigned fSamePresentationTimeCounter;
  59. };
  60. #endif