From 8d86eb6516ee82da39f57173f80a4e24a218c5c6 Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 28 Jul 2015 17:56:50 +0800 Subject: [PATCH 1/6] refine code naming or comments. --- trunk/src/core/srs_core_autofree.hpp | 4 +- trunk/src/kernel/srs_kernel_file.cpp | 36 +++++++------- trunk/src/kernel/srs_kernel_file.hpp | 33 ++++++++----- trunk/src/kernel/srs_kernel_flv.cpp | 74 ++++++++++++++-------------- trunk/src/kernel/srs_kernel_flv.hpp | 18 +++---- 5 files changed, 88 insertions(+), 77 deletions(-) diff --git a/trunk/src/core/srs_core_autofree.hpp b/trunk/src/core/srs_core_autofree.hpp index 72ff6f72e..9687cce7d 100644 --- a/trunk/src/core/srs_core_autofree.hpp +++ b/trunk/src/core/srs_core_autofree.hpp @@ -51,8 +51,8 @@ public: /** * auto delete the ptr. */ - impl__SrsAutoFree(T** _ptr) { - ptr = _ptr; + impl__SrsAutoFree(T** p) { + ptr = p; } virtual ~impl__SrsAutoFree() { diff --git a/trunk/src/kernel/srs_kernel_file.cpp b/trunk/src/kernel/srs_kernel_file.cpp index 75410b568..88b2dfa48 100644 --- a/trunk/src/kernel/srs_kernel_file.cpp +++ b/trunk/src/kernel/srs_kernel_file.cpp @@ -46,50 +46,50 @@ SrsFileWriter::~SrsFileWriter() close(); } -int SrsFileWriter::open(string file) +int SrsFileWriter::open(string p) { int ret = ERROR_SUCCESS; if (fd > 0) { ret = ERROR_SYSTEM_FILE_ALREADY_OPENED; - srs_error("file %s already opened. ret=%d", _file.c_str(), ret); + srs_error("file %s already opened. ret=%d", path.c_str(), ret); return ret; } int flags = O_CREAT|O_WRONLY|O_TRUNC; mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH; - if ((fd = ::open(file.c_str(), flags, mode)) < 0) { + if ((fd = ::open(p.c_str(), flags, mode)) < 0) { ret = ERROR_SYSTEM_FILE_OPENE; - srs_error("open file %s failed. ret=%d", file.c_str(), ret); + srs_error("open file %s failed. ret=%d", p.c_str(), ret); return ret; } - _file = file; + path = p; return ret; } -int SrsFileWriter::open_append(string file) +int SrsFileWriter::open_append(string p) { int ret = ERROR_SUCCESS; if (fd > 0) { ret = ERROR_SYSTEM_FILE_ALREADY_OPENED; - srs_error("file %s already opened. ret=%d", _file.c_str(), ret); + srs_error("file %s already opened. ret=%d", path.c_str(), ret); return ret; } int flags = O_APPEND|O_WRONLY; mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH; - if ((fd = ::open(file.c_str(), flags, mode)) < 0) { + if ((fd = ::open(p.c_str(), flags, mode)) < 0) { ret = ERROR_SYSTEM_FILE_OPENE; - srs_error("open file %s failed. ret=%d", file.c_str(), ret); + srs_error("open file %s failed. ret=%d", p.c_str(), ret); return ret; } - _file = file; + path = p; return ret; } @@ -104,7 +104,7 @@ void SrsFileWriter::close() if (::close(fd) < 0) { ret = ERROR_SYSTEM_FILE_CLOSE; - srs_error("close file %s failed. ret=%d", _file.c_str(), ret); + srs_error("close file %s failed. ret=%d", path.c_str(), ret); return; } fd = -1; @@ -135,7 +135,7 @@ int SrsFileWriter::write(void* buf, size_t count, ssize_t* pnwrite) // TODO: FIXME: use st_write. if ((nwrite = ::write(fd, buf, count)) < 0) { ret = ERROR_SYSTEM_FILE_WRITE; - srs_error("write to file %s failed. ret=%d", _file.c_str(), ret); + srs_error("write to file %s failed. ret=%d", path.c_str(), ret); return ret; } @@ -177,23 +177,23 @@ SrsFileReader::~SrsFileReader() close(); } -int SrsFileReader::open(string file) +int SrsFileReader::open(string p) { int ret = ERROR_SUCCESS; if (fd > 0) { ret = ERROR_SYSTEM_FILE_ALREADY_OPENED; - srs_error("file %s already opened. ret=%d", _file.c_str(), ret); + srs_error("file %s already opened. ret=%d", path.c_str(), ret); return ret; } - if ((fd = ::open(file.c_str(), O_RDONLY)) < 0) { + if ((fd = ::open(p.c_str(), O_RDONLY)) < 0) { ret = ERROR_SYSTEM_FILE_OPENE; - srs_error("open file %s failed. ret=%d", file.c_str(), ret); + srs_error("open file %s failed. ret=%d", p.c_str(), ret); return ret; } - _file = file; + path = p; return ret; } @@ -208,7 +208,7 @@ void SrsFileReader::close() if (::close(fd) < 0) { ret = ERROR_SYSTEM_FILE_CLOSE; - srs_error("close file %s failed. ret=%d", _file.c_str(), ret); + srs_error("close file %s failed. ret=%d", path.c_str(), ret); return; } fd = -1; diff --git a/trunk/src/kernel/srs_kernel_file.hpp b/trunk/src/kernel/srs_kernel_file.hpp index 167e8559d..6074c7a24 100644 --- a/trunk/src/kernel/srs_kernel_file.hpp +++ b/trunk/src/kernel/srs_kernel_file.hpp @@ -42,20 +42,26 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. class SrsFileWriter { private: - std::string _file; + std::string path; int fd; public: SrsFileWriter(); virtual ~SrsFileWriter(); public: /** - * open file writer, can open then close then open... - */ - virtual int open(std::string file); + * open file writer, in truncate mode. + * @param p a string indicates the path of file to open. + */ + virtual int open(std::string p); /** - * open file writer in append mode. - */ - virtual int open_append(std::string file); + * open file writer, in append mode. + * @param p a string indicates the path of file to open. + */ + virtual int open_append(std::string p); + /** + * close current writer. + * @remark user can reopen again. + */ virtual void close(); public: virtual bool is_open(); @@ -80,16 +86,21 @@ public: class SrsFileReader { private: - std::string _file; + std::string path; int fd; public: SrsFileReader(); virtual ~SrsFileReader(); public: /** - * open file reader, can open then close then open... - */ - virtual int open(std::string file); + * open file reader. + * @param p a string indicates the path of file to open. + */ + virtual int open(std::string p); + /** + * close current reader. + * @remark user can reopen again. + */ virtual void close(); public: // TODO: FIXME: extract interface. diff --git a/trunk/src/kernel/srs_kernel_flv.cpp b/trunk/src/kernel/srs_kernel_flv.cpp index ad446a938..1f132b788 100644 --- a/trunk/src/kernel/srs_kernel_flv.cpp +++ b/trunk/src/kernel/srs_kernel_flv.cpp @@ -332,7 +332,7 @@ SrsSharedPtrMessage* SrsSharedPtrMessage::copy() SrsFlvEncoder::SrsFlvEncoder() { - _fs = NULL; + reader = NULL; tag_stream = new SrsStream(); #ifdef SRS_PERF_FAST_FLV_ENCODER @@ -356,19 +356,19 @@ SrsFlvEncoder::~SrsFlvEncoder() #endif } -int SrsFlvEncoder::initialize(SrsFileWriter* fs) +int SrsFlvEncoder::initialize(SrsFileWriter* fr) { int ret = ERROR_SUCCESS; - srs_assert(fs); + srs_assert(fr); - if (!fs->is_open()) { + if (!fr->is_open()) { ret = ERROR_KERNEL_FLV_STREAM_CLOSED; srs_warn("stream is not open for encoder. ret=%d", ret); return ret; } - _fs = fs; + reader = fr; return ret; } @@ -402,14 +402,14 @@ int SrsFlvEncoder::write_header(char flv_header[9]) int ret = ERROR_SUCCESS; // write data. - if ((ret = _fs->write(flv_header, 9, NULL)) != ERROR_SUCCESS) { + if ((ret = reader->write(flv_header, 9, NULL)) != ERROR_SUCCESS) { srs_error("write flv header failed. ret=%d", ret); return ret; } // previous tag size. char pts[] = { (char)0x00, (char)0x00, (char)0x00, (char)0x00 }; - if ((ret = _fs->write(pts, 4, NULL)) != ERROR_SUCCESS) { + if ((ret = reader->write(pts, 4, NULL)) != ERROR_SUCCESS) { return ret; } @@ -552,7 +552,7 @@ int SrsFlvEncoder::write_tags(SrsSharedPtrMessage** msgs, int count) iovs += 3; } - if ((ret = _fs->writev(iovss, nb_iovss, NULL)) != ERROR_SUCCESS) { + if ((ret = reader->writev(iovss, nb_iovss, NULL)) != ERROR_SUCCESS) { if (!srs_is_client_gracefully_close(ret)) { srs_error("write flv tags failed. ret=%d", ret); } @@ -683,7 +683,7 @@ int SrsFlvEncoder::write_tag(char* header, int header_size, char* tag, int tag_s iovs[2].iov_base = pre_size; iovs[2].iov_len = SRS_FLV_PREVIOUS_TAG_SIZE; - if ((ret = _fs->writev(iovs, 3, NULL)) != ERROR_SUCCESS) { + if ((ret = reader->writev(iovs, 3, NULL)) != ERROR_SUCCESS) { if (!srs_is_client_gracefully_close(ret)) { srs_error("write flv tag failed. ret=%d", ret); } @@ -695,7 +695,7 @@ int SrsFlvEncoder::write_tag(char* header, int header_size, char* tag, int tag_s SrsFlvDecoder::SrsFlvDecoder() { - _fs = NULL; + reader = NULL; tag_stream = new SrsStream(); } @@ -704,19 +704,19 @@ SrsFlvDecoder::~SrsFlvDecoder() srs_freep(tag_stream); } -int SrsFlvDecoder::initialize(SrsFileReader* fs) +int SrsFlvDecoder::initialize(SrsFileReader* fr) { int ret = ERROR_SUCCESS; - srs_assert(fs); + srs_assert(fr); - if (!fs->is_open()) { + if (!fr->is_open()) { ret = ERROR_KERNEL_FLV_STREAM_CLOSED; srs_warn("stream is not open for decoder. ret=%d", ret); return ret; } - _fs = fs; + reader = fr; return ret; } @@ -727,7 +727,7 @@ int SrsFlvDecoder::read_header(char header[9]) srs_assert(header); - if ((ret = _fs->read(header, 9, NULL)) != ERROR_SUCCESS) { + if ((ret = reader->read(header, 9, NULL)) != ERROR_SUCCESS) { return ret; } @@ -752,7 +752,7 @@ int SrsFlvDecoder::read_tag_header(char* ptype, int32_t* pdata_size, u_int32_t* char th[11]; // tag header // read tag header - if ((ret = _fs->read(th, 11, NULL)) != ERROR_SUCCESS) { + if ((ret = reader->read(th, 11, NULL)) != ERROR_SUCCESS) { if (ret != ERROR_SYSTEM_FILE_EOF) { srs_error("read flv tag header failed. ret=%d", ret); } @@ -789,7 +789,7 @@ int SrsFlvDecoder::read_tag_data(char* data, int32_t size) srs_assert(data); - if ((ret = _fs->read(data, size, NULL)) != ERROR_SUCCESS) { + if ((ret = reader->read(data, size, NULL)) != ERROR_SUCCESS) { if (ret != ERROR_SYSTEM_FILE_EOF) { srs_error("read flv tag header failed. ret=%d", ret); } @@ -807,7 +807,7 @@ int SrsFlvDecoder::read_previous_tag_size(char previous_tag_size[4]) srs_assert(previous_tag_size); // ignore 4bytes tag size. - if ((ret = _fs->read(previous_tag_size, 4, NULL)) != ERROR_SUCCESS) { + if ((ret = reader->read(previous_tag_size, 4, NULL)) != ERROR_SUCCESS) { if (ret != ERROR_SYSTEM_FILE_EOF) { srs_error("read flv previous tag size failed. ret=%d", ret); } @@ -819,7 +819,7 @@ int SrsFlvDecoder::read_previous_tag_size(char previous_tag_size[4]) SrsFlvVodStreamDecoder::SrsFlvVodStreamDecoder() { - _fs = NULL; + reader = NULL; tag_stream = new SrsStream(); } @@ -828,19 +828,19 @@ SrsFlvVodStreamDecoder::~SrsFlvVodStreamDecoder() srs_freep(tag_stream); } -int SrsFlvVodStreamDecoder::initialize(SrsFileReader* fs) +int SrsFlvVodStreamDecoder::initialize(SrsFileReader* fr) { int ret = ERROR_SUCCESS; - srs_assert(fs); + srs_assert(fr); - if (!fs->is_open()) { + if (!fr->is_open()) { ret = ERROR_KERNEL_FLV_STREAM_CLOSED; srs_warn("stream is not open for decoder. ret=%d", ret); return ret; } - _fs = fs; + reader = fr; return ret; } @@ -857,7 +857,7 @@ int SrsFlvVodStreamDecoder::read_header_ext(char header[13]) // 9bytes header and 4bytes first previous-tag-size int size = 13; - if ((ret = _fs->read(header, size, NULL)) != ERROR_SUCCESS) { + if ((ret = reader->read(header, size, NULL)) != ERROR_SUCCESS) { return ret; } @@ -891,7 +891,7 @@ int SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart, int* p int64_t av_sequence_offset_start = -1; int64_t av_sequence_offset_end = -1; for (;;) { - if ((ret = _fs->read(tag_header, SRS_FLV_TAG_HEADER_SIZE, NULL)) != ERROR_SUCCESS) { + if ((ret = reader->read(tag_header, SRS_FLV_TAG_HEADER_SIZE, NULL)) != ERROR_SUCCESS) { return ret; } @@ -907,7 +907,7 @@ int SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart, int* p bool is_not_av = !is_video && !is_audio; if (is_not_av) { // skip body and tag size. - _fs->skip(data_size + SRS_FLV_PREVIOUS_TAG_SIZE); + reader->skip(data_size + SRS_FLV_PREVIOUS_TAG_SIZE); continue; } @@ -926,10 +926,10 @@ int SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart, int* p got_video = true; if (av_sequence_offset_start < 0) { - av_sequence_offset_start = _fs->tellg() - SRS_FLV_TAG_HEADER_SIZE; + av_sequence_offset_start = reader->tellg() - SRS_FLV_TAG_HEADER_SIZE; } - av_sequence_offset_end = _fs->tellg() + data_size + SRS_FLV_PREVIOUS_TAG_SIZE; - _fs->skip(data_size + SRS_FLV_PREVIOUS_TAG_SIZE); + av_sequence_offset_end = reader->tellg() + data_size + SRS_FLV_PREVIOUS_TAG_SIZE; + reader->skip(data_size + SRS_FLV_PREVIOUS_TAG_SIZE); } // audio @@ -938,16 +938,16 @@ int SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart, int* p got_audio = true; if (av_sequence_offset_start < 0) { - av_sequence_offset_start = _fs->tellg() - SRS_FLV_TAG_HEADER_SIZE; + av_sequence_offset_start = reader->tellg() - SRS_FLV_TAG_HEADER_SIZE; } - av_sequence_offset_end = _fs->tellg() + data_size + SRS_FLV_PREVIOUS_TAG_SIZE; - _fs->skip(data_size + SRS_FLV_PREVIOUS_TAG_SIZE); + av_sequence_offset_end = reader->tellg() + data_size + SRS_FLV_PREVIOUS_TAG_SIZE; + reader->skip(data_size + SRS_FLV_PREVIOUS_TAG_SIZE); } } // seek to the sequence header start offset. if (av_sequence_offset_start > 0) { - _fs->lseek(av_sequence_offset_start); + reader->lseek(av_sequence_offset_start); *pstart = av_sequence_offset_start; *psize = (int)(av_sequence_offset_end - av_sequence_offset_start); } @@ -959,19 +959,19 @@ int SrsFlvVodStreamDecoder::lseek(int64_t offset) { int ret = ERROR_SUCCESS; - if (offset >= _fs->filesize()) { + if (offset >= reader->filesize()) { ret = ERROR_SYSTEM_FILE_EOF; srs_warn("flv fast decoder seek overflow file, " "size=%"PRId64", offset=%"PRId64", ret=%d", - _fs->filesize(), offset, ret); + reader->filesize(), offset, ret); return ret; } - if (_fs->lseek(offset) < 0) { + if (reader->lseek(offset) < 0) { ret = ERROR_SYSTEM_FILE_SEEK; srs_warn("flv fast decoder seek error, " "size=%"PRId64", offset=%"PRId64", ret=%d", - _fs->filesize(), offset, ret); + reader->filesize(), offset, ret); return ret; } diff --git a/trunk/src/kernel/srs_kernel_flv.hpp b/trunk/src/kernel/srs_kernel_flv.hpp index ed45a7bf0..a38c500f8 100644 --- a/trunk/src/kernel/srs_kernel_flv.hpp +++ b/trunk/src/kernel/srs_kernel_flv.hpp @@ -434,7 +434,7 @@ public: class SrsFlvEncoder { private: - SrsFileWriter* _fs; + SrsFileWriter* reader; private: SrsStream* tag_stream; char tag_header[SRS_FLV_TAG_HEADER_SIZE]; @@ -445,9 +445,9 @@ public: /** * initialize the underlayer file stream. * @remark user can initialize multiple times to encode multiple flv files. - * @remark, user must free the fs, flv encoder never close/free it. + * @remark, user must free the @param fr, flv encoder never close/free it. */ - virtual int initialize(SrsFileWriter* fs); + virtual int initialize(SrsFileWriter* fr); public: /** * write flv header. @@ -512,7 +512,7 @@ private: class SrsFlvDecoder { private: - SrsFileReader* _fs; + SrsFileReader* reader; private: SrsStream* tag_stream; public: @@ -522,9 +522,9 @@ public: /** * initialize the underlayer file stream * @remark user can initialize multiple times to decode multiple flv files. - * @remark, user must free the fs, flv decoder never close/free it. + * @remark user must free the @param fr, flv decoder never close/free it. */ - virtual int initialize(SrsFileReader* fs); + virtual int initialize(SrsFileReader* fr); public: /** * read the flv header, donot including the 4bytes previous tag size. @@ -556,7 +556,7 @@ public: class SrsFlvVodStreamDecoder { private: - SrsFileReader* _fs; + SrsFileReader* reader; private: SrsStream* tag_stream; public: @@ -566,9 +566,9 @@ public: /** * initialize the underlayer file stream * @remark user can initialize multiple times to decode multiple flv files. - * @remark, user must free the fs, flv decoder never close/free it. + * @remark user must free the @param fr, flv decoder never close/free it. */ - virtual int initialize(SrsFileReader* fs); + virtual int initialize(SrsFileReader* fr); public: /** * read the flv header and its size. From bfe0f97edd059359c62865279fbd446cfda61a1a Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 28 Jul 2015 18:08:11 +0800 Subject: [PATCH 2/6] refine params nameing and SrsStream. --- trunk/src/kernel/srs_kernel_file.cpp | 2 +- trunk/src/kernel/srs_kernel_mp3.cpp | 14 ++++----- trunk/src/kernel/srs_kernel_mp3.hpp | 7 ++--- trunk/src/kernel/srs_kernel_stream.cpp | 42 +++++++++++++------------- trunk/src/kernel/srs_kernel_stream.hpp | 14 +++++---- trunk/src/kernel/srs_kernel_ts.cpp | 16 +++++----- trunk/src/kernel/srs_kernel_ts.hpp | 16 +++++----- 7 files changed, 57 insertions(+), 54 deletions(-) diff --git a/trunk/src/kernel/srs_kernel_file.cpp b/trunk/src/kernel/srs_kernel_file.cpp index 88b2dfa48..c06ccc445 100644 --- a/trunk/src/kernel/srs_kernel_file.cpp +++ b/trunk/src/kernel/srs_kernel_file.cpp @@ -252,7 +252,7 @@ int SrsFileReader::read(void* buf, size_t count, ssize_t* pnread) // TODO: FIXME: use st_read. if ((nread = ::read(fd, buf, count)) < 0) { ret = ERROR_SYSTEM_FILE_READ; - srs_error("read from file %s failed. ret=%d", _file.c_str(), ret); + srs_error("read from file %s failed. ret=%d", path.c_str(), ret); return ret; } diff --git a/trunk/src/kernel/srs_kernel_mp3.cpp b/trunk/src/kernel/srs_kernel_mp3.cpp index 339ca1a47..34998be03 100644 --- a/trunk/src/kernel/srs_kernel_mp3.cpp +++ b/trunk/src/kernel/srs_kernel_mp3.cpp @@ -40,7 +40,7 @@ using namespace std; SrsMp3Encoder::SrsMp3Encoder() { - _fs = NULL; + writer = NULL; tag_stream = new SrsStream(); } @@ -49,19 +49,19 @@ SrsMp3Encoder::~SrsMp3Encoder() srs_freep(tag_stream); } -int SrsMp3Encoder::initialize(SrsFileWriter* fs) +int SrsMp3Encoder::initialize(SrsFileWriter* fw) { int ret = ERROR_SUCCESS; - srs_assert(fs); + srs_assert(fw); - if (!fs->is_open()) { + if (!fw->is_open()) { ret = ERROR_KERNEL_MP3_STREAM_CLOSED; srs_warn("stream is not open for encoder. ret=%d", ret); return ret; } - _fs = fs; + writer = fw; return ret; } @@ -78,7 +78,7 @@ int SrsMp3Encoder::write_header() (char)0x00, (char)0x00, (char)0x00, (char)0x00, // FrameSize (char)0x00, (char)0x00 // Flags }; - return _fs->write(id3, sizeof(id3), NULL); + return writer->write(id3, sizeof(id3), NULL); } 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) return ret; } - return _fs->write(data + stream->pos(), size - stream->pos(), NULL); + return writer->write(data + stream->pos(), size - stream->pos(), NULL); } diff --git a/trunk/src/kernel/srs_kernel_mp3.hpp b/trunk/src/kernel/srs_kernel_mp3.hpp index 64a37020a..5a42dc2db 100644 --- a/trunk/src/kernel/srs_kernel_mp3.hpp +++ b/trunk/src/kernel/srs_kernel_mp3.hpp @@ -33,7 +33,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. class SrsStream; class SrsFileWriter; -class SrsFileReader; /** * encode data to aac file. @@ -41,7 +40,7 @@ class SrsFileReader; class SrsMp3Encoder { private: - SrsFileWriter* _fs; + SrsFileWriter* writer; private: SrsStream* tag_stream; public: @@ -51,9 +50,9 @@ public: /** * initialize the underlayer file stream. * @remark user can initialize multiple times to encode multiple mp3 files. - * @remark, user must free the fs, mp3 encoder never close/free it. + * @remark, user must free the @param fw, mp3 encoder never close/free it. */ - virtual int initialize(SrsFileWriter* fs); + virtual int initialize(SrsFileWriter* fw); public: /** * write mp3 id3 v2.3 header. diff --git a/trunk/src/kernel/srs_kernel_stream.cpp b/trunk/src/kernel/srs_kernel_stream.cpp index 48a1dc8dc..309c4b8f1 100644 --- a/trunk/src/kernel/srs_kernel_stream.cpp +++ b/trunk/src/kernel/srs_kernel_stream.cpp @@ -31,8 +31,8 @@ using namespace std; SrsStream::SrsStream() { - p = _bytes = NULL; - _size = 0; + p = bytes = NULL; + nb_bytes = 0; // TODO: support both little and big endian. srs_assert(srs_is_little_endian()); @@ -42,24 +42,24 @@ SrsStream::~SrsStream() { } -int SrsStream::initialize(char* bytes, int size) +int SrsStream::initialize(char* b, int nb) { int ret = ERROR_SUCCESS; - if (!bytes) { + if (!b) { ret = ERROR_KERNEL_STREAM_INIT; srs_error("stream param bytes must not be NULL. ret=%d", ret); return ret; } - if (size <= 0) { + if (nb <= 0) { ret = ERROR_KERNEL_STREAM_INIT; srs_error("stream param size must be positive. ret=%d", ret); return ret; } - _size = size; - p = _bytes = bytes; + nb_bytes = nb; + p = bytes = b; srs_info("init stream ok, size=%d", size); return ret; @@ -67,29 +67,29 @@ int SrsStream::initialize(char* bytes, int size) char* SrsStream::data() { - return _bytes; + return bytes; } int SrsStream::size() { - return _size; + return nb_bytes; } int SrsStream::pos() { - return p - _bytes; + return (int)(p - bytes); } bool SrsStream::empty() { - return !_bytes || (p >= _bytes + _size); + return !bytes || (p >= bytes + nb_bytes); } bool SrsStream::require(int required_size) { srs_assert(required_size > 0); - return required_size <= _size - (p - _bytes); + return required_size <= nb_bytes - (p - bytes); } void SrsStream::skip(int size) @@ -111,7 +111,7 @@ int16_t SrsStream::read_2bytes() srs_assert(require(2)); int16_t value; - pp = (char*)&value; + char* pp = (char*)&value; pp[1] = *p++; pp[0] = *p++; @@ -123,7 +123,7 @@ int32_t SrsStream::read_3bytes() srs_assert(require(3)); int32_t value = 0x00; - pp = (char*)&value; + char* pp = (char*)&value; pp[2] = *p++; pp[1] = *p++; pp[0] = *p++; @@ -136,7 +136,7 @@ int32_t SrsStream::read_4bytes() srs_assert(require(4)); int32_t value; - pp = (char*)&value; + char* pp = (char*)&value; pp[3] = *p++; pp[2] = *p++; pp[1] = *p++; @@ -150,7 +150,7 @@ int64_t SrsStream::read_8bytes() srs_assert(require(8)); int64_t value; - pp = (char*)&value; + char* pp = (char*)&value; pp[7] = *p++; pp[6] = *p++; pp[5] = *p++; @@ -195,7 +195,7 @@ void SrsStream::write_2bytes(int16_t value) { srs_assert(require(2)); - pp = (char*)&value; + char* pp = (char*)&value; *p++ = pp[1]; *p++ = pp[0]; } @@ -204,7 +204,7 @@ void SrsStream::write_4bytes(int32_t value) { srs_assert(require(4)); - pp = (char*)&value; + char* pp = (char*)&value; *p++ = pp[3]; *p++ = pp[2]; *p++ = pp[1]; @@ -215,7 +215,7 @@ void SrsStream::write_3bytes(int32_t value) { srs_assert(require(3)); - pp = (char*)&value; + char* pp = (char*)&value; *p++ = pp[2]; *p++ = pp[1]; *p++ = pp[0]; @@ -225,7 +225,7 @@ void SrsStream::write_8bytes(int64_t value) { srs_assert(require(8)); - pp = (char*)&value; + char* pp = (char*)&value; *p++ = pp[7]; *p++ = pp[6]; *p++ = pp[5]; @@ -238,7 +238,7 @@ void SrsStream::write_8bytes(int64_t value) void SrsStream::write_string(string value) { - srs_assert(require(value.length())); + srs_assert(require((int)value.length())); memcpy(p, value.data(), value.length()); p += value.length(); diff --git a/trunk/src/kernel/srs_kernel_stream.hpp b/trunk/src/kernel/srs_kernel_stream.hpp index 1c17cdad2..0d80800df 100644 --- a/trunk/src/kernel/srs_kernel_stream.hpp +++ b/trunk/src/kernel/srs_kernel_stream.hpp @@ -41,23 +41,25 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. class SrsStream { private: + // current position at bytes. char* p; - char* pp; - char* _bytes; - int _size; + // the bytes data for stream to read or write. + char* bytes; + // the total number of bytes. + int nb_bytes; public: SrsStream(); virtual ~SrsStream(); public: /** * initialize the stream from bytes. - * @bytes, the bytes to convert from/to basic types. - * @size, the size of bytes. + * @b, the bytes to convert from/to basic types. + * @nb, the size of bytes, total number of bytes for stream. * @remark, stream never free the bytes, user must free it. * @remark, return error when bytes NULL. * @remark, return error when size is not positive. */ - virtual int initialize(char* bytes, int size); + virtual int initialize(char* b, int nb); // get the status of stream public: /** diff --git a/trunk/src/kernel/srs_kernel_ts.cpp b/trunk/src/kernel/srs_kernel_ts.cpp index 0f6baa666..433aaa201 100644 --- a/trunk/src/kernel/srs_kernel_ts.cpp +++ b/trunk/src/kernel/srs_kernel_ts.cpp @@ -2697,11 +2697,11 @@ SrsTSMuxer::~SrsTSMuxer() close(); } -int SrsTSMuxer::open(string _path) +int SrsTSMuxer::open(string p) { int ret = ERROR_SUCCESS; - path = _path; + path = p; close(); @@ -3048,7 +3048,7 @@ int SrsTsCache::do_cache_avc(SrsAvcAacCodec* codec, SrsCodecSample* sample) SrsTsEncoder::SrsTsEncoder() { - _fs = NULL; + writer = NULL; codec = new SrsAvcAacCodec(); sample = new SrsCodecSample(); cache = new SrsTsCache(); @@ -3065,22 +3065,22 @@ SrsTsEncoder::~SrsTsEncoder() srs_freep(context); } -int SrsTsEncoder::initialize(SrsFileWriter* fs) +int SrsTsEncoder::initialize(SrsFileWriter* fw) { int ret = ERROR_SUCCESS; - srs_assert(fs); + srs_assert(fw); - if (!fs->is_open()) { + if (!fw->is_open()) { ret = ERROR_KERNEL_FLV_STREAM_CLOSED; srs_warn("stream is not open for encoder. ret=%d", ret); return ret; } - _fs = fs; + writer = fw; srs_freep(muxer); - muxer = new SrsTSMuxer(fs, context, SrsCodecAudioAAC, SrsCodecVideoAVC); + muxer = new SrsTSMuxer(fw, context, SrsCodecAudioAAC, SrsCodecVideoAVC); if ((ret = muxer->open("")) != ERROR_SUCCESS) { return ret; diff --git a/trunk/src/kernel/srs_kernel_ts.hpp b/trunk/src/kernel/srs_kernel_ts.hpp index f042256d8..772524f1d 100644 --- a/trunk/src/kernel/srs_kernel_ts.hpp +++ b/trunk/src/kernel/srs_kernel_ts.hpp @@ -1560,9 +1560,10 @@ public: virtual ~SrsTSMuxer(); public: /** - * open the writer, donot write the PSI of ts. - */ - virtual int open(std::string _path); + * open the writer, donot write the PSI of ts. + * @param p a string indicates the path of ts file to mux to. + */ + virtual int open(std::string p); /** * when open ts, we donot write the header(PSI), * for user may need to update the acodec to mp3 or others, @@ -1625,7 +1626,7 @@ private: class SrsTsEncoder { private: - SrsFileWriter* _fs; + SrsFileWriter* writer; private: SrsAvcAacCodec* codec; SrsCodecSample* sample; @@ -1637,9 +1638,10 @@ public: virtual ~SrsTsEncoder(); public: /** - * initialize the underlayer file stream. - */ - virtual int initialize(SrsFileWriter* fs); + * initialize the underlayer file stream. + * @param fw the writer to use for ts encoder, user must free it. + */ + virtual int initialize(SrsFileWriter* fw); public: /** * write audio/video packet. From a62d1cdf2a63b2700bc7dfa5aa66e6fa060f8e8b Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 30 Jul 2015 17:47:40 +0800 Subject: [PATCH 3/6] refine the readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 182f1e380..833b5e3ab 100755 --- a/README.md +++ b/README.md @@ -691,7 +691,7 @@ The publish RTMP benchmark by [SB](https://github.com/simple-rtmp-server/srs-ben | 2014-12-03 | 2.0.12 | 1.2k(1200) | publishers | 96% | 43MB | - | | 2014-12-03 | 2.0.47 | 1.2k(1200) | publishers | 84% | 76MB | [code][p1] | | 2014-12-03 | 2.0.47 | 1.4k(1400) | publishers | 95% | 140MB | - | -| 2014-12-03 | 2.0.48 | 1.4k(1400 | publishers | 95% | 140MB | [code][p2] | +| 2014-12-03 | 2.0.48 | 1.4k(1400) | publishers | 95% | 140MB | [code][p2] | | 2014-12-04 | 2.0.49 | 1.4k(1400) | publishers | 68% | 144MB | - | | 2014-12-04 | 2.0.49 | 2.5k(2500) | publishers | 95% | 404MB | [code][p3] | | 2014-12-04 | 2.0.51 | 2.5k(2500) | publishers | 91% | 259MB | [code][p4] | From ccf6a4de1ea5e03ab81f9f1345e22f8dd510cfdf Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 3 Aug 2015 13:35:25 +0800 Subject: [PATCH 4/6] remove the on_reload_vhost_http_remux_updated for vhost added. --- trunk/src/app/srs_app_config.cpp | 12 ------------ trunk/src/app/srs_app_http_stream.cpp | 11 +++++++++++ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index a5fd507bf..c6404a436 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -852,18 +852,6 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root) } } - // TODO: reload new http_remux in on_vhost_add - // http_remux, only one per vhost. - if (get_vhost_http_remux_enabled(vhost)) { - for (it = subscribes.begin(); it != subscribes.end(); ++it) { - ISrsReloadHandler* subscribe = *it; - if ((ret = subscribe->on_reload_vhost_http_remux_updated(vhost)) != ERROR_SUCCESS) { - srs_error("vhost %s notify subscribes http_remux failed. ret=%d", vhost.c_str(), ret); - return ret; - } - } - srs_trace("vhost %s reload http_remux success.", vhost.c_str()); - } srs_trace("reload new vhost %s success.", vhost.c_str()); continue; } diff --git a/trunk/src/app/srs_app_http_stream.cpp b/trunk/src/app/srs_app_http_stream.cpp index cc41986cb..4702269b9 100644 --- a/trunk/src/app/srs_app_http_stream.cpp +++ b/trunk/src/app/srs_app_http_stream.cpp @@ -863,6 +863,17 @@ void SrsHttpStreamServer::http_unmount(SrsSource* s, SrsRequest* r) entry->stream->entry->enabled = false; } +int SrsHttpStreamServer::on_reload_vhost_added(string vhost) +{ + int ret = ERROR_SUCCESS; + + if ((ret = on_reload_vhost_http_remux_updated(vhost)) != ERROR_SUCCESS) { + return ret; + } + + return ret; +} + int SrsHttpStreamServer::on_reload_vhost_http_remux_updated(string vhost) { int ret = ERROR_SUCCESS; From 71f2726b312e8c1824372171047b89cc0daa4dc3 Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 3 Aug 2015 13:44:24 +0800 Subject: [PATCH 5/6] fix bug of merge code for reload http_remux for vhost --- trunk/src/app/srs_app_http_stream.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/trunk/src/app/srs_app_http_stream.hpp b/trunk/src/app/srs_app_http_stream.hpp index b07dd448c..26c172bd4 100644 --- a/trunk/src/app/srs_app_http_stream.hpp +++ b/trunk/src/app/srs_app_http_stream.hpp @@ -354,6 +354,7 @@ public: virtual void unmount_hls(SrsRequest* r); // interface ISrsReloadHandler. public: + virtual int on_reload_vhost_added(std::string vhost); virtual int on_reload_vhost_http_remux_updated(std::string vhost); virtual int on_reload_vhost_hls(std::string vhost); // interface ISrsHttpMatchHijacker From 65b2ed7ac552e5db080221fe32cb93803358bed2 Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 3 Aug 2015 14:11:21 +0800 Subject: [PATCH 6/6] refine code, move the order of functions. --- trunk/src/app/srs_app_config.cpp | 994 ++++++++++++++--------------- trunk/src/app/srs_app_config.hpp | 11 +- trunk/src/app/srs_app_http_api.cpp | 19 +- trunk/src/app/srs_app_ingest.cpp | 3 +- 4 files changed, 514 insertions(+), 513 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index c6404a436..37a650f95 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -535,271 +535,6 @@ int SrsConfig::reload() return reload_conf(&conf); } -int SrsConfig::reload_conf(SrsConfig* conf) -{ - int ret = ERROR_SUCCESS; - - SrsConfDirective* old_root = root; - SrsAutoFree(SrsConfDirective, old_root); - - root = conf->root; - conf->root = NULL; - - // merge config. - std::vector::iterator it; - - // never support reload: - // daemon - // - // always support reload without additional code: - // chunk_size, ff_log_dir, - // bandcheck, http_hooks, heartbeat, - // token_traverse, debug_srs_upnode, - // security - - // merge config: max_connections - if (!srs_directive_equals(root->get("max_connections"), old_root->get("max_connections"))) { - for (it = subscribes.begin(); it != subscribes.end(); ++it) { - ISrsReloadHandler* subscribe = *it; - if ((ret = subscribe->on_reload_max_conns()) != ERROR_SUCCESS) { - srs_error("notify subscribes reload max_connections failed. ret=%d", ret); - return ret; - } - } - srs_trace("reload max_connections success."); - } - - // merge config: listen - if (!srs_directive_equals(root->get("listen"), old_root->get("listen"))) { - for (it = subscribes.begin(); it != subscribes.end(); ++it) { - ISrsReloadHandler* subscribe = *it; - if ((ret = subscribe->on_reload_listen()) != ERROR_SUCCESS) { - srs_error("notify subscribes reload listen failed. ret=%d", ret); - return ret; - } - } - srs_trace("reload listen success."); - } - - // merge config: pid - if (!srs_directive_equals(root->get("pid"), old_root->get("pid"))) { - for (it = subscribes.begin(); it != subscribes.end(); ++it) { - ISrsReloadHandler* subscribe = *it; - if ((ret = subscribe->on_reload_pid()) != ERROR_SUCCESS) { - srs_error("notify subscribes reload pid failed. ret=%d", ret); - return ret; - } - } - srs_trace("reload pid success."); - } - - // merge config: srs_log_tank - if (!srs_directive_equals(root->get("srs_log_tank"), old_root->get("srs_log_tank"))) { - for (it = subscribes.begin(); it != subscribes.end(); ++it) { - ISrsReloadHandler* subscribe = *it; - if ((ret = subscribe->on_reload_log_tank()) != ERROR_SUCCESS) { - srs_error("notify subscribes reload srs_log_tank failed. ret=%d", ret); - return ret; - } - } - srs_trace("reload srs_log_tank success."); - } - - // merge config: srs_log_level - if (!srs_directive_equals(root->get("srs_log_level"), old_root->get("srs_log_level"))) { - for (it = subscribes.begin(); it != subscribes.end(); ++it) { - ISrsReloadHandler* subscribe = *it; - if ((ret = subscribe->on_reload_log_level()) != ERROR_SUCCESS) { - srs_error("notify subscribes reload srs_log_level failed. ret=%d", ret); - return ret; - } - } - srs_trace("reload srs_log_level success."); - } - - // merge config: srs_log_file - if (!srs_directive_equals(root->get("srs_log_file"), old_root->get("srs_log_file"))) { - for (it = subscribes.begin(); it != subscribes.end(); ++it) { - ISrsReloadHandler* subscribe = *it; - if ((ret = subscribe->on_reload_log_file()) != ERROR_SUCCESS) { - srs_error("notify subscribes reload srs_log_file failed. ret=%d", ret); - return ret; - } - } - srs_trace("reload srs_log_file success."); - } - - // merge config: pithy_print_ms - if (!srs_directive_equals(root->get("pithy_print_ms"), old_root->get("pithy_print_ms"))) { - for (it = subscribes.begin(); it != subscribes.end(); ++it) { - ISrsReloadHandler* subscribe = *it; - if ((ret = subscribe->on_reload_pithy_print()) != ERROR_SUCCESS) { - srs_error("notify subscribes pithy_print_ms listen failed. ret=%d", ret); - return ret; - } - } - srs_trace("reload pithy_print_ms success."); - } - - // merge config: http_api - if ((ret = reload_http_api(old_root)) != ERROR_SUCCESS) { - return ret; - } - - // merge config: http_stream - if ((ret = reload_http_stream(old_root)) != ERROR_SUCCESS) { - return ret; - } - - // TODO: FIXME: support reload stream_caster. - - // merge config: vhost - if ((ret = reload_vhost(old_root)) != ERROR_SUCCESS) { - return ret; - } - - return ret; -} - -int SrsConfig::reload_http_api(SrsConfDirective* old_root) -{ - int ret = ERROR_SUCCESS; - - // merge config. - std::vector::iterator it; - - // state graph - // old_http_api new_http_api - // DISABLED => ENABLED - // ENABLED => DISABLED - // ENABLED => ENABLED (modified) - - SrsConfDirective* new_http_api = root->get("http_api"); - SrsConfDirective* old_http_api = old_root->get("http_api"); - - // DISABLED => ENABLED - if (!get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api)) { - for (it = subscribes.begin(); it != subscribes.end(); ++it) { - ISrsReloadHandler* subscribe = *it; - if ((ret = subscribe->on_reload_http_api_enabled()) != ERROR_SUCCESS) { - srs_error("notify subscribes http_api disabled=>enabled failed. ret=%d", ret); - return ret; - } - } - srs_trace("reload disabled=>enabled http_api success."); - - return ret; - } - - // ENABLED => DISABLED - if (get_http_api_enabled(old_http_api) && !get_http_api_enabled(new_http_api)) { - for (it = subscribes.begin(); it != subscribes.end(); ++it) { - ISrsReloadHandler* subscribe = *it; - if ((ret = subscribe->on_reload_http_api_disabled()) != ERROR_SUCCESS) { - srs_error("notify subscribes http_api enabled=>disabled failed. ret=%d", ret); - return ret; - } - } - srs_trace("reload enabled=>disabled http_api success."); - - return ret; - } - - // ENABLED => ENABLED (modified) - if (get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api) - && !srs_directive_equals(old_http_api, new_http_api) - ) { - for (it = subscribes.begin(); it != subscribes.end(); ++it) { - ISrsReloadHandler* subscribe = *it; - if ((ret = subscribe->on_reload_http_api_enabled()) != ERROR_SUCCESS) { - srs_error("notify subscribes http_api enabled modified failed. ret=%d", ret); - return ret; - } - } - srs_trace("reload enabled modified http_api success."); - - return ret; - } - - srs_trace("reload http_api not changed success."); - - return ret; -} - -int SrsConfig::reload_http_stream(SrsConfDirective* old_root) -{ - int ret = ERROR_SUCCESS; - - // merge config. - std::vector::iterator it; - - // state graph - // old_http_stream new_http_stream - // DISABLED => ENABLED - // ENABLED => DISABLED - // ENABLED => ENABLED (modified) - - SrsConfDirective* new_http_stream = root->get("http_stream"); - // http_stream rename to http_server in SRS2. - if (!new_http_stream) { - new_http_stream = root->get("http_server"); - } - - SrsConfDirective* old_http_stream = old_root->get("http_stream"); - // http_stream rename to http_server in SRS2. - if (!old_http_stream) { - old_http_stream = root->get("http_server"); - } - - // DISABLED => ENABLED - if (!get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)) { - for (it = subscribes.begin(); it != subscribes.end(); ++it) { - ISrsReloadHandler* subscribe = *it; - if ((ret = subscribe->on_reload_http_stream_enabled()) != ERROR_SUCCESS) { - srs_error("notify subscribes http_stream disabled=>enabled failed. ret=%d", ret); - return ret; - } - } - srs_trace("reload disabled=>enabled http_stream success."); - - return ret; - } - - // ENABLED => DISABLED - if (get_http_stream_enabled(old_http_stream) && !get_http_stream_enabled(new_http_stream)) { - for (it = subscribes.begin(); it != subscribes.end(); ++it) { - ISrsReloadHandler* subscribe = *it; - if ((ret = subscribe->on_reload_http_stream_disabled()) != ERROR_SUCCESS) { - srs_error("notify subscribes http_stream enabled=>disabled failed. ret=%d", ret); - return ret; - } - } - srs_trace("reload enabled=>disabled http_stream success."); - - return ret; - } - - // ENABLED => ENABLED (modified) - if (get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream) - && !srs_directive_equals(old_http_stream, new_http_stream) - ) { - for (it = subscribes.begin(); it != subscribes.end(); ++it) { - ISrsReloadHandler* subscribe = *it; - if ((ret = subscribe->on_reload_http_stream_updated()) != ERROR_SUCCESS) { - srs_error("notify subscribes http_stream enabled modified failed. ret=%d", ret); - return ret; - } - } - srs_trace("reload enabled modified http_stream success."); - - return ret; - } - - srs_trace("reload http_stream not changed success."); - - return ret; -} - int SrsConfig::reload_vhost(SrsConfDirective* old_root) { int ret = ERROR_SUCCESS; @@ -1084,6 +819,271 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root) return ret; } +int SrsConfig::reload_conf(SrsConfig* conf) +{ + int ret = ERROR_SUCCESS; + + SrsConfDirective* old_root = root; + SrsAutoFree(SrsConfDirective, old_root); + + root = conf->root; + conf->root = NULL; + + // merge config. + std::vector::iterator it; + + // never support reload: + // daemon + // + // always support reload without additional code: + // chunk_size, ff_log_dir, + // bandcheck, http_hooks, heartbeat, + // token_traverse, debug_srs_upnode, + // security + + // merge config: max_connections + if (!srs_directive_equals(root->get("max_connections"), old_root->get("max_connections"))) { + for (it = subscribes.begin(); it != subscribes.end(); ++it) { + ISrsReloadHandler* subscribe = *it; + if ((ret = subscribe->on_reload_max_conns()) != ERROR_SUCCESS) { + srs_error("notify subscribes reload max_connections failed. ret=%d", ret); + return ret; + } + } + srs_trace("reload max_connections success."); + } + + // merge config: listen + if (!srs_directive_equals(root->get("listen"), old_root->get("listen"))) { + for (it = subscribes.begin(); it != subscribes.end(); ++it) { + ISrsReloadHandler* subscribe = *it; + if ((ret = subscribe->on_reload_listen()) != ERROR_SUCCESS) { + srs_error("notify subscribes reload listen failed. ret=%d", ret); + return ret; + } + } + srs_trace("reload listen success."); + } + + // merge config: pid + if (!srs_directive_equals(root->get("pid"), old_root->get("pid"))) { + for (it = subscribes.begin(); it != subscribes.end(); ++it) { + ISrsReloadHandler* subscribe = *it; + if ((ret = subscribe->on_reload_pid()) != ERROR_SUCCESS) { + srs_error("notify subscribes reload pid failed. ret=%d", ret); + return ret; + } + } + srs_trace("reload pid success."); + } + + // merge config: srs_log_tank + if (!srs_directive_equals(root->get("srs_log_tank"), old_root->get("srs_log_tank"))) { + for (it = subscribes.begin(); it != subscribes.end(); ++it) { + ISrsReloadHandler* subscribe = *it; + if ((ret = subscribe->on_reload_log_tank()) != ERROR_SUCCESS) { + srs_error("notify subscribes reload srs_log_tank failed. ret=%d", ret); + return ret; + } + } + srs_trace("reload srs_log_tank success."); + } + + // merge config: srs_log_level + if (!srs_directive_equals(root->get("srs_log_level"), old_root->get("srs_log_level"))) { + for (it = subscribes.begin(); it != subscribes.end(); ++it) { + ISrsReloadHandler* subscribe = *it; + if ((ret = subscribe->on_reload_log_level()) != ERROR_SUCCESS) { + srs_error("notify subscribes reload srs_log_level failed. ret=%d", ret); + return ret; + } + } + srs_trace("reload srs_log_level success."); + } + + // merge config: srs_log_file + if (!srs_directive_equals(root->get("srs_log_file"), old_root->get("srs_log_file"))) { + for (it = subscribes.begin(); it != subscribes.end(); ++it) { + ISrsReloadHandler* subscribe = *it; + if ((ret = subscribe->on_reload_log_file()) != ERROR_SUCCESS) { + srs_error("notify subscribes reload srs_log_file failed. ret=%d", ret); + return ret; + } + } + srs_trace("reload srs_log_file success."); + } + + // merge config: pithy_print_ms + if (!srs_directive_equals(root->get("pithy_print_ms"), old_root->get("pithy_print_ms"))) { + for (it = subscribes.begin(); it != subscribes.end(); ++it) { + ISrsReloadHandler* subscribe = *it; + if ((ret = subscribe->on_reload_pithy_print()) != ERROR_SUCCESS) { + srs_error("notify subscribes pithy_print_ms listen failed. ret=%d", ret); + return ret; + } + } + srs_trace("reload pithy_print_ms success."); + } + + // merge config: http_api + if ((ret = reload_http_api(old_root)) != ERROR_SUCCESS) { + return ret; + } + + // merge config: http_stream + if ((ret = reload_http_stream(old_root)) != ERROR_SUCCESS) { + return ret; + } + + // TODO: FIXME: support reload stream_caster. + + // merge config: vhost + if ((ret = reload_vhost(old_root)) != ERROR_SUCCESS) { + return ret; + } + + return ret; +} + +int SrsConfig::reload_http_api(SrsConfDirective* old_root) +{ + int ret = ERROR_SUCCESS; + + // merge config. + std::vector::iterator it; + + // state graph + // old_http_api new_http_api + // DISABLED => ENABLED + // ENABLED => DISABLED + // ENABLED => ENABLED (modified) + + SrsConfDirective* new_http_api = root->get("http_api"); + SrsConfDirective* old_http_api = old_root->get("http_api"); + + // DISABLED => ENABLED + if (!get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api)) { + for (it = subscribes.begin(); it != subscribes.end(); ++it) { + ISrsReloadHandler* subscribe = *it; + if ((ret = subscribe->on_reload_http_api_enabled()) != ERROR_SUCCESS) { + srs_error("notify subscribes http_api disabled=>enabled failed. ret=%d", ret); + return ret; + } + } + srs_trace("reload disabled=>enabled http_api success."); + + return ret; + } + + // ENABLED => DISABLED + if (get_http_api_enabled(old_http_api) && !get_http_api_enabled(new_http_api)) { + for (it = subscribes.begin(); it != subscribes.end(); ++it) { + ISrsReloadHandler* subscribe = *it; + if ((ret = subscribe->on_reload_http_api_disabled()) != ERROR_SUCCESS) { + srs_error("notify subscribes http_api enabled=>disabled failed. ret=%d", ret); + return ret; + } + } + srs_trace("reload enabled=>disabled http_api success."); + + return ret; + } + + // ENABLED => ENABLED (modified) + if (get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api) + && !srs_directive_equals(old_http_api, new_http_api) + ) { + for (it = subscribes.begin(); it != subscribes.end(); ++it) { + ISrsReloadHandler* subscribe = *it; + if ((ret = subscribe->on_reload_http_api_enabled()) != ERROR_SUCCESS) { + srs_error("notify subscribes http_api enabled modified failed. ret=%d", ret); + return ret; + } + } + srs_trace("reload enabled modified http_api success."); + + return ret; + } + + srs_trace("reload http_api not changed success."); + + return ret; +} + +int SrsConfig::reload_http_stream(SrsConfDirective* old_root) +{ + int ret = ERROR_SUCCESS; + + // merge config. + std::vector::iterator it; + + // state graph + // old_http_stream new_http_stream + // DISABLED => ENABLED + // ENABLED => DISABLED + // ENABLED => ENABLED (modified) + + SrsConfDirective* new_http_stream = root->get("http_stream"); + // http_stream rename to http_server in SRS2. + if (!new_http_stream) { + new_http_stream = root->get("http_server"); + } + + SrsConfDirective* old_http_stream = old_root->get("http_stream"); + // http_stream rename to http_server in SRS2. + if (!old_http_stream) { + old_http_stream = root->get("http_server"); + } + + // DISABLED => ENABLED + if (!get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)) { + for (it = subscribes.begin(); it != subscribes.end(); ++it) { + ISrsReloadHandler* subscribe = *it; + if ((ret = subscribe->on_reload_http_stream_enabled()) != ERROR_SUCCESS) { + srs_error("notify subscribes http_stream disabled=>enabled failed. ret=%d", ret); + return ret; + } + } + srs_trace("reload disabled=>enabled http_stream success."); + + return ret; + } + + // ENABLED => DISABLED + if (get_http_stream_enabled(old_http_stream) && !get_http_stream_enabled(new_http_stream)) { + for (it = subscribes.begin(); it != subscribes.end(); ++it) { + ISrsReloadHandler* subscribe = *it; + if ((ret = subscribe->on_reload_http_stream_disabled()) != ERROR_SUCCESS) { + srs_error("notify subscribes http_stream enabled=>disabled failed. ret=%d", ret); + return ret; + } + } + srs_trace("reload enabled=>disabled http_stream success."); + + return ret; + } + + // ENABLED => ENABLED (modified) + if (get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream) + && !srs_directive_equals(old_http_stream, new_http_stream) + ) { + for (it = subscribes.begin(); it != subscribes.end(); ++it) { + ISrsReloadHandler* subscribe = *it; + if ((ret = subscribe->on_reload_http_stream_updated()) != ERROR_SUCCESS) { + srs_error("notify subscribes http_stream enabled modified failed. ret=%d", ret); + return ret; + } + } + srs_trace("reload enabled modified http_stream success."); + + return ret; + } + + srs_trace("reload http_stream not changed success."); + + return ret; +} + int SrsConfig::reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost) { int ret = ERROR_SUCCESS; @@ -1481,9 +1481,6 @@ int SrsConfig::check_config() int ret = ERROR_SUCCESS; srs_trace("srs checking config..."); - - vector vhosts = get_vhosts(); - vector stream_casters = get_stream_casters(); //////////////////////////////////////////////////////////////////////// // check empty @@ -1538,9 +1535,9 @@ int SrsConfig::check_config() SrsConfDirective* conf = get_heartbeart(); for (int i = 0; conf && i < (int)conf->directives.size(); i++) { string n = conf->at(i)->name; - if (n != "enabled" && n != "interval" && n != "url" + if (n != "enabled" && n != "interval" && n != "url" && n != "device_id" && n != "summaries" - ) { + ) { ret = ERROR_SYSTEM_CONFIG_INVALID; srs_error("unsupported heartbeat directive %s, ret=%d", n.c_str(), ret); return ret; @@ -1558,200 +1555,7 @@ int SrsConfig::check_config() } } } - for (int n = 0; n < (int)stream_casters.size(); n++) { - SrsConfDirective* stream_caster = stream_casters[n]; - for (int i = 0; stream_caster && i < (int)stream_caster->directives.size(); i++) { - SrsConfDirective* conf = stream_caster->at(i); - string n = conf->name; - if (n != "enabled" && n != "caster" && n != "output" - && n != "listen" && n != "rtp_port_min" && n != "rtp_port_max" - ) { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("unsupported stream_caster directive %s, ret=%d", n.c_str(), ret); - return ret; - } - } - } - for (int n = 0; n < (int)vhosts.size(); n++) { - SrsConfDirective* vhost = vhosts[n]; - for (int i = 0; vhost && i < (int)vhost->directives.size(); i++) { - SrsConfDirective* conf = vhost->at(i); - string n = conf->name; - if (n != "enabled" && n != "chunk_size" - && n != "mode" && n != "origin" && n != "token_traverse" && n != "vhost" - && n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks" - && n != "gop_cache" && n != "queue_length" - && n != "refer" && n != "refer_publish" && n != "refer_play" - && n != "forward" && n != "transcode" && n != "bandcheck" - && n != "time_jitter" && n != "mix_correct" - && n != "atc" && n != "atc_auto" - && n != "debug_srs_upnode" - && n != "mr" && n != "mw_latency" && n != "min_latency" - && n != "security" && n != "http_remux" - && n != "http" && n != "http_static" - && n != "hds" - ) { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("unsupported vhost directive %s, ret=%d", n.c_str(), ret); - return ret; - } - // for each sub directives of vhost. - if (n == "dvr") { - for (int j = 0; j < (int)conf->directives.size(); j++) { - string m = conf->at(j)->name.c_str(); - if (m != "enabled" && m != "dvr_path" && m != "dvr_plan" - && m != "dvr_duration" && m != "dvr_wait_keyframe" && m != "time_jitter" - ) { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("unsupported vhost dvr directive %s, ret=%d", m.c_str(), ret); - return ret; - } - } - } else if (n == "mr") { - for (int j = 0; j < (int)conf->directives.size(); j++) { - string m = conf->at(j)->name.c_str(); - if (m != "enabled" && m != "latency" - ) { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("unsupported vhost mr directive %s, ret=%d", m.c_str(), ret); - return ret; - } - } - } else if (n == "ingest") { - for (int j = 0; j < (int)conf->directives.size(); j++) { - string m = conf->at(j)->name.c_str(); - if (m != "enabled" && m != "input" && m != "ffmpeg" - && m != "engine" - ) { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("unsupported vhost ingest directive %s, ret=%d", m.c_str(), ret); - return ret; - } - } - } else if (n == "http" || n == "http_static") { - for (int j = 0; j < (int)conf->directives.size(); j++) { - string m = conf->at(j)->name.c_str(); - if (m != "enabled" && m != "mount" && m != "dir") { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("unsupported vhost http directive %s, ret=%d", m.c_str(), ret); - return ret; - } - } - } else if (n == "http_remux") { - for (int j = 0; j < (int)conf->directives.size(); j++) { - string m = conf->at(j)->name.c_str(); - if (m != "enabled" && m != "mount" && m != "fast_cache" && m != "hstrs") { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("unsupported vhost http_remux directive %s, ret=%d", m.c_str(), ret); - return ret; - } - } - } else if (n == "hls") { - for (int j = 0; j < (int)conf->directives.size(); j++) { - string m = conf->at(j)->name.c_str(); - if (m != "enabled" && m != "hls_entry_prefix" && m != "hls_path" && m != "hls_fragment" && m != "hls_window" && m != "hls_on_error" - && m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec" - && m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" && m != "hls_cleanup" && m != "hls_nb_notify" - && m != "hls_wait_keyframe" && m != "hls_dispose" - ) { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret); - return ret; - } - } - } else if (n == "http_hooks") { - for (int j = 0; j < (int)conf->directives.size(); j++) { - string m = conf->at(j)->name.c_str(); - if (m != "enabled" && m != "on_connect" && m != "on_close" && m != "on_publish" - && m != "on_unpublish" && m != "on_play" && m != "on_stop" - && m != "on_dvr" && m != "on_hls" && m != "on_hls_notify" - ) { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("unsupported vhost http_hooks directive %s, ret=%d", m.c_str(), ret); - return ret; - } - } - } else if (n == "forward") { - // TODO: FIXME: implements it. - /*for (int j = 0; j < (int)conf->directives.size(); j++) { - string m = conf->at(j)->name.c_str(); - if (m != "enabled" && m != "vhost" && m != "refer") { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("unsupported vhost forward directive %s, ret=%d", m.c_str(), ret); - return ret; - } - }*/ - } else if (n == "security") { - for (int j = 0; j < (int)conf->directives.size(); j++) { - SrsConfDirective* security = conf->at(j); - string m = security->name.c_str(); - if (m != "enabled" && m != "deny" && m != "allow") { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("unsupported vhost security directive %s, ret=%d", m.c_str(), ret); - return ret; - } - } - } else if (n == "transcode") { - for (int j = 0; j < (int)conf->directives.size(); j++) { - SrsConfDirective* trans = conf->at(j); - string m = trans->name.c_str(); - if (m != "enabled" && m != "ffmpeg" && m != "engine") { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("unsupported vhost transcode directive %s, ret=%d", m.c_str(), ret); - return ret; - } - if (m == "engine") { - for (int k = 0; k < (int)trans->directives.size(); k++) { - string e = trans->at(k)->name; - if (e != "enabled" && e != "vfilter" && e != "vcodec" - && e != "vbitrate" && e != "vfps" && e != "vwidth" && e != "vheight" - && e != "vthreads" && e != "vprofile" && e != "vpreset" && e != "vparams" - && e != "acodec" && e != "abitrate" && e != "asample_rate" && e != "achannels" - && e != "aparams" && e != "output" - && e != "iformat" && e != "oformat" - ) { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("unsupported vhost transcode engine directive %s, ret=%d", e.c_str(), ret); - return ret; - } - } - } - } - } else if (n == "bandcheck") { - for (int j = 0; j < (int)conf->directives.size(); j++) { - string m = conf->at(j)->name.c_str(); - if (m != "enabled" && m != "key" && m != "interval" && m != "limit_kbps") { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("unsupported vhost bandcheck directive %s, ret=%d", m.c_str(), ret); - return ret; - } - } - } - } - } - // check ingest id unique. - for (int i = 0; i < (int)vhosts.size(); i++) { - SrsConfDirective* vhost = vhosts[i]; - std::vector ids; - - for (int j = 0; j < (int)vhost->directives.size(); j++) { - SrsConfDirective* conf = vhost->at(j); - if (conf->name != "ingest") { - continue; - } - - std::string id = conf->arg0(); - for (int k = 0; k < (int)ids.size(); k++) { - if (id == ids.at(k)) { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("directive \"ingest\" id duplicated, vhost=%s, id=%s, ret=%d", - vhost->name.c_str(), id.c_str(), ret); - return ret; - } - } - ids.push_back(id); - } - } + //////////////////////////////////////////////////////////////////////// // check listen for rtmp. @@ -1881,32 +1685,6 @@ int SrsConfig::check_config() get_http_stream_listen().c_str(), ret); return ret; } - - //////////////////////////////////////////////////////////////////////// - // check chunk size - //////////////////////////////////////////////////////////////////////// - if (get_global_chunk_size() < SRS_CONSTS_RTMP_MIN_CHUNK_SIZE - || get_global_chunk_size() > SRS_CONSTS_RTMP_MAX_CHUNK_SIZE - ) { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("directive chunk_size invalid, chunk_size=%d, must in [%d, %d], ret=%d", - get_global_chunk_size(), SRS_CONSTS_RTMP_MIN_CHUNK_SIZE, - SRS_CONSTS_RTMP_MAX_CHUNK_SIZE, ret); - return ret; - } - for (int i = 0; i < (int)vhosts.size(); i++) { - SrsConfDirective* vhost = vhosts[i]; - if (get_chunk_size(vhost->arg0()) < SRS_CONSTS_RTMP_MIN_CHUNK_SIZE - || get_chunk_size(vhost->arg0()) > SRS_CONSTS_RTMP_MAX_CHUNK_SIZE - ) { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("directive vhost %s chunk_size invalid, chunk_size=%d, must in [%d, %d], ret=%d", - vhost->arg0().c_str(), get_chunk_size(vhost->arg0()), SRS_CONSTS_RTMP_MIN_CHUNK_SIZE, - SRS_CONSTS_RTMP_MAX_CHUNK_SIZE, ret); - return ret; - } - } - //////////////////////////////////////////////////////////////////////// // check log name and level //////////////////////////////////////////////////////////////////////// @@ -1939,6 +1717,230 @@ int SrsConfig::check_config() srs_warn("http_api is disabled by configure"); } #endif + + vector stream_casters = get_stream_casters(); + for (int n = 0; n < (int)stream_casters.size(); n++) { + SrsConfDirective* stream_caster = stream_casters[n]; + for (int i = 0; stream_caster && i < (int)stream_caster->directives.size(); i++) { + SrsConfDirective* conf = stream_caster->at(i); + string n = conf->name; + if (n != "enabled" && n != "caster" && n != "output" + && n != "listen" && n != "rtp_port_min" && n != "rtp_port_max" + ) { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("unsupported stream_caster directive %s, ret=%d", n.c_str(), ret); + return ret; + } + } + } + + vector vhosts; + get_vhosts(vhosts); + for (int n = 0; n < (int)vhosts.size(); n++) { + SrsConfDirective* vhost = vhosts[n]; + for (int i = 0; vhost && i < (int)vhost->directives.size(); i++) { + SrsConfDirective* conf = vhost->at(i); + string n = conf->name; + if (n != "enabled" && n != "chunk_size" + && n != "mode" && n != "origin" && n != "token_traverse" && n != "vhost" + && n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks" + && n != "gop_cache" && n != "queue_length" + && n != "refer" && n != "refer_publish" && n != "refer_play" + && n != "forward" && n != "transcode" && n != "bandcheck" + && n != "time_jitter" && n != "mix_correct" + && n != "atc" && n != "atc_auto" + && n != "debug_srs_upnode" + && n != "mr" && n != "mw_latency" && n != "min_latency" + && n != "security" && n != "http_remux" + && n != "http" && n != "http_static" + && n != "hds" + ) { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("unsupported vhost directive %s, ret=%d", n.c_str(), ret); + return ret; + } + // for each sub directives of vhost. + if (n == "dvr") { + for (int j = 0; j < (int)conf->directives.size(); j++) { + string m = conf->at(j)->name.c_str(); + if (m != "enabled" && m != "dvr_path" && m != "dvr_plan" + && m != "dvr_duration" && m != "dvr_wait_keyframe" && m != "time_jitter" + ) { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("unsupported vhost dvr directive %s, ret=%d", m.c_str(), ret); + return ret; + } + } + } else if (n == "mr") { + for (int j = 0; j < (int)conf->directives.size(); j++) { + string m = conf->at(j)->name.c_str(); + if (m != "enabled" && m != "latency" + ) { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("unsupported vhost mr directive %s, ret=%d", m.c_str(), ret); + return ret; + } + } + } else if (n == "ingest") { + for (int j = 0; j < (int)conf->directives.size(); j++) { + string m = conf->at(j)->name.c_str(); + if (m != "enabled" && m != "input" && m != "ffmpeg" + && m != "engine" + ) { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("unsupported vhost ingest directive %s, ret=%d", m.c_str(), ret); + return ret; + } + } + } else if (n == "http" || n == "http_static") { + for (int j = 0; j < (int)conf->directives.size(); j++) { + string m = conf->at(j)->name.c_str(); + if (m != "enabled" && m != "mount" && m != "dir") { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("unsupported vhost http directive %s, ret=%d", m.c_str(), ret); + return ret; + } + } + } else if (n == "http_remux") { + for (int j = 0; j < (int)conf->directives.size(); j++) { + string m = conf->at(j)->name.c_str(); + if (m != "enabled" && m != "mount" && m != "fast_cache" && m != "hstrs") { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("unsupported vhost http_remux directive %s, ret=%d", m.c_str(), ret); + return ret; + } + } + } else if (n == "hls") { + for (int j = 0; j < (int)conf->directives.size(); j++) { + string m = conf->at(j)->name.c_str(); + if (m != "enabled" && m != "hls_entry_prefix" && m != "hls_path" && m != "hls_fragment" && m != "hls_window" && m != "hls_on_error" + && m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec" + && m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" && m != "hls_cleanup" && m != "hls_nb_notify" + && m != "hls_wait_keyframe" && m != "hls_dispose" + ) { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret); + return ret; + } + } + } else if (n == "http_hooks") { + for (int j = 0; j < (int)conf->directives.size(); j++) { + string m = conf->at(j)->name.c_str(); + if (m != "enabled" && m != "on_connect" && m != "on_close" && m != "on_publish" + && m != "on_unpublish" && m != "on_play" && m != "on_stop" + && m != "on_dvr" && m != "on_hls" && m != "on_hls_notify" + ) { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("unsupported vhost http_hooks directive %s, ret=%d", m.c_str(), ret); + return ret; + } + } + } else if (n == "forward") { + // TODO: FIXME: implements it. + /*for (int j = 0; j < (int)conf->directives.size(); j++) { + string m = conf->at(j)->name.c_str(); + if (m != "enabled" && m != "vhost" && m != "refer") { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("unsupported vhost forward directive %s, ret=%d", m.c_str(), ret); + return ret; + } + }*/ + } else if (n == "security") { + for (int j = 0; j < (int)conf->directives.size(); j++) { + SrsConfDirective* security = conf->at(j); + string m = security->name.c_str(); + if (m != "enabled" && m != "deny" && m != "allow") { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("unsupported vhost security directive %s, ret=%d", m.c_str(), ret); + return ret; + } + } + } else if (n == "transcode") { + for (int j = 0; j < (int)conf->directives.size(); j++) { + SrsConfDirective* trans = conf->at(j); + string m = trans->name.c_str(); + if (m != "enabled" && m != "ffmpeg" && m != "engine") { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("unsupported vhost transcode directive %s, ret=%d", m.c_str(), ret); + return ret; + } + if (m == "engine") { + for (int k = 0; k < (int)trans->directives.size(); k++) { + string e = trans->at(k)->name; + if (e != "enabled" && e != "vfilter" && e != "vcodec" + && e != "vbitrate" && e != "vfps" && e != "vwidth" && e != "vheight" + && e != "vthreads" && e != "vprofile" && e != "vpreset" && e != "vparams" + && e != "acodec" && e != "abitrate" && e != "asample_rate" && e != "achannels" + && e != "aparams" && e != "output" + && e != "iformat" && e != "oformat" + ) { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("unsupported vhost transcode engine directive %s, ret=%d", e.c_str(), ret); + return ret; + } + } + } + } + } else if (n == "bandcheck") { + for (int j = 0; j < (int)conf->directives.size(); j++) { + string m = conf->at(j)->name.c_str(); + if (m != "enabled" && m != "key" && m != "interval" && m != "limit_kbps") { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("unsupported vhost bandcheck directive %s, ret=%d", m.c_str(), ret); + return ret; + } + } + } + } + } + // check ingest id unique. + for (int i = 0; i < (int)vhosts.size(); i++) { + SrsConfDirective* vhost = vhosts[i]; + std::vector ids; + + for (int j = 0; j < (int)vhost->directives.size(); j++) { + SrsConfDirective* conf = vhost->at(j); + if (conf->name != "ingest") { + continue; + } + + std::string id = conf->arg0(); + for (int k = 0; k < (int)ids.size(); k++) { + if (id == ids.at(k)) { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("directive \"ingest\" id duplicated, vhost=%s, id=%s, ret=%d", + vhost->name.c_str(), id.c_str(), ret); + return ret; + } + } + ids.push_back(id); + } + } + + //////////////////////////////////////////////////////////////////////// + // check chunk size + //////////////////////////////////////////////////////////////////////// + if (get_global_chunk_size() < SRS_CONSTS_RTMP_MIN_CHUNK_SIZE + || get_global_chunk_size() > SRS_CONSTS_RTMP_MAX_CHUNK_SIZE + ) { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("directive chunk_size invalid, chunk_size=%d, must in [%d, %d], ret=%d", + get_global_chunk_size(), SRS_CONSTS_RTMP_MIN_CHUNK_SIZE, + SRS_CONSTS_RTMP_MAX_CHUNK_SIZE, ret); + return ret; + } + for (int i = 0; i < (int)vhosts.size(); i++) { + SrsConfDirective* vhost = vhosts[i]; + if (get_chunk_size(vhost->arg0()) < SRS_CONSTS_RTMP_MIN_CHUNK_SIZE + || get_chunk_size(vhost->arg0()) > SRS_CONSTS_RTMP_MAX_CHUNK_SIZE + ) { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("directive vhost %s chunk_size invalid, chunk_size=%d, must in [%d, %d], ret=%d", + vhost->arg0().c_str(), get_chunk_size(vhost->arg0()), SRS_CONSTS_RTMP_MIN_CHUNK_SIZE, + SRS_CONSTS_RTMP_MAX_CHUNK_SIZE, ret); + return ret; + } + } for (int i = 0; i < (int)vhosts.size(); i++) { SrsConfDirective* vhost = vhosts[i]; srs_assert(vhost != NULL); @@ -2207,23 +2209,19 @@ SrsConfDirective* SrsConfig::get_vhost(string vhost) return NULL; } -vector SrsConfig::get_vhosts() +void SrsConfig::get_vhosts(vector& vhosts) { srs_assert(root); - - std::vector vhosts; - + for (int i = 0; i < (int)root->directives.size(); i++) { SrsConfDirective* conf = root->at(i); - + if (!conf->is_vhost()) { continue; } - + vhosts.push_back(conf); } - - return vhosts; } bool SrsConfig::get_vhost_enabled(string vhost) diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 2378d1e65..2c5f52d5f 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -253,6 +253,11 @@ public: * @remark, user can test the config before reload it. */ virtual int reload(); +private: + /** + * reload the vhost section of config. + */ + virtual int reload_vhost(SrsConfDirective* old_root); protected: /** * reload from the config. @@ -269,10 +274,6 @@ private: */ virtual int reload_http_stream(SrsConfDirective* old_root); /** - * reload the vhost section of config. - */ - virtual int reload_vhost(SrsConfDirective* old_root); - /** * reload the transcode section of vhost of config. */ virtual int reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost); @@ -413,7 +414,7 @@ public: /** * get all vhosts in config file. */ - virtual std::vector get_vhosts(); + virtual void get_vhosts(std::vector& vhosts); /** * whether vhost is enabled * @param vhost, the vhost name. diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index b21fadedc..c95cb9289 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -543,20 +543,21 @@ int SrsHttpApi::do_cycle() // always free it in this scope. SrsAutoFree(ISrsHttpMessage, req); - // TODO: FIXME: use the post body. - std::string res; - - // get response body. - if ((ret = req->body_read_all(res)) != ERROR_SUCCESS) { - return ret; - } - // ok, handle http request. SrsHttpResponseWriter writer(&skt); if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) { return ret; } - + + // read all rest bytes in request body. + char buf[SRS_HTTP_READ_CACHE_BYTES]; + ISrsHttpResponseReader* br = req->body_reader(); + while (!br->eof()) { + if ((ret = br->read(buf, SRS_HTTP_READ_CACHE_BYTES, NULL)) != ERROR_SUCCESS) { + return ret; + } + } + // donot keep alive, disconnect it. // @see https://github.com/simple-rtmp-server/srs/issues/399 if (!req->is_keep_alive()) { diff --git a/trunk/src/app/srs_app_ingest.cpp b/trunk/src/app/srs_app_ingest.cpp index 43527bbed..b24fc3a25 100644 --- a/trunk/src/app/srs_app_ingest.cpp +++ b/trunk/src/app/srs_app_ingest.cpp @@ -293,7 +293,8 @@ int SrsIngester::parse() int ret = ERROR_SUCCESS; // parse ingesters - std::vector vhosts = _srs_config->get_vhosts(); + std::vector vhosts; + _srs_config->get_vhosts(vhosts); for (int i = 0; i < (int)vhosts.size(); i++) { SrsConfDirective* vhost = vhosts[i];