diff --git a/trunk/src/app/srs_app_recv_thread.cpp b/trunk/src/app/srs_app_recv_thread.cpp index 877ed14a6..e17f9737e 100644 --- a/trunk/src/app/srs_app_recv_thread.cpp +++ b/trunk/src/app/srs_app_recv_thread.cpp @@ -429,7 +429,8 @@ void SrsPublishRecvThread::set_socket_buffer(int sleep_ms) // sleep 800ms for small bytes, the buffer should set to: // 800*1000/8=100000B(about 128KB). // 2000*3000/8=750000B(about 732KB). - int kbps = 3000; + // 2000*5000/8=1250000B(about 1220KB). + int kbps = 5000; int socket_buffer_size = sleep_ms * kbps / 8; // socket recv buffer, system will double it. diff --git a/trunk/src/rtmp/srs_protocol_buffer.cpp b/trunk/src/rtmp/srs_protocol_buffer.cpp index bc5d21784..f801380c0 100644 --- a/trunk/src/rtmp/srs_protocol_buffer.cpp +++ b/trunk/src/rtmp/srs_protocol_buffer.cpp @@ -28,8 +28,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include -// the default recv buffer size -#define SRS_DEFAULT_RECV_BUFFER_SIZE 32768 +// the default recv buffer size, 128KB. +#define SRS_DEFAULT_RECV_BUFFER_SIZE 131072 + +// limit user-space buffer to 256KB, for 3Mbps stream delivery. +// 800*2000/8=200000B(about 195KB). +// @remark it's ok for higher stream, the buffer is ok for one chunk is 256KB. +#define SRS_MAX_SOCKET_BUFFER 262144 // the max header size, // @see SrsProtocol::read_message_header(). @@ -100,15 +105,21 @@ SrsFastBuffer::SrsFastBuffer() void SrsFastBuffer::set_buffer(int buffer_size) { + // the user-space buffer size limit to a max value. + int nb_max_buf = srs_min(buffer_size, SRS_MAX_SOCKET_BUFFER); + if (nb_max_buf < buffer_size) { + srs_warn("limit the user-space buffer from %d to %d", buffer_size, nb_max_buf); + } + // only realloc when buffer changed bigger - if (buffer_size <= nb_buffer) { + if (nb_max_buf <= nb_buffer) { return; } int start = p - buffer; int cap = end - p; - char* buf = new char[buffer_size]; + char* buf = new char[nb_max_buf]; if (cap > 0) { memcpy(buf, buffer, nb_buffer); }