live
ServerMediaSession.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// 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
31class ServerMediaSubsession; // forward
32
34public:
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 server then, before calling this function,
73 // you must first close any client connections that use it,
74 // by calling "GenericMediaServer::closeAllClientSessionsForServerMediaSession()".
75
76 Boolean streamingUsesSRTP; // by default, False
77 Boolean streamingIsEncrypted; // by default, False
78
79protected:
81 char const* info, char const* description,
82 Boolean isSSM, char const* miscSDPLines);
83 // called only by "createNew()"
84
86
87private: // redefined virtual functions
89
90private:
92
93 // Linkage fields:
98
103 struct timeval fCreationTime;
106};
107
108
110public:
113
114 ServerMediaSubsession* next(); // NULL if none
115 void reset();
116
117private:
120};
121
122
124public:
125 unsigned trackNumber() const { return fTrackNumber; }
126 char const* trackId();
127 virtual char const* sdpLines(int addressFamily) = 0;
128 virtual void getStreamParameters(unsigned clientSessionId, // in
129 struct sockaddr_storage const& clientAddress, // in
130 Port const& clientRTPPort, // in
131 Port const& clientRTCPPort, // in
132 int tcpSocketNum, // in (-1 means use UDP, not TCP)
133 unsigned char rtpChannelId, // in (used if TCP)
134 unsigned char rtcpChannelId, // in (used if TCP)
135 TLSState* tlsState, // in (used if TCP)
136 struct sockaddr_storage& destinationAddress, // in out
137 u_int8_t& destinationTTL, // in out
138 Boolean& isMulticast, // out
139 Port& serverRTPPort, // out
140 Port& serverRTCPPort, // out
141 void*& streamToken // out
142 ) = 0;
143 virtual void startStream(unsigned clientSessionId, void* streamToken,
144 TaskFunc* rtcpRRHandler,
145 void* rtcpRRHandlerClientData,
146 unsigned short& rtpSeqNum,
147 unsigned& rtpTimestamp,
148 ServerRequestAlternativeByteHandler* serverRequestAlternativeByteHandler,
149 void* serverRequestAlternativeByteHandlerClientData) = 0;
150 virtual void pauseStream(unsigned clientSessionId, void* streamToken);
151 virtual void seekStream(unsigned clientSessionId, void* streamToken, double& seekNPT,
152 double streamDuration, u_int64_t& numBytes);
153 // This routine is used to seek by relative (i.e., NPT) time.
154 // "streamDuration", if >0.0, specifies how much data to stream, past "seekNPT". (If <=0.0, all remaining data is streamed.)
155 // "numBytes" returns the size (in bytes) of the data to be streamed, or 0 if unknown or unlimited.
156 virtual void seekStream(unsigned clientSessionId, void* streamToken, char*& absStart, char*& absEnd);
157 // This routine is used to seek by 'absolute' time.
158 // "absStart" should be a string of the form "YYYYMMDDTHHMMSSZ" or "YYYYMMDDTHHMMSS.<frac>Z".
159 // "absEnd" should be either NULL (for no end time), or a string of the same form as "absStart".
160 // These strings may be modified in-place, or can be reassigned to a newly-allocated value (after delete[]ing the original).
161 virtual void nullSeekStream(unsigned clientSessionId, void* streamToken,
162 double streamEndTime, u_int64_t& numBytes);
163 // Called whenever we're handling a "PLAY" command without a specified start time.
164 virtual void setStreamScale(unsigned clientSessionId, void* streamToken, float scale);
165 virtual float getCurrentNPT(void* streamToken);
166 virtual FramedSource* getStreamSource(void* streamToken);
167 virtual void getRTPSinkandRTCP(void* streamToken,
168 RTPSink*& rtpSink, RTCPInstance*& rtcp) = 0;
169 // Returns pointers to the "RTPSink" and "RTCPInstance" objects for "streamToken".
170 // (This can be useful if you want to get the associated 'Groupsock' objects, for example.)
171 // You must not delete these objects, or start/stop playing them; instead, that is done
172 // using the "startStream()" and "deleteStream()" functions.
173 virtual void deleteStream(unsigned clientSessionId, void*& streamToken);
174
175 virtual void testScaleFactor(float& scale); // sets "scale" to the actual supported scale
176 virtual float duration() const;
177 // returns 0 for an unbounded session (the default)
178 // returns > 0 for a bounded session
179 virtual void getAbsoluteTimeRange(char*& absStartTime, char*& absEndTime) const;
180 // Subclasses can reimplement this iff they support seeking by 'absolute' time.
181
182protected: // we're a virtual base class
185
186 char const* rangeSDPLine() const;
187 // returns a string to be delete[]d
188
190
191private:
192 friend class ServerMediaSession;
195
196 unsigned fTrackNumber; // within an enclosing ServerMediaSession
197 char const* fTrackId;
198};
199
200#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)
void deleteAllSubsessions()
Boolean & deleteWhenUnreferenced()
char * generateSDPDescription(int addressFamily)
virtual Boolean isServerMediaSession() const
ServerMediaSubsession * fSubsessionsHead
char const * streamName() const
virtual void noteLiveness()
ServerMediaSession(UsageEnvironment &env, char const *streamName, char const *info, char const *description, Boolean isSSM, char const *miscSDPLines)
struct timeval fCreationTime
ServerMediaSubsession * fSubsessionsTail
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()
ServerMediaSubsessionIterator(ServerMediaSession &session)
ServerMediaSubsession * fNextPtr
ServerMediaSubsession * next()
virtual void seekStream(unsigned clientSessionId, void *streamToken, double &seekNPT, double streamDuration, u_int64_t &numBytes)
virtual void pauseStream(unsigned clientSessionId, void *streamToken)
ServerMediaSession * fParentSession
virtual void getRTPSinkandRTCP(void *streamToken, RTPSink *&rtpSink, RTCPInstance *&rtcp)=0
ServerMediaSubsession(UsageEnvironment &env)
char const * rangeSDPLine() const
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 void testScaleFactor(float &scale)
virtual ~ServerMediaSubsession()
virtual FramedSource * getStreamSource(void *streamToken)
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