diff --git a/http-video-streaming/http-video-streaming-types/src/lib.rs b/http-video-streaming/http-video-streaming-types/src/lib.rs index bd307321e..6df8d130d 100644 --- a/http-video-streaming/http-video-streaming-types/src/lib.rs +++ b/http-video-streaming/http-video-streaming-types/src/lib.rs @@ -20,7 +20,6 @@ pub struct Point { pub struct ToClient { pub fno: u64, pub firehose_frame_data_url: String, - pub found_points: Vec, /// Indicates which region of the entire image is "valid". /// /// For example, when tracking, there can be image regions in which tracking diff --git a/http-video-streaming/src/lib.rs b/http-video-streaming/src/lib.rs index a5020b9fa..d96ecd711 100644 --- a/http-video-streaming/src/lib.rs +++ b/http-video-streaming/src/lib.rs @@ -1,5 +1,6 @@ #![cfg_attr(feature = "backtrace", feature(error_generic_member_access))] +use http_video_streaming_types::StrokeStyle; use parking_lot::Mutex; use std::{collections::HashMap, sync::Arc}; @@ -47,6 +48,7 @@ struct PerSender { ready_to_send: bool, conn_key: ConnectionKey, fno: u64, + green_stroke: StrokeStyle, } fn _test_per_sender_is_send() { @@ -74,6 +76,7 @@ impl PerSender { ready_to_send: true, conn_key, fno: 0, + green_stroke: StrokeStyle::from_rgb(0x7F, 0xFF, 0x7F), } } fn push(&mut self, frame: Arc>) { @@ -106,12 +109,27 @@ impl PerSender { let firehose_frame_base64 = base64::encode(&bytes); let data_url = format!("data:image/jpeg;base64,{}", firehose_frame_base64); // most_recent_frame_data.data_url = Some(data_url.clone()); // todo: cache like this - let found_points = most_recent_frame_data.found_points.clone(); + let mut annotations = most_recent_frame_data.annotations.clone(); + // Convert found points into normal annotations. (This should perhaps be done earlier.) + for found_point in most_recent_frame_data.found_points.iter() { + dbg!(&found_point); + let line_width = 5.0; + let shape = Shape::Circle(CircleParams { + center_x: found_point.x.round() as i16, + center_y: found_point.y.round() as i16, + radius: 10, + }); + let green_shape = http_video_streaming_types::DrawableShape::from_shape( + &shape, + &self.green_stroke, + line_width, + ); + annotations.push(green_shape); + } ToClient { firehose_frame_data_url: data_url, - found_points, valid_display: most_recent_frame_data.valid_display.clone(), - annotations: most_recent_frame_data.annotations.clone(), + annotations, fno: self.fno, ts_rfc3339: sent_time.to_rfc3339(), ck: self.conn_key, diff --git a/strand-cam/yew_frontend/src/components/video_field.rs b/strand-cam/yew_frontend/src/components/video_field.rs index ad0681adb..2f1f0e95d 100644 --- a/strand-cam/yew_frontend/src/components/video_field.rs +++ b/strand-cam/yew_frontend/src/components/video_field.rs @@ -9,7 +9,7 @@ use yew::{classes, html, Callback, Component, Context, Html, MouseEvent, Propert use yew_tincture::components::{Button, CheckboxLabel}; -use http_video_streaming_types::{CanvasDrawableShape, CircleParams, Point, StrokeStyle}; +use http_video_streaming_types::{CanvasDrawableShape, CircleParams, StrokeStyle}; const PLAYING_FPS: f64 = 10.0; const PAUSED_FPS: f64 = 0.1; @@ -22,7 +22,6 @@ struct MouseCoords { #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] pub struct ImData2 { - pub found_points: Vec, pub draw_shapes: Vec, pub fno: u64, pub ts_rfc3339: String, // timestamp in RFC3339 format @@ -230,11 +229,12 @@ impl Component for VideoField { ); draw_shapes.push(green_shape); } + + let draw_shapes = draw_shapes.into_iter().map(|s| s.into()).collect(); let in_msg2 = ImData2 { fno: in_msg.fno, - found_points: in_msg.found_points, ts_rfc3339: in_msg.ts_rfc3339, - draw_shapes: draw_shapes.into_iter().map(|s| s.into()).collect(), + draw_shapes, }; // It seems that in some circumstances with yew 0.21.0, this @@ -423,31 +423,6 @@ impl VideoField { ctx.set_stroke_style(&self.green); ctx.set_line_width(1.0); - for pt in in_msg.found_points.iter() { - ctx.begin_path(); - ctx.arc( - // circle - pt.x as f64, - pt.y as f64, - 30.0, - 0.0, - std::f64::consts::PI * 2.0, - ) - .unwrap_throw(); - - let r: f64 = 30.0; - if let Some(theta) = pt.theta { - let theta = theta as f64; - let dx = r * theta.cos(); - let dy = r * theta.sin(); - ctx.move_to(pt.x as f64 - dx, pt.y as f64 - dy); - ctx.line_to(pt.x as f64 + dx, pt.y as f64 + dy); - } - - ctx.close_path(); - ctx.stroke(); - } - for drawable_shape in in_msg.draw_shapes.iter() { ctx.set_stroke_style(&drawable_shape.stroke_style.clone().into()); ctx.set_line_width(drawable_shape.line_width as f64);