In live555 there is an embededed HTTP server that is used for streaming RTP over HTTP.
You can use it overloading the handleHTTPCmd_StreamingGET
of RTSPServer::RTSPClientConnection
In order to implement your GET implementation, you need to :
- overload RTSPServer::RTSPClientConnection class to implement handleHTTPCmd_StreamingGET
- overload RTSPServer class to instanciate your overloaded class of RTSPServer::RTSPClientConnection
Putting everything together could give a very simplify sample, without error handling, like :
#include "BasicUsageEnvironment.hh"
#include "RTSPServer.hh"
class HTTPServer : public RTSPServer {
class HTTPClientConnection : public RTSPServer::RTSPClientConnection {
public:
HTTPClientConnection(RTSPServer& ourServer, int clientSocket, struct sockaddr_in clientAddr)
: RTSPServer::RTSPClientConnection(ourServer, clientSocket, clientAddr) {}
private:
virtual void handleHTTPCmd_StreamingGET(char const* urlSuffix, char const* fullRequestStr) {
// build HTTP answer
snprintf((char*)fResponseBuffer, sizeof fResponseBuffer,
"HTTP/1.1 200 OK\r\n"
"Content-Length: %zd\r\n"
"\r\n"
"%s",
strlen(fullRequestStr),fullRequestStr);
}
};
public:
static HTTPServer* createNew(UsageEnvironment& env, Port rtspPort) {
return new HTTPServer(env, setUpOurSocket(env, rtspPort), rtspPort);
}
HTTPServer(UsageEnvironment& env, int ourSocket, Port rtspPort)
: RTSPServer(env, ourSocket, rtspPort, NULL, 0) {}
RTSPServer::RTSPClientConnection* createNewClientConnection(int clientSocket, struct sockaddr_in clientAddr) {
return new HTTPClientConnection(*this, clientSocket, clientAddr);
}
};
This HTTPServer implementation answer with the http request it received, something like :
GET / HTTP/1.1
Host: 127.0.0.1:9999
User-Agent: curl/7.54.0
Accept: */*