winlin

fix the bug to support dump packets with count.

@@ -301,8 +301,7 @@ int SrsMessageQueue::dump_packets(int max_count, SrsSharedPtrMessage** pmsgs, in @@ -301,8 +301,7 @@ int SrsMessageQueue::dump_packets(int max_count, SrsSharedPtrMessage** pmsgs, in
301 } 301 }
302 302
303 srs_assert(max_count > 0); 303 srs_assert(max_count > 0);
304 - // when count is 0, dumps all; otherwise, dumps no more than count.  
305 - count = srs_min(max_count, count? count : nb_msgs); 304 + count = srs_min(max_count, nb_msgs);
306 305
307 SrsSharedPtrMessage** omsgs = msgs.data(); 306 SrsSharedPtrMessage** omsgs = msgs.data();
308 for (int i = 0; i < count; i++) { 307 for (int i = 0; i < count; i++) {
@@ -312,7 +311,7 @@ int SrsMessageQueue::dump_packets(int max_count, SrsSharedPtrMessage** pmsgs, in @@ -312,7 +311,7 @@ int SrsMessageQueue::dump_packets(int max_count, SrsSharedPtrMessage** pmsgs, in
312 SrsSharedPtrMessage* last = omsgs[count - 1]; 311 SrsSharedPtrMessage* last = omsgs[count - 1];
313 av_start_time = last->timestamp; 312 av_start_time = last->timestamp;
314 313
315 - if (count >= nb_msgs) { 314 + if (count >= (int)msgs.size()) {
316 // the pmsgs is big enough and clear msgs at most time. 315 // the pmsgs is big enough and clear msgs at most time.
317 msgs.clear(); 316 msgs.clear();
318 } else { 317 } else {
@@ -502,8 +501,16 @@ int SrsConsumer::dump_packets(SrsMessageArray* msgs, int& count) @@ -502,8 +501,16 @@ int SrsConsumer::dump_packets(SrsMessageArray* msgs, int& count)
502 { 501 {
503 int ret =ERROR_SUCCESS; 502 int ret =ERROR_SUCCESS;
504 503
  504 + srs_assert(count >= 0);
505 srs_assert(msgs->max > 0); 505 srs_assert(msgs->max > 0);
506 506
  507 + // the count used as input to reset the max if positive.
  508 + int max = count? srs_min(count, msgs->max) : msgs->max;
  509 +
  510 + // the count specifies the max acceptable count,
  511 + // here maybe 1+, and we must set to 0 when got nothing.
  512 + count = 0;
  513 +
507 if (should_update_source_id) { 514 if (should_update_source_id) {
508 srs_trace("update source_id=%d[%d]", source->source_id(), source->source_id()); 515 srs_trace("update source_id=%d[%d]", source->source_id(), source->source_id());
509 should_update_source_id = false; 516 should_update_source_id = false;
@@ -515,7 +522,7 @@ int SrsConsumer::dump_packets(SrsMessageArray* msgs, int& count) @@ -515,7 +522,7 @@ int SrsConsumer::dump_packets(SrsMessageArray* msgs, int& count)
515 } 522 }
516 523
517 // pump msgs from queue. 524 // pump msgs from queue.
518 - if ((ret = queue->dump_packets(msgs->max, msgs->msgs, count)) != ERROR_SUCCESS) { 525 + if ((ret = queue->dump_packets(max, msgs->msgs, count)) != ERROR_SUCCESS) {
519 return ret; 526 return ret;
520 } 527 }
521 528
@@ -175,9 +175,8 @@ public: @@ -175,9 +175,8 @@ public:
175 /** 175 /**
176 * get packets in consumer queue. 176 * get packets in consumer queue.
177 * @pmsgs SrsSharedPtrMessage*[], used to store the msgs, user must alloc it. 177 * @pmsgs SrsSharedPtrMessage*[], used to store the msgs, user must alloc it.
178 - * @count the count in array, input and output param. 178 + * @count the count in array, output param.
179 * @max_count the max count to dequeue, must be positive. 179 * @max_count the max count to dequeue, must be positive.
180 - * @remark user can specifies the count to get specified msgs; 0 to get all if possible.  
181 */ 180 */
182 virtual int dump_packets(int max_count, SrsSharedPtrMessage** pmsgs, int& count); 181 virtual int dump_packets(int max_count, SrsSharedPtrMessage** pmsgs, int& count);
183 /** 182 /**