1/**********
2This library is free software; you can redistribute it and/or modify it under
3the terms of the GNU Lesser General Public License as published by the
4Free Software Foundation; either version 3 of the License, or (at your
5option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6
7This library is distributed in the hope that it will be useful, but WITHOUT
8ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10more details.
11
12You should have received a copy of the GNU Lesser General Public License
13along with this library; if not, write to the Free Software Foundation, Inc.,
1451 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15**********/
16// "liveMedia"
17// Copyright (c) 1996-2020 Live Networks, Inc. All rights reserved.
18// A media sink that takes - as input - a MPEG Transport Stream, and outputs a series
19// of MPEG Transport Stream files, each representing a segment of the input stream,
20// suitable for HLS (Apple's "HTTP Live Streaming").
21// C++ header
22
23#ifndef _HLS_SEGMENTER_HH
24#define _HLS_SEGMENTER_HH
25
26#ifndef _MEDIA_SINK_HH
27#include "MediaSink.hh"
28#endif
29
30class HLSSegmenter: public MediaSink {
31public:
32 typedef void (onEndOfSegmentFunc)(void* clientData,
33 char const* segmentFileName, double segmentDuration);
34 static HLSSegmenter* createNew(UsageEnvironment& env,
35 unsigned segmentationDuration, char const* fileNamePrefix,
36 onEndOfSegmentFunc* onEndOfSegmentFunc = NULL,
37 void* onEndOfSegmentClientData = NULL);
38
39private:
40 HLSSegmenter(UsageEnvironment& env, unsigned segmentationDuration, char const* fileNamePrefix,
41 onEndOfSegmentFunc* onEndOfSegmentFunc, void* onEndOfSegmentClientData);
42 // called only by createNew()
43 virtual ~HLSSegmenter();
44
45 static void ourEndOfSegmentHandler(void* clientData, double segmentDuration);
46 void ourEndOfSegmentHandler(double segmentDuration);
47
48 Boolean openNextOutputSegment();
49
50 static void afterGettingFrame(void* clientData, unsigned frameSize,
51 unsigned numTruncatedBytes,
52 struct timeval presentationTime,
53 unsigned durationInMicroseconds);
54 virtual void afterGettingFrame(unsigned frameSize,
55 unsigned numTruncatedBytes);
56
57 static void ourOnSourceClosure(void* clientData);
58 void ourOnSourceClosure();
59
60private: // redefined virtual functions:
61 virtual Boolean sourceIsCompatibleWithUs(MediaSource& source);
62 virtual Boolean continuePlaying();
63
64private:
65 unsigned fSegmentationDuration;
66 char const* fFileNamePrefix;
67 onEndOfSegmentFunc* fOnEndOfSegmentFunc;
68 void* fOnEndOfSegmentClientData;
69 Boolean fHaveConfiguredUpstreamSource;
70 unsigned fCurrentSegmentCounter;
71 char* fOutputSegmentFileName;
72 FILE* fOutFid;
73 unsigned char* fOutputFileBuffer;
74};
75
76#endif
77