For #910, Support HTTP FLV with HTTP callback. 2.0.254

pull/1150/merge
winlin 7 years ago
parent 6cea551c64
commit 1e7c12a6dd

@ -333,6 +333,7 @@ Remark:
## History
* v2.0, 2018-08-11, For [#910][bug #910], Support HTTP FLV with HTTP callback. 2.0.254
* v2.0, 2018-08-11, For [#1110][bug #1110], Refine params in http callback. 2.0.253
* v2.0, 2018-08-05, Refine HTTP-FLV latency, support realtime mode. 2.0.252
* v2.0, 2018-08-04, For [#1110][bug #1110], Support params in http callback. 2.0.251
@ -1321,6 +1322,7 @@ Winlin
[bug #1119]: https://github.com/ossrs/srs/issues/1119
[bug #1031]: https://github.com/ossrs/srs/issues/1031
[bug #1110]: https://github.com/ossrs/srs/issues/1110
[bug #910]: https://github.com/ossrs/srs/issues/910
[bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx
[exo #828]: https://github.com/google/ExoPlayer/pull/828

@ -864,10 +864,8 @@ SrsRequest* SrsHttpMessage::to_request(string vhost)
req->pageUrl = get_request_header("Referer");
req->objectEncoding = 0;
srs_discovery_tc_url(req->tcUrl,
req->schema, req->host, req->vhost, req->app, req->stream, req->port,
req->param);
req->strip();
srs_discovery_tc_url(req->tcUrl, req->schema, req->host, req->vhost, req->app, req->stream, req->port, req->param);
req->as_http();
return req;
}

@ -55,6 +55,7 @@ using namespace std;
#include <srs_app_source.hpp>
#include <srs_app_server.hpp>
#include <srs_app_recv_thread.hpp>
#include <srs_app_http_hooks.hpp>
#endif
@ -64,7 +65,7 @@ using namespace std;
SrsStreamCache::SrsStreamCache(SrsSource* s, SrsRequest* r)
{
req = r->copy();
req = r->copy()->as_http();
source = s;
queue = new SrsMessageQueue(true);
pthread = new SrsEndlessThread("http-stream", this);
@ -457,7 +458,7 @@ SrsLiveStream::SrsLiveStream(SrsSource* s, SrsRequest* r, SrsStreamCache* c)
{
source = s;
cache = c;
req = r->copy();
req = r->copy()->as_http();
}
SrsLiveStream::~SrsLiveStream()
@ -480,6 +481,22 @@ int SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
{
int ret = ERROR_SUCCESS;
if ((ret = http_hooks_on_play()) != ERROR_SUCCESS) {
srs_error("http hook on_play failed. ret=%d", ret);
return ret;
}
ret = do_serve_http(w, r);
http_hooks_on_stop();
return ret;
}
int SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
{
int ret = ERROR_SUCCESS;
ISrsStreamEncoder* enc = NULL;
srs_assert(entry);
@ -619,6 +636,75 @@ int SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
return ret;
}
int SrsLiveStream::http_hooks_on_play()
{
int ret = ERROR_SUCCESS;
#ifdef SRS_AUTO_HTTP_CALLBACK
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
return ret;
}
// the http hooks will cause context switch,
// so we must copy all hooks for the on_connect may freed.
// @see https://github.com/ossrs/srs/issues/475
vector<string> hooks;
if (true) {
SrsConfDirective* conf = _srs_config->get_vhost_on_play(req->vhost);
if (!conf) {
srs_info("ignore the empty http callback: on_play");
return ret;
}
hooks = conf->args;
}
for (int i = 0; i < (int)hooks.size(); i++) {
std::string url = hooks.at(i);
if ((ret = SrsHttpHooks::on_play(url, req)) != ERROR_SUCCESS) {
srs_error("hook client on_play failed. url=%s, ret=%d", url.c_str(), ret);
return ret;
}
}
#endif
return ret;
}
void SrsLiveStream::http_hooks_on_stop()
{
#ifdef SRS_AUTO_HTTP_CALLBACK
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
return;
}
// the http hooks will cause context switch,
// so we must copy all hooks for the on_connect may freed.
// @see https://github.com/ossrs/srs/issues/475
vector<string> hooks;
if (true) {
SrsConfDirective* conf = _srs_config->get_vhost_on_stop(req->vhost);
if (!conf) {
srs_info("ignore the empty http callback: on_stop");
return;
}
hooks = conf->args;
}
for (int i = 0; i < (int)hooks.size(); i++) {
std::string url = hooks.at(i);
SrsHttpHooks::on_stop(url, req);
}
#endif
return;
}
int SrsLiveStream::streaming_send_messages(ISrsStreamEncoder* enc, SrsSharedPtrMessage** msgs, int nb_msgs)
{
int ret = ERROR_SUCCESS;
@ -844,7 +930,7 @@ int SrsHttpStreamServer::http_mount(SrsSource* s, SrsRequest* r)
srs_freep(tmpl->req);
tmpl->source = s;
tmpl->req = r->copy();
tmpl->req = r->copy()->as_http();
sflvs[sid] = entry;

@ -232,6 +232,9 @@ public:
public:
virtual int serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
private:
virtual int do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
virtual int http_hooks_on_play();
virtual void http_hooks_on_stop();
virtual int streaming_send_messages(ISrsStreamEncoder* enc, SrsSharedPtrMessage** msgs, int nb_msgs);
};

@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR 2
#define VERSION_MINOR 0
#define VERSION_REVISION 253
#define VERSION_REVISION 254
// generated by configure, only macros.
#include <srs_auto_headers.hpp>

@ -1776,6 +1776,12 @@ void SrsRequest::strip()
stream = srs_string_trim_start(stream, "/");
}
SrsRequest* SrsRequest::as_http()
{
schema = "http";
return this;
}
SrsResponse::SrsResponse()
{
stream_id = SRS_DEFAULT_SID;

@ -606,6 +606,9 @@ public:
* strip url, user must strip when update the url.
*/
virtual void strip();
public:
// Transform it as HTTP request.
virtual SrsRequest* as_http();
};
/**

@ -71,6 +71,10 @@ void srs_discovery_tc_url(
vhost = host;
srs_vhost_resolve(vhost, app, param);
srs_vhost_resolve(vhost, stream, param);
if (param == "?vhost="SRS_CONSTS_RTMP_DEFAULT_VHOST) {
param = "";
}
}
void srs_vhost_resolve(string& vhost, string& app, string& param)

Loading…
Cancel
Save