From 42a6f4d0915b1160a34a8ac52079b76b90d57bf8 Mon Sep 17 00:00:00 2001 From: Scott Lamb Date: Mon, 22 Jun 2020 00:38:23 -0700 Subject: [PATCH] API change: cameraConfigs should include rtsp urls --- design/api.md | 10 +++++++--- src/json.rs | 22 +++++++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/design/api.md b/design/api.md index eeedf3d..d7c6415 100644 --- a/design/api.md +++ b/design/api.md @@ -53,9 +53,10 @@ request parameters: * `days`: a boolean indicating if the days parameter described below should be included. -* `cameraConfigs`: a boolean indicating if the `camera.config` parameter - described below should be included. This requires the - `read_camera_configs` permission as described in `schema.proto`. +* `cameraConfigs`: a boolean indicating if the `camera.config` and + `camera.stream[].config` parameters described below should be included. + This requires the `read_camera_configs` permission as described in + `schema.proto`. Example request URI (with added whitespace between parameters): @@ -104,6 +105,9 @@ The `application/json` response will have a dict as follows: time zone. It is usually 24 hours after the start time. It might be 23 hours or 25 hours during spring forward or fall back, respectively. + * `config`: (only included if request parameter `cameraConfigs` is + true) a dictionary describing the configuration of the stream: + * `rtsp_url` * `signals`: a list of all signals known to the server. Each is a dictionary with the following properties: * `id`: an integer identifier. diff --git a/src/json.rs b/src/json.rs index 3ef695c..1e82824 100644 --- a/src/json.rs +++ b/src/json.rs @@ -110,6 +110,15 @@ pub struct Stream<'a> { #[serde(skip_serializing_if = "Option::is_none")] #[serde(serialize_with = "Stream::serialize_days")] pub days: Option<&'a BTreeMap>, + + #[serde(skip_serializing_if = "Option::is_none")] + pub config: Option>, +} + +#[derive(Debug, Serialize)] +#[serde(rename_all="camelCase")] +pub struct StreamConfig<'a> { + pub rtsp_url: &'a str, } #[derive(Serialize)] @@ -203,8 +212,8 @@ impl<'a> Camera<'a> { }), }, streams: [ - Stream::wrap(db, c.streams[0], include_days)?, - Stream::wrap(db, c.streams[1], include_days)?, + Stream::wrap(db, c.streams[0], include_days, include_config)?, + Stream::wrap(db, c.streams[1], include_days, include_config)?, ], }) } @@ -223,7 +232,8 @@ impl<'a> Camera<'a> { } impl<'a> Stream<'a> { - fn wrap(db: &'a db::LockedDatabase, id: Option, include_days: bool) -> Result, Error> { + fn wrap(db: &'a db::LockedDatabase, id: Option, include_days: bool, include_config: bool) + -> Result, Error> { let id = match id { Some(id) => id, None => return Ok(None), @@ -236,6 +246,12 @@ impl<'a> Stream<'a> { total_duration_90k: s.duration.0, total_sample_file_bytes: s.sample_file_bytes, days: if include_days { Some(&s.days) } else { None }, + config: match include_config { + false => None, + true => Some(StreamConfig { + rtsp_url: &s.rtsp_url, + }), + }, })) }