Skip to content

Commit c95a851

Browse files
committed
For #307, padding to next packet or GSO size
1 parent bbdd2d7 commit c95a851

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

trunk/src/app/srs_app_rtc_conn.cpp

+17-7
Original file line numberDiff line numberDiff line change
@@ -882,15 +882,25 @@ srs_error_t SrsRtcSenderThread::send_packets_gso(SrsUdpMuxSocket* skt, SrsRtcPac
882882
nn_next_packet = next_packet? next_packet->nb_bytes() : 0;
883883
}
884884

885-
// Padding the first packet if size is similar to the next one.
886-
if (i == 0 && max_padding > 0 && next_packet && nn_packet < nn_next_packet && nn_next_packet - nn_packet < max_padding) {
885+
// Padding the packet to next or GSO size.
886+
if (max_padding > 0 && next_packet) {
887+
// Padding to the next packet to merge with it.
888+
int padding = nn_next_packet - nn_packet;
889+
890+
// If the next one could merge to this GSO stage, padding current to GSO size.
891+
if (use_gso && nn_next_packet < gso_size) {
892+
padding = gso_size - nn_packet;
893+
}
894+
895+
if (padding > 0 && padding < max_padding) {
887896
#if defined(SRS_DEBUG)
888-
srs_trace("Padding %d bytes %d=>%d, packets %d, max_padding %d", nn_next_packet - nn_packet,
889-
nn_packet, nn_next_packet, nn_packets, max_padding);
897+
srs_trace("Padding %d bytes %d=>%d, packets %d, max_padding %d", padding, nn_packet + padding,
898+
nn_next_packet, nn_packets, max_padding);
890899
#endif
891-
packet->set_padding(nn_next_packet - nn_packet);
892-
nn_packet = nn_next_packet;
893-
packets.nn_paddings++;
900+
packet->set_padding(padding);
901+
nn_packet += padding;
902+
packets.nn_paddings++;
903+
}
894904
}
895905

896906
// Check whether we can use GSO to send it.

0 commit comments

Comments
 (0)