Skip to content

Commit

Permalink
Better RTSP protocol handling (#253)
Browse files Browse the repository at this point in the history
* Better RTSP protocol handling

* better docstring

* apply formatting

* Apply suggestions from code review

* apply formatting to new suggestions

---------

Co-authored-by: Martin Hjelmare <[email protected]>
  • Loading branch information
regulad and MartinHjelmare authored Sep 10, 2024
1 parent c00b346 commit ee3efb4
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pydroid_ipcam/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""PyDroidIPCam API for the Android IP Webcam app."""

import asyncio
from typing import Any, Dict, List, Optional, Union, cast
from typing import Any, Dict, List, Optional, Union, cast, Literal

import aiohttp
from yarl import URL
Expand Down Expand Up @@ -63,10 +63,25 @@ def audio_opus_url(self) -> str:
"""Return url that LibOPUS audio can be streamed from."""
return f"{self.base_url}/audio.opus"

def get_rtsp_url(
self,
video_codec: Literal["jpeg", "h264"] = "h264",
audio_codec: Literal["ulaw", "alaw", "pcm", "opus", "aac"] = "opus",
) -> str:
"""Return the RTSP URL for a given pair of video & audio codecs.
Use the developer-recommended h264 & opus if no arguments are supplied.
"""
rtsp_protocol = "rtsps" if self._ssl else "rtsp"
return (
f"{rtsp_protocol}://{self._host}:{self._port}/"
f"{video_codec}_{audio_codec}.sdp"
)

@property
def h264_url(self) -> str:
"""Return h264 url."""
return f"rtsp://{self._host}:{self._port}/h264_pcm.sdp"
return self.get_rtsp_url("h264", "pcm")

@property
def image_url(self) -> str:
Expand Down

0 comments on commit ee3efb4

Please sign in to comment.