正在显示
3 个修改的文件
包含
48 行增加
和
43 行删除
| @@ -52,22 +52,16 @@ SrsForwarder::SrsForwarder(SrsSource* _source) | @@ -52,22 +52,16 @@ SrsForwarder::SrsForwarder(SrsSource* _source) | ||
| 52 | 52 | ||
| 53 | pthread = new SrsThread(this, SRS_FORWARDER_SLEEP_MS); | 53 | pthread = new SrsThread(this, SRS_FORWARDER_SLEEP_MS); |
| 54 | queue = new SrsMessageQueue(); | 54 | queue = new SrsMessageQueue(); |
| 55 | + jitter = new SrsRtmpJitter(); | ||
| 55 | } | 56 | } |
| 56 | 57 | ||
| 57 | SrsForwarder::~SrsForwarder() | 58 | SrsForwarder::~SrsForwarder() |
| 58 | { | 59 | { |
| 59 | on_unpublish(); | 60 | on_unpublish(); |
| 60 | 61 | ||
| 61 | - // TODO: FIXME: remove it. | ||
| 62 | - std::vector<SrsSharedPtrMessage*>::iterator it; | ||
| 63 | - for (it = msgs.begin(); it != msgs.end(); ++it) { | ||
| 64 | - SrsSharedPtrMessage* msg = *it; | ||
| 65 | - srs_freep(msg); | ||
| 66 | - } | ||
| 67 | - msgs.clear(); | ||
| 68 | - | ||
| 69 | srs_freep(pthread); | 62 | srs_freep(pthread); |
| 70 | srs_freep(queue); | 63 | srs_freep(queue); |
| 64 | + srs_freep(jitter); | ||
| 71 | } | 65 | } |
| 72 | 66 | ||
| 73 | void SrsForwarder::set_queue_size(double queue_size) | 67 | void SrsForwarder::set_queue_size(double queue_size) |
| @@ -143,7 +137,14 @@ int SrsForwarder::on_meta_data(SrsSharedPtrMessage* metadata) | @@ -143,7 +137,14 @@ int SrsForwarder::on_meta_data(SrsSharedPtrMessage* metadata) | ||
| 143 | { | 137 | { |
| 144 | int ret = ERROR_SUCCESS; | 138 | int ret = ERROR_SUCCESS; |
| 145 | 139 | ||
| 146 | - msgs.push_back(metadata); | 140 | + if ((ret = jitter->correct(metadata, 0, 0)) != ERROR_SUCCESS) { |
| 141 | + srs_freep(msg); | ||
| 142 | + return ret; | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + if ((ret = queue->enqueue(metadata)) != ERROR_SUCCESS) { | ||
| 146 | + return ret; | ||
| 147 | + } | ||
| 147 | 148 | ||
| 148 | return ret; | 149 | return ret; |
| 149 | } | 150 | } |
| @@ -152,8 +153,14 @@ int SrsForwarder::on_audio(SrsSharedPtrMessage* msg) | @@ -152,8 +153,14 @@ int SrsForwarder::on_audio(SrsSharedPtrMessage* msg) | ||
| 152 | { | 153 | { |
| 153 | int ret = ERROR_SUCCESS; | 154 | int ret = ERROR_SUCCESS; |
| 154 | 155 | ||
| 155 | - // TODO: FIXME: must drop the msgs when server failed. | ||
| 156 | - msgs.push_back(msg); | 156 | + if ((ret = jitter->correct(msg, 0, 0)) != ERROR_SUCCESS) { |
| 157 | + srs_freep(msg); | ||
| 158 | + return ret; | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + if ((ret = queue->enqueue(msg)) != ERROR_SUCCESS) { | ||
| 162 | + return ret; | ||
| 163 | + } | ||
| 157 | 164 | ||
| 158 | return ret; | 165 | return ret; |
| 159 | } | 166 | } |
| @@ -162,8 +169,14 @@ int SrsForwarder::on_video(SrsSharedPtrMessage* msg) | @@ -162,8 +169,14 @@ int SrsForwarder::on_video(SrsSharedPtrMessage* msg) | ||
| 162 | { | 169 | { |
| 163 | int ret = ERROR_SUCCESS; | 170 | int ret = ERROR_SUCCESS; |
| 164 | 171 | ||
| 165 | - // TODO: FIXME: must drop the msgs when server failed. | ||
| 166 | - msgs.push_back(msg); | 172 | + if ((ret = jitter->correct(msg, 0, 0)) != ERROR_SUCCESS) { |
| 173 | + srs_freep(msg); | ||
| 174 | + return ret; | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + if ((ret = queue->enqueue(msg)) != ERROR_SUCCESS) { | ||
| 178 | + return ret; | ||
| 179 | + } | ||
| 167 | 180 | ||
| 168 | return ret; | 181 | return ret; |
| 169 | } | 182 | } |
| @@ -292,11 +305,20 @@ int SrsForwarder::forward() | @@ -292,11 +305,20 @@ int SrsForwarder::forward() | ||
| 292 | } | 305 | } |
| 293 | } | 306 | } |
| 294 | 307 | ||
| 308 | + // forward all messages. | ||
| 309 | + int count = 0; | ||
| 310 | + SrsSharedPtrMessage** msgs = NULL; | ||
| 311 | + if ((ret = queue->get_packets(0, &msgs, count)) != ERROR_SUCCESS) { | ||
| 312 | + srs_error("get message to forward failed. ret=%d", ret); | ||
| 313 | + return ret; | ||
| 314 | + } | ||
| 315 | + | ||
| 295 | // ignore when no messages. | 316 | // ignore when no messages. |
| 296 | - int count = (int)msgs.size(); | ||
| 297 | - if (msgs.empty()) { | 317 | + if (count <= 0) { |
| 318 | + srs_verbose("no packets to forward."); | ||
| 298 | continue; | 319 | continue; |
| 299 | } | 320 | } |
| 321 | + SrsAutoFree(SrsSharedPtrMessage*, msgs, true); | ||
| 300 | 322 | ||
| 301 | // pithy print | 323 | // pithy print |
| 302 | pithy_print.elapse(SRS_PULSE_TIMEOUT_MS); | 324 | pithy_print.elapse(SRS_PULSE_TIMEOUT_MS); |
| @@ -306,36 +328,17 @@ int SrsForwarder::forward() | @@ -306,36 +328,17 @@ int SrsForwarder::forward() | ||
| 306 | } | 328 | } |
| 307 | 329 | ||
| 308 | // all msgs to forward. | 330 | // all msgs to forward. |
| 309 | - int i = 0; | ||
| 310 | - for (i = 0; i < count; i++) { | 331 | + for (int i = 0; i < count; i++) { |
| 311 | SrsSharedPtrMessage* msg = msgs[i]; | 332 | SrsSharedPtrMessage* msg = msgs[i]; |
| 312 | - msgs[i] = NULL; | ||
| 313 | - | ||
| 314 | - // we erased the sendout messages, the msg must not be NULL. | 333 | + |
| 315 | srs_assert(msg); | 334 | srs_assert(msg); |
| 335 | + msgs[i] = NULL; | ||
| 316 | 336 | ||
| 317 | - ret = client->send_message(msg); | ||
| 318 | - if (ret != ERROR_SUCCESS) { | 337 | + if ((ret = client->send_message(msg)) != ERROR_SUCCESS) { |
| 319 | srs_error("forwarder send message to server failed. ret=%d", ret); | 338 | srs_error("forwarder send message to server failed. ret=%d", ret); |
| 320 | - | ||
| 321 | - // convert the index to count when error. | ||
| 322 | - i++; | ||
| 323 | - | ||
| 324 | - break; | 339 | + return ret; |
| 325 | } | 340 | } |
| 326 | } | 341 | } |
| 327 | - | ||
| 328 | - // clear sendout mesages. | ||
| 329 | - if (i < count) { | ||
| 330 | - srs_warn("clear forwarded msg, total=%d, forwarded=%d, ret=%d", count, i, ret); | ||
| 331 | - } else { | ||
| 332 | - srs_info("clear forwarded msg, total=%d, forwarded=%d, ret=%d", count, i, ret); | ||
| 333 | - } | ||
| 334 | - msgs.erase(msgs.begin(), msgs.begin() + i); | ||
| 335 | - | ||
| 336 | - if (ret != ERROR_SUCCESS) { | ||
| 337 | - break; | ||
| 338 | - } | ||
| 339 | } | 342 | } |
| 340 | 343 | ||
| 341 | return ret; | 344 | return ret; |
| @@ -30,13 +30,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -30,13 +30,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 30 | #include <srs_core.hpp> | 30 | #include <srs_core.hpp> |
| 31 | 31 | ||
| 32 | #include <string> | 32 | #include <string> |
| 33 | -#include <vector> | ||
| 34 | 33 | ||
| 35 | #include <srs_core_thread.hpp> | 34 | #include <srs_core_thread.hpp> |
| 36 | 35 | ||
| 37 | class SrsSharedPtrMessage; | 36 | class SrsSharedPtrMessage; |
| 38 | class SrsOnMetaDataPacket; | 37 | class SrsOnMetaDataPacket; |
| 39 | class SrsMessageQueue; | 38 | class SrsMessageQueue; |
| 39 | +class SrsRtmpJitter; | ||
| 40 | class SrsRtmpClient; | 40 | class SrsRtmpClient; |
| 41 | class SrsRequest; | 41 | class SrsRequest; |
| 42 | class SrsSource; | 42 | class SrsSource; |
| @@ -59,8 +59,8 @@ private: | @@ -59,8 +59,8 @@ private: | ||
| 59 | private: | 59 | private: |
| 60 | SrsSource* source; | 60 | SrsSource* source; |
| 61 | SrsRtmpClient* client; | 61 | SrsRtmpClient* client; |
| 62 | + SrsRtmpJitter* jitter; | ||
| 62 | SrsMessageQueue* queue; | 63 | SrsMessageQueue* queue; |
| 63 | - std::vector<SrsSharedPtrMessage*> msgs; | ||
| 64 | public: | 64 | public: |
| 65 | SrsForwarder(SrsSource* _source); | 65 | SrsForwarder(SrsSource* _source); |
| 66 | virtual ~SrsForwarder(); | 66 | virtual ~SrsForwarder(); |
| @@ -101,7 +101,10 @@ public: | @@ -101,7 +101,10 @@ public: | ||
| 101 | */ | 101 | */ |
| 102 | virtual int enqueue(SrsSharedPtrMessage* msg); | 102 | virtual int enqueue(SrsSharedPtrMessage* msg); |
| 103 | /** | 103 | /** |
| 104 | - * get messages from the queue. | 104 | + * get packets in consumer queue. |
| 105 | + * @pmsgs SrsMessages*[], output the prt array. | ||
| 106 | + * @count the count in array. | ||
| 107 | + * @max_count the max count to dequeue, 0 to dequeue all. | ||
| 105 | */ | 108 | */ |
| 106 | virtual int get_packets(int max_count, SrsSharedPtrMessage**& pmsgs, int& count); | 109 | virtual int get_packets(int max_count, SrsSharedPtrMessage**& pmsgs, int& count); |
| 107 | private: | 110 | private: |
| @@ -122,7 +125,6 @@ private: | @@ -122,7 +125,6 @@ private: | ||
| 122 | SrsRtmpJitter* jitter; | 125 | SrsRtmpJitter* jitter; |
| 123 | SrsSource* source; | 126 | SrsSource* source; |
| 124 | SrsMessageQueue* queue; | 127 | SrsMessageQueue* queue; |
| 125 | - std::vector<SrsSharedPtrMessage*> msgs; | ||
| 126 | bool paused; | 128 | bool paused; |
| 127 | public: | 129 | public: |
| 128 | SrsConsumer(SrsSource* _source); | 130 | SrsConsumer(SrsSource* _source); |
-
请 注册 或 登录 后发表评论