winlin

Merge branch '2.0release' into develop

@@ -7,6 +7,7 @@ RMB 10000+ @@ -7,6 +7,7 @@ RMB 10000+
7 * [2015-03-03 13:25] 郭强 7 * [2015-03-03 13:25] 郭强
8 8
9 RMB 1000-9999 9 RMB 1000-9999
  10 +* [2015-04-29 09:20] 王光辉
10 * [2015-04-04 16:19] 蔡汉城 11 * [2015-04-04 16:19] 蔡汉城
11 12
12 RMB 500-999 13 RMB 500-999
@@ -780,7 +780,10 @@ vhost hooks.callback.srs.com { @@ -780,7 +780,10 @@ vhost hooks.callback.srs.com {
780 # "stream": "livestream", 780 # "stream": "livestream",
781 # "duration": 9.36, // in seconds 781 # "duration": 9.36, // in seconds
782 # "cwd": "/usr/local/srs", 782 # "cwd": "/usr/local/srs",
783 - # "file": "./objs/nginx/html/live/livestream.1420254068776-100.ts", 783 + # "file": "./objs/nginx/html/live/livestream/2015-04-23/01/476584165.ts",
  784 + # "url": "live/livestream/2015-04-23/01/476584165.ts",
  785 + # "m3u8": "./objs/nginx/html/live/livestream/live.m3u8",
  786 + # "m3u8_url": "live/livestream/live.m3u8",
784 # "seq_no": 100 787 # "seq_no": 100
785 # } 788 # }
786 # if valid, the hook must return HTTP code 200(Stauts OK) and response 789 # if valid, the hook must return HTTP code 200(Stauts OK) and response
  1 +if [[ $# -lt 2 ]]; then
  2 + echo "Usage: $0 <hls0> <hls1> [keep_ts]"
  3 + echo " keep_ts to keep the download ts, default is off"
  4 + echo "For example:"
  5 + echo " $0 http://192.168.1.137:1980/hls/live/stone/live.m3u8 http://192.168.1.137:1984/hls/live/stone/live.m3u8"
  6 + echo " $0 http://192.168.1.137:1980/hls/live/livestream/live.m3u8 http://192.168.1.137:1984/hls/live/livestream/live.m3u8"
  7 + echo " $0 http://ossrs.net:1984/hls/live/livestream/live.m3u8 http://ossrs.net:1996/hls/live/livestream/live.m3u8"
  8 + exit 1
  9 +fi
  10 +
  11 +hls0=$1
  12 +hls1=$2
  13 +keep_ts=NO
  14 +if [[ $# -gt 2 ]]; then
  15 + keep_ts=YES
  16 +fi
  17 +#echo "check hls backup of $hls0 vs $hls1, keep_ts=$keep_ts"
  18 +
  19 +hls0_tss=`curl $hls0 2>/dev/null |grep "\.ts"`
  20 +hls1_tss=`curl $hls1 2>/dev/null |grep "\.ts"`
  21 +
  22 +hls0_prefix=`dirname $hls0`
  23 +hls1_prefix=`dirname $hls1`
  24 +work_dir="./hbt_temp_`date +%s`"
  25 +
  26 +md5_tool="md5"
  27 +`md5sum --version >/dev/null 2>&1` && md5_tool="md5sum"
  28 +#echo "use md5 tool: $md5_tool"
  29 +
  30 +CHECKED=NO
  31 +OK=YES
  32 +for ts in $hls0_tss; do
  33 + match=NO
  34 + for ts1 in $hls1_tss; do
  35 + if [[ $ts == $ts1 ]]; then
  36 + #echo "check ts $ts"
  37 + match=YES
  38 + break
  39 + fi
  40 + done
  41 + #echo "check ts $ts, match=$match"
  42 +
  43 + if [ $match = NO ]; then
  44 + echo "skip $ts"
  45 + continue
  46 + fi
  47 +
  48 + ts0_uri=$hls0_prefix/$ts
  49 + ts1_uri=$hls1_prefix/$ts
  50 + ts0_tmp=$work_dir/hls0/`basename $ts`
  51 + ts1_tmp=$work_dir/hls1/`basename $ts`
  52 + #echo "start check $ts0_uri($ts0_tmp) vs $ts1_uri($ts1_tmp)"
  53 +
  54 + mkdir -p `dirname $ts0_tmp` &&
  55 + curl $ts0_uri >$ts0_tmp 2>/dev/null &&
  56 + ret=$?; if [[ $ret -ne 0 ]]; then echo "download $ts0_uri to $ts0_tmp failed. ret=$ret"; exit $ret; fi
  57 +
  58 + mkdir -p `dirname $ts1_tmp` &&
  59 + curl $ts1_uri >$ts1_tmp 2>/dev/null &&
  60 + ret=$?; if [[ $ret -ne 0 ]]; then echo "download $ts1_uri to $ts1_tmp failed. ret=$ret"; exit $ret; fi
  61 +
  62 + if [[ $md5_tool == "md5" ]]; then
  63 + ts0_cs=`$md5_tool $ts0_tmp|awk '{print $4}'`
  64 + else
  65 + ts0_cs=`$md5_tool $ts0_tmp|awk '{print $1}'`
  66 + fi
  67 + #echo "hls0: md5sum($ts0_tmp)=$ts0_cs"
  68 +
  69 + if [[ $md5_tool == "md5" ]]; then
  70 + ts1_cs=`$md5_tool $ts1_tmp|awk '{print $4}'`
  71 + else
  72 + ts1_cs=`$md5_tool $ts1_tmp|awk '{print $1}'`
  73 + fi
  74 + #echo "hls1: md5sum($ts1_tmp)=$ts1_cs"
  75 +
  76 + if [[ $ts0_cs != $ts1_cs ]]; then
  77 + echo "$ts0_uri($ts0_cs) not equals to $ts1_uri($ts1_cs)"
  78 + OK=NO
  79 + fi
  80 + CHECKED=YES
  81 +done
  82 +
  83 +if [ $keep_ts = NO ]; then
  84 + #echo "clenaup work dir $work_dir"
  85 + rm -rf $work_dir
  86 +else
  87 + echo "keep work dir $work_dir"
  88 +fi
  89 +
  90 +#echo "====================================================="
  91 +if [[ $OK = YES && $CHECKED = YES ]]; then
  92 + echo "OK"
  93 + exit 0
  94 +else
  95 + echo "FAILED"
  96 + exit 1
  97 +fi
  98 +
  99 +exit 0
@@ -2570,7 +2570,7 @@ bool SrsConfig::get_vhost_is_edge(SrsConfDirective* vhost) @@ -2570,7 +2570,7 @@ bool SrsConfig::get_vhost_is_edge(SrsConfDirective* vhost)
2570 return SRS_CONF_DEFAULT_EDGE_MODE; 2570 return SRS_CONF_DEFAULT_EDGE_MODE;
2571 } 2571 }
2572 2572
2573 - return SRS_CONF_PERFER_FALSE(conf->arg0()); 2573 + return conf->arg0() == "remote";
2574 } 2574 }
2575 2575
2576 SrsConfDirective* SrsConfig::get_vhost_edge_origin(string vhost) 2576 SrsConfDirective* SrsConfig::get_vhost_edge_origin(string vhost)
@@ -170,10 +170,13 @@ void SrsHlsSegment::update_duration(int64_t current_frame_dts) @@ -170,10 +170,13 @@ void SrsHlsSegment::update_duration(int64_t current_frame_dts)
170 return; 170 return;
171 } 171 }
172 172
173 -SrsDvrAsyncCallOnHls::SrsDvrAsyncCallOnHls(SrsRequest* r, string p, int s, double d) 173 +SrsDvrAsyncCallOnHls::SrsDvrAsyncCallOnHls(SrsRequest* r, string p, string t, string m, string mu, int s, double d)
174 { 174 {
175 req = r; 175 req = r;
176 path = p; 176 path = p;
  177 + ts_url = t;
  178 + m3u8 = m;
  179 + m3u8_url = mu;
177 seq_no = s; 180 seq_no = s;
178 duration = d; 181 duration = d;
179 } 182 }
@@ -200,7 +203,7 @@ int SrsDvrAsyncCallOnHls::call() @@ -200,7 +203,7 @@ int SrsDvrAsyncCallOnHls::call()
200 int sn = seq_no; 203 int sn = seq_no;
201 for (int i = 0; i < (int)on_hls->args.size(); i++) { 204 for (int i = 0; i < (int)on_hls->args.size(); i++) {
202 std::string url = on_hls->args.at(i); 205 std::string url = on_hls->args.at(i);
203 - if ((ret = SrsHttpHooks::on_hls(url, req, file, sn, duration)) != ERROR_SUCCESS) { 206 + if ((ret = SrsHttpHooks::on_hls(url, req, file, ts_url, m3u8, m3u8_url, sn, duration)) != ERROR_SUCCESS) {
204 srs_error("hook client on_hls failed. url=%s, ret=%d", url.c_str(), ret); 207 srs_error("hook client on_hls failed. url=%s, ret=%d", url.c_str(), ret);
205 return ret; 208 return ret;
206 } 209 }
@@ -361,8 +364,8 @@ int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix, @@ -361,8 +364,8 @@ int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix,
361 deviation_ts = 0; 364 deviation_ts = 0;
362 365
363 // generate the m3u8 dir and path. 366 // generate the m3u8 dir and path.
364 - m3u8 = path + "/" + m3u8_file;  
365 - m3u8 = srs_path_build_stream(m3u8, req->vhost, req->app, req->stream); 367 + m3u8_url = srs_path_build_stream(m3u8_file, req->vhost, req->app, req->stream);
  368 + m3u8 = path + "/" + m3u8_url;
366 369
367 // we always keep the target duration increasing. 370 // we always keep the target duration increasing.
368 int max_td = srs_max(target_duration, (int)(fragment * _srs_config->get_hls_td_ratio(r->vhost))); 371 int max_td = srs_max(target_duration, (int)(fragment * _srs_config->get_hls_td_ratio(r->vhost)));
@@ -664,7 +667,10 @@ int SrsHlsMuxer::segment_close(string log_desc) @@ -664,7 +667,10 @@ int SrsHlsMuxer::segment_close(string log_desc)
664 segments.push_back(current); 667 segments.push_back(current);
665 668
666 // use async to call the http hooks, for it will cause thread switch. 669 // use async to call the http hooks, for it will cause thread switch.
667 - if ((ret = async->call(new SrsDvrAsyncCallOnHls(req, current->full_path, current->sequence_no, current->duration))) != ERROR_SUCCESS) { 670 + if ((ret = async->call(new SrsDvrAsyncCallOnHls(req,
  671 + current->full_path, current->uri, m3u8, m3u8_url,
  672 + current->sequence_no, current->duration))) != ERROR_SUCCESS)
  673 + {
668 return ret; 674 return ret;
669 } 675 }
670 676
@@ -163,11 +163,14 @@ class SrsDvrAsyncCallOnHls : public ISrsDvrAsyncCall @@ -163,11 +163,14 @@ class SrsDvrAsyncCallOnHls : public ISrsDvrAsyncCall
163 { 163 {
164 private: 164 private:
165 std::string path; 165 std::string path;
  166 + std::string ts_url;
  167 + std::string m3u8;
  168 + std::string m3u8_url;
166 int seq_no; 169 int seq_no;
167 SrsRequest* req; 170 SrsRequest* req;
168 double duration; 171 double duration;
169 public: 172 public:
170 - SrsDvrAsyncCallOnHls(SrsRequest* r, std::string p, int s, double d); 173 + SrsDvrAsyncCallOnHls(SrsRequest* r, std::string p, std::string t, std::string m, std::string mu, int s, double d);
171 virtual ~SrsDvrAsyncCallOnHls(); 174 virtual ~SrsDvrAsyncCallOnHls();
172 public: 175 public:
173 virtual int call(); 176 virtual int call();
@@ -227,6 +230,7 @@ private: @@ -227,6 +230,7 @@ private:
227 int _sequence_no; 230 int _sequence_no;
228 int target_duration; 231 int target_duration;
229 std::string m3u8; 232 std::string m3u8;
  233 + std::string m3u8_url;
230 private: 234 private:
231 ISrsHlsHandler* handler; 235 ISrsHlsHandler* handler;
232 // TODO: FIXME: supports reload. 236 // TODO: FIXME: supports reload.
@@ -292,7 +292,7 @@ int SrsHttpHooks::on_dvr(string url, SrsRequest* req, string file) @@ -292,7 +292,7 @@ int SrsHttpHooks::on_dvr(string url, SrsRequest* req, string file)
292 return ret; 292 return ret;
293 } 293 }
294 294
295 -int SrsHttpHooks::on_hls(string url, SrsRequest* req, string file, int sn, double duration) 295 +int SrsHttpHooks::on_hls(string url, SrsRequest* req, string file, string ts_url, string m3u8, string m3u8_url, int sn, double duration)
296 { 296 {
297 int ret = ERROR_SUCCESS; 297 int ret = ERROR_SUCCESS;
298 298
@@ -310,6 +310,9 @@ int SrsHttpHooks::on_hls(string url, SrsRequest* req, string file, int sn, doubl @@ -310,6 +310,9 @@ int SrsHttpHooks::on_hls(string url, SrsRequest* req, string file, int sn, doubl
310 << SRS_JFIELD_ORG("duration", duration) << SRS_JFIELD_CONT 310 << SRS_JFIELD_ORG("duration", duration) << SRS_JFIELD_CONT
311 << SRS_JFIELD_STR("cwd", cwd) << SRS_JFIELD_CONT 311 << SRS_JFIELD_STR("cwd", cwd) << SRS_JFIELD_CONT
312 << SRS_JFIELD_STR("file", file) << SRS_JFIELD_CONT 312 << SRS_JFIELD_STR("file", file) << SRS_JFIELD_CONT
  313 + << SRS_JFIELD_STR("url", ts_url) << SRS_JFIELD_CONT
  314 + << SRS_JFIELD_STR("m3u8", m3u8) << SRS_JFIELD_CONT
  315 + << SRS_JFIELD_STR("m3u8_url", m3u8_url) << SRS_JFIELD_CONT
313 << SRS_JFIELD_ORG("seq_no", sn) 316 << SRS_JFIELD_ORG("seq_no", sn)
314 << SRS_JOBJECT_END; 317 << SRS_JOBJECT_END;
315 318
@@ -101,10 +101,13 @@ public: @@ -101,10 +101,13 @@ public:
101 * @param url the api server url, to process the event. 101 * @param url the api server url, to process the event.
102 * ignore if empty. 102 * ignore if empty.
103 * @param file the ts file path, can be relative or absolute path. 103 * @param file the ts file path, can be relative or absolute path.
  104 + * @param ts_url the ts url, which used for m3u8.
  105 + * @param m3u8 the m3u8 file path, can be relative or absolute path.
  106 + * @param m3u8_url the m3u8 url, which is used for the http mount path.
104 * @param sn the seq_no, the sequence number of ts in hls/m3u8. 107 * @param sn the seq_no, the sequence number of ts in hls/m3u8.
105 * @param duration the segment duration in seconds. 108 * @param duration the segment duration in seconds.
106 */ 109 */
107 - static int on_hls(std::string url, SrsRequest* req, std::string file, int sn, double duration); 110 + 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);
108 /** 111 /**
109 * when hls reap segment, callback. 112 * when hls reap segment, callback.
110 * @param url the api server url, to process the event. 113 * @param url the api server url, to process the event.
@@ -48,9 +48,6 @@ using namespace std; @@ -48,9 +48,6 @@ using namespace std;
48 #include <srs_rtmp_amf0.hpp> 48 #include <srs_rtmp_amf0.hpp>
49 #include <srs_raw_avc.hpp> 49 #include <srs_raw_avc.hpp>
50 50
51 -// the retry timeout in ms.  
52 -#define SRS_INGEST_HLS_ERROR_RETRY_MS 3000  
53 -  
54 // pre-declare 51 // pre-declare
55 int proxy_hls2rtmp(std::string hls, std::string rtmp); 52 int proxy_hls2rtmp(std::string hls, std::string rtmp);
56 53
@@ -217,7 +214,7 @@ private: @@ -217,7 +214,7 @@ private:
217 /** 214 /**
218 * fetch all ts body. 215 * fetch all ts body.
219 */ 216 */
220 - virtual void fetch_all_ts(bool fresh_m3u8); 217 + virtual int fetch_all_ts(bool fresh_m3u8);
221 /** 218 /**
222 * remove all ts which is dirty. 219 * remove all ts which is dirty.
223 */ 220 */
@@ -245,7 +242,10 @@ int SrsIngestSrsInput::connect() @@ -245,7 +242,10 @@ int SrsIngestSrsInput::connect()
245 } 242 }
246 243
247 // fetch all ts. 244 // fetch all ts.
248 - fetch_all_ts(fresh_m3u8); 245 + if ((ret = fetch_all_ts(fresh_m3u8)) != ERROR_SUCCESS) {
  246 + srs_error("fetch all ts failed. ret=%d", ret);
  247 + return ret;
  248 + }
249 249
250 // remove all dirty ts. 250 // remove all dirty ts.
251 remove_dirty(); 251 remove_dirty();
@@ -304,15 +304,9 @@ int SrsIngestSrsInput::parseTs(ISrsTsHandler* handler, char* body, int nb_body) @@ -304,15 +304,9 @@ int SrsIngestSrsInput::parseTs(ISrsTsHandler* handler, char* body, int nb_body)
304 304
305 // process each ts packet 305 // process each ts packet
306 if ((ret = context->decode(stream, handler)) != ERROR_SUCCESS) { 306 if ((ret = context->decode(stream, handler)) != ERROR_SUCCESS) {
307 - // when peer closed, must interrupt parse and reconnect.  
308 - if (srs_is_client_gracefully_close(ret)) {  
309 - srs_warn("interrupt parse for peer closed. ret=%d", ret); 307 + srs_error("mpegts: ignore parse ts packet failed. ret=%d", ret);
310 return ret; 308 return ret;
311 } 309 }
312 -  
313 - srs_warn("mpegts: ignore parse ts packet failed. ret=%d", ret);  
314 - continue;  
315 - }  
316 srs_info("mpegts: parse ts packet completed"); 310 srs_info("mpegts: parse ts packet completed");
317 } 311 }
318 srs_info("mpegts: parse udp packet completed"); 312 srs_info("mpegts: parse udp packet completed");
@@ -536,7 +530,7 @@ void SrsIngestSrsInput::dirty_all_ts() @@ -536,7 +530,7 @@ void SrsIngestSrsInput::dirty_all_ts()
536 } 530 }
537 } 531 }
538 532
539 -void SrsIngestSrsInput::fetch_all_ts(bool fresh_m3u8) 533 +int SrsIngestSrsInput::fetch_all_ts(bool fresh_m3u8)
540 { 534 {
541 int ret = ERROR_SUCCESS; 535 int ret = ERROR_SUCCESS;
542 536
@@ -555,9 +549,9 @@ void SrsIngestSrsInput::fetch_all_ts(bool fresh_m3u8) @@ -555,9 +549,9 @@ void SrsIngestSrsInput::fetch_all_ts(bool fresh_m3u8)
555 } 549 }
556 550
557 if ((ret = tp->fetch(in_hls->get_url())) != ERROR_SUCCESS) { 551 if ((ret = tp->fetch(in_hls->get_url())) != ERROR_SUCCESS) {
558 - srs_warn("ignore ts %s for error. ret=%d", tp->url.c_str(), ret); 552 + srs_error("fetch ts %s for error. ret=%d", tp->url.c_str(), ret);
559 tp->skip = true; 553 tp->skip = true;
560 - continue; 554 + return ret;
561 } 555 }
562 556
563 // only wait for a duration of last piece. 557 // only wait for a duration of last piece.
@@ -565,6 +559,8 @@ void SrsIngestSrsInput::fetch_all_ts(bool fresh_m3u8) @@ -565,6 +559,8 @@ void SrsIngestSrsInput::fetch_all_ts(bool fresh_m3u8)
565 next_connect_time = srs_update_system_time_ms() + (int)tp->duration * 1000; 559 next_connect_time = srs_update_system_time_ms() + (int)tp->duration * 1000;
566 } 560 }
567 } 561 }
  562 +
  563 + return ret;
568 } 564 }
569 565
570 566
@@ -779,10 +775,6 @@ int SrsIngestSrsOutput::on_ts_message(SrsTsMessage* msg) @@ -779,10 +775,6 @@ int SrsIngestSrsOutput::on_ts_message(SrsTsMessage* msg)
779 // we must use queue to cache the msg, then parse it if possible. 775 // we must use queue to cache the msg, then parse it if possible.
780 queue.insert(std::make_pair(msg->dts, msg->detach())); 776 queue.insert(std::make_pair(msg->dts, msg->detach()));
781 if ((ret = parse_message_queue()) != ERROR_SUCCESS) { 777 if ((ret = parse_message_queue()) != ERROR_SUCCESS) {
782 - // when peer closed, close the output and reconnect.  
783 - if (srs_is_client_gracefully_close(ret)) {  
784 - close();  
785 - }  
786 return ret; 778 return ret;
787 } 779 }
788 780
@@ -1204,6 +1196,7 @@ int SrsIngestSrsOutput::rtmp_write_packet(char type, u_int32_t timestamp, char* @@ -1204,6 +1196,7 @@ int SrsIngestSrsOutput::rtmp_write_packet(char type, u_int32_t timestamp, char*
1204 1196
1205 // send out encoded msg. 1197 // send out encoded msg.
1206 if ((ret = client->send_and_free_message(msg, stream_id)) != ERROR_SUCCESS) { 1198 if ((ret = client->send_and_free_message(msg, stream_id)) != ERROR_SUCCESS) {
  1199 + srs_error("send RTMP type=%d, dts=%d, size=%d failed. ret=%d", type, timestamp, size, ret);
1207 return ret; 1200 return ret;
1208 } 1201 }
1209 1202
@@ -1355,22 +1348,22 @@ public: @@ -1355,22 +1348,22 @@ public:
1355 int ret = ERROR_SUCCESS; 1348 int ret = ERROR_SUCCESS;
1356 1349
1357 if ((ret = ic->connect()) != ERROR_SUCCESS) { 1350 if ((ret = ic->connect()) != ERROR_SUCCESS) {
1358 - srs_warn("connect oc failed. ret=%d", ret); 1351 + srs_error("connect oc failed. ret=%d", ret);
1359 return ret; 1352 return ret;
1360 } 1353 }
1361 1354
1362 if ((ret = oc->connect()) != ERROR_SUCCESS) { 1355 if ((ret = oc->connect()) != ERROR_SUCCESS) {
1363 - srs_warn("connect ic failed. ret=%d", ret); 1356 + srs_error("connect ic failed. ret=%d", ret);
1364 return ret; 1357 return ret;
1365 } 1358 }
1366 1359
1367 if ((ret = ic->parse(oc, oc)) != ERROR_SUCCESS) { 1360 if ((ret = ic->parse(oc, oc)) != ERROR_SUCCESS) {
1368 - srs_warn("proxy ts to rtmp failed. ret=%d", ret); 1361 + srs_error("proxy ts to rtmp failed. ret=%d", ret);
1369 return ret; 1362 return ret;
1370 } 1363 }
1371 1364
1372 if ((ret = oc->flush_message_queue()) != ERROR_SUCCESS) { 1365 if ((ret = oc->flush_message_queue()) != ERROR_SUCCESS) {
1373 - srs_warn("flush oc message failed. ret=%d", ret); 1366 + srs_error("flush oc message failed. ret=%d", ret);
1374 return ret; 1367 return ret;
1375 } 1368 }
1376 1369
@@ -1400,12 +1393,10 @@ int proxy_hls2rtmp(string hls, string rtmp) @@ -1400,12 +1393,10 @@ int proxy_hls2rtmp(string hls, string rtmp)
1400 1393
1401 SrsIngestSrsContext context(&hls_uri, &rtmp_uri); 1394 SrsIngestSrsContext context(&hls_uri, &rtmp_uri);
1402 for (;;) { 1395 for (;;) {
1403 - if ((ret = context.proxy()) == ERROR_SUCCESS) {  
1404 - continue; 1396 + if ((ret = context.proxy()) != ERROR_SUCCESS) {
  1397 + srs_error("proxy hls to rtmp failed. ret=%d", ret);
  1398 + return ret;
1405 } 1399 }
1406 -  
1407 - srs_warn("proxy hls to rtmp failed. ret=%d", ret);  
1408 - st_usleep(SRS_INGEST_HLS_ERROR_RETRY_MS * 1000);  
1409 } 1400 }
1410 1401
1411 return ret; 1402 return ret;