Skip to content

Commit

Permalink
For #1339, Support HTTP-FLV params.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Apr 5, 2019
2 parents d5ea3c3 + 91c462b commit b9750ba
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@

# Apple-specific garbage files.
.AppleDouble

.idea
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ Please select according to languages:

### V2 changes

* v2.0, 2019-04-05, Merge [#1339][bug #1339], Support HTTP-FLV params. 2.0.262
* v2.0, 2018-12-01, Merge [#1274][bug #1274], Upgrade to FFMPEG 4.1 and X264 157. 2.0.261
* v2.0, 2018-11-11, Merge [#1261][bug #1261], Support `_definst_` for Wowza. 2.0.260
* v2.0, 2018-11-11, Merge [#1263][bug #1263], Fix string trim bug. 2.0.259
Expand Down Expand Up @@ -1446,6 +1447,7 @@ Winlin
[bug #1263]: https://github.com/ossrs/srs/issues/1263
[bug #1261]: https://github.com/ossrs/srs/issues/1261
[bug #1274]: https://github.com/ossrs/srs/pull/1274
[bug #1339]: https://github.com/ossrs/srs/pull/1339
[bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx

[bug #735]: https://github.com/ossrs/srs/issues/735
Expand Down
28 changes: 19 additions & 9 deletions trunk/src/app/srs_app_http_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,13 @@ srs_error_t SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage
{
srs_error_t err = srs_success;

if ((err = http_hooks_on_play()) != srs_success) {
if ((err = http_hooks_on_play(r)) != srs_success) {
return srs_error_wrap(err, "http hook");
}

err = do_serve_http(w, r);

http_hooks_on_stop();
http_hooks_on_stop(r);

return err;
}
Expand Down Expand Up @@ -658,21 +658,26 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
return err;
}

srs_error_t SrsLiveStream::http_hooks_on_play()
srs_error_t SrsLiveStream::http_hooks_on_play(ISrsHttpMessage* r)
{
srs_error_t err = srs_success;

if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
return err;
}

// Create request to report for the specified connection.
SrsHttpMessage* hr = dynamic_cast<SrsHttpMessage*>(r);
SrsRequest* nreq = hr->to_request(req->vhost);
SrsAutoFree(SrsRequest, nreq);

// 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);
SrsConfDirective* conf = _srs_config->get_vhost_on_play(nreq->vhost);

if (!conf) {
return err;
Expand All @@ -683,27 +688,32 @@ srs_error_t SrsLiveStream::http_hooks_on_play()

for (int i = 0; i < (int)hooks.size(); i++) {
std::string url = hooks.at(i);
if ((err = SrsHttpHooks::on_play(url, req)) != srs_success) {
return srs_error_wrap(err, "rtmp on_play %s", url.c_str());
if ((err = SrsHttpHooks::on_play(url, nreq)) != srs_success) {
return srs_error_wrap(err, "http on_play %s", url.c_str());
}
}

return err;
}

void SrsLiveStream::http_hooks_on_stop()
void SrsLiveStream::http_hooks_on_stop(ISrsHttpMessage* r)
{
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
return;
}

// Create request to report for the specified connection.
SrsHttpMessage* hr = dynamic_cast<SrsHttpMessage*>(r);
SrsRequest* nreq = hr->to_request(req->vhost);
SrsAutoFree(SrsRequest, nreq);

// 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);
SrsConfDirective* conf = _srs_config->get_vhost_on_stop(nreq->vhost);

if (!conf) {
srs_info("ignore the empty http callback: on_stop");
Expand All @@ -715,7 +725,7 @@ void SrsLiveStream::http_hooks_on_stop()

for (int i = 0; i < (int)hooks.size(); i++) {
std::string url = hooks.at(i);
SrsHttpHooks::on_stop(url, req);
SrsHttpHooks::on_stop(url, nreq);
}

return;
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_http_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ class SrsLiveStream : public ISrsHttpHandler
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
private:
virtual srs_error_t do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
virtual srs_error_t http_hooks_on_play();
virtual void http_hooks_on_stop();
virtual srs_error_t http_hooks_on_play(ISrsHttpMessage* r);
virtual void http_hooks_on_stop(ISrsHttpMessage* r);
virtual srs_error_t streaming_send_messages(ISrsBufferEncoder* enc, SrsSharedPtrMessage** msgs, int nb_msgs);
};

Expand Down
5 changes: 5 additions & 0 deletions trunk/src/service/srs_service_http_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,11 @@ SrsRequest* SrsHttpMessage::to_request(string vhost)
req->tcUrl = "rtmp://" + vhost + "/" + req->app;
req->pageUrl = get_request_header("Referer");
req->objectEncoding = 0;

std::string query = _uri->get_query();
if (!query.empty()) {
req->tcUrl = req->tcUrl + "?" + query;
}

srs_discovery_tc_url(req->tcUrl, req->schema, req->host, req->vhost, req->app, req->stream, req->port, req->param);
req->strip();
Expand Down

0 comments on commit b9750ba

Please sign in to comment.