live
OggFileSink.hh
Go to the documentation of this file.
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 
7 This library is distributed in the hope that it will be useful, but WITHOUT
8 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10 more details.
11 
12 You should have received a copy of the GNU Lesser General Public License
13 along with this library; if not, write to the Free Software Foundation, Inc.,
14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 **********/
16 // "liveMedia"
17 // Copyright (c) 1996-2021 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 
28 class OggFileSink: public FileSink {
29 public:
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 
40 protected:
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 
46 protected: // redefined virtual functions:
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 
53 private:
54  static void ourOnSourceClosure(void* clientData);
56 
57 private:
59  char const* fConfigStr;
61  struct timeval fFirstPresentationTime;
63  int64_t fGranulePositionAdjustment; // used to ensure that "fGranulePosition" stays monotonic
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:
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;
76  struct timeval fAltPresentationTime;
77 };
78 
79 #endif
const Boolean False
Definition: Boolean.hh:28
unsigned char Boolean
Definition: Boolean.hh:25
#define NULL
Boolean fHaveSeenEOF
Definition: OggFileSink.hh:60
int64_t fGranulePosition
Definition: OggFileSink.hh:62
struct timeval fFirstPresentationTime
Definition: OggFileSink.hh:61
unsigned char * fAltBuffer
Definition: OggFileSink.hh:74
static OggFileSink * createNew(UsageEnvironment &env, char const *fileName, unsigned samplingFrequency=0, char const *configStr=NULL, unsigned bufferSize=100000, Boolean oneFilePerFrame=False)
u_int32_t fPageSequenceNumber
Definition: OggFileSink.hh:64
virtual ~OggFileSink()
unsigned fAltFrameSize
Definition: OggFileSink.hh:75
static void ourOnSourceClosure(void *clientData)
struct timeval fAltPresentationTime
Definition: OggFileSink.hh:76
Boolean fHaveWrittenFirstFrame
Definition: OggFileSink.hh:60
Boolean fIsTheora
Definition: OggFileSink.hh:69
void ourOnSourceClosure()
virtual void afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime)
int64_t fGranulePositionAdjustment
Definition: OggFileSink.hh:63
OggFileSink(UsageEnvironment &env, FILE *fid, unsigned samplingFrequency, char const *configStr, unsigned bufferSize, char const *perFrameFileNamePrefix)
virtual void addData(unsigned char const *data, unsigned dataSize, struct timeval presentationTime)
unsigned fAltNumTruncatedBytes
Definition: OggFileSink.hh:75
char const * fConfigStr
Definition: OggFileSink.hh:59
u_int64_t fGranuleIncrementPerFrame
Definition: OggFileSink.hh:70
u_int8_t fPageHeaderBytes[27]
Definition: OggFileSink.hh:65
unsigned fSamplingFrequency
Definition: OggFileSink.hh:58
virtual Boolean continuePlaying()