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 | // File Sinks |
19 | // C++ header |
20 | |
21 | #ifndef _FILE_SINK_HH |
22 | #define _FILE_SINK_HH |
23 | |
24 | #ifndef _MEDIA_SINK_HH |
25 | #include "MediaSink.hh" |
26 | #endif |
27 | |
28 | class FileSink: public MediaSink { |
29 | public: |
30 | static FileSink* createNew(UsageEnvironment& env, char const* fileName, |
31 | unsigned bufferSize = 20000, |
32 | Boolean oneFilePerFrame = False); |
33 | // "bufferSize" should be at least as large as the largest expected |
34 | // input frame. |
35 | // "oneFilePerFrame" - if True - specifies that each input frame will |
36 | // be written to a separate file (using the presentation time as a |
37 | // file name suffix). The default behavior ("oneFilePerFrame" == False) |
38 | // is to output all incoming data into a single file. |
39 | |
40 | virtual void addData(unsigned char const* data, unsigned dataSize, |
41 | struct timeval presentationTime); |
42 | // (Available in case a client wants to add extra data to the output file) |
43 | |
44 | protected: |
45 | FileSink(UsageEnvironment& env, FILE* fid, unsigned bufferSize, |
46 | char const* perFrameFileNamePrefix); |
47 | // called only by createNew() |
48 | virtual ~FileSink(); |
49 | |
50 | protected: // redefined virtual functions: |
51 | virtual Boolean continuePlaying(); |
52 | |
53 | protected: |
54 | static void afterGettingFrame(void* clientData, unsigned frameSize, |
55 | unsigned numTruncatedBytes, |
56 | struct timeval presentationTime, |
57 | unsigned durationInMicroseconds); |
58 | virtual void afterGettingFrame(unsigned frameSize, |
59 | unsigned numTruncatedBytes, |
60 | struct timeval presentationTime); |
61 | |
62 | FILE* fOutFid; |
63 | unsigned char* fBuffer; |
64 | unsigned fBufferSize; |
65 | char* fPerFrameFileNamePrefix; // used if "oneFilePerFrame" is True |
66 | char* fPerFrameFileNameBuffer; // used if "oneFilePerFrame" is True |
67 | struct timeval fPrevPresentationTime; |
68 | unsigned fSamePresentationTimeCounter; |
69 | }; |
70 | |
71 | #endif |
72 | |