HLSSegmenter.hh 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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-2020 Live Networks, Inc. All rights reserved.
  16. // A media sink that takes - as input - a MPEG Transport Stream, and outputs a series
  17. // of MPEG Transport Stream files, each representing a segment of the input stream,
  18. // suitable for HLS (Apple's "HTTP Live Streaming").
  19. // C++ header
  20. #ifndef _HLS_SEGMENTER_HH
  21. #define _HLS_SEGMENTER_HH
  22. #ifndef _MEDIA_SINK_HH
  23. #include "MediaSink.hh"
  24. #endif
  25. class HLSSegmenter: public MediaSink {
  26. public:
  27. typedef void (onEndOfSegmentFunc)(void* clientData,
  28. char const* segmentFileName, double segmentDuration);
  29. static HLSSegmenter* createNew(UsageEnvironment& env,
  30. unsigned segmentationDuration, char const* fileNamePrefix,
  31. onEndOfSegmentFunc* onEndOfSegmentFunc = NULL,
  32. void* onEndOfSegmentClientData = NULL);
  33. private:
  34. HLSSegmenter(UsageEnvironment& env, unsigned segmentationDuration, char const* fileNamePrefix,
  35. onEndOfSegmentFunc* onEndOfSegmentFunc, void* onEndOfSegmentClientData);
  36. // called only by createNew()
  37. virtual ~HLSSegmenter();
  38. static void ourEndOfSegmentHandler(void* clientData, double segmentDuration);
  39. void ourEndOfSegmentHandler(double segmentDuration);
  40. Boolean openNextOutputSegment();
  41. static void afterGettingFrame(void* clientData, unsigned frameSize,
  42. unsigned numTruncatedBytes,
  43. struct timeval presentationTime,
  44. unsigned durationInMicroseconds);
  45. virtual void afterGettingFrame(unsigned frameSize,
  46. unsigned numTruncatedBytes);
  47. static void ourOnSourceClosure(void* clientData);
  48. void ourOnSourceClosure();
  49. private: // redefined virtual functions:
  50. virtual Boolean sourceIsCompatibleWithUs(MediaSource& source);
  51. virtual Boolean continuePlaying();
  52. private:
  53. unsigned fSegmentationDuration;
  54. char const* fFileNamePrefix;
  55. onEndOfSegmentFunc* fOnEndOfSegmentFunc;
  56. void* fOnEndOfSegmentClientData;
  57. Boolean fHaveConfiguredUpstreamSource;
  58. unsigned fCurrentSegmentCounter;
  59. char* fOutputSegmentFileName;
  60. FILE* fOutFid;
  61. unsigned char* fOutputFileBuffer;
  62. };
  63. #endif