Fix circular dependencies in webrtc_common.
One reason for the circular deps is that common_types.h is a historical dumping ground for various structs and defines that are believed to be generally useful. I tried moving things out that did not appear to be used downstream (StreamCounters, RtpCounters etc) and moved the things that seemed used (RtpHeader + supporting structs) to a new file api/rtp_headers.h. This makes their place in the api more clear while moving out the things that don't belong in the API in the first place. I had to extract out typedefs.h from webrtc_common to resolve another circular dependency. I believe checks includes typedefs, but common depends on checks. Bug: webrtc:7745 Change-Id: I725d49616b1ec0cdc8b74be7c078f7a4d46f084b Reviewed-on: https://webrtc-review.googlesource.com/33001 Commit-Queue: Patrik Höglund <phoglund@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#21295}
This commit is contained in:
committed by
Commit Bot
parent
d5d0540b86
commit
3e113438b1
@ -16,6 +16,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "api/audio_codecs/audio_format.h"
|
||||
#include "api/rtp_headers.h"
|
||||
#include "common_types.h" // NOLINT(build/include)
|
||||
#include "modules/include/module_common_types.h"
|
||||
#include "rtc_base/deprecation.h"
|
||||
@ -496,5 +497,100 @@ class TransportSequenceNumberAllocator {
|
||||
virtual uint16_t AllocateSequenceNumber() = 0;
|
||||
};
|
||||
|
||||
struct RtpPacketCounter {
|
||||
RtpPacketCounter()
|
||||
: header_bytes(0), payload_bytes(0), padding_bytes(0), packets(0) {}
|
||||
|
||||
void Add(const RtpPacketCounter& other) {
|
||||
header_bytes += other.header_bytes;
|
||||
payload_bytes += other.payload_bytes;
|
||||
padding_bytes += other.padding_bytes;
|
||||
packets += other.packets;
|
||||
}
|
||||
|
||||
void Subtract(const RtpPacketCounter& other) {
|
||||
RTC_DCHECK_GE(header_bytes, other.header_bytes);
|
||||
header_bytes -= other.header_bytes;
|
||||
RTC_DCHECK_GE(payload_bytes, other.payload_bytes);
|
||||
payload_bytes -= other.payload_bytes;
|
||||
RTC_DCHECK_GE(padding_bytes, other.padding_bytes);
|
||||
padding_bytes -= other.padding_bytes;
|
||||
RTC_DCHECK_GE(packets, other.packets);
|
||||
packets -= other.packets;
|
||||
}
|
||||
|
||||
void AddPacket(size_t packet_length, const RTPHeader& header) {
|
||||
++packets;
|
||||
header_bytes += header.headerLength;
|
||||
padding_bytes += header.paddingLength;
|
||||
payload_bytes +=
|
||||
packet_length - (header.headerLength + header.paddingLength);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
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)) {
|
||||
// Use oldest time.
|
||||
first_packet_time_ms = other.first_packet_time_ms;
|
||||
}
|
||||
}
|
||||
|
||||
void Subtract(const StreamDataCounters& other) {
|
||||
transmitted.Subtract(other.transmitted);
|
||||
retransmitted.Subtract(other.retransmitted);
|
||||
fec.Subtract(other.fec);
|
||||
if (other.first_packet_time_ms != -1 &&
|
||||
(other.first_packet_time_ms > first_packet_time_ms ||
|
||||
first_packet_time_ms == -1)) {
|
||||
// Use youngest time.
|
||||
first_packet_time_ms = other.first_packet_time_ms;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
|
||||
return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
|
||||
}
|
||||
|
||||
// Returns the number of bytes corresponding to the actual media payload (i.e.
|
||||
// RTP headers, padding, retransmissions and fec packets are excluded).
|
||||
// Note this function does not have meaning for an RTX stream.
|
||||
size_t MediaPayloadBytes() const {
|
||||
return transmitted.payload_bytes - retransmitted.payload_bytes -
|
||||
fec.payload_bytes;
|
||||
}
|
||||
|
||||
int64_t first_packet_time_ms; // Time when first packet is sent/received.
|
||||
RtpPacketCounter transmitted; // Number of transmitted packets/bytes.
|
||||
RtpPacketCounter retransmitted; // Number of retransmitted packets/bytes.
|
||||
RtpPacketCounter fec; // Number of redundancy packets/bytes.
|
||||
};
|
||||
|
||||
// Callback, called whenever byte/packet counts have been updated.
|
||||
class StreamDataCountersCallback {
|
||||
public:
|
||||
virtual ~StreamDataCountersCallback() {}
|
||||
|
||||
virtual void DataCountersUpdated(const StreamDataCounters& counters,
|
||||
uint32_t ssrc) = 0;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
#endif // MODULES_RTP_RTCP_INCLUDE_RTP_RTCP_DEFINES_H_
|
||||
|
||||
Reference in New Issue
Block a user