live
MediaSink.hh
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 <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-2021 Live Networks, Inc. All rights reserved.
18 // Media Sinks
19 // C++ header
20 
21 #ifndef _MEDIA_SINK_HH
22 #define _MEDIA_SINK_HH
23 
24 #ifndef _FRAMED_SOURCE_HH
25 #include "FramedSource.hh"
26 #endif
27 
28 class MediaSink: public Medium {
29 public:
30  static Boolean lookupByName(UsageEnvironment& env, char const* sinkName,
31  MediaSink*& resultSink);
32 
33  typedef void (afterPlayingFunc)(void* clientData);
35  afterPlayingFunc* afterFunc,
36  void* afterClientData);
37  virtual void stopPlaying();
38 
39  // Test for specific types of sink:
40  virtual Boolean isRTPSink() const;
41 
42  FramedSource* source() const {return fSource;}
43 
44 protected:
45  MediaSink(UsageEnvironment& env); // abstract base class
46  virtual ~MediaSink();
47 
49  // called by startPlaying()
50  virtual Boolean continuePlaying() = 0;
51  // called by startPlaying()
52 
53  static void onSourceClosure(void* clientData); // can be used in "getNextFrame()" calls
55  // should be called (on ourselves) by continuePlaying() when it
56  // discovers that the source we're playing from has closed.
57 
59 
60 private:
61  // redefined virtual functions:
62  virtual Boolean isSink() const;
63 
64 private:
65  // The following fields are used when we're being played:
68 };
69 
70 // A data structure that a sink may use for an output packet:
72 public:
73  OutPacketBuffer(unsigned preferredPacketSize, unsigned maxPacketSize,
74  unsigned maxBufferSize = 0);
75  // if "maxBufferSize" is >0, use it - instead of "maxSize" to compute the buffer size
77 
78  static unsigned maxSize;
79  static void increaseMaxSizeTo(unsigned newMaxSize) { if (newMaxSize > OutPacketBuffer::maxSize) OutPacketBuffer::maxSize = newMaxSize; }
80 
81  unsigned char* curPtr() const {return &fBuf[fPacketStart + fCurOffset];}
82  unsigned totalBytesAvailable() const {
83  return fLimit - (fPacketStart + fCurOffset);
84  }
85  unsigned totalBufferSize() const { return fLimit; }
86  unsigned char* packet() const {return &fBuf[fPacketStart];}
87  unsigned curPacketSize() const {return fCurOffset;}
88 
89  void increment(unsigned numBytes) {fCurOffset += numBytes;}
90 
91  void enqueue(unsigned char const* from, unsigned numBytes);
92  void enqueueWord(u_int32_t word);
93  void insert(unsigned char const* from, unsigned numBytes, unsigned toPosition);
94  void insertWord(u_int32_t word, unsigned toPosition);
95  void extract(unsigned char* to, unsigned numBytes, unsigned fromPosition);
96  u_int32_t extractWord(unsigned fromPosition);
97 
98  void skipBytes(unsigned numBytes);
99 
101  Boolean wouldOverflow(unsigned numBytes) const {
102  return (fCurOffset+numBytes) > fMax;
103  }
104  unsigned numOverflowBytes(unsigned numBytes) const {
105  return (fCurOffset+numBytes) - fMax;
106  }
107  Boolean isTooBigForAPacket(unsigned numBytes) const {
108  return numBytes > fMax;
109  }
110 
111  void setOverflowData(unsigned overflowDataOffset,
112  unsigned overflowDataSize,
113  struct timeval const& presentationTime,
114  unsigned durationInMicroseconds);
115  unsigned overflowDataSize() const {return fOverflowDataSize;}
116  struct timeval overflowPresentationTime() const {return fOverflowPresentationTime;}
120 
121  void adjustPacketStart(unsigned numBytes);
123  void resetOffset() { fCurOffset = 0; }
125 
126 private:
128  unsigned char* fBuf;
129 
131  struct timeval fOverflowPresentationTime;
133 };
134 
135 #endif
unsigned char Boolean
Definition: Boolean.hh:25
FramedSource * fSource
Definition: MediaSink.hh:58
virtual ~MediaSink()
static Boolean lookupByName(UsageEnvironment &env, char const *sinkName, MediaSink *&resultSink)
virtual Boolean isRTPSink() const
MediaSink(UsageEnvironment &env)
virtual Boolean continuePlaying()=0
void() afterPlayingFunc(void *clientData)
Definition: MediaSink.hh:33
FramedSource * source() const
Definition: MediaSink.hh:42
static void onSourceClosure(void *clientData)
virtual Boolean isSink() const
Boolean startPlaying(MediaSource &source, afterPlayingFunc *afterFunc, void *afterClientData)
afterPlayingFunc * fAfterFunc
Definition: MediaSink.hh:66
void onSourceClosure()
virtual Boolean sourceIsCompatibleWithUs(MediaSource &source)
void * fAfterClientData
Definition: MediaSink.hh:67
virtual void stopPlaying()
Definition: Media.hh:50
static void increaseMaxSizeTo(unsigned newMaxSize)
Definition: MediaSink.hh:79
struct timeval fOverflowPresentationTime
Definition: MediaSink.hh:131
Boolean wouldOverflow(unsigned numBytes) const
Definition: MediaSink.hh:101
unsigned fPacketStart
Definition: MediaSink.hh:127
Boolean isTooBigForAPacket(unsigned numBytes) const
Definition: MediaSink.hh:107
Boolean haveOverflowData() const
Definition: MediaSink.hh:118
void extract(unsigned char *to, unsigned numBytes, unsigned fromPosition)
static unsigned maxSize
Definition: MediaSink.hh:78
unsigned fOverflowDurationInMicroseconds
Definition: MediaSink.hh:132
unsigned fLimit
Definition: MediaSink.hh:127
unsigned fOverflowDataSize
Definition: MediaSink.hh:130
unsigned numOverflowBytes(unsigned numBytes) const
Definition: MediaSink.hh:104
void resetPacketStart()
unsigned fMax
Definition: MediaSink.hh:127
unsigned fOverflowDataOffset
Definition: MediaSink.hh:130
unsigned fPreferred
Definition: MediaSink.hh:127
unsigned overflowDataSize() const
Definition: MediaSink.hh:115
struct timeval overflowPresentationTime() const
Definition: MediaSink.hh:116
unsigned totalBytesAvailable() const
Definition: MediaSink.hh:82
Boolean isPreferredSize() const
Definition: MediaSink.hh:100
void resetOffset()
Definition: MediaSink.hh:123
unsigned char * curPtr() const
Definition: MediaSink.hh:81
void skipBytes(unsigned numBytes)
void setOverflowData(unsigned overflowDataOffset, unsigned overflowDataSize, struct timeval const &presentationTime, unsigned durationInMicroseconds)
unsigned fCurOffset
Definition: MediaSink.hh:127
unsigned overflowDurationInMicroseconds() const
Definition: MediaSink.hh:117
void increment(unsigned numBytes)
Definition: MediaSink.hh:89
void enqueue(unsigned char const *from, unsigned numBytes)
void insertWord(u_int32_t word, unsigned toPosition)
void enqueueWord(u_int32_t word)
unsigned curPacketSize() const
Definition: MediaSink.hh:87
unsigned char * fBuf
Definition: MediaSink.hh:128
OutPacketBuffer(unsigned preferredPacketSize, unsigned maxPacketSize, unsigned maxBufferSize=0)
unsigned totalBufferSize() const
Definition: MediaSink.hh:85
void useOverflowData()
void resetOverflowData()
Definition: MediaSink.hh:124
unsigned char * packet() const
Definition: MediaSink.hh:86
void adjustPacketStart(unsigned numBytes)
u_int32_t extractWord(unsigned fromPosition)
void insert(unsigned char const *from, unsigned numBytes, unsigned toPosition)