winlin

fix async call and hls_nb_notify bug.

@@ -87,7 +87,7 @@ int SrsDvrAsyncCallThread::cycle() @@ -87,7 +87,7 @@ int SrsDvrAsyncCallThread::cycle()
87 for (it = copies.begin(); it != copies.end(); ++it) { 87 for (it = copies.begin(); it != copies.end(); ++it) {
88 ISrsDvrAsyncCall* call = *it; 88 ISrsDvrAsyncCall* call = *it;
89 if ((ret = call->call()) != ERROR_SUCCESS) { 89 if ((ret = call->call()) != ERROR_SUCCESS) {
90 - srs_warn("dvr: ignore callback %s, ret=%d", call->to_string().c_str(), ret); 90 + srs_warn("ignore async callback %s, ret=%d", call->to_string().c_str(), ret);
91 } 91 }
92 srs_freep(call); 92 srs_freep(call);
93 } 93 }
@@ -2440,22 +2440,6 @@ SrsConfDirective* SrsConfig::get_vhost_on_hls_notify(string vhost) @@ -2440,22 +2440,6 @@ SrsConfDirective* SrsConfig::get_vhost_on_hls_notify(string vhost)
2440 return conf->get("on_hls_notify"); 2440 return conf->get("on_hls_notify");
2441 } 2441 }
2442 2442
2443 -int SrsConfig::get_vhost_hls_nb_notify(string vhost)  
2444 -{  
2445 - SrsConfDirective* conf = get_vhost_http_hooks(vhost);  
2446 -  
2447 - if (!conf) {  
2448 - return SRS_CONF_DEFAULT_HLS_NB_NOTIFY;  
2449 - }  
2450 -  
2451 - conf = conf->get("hls_nb_notify");  
2452 - if (!conf || conf->arg0().empty()) {  
2453 - return SRS_CONF_DEFAULT_HLS_NB_NOTIFY;  
2454 - }  
2455 -  
2456 - return ::atoi(conf->arg0().c_str());  
2457 -}  
2458 -  
2459 bool SrsConfig::get_bw_check_enabled(string vhost) 2443 bool SrsConfig::get_bw_check_enabled(string vhost)
2460 { 2444 {
2461 SrsConfDirective* conf = get_vhost(vhost); 2445 SrsConfDirective* conf = get_vhost(vhost);
@@ -3434,6 +3418,22 @@ string SrsConfig::get_hls_vcodec(string vhost) @@ -3434,6 +3418,22 @@ string SrsConfig::get_hls_vcodec(string vhost)
3434 return conf->arg0(); 3418 return conf->arg0();
3435 } 3419 }
3436 3420
  3421 +int SrsConfig::get_vhost_hls_nb_notify(string vhost)
  3422 +{
  3423 + SrsConfDirective* conf = get_hls(vhost);
  3424 +
  3425 + if (!conf) {
  3426 + return SRS_CONF_DEFAULT_HLS_NB_NOTIFY;
  3427 + }
  3428 +
  3429 + conf = conf->get("hls_nb_notify");
  3430 + if (!conf || conf->arg0().empty()) {
  3431 + return SRS_CONF_DEFAULT_HLS_NB_NOTIFY;
  3432 + }
  3433 +
  3434 + return ::atoi(conf->arg0().c_str());
  3435 +}
  3436 +
3437 bool SrsConfig::get_hls_cleanup(string vhost) 3437 bool SrsConfig::get_hls_cleanup(string vhost)
3438 { 3438 {
3439 SrsConfDirective* hls = get_hls(vhost); 3439 SrsConfDirective* hls = get_hls(vhost);
@@ -652,11 +652,6 @@ public: @@ -652,11 +652,6 @@ public:
652 * @return the on_hls_notify callback directive, the args is the url to callback. 652 * @return the on_hls_notify callback directive, the args is the url to callback.
653 */ 653 */
654 virtual SrsConfDirective* get_vhost_on_hls_notify(std::string vhost); 654 virtual SrsConfDirective* get_vhost_on_hls_notify(std::string vhost);
655 - /**  
656 - * get the size of bytes to read from cdn network, for the on_hls_notify callback,  
657 - * that is, to read max bytes of the bytes from the callback, or timeout or error.  
658 - */  
659 - virtual int get_vhost_hls_nb_notify(std::string vhost);  
660 // bwct(bandwidth check tool) section 655 // bwct(bandwidth check tool) section
661 public: 656 public:
662 /** 657 /**
@@ -965,8 +960,12 @@ public: @@ -965,8 +960,12 @@ public:
965 * whether cleanup the old ts files. 960 * whether cleanup the old ts files.
966 */ 961 */
967 virtual bool get_hls_cleanup(std::string vhost); 962 virtual bool get_hls_cleanup(std::string vhost);
968 -  
969 - // hds section 963 + /**
  964 + * get the size of bytes to read from cdn network, for the on_hls_notify callback,
  965 + * that is, to read max bytes of the bytes from the callback, or timeout or error.
  966 + */
  967 + virtual int get_vhost_hls_nb_notify(std::string vhost);
  968 +// hds section
970 private: 969 private:
971 /** 970 /**
972 * get the hds directive of vhost. 971 * get the hds directive of vhost.
@@ -42,6 +42,7 @@ using namespace std; @@ -42,6 +42,7 @@ using namespace std;
42 #define SRS_HTTP_RESPONSE_OK SRS_XSTR(ERROR_SUCCESS) 42 #define SRS_HTTP_RESPONSE_OK SRS_XSTR(ERROR_SUCCESS)
43 43
44 #define SRS_HTTP_HEADER_BUFFER 1024 44 #define SRS_HTTP_HEADER_BUFFER 1024
  45 +#define SRS_HTTP_READ_BUFFER 4096
45 #define SRS_HTTP_BODY_BUFFER 32 * 1024 46 #define SRS_HTTP_BODY_BUFFER 32 * 1024
46 47
47 // the timeout for hls notify, in us. 48 // the timeout for hls notify, in us.
@@ -363,15 +364,18 @@ int SrsHttpHooks::on_hls_notify(std::string url, SrsRequest* req, std::string ts @@ -363,15 +364,18 @@ int SrsHttpHooks::on_hls_notify(std::string url, SrsRequest* req, std::string ts
363 } 364 }
364 SrsAutoFree(SrsHttpMessage, msg); 365 SrsAutoFree(SrsHttpMessage, msg);
365 366
  367 + int nb_buf = srs_min(nb_notify, SRS_HTTP_READ_BUFFER);
  368 + char* buf = new char[nb_buf];
  369 + SrsAutoFree(char, buf);
  370 +
366 int nb_read = 0; 371 int nb_read = 0;
367 ISrsHttpResponseReader* br = msg->body_reader(); 372 ISrsHttpResponseReader* br = msg->body_reader();
368 while (nb_read < nb_notify && !br->eof()) { 373 while (nb_read < nb_notify && !br->eof()) {
369 - char buf[64]; // only read a little of bytes of ts.  
370 - int nb_buf = 64;  
371 - if ((ret = br->read(buf, nb_buf, &nb_buf)) != ERROR_SUCCESS) { 374 + int nb_bytes = 0;
  375 + if ((ret = br->read(buf, nb_buf, &nb_bytes)) != ERROR_SUCCESS) {
372 break; 376 break;
373 } 377 }
374 - nb_read += nb_buf; 378 + nb_read += nb_bytes;
375 } 379 }
376 380
377 int spenttime = (int)(srs_update_system_time_ms() - starttime); 381 int spenttime = (int)(srs_update_system_time_ms() - starttime);