@@ -882,15 +882,25 @@ srs_error_t SrsRtcSenderThread::send_packets_gso(SrsUdpMuxSocket* skt, SrsRtcPac
882
882
nn_next_packet = next_packet? next_packet->nb_bytes () : 0 ;
883
883
}
884
884
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) {
887
896
#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);
890
899
#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
+ }
894
904
}
895
905
896
906
// Check whether we can use GSO to send it.
0 commit comments