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

For #307, correct the RTP packet stat.

This commit is contained in:
winlin 2020-04-14 20:12:14 +08:00
parent 9d5c855727
commit 8e4ef98629
2 changed files with 27 additions and 7 deletions

View file

@ -654,8 +654,9 @@ srs_error_t SrsRtcSenderThread::cycle()
pprint->elapse();
if (pprint->can_print()) {
// TODO: FIXME: Print stat like frame/s, packet/s, loss_packets.
srs_trace("-> RTC PLAY %d msgs, %d packets, %d audios, %d extras, %d videos, %d samples, %d bytes",
msg_count, pkts.nn_rtp_pkts, pkts.nn_audios, pkts.nn_extras, pkts.nn_videos, pkts.nn_samples, pkts.nn_bytes);
srs_trace("-> RTC PLAY %d msgs, %d/%d packets, %d audios, %d extras, %d videos, %d samples, %d bytes",
msg_count, pkts.packets.size(), pkts.nn_rtp_pkts, pkts.nn_audios, pkts.nn_extras, pkts.nn_videos,
pkts.nn_samples, pkts.nn_bytes);
}
}
}
@ -674,8 +675,6 @@ srs_error_t SrsRtcSenderThread::send_messages(
return srs_error_wrap(err, "messages to packets");
}
packets.nn_rtp_pkts = (int)packets.packets.size();
#ifndef SRS_AUTO_OSX
// If enabled GSO, send out some packets in a msghdr.
if (packets.use_gso) {
@ -820,6 +819,9 @@ srs_error_t SrsRtcSenderThread::send_packets(SrsUdpMuxSocket* skt, SrsRtcPackets
mhdr->msg_hdr.msg_controllen = 0;
mhdr->msg_len = 0;
// When we send out a packet, we commit a RTP packet.
packets.nn_rtp_pkts++;
if ((err = sender->sendmmsg(mhdr)) != srs_success) {
return srs_error_wrap(err, "send msghdr");
}
@ -833,13 +835,12 @@ srs_error_t SrsRtcSenderThread::send_packets_gso(SrsUdpMuxSocket* skt, SrsRtcPac
{
srs_error_t err = srs_success;
ISrsUdpSender* sender = skt->sender();
// Previous handler, if has the same size, we can use GSO.
mmsghdr* gso_mhdr = NULL; int gso_size = 0; int gso_encrypt = 0; int gso_cursor = 0;
// GSO, N packets has same length, the final one may not.
bool use_gso = false; bool gso_final = false;
ISrsUdpSender* sender = skt->sender();
int nn_packets = (int)packets.packets.size();
for (int i = 0; i < nn_packets; i++) {
SrsRtpPacket2* packet = packets.packets[i];
@ -950,7 +951,8 @@ srs_error_t SrsRtcSenderThread::send_packets_gso(SrsUdpMuxSocket* skt, SrsRtcPac
bool do_send = (i == nn_packets - 1 || gso_final || !use_gso);
#if defined(SRS_DEBUG)
srs_trace("packet SSRC=%d, SN=%d, %d bytes", packet->rtp_header.get_ssrc(),
bool is_video = packet->rtp_header.get_payload_type() == video_payload_type;
srs_trace("Packet %s SSRC=%d, SN=%d, %d bytes", is_video? "Video":"Audio", packet->rtp_header.get_ssrc(),
packet->rtp_header.get_sequence(), nn_packet);
if (do_send) {
for (int j = 0; j < (int)mhdr->msg_hdr.msg_iovlen; j++) {
@ -988,6 +990,9 @@ srs_error_t SrsRtcSenderThread::send_packets_gso(SrsUdpMuxSocket* skt, SrsRtcPac
}
#endif
// When we send out a packet, we commit a RTP packet.
packets.nn_rtp_pkts++;
if ((err = sender->sendmmsg(mhdr)) != srs_success) {
return srs_error_wrap(err, "send msghdr");
}
@ -998,6 +1003,11 @@ srs_error_t SrsRtcSenderThread::send_packets_gso(SrsUdpMuxSocket* skt, SrsRtcPac
}
}
#if defined(SRS_DEBUG)
srs_trace("GSO packets, rtp %d/%d, videos %d/%d", packets.packets.size(),
packets.nn_rtp_pkts, packets.nn_videos, packets.nn_samples, packets.nn_audios, packets.nn_extras);
#endif
return err;
}
@ -1816,6 +1826,7 @@ srs_error_t SrsUdpMuxSender::cycle()
mmsghdr* p = &hotspot[0]; mmsghdr* end = p + pos;
for (p = &hotspot[0]; p < end; p++) {
if (!p->msg_len) {
stat->perf_gso_on_packets(1);
continue;
}

View file

@ -117,17 +117,26 @@ private:
srs_error_t srtp_recv_init();
};
// A group of RTP packets.
class SrsRtcPackets
{
public:
bool use_gso;
bool should_merge_nalus;
public:
// The total bytes of RTP packets.
int nn_bytes;
// The RTP packets send out by sendmmsg or sendmsg. Note that if many packets group to
// one msghdr by GSO, it's only one RTP packet, because we only send once.
int nn_rtp_pkts;
// For video, the samples or NALUs.
int nn_samples;
// For audio, the generated extra audio packets.
// For example, when transcoding AAC to opus, may many extra payloads for a audio.
int nn_extras;
// The original audio messages.
int nn_audios;
// The original video messages.
int nn_videos;
public:
std::vector<SrsRtpPacket2*> packets;