mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
for bug #248, use simple buffer for http.
This commit is contained in:
parent
2cb8b7dd52
commit
0ea8cd9e84
6 changed files with 84 additions and 81 deletions
|
@ -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;
|
||||
|
|
|
@ -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<char> 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,
|
||||
|
|
|
@ -537,7 +537,7 @@ SrsHttpHandler* SrsHttpHandler::create_http_stream()
|
|||
|
||||
SrsHttpMessage::SrsHttpMessage()
|
||||
{
|
||||
_body = new SrsBuffer();
|
||||
_body = new SrsSimpleBuffer();
|
||||
_state = SrsHttpParseStateInit;
|
||||
_uri = new SrsHttpUri();
|
||||
_match = NULL;
|
||||
|
|
|
@ -39,7 +39,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
||||
#include <srs_app_st.hpp>
|
||||
|
||||
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.
|
||||
|
|
|
@ -27,6 +27,47 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#include <srs_kernel_log.hpp>
|
||||
#include <srs_kernel_utility.hpp>
|
||||
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -34,6 +34,43 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
||||
#include <srs_protocol_io.hpp>
|
||||
|
||||
/**
|
||||
* 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<char> 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
|
||||
|
|
Loading…
Reference in a new issue