mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
refine code for bug #194, use send messages for all msg array.
This commit is contained in:
parent
f11272e3ce
commit
47ed9e33dd
8 changed files with 38 additions and 52 deletions
|
|
@ -25,27 +25,21 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
||||
#include <srs_protocol_stack.hpp>
|
||||
|
||||
SrsMessageArray::SrsMessageArray(int _size)
|
||||
SrsMessageArray::SrsMessageArray(int max_msgs)
|
||||
{
|
||||
srs_assert(_size > 0);
|
||||
srs_assert(max_msgs > 0);
|
||||
|
||||
msgs = new SrsMessage*[_size];
|
||||
size = _size;
|
||||
msgs = new SrsMessage*[max_msgs];
|
||||
max = max_msgs;
|
||||
|
||||
// initialize
|
||||
for (int i = 0; i < _size; i++) {
|
||||
for (int i = 0; i < max_msgs; i++) {
|
||||
msgs[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
SrsMessageArray::~SrsMessageArray()
|
||||
{
|
||||
// cleanup
|
||||
for (int i = 0; i < size; i++) {
|
||||
SrsMessage* msg = msgs[i];
|
||||
srs_freep(msg);
|
||||
}
|
||||
|
||||
srs_freep(msgs);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,9 @@ class SrsMessage;
|
|||
* when need to get some messages, for instance, from Consumer queue,
|
||||
* create a message array, whose msgs can used to accept the msgs,
|
||||
* then send each message and set to NULL.
|
||||
* @remark: when error, the message array will free the msg not sent out.
|
||||
*
|
||||
* @remark: user must free all msgs in array, for the SRS2.0 protocol stack
|
||||
* provides an api to send messages, @see send_and_free_messages
|
||||
*/
|
||||
class SrsMessageArray
|
||||
{
|
||||
|
|
@ -48,12 +50,12 @@ public:
|
|||
* where send(msg) will always send and free it.
|
||||
*/
|
||||
SrsMessage** msgs;
|
||||
int size;
|
||||
int max;
|
||||
public:
|
||||
/**
|
||||
* create msg array, initialize array to NULL ptrs.
|
||||
*/
|
||||
SrsMessageArray(int _size);
|
||||
SrsMessageArray(int max_msgs);
|
||||
/**
|
||||
* free the msgs not sent out(not NULL).
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -371,6 +371,11 @@ int SrsRtmpClient::send_and_free_message(SrsMessage* msg, int stream_id)
|
|||
return protocol->send_and_free_message(msg, stream_id);
|
||||
}
|
||||
|
||||
int SrsRtmpClient::send_and_free_messages(SrsMessage** msgs, int nb_msgs, int stream_id)
|
||||
{
|
||||
return protocol->send_and_free_messages(msgs, nb_msgs, stream_id);
|
||||
}
|
||||
|
||||
int SrsRtmpClient::send_and_free_packet(SrsPacket* packet, int stream_id)
|
||||
{
|
||||
return protocol->send_and_free_packet(packet, stream_id);
|
||||
|
|
|
|||
|
|
@ -222,6 +222,15 @@ public:
|
|||
*/
|
||||
virtual int send_and_free_message(SrsMessage* msg, int stream_id);
|
||||
/**
|
||||
* send the RTMP message and always free it.
|
||||
* user must never free or use the msg after this method,
|
||||
* for it will always free the msg.
|
||||
* @param msgs, the msgs to send out, never be NULL.
|
||||
* @param nb_msgs, the size of msgs to send out.
|
||||
* @param stream_id, the stream id of packet to send over, 0 for control message.
|
||||
*/
|
||||
virtual int send_and_free_messages(SrsMessage** msgs, int nb_msgs, int stream_id);
|
||||
/**
|
||||
* send the RTMP packet and always free it.
|
||||
* user must never free or use the packet after this method,
|
||||
* for it will always free the packet.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue