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

Added option to completely skip RTSP Discovery in autodiscover() #47

Merged
merged 12 commits into from
Jul 22, 2024
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "framegrab"
version = "0.5.4"
version = "0.5.5"
description = "Easily grab frames from cameras or streams"
authors = ["Groundlight <info@groundlight.ai>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/framegrab/cli/autodiscover.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@click.option(
"--rtsp_discover_modes",
type=click.Choice(PREVIEW_RTSP_COMMAND_CHOICES, case_sensitive=False),
default="light",
default="disable",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to set it to disable since we don't want to guess passwords by default.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do want to guess passwords in autodiscover. Without the password, we cannot connect to the grabber, which is the point of the autodiscover, right? I guess there is the question of how thorough we are with our password guessing; maybe that should be an option?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, the mode light should be alright but other modes such as complete_fast and complete_slow may cause you to exceed the number of attempts before the camera blocks you.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, but 'disable' is a weird choice for the default. 'disable' implies the default should be to search for rtsp urls and we're going out of our way to turn it off. 'off' or 'none' would make more sense to me

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I agree, off would be a better naming for this.

show_default=True,
)
def autodiscover(preview: str, rtsp_discover_modes: str = "light"):
Expand Down
35 changes: 18 additions & 17 deletions src/framegrab/grabber.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,7 @@ def create_grabber(config: dict, autogenerate_name: bool = True, warmup_delay: f
return grabber

@staticmethod
def autodiscover(
warmup_delay: float = 1.0, rtsp_discover_modes: AutodiscoverModes = AutodiscoverModes.light
) -> dict:
def autodiscover(warmup_delay: float = 1.0, rtsp_discover_modes: Union[AutodiscoverModes, None] = None) -> dict:
"""Autodiscovers cameras and returns a dictionary of FrameGrabber objects

warmup_delay (float, optional): The number of seconds to wait after creating the grabbers. USB
Expand All @@ -290,7 +288,8 @@ def autodiscover(
light: Only try first two usernames and passwords ("admin:admin" and no username/password).
complete_fast: Try the entire DEFAULT_CREDENTIALS without delays in between.
complete_slow: Try the entire DEFAULT_CREDENTIALS with a delay of 1 seconds in between.
Defaults to AutodiscoverModes.light.
None: Will not search for rtsp streams
Defaults to None.
"""
autodiscoverable_input_types = (
InputTypes.REALSENSE,
Expand All @@ -304,20 +303,22 @@ def autodiscover(
for input_type in autodiscoverable_input_types:
logger.info(f"Autodiscovering {input_type} cameras...")

# If the input type is RTSP and rtsp_discover_modes is provided, use RTSPDiscovery to find the cameras
if input_type == InputTypes.RTSP:
onvif_devices = RTSPDiscovery.discover_onvif_devices(auto_discover_modes=rtsp_discover_modes)
for device in onvif_devices:
for index, rtsp_url in enumerate(device.rtsp_urls):
grabber = FrameGrabber.create_grabber(
{
"input_type": input_type,
"id": {"rtsp_url": rtsp_url},
"name": f"RTSP Camera - {device.ip} - {index}",
},
autogenerate_name=False,
warmup_delay=0,
)
grabber_list.append(grabber)
if rtsp_discover_modes is not None:
onvif_devices = RTSPDiscovery.discover_onvif_devices(auto_discover_modes=rtsp_discover_modes)
for device in onvif_devices:
for index, rtsp_url in enumerate(device.rtsp_urls):
grabber = FrameGrabber.create_grabber(
{
"input_type": input_type,
"id": {"rtsp_url": rtsp_url},
"name": f"RTSP Camera - {device.ip} - {index}",
},
autogenerate_name=False,
warmup_delay=0,
)
grabber_list.append(grabber)
continue

for _ in range(
Expand Down
Loading