diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..07c2460 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,57 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "list": "cpp", + "map": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp" + } +} \ No newline at end of file diff --git a/inc/HTTPServer.h b/inc/HTTPServer.h index bb1dbc1..ee501f7 100644 --- a/inc/HTTPServer.h +++ b/inc/HTTPServer.h @@ -13,7 +13,9 @@ #pragma once -#include "RTSPServer.hh" +// hacking private members RTSPServer::fWeServeSRTP & RTSPServer::fWeEncryptSRTP +#define private protected +#include "liveMedia.hh" #include "RTSPCommon.hh" #include // for "ignoreSigPipeOnSocket()" @@ -162,7 +164,7 @@ class HTTPServer : public RTSPServer }; public: - static HTTPServer* createNew(UsageEnvironment& env, Port rtspPort, UserAuthenticationDatabase* authDatabase, unsigned reclamationTestSeconds, unsigned int hlsSegment, const std::string & webroot, const std::string & sslCert, bool weServeSRTP) + static HTTPServer* createNew(UsageEnvironment& env, Port rtspPort, UserAuthenticationDatabase* authDatabase, unsigned reclamationTestSeconds, unsigned int hlsSegment, const std::string & webroot, const std::string & sslCert, bool enableRTSPS) { HTTPServer* httpServer = NULL; #if LIVEMEDIA_LIBRARY_VERSION_INT < 1610928000 @@ -178,17 +180,17 @@ class HTTPServer : public RTSPServer if (ourSocketIPv4 != -1) { - httpServer = new HTTPServer(env, ourSocketIPv4, ourSocketIPv6, rtspPort, authDatabase, reclamationTestSeconds, hlsSegment, webroot, sslCert, weServeSRTP); + httpServer = new HTTPServer(env, ourSocketIPv4, ourSocketIPv6, rtspPort, authDatabase, reclamationTestSeconds, hlsSegment, webroot, sslCert, enableRTSPS); } return httpServer; } #if LIVEMEDIA_LIBRARY_VERSION_INT < 1611187200 - HTTPServer(UsageEnvironment& env, int ourSocketIPv4, int ourSocketIPv6, Port rtspPort, UserAuthenticationDatabase* authDatabase, unsigned reclamationTestSeconds, unsigned int hlsSegment, const std::string & webroot, const std::string & sslCert, bool weServeSRTP) + HTTPServer(UsageEnvironment& env, int ourSocketIPv4, int ourSocketIPv6, Port rtspPort, UserAuthenticationDatabase* 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) #else - HTTPServer(UsageEnvironment& env, int ourSocketIPv4, int ourSocketIPv6, Port rtspPort, UserAuthenticationDatabase* authDatabase, unsigned reclamationTestSeconds, unsigned int hlsSegment, const std::string & webroot, const std::string & sslCert, bool weServeSRTP) - : RTSPServer(env, ourSocketIPv4, ourSocketIPv6, rtspPort, authDatabase, reclamationTestSeconds), m_hlsSegment(hlsSegment), m_webroot(webroot), m_sslCert(sslCert), m_weServeSRTP(weServeSRTP) + HTTPServer(UsageEnvironment& env, int ourSocketIPv4, int ourSocketIPv6, Port rtspPort, UserAuthenticationDatabase* 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) #endif { if ( (!m_webroot.empty()) && (*m_webroot.rend() != '/') ) { @@ -196,14 +198,20 @@ class HTTPServer : public RTSPServer } #if LIVEMEDIA_LIBRARY_VERSION_INT >= 1642723200 if (this->isSSL()) { - this->setTLSState(m_sslCert.c_str(), m_sslCert.c_str(), m_weServeSRTP); + 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 } virtual RTSPServer::ClientConnection* createNewClientConnection(int clientSocket, struct SOCKETCLIENT clientAddr) { - return new HTTPClientConnection(*this, clientSocket, clientAddr, this->isSSL()); + return new HTTPClientConnection(*this, clientSocket, clientAddr, this->isSSL() && m_enableRTSPS); } virtual RTSPServer::ClientSession* createNewClientSession(u_int32_t sessionId) { @@ -216,6 +224,6 @@ class HTTPServer : public RTSPServer const unsigned int m_hlsSegment; std::string m_webroot; std::string m_sslCert; - bool m_weServeSRTP; + bool m_enableRTSPS; }; diff --git a/inc/V4l2RTSPServer.h b/inc/V4l2RTSPServer.h index 6bdf8a8..958f323 100644 --- a/inc/V4l2RTSPServer.h +++ b/inc/V4l2RTSPServer.h @@ -17,20 +17,20 @@ #include #include +#include "HTTPServer.h" #include "UnicastServerMediaSubsession.h" #include "MulticastServerMediaSubsession.h" #include "TSServerMediaSubsession.h" -#include "HTTPServer.h" class V4l2RTSPServer { public: - V4l2RTSPServer(unsigned short rtspPort, unsigned short rtspOverHTTPPort = 0, int timeout = 10, unsigned int hlsSegment = 0, const std::list & userPasswordList = std::list(), const char* realm = NULL, const std::string & webroot = "", const std::string & sslkeycert = "", bool weServeSRTP = true) + V4l2RTSPServer(unsigned short rtspPort, unsigned short rtspOverHTTPPort = 0, int timeout = 10, unsigned int hlsSegment = 0, const std::list & userPasswordList = std::list(), const char* realm = NULL, const std::string & webroot = "", const std::string & sslkeycert = "", bool enableRTSPS = false) : m_stop(0) , m_env(BasicUsageEnvironment::createNew(*BasicTaskScheduler::createNew())) , m_rtspPort(rtspPort) { UserAuthenticationDatabase* auth = createUserAuthenticationDatabase(userPasswordList, realm); - m_rtspServer = HTTPServer::createNew(*m_env, rtspPort, auth, timeout, hlsSegment, webroot, sslkeycert, weServeSRTP); + m_rtspServer = HTTPServer::createNew(*m_env, rtspPort, auth, timeout, hlsSegment, webroot, sslkeycert, enableRTSPS); if (m_rtspServer != NULL) { if (rtspOverHTTPPort) diff --git a/main.cpp b/main.cpp index bc324fd..391e63c 100755 --- a/main.cpp +++ b/main.cpp @@ -31,8 +31,8 @@ #include "V4l2Device.h" #include "V4l2Output.h" -#include "DeviceSourceFactory.h" #include "V4l2RTSPServer.h" +#include "DeviceSourceFactory.h" // ----------------------------------------- @@ -97,7 +97,7 @@ int main(int argc, char** argv) int defaultHlsSegment = 2; unsigned int hlsSegment = 0; std::string sslKeyCert; - bool weServeSRTP = true; + bool enableRTSPS = true; const char* realm = NULL; std::list userPasswordList; std::string webroot; @@ -135,7 +135,7 @@ int main(int argc, char** argv) case 'S': hlsSegment = optarg ? atoi(optarg) : defaultHlsSegment; break; #ifndef NO_OPENSSL case 'x': sslKeyCert = optarg; break; - case 'X': weServeSRTP = false; break; + case 'X': enableRTSPS = true; break; #endif // users @@ -191,8 +191,8 @@ int main(int argc, char** argv) std::cout << "\t -c : don't repeat config (default repeat config before IDR frame)" << std::endl; std::cout << "\t -t : RTCP expiration timeout in seconds (default " << timeout << ")" << std::endl; std::cout << "\t -S[] : enable HLS & MPEG-DASH with segment duration in seconds (default " << defaultHlsSegment << ")" << std::endl; - std::cout << "\t -x : enable RTSPS & SRTP" << std::endl; - std::cout << "\t -X : disable SRTP" << std::endl; + std::cout << "\t -x : enable SRTP" << std::endl; + std::cout << "\t -X : enable RTSPS" << std::endl; std::cout << "\t V4L2 options" << std::endl; std::cout << "\t -r : V4L2 capture using read interface (default use memory mapped buffers)" << std::endl; @@ -253,7 +253,7 @@ int main(int argc, char** argv) // create RTSP server - V4l2RTSPServer rtspServer(rtspPort, rtspOverHTTPPort, timeout, hlsSegment, userPasswordList, realm, webroot, sslKeyCert, weServeSRTP); + V4l2RTSPServer rtspServer(rtspPort, rtspOverHTTPPort, timeout, hlsSegment, userPasswordList, realm, webroot, sslKeyCert, enableRTSPS); if (!rtspServer.available()) { LOG(ERROR) << "Failed to create RTSP server: " << rtspServer.getResultMsg(); diff --git a/src/HTTPServer.cpp b/src/HTTPServer.cpp index b4895a0..52b44ab 100644 --- a/src/HTTPServer.cpp +++ b/src/HTTPServer.cpp @@ -16,8 +16,6 @@ #include #include -#include "RTSPServer.hh" -#include "RTSPCommon.hh" #include #include "ByteStreamMemoryBufferSource.hh" diff --git a/src/V4l2RTSPServer.cpp b/src/V4l2RTSPServer.cpp index fb33f28..3ad272a 100644 --- a/src/V4l2RTSPServer.cpp +++ b/src/V4l2RTSPServer.cpp @@ -16,8 +16,8 @@ #include "logger.h" #include "V4l2Capture.h" #include "V4l2Output.h" -#include "DeviceSourceFactory.h" #include "V4l2RTSPServer.h" +#include "DeviceSourceFactory.h" #include "VideoCaptureAccess.h" #ifdef HAVE_ALSA