Skip to content

Commit

Permalink
add api to acess srtp/rtsps flags
Browse files Browse the repository at this point in the history
  • Loading branch information
mpromonet committed Sep 20, 2024
1 parent 9808945 commit 8d2f05d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
43 changes: 26 additions & 17 deletions inc/HTTPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,38 +232,49 @@ class HTTPServer : public RTSPServer

#if LIVEMEDIA_LIBRARY_VERSION_INT < 1611187200
HTTPServer(UsageEnvironment& env, int ourSocketIPv4, int ourSocketIPv6, Port rtspPort, MyUserAuthenticationDatabase* authDatabase, unsigned reclamationTestSeconds, unsigned int hlsSegment, const std::string & webroot, const std::string & sslCert, bool enableRTSPS)
: RTSPServer(env, ourSocketIPv4, rtspPort, authDatabase, reclamationTestSeconds), m_hlsSegment(hlsSegment), m_webroot(webroot), m_sslCert(sslCert)
: RTSPServer(env, ourSocketIPv4, rtspPort, authDatabase, reclamationTestSeconds), m_hlsSegment(hlsSegment), m_webroot(webroot)
#else
HTTPServer(UsageEnvironment& env, int ourSocketIPv4, int ourSocketIPv6, Port rtspPort, MyUserAuthenticationDatabase* authDatabase, unsigned reclamationTestSeconds, unsigned int hlsSegment, const std::string & webroot, const std::string & sslCert, bool enableRTSPS)
: RTSPServer(env, ourSocketIPv4, ourSocketIPv6, rtspPort, authDatabase, reclamationTestSeconds), m_hlsSegment(hlsSegment), m_webroot(webroot), m_sslCert(sslCert), m_enableRTSPS(enableRTSPS)
: RTSPServer(env, ourSocketIPv4, ourSocketIPv6, rtspPort, authDatabase, reclamationTestSeconds), m_hlsSegment(hlsSegment), m_webroot(webroot)
#endif
{
if ( (!m_webroot.empty()) && (*m_webroot.rend() != '/') ) {
m_webroot += "/";
}
#if LIVEMEDIA_LIBRARY_VERSION_INT >= 1642723200
if (this->isSSL()) {
if (m_enableRTSPS) {
this->setTLSState(m_sslCert.c_str(), m_sslCert.c_str());
} else {
this->setTLSFileNames(m_sslCert.c_str(), m_sslCert.c_str());
this->fWeServeSRTP = true;
this->fWeEncryptSRTP = true;
}
}
#endif
this->setTLS(sslCert, enableRTSPS);
}

virtual RTSPServer::ClientConnection* createNewClientConnection(int clientSocket, struct SOCKETCLIENT clientAddr)
{
return new HTTPClientConnection(*this, clientSocket, clientAddr, this->isSSL() && m_enableRTSPS);
return new HTTPClientConnection(*this, clientSocket, clientAddr, fOurConnectionsUseTLS);
}

virtual RTSPServer::ClientSession* createNewClientSession(u_int32_t sessionId) {
return new HTTPClientSession(*this, sessionId);
}

bool isSSL() { return (!m_sslCert.empty()); }
void setTLS(const std::string & sslCert, bool enableRTSPS = false, bool encryptSRTP = true) {
#if LIVEMEDIA_LIBRARY_VERSION_INT >= 1642723200
if (!sslCert.empty()) {
this->setTLSFileNames(sslCert.c_str(), sslCert.c_str());
fWeServeSRTP = true;
fWeEncryptSRTP = encryptSRTP;
if (enableRTSPS) {
fOurConnectionsUseTLS = true;
} else {
fOurConnectionsUseTLS = false;
}
} else {
fOurConnectionsUseTLS = false;
fWeServeSRTP = false;
fWeEncryptSRTP = false;
}
#endif
}

bool isRTSPS() { return fOurConnectionsUseTLS; }
bool isSRTP() { return fWeServeSRTP; }
bool isSRTPEncrypted() { return fWeEncryptSRTP; }

void addUserRecord(const char* username, const char* password) {
UserAuthenticationDatabase* auth = this->getAuthenticationDatabaseForCommand(NULL);
Expand Down Expand Up @@ -292,7 +303,5 @@ class HTTPServer : public RTSPServer
private:
const unsigned int m_hlsSegment;
std::string m_webroot;
std::string m_sslCert;
bool m_enableRTSPS;
};

16 changes: 16 additions & 0 deletions inc/V4l2RTSPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,22 @@ class V4l2RTSPServer {
return m_rtspServer->getUsers();
}

void setTLS(const std::string & sslCert, bool enableRTSPS = false, bool encryptSRTP = true) {
m_rtspServer->setTLS(sslCert, enableRTSPS, encryptSRTP);
}

bool isRTSPS() {
return m_rtspServer->isRTSPS();
}

bool isSRTP() {
return m_rtspServer->isSRTP();
}

bool isSRTPEncrypted() {
return m_rtspServer->isSRTPEncrypted();
}

protected:
ServerMediaSession* addSession(const std::string & sessionName, ServerMediaSubsession* subSession)
{
Expand Down

0 comments on commit 8d2f05d

Please sign in to comment.