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

Add port argument to Set Preview Stream in Python SDK #513

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,20 @@ async def load_preset_group(self, *, group: proto.EnumPresetGroup.ValueType) ->
"""
return {"id": group} # type: ignore

@http_get_json_command(endpoint="gopro/camera/stream", components=["mode"], identifier="Preview Stream")
async def set_preview_stream(self, *, mode: Params.Toggle) -> GoProResp[None]:
@http_get_json_command(
endpoint="gopro/camera/stream", arguments=["port"], components=["mode"], identifier="Preview Stream"
)
async def set_preview_stream(self, *, mode: Params.Toggle, port: int | None = None) -> GoProResp[None]:
"""Start or stop the preview stream

Args:
mode (open_gopro.api.params.Toggle): enable to start or disable to stop
port (int): Port to use for Preview Stream. Defaults to 8554 if None. Only relevant when starting the stream.

Returns:
GoProResp: command status
"""
return {"mode": "start" if mode is Params.Toggle.ENABLE else "stop"} # type: ignore
return {"mode": "start" if mode is Params.Toggle.ENABLE else "stop", "port": port} # type: ignore

@http_get_json_command(endpoint="gopro/camera/analytics/set_client_info")
async def set_third_party_client_info(self) -> GoProResp[None]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ async def main(args: argparse.Namespace) -> None:
async with WirelessGoPro(args.identifier) as gopro:
await gopro.http_command.set_preview_stream(mode=Params.Toggle.DISABLE)
await gopro.ble_command.set_shutter(shutter=Params.Toggle.DISABLE)
assert (await gopro.http_command.set_preview_stream(mode=Params.Toggle.ENABLE)).ok
assert (await gopro.http_command.set_preview_stream(mode=Params.Toggle.ENABLE, port=args.port)).ok

console.print("Displaying the preview stream...")
display_video_blocking(r"udp://127.0.0.1:8554", printer=console.print)
display_video_blocking(f"udp://127.0.0.1:{args.port}", printer=console.print)

await gopro.http_command.set_preview_stream(mode=Params.Toggle.DISABLE)

Expand All @@ -34,6 +34,9 @@ def parse_arguments() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="Connect to the GoPro via BLE and Wifi, start a preview stream, then display it with CV2."
)
parser.add_argument(
"--port", type=int, help="Port to use for livestream. Defaults to 8554 if not set", default=8554
)
return add_cli_args_and_parse(parser, wifi=False)


Expand Down
Loading