Skip to content

Commit

Permalink
HLS fmp4 support hls_ctx.
Browse files Browse the repository at this point in the history
  • Loading branch information
suzp1984 committed Sep 3, 2024
1 parent bf029ed commit 96cd36a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
8 changes: 6 additions & 2 deletions trunk/conf/hls.mp4.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ http_server {
listen 8080;
dir ./objs/nginx/html;
}
http_api {
enabled on;
listen 1985;
}
vhost __defaultVhost__ {
hls {
enabled on;
hls_use_fmp4 on;
hls_path ./objs/nginx/html;
hls_fragment 10;
hls_window 60;
hls_fragment 2;
hls_window 10;
}
}
1 change: 1 addition & 0 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,7 @@ class SrsConfig
// Whether enable hls_ctx
virtual bool get_hls_ctx_enabled(std::string vhost);
// 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);
// hds section
private:
Expand Down
1 change: 1 addition & 0 deletions trunk/src/app/srs_app_http_static.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class SrsVodStream : public SrsHttpFileServer
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.
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);
};

Expand Down
10 changes: 6 additions & 4 deletions trunk/src/protocol/srs_protocol_http_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,15 @@ srs_error_t SrsHttpFileServer::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMes
// use vod stream for .flv/.fhv
if (srs_string_ends_with(fullpath, ".flv") || srs_string_ends_with(fullpath, ".fhv")) {
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);
} 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);
}
} else if (srs_string_ends_with(fullpath, ".mp4")) {
return serve_mp4_file(w, r, fullpath);
}

// serve common static file.
return serve_file(w, r, fullpath);
Expand Down
2 changes: 2 additions & 0 deletions trunk/src/protocol/srs_protocol_http_stack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ class SrsHttpFileServer : public ISrsHttpHandler
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);
// the ts file including: .ts .m4s init.mp4
virtual srs_error_t serve_ts_file(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath);
protected:
// When access flv file with x.flv?start=xxx
Expand All @@ -371,6 +372,7 @@ class SrsHttpFileServer : public ISrsHttpHandler
// 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);
// the ts file including: .ts .m4s init.mp4
virtual srs_error_t serve_ts_ctx(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string fullpath);
protected:
// Copy the fs to response writer in size bytes.
Expand Down

0 comments on commit 96cd36a

Please sign in to comment.