mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix the bug to support dump packets with count.
This commit is contained in:
parent
a0a89a8ca6
commit
3b0b2e0b85
2 changed files with 12 additions and 6 deletions
|
@ -301,8 +301,7 @@ int SrsMessageQueue::dump_packets(int max_count, SrsSharedPtrMessage** pmsgs, in
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_assert(max_count > 0);
|
srs_assert(max_count > 0);
|
||||||
// when count is 0, dumps all; otherwise, dumps no more than count.
|
count = srs_min(max_count, nb_msgs);
|
||||||
count = srs_min(max_count, count? count : nb_msgs);
|
|
||||||
|
|
||||||
SrsSharedPtrMessage** omsgs = msgs.data();
|
SrsSharedPtrMessage** omsgs = msgs.data();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
|
@ -312,7 +311,7 @@ int SrsMessageQueue::dump_packets(int max_count, SrsSharedPtrMessage** pmsgs, in
|
||||||
SrsSharedPtrMessage* last = omsgs[count - 1];
|
SrsSharedPtrMessage* last = omsgs[count - 1];
|
||||||
av_start_time = last->timestamp;
|
av_start_time = last->timestamp;
|
||||||
|
|
||||||
if (count >= nb_msgs) {
|
if (count >= (int)msgs.size()) {
|
||||||
// the pmsgs is big enough and clear msgs at most time.
|
// the pmsgs is big enough and clear msgs at most time.
|
||||||
msgs.clear();
|
msgs.clear();
|
||||||
} else {
|
} else {
|
||||||
|
@ -502,8 +501,16 @@ int SrsConsumer::dump_packets(SrsMessageArray* msgs, int& count)
|
||||||
{
|
{
|
||||||
int ret =ERROR_SUCCESS;
|
int ret =ERROR_SUCCESS;
|
||||||
|
|
||||||
|
srs_assert(count >= 0);
|
||||||
srs_assert(msgs->max > 0);
|
srs_assert(msgs->max > 0);
|
||||||
|
|
||||||
|
// the count used as input to reset the max if positive.
|
||||||
|
int max = count? srs_min(count, msgs->max) : msgs->max;
|
||||||
|
|
||||||
|
// the count specifies the max acceptable count,
|
||||||
|
// here maybe 1+, and we must set to 0 when got nothing.
|
||||||
|
count = 0;
|
||||||
|
|
||||||
if (should_update_source_id) {
|
if (should_update_source_id) {
|
||||||
srs_trace("update source_id=%d[%d]", source->source_id(), source->source_id());
|
srs_trace("update source_id=%d[%d]", source->source_id(), source->source_id());
|
||||||
should_update_source_id = false;
|
should_update_source_id = false;
|
||||||
|
@ -515,7 +522,7 @@ int SrsConsumer::dump_packets(SrsMessageArray* msgs, int& count)
|
||||||
}
|
}
|
||||||
|
|
||||||
// pump msgs from queue.
|
// pump msgs from queue.
|
||||||
if ((ret = queue->dump_packets(msgs->max, msgs->msgs, count)) != ERROR_SUCCESS) {
|
if ((ret = queue->dump_packets(max, msgs->msgs, count)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -175,9 +175,8 @@ public:
|
||||||
/**
|
/**
|
||||||
* get packets in consumer queue.
|
* get packets in consumer queue.
|
||||||
* @pmsgs SrsSharedPtrMessage*[], used to store the msgs, user must alloc it.
|
* @pmsgs SrsSharedPtrMessage*[], used to store the msgs, user must alloc it.
|
||||||
* @count the count in array, input and output param.
|
* @count the count in array, output param.
|
||||||
* @max_count the max count to dequeue, must be positive.
|
* @max_count the max count to dequeue, must be positive.
|
||||||
* @remark user can specifies the count to get specified msgs; 0 to get all if possible.
|
|
||||||
*/
|
*/
|
||||||
virtual int dump_packets(int max_count, SrsSharedPtrMessage** pmsgs, int& count);
|
virtual int dump_packets(int max_count, SrsSharedPtrMessage** pmsgs, int& count);
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue