HLS fmp4 support hls_ctx.

pull/4159/head
Jacob Su 6 months ago
parent bf029ed564
commit 96cd36afd4

@ -11,12 +11,16 @@ http_server {
listen 8080; listen 8080;
dir ./objs/nginx/html; dir ./objs/nginx/html;
} }
http_api {
enabled on;
listen 1985;
}
vhost __defaultVhost__ { vhost __defaultVhost__ {
hls { hls {
enabled on; enabled on;
hls_use_fmp4 on; hls_use_fmp4 on;
hls_path ./objs/nginx/html; hls_path ./objs/nginx/html;
hls_fragment 10; hls_fragment 2;
hls_window 60; hls_window 10;
} }
} }

@ -989,6 +989,7 @@ public:
// Whether enable hls_ctx // Whether enable hls_ctx
virtual bool get_hls_ctx_enabled(std::string vhost); virtual bool get_hls_ctx_enabled(std::string vhost);
// Whether enable session for ts file. // Whether enable session for ts file.
// The ts file including .ts file for MPEG-ts segment, .m4s file and init.mp4 file for fmp4 segment.
virtual bool get_hls_ts_ctx_enabled(std::string vhost); virtual bool get_hls_ts_ctx_enabled(std::string vhost);
// hds section // hds section
private: private:

@ -74,6 +74,7 @@ protected:
virtual srs_error_t serve_mp4_stream(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath, int64_t start, int64_t end); virtual srs_error_t serve_mp4_stream(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath, int64_t start, int64_t end);
// Support HLS streaming with pseudo session id. // Support HLS streaming with pseudo session id.
virtual srs_error_t serve_m3u8_ctx(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath); virtual srs_error_t serve_m3u8_ctx(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath);
// the ts file including: .ts .m4s init.mp4
virtual srs_error_t serve_ts_ctx(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath); virtual srs_error_t serve_ts_ctx(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath);
}; };

@ -405,13 +405,15 @@ srs_error_t SrsHttpFileServer::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMes
// use vod stream for .flv/.fhv // use vod stream for .flv/.fhv
if (srs_string_ends_with(fullpath, ".flv") || srs_string_ends_with(fullpath, ".fhv")) { if (srs_string_ends_with(fullpath, ".flv") || srs_string_ends_with(fullpath, ".fhv")) {
return serve_flv_file(w, r, fullpath); 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")) { } else if (srs_string_ends_with(upath, ".m3u8")) {
return serve_m3u8_file(w, r, fullpath); return serve_m3u8_file(w, r, fullpath);
} else if (srs_string_ends_with(upath, ".ts")) { } else if (srs_string_ends_with(upath, ".ts") ||
srs_string_ends_with(upath, ".m4s") ||
srs_path_basename(upath) == "init.mp4") {
return serve_ts_file(w, r, fullpath); return serve_ts_file(w, r, fullpath);
} } else if (srs_string_ends_with(fullpath, ".mp4")) {
return serve_mp4_file(w, r, fullpath);
}
// serve common static file. // serve common static file.
return serve_file(w, r, fullpath); return serve_file(w, r, fullpath);

@ -352,6 +352,7 @@ private:
virtual srs_error_t serve_flv_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_mp4_file(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath);
virtual srs_error_t serve_m3u8_file(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath); virtual srs_error_t serve_m3u8_file(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath);
// the ts file including: .ts .m4s init.mp4
virtual srs_error_t serve_ts_file(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath); virtual srs_error_t serve_ts_file(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath);
protected: protected:
// When access flv file with x.flv?start=xxx // When access flv file with x.flv?start=xxx
@ -371,6 +372,7 @@ protected:
// Remark 2: // Remark 2:
// If use two same "hls_ctx" in different requests, SRS cannot detect so that they will be treated as one. // 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); virtual srs_error_t serve_m3u8_ctx(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath);
// the ts file including: .ts .m4s init.mp4
virtual srs_error_t serve_ts_ctx(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath); virtual srs_error_t serve_ts_ctx(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath);
protected: protected:
// Copy the fs to response writer in size bytes. // Copy the fs to response writer in size bytes.

Loading…
Cancel
Save