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> =
/**
* 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.
......@@ -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}`);
......@@ -738,6 +743,11 @@ function producerTraceEventTypeFromFbs(eventType: FbsProducer.TraceEventType)
{
return 'rtp';
}
case FbsProducer.TraceEventType.SR:
{
return 'sr';
}
}
}
......
......@@ -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};
......@@ -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 @@
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,
......@@ -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 {
......@@ -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)
},
},
}
}
}
......@@ -465,6 +487,8 @@ pub enum ProducerTraceEventType {
Pli,
/// RTCP FIR packet.
Fir,
/// RTCP Sender report.
SR,
}
impl ProducerTraceEventType {
......@@ -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,
}
}
......@@ -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,
}
}
}
......
......@@ -11,6 +11,7 @@ enum TraceEventType: uint8 {
NACK,
PLI,
RTP,
SR,
}
table EnableTraceEventRequest {
......@@ -60,6 +61,7 @@ union TraceInfo {
FirTraceInfo,
PliTraceInfo,
RtpTraceInfo,
SrTraceInfo,
}
table KeyFrameTraceInfo {
......@@ -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;
......
......@@ -89,6 +89,7 @@ namespace RTC
bool nack{ false };
bool pli{ false };
bool fir{ false };
bool sr{ false };
};
public:
......@@ -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. */
......
......@@ -486,6 +486,12 @@ namespace RTC
{
newTraceEventTypes.rtp = true;
break;
}
case FBS::Producer::TraceEventType::SR:
{
newTraceEventTypes.sr = true;
break;
}
}
......@@ -706,6 +712,8 @@ namespace RTC
this->listener->OnProducerRtcpSenderReport(this, rtpStream, first);
EmitTraceEventSrType(report);
return;
}
......@@ -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
{
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论