add an HTTP api to get the list of streams and return this list when RTSP server doesnot know a stream

pull/59/merge
mpromonet 7 years ago
parent f103443c2b
commit b4c3a2c3a5

@ -37,6 +37,7 @@ class HTTPServer : public RTSPServer
bool sendM3u8PlayList(char const* urlSuffix);
bool sendMpdPlayList(char const* urlSuffix);
virtual void handleHTTPCmd_StreamingGET(char const* urlSuffix, char const* fullRequestStr);
virtual void handleCmd_notFound();
static void afterStreaming(void* clientData);
private:

@ -1,6 +1,8 @@
<html>
<link rel="shortcut icon" href="about:blank"/>
<body>
<!--fill streamList variable with the list of streams -->
<script src="/getStreamList?streamList" ></script>
<h3>HLS</h3>
<video controls id="hlsvideo"></video>
<script src="https://cdn.jsdelivr.net/hls.js/latest/hls.min.js" ></script>
@ -8,11 +10,20 @@
if (Hls.isSupported()) {
var video = document.getElementById("hlsvideo");
var hls = new Hls();
hls.loadSource("unicast.m3u8");
hls.loadSource(streamList[0]+".m3u8");
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, function() { video.play(); });
} else {
document.write("HLS not supported");
}
</script>
<h3>MPEG-DASH</h3>
<video controls id="dashvideo"></video>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dashjs/2.5.0/dash.all.min.js" ></script>
<script>
var player = new dashjs.MediaPlayer().create();
player.initialize(document.getElementById("dashvideo"),streamList[0]+".mpd",true);
</script>
</body>
</html>

@ -162,7 +162,36 @@ bool HTTPServer::HTTPClientConnection::sendMpdPlayList(char const* urlSuffix)
void HTTPServer::HTTPClientConnection::handleHTTPCmd_StreamingGET(char const* urlSuffix, char const* /*fullRequestStr*/)
{
char const* questionMarkPos = strrchr(urlSuffix, '?');
if (questionMarkPos == NULL)
if (strncmp(urlSuffix, "getStreamList", strlen("getStreamList")) == 0)
{
std::ostringstream os;
ServerMediaSessionIterator it(fOurServer);
ServerMediaSession* serverSession = NULL;
if (questionMarkPos != NULL) {
questionMarkPos++;
os << "var " << questionMarkPos << "=";
}
os << "[\n";
bool first = true;
while ( (serverSession = it.next()) != NULL) {
if (first)
{
first = false;
os << " ";
}
else
{
os << ",";
}
os << "\"" << serverSession->streamName() << "\"";
os << "\n";
}
os << "]\n";
std::string content(os.str());
this->sendHeader("text/plain", content.size());
this->streamSource(ByteStreamMemoryBufferSource::createNew(envir(), (u_int8_t*)content.c_str(), content.size()));
}
else if (questionMarkPos == NULL)
{
std::string streamName(urlSuffix);
std::string ext;
@ -266,6 +295,17 @@ void HTTPServer::HTTPClientConnection::handleHTTPCmd_StreamingGET(char const* ur
}
}
void HTTPServer::HTTPClientConnection::handleCmd_notFound() {
std::ostringstream os;
ServerMediaSessionIterator it(fOurServer);
ServerMediaSession* serverSession = NULL;
while ( (serverSession = it.next()) != NULL) {
os << serverSession->streamName() << "\n";
}
setRTSPResponse("404 Stream Not Found", os.str().c_str());
}
void HTTPServer::HTTPClientConnection::afterStreaming(void* clientData)
{
HTTPServer::HTTPClientConnection* clientConnection = (HTTPServer::HTTPClientConnection*)clientData;

Loading…
Cancel
Save