mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Enhance HLS: support http callback on_play/stop, support statistic (#2578)
* Enhance HLS: support http callback on_play/stop, support statistic * make code readable * make code readable * rename secret
This commit is contained in:
parent
40f8460929
commit
f901831362
7 changed files with 277 additions and 5 deletions
|
@ -364,7 +364,7 @@ srs_error_t SrsHttpFileServer::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMes
|
|||
|
||||
string upath = r->path();
|
||||
string fullpath = srs_http_fs_fullpath(dir, entry->pattern, upath);
|
||||
|
||||
|
||||
// stat current dir, if exists, return error.
|
||||
if (!_srs_path_exists(fullpath)) {
|
||||
srs_warn("http miss file=%s, pattern=%s, upath=%s",
|
||||
|
@ -380,6 +380,8 @@ srs_error_t SrsHttpFileServer::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMes
|
|||
return serve_flv_file(w, r, fullpath);
|
||||
} else if (srs_string_ends_with(fullpath, ".mp4")) {
|
||||
return serve_mp4_file(w, r, fullpath);
|
||||
} else if (srs_string_ends_with(upath, ".m3u8")) {
|
||||
return serve_m3u8_file(w, r, fullpath);
|
||||
}
|
||||
|
||||
// serve common static file.
|
||||
|
@ -522,6 +524,11 @@ srs_error_t SrsHttpFileServer::serve_mp4_file(ISrsHttpResponseWriter* w, ISrsHtt
|
|||
}
|
||||
|
||||
return serve_mp4_stream(w, r, fullpath, start, end);
|
||||
}
|
||||
|
||||
srs_error_t SrsHttpFileServer::serve_m3u8_file(ISrsHttpResponseWriter * w, ISrsHttpMessage * r, std::string fullpath)
|
||||
{
|
||||
return serve_m3u8_ctx(w, r, fullpath);
|
||||
}
|
||||
|
||||
srs_error_t SrsHttpFileServer::serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, string fullpath, int offset)
|
||||
|
@ -536,6 +543,13 @@ srs_error_t SrsHttpFileServer::serve_mp4_stream(ISrsHttpResponseWriter* w, ISrsH
|
|||
// @remark For common http file server, we don't support stream request, please use SrsVodStream instead.
|
||||
// TODO: FIXME: Support range in header https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Range_requests
|
||||
return serve_file(w, r, fullpath);
|
||||
}
|
||||
|
||||
srs_error_t SrsHttpFileServer::serve_m3u8_ctx(ISrsHttpResponseWriter * w, ISrsHttpMessage * r, std::string fullpath)
|
||||
{
|
||||
// @remark For common http file server, we don't support stream request, please use SrsVodStream instead.
|
||||
// TODO: FIXME: Support range in header https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Range_requests
|
||||
return serve_file(w, r, fullpath);
|
||||
}
|
||||
|
||||
srs_error_t SrsHttpFileServer::copy(ISrsHttpResponseWriter* w, SrsFileReader* fs, ISrsHttpMessage* r, int size)
|
||||
|
|
|
@ -285,6 +285,7 @@ private:
|
|||
virtual srs_error_t serve_file(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath);
|
||||
virtual srs_error_t serve_flv_file(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath);
|
||||
virtual srs_error_t serve_mp4_file(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath);
|
||||
virtual srs_error_t serve_m3u8_file(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath);
|
||||
protected:
|
||||
// When access flv file with x.flv?start=xxx
|
||||
virtual srs_error_t serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath, int offset);
|
||||
|
@ -293,6 +294,16 @@ protected:
|
|||
// @param end the end offset in bytes. -1 to end of file.
|
||||
// @remark response data in [start, end].
|
||||
virtual srs_error_t serve_mp4_stream(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath, int start, int end);
|
||||
// For HLS protocol.
|
||||
// When the request url, like as "http://127.0.0.1:8080/live/livestream.m3u8",
|
||||
// returns the response like as "http://127.0.0.1:8080/live/livestream.m3u8?hls_ctx=12345678" .
|
||||
// SRS use "hls_ctx" to keep track of subsequent requests that is short-connection.
|
||||
// Remark 1:
|
||||
// Fill the parameter "hls_ctx" by yourself in the first request is allowed, SRS will use it.
|
||||
// And MUST make sure it is unique.
|
||||
// Remark 2:
|
||||
// If use two same "hls_ctx" in different requests, SRS cannot detect so that they will be treated as one.
|
||||
virtual srs_error_t serve_m3u8_ctx(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath);
|
||||
protected:
|
||||
// Copy the fs to response writer in size bytes.
|
||||
virtual srs_error_t copy(ISrsHttpResponseWriter* w, SrsFileReader* fs, ISrsHttpMessage* r, int size);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue