winlin

Merge branch '2.0release' into develop

@@ -691,7 +691,7 @@ The publish RTMP benchmark by [SB](https://github.com/simple-rtmp-server/srs-ben @@ -691,7 +691,7 @@ The publish RTMP benchmark by [SB](https://github.com/simple-rtmp-server/srs-ben
691 | 2014-12-03 | 2.0.12 | 1.2k(1200) | publishers | 96% | 43MB | - | 691 | 2014-12-03 | 2.0.12 | 1.2k(1200) | publishers | 96% | 43MB | - |
692 | 2014-12-03 | 2.0.47 | 1.2k(1200) | publishers | 84% | 76MB | [code][p1] | 692 | 2014-12-03 | 2.0.47 | 1.2k(1200) | publishers | 84% | 76MB | [code][p1] |
693 | 2014-12-03 | 2.0.47 | 1.4k(1400) | publishers | 95% | 140MB | - | 693 | 2014-12-03 | 2.0.47 | 1.4k(1400) | publishers | 95% | 140MB | - |
694 -| 2014-12-03 | 2.0.48 | 1.4k(1400 | publishers | 95% | 140MB | [code][p2] | 694 +| 2014-12-03 | 2.0.48 | 1.4k(1400) | publishers | 95% | 140MB | [code][p2] |
695 | 2014-12-04 | 2.0.49 | 1.4k(1400) | publishers | 68% | 144MB | - | 695 | 2014-12-04 | 2.0.49 | 1.4k(1400) | publishers | 68% | 144MB | - |
696 | 2014-12-04 | 2.0.49 | 2.5k(2500) | publishers | 95% | 404MB | [code][p3] | 696 | 2014-12-04 | 2.0.49 | 2.5k(2500) | publishers | 95% | 404MB | [code][p3] |
697 | 2014-12-04 | 2.0.51 | 2.5k(2500) | publishers | 91% | 259MB | [code][p4] | 697 | 2014-12-04 | 2.0.51 | 2.5k(2500) | publishers | 91% | 259MB | [code][p4] |
@@ -535,271 +535,6 @@ int SrsConfig::reload() @@ -535,271 +535,6 @@ int SrsConfig::reload()
535 return reload_conf(&conf); 535 return reload_conf(&conf);
536 } 536 }
537 537
538 -int SrsConfig::reload_conf(SrsConfig* conf)  
539 -{  
540 - int ret = ERROR_SUCCESS;  
541 -  
542 - SrsConfDirective* old_root = root;  
543 - SrsAutoFree(SrsConfDirective, old_root);  
544 -  
545 - root = conf->root;  
546 - conf->root = NULL;  
547 -  
548 - // merge config.  
549 - std::vector<ISrsReloadHandler*>::iterator it;  
550 -  
551 - // never support reload:  
552 - // daemon  
553 - //  
554 - // always support reload without additional code:  
555 - // chunk_size, ff_log_dir,  
556 - // bandcheck, http_hooks, heartbeat,  
557 - // token_traverse, debug_srs_upnode,  
558 - // security  
559 -  
560 - // merge config: max_connections  
561 - if (!srs_directive_equals(root->get("max_connections"), old_root->get("max_connections"))) {  
562 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
563 - ISrsReloadHandler* subscribe = *it;  
564 - if ((ret = subscribe->on_reload_max_conns()) != ERROR_SUCCESS) {  
565 - srs_error("notify subscribes reload max_connections failed. ret=%d", ret);  
566 - return ret;  
567 - }  
568 - }  
569 - srs_trace("reload max_connections success.");  
570 - }  
571 -  
572 - // merge config: listen  
573 - if (!srs_directive_equals(root->get("listen"), old_root->get("listen"))) {  
574 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
575 - ISrsReloadHandler* subscribe = *it;  
576 - if ((ret = subscribe->on_reload_listen()) != ERROR_SUCCESS) {  
577 - srs_error("notify subscribes reload listen failed. ret=%d", ret);  
578 - return ret;  
579 - }  
580 - }  
581 - srs_trace("reload listen success.");  
582 - }  
583 -  
584 - // merge config: pid  
585 - if (!srs_directive_equals(root->get("pid"), old_root->get("pid"))) {  
586 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
587 - ISrsReloadHandler* subscribe = *it;  
588 - if ((ret = subscribe->on_reload_pid()) != ERROR_SUCCESS) {  
589 - srs_error("notify subscribes reload pid failed. ret=%d", ret);  
590 - return ret;  
591 - }  
592 - }  
593 - srs_trace("reload pid success.");  
594 - }  
595 -  
596 - // merge config: srs_log_tank  
597 - if (!srs_directive_equals(root->get("srs_log_tank"), old_root->get("srs_log_tank"))) {  
598 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
599 - ISrsReloadHandler* subscribe = *it;  
600 - if ((ret = subscribe->on_reload_log_tank()) != ERROR_SUCCESS) {  
601 - srs_error("notify subscribes reload srs_log_tank failed. ret=%d", ret);  
602 - return ret;  
603 - }  
604 - }  
605 - srs_trace("reload srs_log_tank success.");  
606 - }  
607 -  
608 - // merge config: srs_log_level  
609 - if (!srs_directive_equals(root->get("srs_log_level"), old_root->get("srs_log_level"))) {  
610 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
611 - ISrsReloadHandler* subscribe = *it;  
612 - if ((ret = subscribe->on_reload_log_level()) != ERROR_SUCCESS) {  
613 - srs_error("notify subscribes reload srs_log_level failed. ret=%d", ret);  
614 - return ret;  
615 - }  
616 - }  
617 - srs_trace("reload srs_log_level success.");  
618 - }  
619 -  
620 - // merge config: srs_log_file  
621 - if (!srs_directive_equals(root->get("srs_log_file"), old_root->get("srs_log_file"))) {  
622 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
623 - ISrsReloadHandler* subscribe = *it;  
624 - if ((ret = subscribe->on_reload_log_file()) != ERROR_SUCCESS) {  
625 - srs_error("notify subscribes reload srs_log_file failed. ret=%d", ret);  
626 - return ret;  
627 - }  
628 - }  
629 - srs_trace("reload srs_log_file success.");  
630 - }  
631 -  
632 - // merge config: pithy_print_ms  
633 - if (!srs_directive_equals(root->get("pithy_print_ms"), old_root->get("pithy_print_ms"))) {  
634 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
635 - ISrsReloadHandler* subscribe = *it;  
636 - if ((ret = subscribe->on_reload_pithy_print()) != ERROR_SUCCESS) {  
637 - srs_error("notify subscribes pithy_print_ms listen failed. ret=%d", ret);  
638 - return ret;  
639 - }  
640 - }  
641 - srs_trace("reload pithy_print_ms success.");  
642 - }  
643 -  
644 - // merge config: http_api  
645 - if ((ret = reload_http_api(old_root)) != ERROR_SUCCESS) {  
646 - return ret;  
647 - }  
648 -  
649 - // merge config: http_stream  
650 - if ((ret = reload_http_stream(old_root)) != ERROR_SUCCESS) {  
651 - return ret;  
652 - }  
653 -  
654 - // TODO: FIXME: support reload stream_caster.  
655 -  
656 - // merge config: vhost  
657 - if ((ret = reload_vhost(old_root)) != ERROR_SUCCESS) {  
658 - return ret;  
659 - }  
660 -  
661 - return ret;  
662 -}  
663 -  
664 -int SrsConfig::reload_http_api(SrsConfDirective* old_root)  
665 -{  
666 - int ret = ERROR_SUCCESS;  
667 -  
668 - // merge config.  
669 - std::vector<ISrsReloadHandler*>::iterator it;  
670 -  
671 - // state graph  
672 - // old_http_api new_http_api  
673 - // DISABLED => ENABLED  
674 - // ENABLED => DISABLED  
675 - // ENABLED => ENABLED (modified)  
676 -  
677 - SrsConfDirective* new_http_api = root->get("http_api");  
678 - SrsConfDirective* old_http_api = old_root->get("http_api");  
679 -  
680 - // DISABLED => ENABLED  
681 - if (!get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api)) {  
682 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
683 - ISrsReloadHandler* subscribe = *it;  
684 - if ((ret = subscribe->on_reload_http_api_enabled()) != ERROR_SUCCESS) {  
685 - srs_error("notify subscribes http_api disabled=>enabled failed. ret=%d", ret);  
686 - return ret;  
687 - }  
688 - }  
689 - srs_trace("reload disabled=>enabled http_api success.");  
690 -  
691 - return ret;  
692 - }  
693 -  
694 - // ENABLED => DISABLED  
695 - if (get_http_api_enabled(old_http_api) && !get_http_api_enabled(new_http_api)) {  
696 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
697 - ISrsReloadHandler* subscribe = *it;  
698 - if ((ret = subscribe->on_reload_http_api_disabled()) != ERROR_SUCCESS) {  
699 - srs_error("notify subscribes http_api enabled=>disabled failed. ret=%d", ret);  
700 - return ret;  
701 - }  
702 - }  
703 - srs_trace("reload enabled=>disabled http_api success.");  
704 -  
705 - return ret;  
706 - }  
707 -  
708 - // ENABLED => ENABLED (modified)  
709 - if (get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api)  
710 - && !srs_directive_equals(old_http_api, new_http_api)  
711 - ) {  
712 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
713 - ISrsReloadHandler* subscribe = *it;  
714 - if ((ret = subscribe->on_reload_http_api_enabled()) != ERROR_SUCCESS) {  
715 - srs_error("notify subscribes http_api enabled modified failed. ret=%d", ret);  
716 - return ret;  
717 - }  
718 - }  
719 - srs_trace("reload enabled modified http_api success.");  
720 -  
721 - return ret;  
722 - }  
723 -  
724 - srs_trace("reload http_api not changed success.");  
725 -  
726 - return ret;  
727 -}  
728 -  
729 -int SrsConfig::reload_http_stream(SrsConfDirective* old_root)  
730 -{  
731 - int ret = ERROR_SUCCESS;  
732 -  
733 - // merge config.  
734 - std::vector<ISrsReloadHandler*>::iterator it;  
735 -  
736 - // state graph  
737 - // old_http_stream new_http_stream  
738 - // DISABLED => ENABLED  
739 - // ENABLED => DISABLED  
740 - // ENABLED => ENABLED (modified)  
741 -  
742 - SrsConfDirective* new_http_stream = root->get("http_stream");  
743 - // http_stream rename to http_server in SRS2.  
744 - if (!new_http_stream) {  
745 - new_http_stream = root->get("http_server");  
746 - }  
747 -  
748 - SrsConfDirective* old_http_stream = old_root->get("http_stream");  
749 - // http_stream rename to http_server in SRS2.  
750 - if (!old_http_stream) {  
751 - old_http_stream = root->get("http_server");  
752 - }  
753 -  
754 - // DISABLED => ENABLED  
755 - if (!get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)) {  
756 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
757 - ISrsReloadHandler* subscribe = *it;  
758 - if ((ret = subscribe->on_reload_http_stream_enabled()) != ERROR_SUCCESS) {  
759 - srs_error("notify subscribes http_stream disabled=>enabled failed. ret=%d", ret);  
760 - return ret;  
761 - }  
762 - }  
763 - srs_trace("reload disabled=>enabled http_stream success.");  
764 -  
765 - return ret;  
766 - }  
767 -  
768 - // ENABLED => DISABLED  
769 - if (get_http_stream_enabled(old_http_stream) && !get_http_stream_enabled(new_http_stream)) {  
770 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
771 - ISrsReloadHandler* subscribe = *it;  
772 - if ((ret = subscribe->on_reload_http_stream_disabled()) != ERROR_SUCCESS) {  
773 - srs_error("notify subscribes http_stream enabled=>disabled failed. ret=%d", ret);  
774 - return ret;  
775 - }  
776 - }  
777 - srs_trace("reload enabled=>disabled http_stream success.");  
778 -  
779 - return ret;  
780 - }  
781 -  
782 - // ENABLED => ENABLED (modified)  
783 - if (get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)  
784 - && !srs_directive_equals(old_http_stream, new_http_stream)  
785 - ) {  
786 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
787 - ISrsReloadHandler* subscribe = *it;  
788 - if ((ret = subscribe->on_reload_http_stream_updated()) != ERROR_SUCCESS) {  
789 - srs_error("notify subscribes http_stream enabled modified failed. ret=%d", ret);  
790 - return ret;  
791 - }  
792 - }  
793 - srs_trace("reload enabled modified http_stream success.");  
794 -  
795 - return ret;  
796 - }  
797 -  
798 - srs_trace("reload http_stream not changed success.");  
799 -  
800 - return ret;  
801 -}  
802 -  
803 int SrsConfig::reload_vhost(SrsConfDirective* old_root) 538 int SrsConfig::reload_vhost(SrsConfDirective* old_root)
804 { 539 {
805 int ret = ERROR_SUCCESS; 540 int ret = ERROR_SUCCESS;
@@ -852,18 +587,6 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root) @@ -852,18 +587,6 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
852 } 587 }
853 } 588 }
854 589
855 - // TODO: reload new http_remux in on_vhost_add  
856 - // http_remux, only one per vhost.  
857 - if (get_vhost_http_remux_enabled(vhost)) {  
858 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
859 - ISrsReloadHandler* subscribe = *it;  
860 - if ((ret = subscribe->on_reload_vhost_http_remux_updated(vhost)) != ERROR_SUCCESS) {  
861 - srs_error("vhost %s notify subscribes http_remux failed. ret=%d", vhost.c_str(), ret);  
862 - return ret;  
863 - }  
864 - }  
865 - srs_trace("vhost %s reload http_remux success.", vhost.c_str());  
866 - }  
867 srs_trace("reload new vhost %s success.", vhost.c_str()); 590 srs_trace("reload new vhost %s success.", vhost.c_str());
868 continue; 591 continue;
869 } 592 }
@@ -1079,20 +802,285 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root) @@ -1079,20 +802,285 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
1079 } 802 }
1080 srs_trace("vhost %s reload http_remux success.", vhost.c_str()); 803 srs_trace("vhost %s reload http_remux success.", vhost.c_str());
1081 } 804 }
1082 - // transcode, many per vhost.  
1083 - if ((ret = reload_transcode(new_vhost, old_vhost)) != ERROR_SUCCESS) { 805 + // transcode, many per vhost.
  806 + if ((ret = reload_transcode(new_vhost, old_vhost)) != ERROR_SUCCESS) {
  807 + return ret;
  808 + }
  809 + // ingest, many per vhost.
  810 + if ((ret = reload_ingest(new_vhost, old_vhost)) != ERROR_SUCCESS) {
  811 + return ret;
  812 + }
  813 + continue;
  814 + }
  815 + srs_trace("ignore reload vhost, enabled old: %d, new: %d",
  816 + get_vhost_enabled(old_vhost), get_vhost_enabled(new_vhost));
  817 + }
  818 +
  819 + return ret;
  820 +}
  821 +
  822 +int SrsConfig::reload_conf(SrsConfig* conf)
  823 +{
  824 + int ret = ERROR_SUCCESS;
  825 +
  826 + SrsConfDirective* old_root = root;
  827 + SrsAutoFree(SrsConfDirective, old_root);
  828 +
  829 + root = conf->root;
  830 + conf->root = NULL;
  831 +
  832 + // merge config.
  833 + std::vector<ISrsReloadHandler*>::iterator it;
  834 +
  835 + // never support reload:
  836 + // daemon
  837 + //
  838 + // always support reload without additional code:
  839 + // chunk_size, ff_log_dir,
  840 + // bandcheck, http_hooks, heartbeat,
  841 + // token_traverse, debug_srs_upnode,
  842 + // security
  843 +
  844 + // merge config: max_connections
  845 + if (!srs_directive_equals(root->get("max_connections"), old_root->get("max_connections"))) {
  846 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  847 + ISrsReloadHandler* subscribe = *it;
  848 + if ((ret = subscribe->on_reload_max_conns()) != ERROR_SUCCESS) {
  849 + srs_error("notify subscribes reload max_connections failed. ret=%d", ret);
  850 + return ret;
  851 + }
  852 + }
  853 + srs_trace("reload max_connections success.");
  854 + }
  855 +
  856 + // merge config: listen
  857 + if (!srs_directive_equals(root->get("listen"), old_root->get("listen"))) {
  858 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  859 + ISrsReloadHandler* subscribe = *it;
  860 + if ((ret = subscribe->on_reload_listen()) != ERROR_SUCCESS) {
  861 + srs_error("notify subscribes reload listen failed. ret=%d", ret);
  862 + return ret;
  863 + }
  864 + }
  865 + srs_trace("reload listen success.");
  866 + }
  867 +
  868 + // merge config: pid
  869 + if (!srs_directive_equals(root->get("pid"), old_root->get("pid"))) {
  870 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  871 + ISrsReloadHandler* subscribe = *it;
  872 + if ((ret = subscribe->on_reload_pid()) != ERROR_SUCCESS) {
  873 + srs_error("notify subscribes reload pid failed. ret=%d", ret);
  874 + return ret;
  875 + }
  876 + }
  877 + srs_trace("reload pid success.");
  878 + }
  879 +
  880 + // merge config: srs_log_tank
  881 + if (!srs_directive_equals(root->get("srs_log_tank"), old_root->get("srs_log_tank"))) {
  882 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  883 + ISrsReloadHandler* subscribe = *it;
  884 + if ((ret = subscribe->on_reload_log_tank()) != ERROR_SUCCESS) {
  885 + srs_error("notify subscribes reload srs_log_tank failed. ret=%d", ret);
  886 + return ret;
  887 + }
  888 + }
  889 + srs_trace("reload srs_log_tank success.");
  890 + }
  891 +
  892 + // merge config: srs_log_level
  893 + if (!srs_directive_equals(root->get("srs_log_level"), old_root->get("srs_log_level"))) {
  894 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  895 + ISrsReloadHandler* subscribe = *it;
  896 + if ((ret = subscribe->on_reload_log_level()) != ERROR_SUCCESS) {
  897 + srs_error("notify subscribes reload srs_log_level failed. ret=%d", ret);
  898 + return ret;
  899 + }
  900 + }
  901 + srs_trace("reload srs_log_level success.");
  902 + }
  903 +
  904 + // merge config: srs_log_file
  905 + if (!srs_directive_equals(root->get("srs_log_file"), old_root->get("srs_log_file"))) {
  906 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  907 + ISrsReloadHandler* subscribe = *it;
  908 + if ((ret = subscribe->on_reload_log_file()) != ERROR_SUCCESS) {
  909 + srs_error("notify subscribes reload srs_log_file failed. ret=%d", ret);
  910 + return ret;
  911 + }
  912 + }
  913 + srs_trace("reload srs_log_file success.");
  914 + }
  915 +
  916 + // merge config: pithy_print_ms
  917 + if (!srs_directive_equals(root->get("pithy_print_ms"), old_root->get("pithy_print_ms"))) {
  918 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  919 + ISrsReloadHandler* subscribe = *it;
  920 + if ((ret = subscribe->on_reload_pithy_print()) != ERROR_SUCCESS) {
  921 + srs_error("notify subscribes pithy_print_ms listen failed. ret=%d", ret);
  922 + return ret;
  923 + }
  924 + }
  925 + srs_trace("reload pithy_print_ms success.");
  926 + }
  927 +
  928 + // merge config: http_api
  929 + if ((ret = reload_http_api(old_root)) != ERROR_SUCCESS) {
  930 + return ret;
  931 + }
  932 +
  933 + // merge config: http_stream
  934 + if ((ret = reload_http_stream(old_root)) != ERROR_SUCCESS) {
  935 + return ret;
  936 + }
  937 +
  938 + // TODO: FIXME: support reload stream_caster.
  939 +
  940 + // merge config: vhost
  941 + if ((ret = reload_vhost(old_root)) != ERROR_SUCCESS) {
  942 + return ret;
  943 + }
  944 +
  945 + return ret;
  946 +}
  947 +
  948 +int SrsConfig::reload_http_api(SrsConfDirective* old_root)
  949 +{
  950 + int ret = ERROR_SUCCESS;
  951 +
  952 + // merge config.
  953 + std::vector<ISrsReloadHandler*>::iterator it;
  954 +
  955 + // state graph
  956 + // old_http_api new_http_api
  957 + // DISABLED => ENABLED
  958 + // ENABLED => DISABLED
  959 + // ENABLED => ENABLED (modified)
  960 +
  961 + SrsConfDirective* new_http_api = root->get("http_api");
  962 + SrsConfDirective* old_http_api = old_root->get("http_api");
  963 +
  964 + // DISABLED => ENABLED
  965 + if (!get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api)) {
  966 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  967 + ISrsReloadHandler* subscribe = *it;
  968 + if ((ret = subscribe->on_reload_http_api_enabled()) != ERROR_SUCCESS) {
  969 + srs_error("notify subscribes http_api disabled=>enabled failed. ret=%d", ret);
  970 + return ret;
  971 + }
  972 + }
  973 + srs_trace("reload disabled=>enabled http_api success.");
  974 +
  975 + return ret;
  976 + }
  977 +
  978 + // ENABLED => DISABLED
  979 + if (get_http_api_enabled(old_http_api) && !get_http_api_enabled(new_http_api)) {
  980 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  981 + ISrsReloadHandler* subscribe = *it;
  982 + if ((ret = subscribe->on_reload_http_api_disabled()) != ERROR_SUCCESS) {
  983 + srs_error("notify subscribes http_api enabled=>disabled failed. ret=%d", ret);
  984 + return ret;
  985 + }
  986 + }
  987 + srs_trace("reload enabled=>disabled http_api success.");
  988 +
  989 + return ret;
  990 + }
  991 +
  992 + // ENABLED => ENABLED (modified)
  993 + if (get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api)
  994 + && !srs_directive_equals(old_http_api, new_http_api)
  995 + ) {
  996 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  997 + ISrsReloadHandler* subscribe = *it;
  998 + if ((ret = subscribe->on_reload_http_api_enabled()) != ERROR_SUCCESS) {
  999 + srs_error("notify subscribes http_api enabled modified failed. ret=%d", ret);
  1000 + return ret;
  1001 + }
  1002 + }
  1003 + srs_trace("reload enabled modified http_api success.");
  1004 +
  1005 + return ret;
  1006 + }
  1007 +
  1008 + srs_trace("reload http_api not changed success.");
  1009 +
  1010 + return ret;
  1011 +}
  1012 +
  1013 +int SrsConfig::reload_http_stream(SrsConfDirective* old_root)
  1014 +{
  1015 + int ret = ERROR_SUCCESS;
  1016 +
  1017 + // merge config.
  1018 + std::vector<ISrsReloadHandler*>::iterator it;
  1019 +
  1020 + // state graph
  1021 + // old_http_stream new_http_stream
  1022 + // DISABLED => ENABLED
  1023 + // ENABLED => DISABLED
  1024 + // ENABLED => ENABLED (modified)
  1025 +
  1026 + SrsConfDirective* new_http_stream = root->get("http_stream");
  1027 + // http_stream rename to http_server in SRS2.
  1028 + if (!new_http_stream) {
  1029 + new_http_stream = root->get("http_server");
  1030 + }
  1031 +
  1032 + SrsConfDirective* old_http_stream = old_root->get("http_stream");
  1033 + // http_stream rename to http_server in SRS2.
  1034 + if (!old_http_stream) {
  1035 + old_http_stream = root->get("http_server");
  1036 + }
  1037 +
  1038 + // DISABLED => ENABLED
  1039 + if (!get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)) {
  1040 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  1041 + ISrsReloadHandler* subscribe = *it;
  1042 + if ((ret = subscribe->on_reload_http_stream_enabled()) != ERROR_SUCCESS) {
  1043 + srs_error("notify subscribes http_stream disabled=>enabled failed. ret=%d", ret);
  1044 + return ret;
  1045 + }
  1046 + }
  1047 + srs_trace("reload disabled=>enabled http_stream success.");
  1048 +
  1049 + return ret;
  1050 + }
  1051 +
  1052 + // ENABLED => DISABLED
  1053 + if (get_http_stream_enabled(old_http_stream) && !get_http_stream_enabled(new_http_stream)) {
  1054 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  1055 + ISrsReloadHandler* subscribe = *it;
  1056 + if ((ret = subscribe->on_reload_http_stream_disabled()) != ERROR_SUCCESS) {
  1057 + srs_error("notify subscribes http_stream enabled=>disabled failed. ret=%d", ret);
1084 return ret; 1058 return ret;
1085 } 1059 }
1086 - // ingest, many per vhost.  
1087 - if ((ret = reload_ingest(new_vhost, old_vhost)) != ERROR_SUCCESS) { 1060 + }
  1061 + srs_trace("reload enabled=>disabled http_stream success.");
  1062 +
  1063 + return ret;
  1064 + }
  1065 +
  1066 + // ENABLED => ENABLED (modified)
  1067 + if (get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)
  1068 + && !srs_directive_equals(old_http_stream, new_http_stream)
  1069 + ) {
  1070 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  1071 + ISrsReloadHandler* subscribe = *it;
  1072 + if ((ret = subscribe->on_reload_http_stream_updated()) != ERROR_SUCCESS) {
  1073 + srs_error("notify subscribes http_stream enabled modified failed. ret=%d", ret);
1088 return ret; 1074 return ret;
1089 } 1075 }
1090 - continue;  
1091 } 1076 }
1092 - srs_trace("ignore reload vhost, enabled old: %d, new: %d",  
1093 - get_vhost_enabled(old_vhost), get_vhost_enabled(new_vhost)); 1077 + srs_trace("reload enabled modified http_stream success.");
  1078 +
  1079 + return ret;
1094 } 1080 }
1095 1081
  1082 + srs_trace("reload http_stream not changed success.");
  1083 +
1096 return ret; 1084 return ret;
1097 } 1085 }
1098 1086
@@ -1493,9 +1481,6 @@ int SrsConfig::check_config() @@ -1493,9 +1481,6 @@ int SrsConfig::check_config()
1493 int ret = ERROR_SUCCESS; 1481 int ret = ERROR_SUCCESS;
1494 1482
1495 srs_trace("srs checking config..."); 1483 srs_trace("srs checking config...");
1496 -  
1497 - vector<SrsConfDirective*> vhosts = get_vhosts();  
1498 - vector<SrsConfDirective*> stream_casters = get_stream_casters();  
1499 1484
1500 //////////////////////////////////////////////////////////////////////// 1485 ////////////////////////////////////////////////////////////////////////
1501 // check empty 1486 // check empty
@@ -1505,71 +1490,235 @@ int SrsConfig::check_config() @@ -1505,71 +1490,235 @@ int SrsConfig::check_config()
1505 srs_error("conf is empty, ret=%d", ret); 1490 srs_error("conf is empty, ret=%d", ret);
1506 return ret; 1491 return ret;
1507 } 1492 }
1508 - 1493 +
  1494 + ////////////////////////////////////////////////////////////////////////
  1495 + // check root directives.
  1496 + ////////////////////////////////////////////////////////////////////////
  1497 + for (int i = 0; i < (int)root->directives.size(); i++) {
  1498 + SrsConfDirective* conf = root->at(i);
  1499 + std::string n = conf->name;
  1500 + if (n != "listen" && n != "pid" && n != "chunk_size" && n != "ff_log_dir"
  1501 + && n != "srs_log_tank" && n != "srs_log_level" && n != "srs_log_file"
  1502 + && n != "max_connections" && n != "daemon" && n != "heartbeat"
  1503 + && n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms"
  1504 + && n != "http_stream" && n != "http_server" && n != "stream_caster"
  1505 + && n != "utc_time"
  1506 + ) {
  1507 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1508 + srs_error("unsupported directive %s, ret=%d", n.c_str(), ret);
  1509 + return ret;
  1510 + }
  1511 + }
  1512 + if (true) {
  1513 + SrsConfDirective* conf = get_http_api();
  1514 + for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
  1515 + string n = conf->at(i)->name;
  1516 + if (n != "enabled" && n != "listen" && n != "crossdomain") {
  1517 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1518 + srs_error("unsupported http_api directive %s, ret=%d", n.c_str(), ret);
  1519 + return ret;
  1520 + }
  1521 + }
  1522 + }
  1523 + if (true) {
  1524 + SrsConfDirective* conf = get_http_stream();
  1525 + for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
  1526 + string n = conf->at(i)->name;
  1527 + if (n != "enabled" && n != "listen" && n != "dir") {
  1528 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1529 + srs_error("unsupported http_stream directive %s, ret=%d", n.c_str(), ret);
  1530 + return ret;
  1531 + }
  1532 + }
  1533 + }
  1534 + if (true) {
  1535 + SrsConfDirective* conf = get_heartbeart();
  1536 + for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
  1537 + string n = conf->at(i)->name;
  1538 + if (n != "enabled" && n != "interval" && n != "url"
  1539 + && n != "device_id" && n != "summaries"
  1540 + ) {
  1541 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1542 + srs_error("unsupported heartbeat directive %s, ret=%d", n.c_str(), ret);
  1543 + return ret;
  1544 + }
  1545 + }
  1546 + }
  1547 + if (true) {
  1548 + SrsConfDirective* conf = get_stats();
  1549 + for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
  1550 + string n = conf->at(i)->name;
  1551 + if (n != "network" && n != "disk") {
  1552 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1553 + srs_error("unsupported stats directive %s, ret=%d", n.c_str(), ret);
  1554 + return ret;
  1555 + }
  1556 + }
  1557 + }
  1558 +
  1559 +
  1560 + ////////////////////////////////////////////////////////////////////////
  1561 + // check listen for rtmp.
  1562 + ////////////////////////////////////////////////////////////////////////
  1563 + if (true) {
  1564 + vector<string> listens = get_listens();
  1565 + if (listens.size() <= 0) {
  1566 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1567 + srs_error("directive \"listen\" is empty, ret=%d", ret);
  1568 + return ret;
  1569 + }
  1570 + for (int i = 0; i < (int)listens.size(); i++) {
  1571 + string port = listens[i];
  1572 + if (port.empty() || ::atoi(port.c_str()) <= 0) {
  1573 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1574 + srs_error("directive listen invalid, port=%s, ret=%d", port.c_str(), ret);
  1575 + return ret;
  1576 + }
  1577 + }
  1578 + }
  1579 +
  1580 + ////////////////////////////////////////////////////////////////////////
  1581 + // check max connections
  1582 + ////////////////////////////////////////////////////////////////////////
  1583 + if (get_max_connections() <= 0) {
  1584 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1585 + srs_error("directive max_connections invalid, max_connections=%d, ret=%d", get_max_connections(), ret);
  1586 + return ret;
  1587 + }
  1588 +
  1589 + // check max connections of system limits
  1590 + if (true) {
  1591 + int nb_consumed_fds = (int)get_listens().size();
  1592 + if (!get_http_api_listen().empty()) {
  1593 + nb_consumed_fds++;
  1594 + }
  1595 + if (!get_http_stream_listen().empty()) {
  1596 + nb_consumed_fds++;
  1597 + }
  1598 + if (get_log_tank_file()) {
  1599 + nb_consumed_fds++;
  1600 + }
  1601 + // 0, 1, 2 for stdin, stdout and stderr.
  1602 + nb_consumed_fds += 3;
  1603 +
  1604 + int nb_connections = get_max_connections();
  1605 + int nb_total = nb_connections + nb_consumed_fds;
  1606 +
  1607 + int max_open_files = (int)sysconf(_SC_OPEN_MAX);
  1608 + int nb_canbe = max_open_files - nb_consumed_fds - 1;
  1609 +
  1610 + // for each play connections, we open a pipe(2fds) to convert SrsConsumver to io,
  1611 + // refine performance, @see: https://github.com/simple-rtmp-server/srs/issues/194
  1612 + if (nb_total >= max_open_files) {
  1613 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1614 + srs_error("invalid max_connections=%d, required=%d, system limit to %d, "
  1615 + "total=%d(max_connections=%d, nb_consumed_fds=%d), ret=%d. "
  1616 + "you can change max_connections from %d to %d, or "
  1617 + "you can login as root and set the limit: ulimit -HSn %d",
  1618 + nb_connections, nb_total + 1, max_open_files,
  1619 + nb_total, nb_connections, nb_consumed_fds,
  1620 + ret, nb_connections, nb_canbe, nb_total + 1);
  1621 + return ret;
  1622 + }
  1623 + }
  1624 +
  1625 + ////////////////////////////////////////////////////////////////////////
  1626 + // check heartbeat
  1627 + ////////////////////////////////////////////////////////////////////////
  1628 + if (get_heartbeat_interval() <= 0) {
  1629 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1630 + srs_error("directive heartbeat interval invalid, interval=%"PRId64", ret=%d",
  1631 + get_heartbeat_interval(), ret);
  1632 + return ret;
  1633 + }
  1634 +
  1635 + ////////////////////////////////////////////////////////////////////////
  1636 + // check stats
  1637 + ////////////////////////////////////////////////////////////////////////
  1638 + if (get_stats_network() < 0) {
  1639 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1640 + srs_error("directive stats network invalid, network=%d, ret=%d",
  1641 + get_stats_network(), ret);
  1642 + return ret;
  1643 + }
  1644 + if (true) {
  1645 + vector<std::string> ips = srs_get_local_ipv4_ips();
  1646 + int index = get_stats_network();
  1647 + if (index >= (int)ips.size()) {
  1648 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1649 + srs_error("stats network invalid, total local ip count=%d, index=%d, ret=%d",
  1650 + (int)ips.size(), index, ret);
  1651 + return ret;
  1652 + }
  1653 + srs_warn("stats network use index=%d, ip=%s", index, ips.at(index).c_str());
  1654 + }
  1655 + if (true) {
  1656 + SrsConfDirective* conf = get_stats_disk_device();
  1657 + if (conf == NULL || (int)conf->args.size() <= 0) {
  1658 + srs_warn("stats disk not configed, disk iops disabled.");
  1659 + } else {
  1660 + string disks;
  1661 + for (int i = 0; i < (int)conf->args.size(); i++) {
  1662 + disks += conf->args.at(i);
  1663 + disks += " ";
  1664 + }
  1665 + srs_warn("stats disk list: %s", disks.c_str());
  1666 + }
  1667 + }
  1668 +
  1669 + ////////////////////////////////////////////////////////////////////////
  1670 + // check http api
  1671 + ////////////////////////////////////////////////////////////////////////
  1672 + if (get_http_api_listen().empty()) {
  1673 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1674 + srs_error("directive http_api listen invalid, listen=%s, ret=%d",
  1675 + get_http_api_listen().c_str(), ret);
  1676 + return ret;
  1677 + }
  1678 +
  1679 + ////////////////////////////////////////////////////////////////////////
  1680 + // check http stream
  1681 + ////////////////////////////////////////////////////////////////////////
  1682 + if (get_http_stream_listen().empty()) {
  1683 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1684 + srs_error("directive http_stream listen invalid, listen=%s, ret=%d",
  1685 + get_http_stream_listen().c_str(), ret);
  1686 + return ret;
  1687 + }
1509 //////////////////////////////////////////////////////////////////////// 1688 ////////////////////////////////////////////////////////////////////////
1510 - // check root directives. 1689 + // check log name and level
1511 //////////////////////////////////////////////////////////////////////// 1690 ////////////////////////////////////////////////////////////////////////
1512 - for (int i = 0; i < (int)root->directives.size(); i++) {  
1513 - SrsConfDirective* conf = root->at(i);  
1514 - std::string n = conf->name;  
1515 - if (n != "listen" && n != "pid" && n != "chunk_size" && n != "ff_log_dir"  
1516 - && n != "srs_log_tank" && n != "srs_log_level" && n != "srs_log_file"  
1517 - && n != "max_connections" && n != "daemon" && n != "heartbeat"  
1518 - && n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms"  
1519 - && n != "http_stream" && n != "http_server" && n != "stream_caster"  
1520 - && n != "utc_time"  
1521 - ) { 1691 + if (true) {
  1692 + std::string log_filename = this->get_log_file();
  1693 + if (get_log_tank_file() && log_filename.empty()) {
1522 ret = ERROR_SYSTEM_CONFIG_INVALID; 1694 ret = ERROR_SYSTEM_CONFIG_INVALID;
1523 - srs_error("unsupported directive %s, ret=%d", n.c_str(), ret); 1695 + srs_error("must specifies the file to write log to. ret=%d", ret);
1524 return ret; 1696 return ret;
1525 } 1697 }
1526 - }  
1527 - if (true) {  
1528 - SrsConfDirective* conf = get_http_api();  
1529 - for (int i = 0; conf && i < (int)conf->directives.size(); i++) {  
1530 - string n = conf->at(i)->name;  
1531 - if (n != "enabled" && n != "listen" && n != "crossdomain") {  
1532 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1533 - srs_error("unsupported http_api directive %s, ret=%d", n.c_str(), ret);  
1534 - return ret;  
1535 - }  
1536 - }  
1537 - }  
1538 - if (true) {  
1539 - SrsConfDirective* conf = get_http_stream();  
1540 - for (int i = 0; conf && i < (int)conf->directives.size(); i++) {  
1541 - string n = conf->at(i)->name;  
1542 - if (n != "enabled" && n != "listen" && n != "dir") {  
1543 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1544 - srs_error("unsupported http_stream directive %s, ret=%d", n.c_str(), ret);  
1545 - return ret;  
1546 - } 1698 + if (get_log_tank_file()) {
  1699 + srs_trace("write log to file %s", log_filename.c_str());
  1700 + srs_trace("you can: tailf %s", log_filename.c_str());
  1701 + srs_trace("@see: %s", SRS_WIKI_URL_LOG);
  1702 + } else {
  1703 + srs_trace("write log to console");
1547 } 1704 }
1548 } 1705 }
1549 - if (true) {  
1550 - SrsConfDirective* conf = get_heartbeart();  
1551 - for (int i = 0; conf && i < (int)conf->directives.size(); i++) {  
1552 - string n = conf->at(i)->name;  
1553 - if (n != "enabled" && n != "interval" && n != "url"  
1554 - && n != "device_id" && n != "summaries"  
1555 - ) {  
1556 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1557 - srs_error("unsupported heartbeat directive %s, ret=%d", n.c_str(), ret);  
1558 - return ret;  
1559 - }  
1560 - } 1706 +
  1707 + ////////////////////////////////////////////////////////////////////////
  1708 + // check features
  1709 + ////////////////////////////////////////////////////////////////////////
  1710 +#ifndef SRS_AUTO_HTTP_SERVER
  1711 + if (get_http_stream_enabled()) {
  1712 + srs_warn("http_stream is disabled by configure");
1561 } 1713 }
1562 - if (true) {  
1563 - SrsConfDirective* conf = get_stats();  
1564 - for (int i = 0; conf && i < (int)conf->directives.size(); i++) {  
1565 - string n = conf->at(i)->name;  
1566 - if (n != "network" && n != "disk") {  
1567 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1568 - srs_error("unsupported stats directive %s, ret=%d", n.c_str(), ret);  
1569 - return ret;  
1570 - }  
1571 - } 1714 +#endif
  1715 +#ifndef SRS_AUTO_HTTP_API
  1716 + if (get_http_api_enabled()) {
  1717 + srs_warn("http_api is disabled by configure");
1572 } 1718 }
  1719 +#endif
  1720 +
  1721 + vector<SrsConfDirective*> stream_casters = get_stream_casters();
1573 for (int n = 0; n < (int)stream_casters.size(); n++) { 1722 for (int n = 0; n < (int)stream_casters.size(); n++) {
1574 SrsConfDirective* stream_caster = stream_casters[n]; 1723 SrsConfDirective* stream_caster = stream_casters[n];
1575 for (int i = 0; stream_caster && i < (int)stream_caster->directives.size(); i++) { 1724 for (int i = 0; stream_caster && i < (int)stream_caster->directives.size(); i++) {
@@ -1577,13 +1726,16 @@ int SrsConfig::check_config() @@ -1577,13 +1726,16 @@ int SrsConfig::check_config()
1577 string n = conf->name; 1726 string n = conf->name;
1578 if (n != "enabled" && n != "caster" && n != "output" 1727 if (n != "enabled" && n != "caster" && n != "output"
1579 && n != "listen" && n != "rtp_port_min" && n != "rtp_port_max" 1728 && n != "listen" && n != "rtp_port_min" && n != "rtp_port_max"
1580 - ) { 1729 + ) {
1581 ret = ERROR_SYSTEM_CONFIG_INVALID; 1730 ret = ERROR_SYSTEM_CONFIG_INVALID;
1582 srs_error("unsupported stream_caster directive %s, ret=%d", n.c_str(), ret); 1731 srs_error("unsupported stream_caster directive %s, ret=%d", n.c_str(), ret);
1583 return ret; 1732 return ret;
1584 } 1733 }
1585 } 1734 }
1586 } 1735 }
  1736 +
  1737 + vector<SrsConfDirective*> vhosts;
  1738 + get_vhosts(vhosts);
1587 for (int n = 0; n < (int)vhosts.size(); n++) { 1739 for (int n = 0; n < (int)vhosts.size(); n++) {
1588 SrsConfDirective* vhost = vhosts[n]; 1740 SrsConfDirective* vhost = vhosts[n];
1589 for (int i = 0; vhost && i < (int)vhost->directives.size(); i++) { 1741 for (int i = 0; vhost && i < (int)vhost->directives.size(); i++) {
@@ -1613,7 +1765,7 @@ int SrsConfig::check_config() @@ -1613,7 +1765,7 @@ int SrsConfig::check_config()
1613 string m = conf->at(j)->name.c_str(); 1765 string m = conf->at(j)->name.c_str();
1614 if (m != "enabled" && m != "dvr_path" && m != "dvr_plan" 1766 if (m != "enabled" && m != "dvr_path" && m != "dvr_plan"
1615 && m != "dvr_duration" && m != "dvr_wait_keyframe" && m != "time_jitter" 1767 && m != "dvr_duration" && m != "dvr_wait_keyframe" && m != "time_jitter"
1616 - ) { 1768 + ) {
1617 ret = ERROR_SYSTEM_CONFIG_INVALID; 1769 ret = ERROR_SYSTEM_CONFIG_INVALID;
1618 srs_error("unsupported vhost dvr directive %s, ret=%d", m.c_str(), ret); 1770 srs_error("unsupported vhost dvr directive %s, ret=%d", m.c_str(), ret);
1619 return ret; 1771 return ret;
@@ -1623,7 +1775,7 @@ int SrsConfig::check_config() @@ -1623,7 +1775,7 @@ int SrsConfig::check_config()
1623 for (int j = 0; j < (int)conf->directives.size(); j++) { 1775 for (int j = 0; j < (int)conf->directives.size(); j++) {
1624 string m = conf->at(j)->name.c_str(); 1776 string m = conf->at(j)->name.c_str();
1625 if (m != "enabled" && m != "latency" 1777 if (m != "enabled" && m != "latency"
1626 - ) { 1778 + ) {
1627 ret = ERROR_SYSTEM_CONFIG_INVALID; 1779 ret = ERROR_SYSTEM_CONFIG_INVALID;
1628 srs_error("unsupported vhost mr directive %s, ret=%d", m.c_str(), ret); 1780 srs_error("unsupported vhost mr directive %s, ret=%d", m.c_str(), ret);
1629 return ret; 1781 return ret;
@@ -1634,7 +1786,7 @@ int SrsConfig::check_config() @@ -1634,7 +1786,7 @@ int SrsConfig::check_config()
1634 string m = conf->at(j)->name.c_str(); 1786 string m = conf->at(j)->name.c_str();
1635 if (m != "enabled" && m != "input" && m != "ffmpeg" 1787 if (m != "enabled" && m != "input" && m != "ffmpeg"
1636 && m != "engine" 1788 && m != "engine"
1637 - ) { 1789 + ) {
1638 ret = ERROR_SYSTEM_CONFIG_INVALID; 1790 ret = ERROR_SYSTEM_CONFIG_INVALID;
1639 srs_error("unsupported vhost ingest directive %s, ret=%d", m.c_str(), ret); 1791 srs_error("unsupported vhost ingest directive %s, ret=%d", m.c_str(), ret);
1640 return ret; 1792 return ret;
@@ -1665,7 +1817,7 @@ int SrsConfig::check_config() @@ -1665,7 +1817,7 @@ int SrsConfig::check_config()
1665 && m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec" 1817 && m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec"
1666 && m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" && m != "hls_cleanup" && m != "hls_nb_notify" 1818 && m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" && m != "hls_cleanup" && m != "hls_nb_notify"
1667 && m != "hls_wait_keyframe" && m != "hls_dispose" 1819 && m != "hls_wait_keyframe" && m != "hls_dispose"
1668 - ) { 1820 + ) {
1669 ret = ERROR_SYSTEM_CONFIG_INVALID; 1821 ret = ERROR_SYSTEM_CONFIG_INVALID;
1670 srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret); 1822 srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret);
1671 return ret; 1823 return ret;
@@ -1677,7 +1829,7 @@ int SrsConfig::check_config() @@ -1677,7 +1829,7 @@ int SrsConfig::check_config()
1677 if (m != "enabled" && m != "on_connect" && m != "on_close" && m != "on_publish" 1829 if (m != "enabled" && m != "on_connect" && m != "on_close" && m != "on_publish"
1678 && m != "on_unpublish" && m != "on_play" && m != "on_stop" 1830 && m != "on_unpublish" && m != "on_play" && m != "on_stop"
1679 && m != "on_dvr" && m != "on_hls" && m != "on_hls_notify" 1831 && m != "on_dvr" && m != "on_hls" && m != "on_hls_notify"
1680 - ) { 1832 + ) {
1681 ret = ERROR_SYSTEM_CONFIG_INVALID; 1833 ret = ERROR_SYSTEM_CONFIG_INVALID;
1682 srs_error("unsupported vhost http_hooks directive %s, ret=%d", m.c_str(), ret); 1834 srs_error("unsupported vhost http_hooks directive %s, ret=%d", m.c_str(), ret);
1683 return ret; 1835 return ret;
@@ -1721,7 +1873,7 @@ int SrsConfig::check_config() @@ -1721,7 +1873,7 @@ int SrsConfig::check_config()
1721 && e != "acodec" && e != "abitrate" && e != "asample_rate" && e != "achannels" 1873 && e != "acodec" && e != "abitrate" && e != "asample_rate" && e != "achannels"
1722 && e != "aparams" && e != "output" 1874 && e != "aparams" && e != "output"
1723 && e != "iformat" && e != "oformat" 1875 && e != "iformat" && e != "oformat"
1724 - ) { 1876 + ) {
1725 ret = ERROR_SYSTEM_CONFIG_INVALID; 1877 ret = ERROR_SYSTEM_CONFIG_INVALID;
1726 srs_error("unsupported vhost transcode engine directive %s, ret=%d", e.c_str(), ret); 1878 srs_error("unsupported vhost transcode engine directive %s, ret=%d", e.c_str(), ret);
1727 return ret; 1879 return ret;
@@ -1745,19 +1897,19 @@ int SrsConfig::check_config() @@ -1745,19 +1897,19 @@ int SrsConfig::check_config()
1745 for (int i = 0; i < (int)vhosts.size(); i++) { 1897 for (int i = 0; i < (int)vhosts.size(); i++) {
1746 SrsConfDirective* vhost = vhosts[i]; 1898 SrsConfDirective* vhost = vhosts[i];
1747 std::vector<std::string> ids; 1899 std::vector<std::string> ids;
1748 - 1900 +
1749 for (int j = 0; j < (int)vhost->directives.size(); j++) { 1901 for (int j = 0; j < (int)vhost->directives.size(); j++) {
1750 SrsConfDirective* conf = vhost->at(j); 1902 SrsConfDirective* conf = vhost->at(j);
1751 if (conf->name != "ingest") { 1903 if (conf->name != "ingest") {
1752 continue; 1904 continue;
1753 } 1905 }
1754 - 1906 +
1755 std::string id = conf->arg0(); 1907 std::string id = conf->arg0();
1756 for (int k = 0; k < (int)ids.size(); k++) { 1908 for (int k = 0; k < (int)ids.size(); k++) {
1757 if (id == ids.at(k)) { 1909 if (id == ids.at(k)) {
1758 ret = ERROR_SYSTEM_CONFIG_INVALID; 1910 ret = ERROR_SYSTEM_CONFIG_INVALID;
1759 - srs_error("directive \"ingest\" id duplicated, vhost=%s, id=%s, ret=%d",  
1760 - vhost->name.c_str(), id.c_str(), ret); 1911 + srs_error("directive \"ingest\" id duplicated, vhost=%s, id=%s, ret=%d",
  1912 + vhost->name.c_str(), id.c_str(), ret);
1761 return ret; 1913 return ret;
1762 } 1914 }
1763 } 1915 }
@@ -1766,135 +1918,6 @@ int SrsConfig::check_config() @@ -1766,135 +1918,6 @@ int SrsConfig::check_config()
1766 } 1918 }
1767 1919
1768 //////////////////////////////////////////////////////////////////////// 1920 ////////////////////////////////////////////////////////////////////////
1769 - // check listen for rtmp.  
1770 - ////////////////////////////////////////////////////////////////////////  
1771 - if (true) {  
1772 - vector<string> listens = get_listens();  
1773 - if (listens.size() <= 0) {  
1774 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1775 - srs_error("directive \"listen\" is empty, ret=%d", ret);  
1776 - return ret;  
1777 - }  
1778 - for (int i = 0; i < (int)listens.size(); i++) {  
1779 - string port = listens[i];  
1780 - if (port.empty() || ::atoi(port.c_str()) <= 0) {  
1781 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1782 - srs_error("directive listen invalid, port=%s, ret=%d", port.c_str(), ret);  
1783 - return ret;  
1784 - }  
1785 - }  
1786 - }  
1787 -  
1788 - ////////////////////////////////////////////////////////////////////////  
1789 - // check max connections  
1790 - ////////////////////////////////////////////////////////////////////////  
1791 - if (get_max_connections() <= 0) {  
1792 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1793 - srs_error("directive max_connections invalid, max_connections=%d, ret=%d", get_max_connections(), ret);  
1794 - return ret;  
1795 - }  
1796 -  
1797 - // check max connections of system limits  
1798 - if (true) {  
1799 - int nb_consumed_fds = (int)get_listens().size();  
1800 - if (!get_http_api_listen().empty()) {  
1801 - nb_consumed_fds++;  
1802 - }  
1803 - if (!get_http_stream_listen().empty()) {  
1804 - nb_consumed_fds++;  
1805 - }  
1806 - if (get_log_tank_file()) {  
1807 - nb_consumed_fds++;  
1808 - }  
1809 - // 0, 1, 2 for stdin, stdout and stderr.  
1810 - nb_consumed_fds += 3;  
1811 -  
1812 - int nb_connections = get_max_connections();  
1813 - int nb_total = nb_connections + nb_consumed_fds;  
1814 -  
1815 - int max_open_files = (int)sysconf(_SC_OPEN_MAX);  
1816 - int nb_canbe = max_open_files - nb_consumed_fds - 1;  
1817 -  
1818 - // for each play connections, we open a pipe(2fds) to convert SrsConsumver to io,  
1819 - // refine performance, @see: https://github.com/simple-rtmp-server/srs/issues/194  
1820 - if (nb_total >= max_open_files) {  
1821 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1822 - srs_error("invalid max_connections=%d, required=%d, system limit to %d, "  
1823 - "total=%d(max_connections=%d, nb_consumed_fds=%d), ret=%d. "  
1824 - "you can change max_connections from %d to %d, or "  
1825 - "you can login as root and set the limit: ulimit -HSn %d",  
1826 - nb_connections, nb_total + 1, max_open_files,  
1827 - nb_total, nb_connections, nb_consumed_fds,  
1828 - ret, nb_connections, nb_canbe, nb_total + 1);  
1829 - return ret;  
1830 - }  
1831 - }  
1832 -  
1833 - ////////////////////////////////////////////////////////////////////////  
1834 - // check heartbeat  
1835 - ////////////////////////////////////////////////////////////////////////  
1836 - if (get_heartbeat_interval() <= 0) {  
1837 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1838 - srs_error("directive heartbeat interval invalid, interval=%"PRId64", ret=%d",  
1839 - get_heartbeat_interval(), ret);  
1840 - return ret;  
1841 - }  
1842 -  
1843 - ////////////////////////////////////////////////////////////////////////  
1844 - // check stats  
1845 - ////////////////////////////////////////////////////////////////////////  
1846 - if (get_stats_network() < 0) {  
1847 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1848 - srs_error("directive stats network invalid, network=%d, ret=%d",  
1849 - get_stats_network(), ret);  
1850 - return ret;  
1851 - }  
1852 - if (true) {  
1853 - vector<std::string> ips = srs_get_local_ipv4_ips();  
1854 - int index = get_stats_network();  
1855 - if (index >= (int)ips.size()) {  
1856 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1857 - srs_error("stats network invalid, total local ip count=%d, index=%d, ret=%d",  
1858 - (int)ips.size(), index, ret);  
1859 - return ret;  
1860 - }  
1861 - srs_warn("stats network use index=%d, ip=%s", index, ips.at(index).c_str());  
1862 - }  
1863 - if (true) {  
1864 - SrsConfDirective* conf = get_stats_disk_device();  
1865 - if (conf == NULL || (int)conf->args.size() <= 0) {  
1866 - srs_warn("stats disk not configed, disk iops disabled.");  
1867 - } else {  
1868 - string disks;  
1869 - for (int i = 0; i < (int)conf->args.size(); i++) {  
1870 - disks += conf->args.at(i);  
1871 - disks += " ";  
1872 - }  
1873 - srs_warn("stats disk list: %s", disks.c_str());  
1874 - }  
1875 - }  
1876 -  
1877 - ////////////////////////////////////////////////////////////////////////  
1878 - // check http api  
1879 - ////////////////////////////////////////////////////////////////////////  
1880 - if (get_http_api_listen().empty()) {  
1881 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1882 - srs_error("directive http_api listen invalid, listen=%s, ret=%d",  
1883 - get_http_api_listen().c_str(), ret);  
1884 - return ret;  
1885 - }  
1886 -  
1887 - ////////////////////////////////////////////////////////////////////////  
1888 - // check http stream  
1889 - ////////////////////////////////////////////////////////////////////////  
1890 - if (get_http_stream_listen().empty()) {  
1891 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1892 - srs_error("directive http_stream listen invalid, listen=%s, ret=%d",  
1893 - get_http_stream_listen().c_str(), ret);  
1894 - return ret;  
1895 - }  
1896 -  
1897 - ////////////////////////////////////////////////////////////////////////  
1898 // check chunk size 1921 // check chunk size
1899 //////////////////////////////////////////////////////////////////////// 1922 ////////////////////////////////////////////////////////////////////////
1900 if (get_global_chunk_size() < SRS_CONSTS_RTMP_MIN_CHUNK_SIZE 1923 if (get_global_chunk_size() < SRS_CONSTS_RTMP_MIN_CHUNK_SIZE
@@ -1918,39 +1941,6 @@ int SrsConfig::check_config() @@ -1918,39 +1941,6 @@ int SrsConfig::check_config()
1918 return ret; 1941 return ret;
1919 } 1942 }
1920 } 1943 }
1921 -  
1922 - ////////////////////////////////////////////////////////////////////////  
1923 - // check log name and level  
1924 - ////////////////////////////////////////////////////////////////////////  
1925 - if (true) {  
1926 - std::string log_filename = this->get_log_file();  
1927 - if (get_log_tank_file() && log_filename.empty()) {  
1928 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1929 - srs_error("must specifies the file to write log to. ret=%d", ret);  
1930 - return ret;  
1931 - }  
1932 - if (get_log_tank_file()) {  
1933 - srs_trace("write log to file %s", log_filename.c_str());  
1934 - srs_trace("you can: tailf %s", log_filename.c_str());  
1935 - srs_trace("@see: %s", SRS_WIKI_URL_LOG);  
1936 - } else {  
1937 - srs_trace("write log to console");  
1938 - }  
1939 - }  
1940 -  
1941 - ////////////////////////////////////////////////////////////////////////  
1942 - // check features  
1943 - ////////////////////////////////////////////////////////////////////////  
1944 -#ifndef SRS_AUTO_HTTP_SERVER  
1945 - if (get_http_stream_enabled()) {  
1946 - srs_warn("http_stream is disabled by configure");  
1947 - }  
1948 -#endif  
1949 -#ifndef SRS_AUTO_HTTP_API  
1950 - if (get_http_api_enabled()) {  
1951 - srs_warn("http_api is disabled by configure");  
1952 - }  
1953 -#endif  
1954 for (int i = 0; i < (int)vhosts.size(); i++) { 1944 for (int i = 0; i < (int)vhosts.size(); i++) {
1955 SrsConfDirective* vhost = vhosts[i]; 1945 SrsConfDirective* vhost = vhosts[i];
1956 srs_assert(vhost != NULL); 1946 srs_assert(vhost != NULL);
@@ -2219,23 +2209,19 @@ SrsConfDirective* SrsConfig::get_vhost(string vhost) @@ -2219,23 +2209,19 @@ SrsConfDirective* SrsConfig::get_vhost(string vhost)
2219 return NULL; 2209 return NULL;
2220 } 2210 }
2221 2211
2222 -vector<SrsConfDirective*> SrsConfig::get_vhosts() 2212 +void SrsConfig::get_vhosts(vector<SrsConfDirective*>& vhosts)
2223 { 2213 {
2224 srs_assert(root); 2214 srs_assert(root);
2225 -  
2226 - std::vector<SrsConfDirective*> vhosts;  
2227 - 2215 +
2228 for (int i = 0; i < (int)root->directives.size(); i++) { 2216 for (int i = 0; i < (int)root->directives.size(); i++) {
2229 SrsConfDirective* conf = root->at(i); 2217 SrsConfDirective* conf = root->at(i);
2230 - 2218 +
2231 if (!conf->is_vhost()) { 2219 if (!conf->is_vhost()) {
2232 continue; 2220 continue;
2233 } 2221 }
2234 - 2222 +
2235 vhosts.push_back(conf); 2223 vhosts.push_back(conf);
2236 } 2224 }
2237 -  
2238 - return vhosts;  
2239 } 2225 }
2240 2226
2241 bool SrsConfig::get_vhost_enabled(string vhost) 2227 bool SrsConfig::get_vhost_enabled(string vhost)
@@ -253,6 +253,11 @@ public: @@ -253,6 +253,11 @@ public:
253 * @remark, user can test the config before reload it. 253 * @remark, user can test the config before reload it.
254 */ 254 */
255 virtual int reload(); 255 virtual int reload();
  256 +private:
  257 + /**
  258 + * reload the vhost section of config.
  259 + */
  260 + virtual int reload_vhost(SrsConfDirective* old_root);
256 protected: 261 protected:
257 /** 262 /**
258 * reload from the config. 263 * reload from the config.
@@ -269,10 +274,6 @@ private: @@ -269,10 +274,6 @@ private:
269 */ 274 */
270 virtual int reload_http_stream(SrsConfDirective* old_root); 275 virtual int reload_http_stream(SrsConfDirective* old_root);
271 /** 276 /**
272 - * reload the vhost section of config.  
273 - */  
274 - virtual int reload_vhost(SrsConfDirective* old_root);  
275 - /**  
276 * reload the transcode section of vhost of config. 277 * reload the transcode section of vhost of config.
277 */ 278 */
278 virtual int reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost); 279 virtual int reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost);
@@ -413,7 +414,7 @@ public: @@ -413,7 +414,7 @@ public:
413 /** 414 /**
414 * get all vhosts in config file. 415 * get all vhosts in config file.
415 */ 416 */
416 - virtual std::vector<SrsConfDirective*> get_vhosts(); 417 + virtual void get_vhosts(std::vector<SrsConfDirective*>& vhosts);
417 /** 418 /**
418 * whether vhost is enabled 419 * whether vhost is enabled
419 * @param vhost, the vhost name. 420 * @param vhost, the vhost name.
@@ -543,20 +543,21 @@ int SrsHttpApi::do_cycle() @@ -543,20 +543,21 @@ int SrsHttpApi::do_cycle()
543 // always free it in this scope. 543 // always free it in this scope.
544 SrsAutoFree(ISrsHttpMessage, req); 544 SrsAutoFree(ISrsHttpMessage, req);
545 545
546 - // TODO: FIXME: use the post body.  
547 - std::string res;  
548 -  
549 - // get response body.  
550 - if ((ret = req->body_read_all(res)) != ERROR_SUCCESS) {  
551 - return ret;  
552 - }  
553 -  
554 // ok, handle http request. 546 // ok, handle http request.
555 SrsHttpResponseWriter writer(&skt); 547 SrsHttpResponseWriter writer(&skt);
556 if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) { 548 if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) {
557 return ret; 549 return ret;
558 } 550 }
559 - 551 +
  552 + // read all rest bytes in request body.
  553 + char buf[SRS_HTTP_READ_CACHE_BYTES];
  554 + ISrsHttpResponseReader* br = req->body_reader();
  555 + while (!br->eof()) {
  556 + if ((ret = br->read(buf, SRS_HTTP_READ_CACHE_BYTES, NULL)) != ERROR_SUCCESS) {
  557 + return ret;
  558 + }
  559 + }
  560 +
560 // donot keep alive, disconnect it. 561 // donot keep alive, disconnect it.
561 // @see https://github.com/simple-rtmp-server/srs/issues/399 562 // @see https://github.com/simple-rtmp-server/srs/issues/399
562 if (!req->is_keep_alive()) { 563 if (!req->is_keep_alive()) {
@@ -863,6 +863,17 @@ void SrsHttpStreamServer::http_unmount(SrsSource* s, SrsRequest* r) @@ -863,6 +863,17 @@ void SrsHttpStreamServer::http_unmount(SrsSource* s, SrsRequest* r)
863 entry->stream->entry->enabled = false; 863 entry->stream->entry->enabled = false;
864 } 864 }
865 865
  866 +int SrsHttpStreamServer::on_reload_vhost_added(string vhost)
  867 +{
  868 + int ret = ERROR_SUCCESS;
  869 +
  870 + if ((ret = on_reload_vhost_http_remux_updated(vhost)) != ERROR_SUCCESS) {
  871 + return ret;
  872 + }
  873 +
  874 + return ret;
  875 +}
  876 +
866 int SrsHttpStreamServer::on_reload_vhost_http_remux_updated(string vhost) 877 int SrsHttpStreamServer::on_reload_vhost_http_remux_updated(string vhost)
867 { 878 {
868 int ret = ERROR_SUCCESS; 879 int ret = ERROR_SUCCESS;
@@ -354,6 +354,7 @@ public: @@ -354,6 +354,7 @@ public:
354 virtual void unmount_hls(SrsRequest* r); 354 virtual void unmount_hls(SrsRequest* r);
355 // interface ISrsReloadHandler. 355 // interface ISrsReloadHandler.
356 public: 356 public:
  357 + virtual int on_reload_vhost_added(std::string vhost);
357 virtual int on_reload_vhost_http_remux_updated(std::string vhost); 358 virtual int on_reload_vhost_http_remux_updated(std::string vhost);
358 virtual int on_reload_vhost_hls(std::string vhost); 359 virtual int on_reload_vhost_hls(std::string vhost);
359 // interface ISrsHttpMatchHijacker 360 // interface ISrsHttpMatchHijacker
@@ -293,7 +293,8 @@ int SrsIngester::parse() @@ -293,7 +293,8 @@ int SrsIngester::parse()
293 int ret = ERROR_SUCCESS; 293 int ret = ERROR_SUCCESS;
294 294
295 // parse ingesters 295 // parse ingesters
296 - std::vector<SrsConfDirective*> vhosts = _srs_config->get_vhosts(); 296 + std::vector<SrsConfDirective*> vhosts;
  297 + _srs_config->get_vhosts(vhosts);
297 298
298 for (int i = 0; i < (int)vhosts.size(); i++) { 299 for (int i = 0; i < (int)vhosts.size(); i++) {
299 SrsConfDirective* vhost = vhosts[i]; 300 SrsConfDirective* vhost = vhosts[i];
@@ -51,8 +51,8 @@ public: @@ -51,8 +51,8 @@ public:
51 /** 51 /**
52 * auto delete the ptr. 52 * auto delete the ptr.
53 */ 53 */
54 - impl__SrsAutoFree(T** _ptr) {  
55 - ptr = _ptr; 54 + impl__SrsAutoFree(T** p) {
  55 + ptr = p;
56 } 56 }
57 57
58 virtual ~impl__SrsAutoFree() { 58 virtual ~impl__SrsAutoFree() {
@@ -46,50 +46,50 @@ SrsFileWriter::~SrsFileWriter() @@ -46,50 +46,50 @@ SrsFileWriter::~SrsFileWriter()
46 close(); 46 close();
47 } 47 }
48 48
49 -int SrsFileWriter::open(string file) 49 +int SrsFileWriter::open(string p)
50 { 50 {
51 int ret = ERROR_SUCCESS; 51 int ret = ERROR_SUCCESS;
52 52
53 if (fd > 0) { 53 if (fd > 0) {
54 ret = ERROR_SYSTEM_FILE_ALREADY_OPENED; 54 ret = ERROR_SYSTEM_FILE_ALREADY_OPENED;
55 - srs_error("file %s already opened. ret=%d", _file.c_str(), ret); 55 + srs_error("file %s already opened. ret=%d", path.c_str(), ret);
56 return ret; 56 return ret;
57 } 57 }
58 58
59 int flags = O_CREAT|O_WRONLY|O_TRUNC; 59 int flags = O_CREAT|O_WRONLY|O_TRUNC;
60 mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH; 60 mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH;
61 61
62 - if ((fd = ::open(file.c_str(), flags, mode)) < 0) { 62 + if ((fd = ::open(p.c_str(), flags, mode)) < 0) {
63 ret = ERROR_SYSTEM_FILE_OPENE; 63 ret = ERROR_SYSTEM_FILE_OPENE;
64 - srs_error("open file %s failed. ret=%d", file.c_str(), ret); 64 + srs_error("open file %s failed. ret=%d", p.c_str(), ret);
65 return ret; 65 return ret;
66 } 66 }
67 67
68 - _file = file; 68 + path = p;
69 69
70 return ret; 70 return ret;
71 } 71 }
72 72
73 -int SrsFileWriter::open_append(string file) 73 +int SrsFileWriter::open_append(string p)
74 { 74 {
75 int ret = ERROR_SUCCESS; 75 int ret = ERROR_SUCCESS;
76 76
77 if (fd > 0) { 77 if (fd > 0) {
78 ret = ERROR_SYSTEM_FILE_ALREADY_OPENED; 78 ret = ERROR_SYSTEM_FILE_ALREADY_OPENED;
79 - srs_error("file %s already opened. ret=%d", _file.c_str(), ret); 79 + srs_error("file %s already opened. ret=%d", path.c_str(), ret);
80 return ret; 80 return ret;
81 } 81 }
82 82
83 int flags = O_APPEND|O_WRONLY; 83 int flags = O_APPEND|O_WRONLY;
84 mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH; 84 mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH;
85 85
86 - if ((fd = ::open(file.c_str(), flags, mode)) < 0) { 86 + if ((fd = ::open(p.c_str(), flags, mode)) < 0) {
87 ret = ERROR_SYSTEM_FILE_OPENE; 87 ret = ERROR_SYSTEM_FILE_OPENE;
88 - srs_error("open file %s failed. ret=%d", file.c_str(), ret); 88 + srs_error("open file %s failed. ret=%d", p.c_str(), ret);
89 return ret; 89 return ret;
90 } 90 }
91 91
92 - _file = file; 92 + path = p;
93 93
94 return ret; 94 return ret;
95 } 95 }
@@ -104,7 +104,7 @@ void SrsFileWriter::close() @@ -104,7 +104,7 @@ void SrsFileWriter::close()
104 104
105 if (::close(fd) < 0) { 105 if (::close(fd) < 0) {
106 ret = ERROR_SYSTEM_FILE_CLOSE; 106 ret = ERROR_SYSTEM_FILE_CLOSE;
107 - srs_error("close file %s failed. ret=%d", _file.c_str(), ret); 107 + srs_error("close file %s failed. ret=%d", path.c_str(), ret);
108 return; 108 return;
109 } 109 }
110 fd = -1; 110 fd = -1;
@@ -135,7 +135,7 @@ int SrsFileWriter::write(void* buf, size_t count, ssize_t* pnwrite) @@ -135,7 +135,7 @@ int SrsFileWriter::write(void* buf, size_t count, ssize_t* pnwrite)
135 // TODO: FIXME: use st_write. 135 // TODO: FIXME: use st_write.
136 if ((nwrite = ::write(fd, buf, count)) < 0) { 136 if ((nwrite = ::write(fd, buf, count)) < 0) {
137 ret = ERROR_SYSTEM_FILE_WRITE; 137 ret = ERROR_SYSTEM_FILE_WRITE;
138 - srs_error("write to file %s failed. ret=%d", _file.c_str(), ret); 138 + srs_error("write to file %s failed. ret=%d", path.c_str(), ret);
139 return ret; 139 return ret;
140 } 140 }
141 141
@@ -177,23 +177,23 @@ SrsFileReader::~SrsFileReader() @@ -177,23 +177,23 @@ SrsFileReader::~SrsFileReader()
177 close(); 177 close();
178 } 178 }
179 179
180 -int SrsFileReader::open(string file) 180 +int SrsFileReader::open(string p)
181 { 181 {
182 int ret = ERROR_SUCCESS; 182 int ret = ERROR_SUCCESS;
183 183
184 if (fd > 0) { 184 if (fd > 0) {
185 ret = ERROR_SYSTEM_FILE_ALREADY_OPENED; 185 ret = ERROR_SYSTEM_FILE_ALREADY_OPENED;
186 - srs_error("file %s already opened. ret=%d", _file.c_str(), ret); 186 + srs_error("file %s already opened. ret=%d", path.c_str(), ret);
187 return ret; 187 return ret;
188 } 188 }
189 189
190 - if ((fd = ::open(file.c_str(), O_RDONLY)) < 0) { 190 + if ((fd = ::open(p.c_str(), O_RDONLY)) < 0) {
191 ret = ERROR_SYSTEM_FILE_OPENE; 191 ret = ERROR_SYSTEM_FILE_OPENE;
192 - srs_error("open file %s failed. ret=%d", file.c_str(), ret); 192 + srs_error("open file %s failed. ret=%d", p.c_str(), ret);
193 return ret; 193 return ret;
194 } 194 }
195 195
196 - _file = file; 196 + path = p;
197 197
198 return ret; 198 return ret;
199 } 199 }
@@ -208,7 +208,7 @@ void SrsFileReader::close() @@ -208,7 +208,7 @@ void SrsFileReader::close()
208 208
209 if (::close(fd) < 0) { 209 if (::close(fd) < 0) {
210 ret = ERROR_SYSTEM_FILE_CLOSE; 210 ret = ERROR_SYSTEM_FILE_CLOSE;
211 - srs_error("close file %s failed. ret=%d", _file.c_str(), ret); 211 + srs_error("close file %s failed. ret=%d", path.c_str(), ret);
212 return; 212 return;
213 } 213 }
214 fd = -1; 214 fd = -1;
@@ -252,7 +252,7 @@ int SrsFileReader::read(void* buf, size_t count, ssize_t* pnread) @@ -252,7 +252,7 @@ int SrsFileReader::read(void* buf, size_t count, ssize_t* pnread)
252 // TODO: FIXME: use st_read. 252 // TODO: FIXME: use st_read.
253 if ((nread = ::read(fd, buf, count)) < 0) { 253 if ((nread = ::read(fd, buf, count)) < 0) {
254 ret = ERROR_SYSTEM_FILE_READ; 254 ret = ERROR_SYSTEM_FILE_READ;
255 - srs_error("read from file %s failed. ret=%d", _file.c_str(), ret); 255 + srs_error("read from file %s failed. ret=%d", path.c_str(), ret);
256 return ret; 256 return ret;
257 } 257 }
258 258
@@ -42,20 +42,26 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -42,20 +42,26 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 class SrsFileWriter 42 class SrsFileWriter
43 { 43 {
44 private: 44 private:
45 - std::string _file; 45 + std::string path;
46 int fd; 46 int fd;
47 public: 47 public:
48 SrsFileWriter(); 48 SrsFileWriter();
49 virtual ~SrsFileWriter(); 49 virtual ~SrsFileWriter();
50 public: 50 public:
51 /** 51 /**
52 - * open file writer, can open then close then open...  
53 - */  
54 - virtual int open(std::string file); 52 + * open file writer, in truncate mode.
  53 + * @param p a string indicates the path of file to open.
  54 + */
  55 + virtual int open(std::string p);
55 /** 56 /**
56 - * open file writer in append mode.  
57 - */  
58 - virtual int open_append(std::string file); 57 + * open file writer, in append mode.
  58 + * @param p a string indicates the path of file to open.
  59 + */
  60 + virtual int open_append(std::string p);
  61 + /**
  62 + * close current writer.
  63 + * @remark user can reopen again.
  64 + */
59 virtual void close(); 65 virtual void close();
60 public: 66 public:
61 virtual bool is_open(); 67 virtual bool is_open();
@@ -80,16 +86,21 @@ public: @@ -80,16 +86,21 @@ public:
80 class SrsFileReader 86 class SrsFileReader
81 { 87 {
82 private: 88 private:
83 - std::string _file; 89 + std::string path;
84 int fd; 90 int fd;
85 public: 91 public:
86 SrsFileReader(); 92 SrsFileReader();
87 virtual ~SrsFileReader(); 93 virtual ~SrsFileReader();
88 public: 94 public:
89 /** 95 /**
90 - * open file reader, can open then close then open...  
91 - */  
92 - virtual int open(std::string file); 96 + * open file reader.
  97 + * @param p a string indicates the path of file to open.
  98 + */
  99 + virtual int open(std::string p);
  100 + /**
  101 + * close current reader.
  102 + * @remark user can reopen again.
  103 + */
93 virtual void close(); 104 virtual void close();
94 public: 105 public:
95 // TODO: FIXME: extract interface. 106 // TODO: FIXME: extract interface.
@@ -332,7 +332,7 @@ SrsSharedPtrMessage* SrsSharedPtrMessage::copy() @@ -332,7 +332,7 @@ SrsSharedPtrMessage* SrsSharedPtrMessage::copy()
332 332
333 SrsFlvEncoder::SrsFlvEncoder() 333 SrsFlvEncoder::SrsFlvEncoder()
334 { 334 {
335 - _fs = NULL; 335 + reader = NULL;
336 tag_stream = new SrsStream(); 336 tag_stream = new SrsStream();
337 337
338 #ifdef SRS_PERF_FAST_FLV_ENCODER 338 #ifdef SRS_PERF_FAST_FLV_ENCODER
@@ -356,19 +356,19 @@ SrsFlvEncoder::~SrsFlvEncoder() @@ -356,19 +356,19 @@ SrsFlvEncoder::~SrsFlvEncoder()
356 #endif 356 #endif
357 } 357 }
358 358
359 -int SrsFlvEncoder::initialize(SrsFileWriter* fs) 359 +int SrsFlvEncoder::initialize(SrsFileWriter* fr)
360 { 360 {
361 int ret = ERROR_SUCCESS; 361 int ret = ERROR_SUCCESS;
362 362
363 - srs_assert(fs); 363 + srs_assert(fr);
364 364
365 - if (!fs->is_open()) { 365 + if (!fr->is_open()) {
366 ret = ERROR_KERNEL_FLV_STREAM_CLOSED; 366 ret = ERROR_KERNEL_FLV_STREAM_CLOSED;
367 srs_warn("stream is not open for encoder. ret=%d", ret); 367 srs_warn("stream is not open for encoder. ret=%d", ret);
368 return ret; 368 return ret;
369 } 369 }
370 370
371 - _fs = fs; 371 + reader = fr;
372 372
373 return ret; 373 return ret;
374 } 374 }
@@ -402,14 +402,14 @@ int SrsFlvEncoder::write_header(char flv_header[9]) @@ -402,14 +402,14 @@ int SrsFlvEncoder::write_header(char flv_header[9])
402 int ret = ERROR_SUCCESS; 402 int ret = ERROR_SUCCESS;
403 403
404 // write data. 404 // write data.
405 - if ((ret = _fs->write(flv_header, 9, NULL)) != ERROR_SUCCESS) { 405 + if ((ret = reader->write(flv_header, 9, NULL)) != ERROR_SUCCESS) {
406 srs_error("write flv header failed. ret=%d", ret); 406 srs_error("write flv header failed. ret=%d", ret);
407 return ret; 407 return ret;
408 } 408 }
409 409
410 // previous tag size. 410 // previous tag size.
411 char pts[] = { (char)0x00, (char)0x00, (char)0x00, (char)0x00 }; 411 char pts[] = { (char)0x00, (char)0x00, (char)0x00, (char)0x00 };
412 - if ((ret = _fs->write(pts, 4, NULL)) != ERROR_SUCCESS) { 412 + if ((ret = reader->write(pts, 4, NULL)) != ERROR_SUCCESS) {
413 return ret; 413 return ret;
414 } 414 }
415 415
@@ -552,7 +552,7 @@ int SrsFlvEncoder::write_tags(SrsSharedPtrMessage** msgs, int count) @@ -552,7 +552,7 @@ int SrsFlvEncoder::write_tags(SrsSharedPtrMessage** msgs, int count)
552 iovs += 3; 552 iovs += 3;
553 } 553 }
554 554
555 - if ((ret = _fs->writev(iovss, nb_iovss, NULL)) != ERROR_SUCCESS) { 555 + if ((ret = reader->writev(iovss, nb_iovss, NULL)) != ERROR_SUCCESS) {
556 if (!srs_is_client_gracefully_close(ret)) { 556 if (!srs_is_client_gracefully_close(ret)) {
557 srs_error("write flv tags failed. ret=%d", ret); 557 srs_error("write flv tags failed. ret=%d", ret);
558 } 558 }
@@ -683,7 +683,7 @@ int SrsFlvEncoder::write_tag(char* header, int header_size, char* tag, int tag_s @@ -683,7 +683,7 @@ int SrsFlvEncoder::write_tag(char* header, int header_size, char* tag, int tag_s
683 iovs[2].iov_base = pre_size; 683 iovs[2].iov_base = pre_size;
684 iovs[2].iov_len = SRS_FLV_PREVIOUS_TAG_SIZE; 684 iovs[2].iov_len = SRS_FLV_PREVIOUS_TAG_SIZE;
685 685
686 - if ((ret = _fs->writev(iovs, 3, NULL)) != ERROR_SUCCESS) { 686 + if ((ret = reader->writev(iovs, 3, NULL)) != ERROR_SUCCESS) {
687 if (!srs_is_client_gracefully_close(ret)) { 687 if (!srs_is_client_gracefully_close(ret)) {
688 srs_error("write flv tag failed. ret=%d", ret); 688 srs_error("write flv tag failed. ret=%d", ret);
689 } 689 }
@@ -695,7 +695,7 @@ int SrsFlvEncoder::write_tag(char* header, int header_size, char* tag, int tag_s @@ -695,7 +695,7 @@ int SrsFlvEncoder::write_tag(char* header, int header_size, char* tag, int tag_s
695 695
696 SrsFlvDecoder::SrsFlvDecoder() 696 SrsFlvDecoder::SrsFlvDecoder()
697 { 697 {
698 - _fs = NULL; 698 + reader = NULL;
699 tag_stream = new SrsStream(); 699 tag_stream = new SrsStream();
700 } 700 }
701 701
@@ -704,19 +704,19 @@ SrsFlvDecoder::~SrsFlvDecoder() @@ -704,19 +704,19 @@ SrsFlvDecoder::~SrsFlvDecoder()
704 srs_freep(tag_stream); 704 srs_freep(tag_stream);
705 } 705 }
706 706
707 -int SrsFlvDecoder::initialize(SrsFileReader* fs) 707 +int SrsFlvDecoder::initialize(SrsFileReader* fr)
708 { 708 {
709 int ret = ERROR_SUCCESS; 709 int ret = ERROR_SUCCESS;
710 710
711 - srs_assert(fs); 711 + srs_assert(fr);
712 712
713 - if (!fs->is_open()) { 713 + if (!fr->is_open()) {
714 ret = ERROR_KERNEL_FLV_STREAM_CLOSED; 714 ret = ERROR_KERNEL_FLV_STREAM_CLOSED;
715 srs_warn("stream is not open for decoder. ret=%d", ret); 715 srs_warn("stream is not open for decoder. ret=%d", ret);
716 return ret; 716 return ret;
717 } 717 }
718 718
719 - _fs = fs; 719 + reader = fr;
720 720
721 return ret; 721 return ret;
722 } 722 }
@@ -727,7 +727,7 @@ int SrsFlvDecoder::read_header(char header[9]) @@ -727,7 +727,7 @@ int SrsFlvDecoder::read_header(char header[9])
727 727
728 srs_assert(header); 728 srs_assert(header);
729 729
730 - if ((ret = _fs->read(header, 9, NULL)) != ERROR_SUCCESS) { 730 + if ((ret = reader->read(header, 9, NULL)) != ERROR_SUCCESS) {
731 return ret; 731 return ret;
732 } 732 }
733 733
@@ -752,7 +752,7 @@ int SrsFlvDecoder::read_tag_header(char* ptype, int32_t* pdata_size, u_int32_t* @@ -752,7 +752,7 @@ int SrsFlvDecoder::read_tag_header(char* ptype, int32_t* pdata_size, u_int32_t*
752 char th[11]; // tag header 752 char th[11]; // tag header
753 753
754 // read tag header 754 // read tag header
755 - if ((ret = _fs->read(th, 11, NULL)) != ERROR_SUCCESS) { 755 + if ((ret = reader->read(th, 11, NULL)) != ERROR_SUCCESS) {
756 if (ret != ERROR_SYSTEM_FILE_EOF) { 756 if (ret != ERROR_SYSTEM_FILE_EOF) {
757 srs_error("read flv tag header failed. ret=%d", ret); 757 srs_error("read flv tag header failed. ret=%d", ret);
758 } 758 }
@@ -789,7 +789,7 @@ int SrsFlvDecoder::read_tag_data(char* data, int32_t size) @@ -789,7 +789,7 @@ int SrsFlvDecoder::read_tag_data(char* data, int32_t size)
789 789
790 srs_assert(data); 790 srs_assert(data);
791 791
792 - if ((ret = _fs->read(data, size, NULL)) != ERROR_SUCCESS) { 792 + if ((ret = reader->read(data, size, NULL)) != ERROR_SUCCESS) {
793 if (ret != ERROR_SYSTEM_FILE_EOF) { 793 if (ret != ERROR_SYSTEM_FILE_EOF) {
794 srs_error("read flv tag header failed. ret=%d", ret); 794 srs_error("read flv tag header failed. ret=%d", ret);
795 } 795 }
@@ -807,7 +807,7 @@ int SrsFlvDecoder::read_previous_tag_size(char previous_tag_size[4]) @@ -807,7 +807,7 @@ int SrsFlvDecoder::read_previous_tag_size(char previous_tag_size[4])
807 srs_assert(previous_tag_size); 807 srs_assert(previous_tag_size);
808 808
809 // ignore 4bytes tag size. 809 // ignore 4bytes tag size.
810 - if ((ret = _fs->read(previous_tag_size, 4, NULL)) != ERROR_SUCCESS) { 810 + if ((ret = reader->read(previous_tag_size, 4, NULL)) != ERROR_SUCCESS) {
811 if (ret != ERROR_SYSTEM_FILE_EOF) { 811 if (ret != ERROR_SYSTEM_FILE_EOF) {
812 srs_error("read flv previous tag size failed. ret=%d", ret); 812 srs_error("read flv previous tag size failed. ret=%d", ret);
813 } 813 }
@@ -819,7 +819,7 @@ int SrsFlvDecoder::read_previous_tag_size(char previous_tag_size[4]) @@ -819,7 +819,7 @@ int SrsFlvDecoder::read_previous_tag_size(char previous_tag_size[4])
819 819
820 SrsFlvVodStreamDecoder::SrsFlvVodStreamDecoder() 820 SrsFlvVodStreamDecoder::SrsFlvVodStreamDecoder()
821 { 821 {
822 - _fs = NULL; 822 + reader = NULL;
823 tag_stream = new SrsStream(); 823 tag_stream = new SrsStream();
824 } 824 }
825 825
@@ -828,19 +828,19 @@ SrsFlvVodStreamDecoder::~SrsFlvVodStreamDecoder() @@ -828,19 +828,19 @@ SrsFlvVodStreamDecoder::~SrsFlvVodStreamDecoder()
828 srs_freep(tag_stream); 828 srs_freep(tag_stream);
829 } 829 }
830 830
831 -int SrsFlvVodStreamDecoder::initialize(SrsFileReader* fs) 831 +int SrsFlvVodStreamDecoder::initialize(SrsFileReader* fr)
832 { 832 {
833 int ret = ERROR_SUCCESS; 833 int ret = ERROR_SUCCESS;
834 834
835 - srs_assert(fs); 835 + srs_assert(fr);
836 836
837 - if (!fs->is_open()) { 837 + if (!fr->is_open()) {
838 ret = ERROR_KERNEL_FLV_STREAM_CLOSED; 838 ret = ERROR_KERNEL_FLV_STREAM_CLOSED;
839 srs_warn("stream is not open for decoder. ret=%d", ret); 839 srs_warn("stream is not open for decoder. ret=%d", ret);
840 return ret; 840 return ret;
841 } 841 }
842 842
843 - _fs = fs; 843 + reader = fr;
844 844
845 return ret; 845 return ret;
846 } 846 }
@@ -857,7 +857,7 @@ int SrsFlvVodStreamDecoder::read_header_ext(char header[13]) @@ -857,7 +857,7 @@ int SrsFlvVodStreamDecoder::read_header_ext(char header[13])
857 // 9bytes header and 4bytes first previous-tag-size 857 // 9bytes header and 4bytes first previous-tag-size
858 int size = 13; 858 int size = 13;
859 859
860 - if ((ret = _fs->read(header, size, NULL)) != ERROR_SUCCESS) { 860 + if ((ret = reader->read(header, size, NULL)) != ERROR_SUCCESS) {
861 return ret; 861 return ret;
862 } 862 }
863 863
@@ -891,7 +891,7 @@ int SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart, int* p @@ -891,7 +891,7 @@ int SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart, int* p
891 int64_t av_sequence_offset_start = -1; 891 int64_t av_sequence_offset_start = -1;
892 int64_t av_sequence_offset_end = -1; 892 int64_t av_sequence_offset_end = -1;
893 for (;;) { 893 for (;;) {
894 - if ((ret = _fs->read(tag_header, SRS_FLV_TAG_HEADER_SIZE, NULL)) != ERROR_SUCCESS) { 894 + if ((ret = reader->read(tag_header, SRS_FLV_TAG_HEADER_SIZE, NULL)) != ERROR_SUCCESS) {
895 return ret; 895 return ret;
896 } 896 }
897 897
@@ -907,7 +907,7 @@ int SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart, int* p @@ -907,7 +907,7 @@ int SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart, int* p
907 bool is_not_av = !is_video && !is_audio; 907 bool is_not_av = !is_video && !is_audio;
908 if (is_not_av) { 908 if (is_not_av) {
909 // skip body and tag size. 909 // skip body and tag size.
910 - _fs->skip(data_size + SRS_FLV_PREVIOUS_TAG_SIZE); 910 + reader->skip(data_size + SRS_FLV_PREVIOUS_TAG_SIZE);
911 continue; 911 continue;
912 } 912 }
913 913
@@ -926,10 +926,10 @@ int SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart, int* p @@ -926,10 +926,10 @@ int SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart, int* p
926 got_video = true; 926 got_video = true;
927 927
928 if (av_sequence_offset_start < 0) { 928 if (av_sequence_offset_start < 0) {
929 - av_sequence_offset_start = _fs->tellg() - SRS_FLV_TAG_HEADER_SIZE; 929 + av_sequence_offset_start = reader->tellg() - SRS_FLV_TAG_HEADER_SIZE;
930 } 930 }
931 - av_sequence_offset_end = _fs->tellg() + data_size + SRS_FLV_PREVIOUS_TAG_SIZE;  
932 - _fs->skip(data_size + SRS_FLV_PREVIOUS_TAG_SIZE); 931 + av_sequence_offset_end = reader->tellg() + data_size + SRS_FLV_PREVIOUS_TAG_SIZE;
  932 + reader->skip(data_size + SRS_FLV_PREVIOUS_TAG_SIZE);
933 } 933 }
934 934
935 // audio 935 // audio
@@ -938,16 +938,16 @@ int SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart, int* p @@ -938,16 +938,16 @@ int SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart, int* p
938 got_audio = true; 938 got_audio = true;
939 939
940 if (av_sequence_offset_start < 0) { 940 if (av_sequence_offset_start < 0) {
941 - av_sequence_offset_start = _fs->tellg() - SRS_FLV_TAG_HEADER_SIZE; 941 + av_sequence_offset_start = reader->tellg() - SRS_FLV_TAG_HEADER_SIZE;
942 } 942 }
943 - av_sequence_offset_end = _fs->tellg() + data_size + SRS_FLV_PREVIOUS_TAG_SIZE;  
944 - _fs->skip(data_size + SRS_FLV_PREVIOUS_TAG_SIZE); 943 + av_sequence_offset_end = reader->tellg() + data_size + SRS_FLV_PREVIOUS_TAG_SIZE;
  944 + reader->skip(data_size + SRS_FLV_PREVIOUS_TAG_SIZE);
945 } 945 }
946 } 946 }
947 947
948 // seek to the sequence header start offset. 948 // seek to the sequence header start offset.
949 if (av_sequence_offset_start > 0) { 949 if (av_sequence_offset_start > 0) {
950 - _fs->lseek(av_sequence_offset_start); 950 + reader->lseek(av_sequence_offset_start);
951 *pstart = av_sequence_offset_start; 951 *pstart = av_sequence_offset_start;
952 *psize = (int)(av_sequence_offset_end - av_sequence_offset_start); 952 *psize = (int)(av_sequence_offset_end - av_sequence_offset_start);
953 } 953 }
@@ -959,19 +959,19 @@ int SrsFlvVodStreamDecoder::lseek(int64_t offset) @@ -959,19 +959,19 @@ int SrsFlvVodStreamDecoder::lseek(int64_t offset)
959 { 959 {
960 int ret = ERROR_SUCCESS; 960 int ret = ERROR_SUCCESS;
961 961
962 - if (offset >= _fs->filesize()) { 962 + if (offset >= reader->filesize()) {
963 ret = ERROR_SYSTEM_FILE_EOF; 963 ret = ERROR_SYSTEM_FILE_EOF;
964 srs_warn("flv fast decoder seek overflow file, " 964 srs_warn("flv fast decoder seek overflow file, "
965 "size=%"PRId64", offset=%"PRId64", ret=%d", 965 "size=%"PRId64", offset=%"PRId64", ret=%d",
966 - _fs->filesize(), offset, ret); 966 + reader->filesize(), offset, ret);
967 return ret; 967 return ret;
968 } 968 }
969 969
970 - if (_fs->lseek(offset) < 0) { 970 + if (reader->lseek(offset) < 0) {
971 ret = ERROR_SYSTEM_FILE_SEEK; 971 ret = ERROR_SYSTEM_FILE_SEEK;
972 srs_warn("flv fast decoder seek error, " 972 srs_warn("flv fast decoder seek error, "
973 "size=%"PRId64", offset=%"PRId64", ret=%d", 973 "size=%"PRId64", offset=%"PRId64", ret=%d",
974 - _fs->filesize(), offset, ret); 974 + reader->filesize(), offset, ret);
975 return ret; 975 return ret;
976 } 976 }
977 977
@@ -434,7 +434,7 @@ public: @@ -434,7 +434,7 @@ public:
434 class SrsFlvEncoder 434 class SrsFlvEncoder
435 { 435 {
436 private: 436 private:
437 - SrsFileWriter* _fs; 437 + SrsFileWriter* reader;
438 private: 438 private:
439 SrsStream* tag_stream; 439 SrsStream* tag_stream;
440 char tag_header[SRS_FLV_TAG_HEADER_SIZE]; 440 char tag_header[SRS_FLV_TAG_HEADER_SIZE];
@@ -445,9 +445,9 @@ public: @@ -445,9 +445,9 @@ public:
445 /** 445 /**
446 * initialize the underlayer file stream. 446 * initialize the underlayer file stream.
447 * @remark user can initialize multiple times to encode multiple flv files. 447 * @remark user can initialize multiple times to encode multiple flv files.
448 - * @remark, user must free the fs, flv encoder never close/free it. 448 + * @remark, user must free the @param fr, flv encoder never close/free it.
449 */ 449 */
450 - virtual int initialize(SrsFileWriter* fs); 450 + virtual int initialize(SrsFileWriter* fr);
451 public: 451 public:
452 /** 452 /**
453 * write flv header. 453 * write flv header.
@@ -512,7 +512,7 @@ private: @@ -512,7 +512,7 @@ private:
512 class SrsFlvDecoder 512 class SrsFlvDecoder
513 { 513 {
514 private: 514 private:
515 - SrsFileReader* _fs; 515 + SrsFileReader* reader;
516 private: 516 private:
517 SrsStream* tag_stream; 517 SrsStream* tag_stream;
518 public: 518 public:
@@ -522,9 +522,9 @@ public: @@ -522,9 +522,9 @@ public:
522 /** 522 /**
523 * initialize the underlayer file stream 523 * initialize the underlayer file stream
524 * @remark user can initialize multiple times to decode multiple flv files. 524 * @remark user can initialize multiple times to decode multiple flv files.
525 - * @remark, user must free the fs, flv decoder never close/free it. 525 + * @remark user must free the @param fr, flv decoder never close/free it.
526 */ 526 */
527 - virtual int initialize(SrsFileReader* fs); 527 + virtual int initialize(SrsFileReader* fr);
528 public: 528 public:
529 /** 529 /**
530 * read the flv header, donot including the 4bytes previous tag size. 530 * read the flv header, donot including the 4bytes previous tag size.
@@ -556,7 +556,7 @@ public: @@ -556,7 +556,7 @@ public:
556 class SrsFlvVodStreamDecoder 556 class SrsFlvVodStreamDecoder
557 { 557 {
558 private: 558 private:
559 - SrsFileReader* _fs; 559 + SrsFileReader* reader;
560 private: 560 private:
561 SrsStream* tag_stream; 561 SrsStream* tag_stream;
562 public: 562 public:
@@ -566,9 +566,9 @@ public: @@ -566,9 +566,9 @@ public:
566 /** 566 /**
567 * initialize the underlayer file stream 567 * initialize the underlayer file stream
568 * @remark user can initialize multiple times to decode multiple flv files. 568 * @remark user can initialize multiple times to decode multiple flv files.
569 - * @remark, user must free the fs, flv decoder never close/free it. 569 + * @remark user must free the @param fr, flv decoder never close/free it.
570 */ 570 */
571 - virtual int initialize(SrsFileReader* fs); 571 + virtual int initialize(SrsFileReader* fr);
572 public: 572 public:
573 /** 573 /**
574 * read the flv header and its size. 574 * read the flv header and its size.
@@ -40,7 +40,7 @@ using namespace std; @@ -40,7 +40,7 @@ using namespace std;
40 40
41 SrsMp3Encoder::SrsMp3Encoder() 41 SrsMp3Encoder::SrsMp3Encoder()
42 { 42 {
43 - _fs = NULL; 43 + writer = NULL;
44 tag_stream = new SrsStream(); 44 tag_stream = new SrsStream();
45 } 45 }
46 46
@@ -49,19 +49,19 @@ SrsMp3Encoder::~SrsMp3Encoder() @@ -49,19 +49,19 @@ SrsMp3Encoder::~SrsMp3Encoder()
49 srs_freep(tag_stream); 49 srs_freep(tag_stream);
50 } 50 }
51 51
52 -int SrsMp3Encoder::initialize(SrsFileWriter* fs) 52 +int SrsMp3Encoder::initialize(SrsFileWriter* fw)
53 { 53 {
54 int ret = ERROR_SUCCESS; 54 int ret = ERROR_SUCCESS;
55 55
56 - srs_assert(fs); 56 + srs_assert(fw);
57 57
58 - if (!fs->is_open()) { 58 + if (!fw->is_open()) {
59 ret = ERROR_KERNEL_MP3_STREAM_CLOSED; 59 ret = ERROR_KERNEL_MP3_STREAM_CLOSED;
60 srs_warn("stream is not open for encoder. ret=%d", ret); 60 srs_warn("stream is not open for encoder. ret=%d", ret);
61 return ret; 61 return ret;
62 } 62 }
63 63
64 - _fs = fs; 64 + writer = fw;
65 65
66 return ret; 66 return ret;
67 } 67 }
@@ -78,7 +78,7 @@ int SrsMp3Encoder::write_header() @@ -78,7 +78,7 @@ int SrsMp3Encoder::write_header()
78 (char)0x00, (char)0x00, (char)0x00, (char)0x00, // FrameSize 78 (char)0x00, (char)0x00, (char)0x00, (char)0x00, // FrameSize
79 (char)0x00, (char)0x00 // Flags 79 (char)0x00, (char)0x00 // Flags
80 }; 80 };
81 - return _fs->write(id3, sizeof(id3), NULL); 81 + return writer->write(id3, sizeof(id3), NULL);
82 } 82 }
83 83
84 int SrsMp3Encoder::write_audio(int64_t timestamp, char* data, int size) 84 int SrsMp3Encoder::write_audio(int64_t timestamp, char* data, int size)
@@ -122,6 +122,6 @@ int SrsMp3Encoder::write_audio(int64_t timestamp, char* data, int size) @@ -122,6 +122,6 @@ int SrsMp3Encoder::write_audio(int64_t timestamp, char* data, int size)
122 return ret; 122 return ret;
123 } 123 }
124 124
125 - return _fs->write(data + stream->pos(), size - stream->pos(), NULL); 125 + return writer->write(data + stream->pos(), size - stream->pos(), NULL);
126 } 126 }
127 127
@@ -33,7 +33,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -33,7 +33,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 33
34 class SrsStream; 34 class SrsStream;
35 class SrsFileWriter; 35 class SrsFileWriter;
36 -class SrsFileReader;  
37 36
38 /** 37 /**
39 * encode data to aac file. 38 * encode data to aac file.
@@ -41,7 +40,7 @@ class SrsFileReader; @@ -41,7 +40,7 @@ class SrsFileReader;
41 class SrsMp3Encoder 40 class SrsMp3Encoder
42 { 41 {
43 private: 42 private:
44 - SrsFileWriter* _fs; 43 + SrsFileWriter* writer;
45 private: 44 private:
46 SrsStream* tag_stream; 45 SrsStream* tag_stream;
47 public: 46 public:
@@ -51,9 +50,9 @@ public: @@ -51,9 +50,9 @@ public:
51 /** 50 /**
52 * initialize the underlayer file stream. 51 * initialize the underlayer file stream.
53 * @remark user can initialize multiple times to encode multiple mp3 files. 52 * @remark user can initialize multiple times to encode multiple mp3 files.
54 - * @remark, user must free the fs, mp3 encoder never close/free it. 53 + * @remark, user must free the @param fw, mp3 encoder never close/free it.
55 */ 54 */
56 - virtual int initialize(SrsFileWriter* fs); 55 + virtual int initialize(SrsFileWriter* fw);
57 public: 56 public:
58 /** 57 /**
59 * write mp3 id3 v2.3 header. 58 * write mp3 id3 v2.3 header.
@@ -31,8 +31,8 @@ using namespace std; @@ -31,8 +31,8 @@ using namespace std;
31 31
32 SrsStream::SrsStream() 32 SrsStream::SrsStream()
33 { 33 {
34 - p = _bytes = NULL;  
35 - _size = 0; 34 + p = bytes = NULL;
  35 + nb_bytes = 0;
36 36
37 // TODO: support both little and big endian. 37 // TODO: support both little and big endian.
38 srs_assert(srs_is_little_endian()); 38 srs_assert(srs_is_little_endian());
@@ -42,24 +42,24 @@ SrsStream::~SrsStream() @@ -42,24 +42,24 @@ SrsStream::~SrsStream()
42 { 42 {
43 } 43 }
44 44
45 -int SrsStream::initialize(char* bytes, int size) 45 +int SrsStream::initialize(char* b, int nb)
46 { 46 {
47 int ret = ERROR_SUCCESS; 47 int ret = ERROR_SUCCESS;
48 48
49 - if (!bytes) { 49 + if (!b) {
50 ret = ERROR_KERNEL_STREAM_INIT; 50 ret = ERROR_KERNEL_STREAM_INIT;
51 srs_error("stream param bytes must not be NULL. ret=%d", ret); 51 srs_error("stream param bytes must not be NULL. ret=%d", ret);
52 return ret; 52 return ret;
53 } 53 }
54 54
55 - if (size <= 0) { 55 + if (nb <= 0) {
56 ret = ERROR_KERNEL_STREAM_INIT; 56 ret = ERROR_KERNEL_STREAM_INIT;
57 srs_error("stream param size must be positive. ret=%d", ret); 57 srs_error("stream param size must be positive. ret=%d", ret);
58 return ret; 58 return ret;
59 } 59 }
60 60
61 - _size = size;  
62 - p = _bytes = bytes; 61 + nb_bytes = nb;
  62 + p = bytes = b;
63 srs_info("init stream ok, size=%d", size); 63 srs_info("init stream ok, size=%d", size);
64 64
65 return ret; 65 return ret;
@@ -67,29 +67,29 @@ int SrsStream::initialize(char* bytes, int size) @@ -67,29 +67,29 @@ int SrsStream::initialize(char* bytes, int size)
67 67
68 char* SrsStream::data() 68 char* SrsStream::data()
69 { 69 {
70 - return _bytes; 70 + return bytes;
71 } 71 }
72 72
73 int SrsStream::size() 73 int SrsStream::size()
74 { 74 {
75 - return _size; 75 + return nb_bytes;
76 } 76 }
77 77
78 int SrsStream::pos() 78 int SrsStream::pos()
79 { 79 {
80 - return p - _bytes; 80 + return (int)(p - bytes);
81 } 81 }
82 82
83 bool SrsStream::empty() 83 bool SrsStream::empty()
84 { 84 {
85 - return !_bytes || (p >= _bytes + _size); 85 + return !bytes || (p >= bytes + nb_bytes);
86 } 86 }
87 87
88 bool SrsStream::require(int required_size) 88 bool SrsStream::require(int required_size)
89 { 89 {
90 srs_assert(required_size > 0); 90 srs_assert(required_size > 0);
91 91
92 - return required_size <= _size - (p - _bytes); 92 + return required_size <= nb_bytes - (p - bytes);
93 } 93 }
94 94
95 void SrsStream::skip(int size) 95 void SrsStream::skip(int size)
@@ -111,7 +111,7 @@ int16_t SrsStream::read_2bytes() @@ -111,7 +111,7 @@ int16_t SrsStream::read_2bytes()
111 srs_assert(require(2)); 111 srs_assert(require(2));
112 112
113 int16_t value; 113 int16_t value;
114 - pp = (char*)&value; 114 + char* pp = (char*)&value;
115 pp[1] = *p++; 115 pp[1] = *p++;
116 pp[0] = *p++; 116 pp[0] = *p++;
117 117
@@ -123,7 +123,7 @@ int32_t SrsStream::read_3bytes() @@ -123,7 +123,7 @@ int32_t SrsStream::read_3bytes()
123 srs_assert(require(3)); 123 srs_assert(require(3));
124 124
125 int32_t value = 0x00; 125 int32_t value = 0x00;
126 - pp = (char*)&value; 126 + char* pp = (char*)&value;
127 pp[2] = *p++; 127 pp[2] = *p++;
128 pp[1] = *p++; 128 pp[1] = *p++;
129 pp[0] = *p++; 129 pp[0] = *p++;
@@ -136,7 +136,7 @@ int32_t SrsStream::read_4bytes() @@ -136,7 +136,7 @@ int32_t SrsStream::read_4bytes()
136 srs_assert(require(4)); 136 srs_assert(require(4));
137 137
138 int32_t value; 138 int32_t value;
139 - pp = (char*)&value; 139 + char* pp = (char*)&value;
140 pp[3] = *p++; 140 pp[3] = *p++;
141 pp[2] = *p++; 141 pp[2] = *p++;
142 pp[1] = *p++; 142 pp[1] = *p++;
@@ -150,7 +150,7 @@ int64_t SrsStream::read_8bytes() @@ -150,7 +150,7 @@ int64_t SrsStream::read_8bytes()
150 srs_assert(require(8)); 150 srs_assert(require(8));
151 151
152 int64_t value; 152 int64_t value;
153 - pp = (char*)&value; 153 + char* pp = (char*)&value;
154 pp[7] = *p++; 154 pp[7] = *p++;
155 pp[6] = *p++; 155 pp[6] = *p++;
156 pp[5] = *p++; 156 pp[5] = *p++;
@@ -195,7 +195,7 @@ void SrsStream::write_2bytes(int16_t value) @@ -195,7 +195,7 @@ void SrsStream::write_2bytes(int16_t value)
195 { 195 {
196 srs_assert(require(2)); 196 srs_assert(require(2));
197 197
198 - pp = (char*)&value; 198 + char* pp = (char*)&value;
199 *p++ = pp[1]; 199 *p++ = pp[1];
200 *p++ = pp[0]; 200 *p++ = pp[0];
201 } 201 }
@@ -204,7 +204,7 @@ void SrsStream::write_4bytes(int32_t value) @@ -204,7 +204,7 @@ void SrsStream::write_4bytes(int32_t value)
204 { 204 {
205 srs_assert(require(4)); 205 srs_assert(require(4));
206 206
207 - pp = (char*)&value; 207 + char* pp = (char*)&value;
208 *p++ = pp[3]; 208 *p++ = pp[3];
209 *p++ = pp[2]; 209 *p++ = pp[2];
210 *p++ = pp[1]; 210 *p++ = pp[1];
@@ -215,7 +215,7 @@ void SrsStream::write_3bytes(int32_t value) @@ -215,7 +215,7 @@ void SrsStream::write_3bytes(int32_t value)
215 { 215 {
216 srs_assert(require(3)); 216 srs_assert(require(3));
217 217
218 - pp = (char*)&value; 218 + char* pp = (char*)&value;
219 *p++ = pp[2]; 219 *p++ = pp[2];
220 *p++ = pp[1]; 220 *p++ = pp[1];
221 *p++ = pp[0]; 221 *p++ = pp[0];
@@ -225,7 +225,7 @@ void SrsStream::write_8bytes(int64_t value) @@ -225,7 +225,7 @@ void SrsStream::write_8bytes(int64_t value)
225 { 225 {
226 srs_assert(require(8)); 226 srs_assert(require(8));
227 227
228 - pp = (char*)&value; 228 + char* pp = (char*)&value;
229 *p++ = pp[7]; 229 *p++ = pp[7];
230 *p++ = pp[6]; 230 *p++ = pp[6];
231 *p++ = pp[5]; 231 *p++ = pp[5];
@@ -238,7 +238,7 @@ void SrsStream::write_8bytes(int64_t value) @@ -238,7 +238,7 @@ void SrsStream::write_8bytes(int64_t value)
238 238
239 void SrsStream::write_string(string value) 239 void SrsStream::write_string(string value)
240 { 240 {
241 - srs_assert(require(value.length())); 241 + srs_assert(require((int)value.length()));
242 242
243 memcpy(p, value.data(), value.length()); 243 memcpy(p, value.data(), value.length());
244 p += value.length(); 244 p += value.length();
@@ -41,23 +41,25 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -41,23 +41,25 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41 class SrsStream 41 class SrsStream
42 { 42 {
43 private: 43 private:
  44 + // current position at bytes.
44 char* p; 45 char* p;
45 - char* pp;  
46 - char* _bytes;  
47 - int _size; 46 + // the bytes data for stream to read or write.
  47 + char* bytes;
  48 + // the total number of bytes.
  49 + int nb_bytes;
48 public: 50 public:
49 SrsStream(); 51 SrsStream();
50 virtual ~SrsStream(); 52 virtual ~SrsStream();
51 public: 53 public:
52 /** 54 /**
53 * initialize the stream from bytes. 55 * initialize the stream from bytes.
54 - * @bytes, the bytes to convert from/to basic types.  
55 - * @size, the size of bytes. 56 + * @b, the bytes to convert from/to basic types.
  57 + * @nb, the size of bytes, total number of bytes for stream.
56 * @remark, stream never free the bytes, user must free it. 58 * @remark, stream never free the bytes, user must free it.
57 * @remark, return error when bytes NULL. 59 * @remark, return error when bytes NULL.
58 * @remark, return error when size is not positive. 60 * @remark, return error when size is not positive.
59 */ 61 */
60 - virtual int initialize(char* bytes, int size); 62 + virtual int initialize(char* b, int nb);
61 // get the status of stream 63 // get the status of stream
62 public: 64 public:
63 /** 65 /**
@@ -2697,11 +2697,11 @@ SrsTSMuxer::~SrsTSMuxer() @@ -2697,11 +2697,11 @@ SrsTSMuxer::~SrsTSMuxer()
2697 close(); 2697 close();
2698 } 2698 }
2699 2699
2700 -int SrsTSMuxer::open(string _path) 2700 +int SrsTSMuxer::open(string p)
2701 { 2701 {
2702 int ret = ERROR_SUCCESS; 2702 int ret = ERROR_SUCCESS;
2703 2703
2704 - path = _path; 2704 + path = p;
2705 2705
2706 close(); 2706 close();
2707 2707
@@ -3048,7 +3048,7 @@ int SrsTsCache::do_cache_avc(SrsAvcAacCodec* codec, SrsCodecSample* sample) @@ -3048,7 +3048,7 @@ int SrsTsCache::do_cache_avc(SrsAvcAacCodec* codec, SrsCodecSample* sample)
3048 3048
3049 SrsTsEncoder::SrsTsEncoder() 3049 SrsTsEncoder::SrsTsEncoder()
3050 { 3050 {
3051 - _fs = NULL; 3051 + writer = NULL;
3052 codec = new SrsAvcAacCodec(); 3052 codec = new SrsAvcAacCodec();
3053 sample = new SrsCodecSample(); 3053 sample = new SrsCodecSample();
3054 cache = new SrsTsCache(); 3054 cache = new SrsTsCache();
@@ -3065,22 +3065,22 @@ SrsTsEncoder::~SrsTsEncoder() @@ -3065,22 +3065,22 @@ SrsTsEncoder::~SrsTsEncoder()
3065 srs_freep(context); 3065 srs_freep(context);
3066 } 3066 }
3067 3067
3068 -int SrsTsEncoder::initialize(SrsFileWriter* fs) 3068 +int SrsTsEncoder::initialize(SrsFileWriter* fw)
3069 { 3069 {
3070 int ret = ERROR_SUCCESS; 3070 int ret = ERROR_SUCCESS;
3071 3071
3072 - srs_assert(fs); 3072 + srs_assert(fw);
3073 3073
3074 - if (!fs->is_open()) { 3074 + if (!fw->is_open()) {
3075 ret = ERROR_KERNEL_FLV_STREAM_CLOSED; 3075 ret = ERROR_KERNEL_FLV_STREAM_CLOSED;
3076 srs_warn("stream is not open for encoder. ret=%d", ret); 3076 srs_warn("stream is not open for encoder. ret=%d", ret);
3077 return ret; 3077 return ret;
3078 } 3078 }
3079 3079
3080 - _fs = fs; 3080 + writer = fw;
3081 3081
3082 srs_freep(muxer); 3082 srs_freep(muxer);
3083 - muxer = new SrsTSMuxer(fs, context, SrsCodecAudioAAC, SrsCodecVideoAVC); 3083 + muxer = new SrsTSMuxer(fw, context, SrsCodecAudioAAC, SrsCodecVideoAVC);
3084 3084
3085 if ((ret = muxer->open("")) != ERROR_SUCCESS) { 3085 if ((ret = muxer->open("")) != ERROR_SUCCESS) {
3086 return ret; 3086 return ret;
@@ -1560,9 +1560,10 @@ public: @@ -1560,9 +1560,10 @@ public:
1560 virtual ~SrsTSMuxer(); 1560 virtual ~SrsTSMuxer();
1561 public: 1561 public:
1562 /** 1562 /**
1563 - * open the writer, donot write the PSI of ts.  
1564 - */  
1565 - virtual int open(std::string _path); 1563 + * open the writer, donot write the PSI of ts.
  1564 + * @param p a string indicates the path of ts file to mux to.
  1565 + */
  1566 + virtual int open(std::string p);
1566 /** 1567 /**
1567 * when open ts, we donot write the header(PSI), 1568 * when open ts, we donot write the header(PSI),
1568 * for user may need to update the acodec to mp3 or others, 1569 * for user may need to update the acodec to mp3 or others,
@@ -1625,7 +1626,7 @@ private: @@ -1625,7 +1626,7 @@ private:
1625 class SrsTsEncoder 1626 class SrsTsEncoder
1626 { 1627 {
1627 private: 1628 private:
1628 - SrsFileWriter* _fs; 1629 + SrsFileWriter* writer;
1629 private: 1630 private:
1630 SrsAvcAacCodec* codec; 1631 SrsAvcAacCodec* codec;
1631 SrsCodecSample* sample; 1632 SrsCodecSample* sample;
@@ -1637,9 +1638,10 @@ public: @@ -1637,9 +1638,10 @@ public:
1637 virtual ~SrsTsEncoder(); 1638 virtual ~SrsTsEncoder();
1638 public: 1639 public:
1639 /** 1640 /**
1640 - * initialize the underlayer file stream.  
1641 - */  
1642 - virtual int initialize(SrsFileWriter* fs); 1641 + * initialize the underlayer file stream.
  1642 + * @param fw the writer to use for ts encoder, user must free it.
  1643 + */
  1644 + virtual int initialize(SrsFileWriter* fw);
1643 public: 1645 public:
1644 /** 1646 /**
1645 * write audio/video packet. 1647 * write audio/video packet.