Skip to content

Commit

Permalink
fix #458, http hooks use source thread cid. 2.0.188
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Sep 14, 2015
1 parent 6d50aa1 commit 0d57ef9
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 37 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ Remark:

## History

* v2.0, 2015-09-14, for [#458][bug #458] http hooks use source thread cid. 2.0.188
* v2.0, 2015-09-14, for [#475][bug #475] fix http hooks crash for st context switch. 2.0.187
* v2.0, 2015-09-09, support reload utc_time. 2.0.186
* <strong>v2.0, 2015-08-23, [2.0 alpha(2.0.185)][r2.0a0] released. 89022 lines.</strong>
Expand Down Expand Up @@ -1026,6 +1027,7 @@ Winlin
[bug #92]: https://github.com/simple-rtmp-server/srs/issues/92
[bug #380]: https://github.com/simple-rtmp-server/srs/issues/380
[bug #475]: https://github.com/simple-rtmp-server/srs/issues/475
[bug #458]: https://github.com/simple-rtmp-server/srs/issues/458
[bug #454]: https://github.com/simple-rtmp-server/srs/issues/454
[bug #442]: https://github.com/simple-rtmp-server/srs/issues/442
[bug #169]: https://github.com/simple-rtmp-server/srs/issues/169
Expand Down
8 changes: 5 additions & 3 deletions trunk/src/app/srs_app_dvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,9 @@ int SrsFlvSegment::on_reload_vhost_dvr(std::string /*vhost*/)
return ret;
}

SrsDvrAsyncCallOnDvr::SrsDvrAsyncCallOnDvr(SrsRequest* r, string p)
SrsDvrAsyncCallOnDvr::SrsDvrAsyncCallOnDvr(int c, SrsRequest* r, string p)
{
cid = c;
req = r->copy();
path = p;
}
Expand Down Expand Up @@ -534,7 +535,7 @@ int SrsDvrAsyncCallOnDvr::call()

for (int i = 0; i < (int)hooks.size(); i++) {
std::string url = hooks.at(i);
if ((ret = SrsHttpHooks::on_dvr(url, req, path)) != ERROR_SUCCESS) {
if ((ret = SrsHttpHooks::on_dvr(cid, url, req, path)) != ERROR_SUCCESS) {
srs_error("hook client on_dvr failed. url=%s, ret=%d", url.c_str(), ret);
return ret;
}
Expand Down Expand Up @@ -638,7 +639,8 @@ int SrsDvrPlan::on_reap_segment()
{
int ret = ERROR_SUCCESS;

if ((ret = async->execute(new SrsDvrAsyncCallOnDvr(req, segment->get_path()))) != ERROR_SUCCESS) {
int cid = _srs_context->get_id();
if ((ret = async->execute(new SrsDvrAsyncCallOnDvr(cid, req, segment->get_path()))) != ERROR_SUCCESS) {
return ret;
}

Expand Down
3 changes: 2 additions & 1 deletion trunk/src/app/srs_app_dvr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ class SrsFlvSegment : public ISrsReloadHandler
class SrsDvrAsyncCallOnDvr : public ISrsAsyncCallTask
{
private:
int cid;
std::string path;
SrsRequest* req;
public:
SrsDvrAsyncCallOnDvr(SrsRequest* r, std::string p);
SrsDvrAsyncCallOnDvr(int c, SrsRequest* r, std::string p);
virtual ~SrsDvrAsyncCallOnDvr();
public:
virtual int call();
Expand Down
15 changes: 9 additions & 6 deletions trunk/src/app/srs_app_hls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,10 @@ void SrsHlsSegment::update_duration(int64_t current_frame_dts)
return;
}

SrsDvrAsyncCallOnHls::SrsDvrAsyncCallOnHls(SrsRequest* r, string p, string t, string m, string mu, int s, double d)
SrsDvrAsyncCallOnHls::SrsDvrAsyncCallOnHls(int c, SrsRequest* r, string p, string t, string m, string mu, int s, double d)
{
req = r->copy();
cid = c;
path = p;
ts_url = t;
m3u8 = m;
Expand Down Expand Up @@ -220,7 +221,7 @@ int SrsDvrAsyncCallOnHls::call()

for (int i = 0; i < (int)hooks.size(); i++) {
std::string url = hooks.at(i);
if ((ret = SrsHttpHooks::on_hls(url, req, path, ts_url, m3u8, m3u8_url, seq_no, duration)) != ERROR_SUCCESS) {
if ((ret = SrsHttpHooks::on_hls(cid, url, req, path, ts_url, m3u8, m3u8_url, seq_no, duration)) != ERROR_SUCCESS) {
srs_error("hook client on_hls failed. url=%s, ret=%d", url.c_str(), ret);
return ret;
}
Expand All @@ -235,8 +236,9 @@ string SrsDvrAsyncCallOnHls::to_string()
return "on_hls: " + path;
}

SrsDvrAsyncCallOnHlsNotify::SrsDvrAsyncCallOnHlsNotify(SrsRequest* r, string u)
SrsDvrAsyncCallOnHlsNotify::SrsDvrAsyncCallOnHlsNotify(int c, SrsRequest* r, string u)
{
cid = c;
req = r->copy();
ts_url = u;
}
Expand Down Expand Up @@ -274,7 +276,7 @@ int SrsDvrAsyncCallOnHlsNotify::call()
int nb_notify = _srs_config->get_vhost_hls_nb_notify(req->vhost);
for (int i = 0; i < (int)hooks.size(); i++) {
std::string url = hooks.at(i);
if ((ret = SrsHttpHooks::on_hls_notify(url, req, ts_url, nb_notify)) != ERROR_SUCCESS) {
if ((ret = SrsHttpHooks::on_hls_notify(cid, url, req, ts_url, nb_notify)) != ERROR_SUCCESS) {
srs_error("hook client on_hls_notify failed. url=%s, ret=%d", url.c_str(), ret);
return ret;
}
Expand Down Expand Up @@ -724,15 +726,16 @@ int SrsHlsMuxer::segment_close(string log_desc)
segments.push_back(current);

// use async to call the http hooks, for it will cause thread switch.
if ((ret = async->execute(new SrsDvrAsyncCallOnHls(req,
if ((ret = async->execute(new SrsDvrAsyncCallOnHls(
_srs_context->get_id(), req,
current->full_path, current->uri, m3u8, m3u8_url,
current->sequence_no, current->duration))) != ERROR_SUCCESS)
{
return ret;
}

// use async to call the http hooks, for it will cause thread switch.
if ((ret = async->execute(new SrsDvrAsyncCallOnHlsNotify(req, current->uri))) != ERROR_SUCCESS) {
if ((ret = async->execute(new SrsDvrAsyncCallOnHlsNotify(_srs_context->get_id(), req, current->uri))) != ERROR_SUCCESS) {
return ret;
}

Expand Down
6 changes: 4 additions & 2 deletions trunk/src/app/srs_app_hls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class SrsHlsSegment
class SrsDvrAsyncCallOnHls : public ISrsAsyncCallTask
{
private:
int cid;
std::string path;
std::string ts_url;
std::string m3u8;
Expand All @@ -175,7 +176,7 @@ class SrsDvrAsyncCallOnHls : public ISrsAsyncCallTask
SrsRequest* req;
double duration;
public:
SrsDvrAsyncCallOnHls(SrsRequest* r, std::string p, std::string t, std::string m, std::string mu, int s, double d);
SrsDvrAsyncCallOnHls(int c, SrsRequest* r, std::string p, std::string t, std::string m, std::string mu, int s, double d);
virtual ~SrsDvrAsyncCallOnHls();
public:
virtual int call();
Expand All @@ -188,10 +189,11 @@ class SrsDvrAsyncCallOnHls : public ISrsAsyncCallTask
class SrsDvrAsyncCallOnHlsNotify : public ISrsAsyncCallTask
{
private:
int cid;
std::string ts_url;
SrsRequest* req;
public:
SrsDvrAsyncCallOnHlsNotify(SrsRequest* r, std::string u);
SrsDvrAsyncCallOnHlsNotify(int c, SrsRequest* r, std::string u);
virtual ~SrsDvrAsyncCallOnHlsNotify();
public:
virtual int call();
Expand Down
12 changes: 6 additions & 6 deletions trunk/src/app/srs_app_http_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,11 @@ void SrsHttpHooks::on_stop(string url, SrsRequest* req)
return;
}

int SrsHttpHooks::on_dvr(string url, SrsRequest* req, string file)
int SrsHttpHooks::on_dvr(int cid, string url, SrsRequest* req, string file)
{
int ret = ERROR_SUCCESS;

int client_id = _srs_context->get_id();
int client_id = cid;
std::string cwd = _srs_config->cwd();

std::stringstream ss;
Expand Down Expand Up @@ -293,11 +293,11 @@ int SrsHttpHooks::on_dvr(string url, SrsRequest* req, string file)
return ret;
}

int SrsHttpHooks::on_hls(string url, SrsRequest* req, string file, string ts_url, string m3u8, string m3u8_url, int sn, double duration)
int SrsHttpHooks::on_hls(int cid, string url, SrsRequest* req, string file, string ts_url, string m3u8, string m3u8_url, int sn, double duration)
{
int ret = ERROR_SUCCESS;

int client_id = _srs_context->get_id();
int client_id = cid;
std::string cwd = _srs_config->cwd();

std::stringstream ss;
Expand Down Expand Up @@ -334,11 +334,11 @@ int SrsHttpHooks::on_hls(string url, SrsRequest* req, string file, string ts_url
return ret;
}

int SrsHttpHooks::on_hls_notify(std::string url, SrsRequest* req, std::string ts_url, int nb_notify)
int SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* req, std::string ts_url, int nb_notify)
{
int ret = ERROR_SUCCESS;

int client_id = _srs_context->get_id();
int client_id = cid;
std::string cwd = _srs_config->cwd();

if (srs_string_starts_with(ts_url, "http://") || srs_string_starts_with(ts_url, "https://")) {
Expand Down
39 changes: 21 additions & 18 deletions trunk/src/app/srs_app_http_hooks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,32 +90,35 @@ class SrsHttpHooks
*/
static void on_stop(std::string url, SrsRequest* req);
/**
* on_dvr hook, when reap a dvr file.
* @param url the api server url, to process the event.
* ignore if empty.
* @param file the file path, can be relative or absolute path.
*/
static int on_dvr(std::string url, SrsRequest* req, std::string file);
* on_dvr hook, when reap a dvr file.
* @param url the api server url, to process the event.
* ignore if empty.
* @param file the file path, can be relative or absolute path.
* @param cid the source connection cid, for the on_dvr is async call.
*/
static int on_dvr(int cid, std::string url, SrsRequest* req, std::string file);
/**
* when hls reap segment, callback.
* @param url the api server url, to process the event.
* ignore if empty.
* @param file the ts file path, can be relative or absolute path.
* @param ts_url the ts url, which used for m3u8.
* @param m3u8 the m3u8 file path, can be relative or absolute path.
* @param m3u8_url the m3u8 url, which is used for the http mount path.
* @param sn the seq_no, the sequence number of ts in hls/m3u8.
* @param duration the segment duration in seconds.
*/
static int on_hls(std::string url, SrsRequest* req, std::string file, std::string ts_url, std::string m3u8, std::string m3u8_url, int sn, double duration);
* when hls reap segment, callback.
* @param url the api server url, to process the event.
* ignore if empty.
* @param file the ts file path, can be relative or absolute path.
* @param ts_url the ts url, which used for m3u8.
* @param m3u8 the m3u8 file path, can be relative or absolute path.
* @param m3u8_url the m3u8 url, which is used for the http mount path.
* @param sn the seq_no, the sequence number of ts in hls/m3u8.
* @param duration the segment duration in seconds.
* @param cid the source connection cid, for the on_dvr is async call.
*/
static int on_hls(int cid, std::string url, SrsRequest* req, std::string file, std::string ts_url, std::string m3u8, std::string m3u8_url, int sn, double duration);
/**
* when hls reap segment, callback.
* @param url the api server url, to process the event.
* ignore if empty.
* @param ts_url the ts uri, used to replace the variable [ts_url] in url.
* @param nb_notify the max bytes to read from notify server.
* @param cid the source connection cid, for the on_dvr is async call.
*/
static int on_hls_notify(std::string url, SrsRequest* req, std::string ts_url, int nb_notify);
static int on_hls_notify(int cid, std::string url, SrsRequest* req, std::string ts_url, int nb_notify);
private:
static int do_post(std::string url, std::string req, int& code, std::string& res);
};
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 187
#define VERSION_REVISION 188

// server info.
#define RTMP_SIG_SRS_KEY "SRS"
Expand Down

0 comments on commit 0d57ef9

Please sign in to comment.