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-2013 Live Networks, Inc. All rights reserved. 00018 // An class that can be used to create (possibly multiple) 'replicas' of an incoming stream. 00019 // C++ header 00020 00021 #ifndef _STREAM_REPLICATOR_HH 00022 #define _STREAM_REPLICATOR_HH 00023 00024 #ifndef _FRAMED_SOURCE_HH 00025 #include "FramedSource.hh" 00026 #endif 00027 00028 class StreamReplica; // forward 00029 00030 class StreamReplicator: public Medium { 00031 public: 00032 static StreamReplicator* createNew(UsageEnvironment& env, FramedSource* inputSource, Boolean deleteWhenLastReplicaDies = True); 00033 // If "deleteWhenLastReplicaDies" is True (the default), then the "StreamReplicator" object is deleted when (and only when) 00034 // all replicas have been deleted. (In this case, you must *not* call "Medium::close()" on the "StreamReplicator" object, 00035 // unless you never created any replicas from it to begin with.) 00036 // If "deleteWhenLastReplicaDies" is False, then the "StreamReplicator" object remains in existence, even when all replicas 00037 // have been deleted. (This allows you to create new replicas later, if you wish.) In this case, you delete the 00038 // "StreamReplicator" object by calling "Medium::close()" on it - but you must do so only when "numReplicas()" returns 0. 00039 00040 FramedSource* createStreamReplica(); 00041 00042 unsigned numReplicas() const { return fNumReplicas; } 00043 00044 FramedSource* inputSource() const { return fInputSource; } 00045 00046 // Call before destruction if you want to prevent the destructor from closing the input source 00047 void detachInputSource() { fInputSource = NULL; } 00048 00049 protected: 00050 StreamReplicator(UsageEnvironment& env, FramedSource* inputSource, Boolean deleteWhenLastReplicaDies); 00051 // called only by "createNew()" 00052 virtual ~StreamReplicator(); 00053 00054 private: 00055 // Routines called by replicas to implement frame delivery, and the stopping/restarting/deletion of replicas: 00056 friend class StreamReplica; 00057 void getNextFrame(StreamReplica* replica); 00058 void deactivateStreamReplica(StreamReplica* replica); 00059 void removeStreamReplica(StreamReplica* replica); 00060 00061 private: 00062 static void afterGettingFrame(void* clientData, unsigned frameSize, 00063 unsigned numTruncatedBytes, 00064 struct timeval presentationTime, 00065 unsigned durationInMicroseconds); 00066 void afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes, 00067 struct timeval presentationTime, unsigned durationInMicroseconds); 00068 00069 static void onSourceClosure(void* clientData); 00070 void onSourceClosure(); 00071 00072 void deliverReceivedFrame(); 00073 00074 private: 00075 FramedSource* fInputSource; 00076 Boolean fDeleteWhenLastReplicaDies, fInputSourceHasClosed; 00077 unsigned fNumReplicas, fNumActiveReplicas, fNumDeliveriesMadeSoFar; 00078 int fFrameIndex; // 0 or 1; used to figure out if a replica is requesting the current frame, or the next frame 00079 00080 StreamReplica* fMasterReplica; // the first replica that requests each frame. We use its buffer when copying to the others. 00081 StreamReplica* fReplicasAwaitingCurrentFrame; // other than the 'master' replica 00082 StreamReplica* fReplicasAwaitingNextFrame; // replicas that have already received the current frame, and have asked for the next 00083 }; 00084 #endif
1.5.2