UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
BasicRTSPOnlySubsession Class Reference

#include <BasicRTSPOnlySubsession.hh>

Inheritance diagram for BasicRTSPOnlySubsession:
Inheritance graph
Collaboration diagram for BasicRTSPOnlySubsession:
Collaboration graph

Static Public Member Functions

static BasicRTSPOnlySubsession * createNew (UsageEnvironment &env, Boolean reuseFirstSource, rtsp_types_t avType, int rtpPort, struct rtsp_server_parameters)
 

Protected Member Functions

 BasicRTSPOnlySubsession (UsageEnvironment &env, Boolean reuseFirstSource, rtsp_types_t avType, int rtpPort, struct rtsp_server_parameters)
 
 ~BasicRTSPOnlySubsession () override
 
void deleteStream (unsigned clientSessionId, void *&streamToken) override
 
void getRTPSinkandRTCP (void *, const RTPSink *&, const RTCPInstance *&) override
 
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, uint8_t &destinationTTL, Boolean &isMulticast, Port &serverRTPPort, Port &serverRTCPPort, void *&streamToken) override
 
char const * sdpLines (int addressFamily) override
 
void startStream (unsigned clientSessionId, void *streamToken, TaskFunc *rtcpRRHandler, void *rtcpRRHandlerClientData, unsigned short &rtpSeqNum, unsigned &rtpTimestamp, ServerRequestAlternativeByteHandler *serverRequestAlternativeByteHandler, void *serverRequestAlternativeByteHandlerClientData) override
 

Protected Attributes

Destinations * Adestination
 
char * fSDPLines
 
Destinations * Vdestination
 

Private Member Functions

void setSDPLines (int addressFamily)
 

Private Attributes

rtsp_types_t avType
 
char fCNAME [100]
 
MAYBE_UNUSED_ATTRIBUTE void * fLastStreamToken
 
MAYBE_UNUSED_ATTRIBUTE Boolean fReuseFirstSource
 
int rtpPort
 
struct rtsp_server_parameters rtsp_params
 

Detailed Description

Definition at line 89 of file BasicRTSPOnlySubsession.hh.

Constructor & Destructor Documentation

◆ BasicRTSPOnlySubsession()

BasicRTSPOnlySubsession::BasicRTSPOnlySubsession ( UsageEnvironment & env,
Boolean reuseFirstSource,
rtsp_types_t avType,
int rtpPort,
struct rtsp_server_parameters params )
protected

Definition at line 71 of file BasicRTSPOnlySubsession.cpp.

73 :
74 ServerMediaSubsession(env), fReuseFirstSource(reuseFirstSource),
76{
78 Vdestination = NULL;
79 Adestination = NULL;
80 gethostname(fCNAME, sizeof fCNAME);
81 this->avType = avType;
82 this->rtpPort = rtpPort;
83 fCNAME[sizeof fCNAME - 1] = '\0';
84
85 // print (preliminary) SDP
86 setSDPLines(AF_UNSPEC);
87 delete[] fSDPLines;
88 fSDPLines = nullptr;
89}
MAYBE_UNUSED_ATTRIBUTE Boolean fReuseFirstSource
void setSDPLines(int addressFamily)
struct rtsp_server_parameters rtsp_params
MAYBE_UNUSED_ATTRIBUTE void * fLastStreamToken
@ rtsp_type_video
Definition rtsp_utils.h:7
@ rtsp_type_audio
Definition rtsp_utils.h:6

References Adestination, avType, fCNAME, fSDPLines, rtpPort, rtsp_type_audio, rtsp_type_video, setSDPLines(), and Vdestination.

Referenced by createNew().

Here is the call graph for this function:

◆ ~BasicRTSPOnlySubsession()

BasicRTSPOnlySubsession::~BasicRTSPOnlySubsession ( )
overrideprotected

Definition at line 91 of file BasicRTSPOnlySubsession.cpp.

91 {
92 delete[] fSDPLines;
93 delete Adestination;
94 delete Vdestination;
95}

References Adestination, fSDPLines, and Vdestination.

Member Function Documentation

◆ createNew()

BasicRTSPOnlySubsession * BasicRTSPOnlySubsession::createNew ( UsageEnvironment & env,
Boolean reuseFirstSource,
rtsp_types_t avType,
int rtpPort,
struct rtsp_server_parameters params )
static

Definition at line 64 of file BasicRTSPOnlySubsession.cpp.

66 {
67 return new BasicRTSPOnlySubsession(env, reuseFirstSource, avType,
69}
BasicRTSPOnlySubsession(UsageEnvironment &env, Boolean reuseFirstSource, rtsp_types_t avType, int rtpPort, struct rtsp_server_parameters)

References BasicRTSPOnlySubsession(), avType, and rtpPort.

Here is the call graph for this function:

◆ deleteStream()

void BasicRTSPOnlySubsession::deleteStream ( unsigned clientSessionId,
void *& streamToken )
overrideprotected

Definition at line 287 of file BasicRTSPOnlySubsession.cpp.

288 {
289 if (Vdestination != NULL) {
290 if (avType == rtsp_type_video) {
291 char pathV[1024];
292 delete Vdestination;
293 Vdestination = NULL;
294 memset(pathV, 0, sizeof(pathV));
295 enum module_class path_sender[] = { MODULE_CLASS_SENDER,
297 append_message_path(pathV, sizeof(pathV), path_sender);
298
299 //CHANGE DST PORT
300 struct msg_sender *msgV1 = (struct msg_sender *) new_message(
301 sizeof(struct msg_sender));
304 struct response *resp;
305 resp = send_message(rtsp_params.parent, pathV, (struct message *) msgV1);
306 free_response(resp);
307
308 //CHANGE DST ADDRESS
309 struct msg_sender *msgV2 = (struct msg_sender *) new_message(
310 sizeof(struct msg_sender));
311 strncpy(msgV2->receiver, "127.0.0.1", sizeof(msgV2->receiver) - 1);
313 resp = send_message(rtsp_params.parent, pathV, (struct message *) msgV2);
314 free_response(resp);
315 }
316 }
317
318 if (Adestination != NULL) {
319 if (avType == rtsp_type_audio) {
320 char pathA[1024];
321 delete Adestination;
322 Adestination = NULL;
323 memset(pathA, 0, sizeof(pathA));
324 enum module_class path_sender[] = { MODULE_CLASS_AUDIO,
326 append_message_path(pathA, sizeof(pathA), path_sender);
327
328 //CHANGE DST PORT
329 struct msg_sender *msgA1 = (struct msg_sender *) new_message(
330 sizeof(struct msg_sender));
331
332 //TODO: GET AUDIO PORT SET (NOT A COMMON CASE WHEN RTSP IS ENABLED: DEFAULT -> vport + 2)
335 struct response *resp;
336 resp = send_message(rtsp_params.parent, pathA, (struct message *) msgA1);
337 free_response(resp);
338
339 //CHANGE DST ADDRESS
340 struct msg_sender *msgA2 = (struct msg_sender *) new_message(
341 sizeof(struct msg_sender));
342 strncpy(msgA2->receiver, "127.0.0.1", sizeof(msgA2->receiver) - 1);
344 resp = send_message(rtsp_params.parent, pathA, (struct message *) msgA2);
345 free_response(resp);
346 }
347 }
348}
static void new_message(struct module *m)
module_class
Definition module.h:81
void append_message_path(char *buf, int buflen, const enum module_class *modules)
Definition module.c:187
@ MODULE_CLASS_NONE
Definition module.h:82
@ MODULE_CLASS_AUDIO
Definition module.h:90
@ MODULE_CLASS_SENDER
Definition module.h:87
struct response * send_message(struct module *root, const char *const_path, struct message *msg)
Sends message without waiting for response.
void free_response(struct response *r)
@ SENDER_MSG_CHANGE_RECEIVER
Definition messaging.h:84
@ SENDER_MSG_CHANGE_PORT
Definition messaging.h:85
char receiver[128]
Definition messaging.h:103
enum msg_sender_type type
Definition messaging.h:97

References Adestination, append_message_path(), avType, free_response(), MODULE_CLASS_AUDIO, MODULE_CLASS_NONE, MODULE_CLASS_SENDER, new_message(), rtsp_server_parameters::parent, msg_sender::receiver, rtsp_server_parameters::rtp_port_audio, rtsp_server_parameters::rtp_port_video, rtsp_params, rtsp_type_audio, rtsp_type_video, send_message(), SENDER_MSG_CHANGE_PORT, SENDER_MSG_CHANGE_RECEIVER, msg_sender::tx_port, msg_sender::type, and Vdestination.

Here is the call graph for this function:

◆ getRTPSinkandRTCP()

void BasicRTSPOnlySubsession::getRTPSinkandRTCP ( void * ,
const RTPSink *& ,
const RTCPInstance *&  )
inlineoverrideprotected

Definition at line 133 of file BasicRTSPOnlySubsession.hh.

135 {
136 }

◆ getStreamParameters()

void BasicRTSPOnlySubsession::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,
uint8_t & destinationTTL,
Boolean & isMulticast,
Port & serverRTPPort,
Port & serverRTCPPort,
void *& streamToken )
overrideprotected

Definition at line 176 of file BasicRTSPOnlySubsession.cpp.

183 {
184 if (avType == rtsp_type_video) {
186 serverRTPPort = rtp;
187 Port rtcp(rtsp_params.rtp_port_video + 1);
188 serverRTCPPort = rtcp;
189
190 delete Vdestination;
191 Vdestination = new Destinations(clientAddress, clientRTPPort,
192 clientRTCPPort);
193 }
194 if (avType == rtsp_type_audio) {
196 serverRTPPort = rtp;
197 Port rtcp(rtsp_params.rtp_port_audio + 1);
198 serverRTCPPort = rtcp;
199
200 delete Adestination;
201 Adestination = new Destinations(clientAddress, clientRTPPort,
202 clientRTCPPort);
203 }
204}
Definition rtp.c:274

References Adestination, avType, rtsp_server_parameters::rtp_port_audio, rtsp_server_parameters::rtp_port_video, rtsp_params, rtsp_type_audio, rtsp_type_video, and Vdestination.

◆ sdpLines()

char const * BasicRTSPOnlySubsession::sdpLines ( int addressFamily)
overrideprotected

Definition at line 108 of file BasicRTSPOnlySubsession.cpp.

108 {
109 if (fSDPLines == NULL) {
110 setSDPLines(addressFamily);
111 }
112 return fSDPLines;
113}

References fSDPLines, and setSDPLines().

Referenced by setSDPLines().

Here is the call graph for this function:

◆ setSDPLines()

void BasicRTSPOnlySubsession::setSDPLines ( int addressFamily)
private

Definition at line 115 of file BasicRTSPOnlySubsession.cpp.

115 {
116 //TODO: should be more dynamic
117 const char *ip_ver_list_addr = nullptr;
118 const char *control = trackId();
119 switch (addressFamily) {
120 case AF_INET:
121 ip_ver_list_addr = "4 0.0.0.0";
122 break;
123 case AF_INET6:
124 ip_ver_list_addr = "6 ::";
125 break;
126 case AF_UNSPEC:
127 ip_ver_list_addr = "<VER> <TO_BE_FILLED>";
128 control = "<CONTROL>"; // is null here
129 break;
130 default:
131 abort();
132 }
133
134 const struct media_spec *mspec = &media_params[avType];
135 char rtpmapLine[STR_LEN];
136 int rtpPayloadType = avType == rtsp_type_audio
139 rtsp_params.adesc.ch_count, rtpmapLine)
140 : get_video_rtp_pt_rtpmap(rtsp_params.video_codec, rtpmapLine);
141 if (rtpPayloadType < 0) {
142 MSG(ERROR, "Unsupported %s codec %s!\n", mspec[avType].mname,
146 }
147 //char const* auxSDPLine = "";
148
149 char const *const sdpFmt = "m=%s %u RTP/AVP %d\r\n"
150 "c=IN IP%s\r\n"
151 "b=AS:%u\r\n"
152 "a=rtcp:%d\r\n"
153 "%s"
154 "a=control:%s\r\n";
155 unsigned sdpFmtSize = strlen(sdpFmt) + strlen(mspec->mname) +
156 5 /* max short len */
157 + 3 /* max char len */
158 + strlen(ip_ver_list_addr) + 20 /* max int len */
159 + strlen(rtpmapLine) + strlen(control);
160 char *sdpLines = new char[sdpFmtSize];
161
162 snprintf(sdpLines, sdpFmtSize, sdpFmt, mspec->mname, // m= <media>
163 rtpPort, // fPortNumForSDP, // m= <port>
164 rtpPayloadType, // m= <fmt list>
165 ip_ver_list_addr, // c= address
166 mspec->estBitrate, // b=AS:<bandwidth>
167 rtpPort + 1,
168 rtpmapLine, // a=rtpmap:... (if present)
169 control); // a=control:<track-id>
170
172 MSG(VERBOSE, "SDP%s:\n%s\n",
173 addressFamily == AF_UNSPEC ? " (preliminary)" : "", fSDPLines);
174}
static const struct media_spec media_params[]
const char * get_codec_name(codec_t codec)
char const * sdpLines(int addressFamily) override
const char * get_name_to_audio_codec(audio_codec_t codec)
Definition codec.cpp:450
#define MSG(l, fmt,...)
Definition debug.h:96
@ STR_LEN
"standard" string length placeholder
Definition macros.h:134
int get_audio_rtp_pt_rtpmap(audio_codec_t codec, int sample_rate, int channels, char rtpmapLine[STR_LEN])
Definition sdp.c:227
int get_video_rtp_pt_rtpmap(codec_t codec, char rtpmapLine[STR_LEN])
Definition sdp.c:304
int sample_rate
Definition types.h:78
int ch_count
Definition types.h:79
audio_codec_t codec
Definition types.h:80

References rtsp_server_parameters::adesc, avType, audio_desc::ch_count, audio_desc::codec, media_spec::estBitrate, fSDPLines, get_audio_rtp_pt_rtpmap(), get_codec_name(), get_name_to_audio_codec(), get_video_rtp_pt_rtpmap(), media_params, media_spec::mname, MSG, rtpPort, rtsp_params, rtsp_type_audio, audio_desc::sample_rate, sdpLines(), STR_LEN, and rtsp_server_parameters::video_codec.

Referenced by BasicRTSPOnlySubsession(), and sdpLines().

Here is the call graph for this function:

◆ startStream()

void BasicRTSPOnlySubsession::startStream ( unsigned clientSessionId,
void * streamToken,
TaskFunc * rtcpRRHandler,
void * rtcpRRHandlerClientData,
unsigned short & rtpSeqNum,
unsigned & rtpTimestamp,
ServerRequestAlternativeByteHandler * serverRequestAlternativeByteHandler,
void * serverRequestAlternativeByteHandlerClientData )
overrideprotected

Definition at line 206 of file BasicRTSPOnlySubsession.cpp.

211 {
212 struct response *resp = NULL;
213
214 if (Vdestination != NULL) {
215 if (avType == rtsp_type_video) {
216 char pathV[1024];
217
218 memset(pathV, 0, sizeof(pathV));
219 enum module_class path_sender[] = { MODULE_CLASS_SENDER,
221 append_message_path(pathV, sizeof(pathV), path_sender);
222
223 //CHANGE DST PORT
224 struct msg_sender *msgV1 = (struct msg_sender *) new_message(
225 sizeof(struct msg_sender));
226 msgV1->tx_port = ntohs(Vdestination->rtpPort.num());
228 resp = send_message(rtsp_params.parent, pathV, (struct message *) msgV1);
229 free_response(resp);
230
231 //CHANGE DST ADDRESS
232 struct msg_sender *msgV2 = (struct msg_sender *) new_message(
233 sizeof(struct msg_sender));
234 char host[IN6_MAX_ASCII_LEN + 1];
235 const int ret =
236 getnameinfo((struct sockaddr *) &Vdestination->addr,
237 sizeof Vdestination->addr, host,
238 sizeof host, nullptr, 0, NI_NUMERICHOST);
239 assert(ret == 0);
240 strncpy(msgV2->receiver, host,
241 sizeof(msgV2->receiver) - 1);
243
244 resp = send_message(rtsp_params.parent, pathV, (struct message *) msgV2);
245 free_response(resp);
246 }
247 }
248
249 if (Adestination != NULL) {
250 if (avType == rtsp_type_audio) {
251 char pathA[1024];
252
253 memset(pathA, 0, sizeof(pathA));
254 enum module_class path_sender[] = { MODULE_CLASS_AUDIO,
256 append_message_path(pathA, sizeof(pathA), path_sender);
257
258 //CHANGE DST PORT
259 struct msg_sender *msgA1 = (struct msg_sender *) new_message(
260 sizeof(struct msg_sender));
261 msgA1->tx_port = ntohs(Adestination->rtpPort.num());
263 resp = send_message(rtsp_params.parent, pathA, (struct message *) msgA1);
264 free_response(resp);
265 resp = NULL;
266
267 //CHANGE DST ADDRESS
268 struct msg_sender *msgA2 = (struct msg_sender *) new_message(
269 sizeof(struct msg_sender));
270 char host[IN6_MAX_ASCII_LEN + 1];
271 const int ret =
272 getnameinfo((struct sockaddr *) &Adestination->addr,
273 sizeof Adestination->addr, host,
274 sizeof host, nullptr, 0, NI_NUMERICHOST);
275 assert(ret == 0);
276 strncpy(msgA2->receiver, host,
277 sizeof(msgA2->receiver) - 1);
279
280 resp = send_message(rtsp_params.parent, pathA, (struct message *) msgA2);
281 free_response(resp);
282 resp = NULL;
283 }
284 }
285}
struct sockaddr_storage addr
#define IN6_MAX_ASCII_LEN
Definition net.h:50

References Destinations::addr, Adestination, append_message_path(), avType, free_response(), IN6_MAX_ASCII_LEN, MODULE_CLASS_AUDIO, MODULE_CLASS_NONE, MODULE_CLASS_SENDER, new_message(), rtsp_server_parameters::parent, msg_sender::receiver, Destinations::rtpPort, rtsp_params, rtsp_type_audio, rtsp_type_video, send_message(), SENDER_MSG_CHANGE_PORT, SENDER_MSG_CHANGE_RECEIVER, msg_sender::tx_port, msg_sender::type, and Vdestination.

Here is the call graph for this function:

Member Data Documentation

◆ Adestination

Destinations* BasicRTSPOnlySubsession::Adestination
protected

◆ avType

rtsp_types_t BasicRTSPOnlySubsession::avType
private

◆ fCNAME

char BasicRTSPOnlySubsession::fCNAME[100]
private

Definition at line 151 of file BasicRTSPOnlySubsession.hh.

Referenced by BasicRTSPOnlySubsession().

◆ fLastStreamToken

MAYBE_UNUSED_ATTRIBUTE void* BasicRTSPOnlySubsession::fLastStreamToken
private

Definition at line 150 of file BasicRTSPOnlySubsession.hh.

◆ fReuseFirstSource

MAYBE_UNUSED_ATTRIBUTE Boolean BasicRTSPOnlySubsession::fReuseFirstSource
private

Definition at line 149 of file BasicRTSPOnlySubsession.hh.

◆ fSDPLines

char* BasicRTSPOnlySubsession::fSDPLines
protected

◆ rtpPort

int BasicRTSPOnlySubsession::rtpPort
private

Definition at line 153 of file BasicRTSPOnlySubsession.hh.

Referenced by BasicRTSPOnlySubsession(), createNew(), and setSDPLines().

◆ rtsp_params

struct rtsp_server_parameters BasicRTSPOnlySubsession::rtsp_params
private

◆ Vdestination

Destinations* BasicRTSPOnlySubsession::Vdestination
protected

The documentation for this class was generated from the following files: