diff --git a/README.md b/README.md
index e63376a4c..c3c685702 100755
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
Simple-RTMP-Server
==================
-SRS(SIMPLE RTMP Server) over state-threads created in 2013.
+SRS(SIMPLE RTMP Server) over state-threads created in 2013.10.
SRS is a simple, [RTMP](https://github.com/winlinvip/simple-rtmp-server/wiki/DeliveryRTMP)/[HLS](https://github.com/winlinvip/simple-rtmp-server/wiki/DeliveryHLS),
[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
* nginx v1.5.0: 139524 lines
### History
+* v1.0, 2014-03-21, write pid to ./objs/srs.pid.
* v1.0, 2014-03-20, refine hls code, support pure audio HLS.
* v1.0, 2014-03-19, add vn/an for FFMPEG to drop video/audio for radio stream.
* v1.0, 2014-03-19, refine handshake, client support coplex handshake, add utest.
@@ -429,7 +430,7 @@ Bandwidth Test Workflow:
@See: class SrsBandwidth comments.
-Beijing, 2013
+Beijing, 2013.10
Winlin
diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf
index c35c21b26..2aed617a2 100644
--- a/trunk/conf/full.conf
+++ b/trunk/conf/full.conf
@@ -2,6 +2,12 @@
# the listen ports, split by space.
listen 1935;
+# the pid file
+# to ensure only one process can use a pid file
+# and provides the current running process id, for script,
+# for example, init.d script to manage the server.
+# default: ./objs/srs.pid
+pid ./objs/srs.pid;
# the default chunk size is 128, max is 65536,
# some client does not support chunk size change,
# however, most clients supports it and it can improve
diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp
index dfb0f173c..5d677b147 100644
--- a/trunk/src/app/srs_app_config.cpp
+++ b/trunk/src/app/srs_app_config.cpp
@@ -682,6 +682,7 @@ int SrsConfig::parse_file(const char* filename)
// TODO: check forward.
// TODO: check ffmpeg.
// TODO: check http.
+ // TODO: check pid.
return ret;
}
@@ -1440,6 +1441,17 @@ SrsConfDirective* SrsConfig::get_listen()
return root->get("listen");
}
+string SrsConfig::get_pid_file()
+{
+ SrsConfDirective* conf = root->get("pid");
+
+ if (!conf) {
+ return SRS_CONF_DEFAULT_PID_FILE;
+ }
+
+ return conf->arg0();
+}
+
int SrsConfig::get_chunk_size(const std::string &vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp
index 8129e4eba..ae5699d1b 100644
--- a/trunk/src/app/srs_app_config.hpp
+++ b/trunk/src/app/srs_app_config.hpp
@@ -38,6 +38,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define RTMP_VHOST_DEFAULT "__defaultVhost__"
#define SRS_LOCALHOST "127.0.0.1"
+#define SRS_CONF_DEFAULT_PID_FILE "./objs/srs.pid"
#define SRS_CONF_DEFAULT_HLS_PATH "./objs/nginx/html"
#define SRS_CONF_DEFAULT_HLS_FRAGMENT 10
@@ -116,62 +117,63 @@ private:
virtual int parse_argv(int& i, char** argv);
virtual void print_help(char** argv);
public:
- virtual SrsConfDirective* get_vhost(std::string vhost);
- virtual bool get_vhost_enabled(std::string vhost);
- virtual bool get_vhost_enabled(SrsConfDirective* vhost);
- virtual SrsConfDirective* get_vhost_on_connect(std::string vhost);
- virtual SrsConfDirective* get_vhost_on_close(std::string vhost);
- virtual SrsConfDirective* get_vhost_on_publish(std::string vhost);
- virtual SrsConfDirective* get_vhost_on_unpublish(std::string vhost);
- virtual SrsConfDirective* get_vhost_on_play(std::string vhost);
- virtual SrsConfDirective* get_vhost_on_stop(std::string vhost);
- virtual SrsConfDirective* get_transcode(std::string vhost, std::string scope);
- virtual bool get_transcode_enabled(SrsConfDirective* transcode);
- virtual std::string get_transcode_ffmpeg(SrsConfDirective* transcode);
+ virtual SrsConfDirective* get_vhost(std::string vhost);
+ virtual bool get_vhost_enabled(std::string vhost);
+ virtual bool get_vhost_enabled(SrsConfDirective* vhost);
+ virtual SrsConfDirective* get_vhost_on_connect(std::string vhost);
+ virtual SrsConfDirective* get_vhost_on_close(std::string vhost);
+ virtual SrsConfDirective* get_vhost_on_publish(std::string vhost);
+ virtual SrsConfDirective* get_vhost_on_unpublish(std::string vhost);
+ virtual SrsConfDirective* get_vhost_on_play(std::string vhost);
+ virtual SrsConfDirective* get_vhost_on_stop(std::string vhost);
+ virtual SrsConfDirective* get_transcode(std::string vhost, std::string scope);
+ virtual bool get_transcode_enabled(SrsConfDirective* transcode);
+ virtual std::string get_transcode_ffmpeg(SrsConfDirective* transcode);
virtual void get_transcode_engines(SrsConfDirective* transcode, std::vector& engines);
virtual bool get_engine_enabled(SrsConfDirective* engine);
- virtual std::string get_engine_vcodec(SrsConfDirective* engine);
- virtual int get_engine_vbitrate(SrsConfDirective* engine);
- virtual double get_engine_vfps(SrsConfDirective* engine);
- virtual int get_engine_vwidth(SrsConfDirective* engine);
- virtual int get_engine_vheight(SrsConfDirective* engine);
- virtual int get_engine_vthreads(SrsConfDirective* engine);
- virtual std::string get_engine_vprofile(SrsConfDirective* engine);
- virtual std::string get_engine_vpreset(SrsConfDirective* engine);
+ virtual std::string get_engine_vcodec(SrsConfDirective* engine);
+ virtual int get_engine_vbitrate(SrsConfDirective* engine);
+ virtual double get_engine_vfps(SrsConfDirective* engine);
+ virtual int get_engine_vwidth(SrsConfDirective* engine);
+ virtual int get_engine_vheight(SrsConfDirective* engine);
+ virtual int get_engine_vthreads(SrsConfDirective* engine);
+ virtual std::string get_engine_vprofile(SrsConfDirective* engine);
+ virtual std::string get_engine_vpreset(SrsConfDirective* engine);
virtual void get_engine_vparams(SrsConfDirective* engine, std::vector& vparams);
virtual void get_engine_vfilter(SrsConfDirective* engine, std::vector& vfilter);
- virtual std::string get_engine_acodec(SrsConfDirective* engine);
- virtual int get_engine_abitrate(SrsConfDirective* engine);
- virtual int get_engine_asample_rate(SrsConfDirective* engine);
- virtual int get_engine_achannels(SrsConfDirective* engine);
+ virtual std::string get_engine_acodec(SrsConfDirective* engine);
+ virtual int get_engine_abitrate(SrsConfDirective* engine);
+ virtual int get_engine_asample_rate(SrsConfDirective* engine);
+ virtual int get_engine_achannels(SrsConfDirective* engine);
virtual void get_engine_aparams(SrsConfDirective* engine, std::vector& aparams);
- virtual std::string get_engine_output(SrsConfDirective* engine);
- virtual std::string get_log_dir();
- virtual int get_max_connections();
+ virtual std::string get_engine_output(SrsConfDirective* engine);
+ virtual std::string get_log_dir();
+ virtual int get_max_connections();
virtual bool get_gop_cache(std::string vhost);
- virtual double get_queue_length(std::string vhost);
- virtual SrsConfDirective* get_forward(std::string vhost);
+ virtual double get_queue_length(std::string vhost);
+ virtual SrsConfDirective* get_forward(std::string vhost);
private:
- virtual SrsConfDirective* get_hls(std::string vhost);
+ virtual SrsConfDirective* get_hls(std::string vhost);
public:
virtual bool get_hls_enabled(std::string vhost);
- virtual std::string get_hls_path(std::string vhost);
- virtual double get_hls_fragment(std::string vhost);
- virtual double get_hls_window(std::string vhost);
- virtual SrsConfDirective* get_refer(std::string vhost);
- virtual SrsConfDirective* get_refer_play(std::string vhost);
- virtual SrsConfDirective* get_refer_publish(std::string vhost);
- virtual SrsConfDirective* get_listen();
- virtual int get_chunk_size(const std::string& vhost);
- virtual int get_pithy_print_publish();
- virtual int get_pithy_print_forwarder();
- virtual int get_pithy_print_encoder();
- virtual int get_pithy_print_hls();
- virtual int get_pithy_print_play();
+ virtual std::string get_hls_path(std::string vhost);
+ virtual double get_hls_fragment(std::string vhost);
+ virtual double get_hls_window(std::string vhost);
+ virtual SrsConfDirective* get_refer(std::string vhost);
+ virtual SrsConfDirective* get_refer_play(std::string vhost);
+ virtual SrsConfDirective* get_refer_publish(std::string vhost);
+ virtual SrsConfDirective* get_listen();
+ virtual std::string get_pid_file();
+ virtual int get_chunk_size(const std::string& vhost);
+ virtual int get_pithy_print_publish();
+ virtual int get_pithy_print_forwarder();
+ virtual int get_pithy_print_encoder();
+ virtual int get_pithy_print_hls();
+ virtual int get_pithy_print_play();
virtual bool get_bw_check_enabled(const std::string& vhost);
- virtual std::string get_bw_check_key(const std::string& vhost);
- virtual int get_bw_check_interval_ms(const std::string& vhost);
- virtual int get_bw_check_limit_kbps(const std::string& vhost);
+ virtual std::string get_bw_check_key(const std::string& vhost);
+ virtual int get_bw_check_interval_ms(const std::string& vhost);
+ virtual int get_bw_check_limit_kbps(const std::string& vhost);
};
/**
diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp
index bc24ac4ca..f5ddf3b82 100644
--- a/trunk/src/app/srs_app_server.cpp
+++ b/trunk/src/app/srs_app_server.cpp
@@ -27,6 +27,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include
#include
#include
+#include
+#include
+#include
#include
@@ -198,6 +201,81 @@ int SrsServer::initialize()
return ret;
}
+int SrsServer::acquire_pid_file()
+{
+ int ret = ERROR_SUCCESS;
+
+ std::string pid_file = _srs_config->get_pid_file();
+
+ // -rw-r--r--
+ // 644
+ int mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
+
+ int fd;
+ // open pid file
+ if ((fd = ::open(pid_file.c_str(), O_WRONLY | O_CREAT, mode)) < 0) {
+ ret = ERROR_SYSTEM_PID_ACQUIRE;
+ srs_error("open pid file %s error, ret=%#x", pid_file.c_str(), ret);
+ return ret;
+ }
+
+ // require write lock
+ flock lock;
+
+ lock.l_type = F_WRLCK; // F_RDLCK, F_WRLCK, F_UNLCK
+ lock.l_start = 0; // type offset, relative to l_whence
+ lock.l_whence = SEEK_SET; // SEEK_SET, SEEK_CUR, SEEK_END
+ lock.l_len = 0;
+
+ if (fcntl(fd, F_SETLK, &lock) < 0) {
+ if(errno == EACCES || errno == EAGAIN) {
+ ret = ERROR_SYSTEM_PID_ALREADY_RUNNING;
+ srs_error("srs is already running! ret=%#x", ret);
+ return ret;
+ }
+
+ ret = ERROR_SYSTEM_PID_LOCK;
+ srs_error("require lock for file %s error! ret=%#x", pid_file.c_str(), ret);
+ return ret;
+ }
+
+ // truncate file
+ if (ftruncate(fd, 0) < 0) {
+ ret = ERROR_SYSTEM_PID_TRUNCATE_FILE;
+ srs_error("truncate pid file %s error! ret=%#x", pid_file.c_str(), ret);
+ return ret;
+ }
+
+ int pid = (int)getpid();
+
+ // write the pid
+ char buf[512];
+ snprintf(buf, sizeof(buf), "%d", pid);
+ if (write(fd, buf, strlen(buf)) != (int)strlen(buf)) {
+ ret = ERROR_SYSTEM_PID_WRITE_FILE;
+ srs_error("write our pid error! pid=%d file=%s ret=%#x", pid, pid_file.c_str(), ret);
+ return ret;
+ }
+
+ // auto close when fork child process.
+ int val;
+ if ((val = fcntl(fd, F_GETFD, 0)) < 0) {
+ ret = ERROR_SYSTEM_PID_GET_FILE_INFO;
+ srs_error("fnctl F_GETFD error! file=%s ret=%#x", pid_file.c_str(), ret);
+ return ret;
+ }
+ val |= FD_CLOEXEC;
+ if (fcntl(fd, F_SETFD, val) < 0) {
+ ret = ERROR_SYSTEM_PID_SET_FILE_INFO;
+ srs_error("fcntl F_SETFD error! file=%s ret=%#x", pid_file.c_str(), ret);
+ return ret;
+ }
+
+ srs_trace("write pid=%d to %s success!", pid, pid_file.c_str());
+
+ return ret;
+}
+
int SrsServer::listen()
{
int ret = ERROR_SUCCESS;
diff --git a/trunk/src/app/srs_app_server.hpp b/trunk/src/app/srs_app_server.hpp
index 1e7f0a59d..11d8b960f 100644
--- a/trunk/src/app/srs_app_server.hpp
+++ b/trunk/src/app/srs_app_server.hpp
@@ -79,6 +79,7 @@ public:
virtual ~SrsServer();
public:
virtual int initialize();
+ virtual int acquire_pid_file();
virtual int listen();
virtual int cycle();
virtual void remove(SrsConnection* conn);
diff --git a/trunk/src/kernel/srs_kernel_error.hpp b/trunk/src/kernel/srs_kernel_error.hpp
index d190ed764..84c218f91 100644
--- a/trunk/src/kernel/srs_kernel_error.hpp
+++ b/trunk/src/kernel/srs_kernel_error.hpp
@@ -30,133 +30,140 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include
-#define ERROR_SUCCESS 0
-
-#define ERROR_ST_SET_EPOLL 100
-#define ERROR_ST_INITIALIZE 101
-#define ERROR_ST_OPEN_SOCKET 102
-#define ERROR_ST_CREATE_LISTEN_THREAD 103
-#define ERROR_ST_CREATE_CYCLE_THREAD 104
-#define ERROR_ST_CONNECT 105
-
-#define ERROR_SOCKET_CREATE 200
-#define ERROR_SOCKET_SETREUSE 201
-#define ERROR_SOCKET_BIND 202
-#define ERROR_SOCKET_LISTEN 203
-#define ERROR_SOCKET_CLOSED 204
-#define ERROR_SOCKET_GET_PEER_NAME 205
-#define ERROR_SOCKET_GET_PEER_IP 206
-#define ERROR_SOCKET_READ 207
-#define ERROR_SOCKET_READ_FULLY 208
-#define ERROR_SOCKET_WRITE 209
-#define ERROR_SOCKET_WAIT 210
-#define ERROR_SOCKET_TIMEOUT 211
-#define ERROR_SOCKET_GET_LOCAL_IP 212
-
-#define ERROR_RTMP_PLAIN_REQUIRED 300
-#define ERROR_RTMP_CHUNK_START 301
-#define ERROR_RTMP_MSG_INVLIAD_SIZE 302
-#define ERROR_RTMP_AMF0_DECODE 303
-#define ERROR_RTMP_AMF0_INVALID 304
-#define ERROR_RTMP_REQ_CONNECT 305
-#define ERROR_RTMP_REQ_TCURL 306
-#define ERROR_RTMP_MESSAGE_DECODE 307
-#define ERROR_RTMP_MESSAGE_ENCODE 308
-#define ERROR_RTMP_AMF0_ENCODE 309
-#define ERROR_RTMP_CHUNK_SIZE 310
-#define ERROR_RTMP_TRY_SIMPLE_HS 311
-#define ERROR_RTMP_CH_SCHEMA 312
-#define ERROR_RTMP_PACKET_SIZE 313
-#define ERROR_RTMP_VHOST_NOT_FOUND 314
-#define ERROR_RTMP_ACCESS_DENIED 315
-#define ERROR_RTMP_HANDSHAKE 316
-#define ERROR_RTMP_NO_REQUEST 317
+#define ERROR_SUCCESS 0
+
+#define ERROR_ST_SET_EPOLL 100
+#define ERROR_ST_INITIALIZE 101
+#define ERROR_ST_OPEN_SOCKET 102
+#define ERROR_ST_CREATE_LISTEN_THREAD 103
+#define ERROR_ST_CREATE_CYCLE_THREAD 104
+#define ERROR_ST_CONNECT 105
+
+#define ERROR_SOCKET_CREATE 200
+#define ERROR_SOCKET_SETREUSE 201
+#define ERROR_SOCKET_BIND 202
+#define ERROR_SOCKET_LISTEN 203
+#define ERROR_SOCKET_CLOSED 204
+#define ERROR_SOCKET_GET_PEER_NAME 205
+#define ERROR_SOCKET_GET_PEER_IP 206
+#define ERROR_SOCKET_READ 207
+#define ERROR_SOCKET_READ_FULLY 208
+#define ERROR_SOCKET_WRITE 209
+#define ERROR_SOCKET_WAIT 210
+#define ERROR_SOCKET_TIMEOUT 211
+#define ERROR_SOCKET_GET_LOCAL_IP 212
+
+#define ERROR_RTMP_PLAIN_REQUIRED 300
+#define ERROR_RTMP_CHUNK_START 301
+#define ERROR_RTMP_MSG_INVLIAD_SIZE 302
+#define ERROR_RTMP_AMF0_DECODE 303
+#define ERROR_RTMP_AMF0_INVALID 304
+#define ERROR_RTMP_REQ_CONNECT 305
+#define ERROR_RTMP_REQ_TCURL 306
+#define ERROR_RTMP_MESSAGE_DECODE 307
+#define ERROR_RTMP_MESSAGE_ENCODE 308
+#define ERROR_RTMP_AMF0_ENCODE 309
+#define ERROR_RTMP_CHUNK_SIZE 310
+#define ERROR_RTMP_TRY_SIMPLE_HS 311
+#define ERROR_RTMP_CH_SCHEMA 312
+#define ERROR_RTMP_PACKET_SIZE 313
+#define ERROR_RTMP_VHOST_NOT_FOUND 314
+#define ERROR_RTMP_ACCESS_DENIED 315
+#define ERROR_RTMP_HANDSHAKE 316
+#define ERROR_RTMP_NO_REQUEST 317
// if user use complex handshake, but without ssl,
// 1. srs is ok, ignore and turn to simple handshake.
// 2. srs-librtmp return error, to terminate the program.
-#define ERROR_RTMP_HS_SSL_REQUIRE 318
-
-#define ERROR_SYSTEM_STREAM_INIT 400
-#define ERROR_SYSTEM_PACKET_INVALID 401
-#define ERROR_SYSTEM_CLIENT_INVALID 402
-#define ERROR_SYSTEM_ASSERT_FAILED 403
-#define ERROR_SYSTEM_SIZE_NEGATIVE 404
-#define ERROR_SYSTEM_CONFIG_INVALID 405
-#define ERROR_SYSTEM_CONFIG_DIRECTIVE 406
-#define ERROR_SYSTEM_CONFIG_BLOCK_START 407
-#define ERROR_SYSTEM_CONFIG_BLOCK_END 408
-#define ERROR_SYSTEM_CONFIG_EOF 409
-#define ERROR_SYSTEM_STREAM_BUSY 410
-#define ERROR_SYSTEM_IP_INVALID 411
-#define ERROR_SYSTEM_FORWARD_LOOP 412
-#define ERROR_SYSTEM_WAITPID 413
-#define ERROR_SYSTEM_BANDWIDTH_KEY 414
-#define ERROR_SYSTEM_BANDWIDTH_DENIED 415
+#define ERROR_RTMP_HS_SSL_REQUIRE 318
+
+#define ERROR_SYSTEM_STREAM_INIT 400
+#define ERROR_SYSTEM_PACKET_INVALID 401
+#define ERROR_SYSTEM_CLIENT_INVALID 402
+#define ERROR_SYSTEM_ASSERT_FAILED 403
+#define ERROR_SYSTEM_SIZE_NEGATIVE 404
+#define ERROR_SYSTEM_CONFIG_INVALID 405
+#define ERROR_SYSTEM_CONFIG_DIRECTIVE 406
+#define ERROR_SYSTEM_CONFIG_BLOCK_START 407
+#define ERROR_SYSTEM_CONFIG_BLOCK_END 408
+#define ERROR_SYSTEM_CONFIG_EOF 409
+#define ERROR_SYSTEM_STREAM_BUSY 410
+#define ERROR_SYSTEM_IP_INVALID 411
+#define ERROR_SYSTEM_FORWARD_LOOP 412
+#define ERROR_SYSTEM_WAITPID 413
+#define ERROR_SYSTEM_BANDWIDTH_KEY 414
+#define ERROR_SYSTEM_BANDWIDTH_DENIED 415
+#define ERROR_SYSTEM_PID_ACQUIRE 416
+#define ERROR_SYSTEM_PID_ALREADY_RUNNING 417
+#define ERROR_SYSTEM_PID_LOCK 418
+#define ERROR_SYSTEM_PID_TRUNCATE_FILE 419
+#define ERROR_SYSTEM_PID_WRITE_FILE 420
+#define ERROR_SYSTEM_PID_GET_FILE_INFO 421
+#define ERROR_SYSTEM_PID_SET_FILE_INFO 422
// see librtmp.
// failed when open ssl create the dh
-#define ERROR_OpenSslCreateDH 500
+#define ERROR_OpenSslCreateDH 500
// failed when open ssl create the Private key.
-#define ERROR_OpenSslCreateP 501
+#define ERROR_OpenSslCreateP 501
// when open ssl create G.
-#define ERROR_OpenSslCreateG 502
+#define ERROR_OpenSslCreateG 502
// when open ssl parse P1024
-#define ERROR_OpenSslParseP1024 503
+#define ERROR_OpenSslParseP1024 503
// when open ssl set G
-#define ERROR_OpenSslSetG 504
+#define ERROR_OpenSslSetG 504
// when open ssl generate DHKeys
-#define ERROR_OpenSslGenerateDHKeys 505
+#define ERROR_OpenSslGenerateDHKeys 505
// when open ssl share key already computed.
-#define ERROR_OpenSslShareKeyComputed 506
+#define ERROR_OpenSslShareKeyComputed 506
// when open ssl get shared key size.
-#define ERROR_OpenSslGetSharedKeySize 507
+#define ERROR_OpenSslGetSharedKeySize 507
// when open ssl get peer public key.
-#define ERROR_OpenSslGetPeerPublicKey 508
+#define ERROR_OpenSslGetPeerPublicKey 508
// when open ssl compute shared key.
-#define ERROR_OpenSslComputeSharedKey 509
+#define ERROR_OpenSslComputeSharedKey 509
// when open ssl is invalid DH state.
-#define ERROR_OpenSslInvalidDHState 510
+#define ERROR_OpenSslInvalidDHState 510
// when open ssl copy key
-#define ERROR_OpenSslCopyKey 511
+#define ERROR_OpenSslCopyKey 511
// when open ssl sha256 digest key invalid size.
-#define ERROR_OpenSslSha256DigestSize 512
-
-#define ERROR_HLS_METADATA 600
-#define ERROR_HLS_DECODE_ERROR 601
-#define ERROR_HLS_CREATE_DIR 602
-#define ERROR_HLS_OPEN_FAILED 603
-#define ERROR_HLS_WRITE_FAILED 604
-#define ERROR_HLS_AAC_FRAME_LENGTH 605
-#define ERROR_HLS_AVC_SAMPLE_SIZE 606
-
-#define ERROR_ENCODER_VCODEC 700
-#define ERROR_ENCODER_OUTPUT 701
-#define ERROR_ENCODER_ACHANNELS 702
-#define ERROR_ENCODER_ASAMPLE_RATE 703
-#define ERROR_ENCODER_ABITRATE 704
-#define ERROR_ENCODER_ACODEC 705
-#define ERROR_ENCODER_VPRESET 706
-#define ERROR_ENCODER_VPROFILE 707
-#define ERROR_ENCODER_VTHREADS 708
-#define ERROR_ENCODER_VHEIGHT 709
-#define ERROR_ENCODER_VWIDTH 710
-#define ERROR_ENCODER_VFPS 711
-#define ERROR_ENCODER_VBITRATE 712
-#define ERROR_ENCODER_FORK 713
-#define ERROR_ENCODER_LOOP 714
-#define ERROR_ENCODER_OPEN 715
-#define ERROR_ENCODER_DUP2 716
-
-#define ERROR_HTTP_PARSE_URI 800
-#define ERROR_HTTP_DATA_INVLIAD 801
-#define ERROR_HTTP_PARSE_HEADER 802
+#define ERROR_OpenSslSha256DigestSize 512
+
+#define ERROR_HLS_METADATA 600
+#define ERROR_HLS_DECODE_ERROR 601
+#define ERROR_HLS_CREATE_DIR 602
+#define ERROR_HLS_OPEN_FAILED 603
+#define ERROR_HLS_WRITE_FAILED 604
+#define ERROR_HLS_AAC_FRAME_LENGTH 605
+#define ERROR_HLS_AVC_SAMPLE_SIZE 606
+
+#define ERROR_ENCODER_VCODEC 700
+#define ERROR_ENCODER_OUTPUT 701
+#define ERROR_ENCODER_ACHANNELS 702
+#define ERROR_ENCODER_ASAMPLE_RATE 703
+#define ERROR_ENCODER_ABITRATE 704
+#define ERROR_ENCODER_ACODEC 705
+#define ERROR_ENCODER_VPRESET 706
+#define ERROR_ENCODER_VPROFILE 707
+#define ERROR_ENCODER_VTHREADS 708
+#define ERROR_ENCODER_VHEIGHT 709
+#define ERROR_ENCODER_VWIDTH 710
+#define ERROR_ENCODER_VFPS 711
+#define ERROR_ENCODER_VBITRATE 712
+#define ERROR_ENCODER_FORK 713
+#define ERROR_ENCODER_LOOP 714
+#define ERROR_ENCODER_OPEN 715
+#define ERROR_ENCODER_DUP2 716
+
+#define ERROR_HTTP_PARSE_URI 800
+#define ERROR_HTTP_DATA_INVLIAD 801
+#define ERROR_HTTP_PARSE_HEADER 802
// system control message,
// not an error, but special control logic.
// sys ctl: rtmp close stream, support replay.
-#define ERROR_CONTROL_RTMP_CLOSE 900
+#define ERROR_CONTROL_RTMP_CLOSE 900
// FMLE stop publish and republish.
-#define ERROR_CONTROL_REPUBLISH 901
+#define ERROR_CONTROL_REPUBLISH 901
/**
* whether the error code is an system control error.
diff --git a/trunk/src/main/srs_main_server.cpp b/trunk/src/main/srs_main_server.cpp
index 3e179d591..c86dc21a0 100644
--- a/trunk/src/main/srs_main_server.cpp
+++ b/trunk/src/main/srs_main_server.cpp
@@ -91,6 +91,10 @@ int main(int argc, char** argv)
// TODO: create log dir in _srs_config->get_log_dir()
+ if ((ret = _srs_server->acquire_pid_file()) != ERROR_SUCCESS) {
+ return ret;
+ }
+
if ((ret = _srs_server->listen()) != ERROR_SUCCESS) {
return ret;
}