v4l2rtspserver/inc/HTTPServer.h

77 lines
2.8 KiB
C
Raw Normal View History

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);
bool sendM3u8PlayList(char const* urlSuffix);
bool sendMpdPlayList(char const* urlSuffix);
virtual void handleHTTPCmd_StreamingGET(char const* urlSuffix, char const* fullRequestStr);
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:
static HTTPServer* createNew(UsageEnvironment& env, Port rtspPort, UserAuthenticationDatabase* authDatabase, unsigned reclamationTestSeconds, unsigned int hlsSegment)
{
HTTPServer* httpServer = NULL;
int ourSocket = setUpOurSocket(env, rtspPort);
if (ourSocket != -1)
{
httpServer = new HTTPServer(env, ourSocket, rtspPort, authDatabase, reclamationTestSeconds, hlsSegment);
}
return httpServer;
}
HTTPServer(UsageEnvironment& env, int ourSocket, Port rtspPort, UserAuthenticationDatabase* authDatabase, unsigned reclamationTestSeconds, unsigned int hlsSegment)
: RTSPServer(env, ourSocket, rtspPort, authDatabase, reclamationTestSeconds), m_hlsSegment(hlsSegment)
{
}
RTSPServer::RTSPClientConnection* createNewClientConnection(int clientSocket, struct sockaddr_in clientAddr)
{
return new HTTPClientConnection(*this, clientSocket, clientAddr);
}
const unsigned int m_hlsSegment;
};