How to use the aiortc.rtcrtpreceiver.RTCRtpReceiver function in aiortc

To help you get started, we’ve selected a few aiortc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aiortc / aiortc / tests / test_rtcrtpreceiver.py View on Github external
def test_rtp_empty_video_packet(self):
        receiver = RTCRtpReceiver("video", self.local_transport)
        self.assertEqual(receiver.transport, self.local_transport)

        receiver._track = RemoteStreamTrack(kind="video")
        run(receiver.receive(RTCRtpReceiveParameters(codecs=[VP8_CODEC])))

        # receive RTP with empty payload
        packet = RtpPacket(payload_type=100)
        run(receiver._handle_rtp_packet(packet, arrival_time_ms=0))

        # shutdown
        run(receiver.stop())
github aiortc / aiortc / tests / test_rtcrtpreceiver.py View on Github external
def test_connection_error(self):
        """
        Close the underlying transport before the receiver.
        """
        receiver = RTCRtpReceiver("audio", self.local_transport)
        self.assertEqual(receiver.transport, self.local_transport)

        receiver._track = RemoteStreamTrack(kind="audio")
        receiver._set_rtcp_ssrc(1234)
        run(receiver.receive(RTCRtpReceiveParameters(codecs=[PCMU_CODEC])))

        # receive a packet to prime RTCP
        packet = RtpPacket.parse(load("rtp.bin"))
        run(receiver._handle_rtp_packet(packet, arrival_time_ms=0))

        # break connection
        run(self.local_transport.stop())

        # give RTCP time to send a report
        run(asyncio.sleep(2))
github aiortc / aiortc / tests / test_rtcrtpreceiver.py View on Github external
def test_rtp_and_rtcp(self):
        receiver = RTCRtpReceiver("audio", self.local_transport)
        self.assertEqual(receiver.transport, self.local_transport)

        receiver._track = RemoteStreamTrack(kind="audio")
        self.assertEqual(receiver._track.readyState, "live")
        run(receiver.receive(RTCRtpReceiveParameters(codecs=[PCMU_CODEC])))

        # receive RTP
        for i in range(10):
            packet = RtpPacket.parse(load("rtp.bin"))
            packet.sequence_number += i
            packet.timestamp += i * 160
            run(receiver._handle_rtp_packet(packet, arrival_time_ms=i * 20))

        # receive RTCP SR
        for packet in RtcpPacket.parse(load("rtcp_sr.bin")):
            run(receiver._handle_rtcp_packet(packet))
github aiortc / aiortc / tests / test_rtcrtpreceiver.py View on Github external
def test_send_rtcp_pli(self):
        receiver = RTCRtpReceiver("video", self.local_transport)
        receiver._set_rtcp_ssrc(1234)
        receiver._track = RemoteStreamTrack(kind="video")

        run(receiver.receive(RTCRtpReceiveParameters(codecs=[VP8_CODEC])))

        # send RTCP feedback PLI
        run(receiver._send_rtcp_pli(5678))

        # shutdown
        run(receiver.stop())
github aiortc / aiortc / tests / test_rtcrtpreceiver.py View on Github external
def test_rtp_invalid_payload(self):
        receiver = RTCRtpReceiver("video", self.local_transport)
        self.assertEqual(receiver.transport, self.local_transport)

        receiver._track = RemoteStreamTrack(kind="video")
        run(receiver.receive(RTCRtpReceiveParameters(codecs=[VP8_CODEC])))

        # receive RTP with unknown payload type
        packet = RtpPacket(payload_type=100, payload=b"\x80")
        run(receiver._handle_rtp_packet(packet, arrival_time_ms=0))

        # shutdown
        run(receiver.stop())
github aiortc / aiortc / tests / test_rtcrtpreceiver.py View on Github external
def test_rtp_rtx(self):
        receiver = RTCRtpReceiver("video", self.local_transport)
        self.assertEqual(receiver.transport, self.local_transport)

        receiver._track = RemoteStreamTrack(kind="video")
        run(
            receiver.receive(
                RTCRtpReceiveParameters(
                    codecs=[
                        VP8_CODEC,
                        RTCRtpCodecParameters(
                            mimeType="video/rtx",
                            clockRate=90000,
                            payloadType=101,
                            parameters={"apt": 100},
                        ),
                    ],
                    encodings=[
github aiortc / aiortc / tests / test_rtcrtpreceiver.py View on Github external
def test_rtp_missing_video_packet(self):
        nacks = []

        async def mock_send_rtcp_nack(*args):
            nacks.append(args)

        receiver = RTCRtpReceiver("video", self.local_transport)
        self.assertEqual(receiver.transport, self.local_transport)

        receiver._send_rtcp_nack = mock_send_rtcp_nack
        receiver._track = RemoteStreamTrack(kind="video")
        run(receiver.receive(RTCRtpReceiveParameters(codecs=[VP8_CODEC])))

        # generate some packets
        packets = create_rtp_video_packets(self, codec=VP8_CODEC, frames=3)

        # receive RTP with a with a gap
        run(receiver._handle_rtp_packet(packets[0], arrival_time_ms=0))
        run(receiver._handle_rtp_packet(packets[2], arrival_time_ms=0))

        # check NACK was triggered
        self.assertEqual(nacks, [(1234, [1])])
github aiortc / aiortc / tests / test_rtcrtpreceiver.py View on Github external
def test_capabilities(self):
        # audio
        capabilities = RTCRtpReceiver.getCapabilities("audio")
        self.assertTrue(isinstance(capabilities, RTCRtpCapabilities))
        self.assertEqual(
            capabilities.codecs,
            [
                RTCRtpCodecCapability(
                    mimeType="audio/opus", clockRate=48000, channels=2
                ),
                RTCRtpCodecCapability(
                    mimeType="audio/PCMU", clockRate=8000, channels=1
                ),
                RTCRtpCodecCapability(
                    mimeType="audio/PCMA", clockRate=8000, channels=1
                ),
            ],
        )
        self.assertEqual(
github aiortc / aiortc / tests / test_rtcrtpreceiver.py View on Github external
def test_send_rtcp_nack(self):
        receiver = RTCRtpReceiver("video", self.local_transport)
        receiver._set_rtcp_ssrc(1234)
        receiver._track = RemoteStreamTrack(kind="video")

        run(receiver.receive(RTCRtpReceiveParameters(codecs=[VP8_CODEC])))

        # send RTCP feedback NACK
        run(receiver._send_rtcp_nack(5678, [7654]))

        # shutdown
        run(receiver.stop())
github aiortc / aiortc / tests / test_rtcrtpreceiver.py View on Github external
def test_rtp_rtx_unknown_ssrc(self):
        receiver = RTCRtpReceiver("video", self.local_transport)
        self.assertEqual(receiver.transport, self.local_transport)

        receiver._track = RemoteStreamTrack(kind="video")
        run(
            receiver.receive(
                RTCRtpReceiveParameters(
                    codecs=[
                        VP8_CODEC,
                        RTCRtpCodecParameters(
                            mimeType="video/rtx",
                            clockRate=90000,
                            payloadType=101,
                            parameters={"apt": 100},
                        ),
                    ]
                )