winlin

change to 0.9.37, for http api/stream

@@ -69,8 +69,9 @@ http_stream { @@ -69,8 +69,9 @@ http_stream {
69 # default: off 69 # default: off
70 enabled on; 70 enabled on;
71 # the http streaming port 71 # the http streaming port
72 - # default: 80  
73 - listen 80; 72 + # @remark, if use lower port, for instance 80, user must start srs by root.
  73 + # default: 8080
  74 + listen 8080;
74 } 75 }
75 76
76 ############################################################################################# 77 #############################################################################################
@@ -416,10 +416,11 @@ RTMP_OBJS="${MODULE_OBJS[@]}" @@ -416,10 +416,11 @@ RTMP_OBJS="${MODULE_OBJS[@]}"
416 MODULE_ID="APP" 416 MODULE_ID="APP"
417 MODULE_DEPENDS=("CORE" "KERNEL" "RTMP") 417 MODULE_DEPENDS=("CORE" "KERNEL" "RTMP")
418 ModuleLibIncs=(${LibSTRoot} ${LibHttpParserRoot} ${SRS_OBJS}) 418 ModuleLibIncs=(${LibSTRoot} ${LibHttpParserRoot} ${SRS_OBJS})
419 -MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_client" "srs_app_socket" "srs_app_source" 419 +MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_rtmp_conn" "srs_app_socket" "srs_app_source"
420 "srs_app_codec" "srs_app_refer" "srs_app_hls" "srs_app_forward" "srs_app_encoder" 420 "srs_app_codec" "srs_app_refer" "srs_app_hls" "srs_app_forward" "srs_app_encoder"
421 "srs_app_http" "srs_app_thread" "srs_app_bandwidth" "srs_app_st" "srs_app_log" 421 "srs_app_http" "srs_app_thread" "srs_app_bandwidth" "srs_app_st" "srs_app_log"
422 - "srs_app_config" "srs_app_pithy_print" "srs_app_reload") 422 + "srs_app_config" "srs_app_pithy_print" "srs_app_reload" "srs_app_http_api"
  423 + "srs_app_http_conn")
423 APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh 424 APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh
424 APP_OBJS="${MODULE_OBJS[@]}" 425 APP_OBJS="${MODULE_OBJS[@]}"
425 # 426 #
@@ -1466,6 +1466,79 @@ double SrsConfig::get_hls_window(string vhost) @@ -1466,6 +1466,79 @@ double SrsConfig::get_hls_window(string vhost)
1466 return ::atof(conf->arg0().c_str()); 1466 return ::atof(conf->arg0().c_str());
1467 } 1467 }
1468 1468
  1469 +SrsConfDirective* SrsConfig::get_http_api()
  1470 +{
  1471 + return root->get("http_api");
  1472 +}
  1473 +
  1474 +bool SrsConfig::get_http_api_enabled()
  1475 +{
  1476 + SrsConfDirective* conf = get_http_api();
  1477 +
  1478 + if (!conf) {
  1479 + return false;
  1480 + }
  1481 +
  1482 + conf = conf->get("enabled");
  1483 + if (conf && conf->arg0() == "on") {
  1484 + return true;
  1485 + }
  1486 +
  1487 + return false;
  1488 +}
  1489 +
  1490 +int SrsConfig::get_http_api_listen()
  1491 +{
  1492 + SrsConfDirective* conf = get_http_api();
  1493 +
  1494 + if (conf) {
  1495 + conf = conf->get("listen");
  1496 +
  1497 + if (conf && !conf->arg0().empty()) {
  1498 + return ::atoi(conf->arg0().c_str());
  1499 + }
  1500 + }
  1501 +
  1502 + return 1985;
  1503 +}
  1504 +
  1505 +SrsConfDirective* SrsConfig::get_http_stream()
  1506 +{
  1507 + return root->get("http_stream");
  1508 +}
  1509 +
  1510 +bool SrsConfig::get_http_stream_enabled()
  1511 +{
  1512 + SrsConfDirective* conf = get_http_stream();
  1513 +
  1514 + if (!conf) {
  1515 + return false;
  1516 + }
  1517 +
  1518 + conf = conf->get("enabled");
  1519 +
  1520 + if (conf && conf->arg0() == "on") {
  1521 + return true;
  1522 + }
  1523 +
  1524 + return false;
  1525 +}
  1526 +
  1527 +int SrsConfig::get_http_stream_listen()
  1528 +{
  1529 + SrsConfDirective* conf = get_http_stream();
  1530 +
  1531 + if (conf) {
  1532 + conf = conf->get("listen");
  1533 +
  1534 + if (conf && !conf->arg0().empty()) {
  1535 + return ::atoi(conf->arg0().c_str());
  1536 + }
  1537 + }
  1538 +
  1539 + return 8080;
  1540 +}
  1541 +
1469 SrsConfDirective* SrsConfig::get_refer(string vhost) 1542 SrsConfDirective* SrsConfig::get_refer(string vhost)
1470 { 1543 {
1471 SrsConfDirective* conf = get_vhost(vhost); 1544 SrsConfDirective* conf = get_vhost(vhost);
@@ -156,6 +156,7 @@ public: @@ -156,6 +156,7 @@ public:
156 virtual bool get_atc(std::string vhost); 156 virtual bool get_atc(std::string vhost);
157 virtual double get_queue_length(std::string vhost); 157 virtual double get_queue_length(std::string vhost);
158 virtual SrsConfDirective* get_forward(std::string vhost); 158 virtual SrsConfDirective* get_forward(std::string vhost);
  159 +// hls section
159 private: 160 private:
160 virtual SrsConfDirective* get_hls(std::string vhost); 161 virtual SrsConfDirective* get_hls(std::string vhost);
161 public: 162 public:
@@ -163,6 +164,20 @@ public: @@ -163,6 +164,20 @@ public:
163 virtual std::string get_hls_path(std::string vhost); 164 virtual std::string get_hls_path(std::string vhost);
164 virtual double get_hls_fragment(std::string vhost); 165 virtual double get_hls_fragment(std::string vhost);
165 virtual double get_hls_window(std::string vhost); 166 virtual double get_hls_window(std::string vhost);
  167 +// http api section
  168 +private:
  169 + virtual SrsConfDirective* get_http_api();
  170 +public:
  171 + virtual bool get_http_api_enabled();
  172 + virtual int get_http_api_listen();
  173 +// http stream section
  174 +private:
  175 + virtual SrsConfDirective* get_http_stream();
  176 +public:
  177 + virtual bool get_http_stream_enabled();
  178 + virtual int get_http_stream_listen();
  179 +// others
  180 +public:
166 virtual SrsConfDirective* get_refer(std::string vhost); 181 virtual SrsConfDirective* get_refer(std::string vhost);
167 virtual SrsConfDirective* get_refer_play(std::string vhost); 182 virtual SrsConfDirective* get_refer_play(std::string vhost);
168 virtual SrsConfDirective* get_refer_publish(std::string vhost); 183 virtual SrsConfDirective* get_refer_publish(std::string vhost);
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2014 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#include <srs_app_http_api.hpp>
  25 +
  26 +SrsHttpApi::SrsHttpApi() {
  27 +}
  28 +
  29 +SrsHttpApi::~SrsHttpApi() {
  30 +}
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2014 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#ifndef SRS_APP_HTTP_API_HPP
  25 +#define SRS_APP_HTTP_API_HPP
  26 +
  27 +/*
  28 +#include <srs_app_http_api.hpp>
  29 +*/
  30 +
  31 +#include <srs_core.hpp>
  32 +
  33 +class SrsHttpApi
  34 +{
  35 +public:
  36 + SrsHttpApi();
  37 + virtual ~SrsHttpApi();
  38 +};
  39 +
  40 +#endif
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2014 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#include <srs_app_http_conn.hpp>
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2014 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#ifndef SRS_APP_HTTP_CONN_HPP
  25 +#define SRS_APP_HTTP_CONN_HPP
  26 +
  27 +/*
  28 +#include <srs_app_http_conn.hpp>
  29 +*/
  30 +
  31 +#include <srs_core.hpp>
  32 +
  33 +class SrsHttpConn
  34 +{
  35 +public:
  36 + SrsHttpConn();
  37 + virtual ~SrsHttpConn();
  38 +};
  39 +
  40 +#endif
@@ -21,7 +21,7 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN @@ -21,7 +21,7 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */ 22 */
23 23
24 -#include <srs_app_client.hpp> 24 +#include <srs_app_rtmp_conn.hpp>
25 25
26 #include <arpa/inet.h> 26 #include <arpa/inet.h>
27 #include <stdlib.h> 27 #include <stdlib.h>
@@ -846,4 +846,6 @@ void SrsClient::on_stop() @@ -846,4 +846,6 @@ void SrsClient::on_stop()
846 http_hooks->on_stop(url, connection_id, ip, req); 846 http_hooks->on_stop(url, connection_id, ip, req);
847 } 847 }
848 #endif 848 #endif
  849 +
  850 + return;
849 } 851 }
@@ -21,11 +21,11 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN @@ -21,11 +21,11 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */ 22 */
23 23
24 -#ifndef SRS_APP_CLIENT_HPP  
25 -#define SRS_APP_CLIENT_HPP 24 +#ifndef SRS_APP_RTMP_CONN_HPP
  25 +#define SRS_APP_RTMP_CONN_HPP
26 26
27 /* 27 /*
28 -#include <srs_app_client.hpp> 28 +#include <srs_app_rtmp_conn.hpp>
29 */ 29 */
30 30
31 #include <srs_core.hpp> 31 #include <srs_core.hpp>
@@ -35,7 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -35,7 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 35
36 #include <srs_kernel_log.hpp> 36 #include <srs_kernel_log.hpp>
37 #include <srs_kernel_error.hpp> 37 #include <srs_kernel_error.hpp>
38 -#include <srs_app_client.hpp> 38 +#include <srs_app_rtmp_conn.hpp>
39 #include <srs_app_config.hpp> 39 #include <srs_app_config.hpp>
40 #include <srs_kernel_utility.hpp> 40 #include <srs_kernel_utility.hpp>
41 41
@@ -118,7 +118,7 @@ int SrsListener::listen(int _port) @@ -118,7 +118,7 @@ int SrsListener::listen(int _port)
118 } 118 }
119 srs_verbose("create st listen thread success."); 119 srs_verbose("create st listen thread success.");
120 120
121 - srs_trace("server started, listen at port=%d, fd=%d", port, fd); 121 + srs_trace("server started, listen at port=%d, type=%d, fd=%d", port, type, fd);
122 122
123 return ret; 123 return ret;
124 } 124 }
@@ -301,7 +301,29 @@ int SrsServer::listen() @@ -301,7 +301,29 @@ int SrsServer::listen()
301 301
302 int port = ::atoi(conf->args.at(i).c_str()); 302 int port = ::atoi(conf->args.at(i).c_str());
303 if ((ret = listener->listen(port)) != ERROR_SUCCESS) { 303 if ((ret = listener->listen(port)) != ERROR_SUCCESS) {
304 - srs_error("listen at port %d failed. ret=%d", port, ret); 304 + srs_error("RTMP stream listen at port %d failed. ret=%d", port, ret);
  305 + return ret;
  306 + }
  307 + }
  308 +
  309 + if (_srs_config->get_http_api_enabled()) {
  310 + SrsListener* listener = new SrsListener(this, SrsListenerHttpApi);
  311 + listeners.push_back(listener);
  312 +
  313 + int port = _srs_config->get_http_api_listen();
  314 + if ((ret = listener->listen(port)) != ERROR_SUCCESS) {
  315 + srs_error("HTTP api listen at port %d failed. ret=%d", port, ret);
  316 + return ret;
  317 + }
  318 + }
  319 +
  320 + if (_srs_config->get_http_stream_enabled()) {
  321 + SrsListener* listener = new SrsListener(this, SrsListenerHttpStream);
  322 + listeners.push_back(listener);
  323 +
  324 + int port = _srs_config->get_http_stream_listen();
  325 + if ((ret = listener->listen(port)) != ERROR_SUCCESS) {
  326 + srs_error("HTTP stream listen at port %d failed. ret=%d", port, ret);
305 return ret; 327 return ret;
306 } 328 }
307 } 329 }
@@ -413,6 +435,8 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) @@ -413,6 +435,8 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
413 SrsConnection* conn = NULL; 435 SrsConnection* conn = NULL;
414 if (type == SrsListenerStream) { 436 if (type == SrsListenerStream) {
415 conn = new SrsClient(this, client_stfd); 437 conn = new SrsClient(this, client_stfd);
  438 + } else if (type == SrsListenerHttpApi) {
  439 + } else if (type == SrsListenerHttpStream) {
416 } else { 440 } else {
417 // TODO: FIXME: handler others 441 // TODO: FIXME: handler others
418 } 442 }
@@ -42,7 +42,8 @@ class SrsConnection; @@ -42,7 +42,8 @@ class SrsConnection;
42 enum SrsListenerType 42 enum SrsListenerType
43 { 43 {
44 SrsListenerStream = 0, 44 SrsListenerStream = 0,
45 - SrsListenerApi 45 + SrsListenerHttpApi,
  46 + SrsListenerHttpStream
46 }; 47 };
47 48
48 class SrsListener : public ISrsThreadHandler 49 class SrsListener : public ISrsThreadHandler
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR "0" 32 #define VERSION_MAJOR "0"
33 #define VERSION_MINOR "9" 33 #define VERSION_MINOR "9"
34 -#define VERSION_REVISION "36" 34 +#define VERSION_REVISION "37"
35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION 35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "srs" 37 #define RTMP_SIG_SRS_KEY "srs"
@@ -41,8 +41,6 @@ file @@ -41,8 +41,6 @@ file
41 app readonly separator, 41 app readonly separator,
42 ..\app\srs_app_bandwidth.hpp, 42 ..\app\srs_app_bandwidth.hpp,
43 ..\app\srs_app_bandwidth.cpp, 43 ..\app\srs_app_bandwidth.cpp,
44 - ..\app\srs_app_client.hpp,  
45 - ..\app\srs_app_client.cpp,  
46 ..\app\srs_app_codec.hpp, 44 ..\app\srs_app_codec.hpp,
47 ..\app\srs_app_codec.cpp, 45 ..\app\srs_app_codec.cpp,
48 ..\app\srs_app_conn.hpp, 46 ..\app\srs_app_conn.hpp,
@@ -57,12 +55,18 @@ file @@ -57,12 +55,18 @@ file
57 ..\app\srs_app_hls.cpp, 55 ..\app\srs_app_hls.cpp,
58 ..\app\srs_app_http.hpp, 56 ..\app\srs_app_http.hpp,
59 ..\app\srs_app_http.cpp, 57 ..\app\srs_app_http.cpp,
  58 + ..\app\srs_app_http_api.hpp,
  59 + ..\app\srs_app_http_api.cpp,
  60 + ..\app\srs_app_http_conn.hpp,
  61 + ..\app\srs_app_http_conn.cpp,
60 ..\app\srs_app_log.hpp, 62 ..\app\srs_app_log.hpp,
61 ..\app\srs_app_log.cpp, 63 ..\app\srs_app_log.cpp,
62 ..\app\srs_app_refer.hpp, 64 ..\app\srs_app_refer.hpp,
63 ..\app\srs_app_refer.cpp, 65 ..\app\srs_app_refer.cpp,
64 ..\app\srs_app_reload.hpp, 66 ..\app\srs_app_reload.hpp,
65 ..\app\srs_app_reload.cpp, 67 ..\app\srs_app_reload.cpp,
  68 + ..\app\srs_app_rtmp_conn.hpp,
  69 + ..\app\srs_app_rtmp_conn.cpp,
66 ..\app\srs_app_pithy_print.hpp, 70 ..\app\srs_app_pithy_print.hpp,
67 ..\app\srs_app_pithy_print.cpp, 71 ..\app\srs_app_pithy_print.cpp,
68 ..\app\srs_app_thread.hpp, 72 ..\app\srs_app_thread.hpp,