RTC: Cache the buffer for player

pull/2252/head
winlin 4 years ago
parent 8baf0867a0
commit 2f4fe31337

@ -1605,6 +1605,11 @@ SrsRtcConnection::SrsRtcConnection(SrsRtcServer* s, const SrsContextId& cid)
server_ = s;
transport_ = new SrsSecurityTransport(this);
cache_iov_ = new iovec();
cache_iov_->iov_base = new char[kRtpPacketSize];
cache_iov_->iov_len = kRtpPacketSize;
cache_buffer_ = new SrsBuffer((char*)cache_iov_->iov_base, kRtpPacketSize);
state_ = INIT;
last_stun_time = 0;
session_timeout = 0;
@ -1648,6 +1653,9 @@ SrsRtcConnection::~SrsRtcConnection()
srs_freep(addr);
}
srs_freep(cache_iov_);
srs_freep(cache_buffer_);
srs_freep(transport_);
srs_freep(req);
srs_freep(stat_);
@ -2510,22 +2518,16 @@ srs_error_t SrsRtcConnection::do_send_packets(const std::vector<SrsRtpPacket2*>&
SrsRtpPacket2* pkt = pkts.at(i);
// For this message, select the first iovec.
iovec* iov = new iovec();
SrsAutoFree(iovec, iov);
char* iov_base = new char[kRtpPacketSize];
SrsAutoFreeA(char, iov_base);
iov->iov_base = iov_base;
iovec* iov = cache_iov_;
iov->iov_len = kRtpPacketSize;
cache_buffer_->skip(-1 * cache_buffer_->pos());
// Marshal packet to bytes in iovec.
if (true) {
SrsBuffer stream((char*)iov->iov_base, iov->iov_len);
if ((err = pkt->encode(&stream)) != srs_success) {
if ((err = pkt->encode(cache_buffer_)) != srs_success) {
return srs_error_wrap(err, "encode packet");
}
iov->iov_len = stream.pos();
iov->iov_len = cache_buffer_->pos();
}
// Cipher RTP to SRTP packet.

@ -431,6 +431,9 @@ private:
SrsRtcConnectionStateType state_;
ISrsRtcTransport* transport_;
SrsHourGlass* timer_;
private:
iovec* cache_iov_;
SrsBuffer* cache_buffer_;
private:
// key: stream id
std::map<std::string, SrsRtcPlayStream*> players_;

Loading…
Cancel
Save