async def test_handle_rtcp_remb(self): async with dummy_dtls_transport_pair() as (local_transport, _): sender = RTCRtpSender(VideoStreamTrack(), local_transport) self.assertEqual(sender.kind, "video") await sender.send(RTCRtpParameters(codecs=[VP8_CODEC])) # receive RTCP feedback REMB packet = RtcpPsfbPacket( fmt=RTCP_PSFB_APP, ssrc=1234, media_ssrc=0, fci=pack_remb_fci(4160000, [sender._ssrc]), ) await sender._handle_rtcp_packet(packet) # receive RTCP feedback REMB (malformed) packet = RtcpPsfbPacket(fmt=RTCP_PSFB_APP, ssrc=1234, media_ssrc=0, fci=b"JUNK") await sender._handle_rtcp_packet(packet) # clean shutdown await sender.stop()
def test_pack_remb_fci(self): # exponent = 0, mantissa = 0 data = pack_remb_fci(0, [2529072847]) self.assertEqual(data, b"REMB\x01\x00\x00\x00\x96\xbe\x96\xcf") # exponent = 0, mantissa = 0x3ffff data = pack_remb_fci(0x3FFFF, [2529072847]) self.assertEqual(data, b"REMB\x01\x03\xff\xff\x96\xbe\x96\xcf") # exponent = 1, mantissa = 0 data = pack_remb_fci(0x40000, [2529072847]) self.assertEqual(data, b"REMB\x01\x06\x00\x00\x96\xbe\x96\xcf") data = pack_remb_fci(4160000, [2529072847]) self.assertEqual(data, b"REMB\x01\x13\xf7\xa0\x96\xbe\x96\xcf") # exponent = 63, mantissa = 0x3ffff data = pack_remb_fci(0x3FFFF << 63, [2529072847]) self.assertEqual(data, b"REMB\x01\xff\xff\xff\x96\xbe\x96\xcf")
def test_route_rtcp(self): receiver = object() sender = object() router = RtpRouter() router.register_receiver(receiver, ssrcs=[1234, 2345], payload_types=[96, 97]) router.register_sender(sender, ssrc=3456) # BYE packet = RtcpByePacket(sources=[1234, 2345]) self.assertEqual(router.route_rtcp(packet), set([receiver])) # RR packet = RtcpRrPacket( ssrc=1234, reports=[ RtcpReceiverInfo( ssrc=3456, fraction_lost=0, packets_lost=0, highest_sequence=630, jitter=1906, lsr=0, dlsr=0, ) ], ) self.assertEqual(router.route_rtcp(packet), set([sender])) # SR packet = RtcpSrPacket( ssrc=1234, sender_info=RtcpSenderInfo( ntp_timestamp=0, rtp_timestamp=0, packet_count=0, octet_count=0 ), reports=[ RtcpReceiverInfo( ssrc=3456, fraction_lost=0, packets_lost=0, highest_sequence=630, jitter=1906, lsr=0, dlsr=0, ) ], ) self.assertEqual(router.route_rtcp(packet), set([receiver, sender])) # PSFB - PLI packet = RtcpPsfbPacket(fmt=RTCP_PSFB_PLI, ssrc=1234, media_ssrc=3456) self.assertEqual(router.route_rtcp(packet), set([sender])) # PSFB - REMB packet = RtcpPsfbPacket( fmt=RTCP_PSFB_APP, ssrc=1234, media_ssrc=0, fci=pack_remb_fci(4160000, [3456]), ) self.assertEqual(router.route_rtcp(packet), set([sender])) # PSFB - JUNK packet = RtcpPsfbPacket(fmt=RTCP_PSFB_APP, ssrc=1234, media_ssrc=0, fci=b"JUNK") self.assertEqual(router.route_rtcp(packet), set()) # RTPFB packet = RtcpRtpfbPacket(fmt=RTCP_RTPFB_NACK, ssrc=1234, media_ssrc=3456) self.assertEqual(router.route_rtcp(packet), set([sender]))