Unverified 提交 87032a8b authored 作者: GithubUser8080's avatar GithubUser8080 提交者: GitHub

Add sender report trace event (#1267)

上级 ddcd72f1
...@@ -52,7 +52,7 @@ export type ProducerOptions<ProducerAppData extends AppData = AppData> = ...@@ -52,7 +52,7 @@ export type ProducerOptions<ProducerAppData extends AppData = AppData> =
/** /**
* Valid types for 'trace' event. * 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. * 'trace' event data.
...@@ -702,6 +702,11 @@ function producerTraceEventTypeToFbs(eventType: ProducerTraceEventType) ...@@ -702,6 +702,11 @@ function producerTraceEventTypeToFbs(eventType: ProducerTraceEventType)
return FbsProducer.TraceEventType.RTP; return FbsProducer.TraceEventType.RTP;
} }
case 'sr':
{
return FbsProducer.TraceEventType.SR;
}
default: default:
{ {
throw new TypeError(`invalid ProducerTraceEventType: ${eventType}`); throw new TypeError(`invalid ProducerTraceEventType: ${eventType}`);
...@@ -738,6 +743,11 @@ function producerTraceEventTypeFromFbs(eventType: FbsProducer.TraceEventType) ...@@ -738,6 +743,11 @@ function producerTraceEventTypeFromFbs(eventType: FbsProducer.TraceEventType)
{ {
return 'rtp'; return 'rtp';
} }
case FbsProducer.TraceEventType.SR:
{
return 'sr';
}
} }
} }
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
#[cfg(test)] #[cfg(test)]
mod tests; 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::de::{MapAccess, Visitor};
use serde::ser::SerializeStruct; use serde::ser::SerializeStruct;
use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
...@@ -1262,3 +1264,34 @@ impl BweTraceInfo { ...@@ -1262,3 +1264,34 @@ impl BweTraceInfo {
} }
} }
} }
/// BWE info in trace event.
#[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,
}
}
}
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
mod tests; mod tests;
use crate::consumer::{RtpStreamParams, RtxStreamParams}; 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::{ use crate::messages::{
ProducerCloseRequest, ProducerDumpRequest, ProducerEnableTraceEventRequest, ProducerCloseRequest, ProducerDumpRequest, ProducerEnableTraceEventRequest,
ProducerGetStatsRequest, ProducerPauseRequest, ProducerResumeRequest, ProducerSendNotification, ProducerGetStatsRequest, ProducerPauseRequest, ProducerResumeRequest, ProducerSendNotification,
...@@ -394,6 +396,15 @@ pub enum ProducerTraceEventData { ...@@ -394,6 +396,15 @@ pub enum ProducerTraceEventData {
/// SSRC info. /// SSRC info.
info: SsrcTraceInfo, info: SsrcTraceInfo,
}, },
/// RTCP Sender report.
Sr {
/// Event timestamp.
timestamp: u64,
/// Event direction.
direction: TraceEventDirection,
/// SSRC info.
info: SrTraceInfo,
},
} }
impl ProducerTraceEventData { impl ProducerTraceEventData {
...@@ -447,6 +458,17 @@ impl ProducerTraceEventData { ...@@ -447,6 +458,17 @@ impl ProducerTraceEventData {
SsrcTraceInfo { ssrc: info.ssrc } 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)
},
},
} }
} }
} }
...@@ -465,6 +487,8 @@ pub enum ProducerTraceEventType { ...@@ -465,6 +487,8 @@ pub enum ProducerTraceEventType {
Pli, Pli,
/// RTCP FIR packet. /// RTCP FIR packet.
Fir, Fir,
/// RTCP Sender report.
SR,
} }
impl ProducerTraceEventType { impl ProducerTraceEventType {
...@@ -475,6 +499,7 @@ impl ProducerTraceEventType { ...@@ -475,6 +499,7 @@ impl ProducerTraceEventType {
ProducerTraceEventType::Nack => producer::TraceEventType::Nack, ProducerTraceEventType::Nack => producer::TraceEventType::Nack,
ProducerTraceEventType::Pli => producer::TraceEventType::Pli, ProducerTraceEventType::Pli => producer::TraceEventType::Pli,
ProducerTraceEventType::Fir => producer::TraceEventType::Fir, ProducerTraceEventType::Fir => producer::TraceEventType::Fir,
ProducerTraceEventType::SR => producer::TraceEventType::Sr,
} }
} }
...@@ -485,6 +510,7 @@ impl ProducerTraceEventType { ...@@ -485,6 +510,7 @@ impl ProducerTraceEventType {
producer::TraceEventType::Nack => ProducerTraceEventType::Nack, producer::TraceEventType::Nack => ProducerTraceEventType::Nack,
producer::TraceEventType::Pli => ProducerTraceEventType::Pli, producer::TraceEventType::Pli => ProducerTraceEventType::Pli,
producer::TraceEventType::Fir => ProducerTraceEventType::Fir, producer::TraceEventType::Fir => ProducerTraceEventType::Fir,
producer::TraceEventType::Sr => ProducerTraceEventType::SR,
} }
} }
} }
......
...@@ -11,6 +11,7 @@ enum TraceEventType: uint8 { ...@@ -11,6 +11,7 @@ enum TraceEventType: uint8 {
NACK, NACK,
PLI, PLI,
RTP, RTP,
SR,
} }
table EnableTraceEventRequest { table EnableTraceEventRequest {
...@@ -60,6 +61,7 @@ union TraceInfo { ...@@ -60,6 +61,7 @@ union TraceInfo {
FirTraceInfo, FirTraceInfo,
PliTraceInfo, PliTraceInfo,
RtpTraceInfo, RtpTraceInfo,
SrTraceInfo,
} }
table KeyFrameTraceInfo { table KeyFrameTraceInfo {
...@@ -80,6 +82,15 @@ table RtpTraceInfo { ...@@ -80,6 +82,15 @@ table RtpTraceInfo {
is_rtx: bool; is_rtx: bool;
} }
table SrTraceInfo {
ssrc: uint32;
ntp_sec: uint32;
ntp_frac: uint32;
rtp_ts: uint32;
packet_count: uint32;
octet_count: uint32;
}
table TraceNotification { table TraceNotification {
type: TraceEventType; type: TraceEventType;
timestamp: uint64; timestamp: uint64;
......
...@@ -89,6 +89,7 @@ namespace RTC ...@@ -89,6 +89,7 @@ namespace RTC
bool nack{ false }; bool nack{ false };
bool pli{ false }; bool pli{ false };
bool fir{ false }; bool fir{ false };
bool sr{ false };
}; };
public: public:
...@@ -160,6 +161,7 @@ namespace RTC ...@@ -160,6 +161,7 @@ namespace RTC
void EmitTraceEventPliType(uint32_t ssrc) const; void EmitTraceEventPliType(uint32_t ssrc) const;
void EmitTraceEventFirType(uint32_t ssrc) const; void EmitTraceEventFirType(uint32_t ssrc) const;
void EmitTraceEventNackType() const; void EmitTraceEventNackType() const;
void EmitTraceEventSrType(RTC::RTCP::SenderReport* report) const;
void EmitTraceEvent(flatbuffers::Offset<FBS::Producer::TraceNotification>& notification) const; void EmitTraceEvent(flatbuffers::Offset<FBS::Producer::TraceNotification>& notification) const;
/* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */ /* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */
......
...@@ -486,6 +486,12 @@ namespace RTC ...@@ -486,6 +486,12 @@ namespace RTC
{ {
newTraceEventTypes.rtp = true; newTraceEventTypes.rtp = true;
break;
}
case FBS::Producer::TraceEventType::SR:
{
newTraceEventTypes.sr = true;
break; break;
} }
} }
...@@ -706,6 +712,8 @@ namespace RTC ...@@ -706,6 +712,8 @@ namespace RTC
this->listener->OnProducerRtcpSenderReport(this, rtpStream, first); this->listener->OnProducerRtcpSenderReport(this, rtpStream, first);
EmitTraceEventSrType(report);
return; return;
} }
...@@ -1576,6 +1584,35 @@ namespace RTC ...@@ -1576,6 +1584,35 @@ namespace RTC
EmitTraceEvent(notification); 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( inline void Producer::EmitTraceEvent(
flatbuffers::Offset<FBS::Producer::TraceNotification>& notification) const flatbuffers::Offset<FBS::Producer::TraceNotification>& notification) const
{ {
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论