Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better RTSP protocol handling #253

Merged
merged 5 commits into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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