winlin

write pid to ./objs/srs.pid.

1 Simple-RTMP-Server 1 Simple-RTMP-Server
2 ================== 2 ==================
3 3
4 -SRS(SIMPLE RTMP Server) over state-threads created in 2013. 4 +SRS(SIMPLE RTMP Server) over state-threads created in 2013.10.
5 5
6 SRS is a simple, [RTMP](https://github.com/winlinvip/simple-rtmp-server/wiki/DeliveryRTMP)/[HLS](https://github.com/winlinvip/simple-rtmp-server/wiki/DeliveryHLS), 6 SRS is a simple, [RTMP](https://github.com/winlinvip/simple-rtmp-server/wiki/DeliveryRTMP)/[HLS](https://github.com/winlinvip/simple-rtmp-server/wiki/DeliveryHLS),
7 [high-performance](https://github.com/winlinvip/simple-rtmp-server/wiki/Performance), single/multiple(plan) processes, edge(plan)/origin live server, 7 [high-performance](https://github.com/winlinvip/simple-rtmp-server/wiki/Performance), single/multiple(plan) processes, edge(plan)/origin live server,
@@ -169,6 +169,7 @@ See also: [Performance Test Guide](https://github.com/winlinvip/simple-rtmp-serv @@ -169,6 +169,7 @@ See also: [Performance Test Guide](https://github.com/winlinvip/simple-rtmp-serv
169 * nginx v1.5.0: 139524 lines <br/> 169 * nginx v1.5.0: 139524 lines <br/>
170 170
171 ### History 171 ### History
  172 +* v1.0, 2014-03-21, write pid to ./objs/srs.pid.
172 * v1.0, 2014-03-20, refine hls code, support pure audio HLS. 173 * v1.0, 2014-03-20, refine hls code, support pure audio HLS.
173 * v1.0, 2014-03-19, add vn/an for FFMPEG to drop video/audio for radio stream. 174 * v1.0, 2014-03-19, add vn/an for FFMPEG to drop video/audio for radio stream.
174 * v1.0, 2014-03-19, refine handshake, client support coplex handshake, add utest. 175 * v1.0, 2014-03-19, refine handshake, client support coplex handshake, add utest.
@@ -429,7 +430,7 @@ Bandwidth Test Workflow: @@ -429,7 +430,7 @@ Bandwidth Test Workflow:
429 @See: class SrsBandwidth comments. 430 @See: class SrsBandwidth comments.
430 </pre> 431 </pre>
431 432
432 -Beijing, 2013<br/> 433 +Beijing, 2013.10<br/>
433 Winlin 434 Winlin
434 435
435 436
@@ -2,6 +2,12 @@ @@ -2,6 +2,12 @@
2 2
3 # the listen ports, split by space. 3 # the listen ports, split by space.
4 listen 1935; 4 listen 1935;
  5 +# the pid file
  6 +# to ensure only one process can use a pid file
  7 +# and provides the current running process id, for script,
  8 +# for example, init.d script to manage the server.
  9 +# default: ./objs/srs.pid
  10 +pid ./objs/srs.pid;
5 # the default chunk size is 128, max is 65536, 11 # the default chunk size is 128, max is 65536,
6 # some client does not support chunk size change, 12 # some client does not support chunk size change,
7 # however, most clients supports it and it can improve 13 # however, most clients supports it and it can improve
@@ -682,6 +682,7 @@ int SrsConfig::parse_file(const char* filename) @@ -682,6 +682,7 @@ int SrsConfig::parse_file(const char* filename)
682 // TODO: check forward. 682 // TODO: check forward.
683 // TODO: check ffmpeg. 683 // TODO: check ffmpeg.
684 // TODO: check http. 684 // TODO: check http.
  685 + // TODO: check pid.
685 686
686 return ret; 687 return ret;
687 } 688 }
@@ -1440,6 +1441,17 @@ SrsConfDirective* SrsConfig::get_listen() @@ -1440,6 +1441,17 @@ SrsConfDirective* SrsConfig::get_listen()
1440 return root->get("listen"); 1441 return root->get("listen");
1441 } 1442 }
1442 1443
  1444 +string SrsConfig::get_pid_file()
  1445 +{
  1446 + SrsConfDirective* conf = root->get("pid");
  1447 +
  1448 + if (!conf) {
  1449 + return SRS_CONF_DEFAULT_PID_FILE;
  1450 + }
  1451 +
  1452 + return conf->arg0();
  1453 +}
  1454 +
1443 int SrsConfig::get_chunk_size(const std::string &vhost) 1455 int SrsConfig::get_chunk_size(const std::string &vhost)
1444 { 1456 {
1445 SrsConfDirective* conf = get_vhost(vhost); 1457 SrsConfDirective* conf = get_vhost(vhost);
@@ -38,6 +38,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -38,6 +38,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 #define RTMP_VHOST_DEFAULT "__defaultVhost__" 38 #define RTMP_VHOST_DEFAULT "__defaultVhost__"
39 39
40 #define SRS_LOCALHOST "127.0.0.1" 40 #define SRS_LOCALHOST "127.0.0.1"
  41 +#define SRS_CONF_DEFAULT_PID_FILE "./objs/srs.pid"
41 42
42 #define SRS_CONF_DEFAULT_HLS_PATH "./objs/nginx/html" 43 #define SRS_CONF_DEFAULT_HLS_PATH "./objs/nginx/html"
43 #define SRS_CONF_DEFAULT_HLS_FRAGMENT 10 44 #define SRS_CONF_DEFAULT_HLS_FRAGMENT 10
@@ -116,62 +117,63 @@ private: @@ -116,62 +117,63 @@ private:
116 virtual int parse_argv(int& i, char** argv); 117 virtual int parse_argv(int& i, char** argv);
117 virtual void print_help(char** argv); 118 virtual void print_help(char** argv);
118 public: 119 public:
119 - virtual SrsConfDirective* get_vhost(std::string vhost);  
120 - virtual bool get_vhost_enabled(std::string vhost);  
121 - virtual bool get_vhost_enabled(SrsConfDirective* vhost);  
122 - virtual SrsConfDirective* get_vhost_on_connect(std::string vhost);  
123 - virtual SrsConfDirective* get_vhost_on_close(std::string vhost);  
124 - virtual SrsConfDirective* get_vhost_on_publish(std::string vhost);  
125 - virtual SrsConfDirective* get_vhost_on_unpublish(std::string vhost);  
126 - virtual SrsConfDirective* get_vhost_on_play(std::string vhost);  
127 - virtual SrsConfDirective* get_vhost_on_stop(std::string vhost);  
128 - virtual SrsConfDirective* get_transcode(std::string vhost, std::string scope);  
129 - virtual bool get_transcode_enabled(SrsConfDirective* transcode);  
130 - virtual std::string get_transcode_ffmpeg(SrsConfDirective* transcode); 120 + virtual SrsConfDirective* get_vhost(std::string vhost);
  121 + virtual bool get_vhost_enabled(std::string vhost);
  122 + virtual bool get_vhost_enabled(SrsConfDirective* vhost);
  123 + virtual SrsConfDirective* get_vhost_on_connect(std::string vhost);
  124 + virtual SrsConfDirective* get_vhost_on_close(std::string vhost);
  125 + virtual SrsConfDirective* get_vhost_on_publish(std::string vhost);
  126 + virtual SrsConfDirective* get_vhost_on_unpublish(std::string vhost);
  127 + virtual SrsConfDirective* get_vhost_on_play(std::string vhost);
  128 + virtual SrsConfDirective* get_vhost_on_stop(std::string vhost);
  129 + virtual SrsConfDirective* get_transcode(std::string vhost, std::string scope);
  130 + virtual bool get_transcode_enabled(SrsConfDirective* transcode);
  131 + virtual std::string get_transcode_ffmpeg(SrsConfDirective* transcode);
131 virtual void get_transcode_engines(SrsConfDirective* transcode, std::vector<SrsConfDirective*>& engines); 132 virtual void get_transcode_engines(SrsConfDirective* transcode, std::vector<SrsConfDirective*>& engines);
132 virtual bool get_engine_enabled(SrsConfDirective* engine); 133 virtual bool get_engine_enabled(SrsConfDirective* engine);
133 - virtual std::string get_engine_vcodec(SrsConfDirective* engine);  
134 - virtual int get_engine_vbitrate(SrsConfDirective* engine);  
135 - virtual double get_engine_vfps(SrsConfDirective* engine);  
136 - virtual int get_engine_vwidth(SrsConfDirective* engine);  
137 - virtual int get_engine_vheight(SrsConfDirective* engine);  
138 - virtual int get_engine_vthreads(SrsConfDirective* engine);  
139 - virtual std::string get_engine_vprofile(SrsConfDirective* engine);  
140 - virtual std::string get_engine_vpreset(SrsConfDirective* engine); 134 + virtual std::string get_engine_vcodec(SrsConfDirective* engine);
  135 + virtual int get_engine_vbitrate(SrsConfDirective* engine);
  136 + virtual double get_engine_vfps(SrsConfDirective* engine);
  137 + virtual int get_engine_vwidth(SrsConfDirective* engine);
  138 + virtual int get_engine_vheight(SrsConfDirective* engine);
  139 + virtual int get_engine_vthreads(SrsConfDirective* engine);
  140 + virtual std::string get_engine_vprofile(SrsConfDirective* engine);
  141 + virtual std::string get_engine_vpreset(SrsConfDirective* engine);
141 virtual void get_engine_vparams(SrsConfDirective* engine, std::vector<std::string>& vparams); 142 virtual void get_engine_vparams(SrsConfDirective* engine, std::vector<std::string>& vparams);
142 virtual void get_engine_vfilter(SrsConfDirective* engine, std::vector<std::string>& vfilter); 143 virtual void get_engine_vfilter(SrsConfDirective* engine, std::vector<std::string>& vfilter);
143 - virtual std::string get_engine_acodec(SrsConfDirective* engine);  
144 - virtual int get_engine_abitrate(SrsConfDirective* engine);  
145 - virtual int get_engine_asample_rate(SrsConfDirective* engine);  
146 - virtual int get_engine_achannels(SrsConfDirective* engine); 144 + virtual std::string get_engine_acodec(SrsConfDirective* engine);
  145 + virtual int get_engine_abitrate(SrsConfDirective* engine);
  146 + virtual int get_engine_asample_rate(SrsConfDirective* engine);
  147 + virtual int get_engine_achannels(SrsConfDirective* engine);
147 virtual void get_engine_aparams(SrsConfDirective* engine, std::vector<std::string>& aparams); 148 virtual void get_engine_aparams(SrsConfDirective* engine, std::vector<std::string>& aparams);
148 - virtual std::string get_engine_output(SrsConfDirective* engine);  
149 - virtual std::string get_log_dir();  
150 - virtual int get_max_connections(); 149 + virtual std::string get_engine_output(SrsConfDirective* engine);
  150 + virtual std::string get_log_dir();
  151 + virtual int get_max_connections();
151 virtual bool get_gop_cache(std::string vhost); 152 virtual bool get_gop_cache(std::string vhost);
152 - virtual double get_queue_length(std::string vhost);  
153 - virtual SrsConfDirective* get_forward(std::string vhost); 153 + virtual double get_queue_length(std::string vhost);
  154 + virtual SrsConfDirective* get_forward(std::string vhost);
154 private: 155 private:
155 - virtual SrsConfDirective* get_hls(std::string vhost); 156 + virtual SrsConfDirective* get_hls(std::string vhost);
156 public: 157 public:
157 virtual bool get_hls_enabled(std::string vhost); 158 virtual bool get_hls_enabled(std::string vhost);
158 - virtual std::string get_hls_path(std::string vhost);  
159 - virtual double get_hls_fragment(std::string vhost);  
160 - virtual double get_hls_window(std::string vhost);  
161 - virtual SrsConfDirective* get_refer(std::string vhost);  
162 - virtual SrsConfDirective* get_refer_play(std::string vhost);  
163 - virtual SrsConfDirective* get_refer_publish(std::string vhost);  
164 - virtual SrsConfDirective* get_listen();  
165 - virtual int get_chunk_size(const std::string& vhost);  
166 - virtual int get_pithy_print_publish();  
167 - virtual int get_pithy_print_forwarder();  
168 - virtual int get_pithy_print_encoder();  
169 - virtual int get_pithy_print_hls();  
170 - virtual int get_pithy_print_play(); 159 + virtual std::string get_hls_path(std::string vhost);
  160 + virtual double get_hls_fragment(std::string vhost);
  161 + virtual double get_hls_window(std::string vhost);
  162 + virtual SrsConfDirective* get_refer(std::string vhost);
  163 + virtual SrsConfDirective* get_refer_play(std::string vhost);
  164 + virtual SrsConfDirective* get_refer_publish(std::string vhost);
  165 + virtual SrsConfDirective* get_listen();
  166 + virtual std::string get_pid_file();
  167 + virtual int get_chunk_size(const std::string& vhost);
  168 + virtual int get_pithy_print_publish();
  169 + virtual int get_pithy_print_forwarder();
  170 + virtual int get_pithy_print_encoder();
  171 + virtual int get_pithy_print_hls();
  172 + virtual int get_pithy_print_play();
171 virtual bool get_bw_check_enabled(const std::string& vhost); 173 virtual bool get_bw_check_enabled(const std::string& vhost);
172 - virtual std::string get_bw_check_key(const std::string& vhost);  
173 - virtual int get_bw_check_interval_ms(const std::string& vhost);  
174 - virtual int get_bw_check_limit_kbps(const std::string& vhost); 174 + virtual std::string get_bw_check_key(const std::string& vhost);
  175 + virtual int get_bw_check_interval_ms(const std::string& vhost);
  176 + virtual int get_bw_check_limit_kbps(const std::string& vhost);
175 }; 177 };
176 178
177 /** 179 /**
@@ -27,6 +27,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -27,6 +27,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include <sys/socket.h> 27 #include <sys/socket.h>
28 #include <arpa/inet.h> 28 #include <arpa/inet.h>
29 #include <signal.h> 29 #include <signal.h>
  30 +#include <sys/types.h>
  31 +#include <sys/stat.h>
  32 +#include <fcntl.h>
30 33
31 #include <algorithm> 34 #include <algorithm>
32 35
@@ -198,6 +201,81 @@ int SrsServer::initialize() @@ -198,6 +201,81 @@ int SrsServer::initialize()
198 return ret; 201 return ret;
199 } 202 }
200 203
  204 +int SrsServer::acquire_pid_file()
  205 +{
  206 + int ret = ERROR_SUCCESS;
  207 +
  208 + std::string pid_file = _srs_config->get_pid_file();
  209 +
  210 + // -rw-r--r--
  211 + // 644
  212 + int mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
  213 +
  214 + int fd;
  215 + // open pid file
  216 + if ((fd = ::open(pid_file.c_str(), O_WRONLY | O_CREAT, mode)) < 0) {
  217 + ret = ERROR_SYSTEM_PID_ACQUIRE;
  218 + srs_error("open pid file %s error, ret=%#x", pid_file.c_str(), ret);
  219 + return ret;
  220 + }
  221 +
  222 + // require write lock
  223 + flock lock;
  224 +
  225 + lock.l_type = F_WRLCK; // F_RDLCK, F_WRLCK, F_UNLCK
  226 + lock.l_start = 0; // type offset, relative to l_whence
  227 + lock.l_whence = SEEK_SET; // SEEK_SET, SEEK_CUR, SEEK_END
  228 + lock.l_len = 0;
  229 +
  230 + if (fcntl(fd, F_SETLK, &lock) < 0) {
  231 + if(errno == EACCES || errno == EAGAIN) {
  232 + ret = ERROR_SYSTEM_PID_ALREADY_RUNNING;
  233 + srs_error("srs is already running! ret=%#x", ret);
  234 + return ret;
  235 + }
  236 +
  237 + ret = ERROR_SYSTEM_PID_LOCK;
  238 + srs_error("require lock for file %s error! ret=%#x", pid_file.c_str(), ret);
  239 + return ret;
  240 + }
  241 +
  242 + // truncate file
  243 + if (ftruncate(fd, 0) < 0) {
  244 + ret = ERROR_SYSTEM_PID_TRUNCATE_FILE;
  245 + srs_error("truncate pid file %s error! ret=%#x", pid_file.c_str(), ret);
  246 + return ret;
  247 + }
  248 +
  249 + int pid = (int)getpid();
  250 +
  251 + // write the pid
  252 + char buf[512];
  253 + snprintf(buf, sizeof(buf), "%d", pid);
  254 + if (write(fd, buf, strlen(buf)) != (int)strlen(buf)) {
  255 + ret = ERROR_SYSTEM_PID_WRITE_FILE;
  256 + srs_error("write our pid error! pid=%d file=%s ret=%#x", pid, pid_file.c_str(), ret);
  257 + return ret;
  258 + }
  259 +
  260 + // auto close when fork child process.
  261 + int val;
  262 + if ((val = fcntl(fd, F_GETFD, 0)) < 0) {
  263 + ret = ERROR_SYSTEM_PID_GET_FILE_INFO;
  264 + srs_error("fnctl F_GETFD error! file=%s ret=%#x", pid_file.c_str(), ret);
  265 + return ret;
  266 + }
  267 + val |= FD_CLOEXEC;
  268 + if (fcntl(fd, F_SETFD, val) < 0) {
  269 + ret = ERROR_SYSTEM_PID_SET_FILE_INFO;
  270 + srs_error("fcntl F_SETFD error! file=%s ret=%#x", pid_file.c_str(), ret);
  271 + return ret;
  272 + }
  273 +
  274 + srs_trace("write pid=%d to %s success!", pid, pid_file.c_str());
  275 +
  276 + return ret;
  277 +}
  278 +
201 int SrsServer::listen() 279 int SrsServer::listen()
202 { 280 {
203 int ret = ERROR_SUCCESS; 281 int ret = ERROR_SUCCESS;
@@ -79,6 +79,7 @@ public: @@ -79,6 +79,7 @@ public:
79 virtual ~SrsServer(); 79 virtual ~SrsServer();
80 public: 80 public:
81 virtual int initialize(); 81 virtual int initialize();
  82 + virtual int acquire_pid_file();
82 virtual int listen(); 83 virtual int listen();
83 virtual int cycle(); 84 virtual int cycle();
84 virtual void remove(SrsConnection* conn); 85 virtual void remove(SrsConnection* conn);
@@ -30,133 +30,140 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -30,133 +30,140 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 30
31 #include <srs_core.hpp> 31 #include <srs_core.hpp>
32 32
33 -#define ERROR_SUCCESS 0  
34 -  
35 -#define ERROR_ST_SET_EPOLL 100  
36 -#define ERROR_ST_INITIALIZE 101  
37 -#define ERROR_ST_OPEN_SOCKET 102  
38 -#define ERROR_ST_CREATE_LISTEN_THREAD 103  
39 -#define ERROR_ST_CREATE_CYCLE_THREAD 104  
40 -#define ERROR_ST_CONNECT 105  
41 -  
42 -#define ERROR_SOCKET_CREATE 200  
43 -#define ERROR_SOCKET_SETREUSE 201  
44 -#define ERROR_SOCKET_BIND 202  
45 -#define ERROR_SOCKET_LISTEN 203  
46 -#define ERROR_SOCKET_CLOSED 204  
47 -#define ERROR_SOCKET_GET_PEER_NAME 205  
48 -#define ERROR_SOCKET_GET_PEER_IP 206  
49 -#define ERROR_SOCKET_READ 207  
50 -#define ERROR_SOCKET_READ_FULLY 208  
51 -#define ERROR_SOCKET_WRITE 209  
52 -#define ERROR_SOCKET_WAIT 210  
53 -#define ERROR_SOCKET_TIMEOUT 211  
54 -#define ERROR_SOCKET_GET_LOCAL_IP 212  
55 -  
56 -#define ERROR_RTMP_PLAIN_REQUIRED 300  
57 -#define ERROR_RTMP_CHUNK_START 301  
58 -#define ERROR_RTMP_MSG_INVLIAD_SIZE 302  
59 -#define ERROR_RTMP_AMF0_DECODE 303  
60 -#define ERROR_RTMP_AMF0_INVALID 304  
61 -#define ERROR_RTMP_REQ_CONNECT 305  
62 -#define ERROR_RTMP_REQ_TCURL 306  
63 -#define ERROR_RTMP_MESSAGE_DECODE 307  
64 -#define ERROR_RTMP_MESSAGE_ENCODE 308  
65 -#define ERROR_RTMP_AMF0_ENCODE 309  
66 -#define ERROR_RTMP_CHUNK_SIZE 310  
67 -#define ERROR_RTMP_TRY_SIMPLE_HS 311  
68 -#define ERROR_RTMP_CH_SCHEMA 312  
69 -#define ERROR_RTMP_PACKET_SIZE 313  
70 -#define ERROR_RTMP_VHOST_NOT_FOUND 314  
71 -#define ERROR_RTMP_ACCESS_DENIED 315  
72 -#define ERROR_RTMP_HANDSHAKE 316  
73 -#define ERROR_RTMP_NO_REQUEST 317 33 +#define ERROR_SUCCESS 0
  34 +
  35 +#define ERROR_ST_SET_EPOLL 100
  36 +#define ERROR_ST_INITIALIZE 101
  37 +#define ERROR_ST_OPEN_SOCKET 102
  38 +#define ERROR_ST_CREATE_LISTEN_THREAD 103
  39 +#define ERROR_ST_CREATE_CYCLE_THREAD 104
  40 +#define ERROR_ST_CONNECT 105
  41 +
  42 +#define ERROR_SOCKET_CREATE 200
  43 +#define ERROR_SOCKET_SETREUSE 201
  44 +#define ERROR_SOCKET_BIND 202
  45 +#define ERROR_SOCKET_LISTEN 203
  46 +#define ERROR_SOCKET_CLOSED 204
  47 +#define ERROR_SOCKET_GET_PEER_NAME 205
  48 +#define ERROR_SOCKET_GET_PEER_IP 206
  49 +#define ERROR_SOCKET_READ 207
  50 +#define ERROR_SOCKET_READ_FULLY 208
  51 +#define ERROR_SOCKET_WRITE 209
  52 +#define ERROR_SOCKET_WAIT 210
  53 +#define ERROR_SOCKET_TIMEOUT 211
  54 +#define ERROR_SOCKET_GET_LOCAL_IP 212
  55 +
  56 +#define ERROR_RTMP_PLAIN_REQUIRED 300
  57 +#define ERROR_RTMP_CHUNK_START 301
  58 +#define ERROR_RTMP_MSG_INVLIAD_SIZE 302
  59 +#define ERROR_RTMP_AMF0_DECODE 303
  60 +#define ERROR_RTMP_AMF0_INVALID 304
  61 +#define ERROR_RTMP_REQ_CONNECT 305
  62 +#define ERROR_RTMP_REQ_TCURL 306
  63 +#define ERROR_RTMP_MESSAGE_DECODE 307
  64 +#define ERROR_RTMP_MESSAGE_ENCODE 308
  65 +#define ERROR_RTMP_AMF0_ENCODE 309
  66 +#define ERROR_RTMP_CHUNK_SIZE 310
  67 +#define ERROR_RTMP_TRY_SIMPLE_HS 311
  68 +#define ERROR_RTMP_CH_SCHEMA 312
  69 +#define ERROR_RTMP_PACKET_SIZE 313
  70 +#define ERROR_RTMP_VHOST_NOT_FOUND 314
  71 +#define ERROR_RTMP_ACCESS_DENIED 315
  72 +#define ERROR_RTMP_HANDSHAKE 316
  73 +#define ERROR_RTMP_NO_REQUEST 317
74 // if user use complex handshake, but without ssl, 74 // if user use complex handshake, but without ssl,
75 // 1. srs is ok, ignore and turn to simple handshake. 75 // 1. srs is ok, ignore and turn to simple handshake.
76 // 2. srs-librtmp return error, to terminate the program. 76 // 2. srs-librtmp return error, to terminate the program.
77 -#define ERROR_RTMP_HS_SSL_REQUIRE 318  
78 -  
79 -#define ERROR_SYSTEM_STREAM_INIT 400  
80 -#define ERROR_SYSTEM_PACKET_INVALID 401  
81 -#define ERROR_SYSTEM_CLIENT_INVALID 402  
82 -#define ERROR_SYSTEM_ASSERT_FAILED 403  
83 -#define ERROR_SYSTEM_SIZE_NEGATIVE 404  
84 -#define ERROR_SYSTEM_CONFIG_INVALID 405  
85 -#define ERROR_SYSTEM_CONFIG_DIRECTIVE 406  
86 -#define ERROR_SYSTEM_CONFIG_BLOCK_START 407  
87 -#define ERROR_SYSTEM_CONFIG_BLOCK_END 408  
88 -#define ERROR_SYSTEM_CONFIG_EOF 409  
89 -#define ERROR_SYSTEM_STREAM_BUSY 410  
90 -#define ERROR_SYSTEM_IP_INVALID 411  
91 -#define ERROR_SYSTEM_FORWARD_LOOP 412  
92 -#define ERROR_SYSTEM_WAITPID 413  
93 -#define ERROR_SYSTEM_BANDWIDTH_KEY 414  
94 -#define ERROR_SYSTEM_BANDWIDTH_DENIED 415 77 +#define ERROR_RTMP_HS_SSL_REQUIRE 318
  78 +
  79 +#define ERROR_SYSTEM_STREAM_INIT 400
  80 +#define ERROR_SYSTEM_PACKET_INVALID 401
  81 +#define ERROR_SYSTEM_CLIENT_INVALID 402
  82 +#define ERROR_SYSTEM_ASSERT_FAILED 403
  83 +#define ERROR_SYSTEM_SIZE_NEGATIVE 404
  84 +#define ERROR_SYSTEM_CONFIG_INVALID 405
  85 +#define ERROR_SYSTEM_CONFIG_DIRECTIVE 406
  86 +#define ERROR_SYSTEM_CONFIG_BLOCK_START 407
  87 +#define ERROR_SYSTEM_CONFIG_BLOCK_END 408
  88 +#define ERROR_SYSTEM_CONFIG_EOF 409
  89 +#define ERROR_SYSTEM_STREAM_BUSY 410
  90 +#define ERROR_SYSTEM_IP_INVALID 411
  91 +#define ERROR_SYSTEM_FORWARD_LOOP 412
  92 +#define ERROR_SYSTEM_WAITPID 413
  93 +#define ERROR_SYSTEM_BANDWIDTH_KEY 414
  94 +#define ERROR_SYSTEM_BANDWIDTH_DENIED 415
  95 +#define ERROR_SYSTEM_PID_ACQUIRE 416
  96 +#define ERROR_SYSTEM_PID_ALREADY_RUNNING 417
  97 +#define ERROR_SYSTEM_PID_LOCK 418
  98 +#define ERROR_SYSTEM_PID_TRUNCATE_FILE 419
  99 +#define ERROR_SYSTEM_PID_WRITE_FILE 420
  100 +#define ERROR_SYSTEM_PID_GET_FILE_INFO 421
  101 +#define ERROR_SYSTEM_PID_SET_FILE_INFO 422
95 102
96 // see librtmp. 103 // see librtmp.
97 // failed when open ssl create the dh 104 // failed when open ssl create the dh
98 -#define ERROR_OpenSslCreateDH 500 105 +#define ERROR_OpenSslCreateDH 500
99 // failed when open ssl create the Private key. 106 // failed when open ssl create the Private key.
100 -#define ERROR_OpenSslCreateP 501 107 +#define ERROR_OpenSslCreateP 501
101 // when open ssl create G. 108 // when open ssl create G.
102 -#define ERROR_OpenSslCreateG 502 109 +#define ERROR_OpenSslCreateG 502
103 // when open ssl parse P1024 110 // when open ssl parse P1024
104 -#define ERROR_OpenSslParseP1024 503 111 +#define ERROR_OpenSslParseP1024 503
105 // when open ssl set G 112 // when open ssl set G
106 -#define ERROR_OpenSslSetG 504 113 +#define ERROR_OpenSslSetG 504
107 // when open ssl generate DHKeys 114 // when open ssl generate DHKeys
108 -#define ERROR_OpenSslGenerateDHKeys 505 115 +#define ERROR_OpenSslGenerateDHKeys 505
109 // when open ssl share key already computed. 116 // when open ssl share key already computed.
110 -#define ERROR_OpenSslShareKeyComputed 506 117 +#define ERROR_OpenSslShareKeyComputed 506
111 // when open ssl get shared key size. 118 // when open ssl get shared key size.
112 -#define ERROR_OpenSslGetSharedKeySize 507 119 +#define ERROR_OpenSslGetSharedKeySize 507
113 // when open ssl get peer public key. 120 // when open ssl get peer public key.
114 -#define ERROR_OpenSslGetPeerPublicKey 508 121 +#define ERROR_OpenSslGetPeerPublicKey 508
115 // when open ssl compute shared key. 122 // when open ssl compute shared key.
116 -#define ERROR_OpenSslComputeSharedKey 509 123 +#define ERROR_OpenSslComputeSharedKey 509
117 // when open ssl is invalid DH state. 124 // when open ssl is invalid DH state.
118 -#define ERROR_OpenSslInvalidDHState 510 125 +#define ERROR_OpenSslInvalidDHState 510
119 // when open ssl copy key 126 // when open ssl copy key
120 -#define ERROR_OpenSslCopyKey 511 127 +#define ERROR_OpenSslCopyKey 511
121 // when open ssl sha256 digest key invalid size. 128 // when open ssl sha256 digest key invalid size.
122 -#define ERROR_OpenSslSha256DigestSize 512  
123 -  
124 -#define ERROR_HLS_METADATA 600  
125 -#define ERROR_HLS_DECODE_ERROR 601  
126 -#define ERROR_HLS_CREATE_DIR 602  
127 -#define ERROR_HLS_OPEN_FAILED 603  
128 -#define ERROR_HLS_WRITE_FAILED 604  
129 -#define ERROR_HLS_AAC_FRAME_LENGTH 605  
130 -#define ERROR_HLS_AVC_SAMPLE_SIZE 606  
131 -  
132 -#define ERROR_ENCODER_VCODEC 700  
133 -#define ERROR_ENCODER_OUTPUT 701  
134 -#define ERROR_ENCODER_ACHANNELS 702  
135 -#define ERROR_ENCODER_ASAMPLE_RATE 703  
136 -#define ERROR_ENCODER_ABITRATE 704  
137 -#define ERROR_ENCODER_ACODEC 705  
138 -#define ERROR_ENCODER_VPRESET 706  
139 -#define ERROR_ENCODER_VPROFILE 707  
140 -#define ERROR_ENCODER_VTHREADS 708  
141 -#define ERROR_ENCODER_VHEIGHT 709  
142 -#define ERROR_ENCODER_VWIDTH 710  
143 -#define ERROR_ENCODER_VFPS 711  
144 -#define ERROR_ENCODER_VBITRATE 712  
145 -#define ERROR_ENCODER_FORK 713  
146 -#define ERROR_ENCODER_LOOP 714  
147 -#define ERROR_ENCODER_OPEN 715  
148 -#define ERROR_ENCODER_DUP2 716  
149 -  
150 -#define ERROR_HTTP_PARSE_URI 800  
151 -#define ERROR_HTTP_DATA_INVLIAD 801  
152 -#define ERROR_HTTP_PARSE_HEADER 802 129 +#define ERROR_OpenSslSha256DigestSize 512
  130 +
  131 +#define ERROR_HLS_METADATA 600
  132 +#define ERROR_HLS_DECODE_ERROR 601
  133 +#define ERROR_HLS_CREATE_DIR 602
  134 +#define ERROR_HLS_OPEN_FAILED 603
  135 +#define ERROR_HLS_WRITE_FAILED 604
  136 +#define ERROR_HLS_AAC_FRAME_LENGTH 605
  137 +#define ERROR_HLS_AVC_SAMPLE_SIZE 606
  138 +
  139 +#define ERROR_ENCODER_VCODEC 700
  140 +#define ERROR_ENCODER_OUTPUT 701
  141 +#define ERROR_ENCODER_ACHANNELS 702
  142 +#define ERROR_ENCODER_ASAMPLE_RATE 703
  143 +#define ERROR_ENCODER_ABITRATE 704
  144 +#define ERROR_ENCODER_ACODEC 705
  145 +#define ERROR_ENCODER_VPRESET 706
  146 +#define ERROR_ENCODER_VPROFILE 707
  147 +#define ERROR_ENCODER_VTHREADS 708
  148 +#define ERROR_ENCODER_VHEIGHT 709
  149 +#define ERROR_ENCODER_VWIDTH 710
  150 +#define ERROR_ENCODER_VFPS 711
  151 +#define ERROR_ENCODER_VBITRATE 712
  152 +#define ERROR_ENCODER_FORK 713
  153 +#define ERROR_ENCODER_LOOP 714
  154 +#define ERROR_ENCODER_OPEN 715
  155 +#define ERROR_ENCODER_DUP2 716
  156 +
  157 +#define ERROR_HTTP_PARSE_URI 800
  158 +#define ERROR_HTTP_DATA_INVLIAD 801
  159 +#define ERROR_HTTP_PARSE_HEADER 802
153 160
154 // system control message, 161 // system control message,
155 // not an error, but special control logic. 162 // not an error, but special control logic.
156 // sys ctl: rtmp close stream, support replay. 163 // sys ctl: rtmp close stream, support replay.
157 -#define ERROR_CONTROL_RTMP_CLOSE 900 164 +#define ERROR_CONTROL_RTMP_CLOSE 900
158 // FMLE stop publish and republish. 165 // FMLE stop publish and republish.
159 -#define ERROR_CONTROL_REPUBLISH 901 166 +#define ERROR_CONTROL_REPUBLISH 901
160 167
161 /** 168 /**
162 * whether the error code is an system control error. 169 * whether the error code is an system control error.
@@ -91,6 +91,10 @@ int main(int argc, char** argv) @@ -91,6 +91,10 @@ int main(int argc, char** argv)
91 91
92 // TODO: create log dir in _srs_config->get_log_dir() 92 // TODO: create log dir in _srs_config->get_log_dir()
93 93
  94 + if ((ret = _srs_server->acquire_pid_file()) != ERROR_SUCCESS) {
  95 + return ret;
  96 + }
  97 +
94 if ((ret = _srs_server->listen()) != ERROR_SUCCESS) { 98 if ((ret = _srs_server->listen()) != ERROR_SUCCESS) {
95 return ret; 99 return ret;
96 } 100 }