winlin

for bug #248, use simple buffer for http.

@@ -396,47 +396,6 @@ private: @@ -396,47 +396,6 @@ private:
396 } 396 }
397 }; 397 };
398 398
399 -SrsSimpleBuffer::SrsSimpleBuffer()  
400 -{  
401 -}  
402 -  
403 -SrsSimpleBuffer::~SrsSimpleBuffer()  
404 -{  
405 -}  
406 -  
407 -int SrsSimpleBuffer::length()  
408 -{  
409 - int len = (int)data.size();  
410 - srs_assert(len >= 0);  
411 - return len;  
412 -}  
413 -  
414 -char* SrsSimpleBuffer::bytes()  
415 -{  
416 - return (length() == 0)? NULL : &data.at(0);  
417 -}  
418 -  
419 -void SrsSimpleBuffer::erase(int size)  
420 -{  
421 - if (size <= 0) {  
422 - return;  
423 - }  
424 -  
425 - if (size >= length()) {  
426 - data.clear();  
427 - return;  
428 - }  
429 -  
430 - data.erase(data.begin(), data.begin() + size);  
431 -}  
432 -  
433 -void SrsSimpleBuffer::append(const char* bytes, int size)  
434 -{  
435 - srs_assert(size > 0);  
436 -  
437 - data.insert(data.end(), bytes, bytes + size);  
438 -}  
439 -  
440 SrsHlsAacJitter::SrsHlsAacJitter() 399 SrsHlsAacJitter::SrsHlsAacJitter()
441 { 400 {
442 base_pts = 0; 401 base_pts = 0;
@@ -61,43 +61,7 @@ class SrsRequest; @@ -61,43 +61,7 @@ class SrsRequest;
61 class SrsPithyPrint; 61 class SrsPithyPrint;
62 class SrsSource; 62 class SrsSource;
63 class SrsFileWriter; 63 class SrsFileWriter;
64 -  
65 -/**  
66 -* the simple buffer use vector to append bytes,  
67 -* it's for hls, and need to be refined in future.  
68 -*/  
69 -class SrsSimpleBuffer  
70 -{  
71 -private:  
72 - std::vector<char> data;  
73 -public:  
74 - SrsSimpleBuffer();  
75 - virtual ~SrsSimpleBuffer();  
76 -public:  
77 - /**  
78 - * get the length of buffer. empty if zero.  
79 - * @remark assert length() is not negative.  
80 - */  
81 - virtual int length();  
82 - /**  
83 - * get the buffer bytes.  
84 - * @return the bytes, NULL if empty.  
85 - */  
86 - virtual char* bytes();  
87 - /**  
88 - * erase size of bytes from begin.  
89 - * @param size to erase size of bytes.  
90 - * clear if size greater than or equals to length()  
91 - * @remark ignore size is not positive.  
92 - */  
93 - virtual void erase(int size);  
94 - /**  
95 - * append specified bytes to buffer.  
96 - * @param size the size of bytes  
97 - * @remark assert size is positive.  
98 - */  
99 - virtual void append(const char* bytes, int size);  
100 -}; 64 +class SrsSimpleBuffer;
101 65
102 /** 66 /**
103 * jitter correct for audio, 67 * jitter correct for audio,
@@ -537,7 +537,7 @@ SrsHttpHandler* SrsHttpHandler::create_http_stream() @@ -537,7 +537,7 @@ SrsHttpHandler* SrsHttpHandler::create_http_stream()
537 537
538 SrsHttpMessage::SrsHttpMessage() 538 SrsHttpMessage::SrsHttpMessage()
539 { 539 {
540 - _body = new SrsBuffer(); 540 + _body = new SrsSimpleBuffer();
541 _state = SrsHttpParseStateInit; 541 _state = SrsHttpParseStateInit;
542 _uri = new SrsHttpUri(); 542 _uri = new SrsHttpUri();
543 _match = NULL; 543 _match = NULL;
@@ -39,7 +39,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -39,7 +39,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 39
40 #include <srs_app_st.hpp> 40 #include <srs_app_st.hpp>
41 41
42 -class SrsBuffer; 42 +class SrsSimpleBuffer;
43 class SrsRequest; 43 class SrsRequest;
44 class SrsStSocket; 44 class SrsStSocket;
45 class SrsHttpUri; 45 class SrsHttpUri;
@@ -214,7 +214,7 @@ private: @@ -214,7 +214,7 @@ private:
214 * body object, in bytes. 214 * body object, in bytes.
215 * @remark, user can get body in string by get_body(). 215 * @remark, user can get body in string by get_body().
216 */ 216 */
217 - SrsBuffer* _body; 217 + SrsSimpleBuffer* _body;
218 /** 218 /**
219 * parser state 219 * parser state
220 * @remark, user can use is_complete() to determine the state. 220 * @remark, user can use is_complete() to determine the state.
@@ -27,6 +27,47 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -27,6 +27,47 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include <srs_kernel_log.hpp> 27 #include <srs_kernel_log.hpp>
28 #include <srs_kernel_utility.hpp> 28 #include <srs_kernel_utility.hpp>
29 29
  30 +SrsSimpleBuffer::SrsSimpleBuffer()
  31 +{
  32 +}
  33 +
  34 +SrsSimpleBuffer::~SrsSimpleBuffer()
  35 +{
  36 +}
  37 +
  38 +int SrsSimpleBuffer::length()
  39 +{
  40 + int len = (int)data.size();
  41 + srs_assert(len >= 0);
  42 + return len;
  43 +}
  44 +
  45 +char* SrsSimpleBuffer::bytes()
  46 +{
  47 + return (length() == 0)? NULL : &data.at(0);
  48 +}
  49 +
  50 +void SrsSimpleBuffer::erase(int size)
  51 +{
  52 + if (size <= 0) {
  53 + return;
  54 + }
  55 +
  56 + if (size >= length()) {
  57 + data.clear();
  58 + return;
  59 + }
  60 +
  61 + data.erase(data.begin(), data.begin() + size);
  62 +}
  63 +
  64 +void SrsSimpleBuffer::append(const char* bytes, int size)
  65 +{
  66 + srs_assert(size > 0);
  67 +
  68 + data.insert(data.end(), bytes, bytes + size);
  69 +}
  70 +
30 IMergeReadHandler::IMergeReadHandler() 71 IMergeReadHandler::IMergeReadHandler()
31 { 72 {
32 } 73 }
@@ -34,6 +34,43 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -34,6 +34,43 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 34
35 #include <srs_protocol_io.hpp> 35 #include <srs_protocol_io.hpp>
36 36
  37 +/**
  38 +* the simple buffer use vector to append bytes,
  39 +* it's for hls and http, and need to be refined in future.
  40 +*/
  41 +class SrsSimpleBuffer
  42 +{
  43 +private:
  44 + std::vector<char> data;
  45 +public:
  46 + SrsSimpleBuffer();
  47 + virtual ~SrsSimpleBuffer();
  48 +public:
  49 + /**
  50 + * get the length of buffer. empty if zero.
  51 + * @remark assert length() is not negative.
  52 + */
  53 + virtual int length();
  54 + /**
  55 + * get the buffer bytes.
  56 + * @return the bytes, NULL if empty.
  57 + */
  58 + virtual char* bytes();
  59 + /**
  60 + * erase size of bytes from begin.
  61 + * @param size to erase size of bytes.
  62 + * clear if size greater than or equals to length()
  63 + * @remark ignore size is not positive.
  64 + */
  65 + virtual void erase(int size);
  66 + /**
  67 + * append specified bytes to buffer.
  68 + * @param size the size of bytes
  69 + * @remark assert size is positive.
  70 + */
  71 + virtual void append(const char* bytes, int size);
  72 +};
  73 +
37 // 4KB=4096 74 // 4KB=4096
38 // 8KB=8192 75 // 8KB=8192
39 // 16KB=16384 76 // 16KB=16384
@@ -97,6 +134,7 @@ public: @@ -97,6 +134,7 @@ public:
97 * @return the bytes, NULL if empty. 134 * @return the bytes, NULL if empty.
98 */ 135 */
99 virtual char* bytes(); 136 virtual char* bytes();
  137 +public:
100 /** 138 /**
101 * erase size of bytes from begin. 139 * erase size of bytes from begin.
102 * @param size to erase size of bytes. 140 * @param size to erase size of bytes.
@@ -104,6 +142,7 @@ public: @@ -104,6 +142,7 @@ public:
104 * @remark ignore size is not positive. 142 * @remark ignore size is not positive.
105 */ 143 */
106 virtual void erase(int size); 144 virtual void erase(int size);
  145 +private:
107 /** 146 /**
108 * append specified bytes to buffer. 147 * append specified bytes to buffer.
109 * @param size the size of bytes 148 * @param size the size of bytes