winlin

for #179, revert dvr http api. 2.0.128.

@@ -513,8 +513,6 @@ Supported operating systems and hardware: @@ -513,8 +513,6 @@ Supported operating systems and hardware:
513 [#304](https://github.com/winlinvip/simple-rtmp-server/issues/304). 513 [#304](https://github.com/winlinvip/simple-rtmp-server/issues/304).
514 1. Support push RTSP to SRS, read 514 1. Support push RTSP to SRS, read
515 [#133](https://github.com/winlinvip/simple-rtmp-server/issues/133). 515 [#133](https://github.com/winlinvip/simple-rtmp-server/issues/133).
516 -1. Support DVR http api, read  
517 -[#179](https://github.com/winlinvip/simple-rtmp-server/issues/179).  
518 1. [no-plan] Support <500ms latency, FRSC(Fast RTMP-compatible Stream Channel tech). 516 1. [no-plan] Support <500ms latency, FRSC(Fast RTMP-compatible Stream Channel tech).
519 1. [no-plan] Support RTMP 302 redirect [#92](https://github.com/winlinvip/simple-rtmp-server/issues/92). 517 1. [no-plan] Support RTMP 302 redirect [#92](https://github.com/winlinvip/simple-rtmp-server/issues/92).
520 1. [no-plan] Support multiple processes, for both origin and edge 518 1. [no-plan] Support multiple processes, for both origin and edge
@@ -552,10 +550,9 @@ Supported operating systems and hardware: @@ -552,10 +550,9 @@ Supported operating systems and hardware:
552 ## History 550 ## History
553 551
554 ### SRS 2.0 history 552 ### SRS 2.0 history
555 -  
556 -* v2.0, 2015-02-24, for [#179](https://github.com/winlinvip/simple-rtmp-server/issues/179), dvr suport vhost/app/stream level control. 2.0.125.  
557 -* v2.0, 2015-02-24, for [#304](https://github.com/winlinvip/simple-rtmp-server/issues/304), fix hls bug, write pts/dts error. 2.0.124.  
558 -* v2.0, 2015-02-24, fix [#179](https://github.com/winlinvip/simple-rtmp-server/issues/179), support dvr http api. 2.0.123. 553 +.
  554 +* v2.0, 2015-03-01, for [#179](https://github.com/winlinvip/simple-rtmp-server/issues/179), revert dvr http api. 2.0.128.
  555 +* v2.0, 2015-02-24, for [#304](https://github.com/winlinvip/simple-rtmp-server/issues/304), fix hls bug, write pts/dts error. 2.0.124
559 * v2.0, 2015-02-19, refine dvr, append file when dvr file exists. 2.0.122. 556 * v2.0, 2015-02-19, refine dvr, append file when dvr file exists. 2.0.122.
560 * v2.0, 2015-02-19, refine pithy print to more easyer to use. 2.0.121. 557 * v2.0, 2015-02-19, refine pithy print to more easyer to use. 2.0.121.
561 * v2.0, 2015-02-18, fix [#133](https://github.com/winlinvip/simple-rtmp-server/issues/133), support push rtsp to srs. 2.0.120. 558 * v2.0, 2015-02-18, fix [#133](https://github.com/winlinvip/simple-rtmp-server/issues/133), support push rtsp to srs. 2.0.120.
@@ -288,52 +288,7 @@ vhost dvr.srs.com { @@ -288,52 +288,7 @@ vhost dvr.srs.com {
288 # session reap flv when session end(unpublish). 288 # session reap flv when session end(unpublish).
289 # segment reap flv when flv duration exceed the specified dvr_duration. 289 # segment reap flv when flv duration exceed the specified dvr_duration.
290 # append always append to flv file, never reap it. 290 # append always append to flv file, never reap it.
291 - # api reap flv when api required.  
292 - # about the api plan, the HTTP api to dvr,  
293 - # http url to control dvr, for example, http://dev:1985/api/v1/dvrs  
294 - # method=GET  
295 - # to query dvrs of server.  
296 - # request params, for example ?vhost=__defaultVhost__&&app=live&&stream=livestream, where:  
297 - # vhost, <required>, query all dvr of this vhost.  
298 - # app, [optinal], query all dvr of this app. query all app if not specified.  
299 - # stream, [optional], query specified dvr stream. query all stream if not specified.  
300 - # response in json, where:  
301 - # {code:0, dvrs: [{path_tmpl:"./[15].[04].[05].[999].flv", path_dvr:"./22.7.43.312.flv",  
302 - # vhost:"__defaultVhost", app:"live", stream:"livestream",  
303 - # wait_keyframe:true, callback:"http://127.0.0.1:8085/api/v1/dvrs",  
304 - # status:"stop"|"start"  
305 - # }]}  
306 - # method=POST  
307 - # to start dvr of specified vhost.  
308 - # request should encode in json, specifies the dvr to create, where:  
309 - # {path_tmpl:"./[15].[04].[05].[999].flv",  
310 - # vhost:"__defaultVhost", app:"live", stream:"livestream",  
311 - # wait_keyframe:true, callback:"http://127.0.0.1:8085/api/v1/dvrs"  
312 - # }  
313 - # @remark, the app and stream is required for POST.  
314 - # response in json, where:  
315 - # {code:0}  
316 - # method=DELETE, to stop dvr  
317 - # to stop dvr of specified vhost.  
318 - # request params, for example ?vhost=__defaultVhost__, where:  
319 - # vhost, stop all dvr of this vhost.  
320 - # response in json, where:  
321 - # {code:0}  
322 - # method=PUT, use as RPC(remote process call).  
323 - # reap_segment, the request params in json, where:  
324 - # {action:"reap_segment", vhost:"__defaultVhost", app:"live", stream:"livestream",  
325 - # path_tmpl:"./[15].[04].[05].[999].flv"  
326 - # }  
327 - # @remark, the app and stream is optional.  
328 - # when reap segment, the callback POST request in json:  
329 - # {action:"on_dvr_reap_segment", client_id:100, vhost:"__defaultVhost__",  
330 - # app:"live", stream:"livestream", cwd:"/home/winlin/srs", file:"./dvr.flv"  
331 - # }  
332 - # for the dvr http callback, @see http_hooks.on_dvr of vhost hooks.callback.srs.com  
333 - # @read https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_DVR#http-callback  
334 - # @read https://github.com/winlinvip/simple-rtmp-server/wiki/v2_EN_DVR#http-callback  
335 # default: session 291 # default: session
336 - # TODO: FIXME: update wiki for the api plan.  
337 dvr_plan session; 292 dvr_plan session;
338 # the dvr output path. 293 # the dvr output path.
339 # we supports some variables to generate the filename. 294 # we supports some variables to generate the filename.
@@ -369,27 +324,20 @@ vhost dvr.srs.com { @@ -369,27 +324,20 @@ vhost dvr.srs.com {
369 # @see https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_DVR#custom-path 324 # @see https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_DVR#custom-path
370 # @see https://github.com/winlinvip/simple-rtmp-server/wiki/v2_EN_DVR#custom-path 325 # @see https://github.com/winlinvip/simple-rtmp-server/wiki/v2_EN_DVR#custom-path
371 # segment,session apply it. 326 # segment,session apply it.
372 - # api apply before api specified the path.  
373 # default: ./objs/nginx/html 327 # default: ./objs/nginx/html
374 dvr_path ./objs/nginx/html; 328 dvr_path ./objs/nginx/html;
375 # the duration for dvr file, reap if exeed, in seconds. 329 # the duration for dvr file, reap if exeed, in seconds.
376 # segment apply it. 330 # segment apply it.
377 - # session,api ignore. 331 + # session,append ignore.
378 # default: 30 332 # default: 30
379 dvr_duration 30; 333 dvr_duration 30;
380 # whether wait keyframe to reap segment, 334 # whether wait keyframe to reap segment,
381 # if off, reap segment when duration exceed the dvr_duration, 335 # if off, reap segment when duration exceed the dvr_duration,
382 # if on, reap segment when duration exceed and got keyframe. 336 # if on, reap segment when duration exceed and got keyframe.
383 # segment apply it. 337 # segment apply it.
384 - # session,api ignore. 338 + # session,append ignore.
385 # default: on 339 # default: on
386 dvr_wait_keyframe on; 340 dvr_wait_keyframe on;
387 - # whether dvr auto start when publish.  
388 - # if off, dvr wait for api to start it.  
389 - # api apply it.  
390 - # segment,session ignore.  
391 - # default: on  
392 - dvr_autostart on;  
393 # about the stream monotonically increasing: 341 # about the stream monotonically increasing:
394 # 1. video timestamp is monotonically increasing, 342 # 1. video timestamp is monotonically increasing,
395 # 2. audio timestamp is monotonically increasing, 343 # 2. audio timestamp is monotonically increasing,
@@ -1418,7 +1418,6 @@ int SrsConfig::check_config() @@ -1418,7 +1418,6 @@ int SrsConfig::check_config()
1418 string m = conf->at(j)->name.c_str(); 1418 string m = conf->at(j)->name.c_str();
1419 if (m != "enabled" && m != "dvr_path" && m != "dvr_plan" 1419 if (m != "enabled" && m != "dvr_path" && m != "dvr_plan"
1420 && m != "dvr_duration" && m != "dvr_wait_keyframe" && m != "time_jitter" 1420 && m != "dvr_duration" && m != "dvr_wait_keyframe" && m != "time_jitter"
1421 - && m != "dvr_autostart"  
1422 ) { 1421 ) {
1423 ret = ERROR_SYSTEM_CONFIG_INVALID; 1422 ret = ERROR_SYSTEM_CONFIG_INVALID;
1424 srs_error("unsupported vhost dvr directive %s, ret=%d", m.c_str(), ret); 1423 srs_error("unsupported vhost dvr directive %s, ret=%d", m.c_str(), ret);
@@ -1977,41 +1976,6 @@ int SrsConfig::get_stream_caster_rtp_port_max(SrsConfDirective* sc) @@ -1977,41 +1976,6 @@ int SrsConfig::get_stream_caster_rtp_port_max(SrsConfDirective* sc)
1977 return ::atoi(conf->arg0().c_str()); 1976 return ::atoi(conf->arg0().c_str());
1978 } 1977 }
1979 1978
1980 -SrsConfDirective* SrsConfig::create_directive(string vhost, string directive, string sub_directive)  
1981 -{  
1982 - SrsConfDirective* vhost_conf = get_vhost(vhost);  
1983 -  
1984 - if (!vhost_conf) {  
1985 - vhost_conf = new SrsConfDirective();  
1986 - vhost_conf->name = vhost;  
1987 - root->directives.push_back(vhost_conf);  
1988 - }  
1989 -  
1990 - if (directive.empty()) {  
1991 - return vhost_conf;  
1992 - }  
1993 -  
1994 - SrsConfDirective* dir = vhost_conf->get(directive);  
1995 - if (!dir) {  
1996 - dir = new SrsConfDirective();  
1997 - dir->name = directive;  
1998 - vhost_conf->directives.push_back(dir);  
1999 - }  
2000 -  
2001 - if (sub_directive.empty()) {  
2002 - return dir;  
2003 - }  
2004 -  
2005 - SrsConfDirective* sdir = dir->get(sub_directive);  
2006 - if (!sdir) {  
2007 - sdir = new SrsConfDirective();  
2008 - sdir->name = sub_directive;  
2009 - dir->directives.push_back(sdir);  
2010 - }  
2011 -  
2012 - return sdir;  
2013 -}  
2014 -  
2015 SrsConfDirective* SrsConfig::get_vhost(string vhost) 1979 SrsConfDirective* SrsConfig::get_vhost(string vhost)
2016 { 1980 {
2017 srs_assert(root); 1981 srs_assert(root);
@@ -2355,13 +2319,6 @@ bool SrsConfig::get_vhost_http_hooks_enabled(string vhost) @@ -2355,13 +2319,6 @@ bool SrsConfig::get_vhost_http_hooks_enabled(string vhost)
2355 return true; 2319 return true;
2356 } 2320 }
2357 2321
2358 -void SrsConfig::set_vhost_http_hooks_enabled(string vhost, bool enabled)  
2359 -{  
2360 - SrsConfDirective* conf = create_directive(vhost, "http_hooks", "enabled");  
2361 - conf->args.clear();  
2362 - conf->args.push_back(enabled? "on":"off");  
2363 -}  
2364 -  
2365 SrsConfDirective* SrsConfig::get_vhost_on_connect(string vhost) 2322 SrsConfDirective* SrsConfig::get_vhost_on_connect(string vhost)
2366 { 2323 {
2367 SrsConfDirective* conf = get_vhost_http_hooks(vhost); 2324 SrsConfDirective* conf = get_vhost_http_hooks(vhost);
@@ -2439,13 +2396,6 @@ SrsConfDirective* SrsConfig::get_vhost_on_dvr(string vhost) @@ -2439,13 +2396,6 @@ SrsConfDirective* SrsConfig::get_vhost_on_dvr(string vhost)
2439 return conf->get("on_dvr"); 2396 return conf->get("on_dvr");
2440 } 2397 }
2441 2398
2442 -void SrsConfig::set_vhost_on_dvr(string vhost, string callback)  
2443 -{  
2444 - SrsConfDirective* conf = create_directive(vhost, "http_hooks", "on_dvr");  
2445 - conf->args.clear();  
2446 - conf->args.push_back(callback);  
2447 -}  
2448 -  
2449 bool SrsConfig::get_bw_check_enabled(string vhost) 2399 bool SrsConfig::get_bw_check_enabled(string vhost)
2450 { 2400 {
2451 SrsConfDirective* conf = get_vhost(vhost); 2401 SrsConfDirective* conf = get_vhost(vhost);
@@ -3359,13 +3309,6 @@ bool SrsConfig::get_dvr_enabled(string vhost) @@ -3359,13 +3309,6 @@ bool SrsConfig::get_dvr_enabled(string vhost)
3359 return false; 3309 return false;
3360 } 3310 }
3361 3311
3362 -void SrsConfig::set_dvr_enabled(string vhost, bool enabled)  
3363 -{  
3364 - SrsConfDirective* conf = create_directive(vhost, "dvr", "enabled");  
3365 - conf->args.clear();  
3366 - conf->args.push_back(enabled? "on":"off");  
3367 -}  
3368 -  
3369 string SrsConfig::get_dvr_path(string vhost) 3312 string SrsConfig::get_dvr_path(string vhost)
3370 { 3313 {
3371 SrsConfDirective* dvr = get_dvr(vhost); 3314 SrsConfDirective* dvr = get_dvr(vhost);
@@ -3383,13 +3326,6 @@ string SrsConfig::get_dvr_path(string vhost) @@ -3383,13 +3326,6 @@ string SrsConfig::get_dvr_path(string vhost)
3383 return conf->arg0(); 3326 return conf->arg0();
3384 } 3327 }
3385 3328
3386 -void SrsConfig::set_dvr_path(string vhost, string path)  
3387 -{  
3388 - SrsConfDirective* conf = create_directive(vhost, "dvr", "dvr_path");  
3389 - conf->args.clear();  
3390 - conf->args.push_back(path);  
3391 -}  
3392 -  
3393 string SrsConfig::get_dvr_plan(string vhost) 3329 string SrsConfig::get_dvr_plan(string vhost)
3394 { 3330 {
3395 SrsConfDirective* dvr = get_dvr(vhost); 3331 SrsConfDirective* dvr = get_dvr(vhost);
@@ -3407,13 +3343,6 @@ string SrsConfig::get_dvr_plan(string vhost) @@ -3407,13 +3343,6 @@ string SrsConfig::get_dvr_plan(string vhost)
3407 return conf->arg0(); 3343 return conf->arg0();
3408 } 3344 }
3409 3345
3410 -void SrsConfig::set_dvr_plan(string vhost, string plan)  
3411 -{  
3412 - SrsConfDirective* conf = create_directive(vhost, "dvr", "dvr_plan");  
3413 - conf->args.clear();  
3414 - conf->args.push_back(plan);  
3415 -}  
3416 -  
3417 int SrsConfig::get_dvr_duration(string vhost) 3346 int SrsConfig::get_dvr_duration(string vhost)
3418 { 3347 {
3419 SrsConfDirective* dvr = get_dvr(vhost); 3348 SrsConfDirective* dvr = get_dvr(vhost);
@@ -3448,30 +3377,6 @@ bool SrsConfig::get_dvr_wait_keyframe(string vhost) @@ -3448,30 +3377,6 @@ bool SrsConfig::get_dvr_wait_keyframe(string vhost)
3448 return false; 3377 return false;
3449 } 3378 }
3450 3379
3451 -void SrsConfig::set_dvr_wait_keyframe(string vhost, bool wait_keyframe)  
3452 -{  
3453 - SrsConfDirective* conf = create_directive(vhost, "dvr", "dvr_wait_keyframe");  
3454 - conf->args.clear();  
3455 - conf->args.push_back(wait_keyframe? "on":"off");  
3456 -}  
3457 -  
3458 -bool SrsConfig::get_dvr_autostart(string vhost)  
3459 -{  
3460 - SrsConfDirective* dvr = get_dvr(vhost);  
3461 -  
3462 - if (!dvr) {  
3463 - return true;  
3464 - }  
3465 -  
3466 - SrsConfDirective* conf = dvr->get("dvr_autostart");  
3467 -  
3468 - if (!conf || conf->arg0() != "off") {  
3469 - return true;  
3470 - }  
3471 -  
3472 - return false;  
3473 -}  
3474 -  
3475 int SrsConfig::get_dvr_time_jitter(string vhost) 3380 int SrsConfig::get_dvr_time_jitter(string vhost)
3476 { 3381 {
3477 SrsConfDirective* dvr = get_dvr(vhost); 3382 SrsConfDirective* dvr = get_dvr(vhost);
@@ -61,7 +61,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -61,7 +61,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
61 #define SRS_CONF_DEFAULT_DVR_PLAN_SESSION "session" 61 #define SRS_CONF_DEFAULT_DVR_PLAN_SESSION "session"
62 #define SRS_CONF_DEFAULT_DVR_PLAN_SEGMENT "segment" 62 #define SRS_CONF_DEFAULT_DVR_PLAN_SEGMENT "segment"
63 #define SRS_CONF_DEFAULT_DVR_PLAN_APPEND "append" 63 #define SRS_CONF_DEFAULT_DVR_PLAN_APPEND "append"
64 -#define SRS_CONF_DEFAULT_DVR_PLAN_API "api"  
65 #define SRS_CONF_DEFAULT_DVR_PLAN SRS_CONF_DEFAULT_DVR_PLAN_SESSION 64 #define SRS_CONF_DEFAULT_DVR_PLAN SRS_CONF_DEFAULT_DVR_PLAN_SESSION
66 #define SRS_CONF_DEFAULT_DVR_DURATION 30 65 #define SRS_CONF_DEFAULT_DVR_DURATION 30
67 #define SRS_CONF_DEFAULT_TIME_JITTER "full" 66 #define SRS_CONF_DEFAULT_TIME_JITTER "full"
@@ -452,14 +451,6 @@ public: @@ -452,14 +451,6 @@ public:
452 * get the max udp port for rtp of stream caster rtsp. 451 * get the max udp port for rtp of stream caster rtsp.
453 */ 452 */
454 virtual int get_stream_caster_rtp_port_max(SrsConfDirective* sc); 453 virtual int get_stream_caster_rtp_port_max(SrsConfDirective* sc);
455 -private:  
456 - /**  
457 - * create directive under vhost.  
458 - * @param directive, get the directive of vhost. get vhost if directive is empty.  
459 - * @param sub_directive, get the sub directive of vhost. get directive if sub-directive is empty.  
460 - * @return the vhost(empty directive and sub-directive); the directive(empty sub-directive); the sub-directive.  
461 - */  
462 - virtual SrsConfDirective* create_directive(std::string vhost, std::string directive, std::string sub_directive);  
463 // vhost specified section 454 // vhost specified section
464 public: 455 public:
465 /** 456 /**
@@ -596,7 +587,6 @@ public: @@ -596,7 +587,6 @@ public:
596 * @remark, if not enabled, donot callback all http hooks. 587 * @remark, if not enabled, donot callback all http hooks.
597 */ 588 */
598 virtual bool get_vhost_http_hooks_enabled(std::string vhost); 589 virtual bool get_vhost_http_hooks_enabled(std::string vhost);
599 - virtual void set_vhost_http_hooks_enabled(std::string vhost, bool enabled);  
600 /** 590 /**
601 * get the on_connect callbacks of vhost. 591 * get the on_connect callbacks of vhost.
602 * @return the on_connect callback directive, the args is the url to callback. 592 * @return the on_connect callback directive, the args is the url to callback.
@@ -632,7 +622,6 @@ public: @@ -632,7 +622,6 @@ public:
632 * @return the on_dvr callback directive, the args is the url to callback. 622 * @return the on_dvr callback directive, the args is the url to callback.
633 */ 623 */
634 virtual SrsConfDirective* get_vhost_on_dvr(std::string vhost); 624 virtual SrsConfDirective* get_vhost_on_dvr(std::string vhost);
635 - virtual void set_vhost_on_dvr(std::string vhost, std::string callback);  
636 // bwct(bandwidth check tool) section 625 // bwct(bandwidth check tool) section
637 public: 626 public:
638 /** 627 /**
@@ -925,17 +914,14 @@ public: @@ -925,17 +914,14 @@ public:
925 * whether dvr is enabled. 914 * whether dvr is enabled.
926 */ 915 */
927 virtual bool get_dvr_enabled(std::string vhost); 916 virtual bool get_dvr_enabled(std::string vhost);
928 - virtual void set_dvr_enabled(std::string vhost, bool enabled);  
929 /** 917 /**
930 * get the dvr path, the flv file to save in. 918 * get the dvr path, the flv file to save in.
931 */ 919 */
932 virtual std::string get_dvr_path(std::string vhost); 920 virtual std::string get_dvr_path(std::string vhost);
933 - virtual void set_dvr_path(std::string vhost, std::string path);  
934 /** 921 /**
935 * get the plan of dvr, how to reap the flv file. 922 * get the plan of dvr, how to reap the flv file.
936 */ 923 */
937 virtual std::string get_dvr_plan(std::string vhost); 924 virtual std::string get_dvr_plan(std::string vhost);
938 - virtual void set_dvr_plan(std::string vhost, std::string plan);  
939 /** 925 /**
940 * get the duration of dvr flv. 926 * get the duration of dvr flv.
941 */ 927 */
@@ -944,11 +930,6 @@ public: @@ -944,11 +930,6 @@ public:
944 * whether wait keyframe to reap segment. 930 * whether wait keyframe to reap segment.
945 */ 931 */
946 virtual bool get_dvr_wait_keyframe(std::string vhost); 932 virtual bool get_dvr_wait_keyframe(std::string vhost);
947 - virtual void set_dvr_wait_keyframe(std::string vhost, bool wait_keyframe);  
948 - /**  
949 - * whether autostart for dvr. wait api to start dvr if false.  
950 - */  
951 - virtual bool get_dvr_autostart(std::string vhost);  
952 /** 933 /**
953 * get the time_jitter algorithm for dvr. 934 * get the time_jitter algorithm for dvr.
954 */ 935 */
@@ -785,17 +785,6 @@ SrsDvrPlan* SrsDvrPlan::create_plan(string vhost) @@ -785,17 +785,6 @@ SrsDvrPlan* SrsDvrPlan::create_plan(string vhost)
785 return new SrsDvrSessionPlan(); 785 return new SrsDvrSessionPlan();
786 } else if (plan == SRS_CONF_DEFAULT_DVR_PLAN_APPEND) { 786 } else if (plan == SRS_CONF_DEFAULT_DVR_PLAN_APPEND) {
787 return new SrsDvrAppendPlan(); 787 return new SrsDvrAppendPlan();
788 - } else if (plan == SRS_CONF_DEFAULT_DVR_PLAN_API) {  
789 - /**  
790 - * @remark the api plan maybe create by publish event or http api post create dvr event.  
791 - * so when we got from pool first when create it.  
792 - */  
793 - SrsApiDvrPool* pool = SrsApiDvrPool::instance();  
794 - SrsDvrApiPlan* plan = pool->get_dvr(vhost);  
795 - if (plan) {  
796 - return plan;  
797 - }  
798 - return new SrsDvrApiPlan();  
799 } else { 788 } else {
800 srs_error("invalid dvr plan=%s, vhost=%s", plan.c_str(), vhost.c_str()); 789 srs_error("invalid dvr plan=%s, vhost=%s", plan.c_str(), vhost.c_str());
801 srs_assert(false); 790 srs_assert(false);
@@ -852,318 +841,6 @@ void SrsDvrSessionPlan::on_unpublish() @@ -852,318 +841,6 @@ void SrsDvrSessionPlan::on_unpublish()
852 dvr_enabled = false; 841 dvr_enabled = false;
853 } 842 }
854 843
855 -SrsDvrApiPlan::SrsDvrApiPlan()  
856 -{  
857 - autostart = false;  
858 - started = false;  
859 -  
860 - metadata = sh_audio = sh_video = NULL;  
861 -}  
862 -  
863 -SrsDvrApiPlan::~SrsDvrApiPlan()  
864 -{  
865 - SrsApiDvrPool* pool = SrsApiDvrPool::instance();  
866 - pool->detach_dvr(this);  
867 -  
868 - srs_freep(metadata);  
869 - srs_freep(sh_audio);  
870 - srs_freep(sh_video);  
871 -}  
872 -  
873 -int SrsDvrApiPlan::initialize(SrsRequest* r)  
874 -{  
875 - int ret = ERROR_SUCCESS;  
876 -  
877 - if ((ret = SrsDvrPlan::initialize(r)) != ERROR_SUCCESS) {  
878 - return ret;  
879 - }  
880 -  
881 - SrsApiDvrPool* pool = SrsApiDvrPool::instance();  
882 - if ((ret = pool->add_dvr(this)) != ERROR_SUCCESS) {  
883 - return ret;  
884 - }  
885 -  
886 - autostart = _srs_config->get_dvr_autostart(r->vhost);  
887 -  
888 - return ret;  
889 -}  
890 -  
891 -int SrsDvrApiPlan::on_publish()  
892 -{  
893 - int ret = ERROR_SUCCESS;  
894 -  
895 - // support multiple publish.  
896 - if (dvr_enabled) {  
897 - return ret;  
898 - }  
899 -  
900 - if (!_srs_config->get_dvr_enabled(req->vhost)) {  
901 - return ret;  
902 - }  
903 -  
904 - // api disabled dvr when not autostart.  
905 - bool autostart = _srs_config->get_dvr_autostart(req->vhost);  
906 - if (!autostart && !started) {  
907 - srs_warn("dvr: api not start and disabled for not autostart.");  
908 - return ret;  
909 - }  
910 -  
911 - dvr_enabled = true;  
912 -  
913 - if ((ret = segment->close()) != ERROR_SUCCESS) {  
914 - return ret;  
915 - }  
916 -  
917 - if ((ret = segment->open()) != ERROR_SUCCESS) {  
918 - return ret;  
919 - }  
920 -  
921 - // update sequence header  
922 - if (metadata && (ret = SrsDvrPlan::on_meta_data(metadata)) != ERROR_SUCCESS) {  
923 - return ret;  
924 - }  
925 - if (sh_video && (ret = SrsDvrPlan::on_video(sh_video)) != ERROR_SUCCESS) {  
926 - return ret;  
927 - }  
928 - if (sh_audio && (ret = SrsDvrPlan::on_audio(sh_audio)) != ERROR_SUCCESS) {  
929 - return ret;  
930 - }  
931 -  
932 - return ret;  
933 -}  
934 -  
935 -void SrsDvrApiPlan::on_unpublish()  
936 -{  
937 -}  
938 -  
939 -int SrsDvrApiPlan::on_meta_data(SrsSharedPtrMessage* __metadata)  
940 -{  
941 - int ret = ERROR_SUCCESS;  
942 -  
943 - srs_freep(metadata);  
944 - metadata = __metadata->copy();  
945 -  
946 - return ret;  
947 -}  
948 -  
949 -int SrsDvrApiPlan::on_audio(SrsSharedPtrMessage* __audio)  
950 -{  
951 - int ret = ERROR_SUCCESS;  
952 -  
953 - if (SrsFlvCodec::audio_is_sequence_header(__audio->payload, __audio->size)) {  
954 - srs_freep(sh_audio);  
955 - sh_audio = __audio->copy();  
956 - }  
957 -  
958 - if ((ret = SrsDvrPlan::on_audio(__audio)) != ERROR_SUCCESS) {  
959 - return ret;  
960 - }  
961 -  
962 - return ret;  
963 -}  
964 -  
965 -int SrsDvrApiPlan::on_video(SrsSharedPtrMessage* __video)  
966 -{  
967 - int ret = ERROR_SUCCESS;  
968 -  
969 - if (SrsFlvCodec::video_is_sequence_header(__video->payload, __video->size)) {  
970 - srs_freep(sh_video);  
971 - sh_video = __video->copy();  
972 - }  
973 -  
974 - if ((ret = check_user_actions(__video)) != ERROR_SUCCESS) {  
975 - return ret;  
976 - }  
977 -  
978 - if ((ret = SrsDvrPlan::on_video(__video)) != ERROR_SUCCESS) {  
979 - return ret;  
980 - }  
981 -  
982 - return ret;  
983 -}  
984 -  
985 -int SrsDvrApiPlan::set_plan()  
986 -{  
987 - _srs_config->set_dvr_plan(req->vhost, SRS_CONF_DEFAULT_DVR_PLAN_API);  
988 - return ERROR_SUCCESS;  
989 -}  
990 -  
991 -int SrsDvrApiPlan::set_path_tmpl(string path_tmpl)  
992 -{  
993 - _srs_config->set_dvr_path(req->vhost, path_tmpl);  
994 - return ERROR_SUCCESS;  
995 -}  
996 -  
997 -int SrsDvrApiPlan::set_callback(string value)  
998 -{  
999 - _srs_config->set_vhost_http_hooks_enabled(req->vhost, true);  
1000 - _srs_config->set_vhost_on_dvr(req->vhost, value);  
1001 - return ERROR_SUCCESS;  
1002 -}  
1003 -  
1004 -int SrsDvrApiPlan::set_wait_keyframe(bool wait_keyframe)  
1005 -{  
1006 - _srs_config->set_dvr_wait_keyframe(req->vhost, wait_keyframe);  
1007 - return ERROR_SUCCESS;  
1008 -}  
1009 -  
1010 -int SrsDvrApiPlan::start()  
1011 -{  
1012 - int ret = ERROR_SUCCESS;  
1013 -  
1014 - if (started) {  
1015 - return ret;  
1016 - }  
1017 -  
1018 - // enable the config.  
1019 - _srs_config->set_dvr_enabled(req->vhost, true);  
1020 -  
1021 - // stop dvr  
1022 - if (dvr_enabled) {  
1023 - // ignore error.  
1024 - int ret = segment->close();  
1025 - if (ret != ERROR_SUCCESS) {  
1026 - srs_warn("ignore flv close error. ret=%d", ret);  
1027 - }  
1028 -  
1029 - dvr_enabled = false;  
1030 - }  
1031 -  
1032 - // start dvr  
1033 - if ((ret = on_publish()) != ERROR_SUCCESS) {  
1034 - return ret;  
1035 - }  
1036 -  
1037 - started = true;  
1038 - return ret;  
1039 -}  
1040 -  
1041 -int SrsDvrApiPlan::dumps(stringstream& ss)  
1042 -{  
1043 - int ret = ERROR_SUCCESS;  
1044 -  
1045 - bool wait_keyframe = _srs_config->get_dvr_wait_keyframe(req->vhost);  
1046 - std::string path_template = _srs_config->get_dvr_path(req->vhost);  
1047 - SrsConfDirective* callbacks = _srs_config->get_vhost_on_dvr(req->vhost);  
1048 -  
1049 - ss << __SRS_JOBJECT_START  
1050 - << __SRS_JFIELD_STR("path_tmpl", path_template) << __SRS_JFIELD_CONT  
1051 - << __SRS_JFIELD_STR("path_dvr", segment->get_path()) << __SRS_JFIELD_CONT  
1052 - << __SRS_JFIELD_BOOL("wait_keyframe", wait_keyframe) << __SRS_JFIELD_CONT  
1053 - << __SRS_JFIELD_STR("vhost", req->vhost) << __SRS_JFIELD_CONT  
1054 - << __SRS_JFIELD_STR("app", req->app) << __SRS_JFIELD_CONT  
1055 - << __SRS_JFIELD_STR("stream", req->stream) << __SRS_JFIELD_CONT  
1056 - << __SRS_JFIELD_STR("callback", callbacks->arg0()) << __SRS_JFIELD_CONT  
1057 - << __SRS_JFIELD_STR("status", (dvr_enabled? "start":"stop"))  
1058 - << __SRS_JOBJECT_END;  
1059 -  
1060 - return ret;  
1061 -}  
1062 -  
1063 -int SrsDvrApiPlan::stop()  
1064 -{  
1065 - int ret = ERROR_SUCCESS;  
1066 -  
1067 - _srs_config->set_dvr_enabled(req->vhost, false);  
1068 - started = false;  
1069 -  
1070 - // stop dvr  
1071 - if (dvr_enabled) {  
1072 - // ignore error.  
1073 - int ret = segment->close();  
1074 - if (ret != ERROR_SUCCESS) {  
1075 - srs_warn("ignore flv close error. ret=%d", ret);  
1076 - }  
1077 -  
1078 - dvr_enabled = false;  
1079 - }  
1080 -  
1081 - srs_trace("dvr: stop dvr of vhost=%s", req->vhost.c_str());  
1082 -  
1083 - return ret;  
1084 -}  
1085 -  
1086 -int SrsDvrApiPlan::rpc(SrsJsonObject* obj)  
1087 -{  
1088 - int ret = ERROR_SUCCESS;  
1089 -  
1090 - SrsJsonAny* prop = NULL;  
1091 - if ((prop = obj->ensure_property_string("action")) == NULL) {  
1092 - ret = ERROR_HTTP_DVR_REQUEST;  
1093 - srs_error("dvr: rpc required action request. ret=%d", ret);  
1094 - return ret;  
1095 - }  
1096 -  
1097 - action = prop->to_str();  
1098 - if (action == SRS_DVR_USER_ACTION_REAP_SEGMENT) {  
1099 - if ((prop = obj->ensure_property_string("path_tmpl")) != NULL) {  
1100 - path_template = prop->to_str();  
1101 - }  
1102 - } else {  
1103 - ret = ERROR_HTTP_DVR_REQUEST;  
1104 - }  
1105 -  
1106 - return ret;  
1107 -}  
1108 -  
1109 -int SrsDvrApiPlan::check_user_actions(SrsSharedPtrMessage* msg)  
1110 -{  
1111 - int ret = ERROR_SUCCESS;  
1112 -  
1113 - srs_assert(segment);  
1114 -  
1115 - if (action == SRS_DVR_USER_ACTION_REAP_SEGMENT) {  
1116 - // when wait keyframe, ignore if no frame arrived.  
1117 - // @see https://github.com/winlinvip/simple-rtmp-server/issues/177  
1118 - if (_srs_config->get_dvr_wait_keyframe(req->vhost)) {  
1119 - if (!msg->is_video()) {  
1120 - return ret;  
1121 - }  
1122 -  
1123 - char* payload = msg->payload;  
1124 - int size = msg->size;  
1125 - bool is_key_frame = SrsFlvCodec::video_is_h264(payload, size)  
1126 - && SrsFlvCodec::video_is_keyframe(payload, size)  
1127 - && !SrsFlvCodec::video_is_sequence_header(payload, size);  
1128 - if (!is_key_frame) {  
1129 - return ret;  
1130 - }  
1131 - }  
1132 -  
1133 - // reap segment  
1134 - if ((ret = segment->close()) != ERROR_SUCCESS) {  
1135 - return ret;  
1136 - }  
1137 -  
1138 - // use new path template if user specified.  
1139 - if (!path_template.empty() && (ret = set_path_tmpl(path_template)) != ERROR_SUCCESS) {  
1140 - return ret;  
1141 - }  
1142 -  
1143 - // open new flv file  
1144 - if ((ret = segment->open()) != ERROR_SUCCESS) {  
1145 - return ret;  
1146 - }  
1147 -  
1148 - // update sequence header  
1149 - if (metadata && (ret = SrsDvrPlan::on_meta_data(metadata)) != ERROR_SUCCESS) {  
1150 - return ret;  
1151 - }  
1152 - if (sh_video && (ret = SrsDvrPlan::on_video(sh_video)) != ERROR_SUCCESS) {  
1153 - return ret;  
1154 - }  
1155 - if (sh_audio && (ret = SrsDvrPlan::on_audio(sh_audio)) != ERROR_SUCCESS) {  
1156 - return ret;  
1157 - }  
1158 - }  
1159 -  
1160 - // reset rcp params.  
1161 - action = "";  
1162 - path_template = "";  
1163 -  
1164 - return ret;  
1165 -}  
1166 -  
1167 SrsDvrAppendPlan::SrsDvrAppendPlan() 844 SrsDvrAppendPlan::SrsDvrAppendPlan()
1168 { 845 {
1169 last_update_time = 0; 846 last_update_time = 0;
@@ -1420,290 +1097,6 @@ int SrsDvrSegmentPlan::update_duration(SrsSharedPtrMessage* msg) @@ -1420,290 +1097,6 @@ int SrsDvrSegmentPlan::update_duration(SrsSharedPtrMessage* msg)
1420 return ret; 1097 return ret;
1421 } 1098 }
1422 1099
1423 -SrsApiDvrPool* SrsApiDvrPool::_instance = new SrsApiDvrPool();  
1424 -  
1425 -SrsApiDvrPool* SrsApiDvrPool::instance()  
1426 -{  
1427 - return SrsApiDvrPool::_instance;  
1428 -}  
1429 -  
1430 -SrsApiDvrPool::SrsApiDvrPool()  
1431 -{  
1432 -}  
1433 -  
1434 -SrsApiDvrPool::~SrsApiDvrPool()  
1435 -{  
1436 - dvrs.clear();  
1437 -}  
1438 -  
1439 -SrsDvrApiPlan* SrsApiDvrPool::get_dvr(string vhost)  
1440 -{  
1441 - std::vector<SrsDvrApiPlan*>::iterator it;  
1442 - for (it = dvrs.begin(); it != dvrs.end(); ++it) {  
1443 - SrsDvrApiPlan* plan = *it;  
1444 - if (plan->req->vhost == vhost) {  
1445 - return plan;  
1446 - }  
1447 - }  
1448 -  
1449 - return NULL;  
1450 -}  
1451 -  
1452 -int SrsApiDvrPool::add_dvr(SrsDvrApiPlan* dvr)  
1453 -{  
1454 - dvrs.push_back(dvr);  
1455 - return ERROR_SUCCESS;  
1456 -}  
1457 -  
1458 -void SrsApiDvrPool::detach_dvr(SrsDvrApiPlan* dvr)  
1459 -{  
1460 - std::vector<SrsDvrApiPlan*>::iterator it;  
1461 - it = ::find(dvrs.begin(), dvrs.end(), dvr);  
1462 -  
1463 - if (it != dvrs.end()) {  
1464 - dvrs.erase(it);  
1465 - }  
1466 -}  
1467 -  
1468 -int SrsApiDvrPool::dumps(string vhost, string app, string stream, stringstream& ss)  
1469 -{  
1470 - int ret = ERROR_SUCCESS;  
1471 -  
1472 - ss << __SRS_JARRAY_START;  
1473 -  
1474 - std::vector<SrsDvrApiPlan*> plans;  
1475 - for (int i = 0; i < (int)dvrs.size(); i++) {  
1476 - SrsDvrApiPlan* plan = dvrs.at(i);  
1477 - if (!vhost.empty() && plan->req->vhost != vhost) {  
1478 - continue;  
1479 - }  
1480 - if (!app.empty() && plan->req->app != app) {  
1481 - continue;  
1482 - }  
1483 - if (!stream.empty() && plan->req->stream != stream) {  
1484 - continue;  
1485 - }  
1486 - plans.push_back(plan);  
1487 - }  
1488 -  
1489 - for (int i = 0; i < (int)plans.size(); i++) {  
1490 - SrsDvrApiPlan* plan = plans.at(i);  
1491 -  
1492 - if ((ret = plan->dumps(ss)) != ERROR_SUCCESS) {  
1493 - return ret;  
1494 - }  
1495 -  
1496 - if (i < (int)plans.size() - 1) {  
1497 - ss << __SRS_JFIELD_CONT;  
1498 - }  
1499 - }  
1500 -  
1501 - ss << __SRS_JARRAY_END;  
1502 -  
1503 - return ret;  
1504 -}  
1505 -  
1506 -int SrsApiDvrPool::create(SrsJsonAny* json)  
1507 -{  
1508 - int ret = ERROR_SUCCESS;  
1509 -  
1510 - srs_assert(json);  
1511 - if (!json->is_object()) {  
1512 - ret = ERROR_HTTP_DVR_CREATE_REQUEST;  
1513 - srs_error("dvr: api create dvr request requires json object. ret=%d", ret);  
1514 - return ret;  
1515 - }  
1516 -  
1517 - SrsJsonObject* obj = json->to_object();  
1518 - SrsJsonAny* prop = NULL;  
1519 - if ((prop = obj->ensure_property_string("vhost")) == NULL) {  
1520 - ret = ERROR_HTTP_DVR_CREATE_REQUEST;  
1521 - srs_error("dvr: api create dvr request requires vhost. ret=%d", ret);  
1522 - return ret;  
1523 - }  
1524 - std::string vhost = prop->to_str();  
1525 -  
1526 - if ((prop = obj->ensure_property_string("app")) == NULL) {  
1527 - ret = ERROR_HTTP_DVR_CREATE_REQUEST;  
1528 - srs_error("dvr: api create dvr request requires app. ret=%d", ret);  
1529 - return ret;  
1530 - }  
1531 - std::string app = prop->to_str();  
1532 -  
1533 - if ((prop = obj->ensure_property_string("stream")) == NULL) {  
1534 - ret = ERROR_HTTP_DVR_CREATE_REQUEST;  
1535 - srs_error("dvr: api create dvr request requires stream. ret=%d", ret);  
1536 - return ret;  
1537 - }  
1538 - std::string stream = prop->to_str();  
1539 -  
1540 - if (vhost.empty() || app.empty() || stream.empty()) {  
1541 - ret = ERROR_HTTP_DVR_CREATE_REQUEST;  
1542 - srs_error("dvr: api create dvr request requires vhost/app/stream. ret=%d", ret);  
1543 - return ret;  
1544 - }  
1545 -  
1546 - SrsDvrApiPlan* dvr = NULL;  
1547 - for (int i = 0; i < (int)dvrs.size(); i++) {  
1548 - SrsDvrApiPlan* plan = dvrs.at(i);  
1549 - if (plan->req->vhost != vhost || plan->req->app != app || plan->req->stream != stream) {  
1550 - continue;  
1551 - }  
1552 - dvr = plan;  
1553 - break;  
1554 - }  
1555 -  
1556 - // mock the client request for dvr.  
1557 - SrsRequest* req = new SrsRequest();  
1558 - SrsAutoFree(SrsRequest, req);  
1559 -  
1560 - // should notice the source to reload dvr when already publishing.  
1561 - SrsSource* source = NULL;  
1562 -  
1563 - // create if not exists  
1564 - if (!dvr) {  
1565 - dvr = new SrsDvrApiPlan();  
1566 -  
1567 - req->vhost = vhost;  
1568 - req->app = app;  
1569 - req->stream = stream;  
1570 - req->tcUrl = "rtmp://" + vhost + "/" + app + "/" + stream;  
1571 -  
1572 - // fetch source from pool.  
1573 - // NULL, create without source, ignore.  
1574 - // start dvr when already publishing.  
1575 - source = SrsSource::fetch(req);  
1576 -  
1577 - // initialize for dvr pool to create it.  
1578 - if ((ret = dvr->initialize(req)) != ERROR_SUCCESS) {  
1579 - return ret;  
1580 - }  
1581 - }  
1582 -  
1583 - // update optional parameters for plan.  
1584 - if ((ret = dvr->set_plan()) != ERROR_SUCCESS) {  
1585 - return ret;  
1586 - }  
1587 - if ((prop = obj->ensure_property_string("path_tmpl")) != NULL) {  
1588 - if ((ret = dvr->set_path_tmpl(prop->to_str())) != ERROR_SUCCESS) {  
1589 - return ret;  
1590 - }  
1591 - }  
1592 - if ((prop = obj->ensure_property_boolean("wait_keyframe")) != NULL) {  
1593 - if ((ret = dvr->set_wait_keyframe(prop->to_boolean())) != ERROR_SUCCESS) {  
1594 - return ret;  
1595 - }  
1596 - }  
1597 - if ((prop = obj->ensure_property_string("callback")) != NULL) {  
1598 - if ((ret = dvr->set_callback(prop->to_str())) != ERROR_SUCCESS) {  
1599 - return ret;  
1600 - }  
1601 - }  
1602 -  
1603 - if ((ret = dvr->start()) != ERROR_SUCCESS) {  
1604 - return ret;  
1605 - }  
1606 -  
1607 - // do reload for source when already publishing.  
1608 - // when reload, the source will use the request instead.  
1609 - if (source) {  
1610 - if ((ret = source->on_reload_vhost_dvr(vhost)) != ERROR_SUCCESS) {  
1611 - return ret;  
1612 - }  
1613 - }  
1614 -  
1615 - return ret;  
1616 -}  
1617 -  
1618 -int SrsApiDvrPool::stop(string vhost, string app, string stream)  
1619 -{  
1620 - int ret = ERROR_SUCCESS;  
1621 -  
1622 - std::vector<SrsDvrApiPlan*> plans;  
1623 - for (int i = 0; i < (int)dvrs.size(); i++) {  
1624 - SrsDvrApiPlan* plan = dvrs.at(i);  
1625 - if (!vhost.empty() && plan->req->vhost != vhost) {  
1626 - continue;  
1627 - }  
1628 - if (!app.empty() && plan->req->app != app) {  
1629 - continue;  
1630 - }  
1631 - if (!stream.empty() && plan->req->stream != stream) {  
1632 - continue;  
1633 - }  
1634 - plans.push_back(plan);  
1635 - }  
1636 -  
1637 - if (plans.empty()) {  
1638 - ret = ERROR_HTTP_DVR_NO_TAEGET;  
1639 - srs_error("dvr: stop not found for url=%s/%s/%s, ret=%d", vhost.c_str(), app.c_str(), stream.c_str(), ret);  
1640 - return ret;  
1641 - }  
1642 -  
1643 - for (int i = 0; i < (int)plans.size(); i++) {  
1644 - SrsDvrApiPlan* plan = plans.at(i);  
1645 -  
1646 - if ((ret = plan->stop()) != ERROR_SUCCESS) {  
1647 - return ret;  
1648 - }  
1649 - }  
1650 -  
1651 - return ret;  
1652 -}  
1653 -  
1654 -int SrsApiDvrPool::rpc(SrsJsonAny* json)  
1655 -{  
1656 - int ret = ERROR_SUCCESS;  
1657 -  
1658 - if (!json->is_object()) {  
1659 - ret = ERROR_HTTP_DVR_REQUEST;  
1660 - srs_error("dvr: rpc required object request. ret=%d", ret);  
1661 - return ret;  
1662 - }  
1663 -  
1664 - SrsJsonObject* obj = json->to_object();  
1665 -  
1666 - SrsJsonAny* prop = NULL;  
1667 - if ((prop = obj->ensure_property_string("vhost")) == NULL) {  
1668 - ret = ERROR_HTTP_DVR_REQUEST;  
1669 - srs_error("dvr: rpc required vhost request. ret=%d", ret);  
1670 - return ret;  
1671 - }  
1672 - std::string vhost = prop->to_str();  
1673 - std::string app, stream;  
1674 - if ((prop = obj->ensure_property_string("app")) != NULL) {  
1675 - app = prop->to_str();  
1676 - }  
1677 - if ((prop = obj->ensure_property_string("stream")) != NULL) {  
1678 - stream = prop->to_str();  
1679 - }  
1680 -  
1681 - std::vector<SrsDvrApiPlan*> plans;  
1682 - for (int i = 0; i < (int)dvrs.size(); i++) {  
1683 - SrsDvrApiPlan* plan = dvrs.at(i);  
1684 - if (!vhost.empty() && plan->req->vhost != vhost) {  
1685 - continue;  
1686 - }  
1687 - plans.push_back(plan);  
1688 - }  
1689 -  
1690 - if (plans.empty()) {  
1691 - ret = ERROR_HTTP_DVR_NO_TAEGET;  
1692 - srs_error("dvr: rpc not found for url=%s/%s/%s, ret=%d", vhost.c_str(), app.c_str(), stream.c_str(), ret);  
1693 - return ret;  
1694 - }  
1695 -  
1696 - for (int i = 0; i < (int)plans.size(); i++) {  
1697 - SrsDvrApiPlan* plan = plans.at(i);  
1698 -  
1699 - if ((ret = plan->rpc(obj)) != ERROR_SUCCESS) {  
1700 - return ret;  
1701 - }  
1702 - }  
1703 -  
1704 - return ret;  
1705 -}  
1706 -  
1707 SrsDvr::SrsDvr() 1100 SrsDvr::SrsDvr()
1708 { 1101 {
1709 source = NULL; 1102 source = NULL;
@@ -277,48 +277,6 @@ public: @@ -277,48 +277,6 @@ public:
277 }; 277 };
278 278
279 /** 279 /**
280 -* api plan: reap flv by api.  
281 -* @remark the api plan maybe create by publish event or http api post create dvr event.  
282 -* so when we got from pool first when create it.  
283 -*/  
284 -class SrsDvrApiPlan : public SrsDvrPlan  
285 -{  
286 -private:  
287 - // cache the metadata and sequence header, for new segment maybe opened.  
288 - SrsSharedPtrMessage* sh_audio;  
289 - SrsSharedPtrMessage* sh_video;  
290 - SrsSharedPtrMessage* metadata;  
291 -private:  
292 - bool autostart;  
293 - bool started;  
294 -private:  
295 - // user action, reap_segment.  
296 - std::string action;  
297 - std::string path_template;  
298 -public:  
299 - SrsDvrApiPlan();  
300 - virtual ~SrsDvrApiPlan();  
301 -public:  
302 - virtual int initialize(SrsRequest* r);  
303 - virtual int on_publish();  
304 - virtual void on_unpublish();  
305 - virtual int on_meta_data(SrsSharedPtrMessage* __metadata);  
306 - virtual int on_audio(SrsSharedPtrMessage* __audio);  
307 - virtual int on_video(SrsSharedPtrMessage* __video);  
308 -public:  
309 - virtual int set_plan();  
310 - virtual int set_path_tmpl(std::string path_tmpl);  
311 - virtual int set_callback(std::string value);  
312 - virtual int set_wait_keyframe(bool wait_keyframe);  
313 - virtual int start();  
314 - virtual int dumps(std::stringstream& ss);  
315 - virtual int stop();  
316 - virtual int rpc(SrsJsonObject* obj);  
317 -private:  
318 - virtual int check_user_actions(SrsSharedPtrMessage* msg);  
319 -};  
320 -  
321 -/**  
322 * always append to flv file, never reap it. 280 * always append to flv file, never reap it.
323 */ 281 */
324 class SrsDvrAppendPlan : public SrsDvrPlan 282 class SrsDvrAppendPlan : public SrsDvrPlan
@@ -363,30 +321,6 @@ private: @@ -363,30 +321,6 @@ private:
363 }; 321 };
364 322
365 /** 323 /**
366 -* the api dvr pool.  
367 -*/  
368 -class SrsApiDvrPool  
369 -{  
370 -private:  
371 - std::vector<SrsDvrApiPlan*> dvrs;  
372 - static SrsApiDvrPool* _instance;  
373 -private:  
374 - SrsApiDvrPool();  
375 -public:  
376 - static SrsApiDvrPool* instance();  
377 - virtual ~SrsApiDvrPool();  
378 -public:  
379 - virtual SrsDvrApiPlan* get_dvr(std::string vhost);  
380 - virtual int add_dvr(SrsDvrApiPlan* dvr);  
381 - virtual void detach_dvr(SrsDvrApiPlan* dvr);  
382 -public:  
383 - virtual int dumps(std::string vhost, std::string app, std::string stream, std::stringstream& ss);  
384 - virtual int create(SrsJsonAny* json);  
385 - virtual int stop(std::string vhost, std::string app, std::string stream);  
386 - virtual int rpc(SrsJsonAny* json);  
387 -};  
388 -  
389 -/**  
390 * dvr(digital video recorder) to record RTMP stream to flv file. 324 * dvr(digital video recorder) to record RTMP stream to flv file.
391 * TODO: FIXME: add utest for it. 325 * TODO: FIXME: add utest for it.
392 */ 326 */
@@ -108,8 +108,7 @@ int SrsGoApiV1::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r) @@ -108,8 +108,7 @@ int SrsGoApiV1::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
108 << __SRS_JFIELD_STR("authors", "the primary authors and contributors") << __SRS_JFIELD_CONT 108 << __SRS_JFIELD_STR("authors", "the primary authors and contributors") << __SRS_JFIELD_CONT
109 << __SRS_JFIELD_STR("requests", "the request itself, for http debug") << __SRS_JFIELD_CONT 109 << __SRS_JFIELD_STR("requests", "the request itself, for http debug") << __SRS_JFIELD_CONT
110 << __SRS_JFIELD_STR("vhosts", "dumps vhost to json") << __SRS_JFIELD_CONT 110 << __SRS_JFIELD_STR("vhosts", "dumps vhost to json") << __SRS_JFIELD_CONT
111 - << __SRS_JFIELD_STR("streams", "dumps streams to json") << __SRS_JFIELD_CONT  
112 - << __SRS_JFIELD_STR("dvrs", "query or control the dvr plan") 111 + << __SRS_JFIELD_STR("streams", "dumps streams to json")
113 << __SRS_JOBJECT_END 112 << __SRS_JOBJECT_END
114 << __SRS_JOBJECT_END; 113 << __SRS_JOBJECT_END;
115 114
@@ -474,76 +473,6 @@ int SrsGoApiStreams::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r) @@ -474,76 +473,6 @@ int SrsGoApiStreams::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
474 return srs_go_http_response_json(w, ss.str()); 473 return srs_go_http_response_json(w, ss.str());
475 } 474 }
476 475
477 -SrsGoApiDvrs::SrsGoApiDvrs()  
478 -{  
479 -}  
480 -  
481 -SrsGoApiDvrs::~SrsGoApiDvrs()  
482 -{  
483 -}  
484 -  
485 -int SrsGoApiDvrs::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)  
486 -{  
487 - std::stringstream ss;  
488 -  
489 -#ifndef SRS_AUTO_DVR  
490 - ss << __SRS_JOBJECT_START  
491 - << __SRS_JFIELD_ERROR(ERROR_HTTP_DVR_DISABLED)  
492 - << __SRS_JOBJECT_END;  
493 -#else  
494 - SrsApiDvrPool* pool = SrsApiDvrPool::instance();  
495 - if (r->is_http_get()) {  
496 - std::stringstream data;  
497 - int ret = pool->dumps(r->query_get("vhost"), r->query_get("app"), r->query_get("stream"), data);  
498 -  
499 - ss << __SRS_JOBJECT_START  
500 - << __SRS_JFIELD_ERROR(ret) << __SRS_JFIELD_CONT  
501 - << __SRS_JFIELD_ORG("dvrs", data.str())  
502 - << __SRS_JOBJECT_END;  
503 - } else if (r->is_http_post()) {  
504 - std::string body = r->body();  
505 - SrsJsonAny* json = SrsJsonAny::loads((char*)body.c_str());  
506 - int ret = ERROR_SUCCESS;  
507 - if (!json) {  
508 - ret = ERROR_HTTP_JSON_REQUIRED;  
509 - } else {  
510 - SrsAutoFree(SrsJsonAny, json);  
511 - ret = pool->create(json);  
512 - }  
513 - ss << __SRS_JOBJECT_START  
514 - << __SRS_JFIELD_ERROR(ret)  
515 - << __SRS_JOBJECT_END;  
516 - } else if (r->is_http_delete()) {  
517 - int ret = pool->stop(r->query_get("vhost"), r->query_get("app"), r->query_get("stream"));  
518 -  
519 - ss << __SRS_JOBJECT_START  
520 - << __SRS_JFIELD_ERROR(ret)  
521 - << __SRS_JOBJECT_END;  
522 - } else if (r->is_http_put()) {  
523 - int ret = ERROR_SUCCESS;  
524 -  
525 - std::string body = r->body();  
526 - SrsJsonAny* json = SrsJsonAny::loads((char*)body.c_str());  
527 - if (!json) {  
528 - ret = ERROR_HTTP_JSON_REQUIRED;  
529 - } else {  
530 - SrsAutoFree(SrsJsonAny, json);  
531 - ret = pool->rpc(json);  
532 - }  
533 -  
534 - ss << __SRS_JOBJECT_START  
535 - << __SRS_JFIELD_ERROR(ret)  
536 - << __SRS_JOBJECT_END;  
537 - } else {  
538 - ss << __SRS_JOBJECT_START  
539 - << __SRS_JFIELD_ERROR(ERROR_HTTP_DVR_REQUEST)  
540 - << __SRS_JOBJECT_END;  
541 - }  
542 -#endif  
543 -  
544 - return srs_go_http_response_json(w, ss.str());  
545 -}  
546 -  
547 SrsHttpApi::SrsHttpApi(SrsServer* svr, st_netfd_t fd, SrsGoHttpServeMux* m) 476 SrsHttpApi::SrsHttpApi(SrsServer* svr, st_netfd_t fd, SrsGoHttpServeMux* m)
548 : SrsConnection(svr, fd) 477 : SrsConnection(svr, fd)
549 { 478 {
@@ -159,15 +159,6 @@ public: @@ -159,15 +159,6 @@ public:
159 virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r); 159 virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
160 }; 160 };
161 161
162 -class SrsGoApiDvrs : public ISrsGoHttpHandler  
163 -{  
164 -public:  
165 - SrsGoApiDvrs();  
166 - virtual ~SrsGoApiDvrs();  
167 -public:  
168 - virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);  
169 -};  
170 -  
171 class SrsHttpApi : public SrsConnection 162 class SrsHttpApi : public SrsConnection
172 { 163 {
173 private: 164 private:
@@ -529,9 +529,6 @@ int SrsServer::initialize() @@ -529,9 +529,6 @@ int SrsServer::initialize()
529 if ((ret = http_api_mux->handle("/api/v1/streams", new SrsGoApiStreams())) != ERROR_SUCCESS) { 529 if ((ret = http_api_mux->handle("/api/v1/streams", new SrsGoApiStreams())) != ERROR_SUCCESS) {
530 return ret; 530 return ret;
531 } 531 }
532 - if ((ret = http_api_mux->handle("/api/v1/dvrs", new SrsGoApiDvrs())) != ERROR_SUCCESS) {  
533 - return ret;  
534 - }  
535 #endif 532 #endif
536 533
537 #ifdef SRS_AUTO_HTTP_SERVER 534 #ifdef SRS_AUTO_HTTP_SERVER
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR 2 32 #define VERSION_MAJOR 2
33 #define VERSION_MINOR 0 33 #define VERSION_MINOR 0
34 -#define VERSION_REVISION 127 34 +#define VERSION_REVISION 128
35 35
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "SRS" 37 #define RTMP_SIG_SRS_KEY "SRS"