1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

for bug #241, merge big chunks for publish, no use.

This commit is contained in:
winlin 2014-12-02 22:26:04 +08:00
parent 463e1fbc41
commit 6b57597718
10 changed files with 90 additions and 21 deletions

View file

@ -26,7 +26,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
#define SOCKET_READ_SIZE 4096
// 4096=4KB
// 16384=16KB
// 65536=64KB
#define SOCKET_READ_SIZE 16384
ISrsBufferReader::ISrsBufferReader()
{
@ -38,10 +41,13 @@ ISrsBufferReader::~ISrsBufferReader()
SrsBuffer::SrsBuffer()
{
merge_chunks_in_big_buffer = false;
buffer = new char[SOCKET_READ_SIZE];
}
SrsBuffer::~SrsBuffer()
{
srs_freep(buffer);
}
int SrsBuffer::length()
@ -88,11 +94,15 @@ int SrsBuffer::grow(ISrsBufferReader* reader, int required_size)
}
while (length() < required_size) {
char buffer[SOCKET_READ_SIZE];
ssize_t nread;
if ((ret = reader->read(buffer, SOCKET_READ_SIZE, &nread)) != ERROR_SUCCESS) {
return ret;
if (merge_chunks_in_big_buffer) {
if ((ret = reader->read_fully(buffer, SOCKET_READ_SIZE, &nread)) != ERROR_SUCCESS) {
return ret;
}
} else {
if ((ret = reader->read(buffer, SOCKET_READ_SIZE, &nread)) != ERROR_SUCCESS) {
return ret;
}
}
srs_assert((int)nread > 0);
@ -102,4 +112,9 @@ int SrsBuffer::grow(ISrsBufferReader* reader, int required_size)
return ret;
}
void SrsBuffer::set_merge_chunks(bool v)
{
merge_chunks_in_big_buffer = v;
}

View file

@ -42,7 +42,16 @@ public:
virtual ~ISrsBufferReader();
// for protocol/amf0/msg-codec
public:
/**
* read some bytes of data.
* @param nread, the actually read size, NULL to ignore.
*/
virtual int read(void* buf, size_t size, ssize_t* nread) = 0;
/**
* read specified size bytes of data
* @param nread, the actually read size, NULL to ignore.
*/
virtual int read_fully(void* buf, size_t size, ssize_t* nread) = 0;
};
/**
@ -53,6 +62,15 @@ class SrsBuffer
{
private:
std::vector<char> data;
/**
* notice the protocol stack to merge chunks to big buffer.
* for example, the buffer is 64KB=512kb, it's 1s buffer for 500kbps video stream.
* so we can use read_fullly(64KB) to merge all chunks in 1s.
* @see https://github.com/winlinvip/simple-rtmp-server/issues/241
*/
bool merge_chunks_in_big_buffer;
// the socket recv buffer.
char* buffer;
public:
SrsBuffer();
virtual ~SrsBuffer();
@ -89,6 +107,14 @@ public:
* @remark, we actually maybe read more than required_size, maybe 4k for example.
*/
virtual int grow(ISrsBufferReader* reader, int required_size);
public:
/**
* notice the protocol stack to merge chunks to big buffer.
* for example, the buffer is 64KB=512kb, it's 1s buffer for 500kbps video stream.
* so we can use read_fullly(64KB) to merge all chunks in 1s.
* @see https://github.com/winlinvip/simple-rtmp-server/issues/241
*/
virtual void set_merge_chunks(bool v);
};
#endif