mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
for #324, refine code, add hstrs config.
This commit is contained in:
parent
2adc069df0
commit
6d15d0ea99
15 changed files with 97 additions and 50 deletions
|
@ -1471,7 +1471,7 @@ int SrsConfig::check_config()
|
|||
} else if (n == "http_remux") {
|
||||
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
||||
string m = conf->at(j)->name.c_str();
|
||||
if (m != "enabled" && m != "mount" && m != "fast_cache") {
|
||||
if (m != "enabled" && m != "mount" && m != "fast_cache" && m != "crss") {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("unsupported vhost http_remux directive %s, ret=%d", m.c_str(), ret);
|
||||
return ret;
|
||||
|
@ -3751,6 +3751,30 @@ string SrsConfig::get_vhost_http_remux_mount(string vhost)
|
|||
return conf->arg0();
|
||||
}
|
||||
|
||||
bool SrsConfig::get_vhost_http_remux_hstrs(string vhost)
|
||||
{
|
||||
SrsConfDirective* conf = get_vhost(vhost);
|
||||
if (!conf) {
|
||||
return false;
|
||||
}
|
||||
|
||||
conf = conf->get("http_remux");
|
||||
if (!conf) {
|
||||
return false;
|
||||
}
|
||||
|
||||
conf = conf->get("hstrs");
|
||||
if (!conf) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (conf->arg0() == "on") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
SrsConfDirective* SrsConfig::get_heartbeart()
|
||||
{
|
||||
return root->get("heartbeat");
|
||||
|
|
|
@ -1041,6 +1041,10 @@ public:
|
|||
* used to generate the flv stream mount path.
|
||||
*/
|
||||
virtual std::string get_vhost_http_remux_mount(std::string vhost);
|
||||
/**
|
||||
* get whether the hstrs(http stream trigger rtmp source) enabled.
|
||||
*/
|
||||
virtual bool get_vhost_http_remux_hstrs(std::string vhost);
|
||||
// http heartbeart section
|
||||
private:
|
||||
/**
|
||||
|
|
|
@ -1269,9 +1269,9 @@ int SrsHttpParser::parse_message(SrsStSocket* skt, SrsHttpMessage** ppmsg)
|
|||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// reset request data.
|
||||
filed_name = "";
|
||||
field_name = "";
|
||||
field_value = "";
|
||||
expect_filed_name = true;
|
||||
expect_field_name = true;
|
||||
state = SrsHttpParseStateInit;
|
||||
header = http_parser();
|
||||
url = "";
|
||||
|
@ -1339,8 +1339,8 @@ int SrsHttpParser::parse_message_imp(SrsStSocket* skt)
|
|||
}
|
||||
|
||||
// parse last header.
|
||||
if (!filed_name.empty() && !field_value.empty()) {
|
||||
headers.push_back(std::make_pair(filed_name, field_value));
|
||||
if (!field_name.empty() && !field_value.empty()) {
|
||||
headers.push_back(std::make_pair(field_name, field_value));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -1406,17 +1406,17 @@ int SrsHttpParser::on_header_field(http_parser* parser, const char* at, size_t l
|
|||
srs_assert(obj);
|
||||
|
||||
// field value=>name, reap the field.
|
||||
if (!obj->expect_filed_name) {
|
||||
obj->headers.push_back(std::make_pair(obj->filed_name, obj->field_value));
|
||||
if (!obj->expect_field_name) {
|
||||
obj->headers.push_back(std::make_pair(obj->field_name, obj->field_value));
|
||||
|
||||
// reset the field name when parsed.
|
||||
obj->filed_name = "";
|
||||
obj->field_name = "";
|
||||
obj->field_value = "";
|
||||
}
|
||||
obj->expect_filed_name = true;
|
||||
obj->expect_field_name = true;
|
||||
|
||||
if (length > 0) {
|
||||
obj->filed_name.append(at, (int)length);
|
||||
obj->field_name.append(at, (int)length);
|
||||
}
|
||||
|
||||
srs_info("Header field(%d bytes): %.*s", (int)length, (int)length, at);
|
||||
|
@ -1431,7 +1431,7 @@ int SrsHttpParser::on_header_value(http_parser* parser, const char* at, size_t l
|
|||
if (length > 0) {
|
||||
obj->field_value.append(at, (int)length);
|
||||
}
|
||||
obj->expect_filed_name = false;
|
||||
obj->expect_field_name = false;
|
||||
|
||||
srs_info("Header value(%d bytes): %.*s", (int)length, (int)length, at);
|
||||
return 0;
|
||||
|
|
|
@ -330,9 +330,13 @@ public:
|
|||
class SrsHttpServeMux
|
||||
{
|
||||
private:
|
||||
// the pattern handler.
|
||||
// the pattern handler, to handle the http request.
|
||||
std::map<std::string, SrsHttpMuxEntry*> entries;
|
||||
// the vhost handler.
|
||||
// when find the handler to process the request,
|
||||
// append the matched vhost when pattern not starts with /,
|
||||
// for example, for pattern /live/livestream.flv of vhost ossrs.net,
|
||||
// the path will rewrite to ossrs.net/live/livestream.flv
|
||||
std::map<std::string, ISrsHttpHandler*> vhosts;
|
||||
public:
|
||||
SrsHttpServeMux();
|
||||
|
@ -544,8 +548,8 @@ private:
|
|||
SrsFastBuffer* buffer;
|
||||
private:
|
||||
// http parse data, reset before parse message.
|
||||
bool expect_filed_name;
|
||||
std::string filed_name;
|
||||
bool expect_field_name;
|
||||
std::string field_name;
|
||||
std::string field_value;
|
||||
SrsHttpParseState state;
|
||||
http_parser header;
|
||||
|
|
|
@ -826,7 +826,7 @@ int SrsHttpServer::initialize()
|
|||
return ret;
|
||||
}
|
||||
|
||||
int SrsHttpServer::mount(SrsSource* s, SrsRequest* r)
|
||||
int SrsHttpServer::http_mount(SrsSource* s, SrsRequest* r)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
|
@ -886,7 +886,7 @@ int SrsHttpServer::mount(SrsSource* s, SrsRequest* r)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void SrsHttpServer::unmount(SrsSource* s, SrsRequest* r)
|
||||
void SrsHttpServer::http_unmount(SrsSource* s, SrsRequest* r)
|
||||
{
|
||||
std::string sid = r->get_stream_url();
|
||||
|
||||
|
@ -1185,7 +1185,7 @@ SrsHttpConn::SrsHttpConn(SrsServer* svr, st_netfd_t fd, SrsHttpServer* m)
|
|||
: SrsConnection(svr, fd)
|
||||
{
|
||||
parser = new SrsHttpParser();
|
||||
mux = m;
|
||||
http_server = m;
|
||||
}
|
||||
|
||||
SrsHttpConn::~SrsHttpConn()
|
||||
|
@ -1271,7 +1271,7 @@ int SrsHttpConn::process_request(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
|||
r->method_str().c_str(), r->url().c_str(), r->content_length());
|
||||
|
||||
// use default server mux to serve http request.
|
||||
if ((ret = mux->mux.serve_http(w, r)) != ERROR_SUCCESS) {
|
||||
if ((ret = http_server->mux.serve_http(w, r)) != ERROR_SUCCESS) {
|
||||
if (!srs_is_client_gracefully_close(ret)) {
|
||||
srs_error("serve http msg failed. ret=%d", ret);
|
||||
}
|
||||
|
|
|
@ -333,8 +333,8 @@ public:
|
|||
virtual int initialize();
|
||||
// http flv/ts/mp3/aac stream
|
||||
public:
|
||||
virtual int mount(SrsSource* s, SrsRequest* r);
|
||||
virtual void unmount(SrsSource* s, SrsRequest* r);
|
||||
virtual int http_mount(SrsSource* s, SrsRequest* r);
|
||||
virtual void http_unmount(SrsSource* s, SrsRequest* r);
|
||||
// hls stream
|
||||
public:
|
||||
virtual int mount_hls(SrsRequest* r);
|
||||
|
@ -356,7 +356,7 @@ class SrsHttpConn : public SrsConnection
|
|||
{
|
||||
private:
|
||||
SrsHttpParser* parser;
|
||||
SrsHttpServer* mux;
|
||||
SrsHttpServer* http_server;
|
||||
public:
|
||||
SrsHttpConn(SrsServer* svr, st_netfd_t fd, SrsHttpServer* m);
|
||||
virtual ~SrsHttpConn();
|
||||
|
|
|
@ -1195,7 +1195,7 @@ int SrsServer::on_publish(SrsSource* s, SrsRequest* r)
|
|||
int ret = ERROR_SUCCESS;
|
||||
|
||||
#ifdef SRS_AUTO_HTTP_SERVER
|
||||
if ((ret = http_stream_mux->mount(s, r)) != ERROR_SUCCESS) {
|
||||
if ((ret = http_stream_mux->http_mount(s, r)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
@ -1206,7 +1206,7 @@ int SrsServer::on_publish(SrsSource* s, SrsRequest* r)
|
|||
void SrsServer::on_unpublish(SrsSource* s, SrsRequest* r)
|
||||
{
|
||||
#ifdef SRS_AUTO_HTTP_SERVER
|
||||
http_stream_mux->unmount(s, r);
|
||||
http_stream_mux->http_unmount(s, r);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue