live
ServerMediaSession.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 // A data structure that represents a session that consists of
19 // potentially multiple (audio and/or video) sub-sessions
20 // (This data structure is used for media *streamers* - i.e., servers.
21 // For media receivers, use "MediaSession" instead.)
22 // C++ header
23 
24 #ifndef _SERVER_MEDIA_SESSION_HH
25 #define _SERVER_MEDIA_SESSION_HH
26 
27 #ifndef _RTCP_HH
28 #include "RTCP.hh"
29 #endif
30 
31 class ServerMediaSubsession; // forward
32 
33 class ServerMediaSession: public Medium {
34 public:
36  char const* streamName = NULL,
37  char const* info = NULL,
38  char const* description = NULL,
39  Boolean isSSM = False,
40  char const* miscSDPLines = NULL);
41 
43  char const* mediumName,
44  ServerMediaSession*& resultSession);
45 
46  char* generateSDPDescription(int addressFamily); // based on the entire session
47  // Note: The caller is responsible for freeing the returned string
48 
49  char const* streamName() const { return fStreamName; }
50 
52  unsigned numSubsessions() const { return fSubsessionCounter; }
53 
54  void testScaleFactor(float& scale); // sets "scale" to the actual supported scale
55  float duration() const;
56  // a result == 0 means an unbounded session (the default)
57  // a result < 0 means: subsession durations differ; the result is -(the largest).
58  // a result > 0 means: this is the duration of a bounded session
59 
60  virtual void noteLiveness();
61  // called whenever a client - accessing this media - notes liveness.
62  // The default implementation does nothing, but subclasses can redefine this - e.g., if you
63  // want to remove long-unused "ServerMediaSession"s from the server.
64 
65  unsigned referenceCount() const { return fReferenceCount; }
69 
71  // Removes and deletes all subsessions added by "addSubsession()", returning us to an 'empty' state
72  // Note: If you have already added this "ServerMediaSession" to a "RTSPServer" then, before calling this function,
73  // you must first close any client connections that use it,
74  // by calling "RTSPServer::closeAllClientSessionsForServerMediaSession()".
75 
76 protected:
78  char const* info, char const* description,
79  Boolean isSSM, char const* miscSDPLines);
80  // called only by "createNew()"
81 
83 
84 private: // redefined virtual functions
85  virtual Boolean isServerMediaSession() const;
86 
87 private:
89 
90  // Linkage fields:
95 
96  char* fStreamName;
100  struct timeval fCreationTime;
101  unsigned fReferenceCount;
103 };
104 
105 
107 public:
110 
111  ServerMediaSubsession* next(); // NULL if none
112  void reset();
113 
114 private:
117 };
118 
119 
121 public:
122  unsigned trackNumber() const { return fTrackNumber; }
123  char const* trackId();
124  virtual char const* sdpLines(int addressFamily) = 0;
125  virtual void getStreamParameters(unsigned clientSessionId, // in
126  struct sockaddr_storage const& clientAddress, // in
127  Port const& clientRTPPort, // in
128  Port const& clientRTCPPort, // in
129  int tcpSocketNum, // in (-1 means use UDP, not TCP)
130  unsigned char rtpChannelId, // in (used if TCP)
131  unsigned char rtcpChannelId, // in (used if TCP)
132  TLSState* tlsState, // in (used if TCP)
133  struct sockaddr_storage& destinationAddress, // in out
134  u_int8_t& destinationTTL, // in out
135  Boolean& isMulticast, // out
136  Port& serverRTPPort, // out
137  Port& serverRTCPPort, // out
138  void*& streamToken // out
139  ) = 0;
140  virtual void startStream(unsigned clientSessionId, void* streamToken,
141  TaskFunc* rtcpRRHandler,
142  void* rtcpRRHandlerClientData,
143  unsigned short& rtpSeqNum,
144  unsigned& rtpTimestamp,
145  ServerRequestAlternativeByteHandler* serverRequestAlternativeByteHandler,
146  void* serverRequestAlternativeByteHandlerClientData) = 0;
147  virtual void pauseStream(unsigned clientSessionId, void* streamToken);
148  virtual void seekStream(unsigned clientSessionId, void* streamToken, double& seekNPT,
149  double streamDuration, u_int64_t& numBytes);
150  // This routine is used to seek by relative (i.e., NPT) time.
151  // "streamDuration", if >0.0, specifies how much data to stream, past "seekNPT". (If <=0.0, all remaining data is streamed.)
152  // "numBytes" returns the size (in bytes) of the data to be streamed, or 0 if unknown or unlimited.
153  virtual void seekStream(unsigned clientSessionId, void* streamToken, char*& absStart, char*& absEnd);
154  // This routine is used to seek by 'absolute' time.
155  // "absStart" should be a string of the form "YYYYMMDDTHHMMSSZ" or "YYYYMMDDTHHMMSS.<frac>Z".
156  // "absEnd" should be either NULL (for no end time), or a string of the same form as "absStart".
157  // These strings may be modified in-place, or can be reassigned to a newly-allocated value (after delete[]ing the original).
158  virtual void nullSeekStream(unsigned clientSessionId, void* streamToken,
159  double streamEndTime, u_int64_t& numBytes);
160  // Called whenever we're handling a "PLAY" command without a specified start time.
161  virtual void setStreamScale(unsigned clientSessionId, void* streamToken, float scale);
162  virtual float getCurrentNPT(void* streamToken);
163  virtual FramedSource* getStreamSource(void* streamToken);
164  virtual void getRTPSinkandRTCP(void* streamToken,
165  RTPSink const*& rtpSink, RTCPInstance const*& rtcp) = 0;
166  // Returns pointers to the "RTPSink" and "RTCPInstance" objects for "streamToken".
167  // (This can be useful if you want to get the associated 'Groupsock' objects, for example.)
168  // You must not delete these objects, or start/stop playing them; instead, that is done
169  // using the "startStream()" and "deleteStream()" functions.
170  virtual void deleteStream(unsigned clientSessionId, void*& streamToken);
171 
172  virtual void testScaleFactor(float& scale); // sets "scale" to the actual supported scale
173  virtual float duration() const;
174  // returns 0 for an unbounded session (the default)
175  // returns > 0 for a bounded session
176  virtual void getAbsoluteTimeRange(char*& absStartTime, char*& absEndTime) const;
177  // Subclasses can reimplement this iff they support seeking by 'absolute' time.
178 
179 protected: // we're a virtual base class
182 
183  char const* rangeSDPLine() const;
184  // returns a string to be delete[]d
185 
187 
188 private:
189  friend class ServerMediaSession;
192 
193  unsigned fTrackNumber; // within an enclosing ServerMediaSession
194  char const* fTrackId;
195 };
196 
197 #endif
const Boolean False
Definition: Boolean.hh:28
unsigned char Boolean
Definition: Boolean.hh:25
void ServerRequestAlternativeByteHandler(void *instance, u_int8_t requestByte)
Definition: RTPInterface.hh:41
#define NULL
void TaskFunc(void *clientData)
Definition: Media.hh:50
void testScaleFactor(float &scale)
char const * streamName() const
void deleteAllSubsessions()
virtual Boolean isServerMediaSession() const
ServerMediaSubsession * fSubsessionsHead
virtual void noteLiveness()
char * generateSDPDescription(int addressFamily)
ServerMediaSession(UsageEnvironment &env, char const *streamName, char const *info, char const *description, Boolean isSSM, char const *miscSDPLines)
struct timeval fCreationTime
ServerMediaSubsession * fSubsessionsTail
Boolean & deleteWhenUnreferenced()
Boolean addSubsession(ServerMediaSubsession *subsession)
unsigned referenceCount() const
float duration() const
unsigned numSubsessions() const
static ServerMediaSession * createNew(UsageEnvironment &env, char const *streamName=NULL, char const *info=NULL, char const *description=NULL, Boolean isSSM=False, char const *miscSDPLines=NULL)
static Boolean lookupByName(UsageEnvironment &env, char const *mediumName, ServerMediaSession *&resultSession)
virtual ~ServerMediaSession()
ServerMediaSubsession * next()
ServerMediaSubsessionIterator(ServerMediaSession &session)
ServerMediaSubsession * fNextPtr
virtual void seekStream(unsigned clientSessionId, void *streamToken, double &seekNPT, double streamDuration, u_int64_t &numBytes)
char const * rangeSDPLine() const
virtual void pauseStream(unsigned clientSessionId, void *streamToken)
ServerMediaSession * fParentSession
ServerMediaSubsession(UsageEnvironment &env)
virtual void seekStream(unsigned clientSessionId, void *streamToken, char *&absStart, char *&absEnd)
unsigned trackNumber() const
virtual void getAbsoluteTimeRange(char *&absStartTime, char *&absEndTime) const
virtual float getCurrentNPT(void *streamToken)
ServerMediaSubsession * fNext
virtual void deleteStream(unsigned clientSessionId, void *&streamToken)
virtual void setStreamScale(unsigned clientSessionId, void *streamToken, float scale)
virtual float duration() const
char const * trackId()
virtual void startStream(unsigned clientSessionId, void *streamToken, TaskFunc *rtcpRRHandler, void *rtcpRRHandlerClientData, unsigned short &rtpSeqNum, unsigned &rtpTimestamp, ServerRequestAlternativeByteHandler *serverRequestAlternativeByteHandler, void *serverRequestAlternativeByteHandlerClientData)=0
virtual void nullSeekStream(unsigned clientSessionId, void *streamToken, double streamEndTime, u_int64_t &numBytes)
virtual FramedSource * getStreamSource(void *streamToken)
virtual void testScaleFactor(float &scale)
virtual ~ServerMediaSubsession()
virtual void getRTPSinkandRTCP(void *streamToken, RTPSink const *&rtpSink, RTCPInstance const *&rtcp)=0
virtual void getStreamParameters(unsigned clientSessionId, struct sockaddr_storage const &clientAddress, Port const &clientRTPPort, Port const &clientRTCPPort, int tcpSocketNum, unsigned char rtpChannelId, unsigned char rtcpChannelId, TLSState *tlsState, struct sockaddr_storage &destinationAddress, u_int8_t &destinationTTL, Boolean &isMulticast, Port &serverRTPPort, Port &serverRTCPPort, void *&streamToken)=0
virtual char const * sdpLines(int addressFamily)=0