Skip to content

Commit

Permalink
Split packets/bytes in StreamDataCounter into RtpPacketCounter struct.
Browse files Browse the repository at this point in the history
Prepares for adding FEC bytes to the StreamDataCounter.

R=mflodman@webrtc.org, stefan@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/37579004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@8122 4adac7df-926f-26a2-2b94-8c16560cd09d
  • Loading branch information
asapersson@webrtc.org committed Jan 22, 2015
1 parent ed41247 commit 6df5ade
Show file tree
Hide file tree
Showing 17 changed files with 298 additions and 259 deletions.
4 changes: 2 additions & 2 deletions talk/media/webrtc/webrtcvideoengine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2754,8 +2754,8 @@ bool WebRtcVideoMediaChannel::GetStats(const StatsOptions& options,
}
VideoReceiverInfo rinfo;
rinfo.add_ssrc(ssrc);
rinfo.bytes_rcvd = received.bytes;
rinfo.packets_rcvd = received.packets;
rinfo.bytes_rcvd = received.transmitted.payload_bytes;
rinfo.packets_rcvd = received.transmitted.packets;
rinfo.packets_lost = -1;
rinfo.packets_concealed = -1;
rinfo.fraction_lost = -1; // from SentRTCP
Expand Down
15 changes: 8 additions & 7 deletions talk/media/webrtc/webrtcvideoengine2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1772,10 +1772,10 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() {
++it) {
// TODO(pbos): Wire up additional stats, such as padding bytes.
webrtc::SsrcStats stream_stats = it->second;
info.bytes_sent += stream_stats.rtp_stats.bytes +
stream_stats.rtp_stats.header_bytes +
stream_stats.rtp_stats.padding_bytes;
info.packets_sent += stream_stats.rtp_stats.packets;
info.bytes_sent += stream_stats.rtp_stats.transmitted.payload_bytes +
stream_stats.rtp_stats.transmitted.header_bytes +
stream_stats.rtp_stats.transmitted.padding_bytes;
info.packets_sent += stream_stats.rtp_stats.transmitted.packets;
info.packets_lost += stream_stats.rtcp_stats.cumulative_lost;
if (stream_stats.sent_width > info.send_frame_width)
info.send_frame_width = stream_stats.sent_width;
Expand Down Expand Up @@ -2020,9 +2020,10 @@ WebRtcVideoChannel2::WebRtcVideoReceiveStream::GetVideoReceiverInfo() {
VideoReceiverInfo info;
info.add_ssrc(config_.rtp.remote_ssrc);
webrtc::VideoReceiveStream::Stats stats = stream_->GetStats();
info.bytes_rcvd = stats.rtp_stats.bytes + stats.rtp_stats.header_bytes +
stats.rtp_stats.padding_bytes;
info.packets_rcvd = stats.rtp_stats.packets;
info.bytes_rcvd = stats.rtp_stats.transmitted.payload_bytes +
stats.rtp_stats.transmitted.header_bytes +
stats.rtp_stats.transmitted.padding_bytes;
info.packets_rcvd = stats.rtp_stats.transmitted.packets;

info.framerate_rcvd = stats.network_frame_rate;
info.framerate_decoded = stats.decode_frame_rate;
Expand Down
74 changes: 35 additions & 39 deletions webrtc/common_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,30 +241,38 @@ struct RtcpPacketTypeCounter {
uint32_t unique_nack_requests; // Number of unique NACKed RTP packets.
};

// Data usage statistics for a (rtp) stream.
struct StreamDataCounters {
StreamDataCounters()
: first_packet_time_ms(-1),
bytes(0),
header_bytes(0),
struct RtpPacketCounter {
RtpPacketCounter()
: header_bytes(0),
payload_bytes(0),
padding_bytes(0),
packets(0),
retransmitted_bytes(0),
retransmitted_header_bytes(0),
retransmitted_padding_bytes(0),
retransmitted_packets(0),
fec_packets(0) {}
packets(0) {}

void Add(const StreamDataCounters& other) {
bytes += other.bytes;
void Add(const RtpPacketCounter& other) {
header_bytes += other.header_bytes;
payload_bytes += other.payload_bytes;
padding_bytes += other.padding_bytes;
packets += other.packets;
retransmitted_bytes += other.retransmitted_bytes;
retransmitted_header_bytes += other.retransmitted_header_bytes;
retransmitted_padding_bytes += other.retransmitted_padding_bytes;
retransmitted_packets += other.retransmitted_packets;
fec_packets += other.fec_packets;
}

size_t TotalBytes() const {
return header_bytes + payload_bytes + padding_bytes;
}

size_t header_bytes; // Number of bytes used by RTP headers.
size_t payload_bytes; // Payload bytes, excluding RTP headers and padding.
size_t padding_bytes; // Number of padding bytes.
uint32_t packets; // Number of packets.
};

// Data usage statistics for a (rtp) stream.
struct StreamDataCounters {
StreamDataCounters() : first_packet_time_ms(-1) {}

void Add(const StreamDataCounters& other) {
transmitted.Add(other.transmitted);
retransmitted.Add(other.retransmitted);
fec.Add(other.fec);
if (other.first_packet_time_ms != -1 &&
(other.first_packet_time_ms < first_packet_time_ms ||
first_packet_time_ms == -1)) {
Expand All @@ -277,30 +285,18 @@ struct StreamDataCounters {
return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
}

size_t TotalBytes() const {
return bytes + header_bytes + padding_bytes;
}

size_t RetransmittedBytes() const {
return retransmitted_bytes + retransmitted_header_bytes +
retransmitted_padding_bytes;
}

// Returns the number of bytes corresponding to the actual media payload (i.e.
// RTP headers, padding and retransmissions are excluded). Note this function
// does not have meaning for an RTX stream.
size_t MediaPayloadBytes() const {
return bytes - retransmitted_bytes;
return transmitted.payload_bytes - retransmitted.payload_bytes;
}

// TODO(pbos): Rename bytes -> media_bytes.
int64_t first_packet_time_ms; // Time when first packet is sent/received.
size_t bytes; // Payload bytes, excluding RTP headers and padding.
size_t header_bytes; // Number of bytes used by RTP headers.
size_t padding_bytes; // Number of padding bytes.
uint32_t packets; // Number of packets.
size_t retransmitted_bytes; // Number of retransmitted payload bytes.
size_t retransmitted_header_bytes; // Retransmitted bytes used by RTP header.
size_t retransmitted_padding_bytes; // Retransmitted padding bytes.
uint32_t retransmitted_packets; // Number of retransmitted packets.
uint32_t fec_packets; // Number of redundancy packets.
RtpPacketCounter transmitted; // Number of transmitted packets/bytes.
RtpPacketCounter retransmitted; // Number of retransmitted packets/bytes.
// TODO(asapersson): add FEC bytes.
RtpPacketCounter fec; // Number of redundancy packets/bytes.
};

// Callback, called whenever byte/packet counts have been updated.
Expand Down
47 changes: 25 additions & 22 deletions webrtc/modules/rtp_rtcp/source/receive_statistics_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@ void StreamStatisticianImpl::UpdateCounters(const RTPHeader& header,
bool in_order = InOrderPacketInternal(header.sequenceNumber);
ssrc_ = header.ssrc;
incoming_bitrate_.Update(packet_length);
receive_counters_.bytes +=
receive_counters_.transmitted.payload_bytes +=
packet_length - (header.paddingLength + header.headerLength);
receive_counters_.header_bytes += header.headerLength;
receive_counters_.padding_bytes += header.paddingLength;
++receive_counters_.packets;
receive_counters_.transmitted.header_bytes += header.headerLength;
receive_counters_.transmitted.padding_bytes += header.paddingLength;
++receive_counters_.transmitted.packets;
if (!in_order && retransmitted) {
++receive_counters_.retransmitted_packets;
receive_counters_.retransmitted_bytes +=
++receive_counters_.retransmitted.packets;
receive_counters_.retransmitted.payload_bytes +=
packet_length - (header.paddingLength + header.headerLength);
receive_counters_.retransmitted_header_bytes += header.headerLength;
receive_counters_.retransmitted_padding_bytes += header.paddingLength;
receive_counters_.retransmitted.header_bytes += header.headerLength;
receive_counters_.retransmitted.padding_bytes += header.paddingLength;
}

if (receive_counters_.packets == 1) {
if (receive_counters_.transmitted.packets == 1) {
received_seq_first_ = header.sequenceNumber;
receive_counters_.first_packet_time_ms = clock_->TimeInMilliseconds();
}
Expand All @@ -108,7 +108,7 @@ void StreamStatisticianImpl::UpdateCounters(const RTPHeader& header,
clock_->CurrentNtp(receive_time_secs, receive_time_frac);

// Wrong if we use RetransmitOfOldPacket.
if (receive_counters_.packets > 1 &&
if (receive_counters_.transmitted.packets > 1 &&
received_seq_max_ > header.sequenceNumber) {
// Wrap around detected.
received_seq_wraps_++;
Expand All @@ -119,8 +119,8 @@ void StreamStatisticianImpl::UpdateCounters(const RTPHeader& header,
// If new time stamp and more than one in-order packet received, calculate
// new jitter statistics.
if (header.timestamp != last_received_timestamp_ &&
(receive_counters_.packets - receive_counters_.retransmitted_packets) >
1) {
(receive_counters_.transmitted.packets -
receive_counters_.retransmitted.packets) > 1) {
UpdateJitter(header, receive_time_secs, receive_time_frac);
}
last_received_timestamp_ = header.timestamp;
Expand Down Expand Up @@ -203,7 +203,7 @@ void StreamStatisticianImpl::NotifyRtcpCallback() {
void StreamStatisticianImpl::FecPacketReceived() {
{
CriticalSectionScoped cs(stream_lock_.get());
++receive_counters_.fec_packets;
++receive_counters_.fec.packets;
}
NotifyRtpCallback();
}
Expand All @@ -218,7 +218,8 @@ bool StreamStatisticianImpl::GetStatistics(RtcpStatistics* statistics,
bool reset) {
{
CriticalSectionScoped cs(stream_lock_.get());
if (received_seq_first_ == 0 && receive_counters_.bytes == 0) {
if (received_seq_first_ == 0 &&
receive_counters_.transmitted.payload_bytes == 0) {
// We have not received anything.
return false;
}
Expand Down Expand Up @@ -260,8 +261,8 @@ RtcpStatistics StreamStatisticianImpl::CalculateRtcpStatistics() {
// Number of received RTP packets since last report, counts all packets but
// not re-transmissions.
uint32_t rec_since_last =
(receive_counters_.packets - receive_counters_.retransmitted_packets) -
last_report_inorder_packets_;
(receive_counters_.transmitted.packets -
receive_counters_.retransmitted.packets) - last_report_inorder_packets_;

// With NACK we don't know the expected retransmissions during the last
// second. We know how many "old" packets we have received. We just count
Expand All @@ -273,7 +274,7 @@ RtcpStatistics StreamStatisticianImpl::CalculateRtcpStatistics() {
// re-transmitted. We use RTT to decide if a packet is re-ordered or
// re-transmitted.
uint32_t retransmitted_packets =
receive_counters_.retransmitted_packets - last_report_old_packets_;
receive_counters_.retransmitted.packets - last_report_old_packets_;
rec_since_last += retransmitted_packets;

int32_t missing = 0;
Expand Down Expand Up @@ -301,8 +302,9 @@ RtcpStatistics StreamStatisticianImpl::CalculateRtcpStatistics() {

// Only for report blocks in RTCP SR and RR.
last_report_inorder_packets_ =
receive_counters_.packets - receive_counters_.retransmitted_packets;
last_report_old_packets_ = receive_counters_.retransmitted_packets;
receive_counters_.transmitted.packets -
receive_counters_.retransmitted.packets;
last_report_old_packets_ = receive_counters_.retransmitted.packets;
last_report_seq_max_ = received_seq_max_;

return stats;
Expand All @@ -312,11 +314,12 @@ void StreamStatisticianImpl::GetDataCounters(
size_t* bytes_received, uint32_t* packets_received) const {
CriticalSectionScoped cs(stream_lock_.get());
if (bytes_received) {
*bytes_received = receive_counters_.bytes + receive_counters_.header_bytes +
receive_counters_.padding_bytes;
*bytes_received = receive_counters_.transmitted.payload_bytes +
receive_counters_.transmitted.header_bytes +
receive_counters_.transmitted.padding_bytes;
}
if (packets_received) {
*packets_received = receive_counters_.packets;
*packets_received = receive_counters_.transmitted.packets;
}
}

Expand Down
Loading

0 comments on commit 6df5ade

Please sign in to comment.