12 #ifndef ROC_RTCP_REPORTER_H_
13 #define ROC_RTCP_REPORTER_H_
244 enum { PreallocatedStreams = 8, PreallocatedAddresses = 4 };
261 struct Stream : core::RefCounted<Stream, core::PoolAllocation>,
264 Stream(core::IPool& pool,
267 const RttConfig& rtt_config)
268 : core::RefCounted<Stream, core::PoolAllocation>(pool)
269 , source_id(source_id)
270 , has_remote_recv_report(false)
271 , remote_recv_rtt(rtt_config)
272 , has_remote_send_report(false)
273 , remote_send_rtt(rtt_config)
274 , local_recv_report(NULL)
275 , last_update(report_time)
278 , last_remote_rr_ntp(0)
279 , last_remote_dlsr(0)
282 , last_remote_sr_ntp(0)
283 , last_remote_dlrr(0)
290 char cname[MaxCnameLen + 1];
294 bool has_remote_recv_report;
295 RecvReport remote_recv_report;
296 RttEstimator remote_recv_rtt;
297 PacketCounter remote_recv_packet_count;
301 bool has_remote_send_report;
302 SendReport remote_send_report;
303 RttEstimator remote_send_rtt;
304 PacketCounter remote_send_packet_count;
305 PacketCounter remote_send_byte_count;
311 RecvReport* local_recv_report;
312 LossEstimator local_recv_loss;
315 address::SocketAddr remote_address;
358 struct Address : core::RefCounted<Address, core::PoolAllocation>,
361 Address(core::IPool& pool,
363 const address::SocketAddr& remote_address,
366 , remote_address(remote_address)
367 , send_stream_index(arena)
368 , recv_stream_index(arena)
369 , last_rebuild(report_time) {
373 address::SocketAddr remote_address;
377 core::Array<Stream*, PreallocatedStreams> send_stream_index;
378 core::Array<Stream*, PreallocatedStreams> recv_stream_index;
384 const address::SocketAddr& key()
const {
385 return remote_address;
392 static bool key_equal(
const address::SocketAddr& addr1,
393 const address::SocketAddr& addr2) {
394 return addr1 == addr2;
398 status::StatusCode notify_streams_();
399 status::StatusCode refresh_streams_();
400 status::StatusCode query_streams_();
401 status::StatusCode rebuild_index_();
403 void detect_timeouts_();
405 void resolve_collision_();
407 void validate_send_report_(
const SendReport& send_report);
408 void validate_recv_report_(
const RecvReport& recv_report);
412 void remove_stream_(Stream& stream);
413 void update_stream_(Stream& stream);
415 core::SharedPtr<Address> find_address_(
const address::SocketAddr& remote_address,
417 void remove_address_(Address& address);
418 void rebuild_address_(Address& address);
420 core::IArena& arena_;
423 IParticipant& participant_;
429 address::SocketAddr participant_report_addr_;
432 char local_cname_[MaxCnameLen + 1];
434 bool has_local_send_report_;
435 SendReport local_send_report_;
436 core::Array<RecvReport, PreallocatedStreams> local_recv_reports_;
439 core::SlabPool<Stream, PreallocatedStreams> stream_pool_;
440 core::Hashmap<Stream, PreallocatedStreams> stream_map_;
445 core::List<Stream, core::NoOwnership> stream_lru_;
451 core::SlabPool<Address, PreallocatedAddresses> address_pool_;
452 core::Hashmap<Address, PreallocatedAddresses> address_map_;
457 core::List<Address, core::NoOwnership> address_lru_;
462 core::Array<Address*, PreallocatedAddresses> address_index_;
464 bool need_rebuild_index_;
472 bool collision_detected_;
473 bool collision_reported_;
476 ReportState report_state_;
477 status::StatusCode report_error_;
478 address::SocketAddr report_addr_;
482 const Config config_;
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Base class for non-copyable objects.
PoolAllocation(IPool &pool)
Initialize.
RTCP report processor and generator.
size_t total_destinations() const
Get number of tracked destination addresses, for testing.
void process_dlrr_subblock(const header::XrPacket &xr, const header::XrDlrrSubblock &blk)
Process XR DLRR sub-block (extended sender report).
void process_sr(const header::SenderReportPacket &sr)
Process SR header.
bool is_valid() const
Check if initialization succeeded.
void generate_dlrr_subblock(size_t addr_index, size_t stream_index, header::XrDlrrSubblock &blk)
Generate XR DLRR sub-block (extended sender report). addr_index should be in range [0; num_dest_addre...
bool is_receiving() const
Check if there are local receiving streams.
void generate_rr(header::ReceiverReportPacket &rr)
Generate RR header.
void process_delay_metrics_block(const header::XrPacket &xr, const header::XrDelayMetricsBlock &blk)
Process XR Delay Metrics block (extended receiver report).
void process_reception_block(packet::stream_source_t ssrc, const header::ReceptionReportBlock &blk)
Process SR/RR reception block.
size_t num_dest_addresses() const
Get number of destination addresses to which to send reports.
void generate_rrtr_block(header::XrRrtrBlock &blk)
Generate XR RRTR header (extended receiver report).
void generate_goodbye(packet::stream_source_t &ssrc)
Generate BYE message.
void process_cname(const SdesChunk &chunk, const SdesItem &item)
Process SDES CNAME.
void process_rrtr_block(const header::XrPacket &xr, const header::XrRrtrBlock &blk)
Process XR RRTR block (extended receiver report).
ROC_ATTR_NODISCARD status::StatusCode begin_generation(core::nanoseconds_t report_time)
Begin report generation. Invoked before genrate_xxx() functions.
size_t total_streams() const
Get number of tracked streams, for testing.
void generate_delay_metrics_block(size_t addr_index, size_t stream_index, header::XrDelayMetricsBlock &blk)
Generate XR Delay Metrics block (extended receiver report). addr_index should be in range [0; num_des...
void generate_xr(header::XrPacket &xr)
Generate XR header.
void generate_sr(header::SenderReportPacket &sr)
Generate SR header.
ROC_ATTR_NODISCARD status::StatusCode end_generation()
End report generation. Invoked after generate_xxx() functions.
size_t num_receiving_streams(size_t addr_index) const
Get number of receiving streams to be reported. addr_index should be in range [0; num_dest_addresses(...
ROC_ATTR_NODISCARD status::StatusCode end_processing()
End report processing. Invoked after process_xxx() functions.
void process_goodbye(packet::stream_source_t ssrc)
Process BYE message.
bool need_goodbye() const
Check if BYE message should be included.
void generate_measurement_info_block(size_t addr_index, size_t stream_index, header::XrMeasurementInfoBlock &blk)
Generate XR Measurement Info block (extended receiver report). addr_index should be in range [0; num_...
void generate_cname(SdesChunk &chunk, SdesItem &item)
Generate SDES chunk with CNAME item.
ROC_ATTR_NODISCARD status::StatusCode begin_processing(const address::SocketAddr &report_addr, core::nanoseconds_t report_time)
Begin report processing. Invoked before process_xxx() functions.
size_t num_sending_streams(size_t addr_index) const
Get number of sending streams to be reported. addr_index should be in range [0; num_dest_addresses()-...
void process_measurement_info_block(const header::XrPacket &xr, const header::XrMeasurementInfoBlock &blk)
Process XR Measurement Info block (extended receiver report).
bool is_sending() const
Check if there is local sending stream.
void generate_dest_address(size_t addr_index, address::SocketAddr &addr)
Generate destination address. addr_index should be in range [0; num_dest_addresses()-1].
void generate_reception_block(size_t addr_index, size_t stream_index, header::ReceptionReportBlock &blk)
Generate SR/RR reception block. addr_index should be in range [0; num_dest_addresses()-1]....
Reporter(const Config &config, IParticipant &participant, core::IArena &arena)
Initialize.
void process_queue_metrics_block(const header::XrPacket &xr, const header::XrQueueMetricsBlock &blk)
Process XR Queue Metrics block (extended receiver report).
void generate_queue_metrics_block(size_t addr_index, size_t stream_index, header::XrQueueMetricsBlock &blk)
Generate XR Queue Metrics block (extended receiver report). addr_index should be in range [0; num_des...
Intrusive doubly-linked list.
hashsum_t hashsum_int(int16_t)
Compute hash of 16-bit integer.
int64_t nanoseconds_t
Nanoseconds.
hashsum_t hashsum_mem(const void *data, size_t size)
Compute hash of byte range.
size_t hashsum_t
Hash type.
uint32_t stream_source_t
Packet stream identifier.
uint64_t ntp_timestamp_t
NTP timestamp.
ParticipantReportMode
Participant report generation mode.
Base class for object with reference counter.
Utitilies for NTP timestamp.
Round-trip time estimator.
Shared ownership intrusive pointer.
Various units used in packets.