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-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 | |
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: |
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 | |
53 | private: |
54 | static void ourOnSourceClosure(void* clientData); |
55 | void ourOnSourceClosure(); |
56 | |
57 | private: |
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 [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 | |