openpilot v0.9.6 release
date: 2024-01-12T10:13:37 master commit: ba792d576a49a0899b88a753fa1c52956bedf9e6
This commit is contained in:
27
teleoprtc/info.py
Normal file
27
teleoprtc/info.py
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
import dataclasses
|
||||
|
||||
import aiortc
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class StreamingMediaInfo:
|
||||
n_expected_camera_tracks: int
|
||||
expected_audio_track: bool
|
||||
incoming_audio_track: bool
|
||||
incoming_datachannel: bool
|
||||
|
||||
|
||||
def parse_info_from_offer(sdp: str) -> StreamingMediaInfo:
|
||||
"""
|
||||
helper function to parse info about outgoing and incoming streams from an offer sdp
|
||||
"""
|
||||
desc = aiortc.sdp.SessionDescription.parse(sdp)
|
||||
audio_tracks = [m for m in desc.media if m.kind == "audio"]
|
||||
video_tracks = [m for m in desc.media if m.kind == "video" and m.direction in ["recvonly", "sendrecv"]]
|
||||
application_tracks = [m for m in desc.media if m.kind == "application"]
|
||||
has_incoming_audio_track = next((t for t in audio_tracks if t.direction in ["sendonly", "sendrecv"]), None) is not None
|
||||
has_incoming_datachannel = len(application_tracks) > 0
|
||||
expects_outgoing_audio_track = next((t for t in audio_tracks if t.direction in ["recvonly", "sendrecv"]), None) is not None
|
||||
|
||||
return StreamingMediaInfo(len(video_tracks), expects_outgoing_audio_track, has_incoming_audio_track, has_incoming_datachannel)
|
||||
Reference in New Issue
Block a user