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 | // A sink representing a TCP output stream |
19 | // C++ header |
20 | |
21 | #ifndef _TCP_STREAM_SINK_HH |
22 | #define _TCP_STREAM_SINK_HH |
23 | |
24 | #ifndef _MEDIA_SINK_HH |
25 | #include "MediaSink.hh" |
26 | #endif |
27 | |
28 | #define TCP_STREAM_SINK_BUFFER_SIZE 10000 |
29 | |
30 | class TCPStreamSink: public MediaSink { |
31 | public: |
32 | static TCPStreamSink* createNew(UsageEnvironment& env, int socketNum); |
33 | // "socketNum" is the socket number of an existing, writable TCP socket (which should be non-blocking). |
34 | // The caller is responsible for closing this socket later (when this object no longer exists). |
35 | |
36 | protected: |
37 | TCPStreamSink(UsageEnvironment& env, int socketNum); // called only by "createNew()" |
38 | virtual ~TCPStreamSink(); |
39 | |
40 | protected: |
41 | // Redefined virtual functions: |
42 | virtual Boolean continuePlaying(); |
43 | |
44 | private: |
45 | void processBuffer(); // common routine, called from both the 'socket writable' and 'incoming data' handlers below |
46 | |
47 | static void socketWritableHandler(void* clientData, int mask); |
48 | void socketWritableHandler1(); |
49 | |
50 | static void afterGettingFrame(void* clientData, unsigned frameSize, unsigned numTruncatedBytes, |
51 | struct timeval /*presentationTime*/, unsigned /*durationInMicroseconds*/); |
52 | void afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes); |
53 | |
54 | static void ourOnSourceClosure(void* clientData); |
55 | void ourOnSourceClosure1(); |
56 | |
57 | unsigned numUnwrittenBytes() const { return fUnwrittenBytesEnd - fUnwrittenBytesStart; } |
58 | unsigned freeBufferSpace() const { return TCP_STREAM_SINK_BUFFER_SIZE - fUnwrittenBytesEnd; } |
59 | |
60 | private: |
61 | unsigned char fBuffer[TCP_STREAM_SINK_BUFFER_SIZE]; |
62 | unsigned fUnwrittenBytesStart, fUnwrittenBytesEnd; |
63 | Boolean fInputSourceIsOpen, fOutputSocketIsWritable; |
64 | int fOutputSocketNum; |
65 | }; |
66 | |
67 | #endif |
68 | |