Skip to content

Commit

Permalink
rtcp count
Browse files Browse the repository at this point in the history
  • Loading branch information
byyam committed Aug 8, 2024
1 parent c20ec6e commit facc822
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
25 changes: 15 additions & 10 deletions monitor/count.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,28 @@ func IceCount(direction DirectionType, packet PacketType) {

// key frame count
const (
KeyframePkgRecv = "key_frame_recv"
KeyframePkgSend = "key_frame_send"
KeyframeRecvFIR = "recv_rtcp_fir"
KeyframeRecvPLI = "recv_rtcp_pli"
KeyframeSendFIR = "send_rtcp_fir"
KeyframeSendPLI = "send_rtcp_pli"
KeyframePkgRecv = "key_frame_recv"
KeyframePkgSend = "key_frame_send"
KeyframeRecvFIR = "recv_rtcp_fir"
KeyframeRecvPLI = "recv_rtcp_pli"
KeyframeSendFIR = "send_rtcp_fir"
KeyframeSendPLI = "send_rtcp_pli"
RtcpRecvNack = "recv_rtcp_nack"
RtcpRecvRemb = "recv_rtcp_remb"
RtcpSenderReport = "recv_rtcp_sr"
RtcpReceiverReport = "recv_rtcp_rr"
RtcpReceiverTransportLayerCC = "recv_rtcp_tcc"
)

var (
keyframeCount = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "keyframe",
rtcpSSRCCount = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "rtcp_ssrc",
Name: "count",
}, []string{"ssrc", "event"})
)

func KeyframeCount(ssrc uint32, event string) {
keyframeCount.WithLabelValues(fmt.Sprintf("%d", ssrc), event).Inc()
func RtcpCountBySSRC(ssrc uint32, event string) {
rtcpSSRCCount.WithLabelValues(fmt.Sprintf("%d", ssrc), event).Inc()
}

// mediasoup count
Expand Down
5 changes: 4 additions & 1 deletion monitor/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func register() {
prometheus.MustRegister(rtcpCount)
prometheus.MustRegister(iceCount)
prometheus.MustRegister(mediasoupCount)
prometheus.MustRegister(keyframeCount)
prometheus.MustRegister(rtcpSSRCCount)
}

type DirectionType string
Expand Down Expand Up @@ -44,6 +44,9 @@ const (
TraceVideo TraceType = "video"
TraceRtpStream TraceType = "rtp_stream"
TraceRtpRtxStream TraceType = "rtp_rtx_stream"
// rtcp type
TraceRtcpSourceDescription TraceType = "rtcp_source_description"
TraceRtcpGoodbye TraceType = "rtcp_goodbye"
)

type EventType string
Expand Down
2 changes: 1 addition & 1 deletion rtc/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (p *Producer) init(param producerParam) error {

func (p *Producer) ReceiveRtpPacket(packet *rtpparser.Packet) (result ReceiveRtpPacketResult) {
if p.Kind == FBS__RtpParameters.MediaKindVIDEO && packet.IsKeyFrame() {
monitor.KeyframeCount(packet.SSRC, monitor.KeyframePkgRecv)
monitor.RtcpCountBySSRC(packet.SSRC, monitor.KeyframePkgRecv)
p.logger.Debug().Msg("isKeyFrame")
}
if p.Kind == FBS__RtpParameters.MediaKindVIDEO {
Expand Down
4 changes: 2 additions & 2 deletions rtc/rtp_stream_recv.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ func (r *RtpStreamRecv) RequestKeyFrame() {
SenderSSRC: r.GetSsrc(),
MediaSSRC: r.GetSsrc(),
}
monitor.KeyframeCount(r.GetSsrc(), monitor.KeyframeSendPLI)
monitor.RtcpCountBySSRC(r.GetSsrc(), monitor.KeyframeSendPLI)
r.onRtpStreamSendRtcpPacketHandler(packet)
} else if r.params.UseFir {
packet := &rtcp.FullIntraRequest{
SenderSSRC: r.GetSsrc(),
MediaSSRC: r.GetSsrc(),
}
monitor.KeyframeCount(r.GetSsrc(), monitor.KeyframeSendFIR)
monitor.RtcpCountBySSRC(r.GetSsrc(), monitor.KeyframeSendFIR)
r.onRtpStreamSendRtcpPacketHandler(packet)
}
}
Expand Down
11 changes: 9 additions & 2 deletions rtc/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ func (t *Transport) HandleRtcpPacket(header *rtcp.Header, packet rtcp.Packet) {
switch packet.(type) {
case *rtcp.SenderReport:
pkg := packet.(*rtcp.SenderReport)
monitor.RtcpCountBySSRC(pkg.SSRC, monitor.RtcpSenderReport)
for _, sr := range pkg.Reports {
t.logger.Debug().Msgf("handle SR:%s,report:%+v", pkg.String(), sr)
producer := t.rtpListener.GetProducerBySSRC(sr.SSRC)
Expand All @@ -615,6 +616,7 @@ func (t *Transport) HandleRtcpPacket(header *rtcp.Header, packet rtcp.Packet) {
}
case *rtcp.ReceiverReport:
pkg := packet.(*rtcp.ReceiverReport)
monitor.RtcpCountBySSRC(pkg.SSRC, monitor.RtcpReceiverReport)
for _, rr := range pkg.Reports {
t.logger.Debug().Msgf("handle RR:%s,report:%+v", pkg.String(), rr)
// Special case for the RTP probator.
Expand All @@ -639,25 +641,29 @@ func (t *Transport) HandleRtcpPacket(header *rtcp.Header, packet rtcp.Packet) {
// todo
}
case *rtcp.SourceDescription:
monitor.RtcpRecvCount(monitor.TraceRtcpSourceDescription)
pkg := packet.(*rtcp.SourceDescription)
t.logger.Debug().Msgf("%s", pkg.String())
case *rtcp.Goodbye:
monitor.RtcpRecvCount(monitor.TraceRtcpGoodbye)
pkg := packet.(*rtcp.Goodbye)
t.logger.Debug().Msgf("ignoring received RTCP BYE %s", pkg.String())
case *rtcp.FullIntraRequest:
pkg := packet.(*rtcp.FullIntraRequest)
t.ReceiveKeyFrameRequest(header.Count, pkg.MediaSSRC)
monitor.KeyframeCount(pkg.MediaSSRC, monitor.KeyframeRecvFIR)
monitor.RtcpCountBySSRC(pkg.MediaSSRC, monitor.KeyframeRecvFIR)
case *rtcp.PictureLossIndication:
pkg := packet.(*rtcp.PictureLossIndication)
t.ReceiveKeyFrameRequest(header.Count, pkg.MediaSSRC)
monitor.KeyframeCount(pkg.MediaSSRC, monitor.KeyframeRecvPLI)
monitor.RtcpCountBySSRC(pkg.MediaSSRC, monitor.KeyframeRecvPLI)
case *rtcp.ReceiverEstimatedMaximumBitrate:
pkg := packet.(*rtcp.ReceiverEstimatedMaximumBitrate)
t.logger.Debug().Msgf("%s", pkg.String())
monitor.RtcpCountBySSRC(pkg.SenderSSRC, monitor.RtcpRecvRemb)
case *rtcp.TransportLayerNack:
pkg := packet.(*rtcp.TransportLayerNack)
t.logger.Debug().Msgf("TransportLayerNack:%+v", pkg)
monitor.RtcpCountBySSRC(pkg.MediaSSRC, monitor.RtcpRecvNack)
consumer, ok := t.mapSsrcConsumer.Load(pkg.MediaSSRC)
if !ok {
t.logger.Warn().Msgf("no Consumer found for received NACK Feedback packet [sender ssrc:%d, media ssrc:%d]", pkg.SenderSSRC, pkg.MediaSSRC)
Expand All @@ -668,6 +674,7 @@ func (t *Transport) HandleRtcpPacket(header *rtcp.Header, packet rtcp.Packet) {
case *rtcp.TransportLayerCC:
pkg := packet.(*rtcp.TransportLayerCC)
t.logger.Info().Msgf("TransportLayerCC:%+v", pkg)
monitor.RtcpCountBySSRC(pkg.MediaSSRC, monitor.RtcpReceiverTransportLayerCC)
default:
monitor.RtcpRecvCount(monitor.TraceUnknownRtcpType)
t.logger.Warn().Msgf("unhandled RTCP type received %+v", header)
Expand Down
1 change: 0 additions & 1 deletion rtc/webrtc_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ func (t *WebrtcTransport) OnRtcpDataReceived(rawData []byte) {
t.logger.Error().Err(err).Msg("rtcp.Unmarshal failed")
return
}
monitor.RtcpRecvCount(monitor.TraceReceive)
t.ITransport.ReceiveRtcpPacket(decryptHeader, packets)
}

Expand Down

0 comments on commit facc822

Please sign in to comment.