UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
BasicRTSPOnlyServer.cpp
Go to the documentation of this file.
1/*
2 * FILE: rtsp/BasicRTSPOnlyServer.cpp
3 * AUTHORS: David Cassany <david.cassany@i2cat.net>
4 * Gerard Castillo <gerard.castillo@i2cat.net>
5 *
6 * Copyright (c) 2005-2010 Fundació i2CAT, Internet I Innovació Digital a Catalunya
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, is permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 *
22 * This product includes software developed by the Fundació i2CAT,
23 * Internet I Innovació Digital a Catalunya. This product also includes
24 * software developed by CESNET z.s.p.o.
25 *
26 * 4. Neither the name of the University nor of the Institute may be used
27 * to endorse or promote products derived from this software without
28 * specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
32 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
33 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
34 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
35 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
37 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
39 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
41 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 *
43 */
44
45#include <GroupsockHelper.hh> // for "weHaveAnIPv*Address()"
46#include <cassert>
47
50#include "rtsp/rtsp_utils.h"
51
53
55 if (params.parent == NULL) {
56 exit(1);
57 }
58 this->params = params;
59 this->rtspServer = NULL;
60 this->env = NULL;
61 this->srvInstance = this;
62}
63
72
75 if (srvInstance != NULL){
76 return srvInstance;
77 }
78 return NULL;
79}
80
81int
83{
84 assert(env == nullptr && rtspServer == nullptr);
85 assert(params.parent != nullptr);
86 assert(params.avType > rtsp_type_none && params.avType <= rtsp_av_type_both);
87
88 //setting livenessTimeoutTask
89 unsigned reclamationTestSeconds = 60;
90
91 TaskScheduler* scheduler = BasicTaskScheduler::createNew();
92 env = BasicUsageEnvironment::createNew(*scheduler);
93
94 UserAuthenticationDatabase* authDB = NULL;
95 #ifdef ACCESS_CONTROL
96 // To implement client access control to the RTSP server, do the following:
97 authDB = new UserAuthenticationDatabase;
98 authDB->addUserRecord("i2cat", "ultragrid"); // replace these with real strings
99 // Repeat the above with each <username>, <password> that you wish to allow
100 // access to the server.
101 #endif
102
103 if (params.rtsp_port == 0) {
104 params.rtsp_port = 8554;
105 }
106
107 rtspServer = RTSPServer::createNew(*env, params.rtsp_port, authDB,
108 reclamationTestSeconds);
109 if (rtspServer == NULL) {
110 *env << "Failed to create RTSP server: " << env->getResultMsg() << "\n";
111 exit(1);
112 }
113 rtspServer->disableStreamingRTPOverTCP();
114 ServerMediaSession* sms;
115 sms = ServerMediaSession::createNew(*env, "ultragrid",
116 "UltraGrid RTSP server enabling standard transport",
117 "UltraGrid RTSP server");
118
119 if ((params.avType & rtsp_type_audio) != 0) {
120 sms->addSubsession(BasicRTSPOnlySubsession ::createNew(
121 *env, True, rtsp_type_audio, params.rtp_port_audio, params));
122 }
123 if ((params.avType & rtsp_type_video) != 0) {
124 sms->addSubsession(BasicRTSPOnlySubsession ::createNew(
125 *env, True, rtsp_type_video, params.rtp_port_video, params));
126 }
127
128 rtspServer->addServerMediaSession(sms);
129
130 *env << "\n";
131 if (weHaveAnIPv4Address(*env)) {
132 char* url = rtspServer->ipv4rtspURL(sms);
133 *env << "[RTSP Server] Play this stream using the URL \"" << url << "\"\n";
134 delete[] url;
135 }
136 if (weHaveAnIPv6Address(*env)) {
137 char* url = rtspServer->ipv6rtspURL(sms);
138 *env << "[RTSP Server] Play this stream using the URL \"" << url << "\"\n";
139 delete[] url;
140 }
141
142 return 0;
143}
144
146 char* watch = (char*) args;
148
149 if (instance == NULL || instance->env == NULL || instance->rtspServer == NULL){
150 return NULL;
151 }
152
153 instance->env->taskScheduler().doEventLoop(watch);
154
155 Medium::close(instance->rtspServer);
156 delete &instance->env->taskScheduler();
157 instance->env->reclaim();
158
159 return NULL;
160}
struct rtsp_server_parameters params
BasicRTSPOnlyServer(struct rtsp_server_parameters params)
static BasicRTSPOnlyServer * initInstance(struct rtsp_server_parameters params)
static BasicRTSPOnlyServer * getInstance()
static BasicRTSPOnlyServer * srvInstance
UsageEnvironment * env
static void * start_server(void *args)
@ rtsp_av_type_both
Definition rtsp_utils.h:8
@ rtsp_type_video
Definition rtsp_utils.h:7
@ rtsp_type_none
Definition rtsp_utils.h:5
@ rtsp_type_audio
Definition rtsp_utils.h:6
static class worker_pool instance
Definition worker.cpp:250