def test_capabilities(self): # audio capabilities = RTCRtpSender.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(capabilities.headerExtensions, [ RTCRtpHeaderExtensionCapability( uri='urn:ietf:params:rtp-hdrext:sdes:mid'), ]) # video capabilities = RTCRtpSender.getCapabilities('video') self.assertTrue(isinstance(capabilities, RTCRtpCapabilities)) self.assertEqual(capabilities.codecs, [ RTCRtpCodecCapability(mimeType='video/VP8', clockRate=90000), RTCRtpCodecCapability(mimeType='video/rtx', clockRate=90000), RTCRtpCodecCapability(mimeType='video/H264', clockRate=90000, parameters=OrderedDict( [('packetization-mode', '1'), ('level-asymmetry-allowed', '1'), ('profile-level-id', '42001f')])), RTCRtpCodecCapability(mimeType='video/H264', clockRate=90000, parameters=OrderedDict( [('packetization-mode', '1'), ('level-asymmetry-allowed', '1'), ('profile-level-id', '42e01f')])), ]) self.assertEqual( capabilities.headerExtensions, [ RTCRtpHeaderExtensionCapability( uri='urn:ietf:params:rtp-hdrext:sdes:mid'), RTCRtpHeaderExtensionCapability( uri= 'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time' ), # noqa ]) # bogus capabilities = RTCRtpSender.getCapabilities('bogus') self.assertIsNone(capabilities)
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")
gi.require_version('Gst', '1.0') from gi.repository import Gst RATE = 15 ROOT = os.path.dirname(__file__) camera = None capabilities = RTCRtpSender.getCapabilities("video") codec_parameters = OrderedDict([ ("packetization-mode", "1"), ("level-asymmetry-allowed", "1"), ("profile-level-id", "42001f"), ]) h264_capability = RTCRtpCodecCapability(mimeType="video/H264", clockRate=90000, channels=None, parameters=codec_parameters) preferences = [h264_capability] rtsp_input = None webcam_input = None class GstH264Camera: WEBCAM_PIPELINE = "v4l2src device=/dev/{} ! video/x-h264,width=1280,height=720,framerate={}/1 ! queue ! appsink emit-signals=True name=h264_sink" RTSP_PIPELINE = "rtspsrc location={} latency=0 ! rtph264depay ! queue ! h264parse ! video/x-h264,alignment=nal,stream-format=byte-stream ! appsink emit-signals=True name=h264_sink" #RTSP_PIPELINE = "rtspsrc location={} latency=0 ! rtph264depay ! queue ! video/x-h264,alignment=nal,stream-format=byte-stream ! appsink emit-signals=True name=h264_sink" def __init__(self, rate, output, rtsp_input=None, webcam_input=None): if rtsp_input is not None and webcam_input is not None: raise Exception("Only one inupt can be used at once")
def test_capabilities(self): # audio capabilities = RTCRtpSender.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( capabilities.headerExtensions, [ RTCRtpHeaderExtensionCapability( uri="urn:ietf:params:rtp-hdrext:sdes:mid") ], ) # video capabilities = RTCRtpSender.getCapabilities("video") self.assertTrue(isinstance(capabilities, RTCRtpCapabilities)) self.assertEqual( capabilities.codecs, [ RTCRtpCodecCapability(mimeType="video/VP8", clockRate=90000), RTCRtpCodecCapability(mimeType="video/rtx", clockRate=90000), RTCRtpCodecCapability( mimeType="video/H264", clockRate=90000, parameters=OrderedDict([ ("packetization-mode", "1"), ("level-asymmetry-allowed", "1"), ("profile-level-id", "42001f"), ]), ), RTCRtpCodecCapability( mimeType="video/H264", clockRate=90000, parameters=OrderedDict([ ("packetization-mode", "1"), ("level-asymmetry-allowed", "1"), ("profile-level-id", "42e01f"), ]), ), ], ) self.assertEqual( capabilities.headerExtensions, [ RTCRtpHeaderExtensionCapability( uri="urn:ietf:params:rtp-hdrext:sdes:mid"), RTCRtpHeaderExtensionCapability( uri= "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time" ), ], ) # bogus with self.assertRaises(ValueError): RTCRtpSender.getCapabilities("bogus")