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