diff --git a/trunk/src/app/srs_app_hls.cpp b/trunk/src/app/srs_app_hls.cpp index 801e72579..1f0c6bba0 100644 --- a/trunk/src/app/srs_app_hls.cpp +++ b/trunk/src/app/srs_app_hls.cpp @@ -396,47 +396,6 @@ private: } }; -SrsSimpleBuffer::SrsSimpleBuffer() -{ -} - -SrsSimpleBuffer::~SrsSimpleBuffer() -{ -} - -int SrsSimpleBuffer::length() -{ - int len = (int)data.size(); - srs_assert(len >= 0); - return len; -} - -char* SrsSimpleBuffer::bytes() -{ - return (length() == 0)? NULL : &data.at(0); -} - -void SrsSimpleBuffer::erase(int size) -{ - if (size <= 0) { - return; - } - - if (size >= length()) { - data.clear(); - return; - } - - data.erase(data.begin(), data.begin() + size); -} - -void SrsSimpleBuffer::append(const char* bytes, int size) -{ - srs_assert(size > 0); - - data.insert(data.end(), bytes, bytes + size); -} - SrsHlsAacJitter::SrsHlsAacJitter() { base_pts = 0; diff --git a/trunk/src/app/srs_app_hls.hpp b/trunk/src/app/srs_app_hls.hpp index 923b56859..8b77945b6 100644 --- a/trunk/src/app/srs_app_hls.hpp +++ b/trunk/src/app/srs_app_hls.hpp @@ -61,43 +61,7 @@ class SrsRequest; class SrsPithyPrint; class SrsSource; class SrsFileWriter; - -/** -* the simple buffer use vector to append bytes, -* it's for hls, and need to be refined in future. -*/ -class SrsSimpleBuffer -{ -private: - std::vector data; -public: - SrsSimpleBuffer(); - virtual ~SrsSimpleBuffer(); -public: - /** - * get the length of buffer. empty if zero. - * @remark assert length() is not negative. - */ - virtual int length(); - /** - * get the buffer bytes. - * @return the bytes, NULL if empty. - */ - virtual char* bytes(); - /** - * erase size of bytes from begin. - * @param size to erase size of bytes. - * clear if size greater than or equals to length() - * @remark ignore size is not positive. - */ - virtual void erase(int size); - /** - * append specified bytes to buffer. - * @param size the size of bytes - * @remark assert size is positive. - */ - virtual void append(const char* bytes, int size); -}; +class SrsSimpleBuffer; /** * jitter correct for audio, diff --git a/trunk/src/app/srs_app_http.cpp b/trunk/src/app/srs_app_http.cpp index 9494b431d..3cc17e5d7 100644 --- a/trunk/src/app/srs_app_http.cpp +++ b/trunk/src/app/srs_app_http.cpp @@ -537,7 +537,7 @@ SrsHttpHandler* SrsHttpHandler::create_http_stream() SrsHttpMessage::SrsHttpMessage() { - _body = new SrsBuffer(); + _body = new SrsSimpleBuffer(); _state = SrsHttpParseStateInit; _uri = new SrsHttpUri(); _match = NULL; diff --git a/trunk/src/app/srs_app_http.hpp b/trunk/src/app/srs_app_http.hpp index a9dd80a59..27822ee0e 100644 --- a/trunk/src/app/srs_app_http.hpp +++ b/trunk/src/app/srs_app_http.hpp @@ -39,7 +39,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include -class SrsBuffer; +class SrsSimpleBuffer; class SrsRequest; class SrsStSocket; class SrsHttpUri; @@ -214,7 +214,7 @@ private: * body object, in bytes. * @remark, user can get body in string by get_body(). */ - SrsBuffer* _body; + SrsSimpleBuffer* _body; /** * parser state * @remark, user can use is_complete() to determine the state. diff --git a/trunk/src/rtmp/srs_protocol_buffer.cpp b/trunk/src/rtmp/srs_protocol_buffer.cpp index 68122c24a..4eb05edb3 100644 --- a/trunk/src/rtmp/srs_protocol_buffer.cpp +++ b/trunk/src/rtmp/srs_protocol_buffer.cpp @@ -27,6 +27,47 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include +SrsSimpleBuffer::SrsSimpleBuffer() +{ +} + +SrsSimpleBuffer::~SrsSimpleBuffer() +{ +} + +int SrsSimpleBuffer::length() +{ + int len = (int)data.size(); + srs_assert(len >= 0); + return len; +} + +char* SrsSimpleBuffer::bytes() +{ + return (length() == 0)? NULL : &data.at(0); +} + +void SrsSimpleBuffer::erase(int size) +{ + if (size <= 0) { + return; + } + + if (size >= length()) { + data.clear(); + return; + } + + data.erase(data.begin(), data.begin() + size); +} + +void SrsSimpleBuffer::append(const char* bytes, int size) +{ + srs_assert(size > 0); + + data.insert(data.end(), bytes, bytes + size); +} + IMergeReadHandler::IMergeReadHandler() { } diff --git a/trunk/src/rtmp/srs_protocol_buffer.hpp b/trunk/src/rtmp/srs_protocol_buffer.hpp index 7ef91299f..89d02182e 100644 --- a/trunk/src/rtmp/srs_protocol_buffer.hpp +++ b/trunk/src/rtmp/srs_protocol_buffer.hpp @@ -34,6 +34,43 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include +/** +* the simple buffer use vector to append bytes, +* it's for hls and http, and need to be refined in future. +*/ +class SrsSimpleBuffer +{ +private: + std::vector data; +public: + SrsSimpleBuffer(); + virtual ~SrsSimpleBuffer(); +public: + /** + * get the length of buffer. empty if zero. + * @remark assert length() is not negative. + */ + virtual int length(); + /** + * get the buffer bytes. + * @return the bytes, NULL if empty. + */ + virtual char* bytes(); + /** + * erase size of bytes from begin. + * @param size to erase size of bytes. + * clear if size greater than or equals to length() + * @remark ignore size is not positive. + */ + virtual void erase(int size); + /** + * append specified bytes to buffer. + * @param size the size of bytes + * @remark assert size is positive. + */ + virtual void append(const char* bytes, int size); +}; + // 4KB=4096 // 8KB=8192 // 16KB=16384 @@ -97,6 +134,7 @@ public: * @return the bytes, NULL if empty. */ virtual char* bytes(); +public: /** * erase size of bytes from begin. * @param size to erase size of bytes. @@ -104,6 +142,7 @@ public: * @remark ignore size is not positive. */ virtual void erase(int size); +private: /** * append specified bytes to buffer. * @param size the size of bytes