Skip to content

Commit

Permalink
allow to use rtsps without srtp
Browse files Browse the repository at this point in the history
  • Loading branch information
mpromonet committed Sep 18, 2024
1 parent 410c0d4 commit 6ad2458
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
13 changes: 7 additions & 6 deletions inc/HTTPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,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)
static HTTPServer* createNew(UsageEnvironment& env, Port rtspPort, UserAuthenticationDatabase* authDatabase, unsigned reclamationTestSeconds, unsigned int hlsSegment, const std::string & webroot, const std::string & sslCert, bool weServeSRTP)
{
HTTPServer* httpServer = NULL;
#if LIVEMEDIA_LIBRARY_VERSION_INT < 1610928000
Expand All @@ -178,25 +178,25 @@ class HTTPServer : public RTSPServer

if (ourSocketIPv4 != -1)
{
httpServer = new HTTPServer(env, ourSocketIPv4, ourSocketIPv6, rtspPort, authDatabase, reclamationTestSeconds, hlsSegment, webroot, sslCert);
httpServer = new HTTPServer(env, ourSocketIPv4, ourSocketIPv6, rtspPort, authDatabase, reclamationTestSeconds, hlsSegment, webroot, sslCert, weServeSRTP);
}
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)
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, 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)
: RTSPServer(env, ourSocketIPv4, ourSocketIPv6, rtspPort, authDatabase, reclamationTestSeconds), m_hlsSegment(hlsSegment), m_webroot(webroot), m_sslCert(sslCert)
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)
#endif
{
if ( (!m_webroot.empty()) && (*m_webroot.rend() != '/') ) {
m_webroot += "/";
}
#if LIVEMEDIA_LIBRARY_VERSION_INT >= 1642723200
if (this->isSSL()) {
this->setTLSState(m_sslCert.c_str(), m_sslCert.c_str(), true, true);
this->setTLSState(m_sslCert.c_str(), m_sslCert.c_str(), m_weServeSRTP);
}
#endif
}
Expand All @@ -216,5 +216,6 @@ class HTTPServer : public RTSPServer
const unsigned int m_hlsSegment;
std::string m_webroot;
std::string m_sslCert;
bool m_weServeSRTP;
};

4 changes: 2 additions & 2 deletions inc/V4l2RTSPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

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 = "")
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)
: 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);
m_rtspServer = HTTPServer::createNew(*m_env, rtspPort, auth, timeout, hlsSegment, webroot, sslkeycert, weServeSRTP);
if (m_rtspServer != NULL)
{
if (rtspOverHTTPPort)
Expand Down
31 changes: 17 additions & 14 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ int main(int argc, char** argv)
int defaultHlsSegment = 2;
unsigned int hlsSegment = 0;
std::string sslKeyCert;
bool weServeSRTP = true;
const char* realm = NULL;
std::list<std::string> userPasswordList;
std::string webroot;
Expand All @@ -113,7 +114,7 @@ int main(int argc, char** argv)

// decode parameters
int c = 0;
while ((c = getopt (argc, argv, "v::Q:O:b:" "I:P:p:m::u:M::ct:S::x:" "R:U:" "rwBsf::F:W:H:G:" "A:C:a:" "Vh")) != -1)
while ((c = getopt (argc, argv, "v::Q:O:b:" "I:P:p:m::u:M::ct:S::x:X" "R:U:" "rwBsf::F:W:H:G:" "A:C:a:" "Vh")) != -1)
{
switch (c)
{
Expand All @@ -134,6 +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;
#endif

// users
Expand Down Expand Up @@ -170,28 +172,29 @@ int main(int argc, char** argv)
{
std::cout << argv[0] << " [-v[v]] [-Q queueSize] [-O file]" << std::endl;
std::cout << "\t [-I interface] [-P RTSP port] [-p RTSP/HTTP port] [-m multicast url] [-u unicast url] [-M multicast addr] [-c] [-t timeout] [-T] [-S[duration]]" << std::endl;
std::cout << "\t [-r] [-w] [-s] [-f[format] [-W width] [-H height] [-F fps] [device] [device]" << std::endl;
std::cout << "\t [-r] [-w] [-s] [-f[format] [-W width] [-H height] [-F fps] [device] [device]" << std::endl;
std::cout << "\t -v : verbose" << std::endl;
std::cout << "\t -vv : very verbose" << std::endl;
std::cout << "\t -Q <length> : Number of frame queue (default "<< queueSize << ")" << std::endl;
std::cout << "\t -O <output> : Copy captured frame to a file or a V4L2 device" << std::endl;
std::cout << "\t -b <webroot> : path to webroot" << std::endl;

std::cout << "\t RTSP/RTP options" << std::endl;
std::cout << "\t RTSP/RTP options" << std::endl;
std::cout << "\t -I <addr> : RTSP interface (default autodetect)" << std::endl;
std::cout << "\t -P <port> : RTSP port (default "<< rtspPort << ")" << std::endl;
std::cout << "\t -p <port> : RTSP over HTTP port (default "<< rtspOverHTTPPort << ")" << std::endl;
std::cout << "\t -U <user>:<pass> : RTSP user and password" << std::endl;
std::cout << "\t -U <user>:<pass> : RTSP user and password" << std::endl;
std::cout << "\t -R <realm> : use md5 password 'md5(<username>:<realm>:<password>')" << std::endl;
std::cout << "\t -u <url> : unicast url (default " << url << ")" << std::endl;
std::cout << "\t -m <url> : multicast url (default " << murl << ")" << std::endl;
std::cout << "\t -M <addr> : multicast group:port (default is random_address:20000)" << std::endl;
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 -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 V4L2 options" << 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;
std::cout << "\t -w : V4L2 capture using write interface (default use memory mapped buffers)" << std::endl;
std::cout << "\t -B : V4L2 capture using blocking mode (default use non-blocking mode)" << std::endl;
Expand All @@ -204,14 +207,14 @@ int main(int argc, char** argv)
std::cout << "\t -G <w>x<h>[x<f>] : V4L2 capture format (default "<< width << "x" << height << "x" << fps << ")" << std::endl;

#ifdef HAVE_ALSA
std::cout << "\t ALSA options" << std::endl;
std::cout << "\t -A freq : ALSA capture frequency and channel (default " << audioFreq << ")" << std::endl;
std::cout << "\t -C channels : ALSA capture channels (default " << audioNbChannels << ")" << std::endl;
std::cout << "\t -a fmt : ALSA capture audio format (default S16_BE)" << std::endl;
std::cout << "\t ALSA options" << std::endl;
std::cout << "\t -A freq : ALSA capture frequency and channel (default " << audioFreq << ")" << std::endl;
std::cout << "\t -C channels : ALSA capture channels (default " << audioNbChannels << ")" << std::endl;
std::cout << "\t -a fmt : ALSA capture audio format (default S16_BE)" << std::endl;
#endif

std::cout << "\t Devices :" << std::endl;
std::cout << "\t [V4L2 device][,ALSA device] : V4L2 capture device or/and ALSA capture device (default "<< dev_name << ")" << std::endl;
std::cout << "\t Devices :" << std::endl;
std::cout << "\t [V4L2 device][,ALSA device] : V4L2 capture device or/and ALSA capture device (default "<< dev_name << ")" << std::endl;
exit(0);
}
}
Expand Down Expand Up @@ -250,7 +253,7 @@ int main(int argc, char** argv)


// create RTSP server
V4l2RTSPServer rtspServer(rtspPort, rtspOverHTTPPort, timeout, hlsSegment, userPasswordList, realm, webroot, sslKeyCert);
V4l2RTSPServer rtspServer(rtspPort, rtspOverHTTPPort, timeout, hlsSegment, userPasswordList, realm, webroot, sslKeyCert, weServeSRTP);
if (!rtspServer.available())
{
LOG(ERROR) << "Failed to create RTSP server: " << rtspServer.getResultMsg();
Expand Down

0 comments on commit 6ad2458

Please sign in to comment.