4 #include "RTSPServer.hh" 5 #include "RTSPCommon.hh" 6 #include "RTSPRegisterSender.hh" 8 #include <GroupsockHelper.hh> 19 RsRTSPServer*
RsRTSPServer::createNew(UsageEnvironment& t_env, std::shared_ptr<RsDevice> t_device, Port t_ourPort, UserAuthenticationDatabase* t_authDatabase,
unsigned t_reclamationSeconds)
21 int ourSocket = setUpOurSocket(t_env, t_ourPort);
25 return new RsRTSPServer(t_env, t_device, ourSocket, t_ourPort, t_authDatabase, t_reclamationSeconds);
28 RsRTSPServer::RsRTSPServer(UsageEnvironment& t_env, std::shared_ptr<RsDevice> t_device,
int t_ourSocket, Port t_ourPort, UserAuthenticationDatabase* t_authDatabase,
unsigned t_reclamationSeconds)
29 : RTSPServer(t_env, t_ourSocket, t_ourPort, t_authDatabase, t_reclamationSeconds)
37 std::ostringstream oss;
38 oss << (int)t_opt <<
"{" << t_min <<
"," << t_max <<
"," << t_def <<
"," << t_step <<
"}" 50 for(
auto option : optionsPair.second)
67 : RTSPClientConnection(t_ourServer, t_clientSocket, t_clientAddr)
68 , m_fOurRsRTSPServer(t_ourServer)
74 fOurRTSPServer.closeAllClientSessionsForServerMediaSession(
STEREO_SENSOR_NAME.c_str());
75 fOurRTSPServer.closeAllClientSessionsForServerMediaSession(
RGB_SENSOR_NAME.c_str());
77 RTSPServer::RTSPClientConnection::handleCmd_DESCRIBE(urlPreSuffix, urlSuffix, fullRequestStr);
82 std::ostringstream oss;
83 std::vector<RsSensor> sensors;
88 afterSplit = str.substr(str.find(ContentLength) + ContentLength.size());
89 char* contLength = strtok((
char*)afterSplit.c_str(),
"\r\n: ");
90 char* sensorName = strtok(
NULL,
"_\r\n:");
95 if(
sensor.getSensorName().compare(sensorName) == 0)
100 char* paramString =
new char[strlen(sensorName) + 1 + strlen(option) + strlen(
std::to_string(value).c_str()) + 10];
101 sprintf(paramString,
"%s_%s: %s\r\n", sensorName, option,
std::to_string(value).c_str());
102 envir() <<
"GET_PARAMETER: sensor '" << sensorName <<
"', option '" << option <<
"', value " << value <<
"\n";
103 setRTSPResponse(
"200 OK", paramString);
106 catch(
const std::exception&
e)
109 setRTSPResponse(error.c_str());
114 setRTSPResponse(
"500 Invalid Option");
119 std::ostringstream oss;
120 std::vector<RsSensor> sensors;
125 afterSplit = str.substr(str.find(ContentLength) + ContentLength.size());
126 char* contLength = strtok((
char*)afterSplit.c_str(),
"\r\n: ");
127 char* sensorName = strtok(
NULL,
"_\r\n:");
131 envir() <<
"SET_PARAMETER: sensor '" << sensorName <<
"', option '" << option <<
"', value " << value <<
"\n";
133 for(
auto sensor : sensors)
135 if(
sensor.getSensorName().compare(sensorName) == 0)
140 setRTSPResponse(
"200 OK");
143 catch(
const std::exception&
e)
146 setRTSPResponse(error.c_str());
151 setRTSPResponse(
"500 Invalid Option");
157 : RTSPClientSession(t_ourServer, t_sessionId)
165 catch(
const std::exception&
e)
173 envir() <<
"TEARDOWN \n";
178 catch(
const std::exception&
e)
181 setRTSPResponse(t_ourClientConnection, error.c_str());
185 RTSPServer::RTSPClientSession::handleCmd_TEARDOWN(t_ourClientConnection, t_subsession);
190 envir() <<
"PLAY \n";
195 catch(
const std::exception&
e)
198 setRTSPResponse(t_ourClientConnection, error.c_str());
202 RTSPServer::RTSPClientSession::handleCmd_PLAY(t_ourClientConnection, t_subsession, t_fullRequestStr);
207 envir() <<
"PAUSE \n";
208 RTSPServer::RTSPClientSession::handleCmd_PAUSE(t_ourClientConnection, t_subsession);
213 catch(
const std::exception&
e)
216 setRTSPResponse(t_ourClientConnection, error.c_str());
222 std::ostringstream oss;
223 std::vector<RsSensor> sensors;
228 envir() <<
"GET_PARAMETER\n";
229 afterSplit = str.substr(str.find(ContentLength) + ContentLength.size());
230 char* contLength = strtok((
char*)afterSplit.c_str(),
"\r\n: ");
231 char* sensorName = strtok(
NULL,
"_\r\n:");
236 char* paramString =
new char[strlen(sensorName) + 1 + strlen(option) + strlen(
std::to_string(value).c_str()) + 10];
237 sprintf(paramString,
"%s_%s: %s\r\n", sensorName, option,
std::to_string(value).c_str());
238 setRTSPResponse(t_ourClientConnection,
"200 OK", paramString);
240 catch(
const std::exception&
e)
243 setRTSPResponse(t_ourClientConnection, error.c_str());
250 std::ostringstream oss;
251 std::vector<RsSensor> sensors;
256 envir() <<
"SET_PARAMETER \n";
257 afterSplit = str.substr(str.find(ContentLength) + ContentLength.size());
258 char* contLength = strtok((
char*)afterSplit.c_str(),
"\r\n: ");
259 char* sensorName = strtok(
NULL,
"_\r\n:");
266 setRTSPResponse(t_ourClientConnection,
"200 OK");
268 catch(
const std::exception&
e)
271 setRTSPResponse(t_ourClientConnection, error.c_str());
277 RTSPServer::RTSPClientSession::handleCmd_SETUP(t_ourClientConnection, t_urlPreSuffix, t_urlSuffix, t_fullRequestStr);
278 ServerMediaSubsession* subsession;
279 if(t_urlSuffix[0] !=
'\0' && strcmp(fOurServerMediaSession->streamName(), t_urlPreSuffix) == 0)
283 ServerMediaSubsessionIterator iter(*fOurServerMediaSession);
284 while((subsession = iter.next()) !=
NULL)
286 if(strcmp(subsession->trackId(), t_urlSuffix) == 0)
304 for(
int i = 0;
i < fNumStreamStates; ++
i)
306 if(fStreamStates[
i].subsession !=
NULL)
std::unordered_map< long long int, rs2::frame_queue > m_streamProfiles
float stof(const std::string &value)
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
void setSupportedOptions(std::string t_key, std::vector< RsOption > t_supportedOptions)
friend class RsRTSPClientConnection
const std::string RGB_SENSOR_NAME("RGB Camera")
RsRTSPClientSession(RTSPServer &t_ourServer, u_int32_t t_sessionId)
virtual ClientSession * createNewClientSession(u_int32_t t_sessionId)
virtual void handleCmd_GET_PARAMETER(RTSPClientConnection *t_ourClientConnection, ServerMediaSubsession *t_subsession, char const *t_fullRequestStr)
virtual void handleCmd_SET_PARAMETER(RTSPClientConnection *t_ourClientConnection, ServerMediaSubsession *t_subsession, char const *t_fullRequestStr)
GLsizei const GLchar *const * string
std::string m_supportedOptionsStr
virtual void handleCmd_PAUSE(RTSPClientConnection *t_ourClientConnection, ServerMediaSubsession *t_subsession)
std::shared_ptr< RsDevice > m_device
virtual void handleCmd_PLAY(RTSPClientConnection *t_ourClientConnection, ServerMediaSubsession *t_subsession, char const *t_fullRequestStr)
RsRTSPServer(UsageEnvironment &t_env, std::shared_ptr< RsDevice > t_device, int t_ourSocket, Port t_ourPort, UserAuthenticationDatabase *t_authDatabase, unsigned t_reclamationSeconds)
char const * allowedCommandNames()
virtual void handleCmd_SETUP(RTSPServer::RTSPClientConnection *t_ourClientConnection, char const *t_urlPreSuffix, char const *t_urlSuffix, char const *t_fullRequestStr)
virtual ~RsRTSPClientConnection()
virtual void handleCmd_SET_PARAMETER(char const *fullRequestStr)
const std::string STEREO_SENSOR_NAME("Stereo Module")
virtual void handleCmd_DESCRIBE(char const *urlPreSuffix, char const *urlSuffix, char const *fullRequestStr)
RsRTSPClientConnection(RsRTSPServer &t_ourServer, int t_clientSocket, struct sockaddr_storage const &t_clientAddr)
void emptyStreamProfileQueue(long long int t_profile_key)
virtual void handleCmd_TEARDOWN(RTSPClientConnection *t_ourClientConnection, ServerMediaSubsession *t_subsession)
std::string getOptionString(rs2_option t_opt, float t_min, float t_max, float t_def, float t_step)
virtual void handleCmd_GET_PARAMETER(char const *fullRequestStr)
RsRTSPServer & m_fOurRsRTSPServer
int stoi(const std::string &value)
virtual ClientConnection * createNewClientConnection(int t_clientSocket, struct sockaddr_storage const &t_clientAddr)
virtual ~RsRTSPClientSession()
static RsRTSPServer * createNew(UsageEnvironment &t_env, std::shared_ptr< RsDevice > t_device, Port t_ourPort=554, UserAuthenticationDatabase *t_authDatabase=NULL, unsigned t_reclamationSeconds=20)
std::map< std::string, std::vector< RsOption > > m_supportedOptions
std::string to_string(T value)