liveMedia/include/TCPStreamSink.hh

Go to the documentation of this file.
00001 /**********
00002 This library is free software; you can redistribute it and/or modify it under
00003 the terms of the GNU Lesser General Public License as published by the
00004 Free Software Foundation; either version 2.1 of the License, or (at your
00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
00006 
00007 This library is distributed in the hope that it will be useful, but WITHOUT
00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
00010 more details.
00011 
00012 You should have received a copy of the GNU Lesser General Public License
00013 along with this library; if not, write to the Free Software Foundation, Inc.,
00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // "liveMedia"
00017 // Copyright (c) 1996-2012 Live Networks, Inc.  All rights reserved.
00018 // A sink representing a TCP output stream
00019 // C++ header
00020 
00021 #ifndef _TCP_STREAM_SINK_HH
00022 #define _TCP_STREAM_SINK_HH
00023 
00024 #ifndef _MEDIA_SINK_HH
00025 #include "MediaSink.hh"
00026 #endif
00027 
00028 #define TCP_STREAM_SINK_BUFFER_SIZE 10000
00029 
00030 class TCPStreamSink: public MediaSink {
00031 public:
00032   static TCPStreamSink* createNew(UsageEnvironment& env, int socketNum);
00033   // "socketNum" is the socket number of an existing, writable TCP socket (which should be non-blocking).
00034   // The caller is responsible for closing this socket later (when this object no longer exists).
00035 
00036 protected:
00037   TCPStreamSink(UsageEnvironment& env, int socketNum); // called only by "createNew()"
00038   virtual ~TCPStreamSink();
00039 
00040 protected:
00041   // Redefined virtual functions:
00042   virtual Boolean continuePlaying();
00043 
00044 private:
00045   void processBuffer(); // common routine, called from both the 'socket writable' and 'incoming data' handlers below
00046 
00047   static void socketWritableHandler(void* clientData, int mask);
00048   void socketWritableHandler1();
00049 
00050   static void afterGettingFrame(void* clientData, unsigned frameSize, unsigned numTruncatedBytes,
00051                                 struct timeval /*presentationTime*/, unsigned /*durationInMicroseconds*/);
00052   void afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes);
00053 
00054   static void ourOnSourceClosure(void* clientData);
00055   void ourOnSourceClosure1();
00056 
00057   unsigned numUnwrittenBytes() const { return fUnwrittenBytesEnd - fUnwrittenBytesStart; }
00058   unsigned freeBufferSpace() const { return TCP_STREAM_SINK_BUFFER_SIZE - fUnwrittenBytesEnd; }
00059 
00060 private:
00061   unsigned char fBuffer[TCP_STREAM_SINK_BUFFER_SIZE];
00062   unsigned fUnwrittenBytesStart, fUnwrittenBytesEnd;
00063   Boolean fInputSourceIsOpen, fOutputSocketIsWritable;
00064   int fOutputSocketNum;
00065 };
00066 
00067 #endif

Generated on Thu May 17 07:11:46 2012 for live by  doxygen 1.5.2