1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Refactor padding

This commit is contained in:
winlin 2020-04-16 11:22:25 +08:00
parent 4dced0b077
commit 34fec09bc0
2 changed files with 7 additions and 6 deletions

View file

@ -941,6 +941,7 @@ srs_error_t SrsRtcSenderThread::send_packets_gso(SrsUdpMuxSocket* skt, SrsRtcPac
for (int i = 0; i < nn_packets; i++) { for (int i = 0; i < nn_packets; i++) {
SrsRtpPacket2* packet = packets.at(i); SrsRtpPacket2* packet = packets.at(i);
int nn_packet = packet->nb_bytes(); int nn_packet = packet->nb_bytes();
int padding = 0;
SrsRtpPacket2* next_packet = NULL; SrsRtpPacket2* next_packet = NULL;
int nn_next_packet = 0; int nn_next_packet = 0;
@ -952,7 +953,7 @@ srs_error_t SrsRtcSenderThread::send_packets_gso(SrsUdpMuxSocket* skt, SrsRtcPac
// Padding the packet to next or GSO size. // Padding the packet to next or GSO size.
if (max_padding > 0 && next_packet) { if (max_padding > 0 && next_packet) {
// Padding to the next packet to merge with it. // Padding to the next packet to merge with it.
int padding = nn_next_packet - nn_packet; padding = nn_next_packet - nn_packet;
if (use_gso) { if (use_gso) {
// If the next one could merge to this GSO stage, padding current to GSO size. // If the next one could merge to this GSO stage, padding current to GSO size.
@ -1080,8 +1081,8 @@ srs_error_t SrsRtcSenderThread::send_packets_gso(SrsUdpMuxSocket* skt, SrsRtcPac
#if defined(SRS_DEBUG) #if defined(SRS_DEBUG)
bool is_video = packet->rtp_header.get_payload_type() == video_payload_type; bool is_video = packet->rtp_header.get_payload_type() == video_payload_type;
srs_trace("#%d, Packet %s SSRC=%d, SN=%d, %d bytes", packets.debug_id, is_video? "Video":"Audio", srs_trace("#%d, Packet %s SSRC=%d, SN=%d, %d/%d bytes", packets.debug_id, is_video? "Video":"Audio",
packet->rtp_header.get_ssrc(), packet->rtp_header.get_sequence(), nn_packet); packet->rtp_header.get_ssrc(), packet->rtp_header.get_sequence(), nn_packet - padding, padding);
if (do_send) { if (do_send) {
for (int j = 0; j < (int)mhdr->msg_hdr.msg_iovlen; j++) { for (int j = 0; j < (int)mhdr->msg_hdr.msg_iovlen; j++) {
iovec* iov = mhdr->msg_hdr.msg_iov + j; iovec* iov = mhdr->msg_hdr.msg_iov + j;
@ -1089,8 +1090,8 @@ srs_error_t SrsRtcSenderThread::send_packets_gso(SrsUdpMuxSocket* skt, SrsRtcPac
if (iov->iov_len <= 0) { if (iov->iov_len <= 0) {
break; break;
} }
srs_trace("#%d, %s #%d/%d/%d, %d bytes, size %d/%d", packets.debug_id, (use_gso? "GSO":"RAW"), j, srs_trace("#%d, %s #%d/%d/%d, %d/%d bytes, size %d/%d", packets.debug_id, (use_gso? "GSO":"RAW"), j,
gso_cursor + 1, mhdr->msg_hdr.msg_iovlen, iov->iov_len, gso_size, gso_encrypt); gso_cursor + 1, mhdr->msg_hdr.msg_iovlen, iov->iov_len, padding, gso_size, gso_encrypt);
} }
} }
#endif #endif

View file

@ -195,7 +195,7 @@ srs_error_t SrsRtpPacket2::encode(SrsBuffer* buf)
return srs_error_wrap(err, "encode payload"); return srs_error_wrap(err, "encode payload");
} }
if (padding) { if (padding > 0) {
if (!buf->require(padding)) { if (!buf->require(padding)) {
return srs_error_new(ERROR_RTC_RTP_MUXER, "requires %d bytes", padding); return srs_error_new(ERROR_RTC_RTP_MUXER, "requires %d bytes", padding);
} }