2016-05-05 14:32:40 +00:00
|
|
|
/* ---------------------------------------------------------------------------
|
|
|
|
** This software is in the public domain, furnished "as is", without technical
|
|
|
|
** support, and with no warranty, express or implied, as to its usefulness for
|
|
|
|
** any purpose.
|
|
|
|
**
|
|
|
|
** HTTPServer.h
|
|
|
|
**
|
|
|
|
** V4L2 RTSP streamer
|
|
|
|
**
|
|
|
|
** HTTP server that serves HLS & MPEG-DASH playlist and segments
|
|
|
|
**
|
|
|
|
** -------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "RTSPServer.hh"
|
|
|
|
#include "RTSPCommon.hh"
|
|
|
|
|
|
|
|
// ---------------------------------------------------------
|
|
|
|
// Extend RTSP server to add support for HLS and MPEG-DASH
|
|
|
|
// ---------------------------------------------------------
|
|
|
|
class HTTPServer : public RTSPServer
|
|
|
|
{
|
|
|
|
|
|
|
|
class HTTPClientConnection : public RTSPServer::RTSPClientConnection
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
HTTPClientConnection(RTSPServer& ourServer, int clientSocket, struct sockaddr_in clientAddr)
|
2017-10-28 14:20:53 +00:00
|
|
|
: RTSPServer::RTSPClientConnection(ourServer, clientSocket, clientAddr), fTCPSink(NULL), fStreamToken(NULL), fSubsession(NULL), fSource(NULL) {
|
2016-05-05 14:32:40 +00:00
|
|
|
}
|
2016-06-04 17:37:07 +00:00
|
|
|
virtual ~HTTPClientConnection();
|
2016-05-05 14:32:40 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void sendHeader(const char* contentType, unsigned int contentLength);
|
2017-09-03 19:25:29 +00:00
|
|
|
void streamSource(FramedSource* source);
|
|
|
|
void streamSource(const std::string & content);
|
2016-05-05 14:32:40 +00:00
|
|
|
ServerMediaSubsession* getSubsesion(const char* urlSuffix);
|
2018-12-08 20:34:23 +00:00
|
|
|
bool sendFile(char const* urlSuffix);
|
2016-05-21 17:02:54 +00:00
|
|
|
bool sendM3u8PlayList(char const* urlSuffix);
|
|
|
|
bool sendMpdPlayList(char const* urlSuffix);
|
|
|
|
virtual void handleHTTPCmd_StreamingGET(char const* urlSuffix, char const* fullRequestStr);
|
2017-09-03 15:44:33 +00:00
|
|
|
virtual void handleCmd_notFound();
|
2016-05-05 14:32:40 +00:00
|
|
|
static void afterStreaming(void* clientData);
|
|
|
|
|
|
|
|
private:
|
2017-10-28 14:20:53 +00:00
|
|
|
static u_int32_t fClientSessionId;
|
2016-05-05 14:32:40 +00:00
|
|
|
TCPStreamSink* fTCPSink;
|
2017-10-28 14:20:53 +00:00
|
|
|
void* fStreamToken;
|
|
|
|
ServerMediaSubsession* fSubsession;
|
|
|
|
FramedSource* fSource;
|
2016-05-05 14:32:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2019-03-30 22:06:24 +00:00
|
|
|
static HTTPServer* createNew(UsageEnvironment& env, Port rtspPort, UserAuthenticationDatabase* authDatabase, unsigned reclamationTestSeconds, unsigned int hlsSegment, const std::string webroot)
|
2016-05-05 14:32:40 +00:00
|
|
|
{
|
|
|
|
HTTPServer* httpServer = NULL;
|
|
|
|
int ourSocket = setUpOurSocket(env, rtspPort);
|
|
|
|
if (ourSocket != -1)
|
|
|
|
{
|
2019-03-30 22:06:24 +00:00
|
|
|
httpServer = new HTTPServer(env, ourSocket, rtspPort, authDatabase, reclamationTestSeconds, hlsSegment, webroot);
|
2016-05-05 14:32:40 +00:00
|
|
|
}
|
|
|
|
return httpServer;
|
|
|
|
}
|
|
|
|
|
2019-03-30 22:06:24 +00:00
|
|
|
HTTPServer(UsageEnvironment& env, int ourSocket, Port rtspPort, UserAuthenticationDatabase* authDatabase, unsigned reclamationTestSeconds, unsigned int hlsSegment, const std::string & webroot)
|
|
|
|
: RTSPServer(env, ourSocket, rtspPort, authDatabase, reclamationTestSeconds), m_hlsSegment(hlsSegment), m_webroot(webroot)
|
2016-05-05 14:32:40 +00:00
|
|
|
{
|
2019-03-30 23:02:07 +00:00
|
|
|
if ( (!m_webroot.empty()) && (*m_webroot.rend() != '/') ) {
|
|
|
|
m_webroot += "/";
|
|
|
|
}
|
2016-05-05 14:32:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RTSPServer::RTSPClientConnection* createNewClientConnection(int clientSocket, struct sockaddr_in clientAddr)
|
|
|
|
{
|
|
|
|
return new HTTPClientConnection(*this, clientSocket, clientAddr);
|
|
|
|
}
|
|
|
|
|
2019-03-30 22:06:24 +00:00
|
|
|
private:
|
2016-05-05 14:32:40 +00:00
|
|
|
const unsigned int m_hlsSegment;
|
2019-03-30 22:06:24 +00:00
|
|
|
std::string m_webroot;
|
2016-05-05 14:32:40 +00:00
|
|
|
};
|
|
|
|
|