live
StreamReplicator.hh
Go to the documentation of this file.
1/**********
2This library is free software; you can redistribute it and/or modify it under
3the terms of the GNU Lesser General Public License as published by the
4Free Software Foundation; either version 3 of the License, or (at your
5option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6
7This library is distributed in the hope that it will be useful, but WITHOUT
8ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10more details.
11
12You should have received a copy of the GNU Lesser General Public License
13along with this library; if not, write to the Free Software Foundation, Inc.,
1451 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15**********/
16// "liveMedia"
17// Copyright (c) 1996-2024 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
20
21#ifndef _STREAM_REPLICATOR_HH
22#define _STREAM_REPLICATOR_HH
23
24#ifndef _FRAMED_SOURCE_HH
25#include "FramedSource.hh"
26#endif
27
28class StreamReplica; // forward
29
30class StreamReplicator: public Medium {
31public:
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.
39
41
42 unsigned numReplicas() const { return fNumReplicas; }
43
45
46 // Call before destruction if you want to prevent the destructor from closing the input source
48
49protected:
51 // called only by "createNew()"
53
54private:
55 // Routines called by replicas to implement frame delivery, and the stopping/restarting/deletion of replicas:
56 friend class StreamReplica;
60
61private:
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);
68
69 static void onSourceClosure(void* clientData);
71
73
74private:
78 int fFrameIndex; // 0 or 1; used to figure out if a replica is requesting the current frame, or the next frame
79
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
StreamReplica * fReplicasAwaitingCurrentFrame
StreamReplicator(UsageEnvironment &env, FramedSource *inputSource, Boolean deleteWhenLastReplicaDies)
friend class StreamReplica
FramedSource * inputSource() const
static void afterGettingFrame(void *clientData, unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds)
FramedSource * fInputSource
void onSourceClosure()
void afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds)
Boolean fDeleteWhenLastReplicaDies
void removeStreamReplica(StreamReplica *replica)
unsigned fNumActiveReplicas
unsigned numReplicas() const
virtual ~StreamReplicator()
static StreamReplicator * createNew(UsageEnvironment &env, FramedSource *inputSource, Boolean deleteWhenLastReplicaDies=True)
FramedSource * createStreamReplica()
void deliverReceivedFrame()
static void onSourceClosure(void *clientData)
void deactivateStreamReplica(StreamReplica *replica)
void getNextFrame(StreamReplica *replica)