Skip to content

Commit

Permalink
for ossrs#324, refine code, add hstrs config.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Mar 14, 2015
1 parent 2adc069 commit 6d15d0e
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 48 deletions.
18 changes: 9 additions & 9 deletions trunk/auto/options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ function apply_user_presets() {
SRS_HTTP_PARSER=YES
SRS_HTTP_CALLBACK=YES
SRS_HTTP_SERVER=YES
SRS_STREAM_CASTER=YES
SRS_STREAM_CASTER=NO
SRS_HTTP_API=YES
SRS_LIBRTMP=YES
SRS_RESEARCH=NO
Expand Down Expand Up @@ -542,7 +542,7 @@ function apply_user_presets() {
SRS_HTTP_PARSER=YES
SRS_HTTP_CALLBACK=YES
SRS_HTTP_SERVER=YES
SRS_STREAM_CASTER=YES
SRS_STREAM_CASTER=NO
SRS_HTTP_API=YES
SRS_LIBRTMP=YES
SRS_RESEARCH=NO
Expand All @@ -569,7 +569,7 @@ function apply_user_presets() {
SRS_HTTP_PARSER=YES
SRS_HTTP_CALLBACK=YES
SRS_HTTP_SERVER=YES
SRS_STREAM_CASTER=YES
SRS_STREAM_CASTER=NO
SRS_HTTP_API=YES
SRS_LIBRTMP=YES
SRS_RESEARCH=NO
Expand All @@ -596,7 +596,7 @@ function apply_user_presets() {
SRS_HTTP_PARSER=YES
SRS_HTTP_CALLBACK=YES
SRS_HTTP_SERVER=YES
SRS_STREAM_CASTER=YES
SRS_STREAM_CASTER=NO
SRS_HTTP_API=NO
SRS_LIBRTMP=YES
SRS_RESEARCH=NO
Expand All @@ -623,7 +623,7 @@ function apply_user_presets() {
SRS_HTTP_PARSER=YES
SRS_HTTP_CALLBACK=YES
SRS_HTTP_SERVER=YES
SRS_STREAM_CASTER=YES
SRS_STREAM_CASTER=NO
SRS_HTTP_API=YES
SRS_LIBRTMP=YES
SRS_RESEARCH=YES
Expand All @@ -650,7 +650,7 @@ function apply_user_presets() {
SRS_HTTP_PARSER=YES
SRS_HTTP_CALLBACK=YES
SRS_HTTP_SERVER=YES
SRS_STREAM_CASTER=YES
SRS_STREAM_CASTER=NO
SRS_HTTP_API=YES
SRS_LIBRTMP=NO
SRS_RESEARCH=NO
Expand All @@ -677,7 +677,7 @@ function apply_user_presets() {
SRS_HTTP_PARSER=YES
SRS_HTTP_CALLBACK=YES
SRS_HTTP_SERVER=YES
SRS_STREAM_CASTER=YES
SRS_STREAM_CASTER=NO
SRS_HTTP_API=YES
SRS_LIBRTMP=YES
SRS_RESEARCH=NO
Expand All @@ -704,7 +704,7 @@ function apply_user_presets() {
SRS_HTTP_PARSER=YES
SRS_HTTP_CALLBACK=YES
SRS_HTTP_SERVER=YES
SRS_STREAM_CASTER=YES
SRS_STREAM_CASTER=NO
SRS_HTTP_API=YES
SRS_LIBRTMP=YES
SRS_RESEARCH=NO
Expand All @@ -731,7 +731,7 @@ function apply_user_presets() {
SRS_HTTP_PARSER=YES
SRS_HTTP_CALLBACK=YES
SRS_HTTP_SERVER=YES
SRS_STREAM_CASTER=YES
SRS_STREAM_CASTER=NO
SRS_HTTP_API=YES
SRS_LIBRTMP=YES
SRS_RESEARCH=NO
Expand Down
17 changes: 10 additions & 7 deletions trunk/auto/summary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SrsIngestSummaryColor="\${YELLOW}{disabled} "; if [ $SRS_INGEST = YES ]; then Sr
SrsHttpCallbackSummaryColor="\${YELLOW}{disabled} "; if [ $SRS_HTTP_CALLBACK = YES ]; then SrsHttpCallbackSummaryColor="\${GREEN}"; fi
SrsHttpServerSummaryColor="\${YELLOW}{disabled} "; if [ $SRS_HTTP_SERVER = YES ]; then SrsHttpServerSummaryColor="\${GREEN}"; fi
SrsHttpApiSummaryColor="\${YELLOW}{disabled} "; if [ $SRS_HTTP_API = YES ]; then SrsHttpApiSummaryColor="\${GREEN}"; fi
SrsStreamCasterSummaryColor="\${YELLOW}{disabled} "; if [ $SRS_STREAM_CASTER = YES ]; then SrsStreamCasterSummaryColor="\${GREEN}"; fi
SrsLibrtmpSummaryColor="\${YELLOW}{disabled} "; if [ $SRS_LIBRTMP = YES ]; then SrsLibrtmpSummaryColor="\${GREEN}"; fi
SrsLibrtmpSSLSummaryColor="\${YELLOW}{disabled} "; if [ $SRS_LIBRTMP = YES ]; then if [ $SRS_SSL = YES ]; then SrsLibrtmpSSLSummaryColor="\${GREEN}"; fi fi
SrsResearchSummaryColor="\${GREEN}{disabled} "; if [ $SRS_RESEARCH = YES ]; then SrsResearchSummaryColor="\${GREEN}"; fi
Expand Down Expand Up @@ -71,11 +72,11 @@ echo -e " | ${SrsLibrtmpSummaryColor}librtmp-sample: ./research/librtmp/
echo -e " | ${SrsLibrtmpSummaryColor}librtmp-sample: ./research/librtmp/objs/srs_bandwidth_check\${BLACK}"
echo -e " \${BLACK}+------------------------------------------------------------------------------------\${BLACK}"
echo -e " |\${GREEN}server: ./objs/srs -c conf/srs.conf, start the srs server\${BLACK}"
echo -e " | ${SrsHlsSummaryColor}hls @see: https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_DeliveryHLS\${BLACK}"
echo -e " | ${SrsHlsSummaryColor}hls @see: https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_DeliveryHLS\${BLACK}"
echo -e " | ${SrsHlsSummaryColor}hls: generate m3u8 and ts from rtmp stream\${BLACK}"
echo -e " | ${SrsDvrSummaryColor}dvr @see: https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_DVR\${BLACK}"
echo -e " | ${SrsDvrSummaryColor}dvr @see: https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_DVR\${BLACK}"
echo -e " | ${SrsDvrSummaryColor}dvr: record RTMP stream to flv files.\${BLACK}"
echo -e " | ${SrsNginxSummaryColor}nginx @see: https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_DeliveryHLS\${BLACK}"
echo -e " | ${SrsNginxSummaryColor}nginx @see: https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_DeliveryHLS\${BLACK}"
echo -e " | ${SrsNginxSummaryColor}nginx: delivery HLS stream by nginx\${BLACK}"
echo -e " | ${SrsNginxSummaryColor}nginx: sudo ./objs/nginx/sbin/nginx\${BLACK}"
echo -e " | ${SrsSslSummaryColor}ssl @see: https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_RTMPHandshake\${BLACK}"
Expand All @@ -87,14 +88,16 @@ echo -e " | ${SrsTranscodeSummaryColor}transcode @see: https://github.co
echo -e " | ${SrsTranscodeSummaryColor}transcode: support transcoding RTMP stream\${BLACK}"
echo -e " | ${SrsIngestSummaryColor}ingest @see: https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_Ingest\${BLACK}"
echo -e " | ${SrsIngestSummaryColor}ingest: support ingest file/stream/device then push to SRS by RTMP stream\${BLACK}"
echo -e " | ${SrsHttpCallbackSummaryColor}http-callback @see: https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_HTTPCallback\${BLACK}"
echo -e " | ${SrsHttpCallbackSummaryColor}http-callback @see: https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_HTTPCallback\${BLACK}"
echo -e " | ${SrsHttpCallbackSummaryColor}http-callback: support http callback for authentication and event injection\${BLACK}"
echo -e " | ${SrsHttpServerSummaryColor}http-server @see: https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_HTTPServer\${BLACK}"
echo -e " | ${SrsHttpServerSummaryColor}http-server @see: https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_HTTPServer\${BLACK}"
echo -e " | ${SrsHttpServerSummaryColor}http-server: support http server to delivery http stream\${BLACK}"
echo -e " | ${SrsHttpApiSummaryColor}http-api @see: https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_HTTPApi\${BLACK}"
echo -e " | ${SrsHttpApiSummaryColor}http-api @see: https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_HTTPApi\${BLACK}"
echo -e " | ${SrsHttpApiSummaryColor}http-api: support http api to manage server\${BLACK}"
echo -e " | ${SrsStreamCasterSummaryColor}stream-caster @see: https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_Streamer\${BLACK}"
echo -e " | ${SrsStreamCasterSummaryColor}stream-caster: start server to cast stream over other protocols.\${BLACK}"
echo -e " \${BLACK}+------------------------------------------------------------------------------------\${BLACK}"
echo -e "\${GREEN}binaries @see: https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_Build\${BLACK}"
echo -e "\${GREEN}binaries @see: https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_Build\${BLACK}"
echo "You can:"
echo " ./objs/srs -c conf/srs.conf"
Expand Down
6 changes: 6 additions & 0 deletions trunk/conf/full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,12 @@ vhost http.remux.srs.com {
# @remark the port of http is specified by http_server section.
# default: [vhost]/[app]/[stream].flv
mount [vhost]/[app]/[stream].flv;
# whether http stream trigger rtmp stream source when no stream available,
# for example, when encoder has not publish stream yet,
# user can play the http flv stream and wait for stream.
# TODO: FIXME: for edge vhost, automatically trigger the backsource connection.
# default: on
hstrs on;
}
}

Expand Down
2 changes: 2 additions & 0 deletions trunk/conf/http.aac.live.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ vhost __defaultVhost__ {
enabled on;
fast_cache 30;
mount [vhost]/[app]/[stream].aac;
hstrs on;

}
}
1 change: 1 addition & 0 deletions trunk/conf/http.flv.live.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ vhost __defaultVhost__ {
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
hstrs on;
}
}
2 changes: 2 additions & 0 deletions trunk/conf/http.mp3.live.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ vhost __defaultVhost__ {
enabled on;
fast_cache 30;
mount [vhost]/[app]/[stream].mp3;
hstrs on;

}
}
1 change: 1 addition & 0 deletions trunk/conf/http.ts.live.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ vhost __defaultVhost__ {
http_remux {
enabled on;
mount [vhost]/[app]/[stream].ts;
hstrs on;
}
}
18 changes: 9 additions & 9 deletions trunk/configure
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ GREEN="\\033[32m"
YELLOW="\\033[33m"
BLACK="\\033[0m"

#####################################################################################
# parse user options, set the variables like:
# srs features: SRS_SSL/SRS_HLS/SRS_NGINX/SRS_FFMPEG_TOOL/SRS_HTTP_CALLBACK/......
# build options: SRS_JOBS
#####################################################################################
# parse options, exit with error when parse options invalid.
. auto/options.sh

# clean the exists, when not export srs-librtmp.
# do this only when the options is ok.
if [[ -f Makefile ]]; then
make clean
make clean
fi
# remove makefile
rm -f ${SRS_WORKDIR}/${SRS_MAKEFILE}

# create objs
mkdir -p ${SRS_OBJS}

#####################################################################################
# parse user options, set the variables like:
# srs features: SRS_SSL/SRS_HLS/SRS_NGINX/SRS_FFMPEG_TOOL/SRS_HTTP_CALLBACK/......
# build options: SRS_JOBS
#####################################################################################
# parse options, exit with error when parse options invalid.
. auto/options.sh

# for export srs-librtmp, change target to it.
. auto/generate-srs-librtmp-project.sh

Expand Down
26 changes: 25 additions & 1 deletion trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 4 additions & 0 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,10 @@ class SrsConfig
* 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:
/**
Expand Down
20 changes: 10 additions & 10 deletions trunk/src/app/srs_app_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions trunk/src/app/srs_app_http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,13 @@ class SrsHttpMuxEntry
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();
Expand Down Expand Up @@ -544,8 +548,8 @@ class SrsHttpParser
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;
Expand Down
8 changes: 4 additions & 4 deletions trunk/src/app/srs_app_http_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions trunk/src/app/srs_app_http_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ class SrsHttpServer : public ISrsReloadHandler
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);
Expand All @@ -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();
Expand Down
Loading

0 comments on commit 6d15d0e

Please sign in to comment.