mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
performance refine, support 3k+ connections(270kbps). 0.9.130
This commit is contained in:
parent
e9c96af91a
commit
1ae3e6c64c
18 changed files with 230 additions and 162 deletions
51
trunk/src/rtmp/srs_protocol_msg_array.cpp
Normal file
51
trunk/src/rtmp/srs_protocol_msg_array.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2014 winlin
|
||||
|
||||
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_msg_array.hpp>
|
||||
|
||||
#include <srs_protocol_rtmp_stack.hpp>
|
||||
|
||||
SrsSharedPtrMessageArray::SrsSharedPtrMessageArray(int _size)
|
||||
{
|
||||
srs_assert(_size > 0);
|
||||
|
||||
msgs = new SrsSharedPtrMessage*[_size];
|
||||
size = _size;
|
||||
|
||||
// initialize
|
||||
for (int i = 0; i < _size; i++) {
|
||||
msgs[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
SrsSharedPtrMessageArray::~SrsSharedPtrMessageArray()
|
||||
{
|
||||
// cleanup
|
||||
for (int i = 0; i < size; i++) {
|
||||
SrsSharedPtrMessage* msg = msgs[i];
|
||||
srs_freep(msg);
|
||||
}
|
||||
|
||||
srs_freep(msgs);
|
||||
}
|
||||
|
53
trunk/src/rtmp/srs_protocol_msg_array.hpp
Normal file
53
trunk/src/rtmp/srs_protocol_msg_array.hpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2014 winlin
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef SRS_RTMP_PROTOCOL_MSG_ARRAY_HPP
|
||||
#define SRS_RTMP_PROTOCOL_MSG_ARRAY_HPP
|
||||
|
||||
/*
|
||||
#include <srs_protocol_msg_array.hpp>
|
||||
*/
|
||||
|
||||
#include <srs_core.hpp>
|
||||
|
||||
class SrsSharedPtrMessage;
|
||||
|
||||
/**
|
||||
* the class to auto free the shared ptr message array.
|
||||
*/
|
||||
class SrsSharedPtrMessageArray
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* when user already send the msg in msgs, please set to NULL,
|
||||
* for instance, msg= msgs.msgs[i], msgs.msgs[i]=NULL, send(msg),
|
||||
* where send(msg) will always send and free it.
|
||||
*/
|
||||
SrsSharedPtrMessage** msgs;
|
||||
int size;
|
||||
public:
|
||||
SrsSharedPtrMessageArray(int _size);
|
||||
virtual ~SrsSharedPtrMessageArray();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -437,13 +437,12 @@ int SrsProtocol::decode_message(SrsMessage* msg, SrsPacket** ppacket)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int SrsProtocol::do_send_and_free_message(SrsMessage* msg, SrsPacket* packet)
|
||||
int SrsProtocol::do_send_message(SrsMessage* msg, SrsPacket* packet)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// always free msg.
|
||||
// always not NULL msg.
|
||||
srs_assert(msg);
|
||||
SrsAutoFree(SrsMessage, msg);
|
||||
|
||||
// we donot use the complex basic header,
|
||||
// ensure the basic header is 1bytes.
|
||||
|
@ -497,7 +496,7 @@ int SrsProtocol::do_send_and_free_message(SrsMessage* msg, SrsPacket* packet)
|
|||
*pheader++ = pp[3];
|
||||
|
||||
// chunk extended timestamp header, 0 or 4 bytes, big-endian
|
||||
if(timestamp >= RTMP_EXTENDED_TIMESTAMP){
|
||||
if(timestamp >= RTMP_EXTENDED_TIMESTAMP) {
|
||||
pp = (char*)×tamp;
|
||||
*pheader++ = pp[3];
|
||||
*pheader++ = pp[2];
|
||||
|
@ -522,7 +521,7 @@ int SrsProtocol::do_send_and_free_message(SrsMessage* msg, SrsPacket* packet)
|
|||
// @see: ngx_rtmp_prepare_message
|
||||
// @see: http://blog.csdn.net/win_lin/article/details/13363699
|
||||
u_int32_t timestamp = (u_int32_t)msg->header.timestamp;
|
||||
if(timestamp >= RTMP_EXTENDED_TIMESTAMP){
|
||||
if (timestamp >= RTMP_EXTENDED_TIMESTAMP) {
|
||||
pp = (char*)×tamp;
|
||||
*pheader++ = pp[3];
|
||||
*pheader++ = pp[2];
|
||||
|
@ -733,7 +732,12 @@ int SrsProtocol::send_and_free_message(SrsMessage* msg, int stream_id)
|
|||
if (msg) {
|
||||
msg->header.stream_id = stream_id;
|
||||
}
|
||||
return do_send_and_free_message(msg, NULL);
|
||||
|
||||
// donot use the auto free to free the msg,
|
||||
// for performance issue.
|
||||
int ret = do_send_message(msg, NULL);
|
||||
srs_freep(msg);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsProtocol::send_and_free_packet(SrsPacket* packet, int stream_id)
|
||||
|
@ -767,9 +771,10 @@ int SrsProtocol::send_and_free_packet(SrsPacket* packet, int stream_id)
|
|||
msg->header.stream_id = stream_id;
|
||||
msg->header.perfer_cid = packet->get_perfer_cid();
|
||||
|
||||
if ((ret = do_send_and_free_message(msg, packet)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
// donot use the auto free to free the msg,
|
||||
// for performance issue.
|
||||
ret = do_send_message(msg, packet);
|
||||
srs_freep(msg);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -174,10 +174,10 @@ public:
|
|||
virtual int send_and_free_packet(SrsPacket* packet, int stream_id);
|
||||
private:
|
||||
/**
|
||||
* imp for send_and_free_message
|
||||
* send out the message, donot free it, the caller must free the param msg.
|
||||
* @param packet the packet of message, NULL for raw message.
|
||||
*/
|
||||
virtual int do_send_and_free_message(SrsMessage* msg, SrsPacket* packet);
|
||||
virtual int do_send_message(SrsMessage* msg, SrsPacket* packet);
|
||||
/**
|
||||
* imp for decode_message
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue