refine code for bug #194, use send messages for all msg array.
正在显示
8 个修改的文件
包含
38 行增加
和
52 行删除
| @@ -499,7 +499,7 @@ int SrsEdgeForwarder::cycle() | @@ -499,7 +499,7 @@ int SrsEdgeForwarder::cycle() | ||
| 499 | 499 | ||
| 500 | // forward all messages. | 500 | // forward all messages. |
| 501 | int count = 0; | 501 | int count = 0; |
| 502 | - if ((ret = queue->dump_packets(msgs.size, msgs.msgs, count)) != ERROR_SUCCESS) { | 502 | + if ((ret = queue->dump_packets(msgs.max, msgs.msgs, count)) != ERROR_SUCCESS) { |
| 503 | srs_error("get message to push to origin failed. ret=%d", ret); | 503 | srs_error("get message to push to origin failed. ret=%d", ret); |
| 504 | return ret; | 504 | return ret; |
| 505 | } | 505 | } |
| @@ -523,18 +523,9 @@ int SrsEdgeForwarder::cycle() | @@ -523,18 +523,9 @@ int SrsEdgeForwarder::cycle() | ||
| 523 | } | 523 | } |
| 524 | 524 | ||
| 525 | // all msgs to forward to origin. | 525 | // all msgs to forward to origin. |
| 526 | - // @remark, becareful, all msgs must be free explicitly, | ||
| 527 | - // free by send_and_free_message or srs_freep. | ||
| 528 | - for (int i = 0; i < count; i++) { | ||
| 529 | - SrsMessage* msg = msgs.msgs[i]; | ||
| 530 | - | ||
| 531 | - srs_assert(msg); | ||
| 532 | - msgs.msgs[i] = NULL; | ||
| 533 | - | ||
| 534 | - if ((ret = client->send_and_free_message(msg, stream_id)) != ERROR_SUCCESS) { | ||
| 535 | - srs_error("edge publish push message to server failed. ret=%d", ret); | ||
| 536 | - return ret; | ||
| 537 | - } | 526 | + if ((ret = client->send_and_free_messages(msgs.msgs, count, stream_id)) != ERROR_SUCCESS) { |
| 527 | + srs_error("edge publish push message to server failed. ret=%d", ret); | ||
| 528 | + return ret; | ||
| 538 | } | 529 | } |
| 539 | } | 530 | } |
| 540 | 531 |
| @@ -417,7 +417,7 @@ int SrsForwarder::forward() | @@ -417,7 +417,7 @@ int SrsForwarder::forward() | ||
| 417 | 417 | ||
| 418 | // forward all messages. | 418 | // forward all messages. |
| 419 | int count = 0; | 419 | int count = 0; |
| 420 | - if ((ret = queue->dump_packets(msgs.size, msgs.msgs, count)) != ERROR_SUCCESS) { | 420 | + if ((ret = queue->dump_packets(msgs.max, msgs.msgs, count)) != ERROR_SUCCESS) { |
| 421 | srs_error("get message to forward failed. ret=%d", ret); | 421 | srs_error("get message to forward failed. ret=%d", ret); |
| 422 | return ret; | 422 | return ret; |
| 423 | } | 423 | } |
| @@ -439,18 +439,9 @@ int SrsForwarder::forward() | @@ -439,18 +439,9 @@ int SrsForwarder::forward() | ||
| 439 | } | 439 | } |
| 440 | 440 | ||
| 441 | // all msgs to forward. | 441 | // all msgs to forward. |
| 442 | - // @remark, becareful, all msgs must be free explicitly, | ||
| 443 | - // free by send_and_free_message or srs_freep. | ||
| 444 | - for (int i = 0; i < count; i++) { | ||
| 445 | - SrsMessage* msg = msgs.msgs[i]; | ||
| 446 | - | ||
| 447 | - srs_assert(msg); | ||
| 448 | - msgs.msgs[i] = NULL; | ||
| 449 | - | ||
| 450 | - if ((ret = client->send_and_free_message(msg, stream_id)) != ERROR_SUCCESS) { | ||
| 451 | - srs_error("forwarder send message to server failed. ret=%d", ret); | ||
| 452 | - return ret; | ||
| 453 | - } | 442 | + if ((ret = client->send_and_free_messages(msgs.msgs, count, stream_id)) != ERROR_SUCCESS) { |
| 443 | + srs_error("forwarder messages to server failed. ret=%d", ret); | ||
| 444 | + return ret; | ||
| 454 | } | 445 | } |
| 455 | } | 446 | } |
| 456 | 447 |
| @@ -559,7 +559,7 @@ int SrsRtmpConn::playing(SrsSource* source) | @@ -559,7 +559,7 @@ int SrsRtmpConn::playing(SrsSource* source) | ||
| 559 | 559 | ||
| 560 | // get messages from consumer. | 560 | // get messages from consumer. |
| 561 | int count = 0; | 561 | int count = 0; |
| 562 | - if ((ret = consumer->dump_packets(msgs.size, msgs.msgs, count)) != ERROR_SUCCESS) { | 562 | + if ((ret = consumer->dump_packets(msgs.max, msgs.msgs, count)) != ERROR_SUCCESS) { |
| 563 | srs_error("get messages from consumer failed. ret=%d", ret); | 563 | srs_error("get messages from consumer failed. ret=%d", ret); |
| 564 | return ret; | 564 | return ret; |
| 565 | } | 565 | } |
| @@ -596,16 +596,10 @@ int SrsRtmpConn::playing(SrsSource* source) | @@ -596,16 +596,10 @@ int SrsRtmpConn::playing(SrsSource* source) | ||
| 596 | // free by send_and_free_message or srs_freep. | 596 | // free by send_and_free_message or srs_freep. |
| 597 | if (count > 0) { | 597 | if (count > 0) { |
| 598 | // no need to assert msg, for the rtmp will assert it. | 598 | // no need to assert msg, for the rtmp will assert it. |
| 599 | - ret = rtmp->send_and_free_messages(msgs.msgs, count, res->stream_id); | ||
| 600 | - } | ||
| 601 | - for (int i = 0; i < count; i++) { | ||
| 602 | - // the send_message will free the msg, | ||
| 603 | - // so set the msgs[i] to NULL. | ||
| 604 | - msgs.msgs[i] = NULL; | ||
| 605 | - } | ||
| 606 | - if (ret != ERROR_SUCCESS) { | ||
| 607 | - srs_error("send messages to client failed. ret=%d", ret); | ||
| 608 | - return ret; | 599 | + if ((ret = rtmp->send_and_free_messages(msgs.msgs, count, res->stream_id)) != ERROR_SUCCESS) { |
| 600 | + srs_error("send messages to client failed. ret=%d", ret); | ||
| 601 | + return ret; | ||
| 602 | + } | ||
| 609 | } | 603 | } |
| 610 | 604 | ||
| 611 | // if duration specified, and exceed it, stop play live. | 605 | // if duration specified, and exceed it, stop play live. |
| @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | // current release version | 31 | // current release version |
| 32 | #define VERSION_MAJOR 2 | 32 | #define VERSION_MAJOR 2 |
| 33 | #define VERSION_MINOR 0 | 33 | #define VERSION_MINOR 0 |
| 34 | -#define VERSION_REVISION 17 | 34 | +#define VERSION_REVISION 18 |
| 35 | // server info. | 35 | // server info. |
| 36 | #define RTMP_SIG_SRS_KEY "SRS" | 36 | #define RTMP_SIG_SRS_KEY "SRS" |
| 37 | #define RTMP_SIG_SRS_ROLE "origin/edge server" | 37 | #define RTMP_SIG_SRS_ROLE "origin/edge server" |
| @@ -25,27 +25,21 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -25,27 +25,21 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 25 | 25 | ||
| 26 | #include <srs_protocol_stack.hpp> | 26 | #include <srs_protocol_stack.hpp> |
| 27 | 27 | ||
| 28 | -SrsMessageArray::SrsMessageArray(int _size) | 28 | +SrsMessageArray::SrsMessageArray(int max_msgs) |
| 29 | { | 29 | { |
| 30 | - srs_assert(_size > 0); | 30 | + srs_assert(max_msgs > 0); |
| 31 | 31 | ||
| 32 | - msgs = new SrsMessage*[_size]; | ||
| 33 | - size = _size; | 32 | + msgs = new SrsMessage*[max_msgs]; |
| 33 | + max = max_msgs; | ||
| 34 | 34 | ||
| 35 | // initialize | 35 | // initialize |
| 36 | - for (int i = 0; i < _size; i++) { | 36 | + for (int i = 0; i < max_msgs; i++) { |
| 37 | msgs[i] = NULL; | 37 | msgs[i] = NULL; |
| 38 | } | 38 | } |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | SrsMessageArray::~SrsMessageArray() | 41 | SrsMessageArray::~SrsMessageArray() |
| 42 | { | 42 | { |
| 43 | - // cleanup | ||
| 44 | - for (int i = 0; i < size; i++) { | ||
| 45 | - SrsMessage* msg = msgs[i]; | ||
| 46 | - srs_freep(msg); | ||
| 47 | - } | ||
| 48 | - | ||
| 49 | srs_freep(msgs); | 43 | srs_freep(msgs); |
| 50 | } | 44 | } |
| 51 | 45 |
| @@ -37,7 +37,9 @@ class SrsMessage; | @@ -37,7 +37,9 @@ class SrsMessage; | ||
| 37 | * when need to get some messages, for instance, from Consumer queue, | 37 | * when need to get some messages, for instance, from Consumer queue, |
| 38 | * create a message array, whose msgs can used to accept the msgs, | 38 | * create a message array, whose msgs can used to accept the msgs, |
| 39 | * then send each message and set to NULL. | 39 | * then send each message and set to NULL. |
| 40 | -* @remark: when error, the message array will free the msg not sent out. | 40 | +* |
| 41 | +* @remark: user must free all msgs in array, for the SRS2.0 protocol stack | ||
| 42 | +* provides an api to send messages, @see send_and_free_messages | ||
| 41 | */ | 43 | */ |
| 42 | class SrsMessageArray | 44 | class SrsMessageArray |
| 43 | { | 45 | { |
| @@ -48,12 +50,12 @@ public: | @@ -48,12 +50,12 @@ public: | ||
| 48 | * where send(msg) will always send and free it. | 50 | * where send(msg) will always send and free it. |
| 49 | */ | 51 | */ |
| 50 | SrsMessage** msgs; | 52 | SrsMessage** msgs; |
| 51 | - int size; | 53 | + int max; |
| 52 | public: | 54 | public: |
| 53 | /** | 55 | /** |
| 54 | * create msg array, initialize array to NULL ptrs. | 56 | * create msg array, initialize array to NULL ptrs. |
| 55 | */ | 57 | */ |
| 56 | - SrsMessageArray(int _size); | 58 | + SrsMessageArray(int max_msgs); |
| 57 | /** | 59 | /** |
| 58 | * free the msgs not sent out(not NULL). | 60 | * free the msgs not sent out(not NULL). |
| 59 | */ | 61 | */ |
| @@ -371,6 +371,11 @@ int SrsRtmpClient::send_and_free_message(SrsMessage* msg, int stream_id) | @@ -371,6 +371,11 @@ int SrsRtmpClient::send_and_free_message(SrsMessage* msg, int stream_id) | ||
| 371 | return protocol->send_and_free_message(msg, stream_id); | 371 | return protocol->send_and_free_message(msg, stream_id); |
| 372 | } | 372 | } |
| 373 | 373 | ||
| 374 | +int SrsRtmpClient::send_and_free_messages(SrsMessage** msgs, int nb_msgs, int stream_id) | ||
| 375 | +{ | ||
| 376 | + return protocol->send_and_free_messages(msgs, nb_msgs, stream_id); | ||
| 377 | +} | ||
| 378 | + | ||
| 374 | int SrsRtmpClient::send_and_free_packet(SrsPacket* packet, int stream_id) | 379 | int SrsRtmpClient::send_and_free_packet(SrsPacket* packet, int stream_id) |
| 375 | { | 380 | { |
| 376 | return protocol->send_and_free_packet(packet, stream_id); | 381 | return protocol->send_and_free_packet(packet, stream_id); |
| @@ -222,6 +222,15 @@ public: | @@ -222,6 +222,15 @@ public: | ||
| 222 | */ | 222 | */ |
| 223 | virtual int send_and_free_message(SrsMessage* msg, int stream_id); | 223 | virtual int send_and_free_message(SrsMessage* msg, int stream_id); |
| 224 | /** | 224 | /** |
| 225 | + * send the RTMP message and always free it. | ||
| 226 | + * user must never free or use the msg after this method, | ||
| 227 | + * for it will always free the msg. | ||
| 228 | + * @param msgs, the msgs to send out, never be NULL. | ||
| 229 | + * @param nb_msgs, the size of msgs to send out. | ||
| 230 | + * @param stream_id, the stream id of packet to send over, 0 for control message. | ||
| 231 | + */ | ||
| 232 | + virtual int send_and_free_messages(SrsMessage** msgs, int nb_msgs, int stream_id); | ||
| 233 | + /** | ||
| 225 | * send the RTMP packet and always free it. | 234 | * send the RTMP packet and always free it. |
| 226 | * user must never free or use the packet after this method, | 235 | * user must never free or use the packet after this method, |
| 227 | * for it will always free the packet. | 236 | * for it will always free the packet. |
-
请 注册 或 登录 后发表评论