File: test_rtcrtptransceiver.py

package info (click to toggle)
python-aiortc 1.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 3,052 kB
  • sloc: python: 20,294; javascript: 321; makefile: 21; sh: 1
file content (50 lines) | stat: -rw-r--r-- 1,756 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from unittest import TestCase

from aiortc.rtcrtpparameters import RTCRtpCodecCapability
from aiortc.rtcrtptransceiver import RTCRtpTransceiver


class RTCRtpTransceiverTest(TestCase):
    def test_codec_preferences(self):
        transceiver = RTCRtpTransceiver("audio", None, None)
        self.assertEqual(transceiver._preferred_codecs, [])

        # set empty preferences
        transceiver.setCodecPreferences([])
        self.assertEqual(transceiver._preferred_codecs, [])

        # set single codec
        transceiver.setCodecPreferences(
            [RTCRtpCodecCapability(mimeType="audio/PCMU", clockRate=8000, channels=1)]
        )
        self.assertEqual(
            transceiver._preferred_codecs,
            [RTCRtpCodecCapability(mimeType="audio/PCMU", clockRate=8000, channels=1)],
        )

        # set single codec (duplicated)
        transceiver.setCodecPreferences(
            [
                RTCRtpCodecCapability(
                    mimeType="audio/PCMU", clockRate=8000, channels=1
                ),
                RTCRtpCodecCapability(
                    mimeType="audio/PCMU", clockRate=8000, channels=1
                ),
            ]
        )
        self.assertEqual(
            transceiver._preferred_codecs,
            [RTCRtpCodecCapability(mimeType="audio/PCMU", clockRate=8000, channels=1)],
        )

        # set single codec (invalid)
        with self.assertRaises(ValueError) as cm:
            transceiver.setCodecPreferences(
                [
                    RTCRtpCodecCapability(
                        mimeType="audio/bogus", clockRate=8000, channels=1
                    )
                ]
            )
        self.assertEqual(str(cm.exception), "Codec is not in capabilities")