使用 Live555 HTTP 能力作为信令服务器

Using Live555 HTTP capacities as a server for signaling

最近我设法(使用其他库)使用 Live555、WebRTC 和 FFMPEG 制作了一个 rtsp 流媒体服务器。 一切都很好,但我的最终目标是最大限度地使用 Live555 以减少我的处理足迹。 rtp 流启动后,我仅将 HTTP 信令服务器用于保活。

我的问题是(因为我似乎没有在 live555 代码和文档中找到答案):

有什么方法可以仅使用 Live555 构建 HTTP 服务器吗?

在 live555 中有一个嵌入式 HTTP 服务器,用于通过 HTTP 流式传输 RTP。

您可以使用它重载 RTSPServer::RTSPClientConnection

handleHTTPCmd_StreamingGET

为了实现您的 GET 实现,您需要:

  • 重载 RTSPServer::RTSPClientConnection class 实施 handleHTTPCmd_StreamingGET
  • 重载 RTSPServer class 以实例化 RTSPServer::RTSPClientConnection
  • 的重载 class

将所有内容放在一起可以得到一个非常简单的示例,没有错误处理,例如:

#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);
        }
};

此 HTTPServer 实现使用它收到的 http 请求进行应答,类似于:

GET / HTTP/1.1
Host: 127.0.0.1:9999
User-Agent: curl/7.54.0
Accept: */*