winlin

for #324, refine code, add hstrs config.

... ... @@ -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
... ... @@ -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
... ... @@ -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
... ... @@ -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
... ... @@ -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
... ... @@ -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
... ... @@ -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
... ... @@ -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
... ... @@ -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
... ...
... ... @@ -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
... ... @@ -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}"
... ... @@ -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"
... ...
... ... @@ -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;
}
}
... ...
... ... @@ -14,5 +14,7 @@ vhost __defaultVhost__ {
enabled on;
fast_cache 30;
mount [vhost]/[app]/[stream].aac;
hstrs on;
}
}
... ...
... ... @@ -13,5 +13,6 @@ vhost __defaultVhost__ {
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
hstrs on;
}
}
... ...
... ... @@ -14,5 +14,7 @@ vhost __defaultVhost__ {
enabled on;
fast_cache 30;
mount [vhost]/[app]/[stream].mp3;
hstrs on;
}
}
... ...
... ... @@ -13,5 +13,6 @@ vhost __defaultVhost__ {
http_remux {
enabled on;
mount [vhost]/[app]/[stream].ts;
hstrs on;
}
}
... ...
... ... @@ -15,10 +15,18 @@ 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}
... ... @@ -26,14 +34,6 @@ 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
... ...
... ... @@ -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
}
... ...