mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
For #299, refine code.
This commit is contained in:
parent
62b7204514
commit
f32aab3d92
175 changed files with 15529 additions and 15935 deletions
|
@ -1,25 +1,25 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2017 SRS(ossrs)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013-2017 SRS(ossrs)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <srs_protocol_stream.hpp>
|
||||
|
||||
|
@ -84,13 +84,13 @@ void SrsFastStream::set_buffer(int buffer_size)
|
|||
{
|
||||
// never exceed the max size.
|
||||
if (buffer_size > SRS_MAX_SOCKET_BUFFER) {
|
||||
srs_warn("limit the user-space buffer from %d to %d",
|
||||
buffer_size, SRS_MAX_SOCKET_BUFFER);
|
||||
srs_warn("limit the user-space buffer from %d to %d",
|
||||
buffer_size, SRS_MAX_SOCKET_BUFFER);
|
||||
}
|
||||
|
||||
// the user-space buffer size limit to a max value.
|
||||
int nb_resize_buf = srs_min(buffer_size, SRS_MAX_SOCKET_BUFFER);
|
||||
|
||||
|
||||
// only realloc when buffer changed bigger
|
||||
if (nb_resize_buf <= nb_buffer) {
|
||||
return;
|
||||
|
@ -120,7 +120,7 @@ char* SrsFastStream::read_slice(int size)
|
|||
|
||||
char* ptr = p;
|
||||
p += size;
|
||||
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
@ -134,16 +134,16 @@ void SrsFastStream::skip(int size)
|
|||
int SrsFastStream::grow(ISrsReader* reader, int required_size)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
|
||||
// already got required size of bytes.
|
||||
if (end - p >= required_size) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// must be positive.
|
||||
srs_assert(required_size > 0);
|
||||
|
||||
// the free space of buffer,
|
||||
|
||||
// the free space of buffer,
|
||||
// buffer = consumed_bytes + exists_bytes + free_space.
|
||||
int nb_free_space = (int)(buffer + nb_buffer - end);
|
||||
|
||||
|
@ -154,7 +154,7 @@ int SrsFastStream::grow(ISrsReader* reader, int required_size)
|
|||
// resize the space when no left space.
|
||||
if (nb_free_space < required_size - nb_exists_bytes) {
|
||||
srs_verbose("move fast buffer %d bytes", nb_exists_bytes);
|
||||
|
||||
|
||||
// reset or move to get more space.
|
||||
if (!nb_exists_bytes) {
|
||||
// reset when buffer is empty.
|
||||
|
@ -172,12 +172,12 @@ int SrsFastStream::grow(ISrsReader* reader, int required_size)
|
|||
nb_free_space = (int)(buffer + nb_buffer - end);
|
||||
if (nb_free_space < required_size - nb_exists_bytes) {
|
||||
ret = ERROR_READER_BUFFER_OVERFLOW;
|
||||
srs_error("buffer overflow, required=%d, max=%d, left=%d, ret=%d",
|
||||
required_size, nb_buffer, nb_free_space, ret);
|
||||
srs_error("buffer overflow, required=%d, max=%d, left=%d, ret=%d",
|
||||
required_size, nb_buffer, nb_free_space, ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// buffer is ok, read required size of bytes.
|
||||
while (end - p < required_size) {
|
||||
ssize_t nread;
|
||||
|
@ -187,11 +187,11 @@ int SrsFastStream::grow(ISrsReader* reader, int required_size)
|
|||
|
||||
#ifdef SRS_PERF_MERGED_READ
|
||||
/**
|
||||
* to improve read performance, merge some packets then read,
|
||||
* when it on and read small bytes, we sleep to wait more data.,
|
||||
* that is, we merge some data to read together.
|
||||
* @see https://github.com/ossrs/srs/issues/241
|
||||
*/
|
||||
* to improve read performance, merge some packets then read,
|
||||
* when it on and read small bytes, we sleep to wait more data.,
|
||||
* that is, we merge some data to read together.
|
||||
* @see https://github.com/ossrs/srs/issues/241
|
||||
*/
|
||||
if (merged_read && _handler) {
|
||||
_handler->on_read(nread);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue