winlin

fix async call and hls_nb_notify bug.

... ... @@ -87,7 +87,7 @@ int SrsDvrAsyncCallThread::cycle()
for (it = copies.begin(); it != copies.end(); ++it) {
ISrsDvrAsyncCall* call = *it;
if ((ret = call->call()) != ERROR_SUCCESS) {
srs_warn("dvr: ignore callback %s, ret=%d", call->to_string().c_str(), ret);
srs_warn("ignore async callback %s, ret=%d", call->to_string().c_str(), ret);
}
srs_freep(call);
}
... ...
... ... @@ -2440,22 +2440,6 @@ SrsConfDirective* SrsConfig::get_vhost_on_hls_notify(string vhost)
return conf->get("on_hls_notify");
}
int SrsConfig::get_vhost_hls_nb_notify(string vhost)
{
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
if (!conf) {
return SRS_CONF_DEFAULT_HLS_NB_NOTIFY;
}
conf = conf->get("hls_nb_notify");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_HLS_NB_NOTIFY;
}
return ::atoi(conf->arg0().c_str());
}
bool SrsConfig::get_bw_check_enabled(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
... ... @@ -3434,6 +3418,22 @@ string SrsConfig::get_hls_vcodec(string vhost)
return conf->arg0();
}
int SrsConfig::get_vhost_hls_nb_notify(string vhost)
{
SrsConfDirective* conf = get_hls(vhost);
if (!conf) {
return SRS_CONF_DEFAULT_HLS_NB_NOTIFY;
}
conf = conf->get("hls_nb_notify");
if (!conf || conf->arg0().empty()) {
return SRS_CONF_DEFAULT_HLS_NB_NOTIFY;
}
return ::atoi(conf->arg0().c_str());
}
bool SrsConfig::get_hls_cleanup(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
... ...
... ... @@ -652,11 +652,6 @@ public:
* @return the on_hls_notify callback directive, the args is the url to callback.
*/
virtual SrsConfDirective* get_vhost_on_hls_notify(std::string vhost);
/**
* get the size of bytes to read from cdn network, for the on_hls_notify callback,
* that is, to read max bytes of the bytes from the callback, or timeout or error.
*/
virtual int get_vhost_hls_nb_notify(std::string vhost);
// bwct(bandwidth check tool) section
public:
/**
... ... @@ -965,8 +960,12 @@ public:
* whether cleanup the old ts files.
*/
virtual bool get_hls_cleanup(std::string vhost);
// hds section
/**
* get the size of bytes to read from cdn network, for the on_hls_notify callback,
* that is, to read max bytes of the bytes from the callback, or timeout or error.
*/
virtual int get_vhost_hls_nb_notify(std::string vhost);
// hds section
private:
/**
* get the hds directive of vhost.
... ...
... ... @@ -42,6 +42,7 @@ using namespace std;
#define SRS_HTTP_RESPONSE_OK SRS_XSTR(ERROR_SUCCESS)
#define SRS_HTTP_HEADER_BUFFER 1024
#define SRS_HTTP_READ_BUFFER 4096
#define SRS_HTTP_BODY_BUFFER 32 * 1024
// the timeout for hls notify, in us.
... ... @@ -363,15 +364,18 @@ int SrsHttpHooks::on_hls_notify(std::string url, SrsRequest* req, std::string ts
}
SrsAutoFree(SrsHttpMessage, msg);
int nb_buf = srs_min(nb_notify, SRS_HTTP_READ_BUFFER);
char* buf = new char[nb_buf];
SrsAutoFree(char, buf);
int nb_read = 0;
ISrsHttpResponseReader* br = msg->body_reader();
while (nb_read < nb_notify && !br->eof()) {
char buf[64]; // only read a little of bytes of ts.
int nb_buf = 64;
if ((ret = br->read(buf, nb_buf, &nb_buf)) != ERROR_SUCCESS) {
int nb_bytes = 0;
if ((ret = br->read(buf, nb_buf, &nb_bytes)) != ERROR_SUCCESS) {
break;
}
nb_read += nb_buf;
nb_read += nb_bytes;
}
int spenttime = (int)(srs_update_system_time_ms() - starttime);
... ...