Go to the documentation of this file.
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 <>.)
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.
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-2021 Live Networks, Inc. All rights reserved.
18 // An class that can be used to create (possibly multiple) 'replicas' of an incoming stream.
19 // C++ header
24 #ifndef _FRAMED_SOURCE_HH
25 #include "FramedSource.hh"
26 #endif
28 class StreamReplica; // forward
30 class StreamReplicator: public Medium {
31 public:
32  static StreamReplicator* createNew(UsageEnvironment& env, FramedSource* inputSource, Boolean deleteWhenLastReplicaDies = True);
33  // If "deleteWhenLastReplicaDies" is True (the default), then the "StreamReplicator" object is deleted when (and only when)
34  // all replicas have been deleted. (In this case, you must *not* call "Medium::close()" on the "StreamReplicator" object,
35  // unless you never created any replicas from it to begin with.)
36  // If "deleteWhenLastReplicaDies" is False, then the "StreamReplicator" object remains in existence, even when all replicas
37  // have been deleted. (This allows you to create new replicas later, if you wish.) In this case, you delete the
38  // "StreamReplicator" object by calling "Medium::close()" on it - but you must do so only when "numReplicas()" returns 0.
42  unsigned numReplicas() const { return fNumReplicas; }
44  FramedSource* inputSource() const { return fInputSource; }
46  // Call before destruction if you want to prevent the destructor from closing the input source
49 protected:
51  // called only by "createNew()"
52  virtual ~StreamReplicator();
54 private:
55  // Routines called by replicas to implement frame delivery, and the stopping/restarting/deletion of replicas:
56  friend class StreamReplica;
57  void getNextFrame(StreamReplica* replica);
61 private:
62  static void afterGettingFrame(void* clientData, unsigned frameSize,
63  unsigned numTruncatedBytes,
64  struct timeval presentationTime,
65  unsigned durationInMicroseconds);
66  void afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes,
67  struct timeval presentationTime, unsigned durationInMicroseconds);
69  static void onSourceClosure(void* clientData);
74 private:
78  int fFrameIndex; // 0 or 1; used to figure out if a replica is requesting the current frame, or the next frame
80  StreamReplica* fPrimaryReplica; // the first replica that requests each frame. We use its buffer when copying to the others.
81  StreamReplica* fReplicasAwaitingCurrentFrame; // other than the 'primary' replica
82  StreamReplica* fReplicasAwaitingNextFrame; // replicas that have already received the current frame, and have asked for the next
83 };
84 #endif
const Boolean True
Definition: Boolean.hh:31
unsigned char Boolean
Definition: Boolean.hh:25
#define NULL
Definition: Media.hh:50
unsigned fNumDeliveriesMadeSoFar
StreamReplica * fPrimaryReplica
Boolean fInputSourceHasClosed
StreamReplica * fReplicasAwaitingNextFrame
FramedSource * createStreamReplica()
StreamReplica * fReplicasAwaitingCurrentFrame
StreamReplicator(UsageEnvironment &env, FramedSource *inputSource, Boolean deleteWhenLastReplicaDies)
friend class StreamReplica
static void afterGettingFrame(void *clientData, unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds)
FramedSource * fInputSource
void onSourceClosure()
FramedSource * inputSource() const
void afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds)
Boolean fDeleteWhenLastReplicaDies
void removeStreamReplica(StreamReplica *replica)
unsigned fNumActiveReplicas
unsigned numReplicas() const
virtual ~StreamReplicator()
void deliverReceivedFrame()
static void onSourceClosure(void *clientData)
static StreamReplicator * createNew(UsageEnvironment &env, FramedSource *inputSource, Boolean deleteWhenLastReplicaDies=True)
void deactivateStreamReplica(StreamReplica *replica)
void getNextFrame(StreamReplica *replica)