mirror of
				https://github.com/ossrs/srs.git
				synced 2025-03-09 15:49:59 +00:00 
			
		
		
		
	Merge branch 'develop' into merge/develop
This commit is contained in:
		
						commit
						ff50ffd3ea
					
				
					 2 changed files with 66 additions and 47 deletions
				
			
		| 
						 | 
					@ -37,6 +37,7 @@ using namespace std;
 | 
				
			||||||
#include <srs_app_http_hooks.hpp>
 | 
					#include <srs_app_http_hooks.hpp>
 | 
				
			||||||
#include <srs_app_statistic.hpp>
 | 
					#include <srs_app_statistic.hpp>
 | 
				
			||||||
#include <srs_app_hybrid.hpp>
 | 
					#include <srs_app_hybrid.hpp>
 | 
				
			||||||
 | 
					#include <srs_service_log.hpp>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define SRS_CONTEXT_IN_HLS "hls_ctx"
 | 
					#define SRS_CONTEXT_IN_HLS "hls_ctx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -194,6 +195,12 @@ srs_error_t SrsVodStream::serve_m3u8_ctx(ISrsHttpResponseWriter * w, ISrsHttpMes
 | 
				
			||||||
    srs_assert(hr);
 | 
					    srs_assert(hr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    SrsRequest* req = hr->to_request(hr->host())->as_http();
 | 
					    SrsRequest* req = hr->to_request(hr->host())->as_http();
 | 
				
			||||||
 | 
					    // discovery vhost, resolve the vhost from config
 | 
				
			||||||
 | 
					    SrsConfDirective* parsed_vhost = _srs_config->get_vhost(req->vhost);
 | 
				
			||||||
 | 
					    if (parsed_vhost) {
 | 
				
			||||||
 | 
					        req->vhost = parsed_vhost->arg0();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    SrsAutoFree(SrsRequest, req);
 | 
					    SrsAutoFree(SrsRequest, req);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    string ctx = hr->query_get(SRS_CONTEXT_IN_HLS);
 | 
					    string ctx = hr->query_get(SRS_CONTEXT_IN_HLS);
 | 
				
			||||||
| 
						 | 
					@ -202,16 +209,19 @@ srs_error_t SrsVodStream::serve_m3u8_ctx(ISrsHttpResponseWriter * w, ISrsHttpMes
 | 
				
			||||||
        return SrsHttpFileServer::serve_m3u8_ctx(w, r, fullpath);
 | 
					        return SrsHttpFileServer::serve_m3u8_ctx(w, r, fullpath);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ((err = http_hooks_on_play(req)) != srs_success) {
 | 
					 | 
				
			||||||
        return srs_error_wrap(err, "HLS: http_hooks_on_play");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (ctx.empty()) {
 | 
					    if (ctx.empty()) {
 | 
				
			||||||
        // make sure unique
 | 
					        // make sure unique
 | 
				
			||||||
        do {
 | 
					        do {
 | 
				
			||||||
            ctx = srs_random_str(8);  // the same as cid
 | 
					            ctx = srs_random_str(8);  // the same as cid
 | 
				
			||||||
        } while (ctx_is_exist(ctx));
 | 
					        } while (ctx_is_exist(ctx));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    SrsContextRestore(_srs_context->get_id());
 | 
				
			||||||
 | 
					    _srs_context->set_id(SrsContextId().set_value(ctx));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ((err = http_hooks_on_play(req)) != srs_success) {
 | 
				
			||||||
 | 
					        return srs_error_wrap(err, "HLS: http_hooks_on_play");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::stringstream ss;
 | 
					    std::stringstream ss;
 | 
				
			||||||
    ss << "#EXTM3U" << SRS_CONSTS_LF;
 | 
					    ss << "#EXTM3U" << SRS_CONSTS_LF;
 | 
				
			||||||
| 
						 | 
					@ -339,6 +349,9 @@ srs_error_t SrsVodStream::on_timer(srs_utime_t interval)
 | 
				
			||||||
        SrsRequest* req = it->second.req;
 | 
					        SrsRequest* req = it->second.req;
 | 
				
			||||||
        srs_utime_t hls_window = _srs_config->get_hls_window(req->vhost);
 | 
					        srs_utime_t hls_window = _srs_config->get_hls_window(req->vhost);
 | 
				
			||||||
        if (it->second.request_time + (2 * hls_window) < srs_get_system_time()) {
 | 
					        if (it->second.request_time + (2 * hls_window) < srs_get_system_time()) {
 | 
				
			||||||
 | 
					            SrsContextRestore(_srs_context->get_id());
 | 
				
			||||||
 | 
					            _srs_context->set_id(SrsContextId().set_value(ctx));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            http_hooks_on_stop(req);
 | 
					            http_hooks_on_stop(req);
 | 
				
			||||||
            srs_freep(req);
 | 
					            srs_freep(req);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -351,22 +351,22 @@ srs_error_t SrsRtcPLIWorker::cycle()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return err;
 | 
					    return err;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SrsRtcAsyncCallOnStop::SrsRtcAsyncCallOnStop(SrsContextId c, SrsRequest * r)
 | 
					SrsRtcAsyncCallOnStop::SrsRtcAsyncCallOnStop(SrsContextId c, SrsRequest * r)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    cid = c;
 | 
					    cid = c;
 | 
				
			||||||
    req = r->copy();
 | 
					    req = r->copy();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SrsRtcAsyncCallOnStop::~SrsRtcAsyncCallOnStop()
 | 
					SrsRtcAsyncCallOnStop::~SrsRtcAsyncCallOnStop()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    srs_freep(req);
 | 
					    srs_freep(req);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
srs_error_t SrsRtcAsyncCallOnStop::call()
 | 
					srs_error_t SrsRtcAsyncCallOnStop::call()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    srs_error_t err = srs_success;
 | 
					    srs_error_t err = srs_success;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
 | 
					    if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
 | 
				
			||||||
        return err;
 | 
					        return err;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -386,17 +386,20 @@ srs_error_t SrsRtcAsyncCallOnStop::call()
 | 
				
			||||||
        hooks = conf->args;
 | 
					        hooks = conf->args;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    SrsContextRestore(_srs_context->get_id());
 | 
				
			||||||
 | 
					    _srs_context->set_id(cid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (int i = 0; i < (int)hooks.size(); i++) {
 | 
					    for (int i = 0; i < (int)hooks.size(); i++) {
 | 
				
			||||||
        std::string url = hooks.at(i);
 | 
					        std::string url = hooks.at(i);
 | 
				
			||||||
        SrsHttpHooks::on_stop(url, req);
 | 
					        SrsHttpHooks::on_stop(url, req);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return err;
 | 
					    return err;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
std::string SrsRtcAsyncCallOnStop::to_string()
 | 
					std::string SrsRtcAsyncCallOnStop::to_string()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return std::string("");
 | 
					    return std::string("");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SrsRtcPlayStream::SrsRtcPlayStream(SrsRtcConnection* s, const SrsContextId& cid)
 | 
					SrsRtcPlayStream::SrsRtcPlayStream(SrsRtcConnection* s, const SrsContextId& cid)
 | 
				
			||||||
| 
						 | 
					@ -997,21 +1000,21 @@ srs_error_t SrsRtcPublishTwccTimer::on_timer(srs_utime_t interval)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SrsRtcAsyncCallOnUnpublish::SrsRtcAsyncCallOnUnpublish(SrsContextId c, SrsRequest * r)
 | 
					SrsRtcAsyncCallOnUnpublish::SrsRtcAsyncCallOnUnpublish(SrsContextId c, SrsRequest * r)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    cid = c;
 | 
					    cid = c;
 | 
				
			||||||
    req = r->copy();
 | 
					    req = r->copy();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SrsRtcAsyncCallOnUnpublish::~SrsRtcAsyncCallOnUnpublish()
 | 
					SrsRtcAsyncCallOnUnpublish::~SrsRtcAsyncCallOnUnpublish()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    srs_freep(req);
 | 
					    srs_freep(req);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
srs_error_t SrsRtcAsyncCallOnUnpublish::call()
 | 
					srs_error_t SrsRtcAsyncCallOnUnpublish::call()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    srs_error_t err = srs_success;
 | 
					    srs_error_t err = srs_success;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
 | 
					    if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
 | 
				
			||||||
        return err;
 | 
					        return err;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -1031,17 +1034,20 @@ srs_error_t SrsRtcAsyncCallOnUnpublish::call()
 | 
				
			||||||
        hooks = conf->args;
 | 
					        hooks = conf->args;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    SrsContextRestore(_srs_context->get_id());
 | 
				
			||||||
 | 
					    _srs_context->set_id(cid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (int i = 0; i < (int)hooks.size(); i++) {
 | 
					    for (int i = 0; i < (int)hooks.size(); i++) {
 | 
				
			||||||
        std::string url = hooks.at(i);
 | 
					        std::string url = hooks.at(i);
 | 
				
			||||||
        SrsHttpHooks::on_unpublish(url, req);
 | 
					        SrsHttpHooks::on_unpublish(url, req);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return err;
 | 
					    return err;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
std::string SrsRtcAsyncCallOnUnpublish::to_string()
 | 
					std::string SrsRtcAsyncCallOnUnpublish::to_string()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return std::string("");
 | 
					    return std::string("");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SrsRtcPublishStream::SrsRtcPublishStream(SrsRtcConnection* session, const SrsContextId& cid)
 | 
					SrsRtcPublishStream::SrsRtcPublishStream(SrsRtcConnection* session, const SrsContextId& cid)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue