Skip to content

Commit

Permalink
Add port argument to Set Preview Stream in Python SDK (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcamise-gpsw authored Apr 11, 2024
1 parent 32a335a commit 58eb0c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
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

0 comments on commit 58eb0c7

Please sign in to comment.