Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sender report trace event #1267

Merged
merged 6 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion node/src/Producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export type ProducerOptions<ProducerAppData extends AppData = AppData> =
/**
* Valid types for 'trace' event.
*/
export type ProducerTraceEventType = 'rtp' | 'keyframe' | 'nack' | 'pli' | 'fir';
export type ProducerTraceEventType = 'rtp' | 'keyframe' | 'nack' | 'pli' | 'fir' | 'sr';

/**
* 'trace' event data.
Expand Down Expand Up @@ -702,6 +702,11 @@ function producerTraceEventTypeToFbs(eventType: ProducerTraceEventType)
return FbsProducer.TraceEventType.RTP;
}

case 'sr':
{
return FbsProducer.TraceEventType.SR;
}

default:
{
throw new TypeError(`invalid ProducerTraceEventType: ${eventType}`);
Expand Down Expand Up @@ -738,6 +743,11 @@ function producerTraceEventTypeFromFbs(eventType: FbsProducer.TraceEventType)
{
return 'rtp';
}

case FbsProducer.TraceEventType.SR:
{
return 'sr';
}
}
}

Expand Down
35 changes: 34 additions & 1 deletion rust/src/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#[cfg(test)]
mod tests;

use mediasoup_sys::fbs::{common, rtp_packet, sctp_association, transport, web_rtc_transport};
use mediasoup_sys::fbs::{
common, producer, rtp_packet, sctp_association, transport, web_rtc_transport,
};
use serde::de::{MapAccess, Visitor};
use serde::ser::SerializeStruct;
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
Expand Down Expand Up @@ -1262,3 +1264,34 @@ impl BweTraceInfo {
}
}
}

/// BWE info in trace event.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not "BWE info".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge and make this change in v3.

#[derive(Debug, Copy, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SrTraceInfo {
/// Stream SSRC
ssrc: u32,
/// NTP : most significant word
ntp_sec: u32,
/// NTP : least significant word
ntp_frac: u32,
/// RTP timestamp
rtp_ts: u32,
/// Sender packet count
packet_count: u32,
/// Sender octet count
octet_count: u32,
}

impl SrTraceInfo {
pub(crate) fn from_fbs(info: producer::SrTraceInfo) -> Self {
Self {
ssrc: info.ssrc,
ntp_sec: info.ntp_sec,
ntp_frac: info.ntp_frac,
rtp_ts: info.rtp_ts,
packet_count: info.packet_count,
octet_count: info.octet_count,
}
}
}
28 changes: 27 additions & 1 deletion rust/src/router/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
mod tests;

use crate::consumer::{RtpStreamParams, RtxStreamParams};
use crate::data_structures::{AppData, RtpPacketTraceInfo, SsrcTraceInfo, TraceEventDirection};
use crate::data_structures::{
AppData, RtpPacketTraceInfo, SrTraceInfo, SsrcTraceInfo, TraceEventDirection,
};
use crate::messages::{
ProducerCloseRequest, ProducerDumpRequest, ProducerEnableTraceEventRequest,
ProducerGetStatsRequest, ProducerPauseRequest, ProducerResumeRequest, ProducerSendNotification,
Expand Down Expand Up @@ -394,6 +396,15 @@ pub enum ProducerTraceEventData {
/// SSRC info.
info: SsrcTraceInfo,
},
/// RTCP Sender report.
Sr {
/// Event timestamp.
timestamp: u64,
/// Event direction.
direction: TraceEventDirection,
/// SSRC info.
info: SrTraceInfo,
},
}

impl ProducerTraceEventData {
Expand Down Expand Up @@ -447,6 +458,17 @@ impl ProducerTraceEventData {
SsrcTraceInfo { ssrc: info.ssrc }
},
},
producer::TraceEventType::Sr => ProducerTraceEventData::Sr {
timestamp: data.timestamp,
direction: TraceEventDirection::from_fbs(data.direction),
info: {
let Some(producer::TraceInfo::SrTraceInfo(info)) = data.info else {
panic!("Wrong message from worker: {data:?}");
};

SrTraceInfo::from_fbs(*info)
},
},
}
}
}
Expand All @@ -465,6 +487,8 @@ pub enum ProducerTraceEventType {
Pli,
/// RTCP FIR packet.
Fir,
/// RTCP Sender report.
SR,
}

impl ProducerTraceEventType {
Expand All @@ -475,6 +499,7 @@ impl ProducerTraceEventType {
ProducerTraceEventType::Nack => producer::TraceEventType::Nack,
ProducerTraceEventType::Pli => producer::TraceEventType::Pli,
ProducerTraceEventType::Fir => producer::TraceEventType::Fir,
ProducerTraceEventType::SR => producer::TraceEventType::Sr,
}
}

Expand All @@ -485,6 +510,7 @@ impl ProducerTraceEventType {
producer::TraceEventType::Nack => ProducerTraceEventType::Nack,
producer::TraceEventType::Pli => ProducerTraceEventType::Pli,
producer::TraceEventType::Fir => ProducerTraceEventType::Fir,
producer::TraceEventType::Sr => ProducerTraceEventType::SR,
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions worker/fbs/producer.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum TraceEventType: uint8 {
NACK,
PLI,
RTP,
SR,
}

table EnableTraceEventRequest {
Expand Down Expand Up @@ -60,6 +61,7 @@ union TraceInfo {
FirTraceInfo,
PliTraceInfo,
RtpTraceInfo,
SrTraceInfo,
}

table KeyFrameTraceInfo {
Expand All @@ -80,6 +82,15 @@ table RtpTraceInfo {
is_rtx: bool;
}

table SrTraceInfo {
ssrc: uint32;
ntp_sec: uint32;
ntp_frac: uint32;
rtp_ts: uint32;
packet_count: uint32;
octet_count: uint32;
}

table TraceNotification {
type: TraceEventType;
timestamp: uint64;
Expand Down
2 changes: 2 additions & 0 deletions worker/include/RTC/Producer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ namespace RTC
bool nack{ false };
bool pli{ false };
bool fir{ false };
bool sr{ false };
};

public:
Expand Down Expand Up @@ -160,6 +161,7 @@ namespace RTC
void EmitTraceEventPliType(uint32_t ssrc) const;
void EmitTraceEventFirType(uint32_t ssrc) const;
void EmitTraceEventNackType() const;
void EmitTraceEventSrType(RTC::RTCP::SenderReport* report) const;
void EmitTraceEvent(flatbuffers::Offset<FBS::Producer::TraceNotification>& notification) const;

/* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */
Expand Down
37 changes: 37 additions & 0 deletions worker/src/RTC/Producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ namespace RTC
{
newTraceEventTypes.rtp = true;

break;
}
case FBS::Producer::TraceEventType::SR:
{
newTraceEventTypes.sr = true;

break;
}
}
Expand Down Expand Up @@ -706,6 +712,8 @@ namespace RTC

this->listener->OnProducerRtcpSenderReport(this, rtpStream, first);

EmitTraceEventSrType(report);

return;
}

Expand Down Expand Up @@ -1576,6 +1584,35 @@ namespace RTC
EmitTraceEvent(notification);
}

inline void Producer::EmitTraceEventSrType(RTC::RTCP::SenderReport* report) const
{
MS_TRACE();

if (!this->traceEventTypes.sr)
{
return;
}

auto traceInfo = FBS::Producer::CreateSrTraceInfo(
this->shared->channelNotifier->GetBufferBuilder(),
report->GetSsrc(),
report->GetNtpSec(),
report->GetNtpFrac(),
report->GetRtpTs(),
report->GetPacketCount(),
report->GetOctetCount());

auto notification = FBS::Producer::CreateTraceNotification(
this->shared->channelNotifier->GetBufferBuilder(),
FBS::Producer::TraceEventType::SR,
DepLibUV::GetTimeMs(),
FBS::Common::TraceDirection::DIRECTION_IN,
FBS::Producer::TraceInfo::SrTraceInfo,
traceInfo.Union());

EmitTraceEvent(notification);
}

inline void Producer::EmitTraceEvent(
flatbuffers::Offset<FBS::Producer::TraceNotification>& notification) const
{
Expand Down
Loading