allow srtp using rtsp

This commit is contained in:
Michel Promonet 2024-09-19 11:28:11 +02:00
parent 6ad245806c
commit 85f6e8dcb9
6 changed files with 84 additions and 21 deletions

57
.vscode/settings.json vendored Normal file
View File

@ -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"
}
}

View File

@ -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 <GroupsockHelper.hh> // 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;
};

View File

@ -17,20 +17,20 @@
#include <BasicUsageEnvironment.hh>
#include <GroupsockHelper.hh>
#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<std::string> & userPasswordList = std::list<std::string>(), 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<std::string> & userPasswordList = std::list<std::string>(), 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)

View File

@ -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<std::string> 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 <timeout> : RTCP expiration timeout in seconds (default " << timeout << ")" << std::endl;
std::cout << "\t -S[<duration>] : enable HLS & MPEG-DASH with segment duration in seconds (default " << defaultHlsSegment << ")" << std::endl;
std::cout << "\t -x <sslkeycert> : enable RTSPS & SRTP" << std::endl;
std::cout << "\t -X : disable SRTP" << std::endl;
std::cout << "\t -x <sslkeycert> : 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();

View File

@ -16,8 +16,6 @@
#include <fstream>
#include <algorithm>
#include "RTSPServer.hh"
#include "RTSPCommon.hh"
#include <time.h>
#include "ByteStreamMemoryBufferSource.hh"

View File

@ -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