mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
for bug #251, add queue fast vector. 2.0.66
This commit is contained in:
parent
8f72f79504
commit
5a2b8afead
4 changed files with 131 additions and 3 deletions
|
@ -156,6 +156,93 @@ int SrsRtmpJitter::get_time()
|
||||||
return (int)last_pkt_correct_time;
|
return (int)last_pkt_correct_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SRS_PERF_QUEUE_FAST_VECTOR
|
||||||
|
SrsFastVector::SrsFastVector()
|
||||||
|
{
|
||||||
|
count = 0;
|
||||||
|
nb_msgs = SRS_PERF_MW_MSGS * 2;
|
||||||
|
msgs = new SrsSharedPtrMessage*[nb_msgs];
|
||||||
|
}
|
||||||
|
|
||||||
|
SrsFastVector::~SrsFastVector()
|
||||||
|
{
|
||||||
|
free();
|
||||||
|
}
|
||||||
|
|
||||||
|
int SrsFastVector::size()
|
||||||
|
{
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SrsFastVector::begin()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SrsFastVector::end()
|
||||||
|
{
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
SrsSharedPtrMessage** SrsFastVector::data()
|
||||||
|
{
|
||||||
|
return msgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
SrsSharedPtrMessage* SrsFastVector::at(int index)
|
||||||
|
{
|
||||||
|
srs_assert(index < count);
|
||||||
|
return msgs[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
void SrsFastVector::clear()
|
||||||
|
{
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SrsFastVector::erase(int _begin, int _end)
|
||||||
|
{
|
||||||
|
srs_assert(_begin < _end);
|
||||||
|
|
||||||
|
// move all erased to previous.
|
||||||
|
for (int i = 0; i < count - _end; i++) {
|
||||||
|
msgs[_begin + i] = msgs[_end + i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// update the count.
|
||||||
|
count -= _end - _begin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SrsFastVector::push_back(SrsSharedPtrMessage* msg)
|
||||||
|
{
|
||||||
|
// increase vector.
|
||||||
|
if (count >= nb_msgs) {
|
||||||
|
int size = nb_msgs * 2;
|
||||||
|
SrsSharedPtrMessage** buf = new SrsSharedPtrMessage*[size];
|
||||||
|
for (int i = 0; i < nb_msgs; i++) {
|
||||||
|
buf[i] = msgs[i];
|
||||||
|
}
|
||||||
|
srs_warn("fast vector incrase %d=>%d", nb_msgs, size);
|
||||||
|
|
||||||
|
// use new array.
|
||||||
|
srs_freep(msgs);
|
||||||
|
msgs = buf;
|
||||||
|
nb_msgs = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
msgs[count++] = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SrsFastVector::free()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
SrsSharedPtrMessage* msg = msgs[i];
|
||||||
|
srs_freep(msg);
|
||||||
|
}
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
SrsMessageQueue::SrsMessageQueue()
|
SrsMessageQueue::SrsMessageQueue()
|
||||||
{
|
{
|
||||||
queue_size_ms = 0;
|
queue_size_ms = 0;
|
||||||
|
@ -251,7 +338,7 @@ void SrsMessageQueue::shrink()
|
||||||
// for when we shrinked, the first is the iframe,
|
// for when we shrinked, the first is the iframe,
|
||||||
// we will directly remove the gop next time.
|
// we will directly remove the gop next time.
|
||||||
for (int i = 1; i < (int)msgs.size(); i++) {
|
for (int i = 1; i < (int)msgs.size(); i++) {
|
||||||
SrsSharedPtrMessage* msg = msgs[i];
|
SrsSharedPtrMessage* msg = msgs.at(i);
|
||||||
|
|
||||||
if (msg->is_video()) {
|
if (msg->is_video()) {
|
||||||
if (SrsFlvCodec::video_is_keyframe(msg->payload, msg->size)) {
|
if (SrsFlvCodec::video_is_keyframe(msg->payload, msg->size)) {
|
||||||
|
@ -281,7 +368,7 @@ void SrsMessageQueue::shrink()
|
||||||
|
|
||||||
// remove the first gop from the front
|
// remove the first gop from the front
|
||||||
for (int i = 0; i < iframe_index; i++) {
|
for (int i = 0; i < iframe_index; i++) {
|
||||||
SrsSharedPtrMessage* msg = msgs[i];
|
SrsSharedPtrMessage* msg = msgs.at(i);
|
||||||
srs_freep(msg);
|
srs_freep(msg);
|
||||||
}
|
}
|
||||||
msgs.erase(msgs.begin(), msgs.begin() + iframe_index);
|
msgs.erase(msgs.begin(), msgs.begin() + iframe_index);
|
||||||
|
@ -289,12 +376,16 @@ void SrsMessageQueue::shrink()
|
||||||
|
|
||||||
void SrsMessageQueue::clear()
|
void SrsMessageQueue::clear()
|
||||||
{
|
{
|
||||||
|
#ifndef SRS_PERF_QUEUE_FAST_VECTOR
|
||||||
std::vector<SrsSharedPtrMessage*>::iterator it;
|
std::vector<SrsSharedPtrMessage*>::iterator it;
|
||||||
|
|
||||||
for (it = msgs.begin(); it != msgs.end(); ++it) {
|
for (it = msgs.begin(); it != msgs.end(); ++it) {
|
||||||
SrsSharedPtrMessage* msg = *it;
|
SrsSharedPtrMessage* msg = *it;
|
||||||
srs_freep(msg);
|
srs_freep(msg);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
msgs.free();
|
||||||
|
#endif
|
||||||
|
|
||||||
msgs.clear();
|
msgs.clear();
|
||||||
|
|
||||||
|
|
|
@ -102,6 +102,34 @@ public:
|
||||||
virtual int get_time();
|
virtual int get_time();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef SRS_PERF_QUEUE_FAST_VECTOR
|
||||||
|
/**
|
||||||
|
* to alloc and increase fixed space,
|
||||||
|
* fast remove and insert for msgs sender.
|
||||||
|
* @see https://github.com/winlinvip/simple-rtmp-server/issues/251
|
||||||
|
*/
|
||||||
|
class SrsFastVector
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
SrsSharedPtrMessage** msgs;
|
||||||
|
int nb_msgs;
|
||||||
|
int count;
|
||||||
|
public:
|
||||||
|
SrsFastVector();
|
||||||
|
virtual ~SrsFastVector();
|
||||||
|
public:
|
||||||
|
virtual int size();
|
||||||
|
virtual int begin();
|
||||||
|
virtual int end();
|
||||||
|
virtual SrsSharedPtrMessage** data();
|
||||||
|
virtual SrsSharedPtrMessage* at(int index);
|
||||||
|
virtual void clear();
|
||||||
|
virtual void erase(int _begin, int _end);
|
||||||
|
virtual void push_back(SrsSharedPtrMessage* msg);
|
||||||
|
virtual void free();
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the message queue for the consumer(client), forwarder.
|
* the message queue for the consumer(client), forwarder.
|
||||||
* we limit the size in seconds, drop old messages(the whole gop) if full.
|
* we limit the size in seconds, drop old messages(the whole gop) if full.
|
||||||
|
@ -112,7 +140,11 @@ private:
|
||||||
int64_t av_start_time;
|
int64_t av_start_time;
|
||||||
int64_t av_end_time;
|
int64_t av_end_time;
|
||||||
int queue_size_ms;
|
int queue_size_ms;
|
||||||
|
#ifdef SRS_PERF_QUEUE_FAST_VECTOR
|
||||||
|
SrsFastVector msgs;
|
||||||
|
#else
|
||||||
std::vector<SrsSharedPtrMessage*> msgs;
|
std::vector<SrsSharedPtrMessage*> msgs;
|
||||||
|
#endif
|
||||||
public:
|
public:
|
||||||
SrsMessageQueue();
|
SrsMessageQueue();
|
||||||
virtual ~SrsMessageQueue();
|
virtual ~SrsMessageQueue();
|
||||||
|
|
|
@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// current release version
|
// current release version
|
||||||
#define VERSION_MAJOR 2
|
#define VERSION_MAJOR 2
|
||||||
#define VERSION_MINOR 0
|
#define VERSION_MINOR 0
|
||||||
#define VERSION_REVISION 65
|
#define VERSION_REVISION 66
|
||||||
// server info.
|
// server info.
|
||||||
#define RTMP_SIG_SRS_KEY "SRS"
|
#define RTMP_SIG_SRS_KEY "SRS"
|
||||||
#define RTMP_SIG_SRS_ROLE "origin/edge server"
|
#define RTMP_SIG_SRS_ROLE "origin/edge server"
|
||||||
|
|
|
@ -135,6 +135,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#undef SRS_PERF_QUEUE_FAST_CACHE
|
#undef SRS_PERF_QUEUE_FAST_CACHE
|
||||||
/**
|
/**
|
||||||
|
* whether enable the fast vector for qeueue.
|
||||||
|
* @see https://github.com/winlinvip/simple-rtmp-server/issues/251
|
||||||
|
*/
|
||||||
|
#undef SRS_PERF_QUEUE_FAST_VECTOR
|
||||||
|
/**
|
||||||
* whether use cond wait to send messages.
|
* whether use cond wait to send messages.
|
||||||
* @remark this improve performance for large connectios.
|
* @remark this improve performance for large connectios.
|
||||||
* @see https://github.com/winlinvip/simple-rtmp-server/issues/251
|
* @see https://github.com/winlinvip/simple-rtmp-server/issues/251
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue