mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
For #910, Support HTTP FLV with HTTP callback. 2.0.254
This commit is contained in:
parent
6cea551c64
commit
1e7c12a6dd
8 changed files with 111 additions and 9 deletions
|
@ -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()
|
||||
|
@ -472,7 +473,7 @@ int SrsLiveStream::update(SrsSource* s, SrsRequest* r)
|
|||
srs_freep(req);
|
||||
source = s;
|
||||
req = r->copy();
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue