Skip to content

Commit

Permalink
Add sender report trace event
Browse files Browse the repository at this point in the history
  • Loading branch information
GithubUser8080 committed Dec 15, 2023
1 parent bc55f22 commit e6b9762
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
6 changes: 5 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 @@ -670,6 +670,8 @@ function producerTraceEventTypeToFbs(eventType: ProducerTraceEventType)
return FbsProducer.TraceEventType.PLI;
case 'rtp':
return FbsProducer.TraceEventType.RTP;
case 'sr':
return FbsProducer.TraceEventType.SR;
default:
throw new TypeError(`invalid ProducerTraceEventType: ${eventType}`);
}
Expand All @@ -690,6 +692,8 @@ function producerTraceEventTypeFromFbs(eventType: FbsProducer.TraceEventType)
return 'pli';
case FbsProducer.TraceEventType.RTP:
return 'rtp';
case FbsProducer.TraceEventType.SR:
return '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

0 comments on commit e6b9762

Please sign in to comment.