From fdabdb77347d4b5178a5e8efeeaee2f1c88e78a5 Mon Sep 17 00:00:00 2001 From: Wojciech Kozyra Date: Mon, 4 Nov 2024 12:45:15 +0100 Subject: [PATCH] fix examples --- .../src/scene/rescaler_component/layout.rs | 7 +- .../examples/rescaler_border_transition.rs | 154 ++++++++++++++++++ ...ansition2.rs => view_border_transition.rs} | 57 ++++--- 3 files changed, 184 insertions(+), 34 deletions(-) create mode 100644 integration_tests/examples/rescaler_border_transition.rs rename integration_tests/examples/{transition2.rs => view_border_transition.rs} (74%) diff --git a/compositor_render/src/scene/rescaler_component/layout.rs b/compositor_render/src/scene/rescaler_component/layout.rs index 57ecc659e..7127ff103 100644 --- a/compositor_render/src/scene/rescaler_component/layout.rs +++ b/compositor_render/src/scene/rescaler_component/layout.rs @@ -1,7 +1,5 @@ use std::time::Duration; -use log::info; - use crate::{ scene::{ layout::StatefulLayoutComponent, BorderRadius, HorizontalAlign, RGBAColor, RescaleMode, @@ -76,7 +74,6 @@ impl RescalerComponentParam { } ref _non_layout => (StatefulLayoutComponent::layout_content(child, 0), vec![], 1), }; - info!("Rescaler child {content:#?} {children:#?}"); let top = match self.vertical_align { VerticalAlign::Top => 0.0, @@ -130,8 +127,8 @@ impl RescalerComponentParam { children: vec![NestedLayout { top: top + self.border_width, left: left + self.border_width, - width: width, - height: height, + width, + height, rotation_degrees: 0.0, scale_x: scale, scale_y: scale, diff --git a/integration_tests/examples/rescaler_border_transition.rs b/integration_tests/examples/rescaler_border_transition.rs new file mode 100644 index 000000000..5e38a5b2e --- /dev/null +++ b/integration_tests/examples/rescaler_border_transition.rs @@ -0,0 +1,154 @@ +use anyhow::Result; +use compositor_api::types::Resolution; +use serde_json::json; +use std::{ + thread::{self}, + time::Duration, +}; + +use integration_tests::{ + examples::{self, run_example, TestSample}, + ffmpeg::{start_ffmpeg_receive, start_ffmpeg_send}, +}; + +const VIDEO_RESOLUTION: Resolution = Resolution { + width: 1280, + height: 720, +}; + +const IP: &str = "127.0.0.1"; +const INPUT_PORT: u16 = 8002; +const OUTPUT_PORT: u16 = 8004; + +fn main() { + run_example(client_code); +} + +fn client_code() -> Result<()> { + start_ffmpeg_receive(Some(OUTPUT_PORT), None)?; + + examples::post( + "input/input_1/register", + &json!({ + "type": "rtp_stream", + "port": INPUT_PORT, + "video": { + "decoder": "ffmpeg_h264" + } + }), + )?; + + examples::post( + "image/example_image/register", + &json!({ + "asset_type": "gif", + "url": "https://gifdb.com/images/high/rust-logo-on-fire-o41c0v9om8drr8dv.gif", + }), + )?; + + let scene1 = json!({ + "type": "view", + "background_color_rgba": "#42daf5ff", + "children": [ + { + "type": "rescaler", + "id": "resized", + "width": VIDEO_RESOLUTION.width, + "height": VIDEO_RESOLUTION.height, + "top": 0.0, + "right": 0.0, + "mode": "fill", + "border_color_rgba": "#FFFFFFFF", + "box_shadow": [ + { + "offset_y": 40, + "offset_x": 0, + "blur_radius": 40, + "color_rgba": "#00000088", + } + ], + "child": { + "type": "input_stream", + "input_id": "input_1" + } + } + ] + }); + + let scene2 = json!({ + "type": "view", + "background_color_rgba": "#42daf5ff", + "children": [ + { + "type": "rescaler", + "id": "resized", + "width": 300, + "height": 300, + "top": (VIDEO_RESOLUTION.height as f32 - 330.0) / 2.0 , + "right": (VIDEO_RESOLUTION.width as f32 - 330.0) / 2.0, + "mode": "fill", + "border_radius": 50, + "border_width": 15, + "border_color_rgba": "#FFFFFFFF", + "box_shadow": [ + { + "offset_y": 40, + "offset_x": 0, + "blur_radius": 40, + "color_rgba": "#00000088", + } + ], + "transition": { + "duration_ms": 1500, + "easing_function": { + "function_name": "cubic_bezier", + "points": [0.33, 1, 0.68, 1] + } + }, + "child": { + "type": "input_stream", + "input_id": "input_1" + } + } + ] + }); + + examples::post( + "output/output_1/register", + &json!({ + "type": "rtp_stream", + "ip": IP, + "port": OUTPUT_PORT, + "video": { + "resolution": { + "width": VIDEO_RESOLUTION.width, + "height": VIDEO_RESOLUTION.height, + }, + "encoder": { + "type": "ffmpeg_h264", + "preset": "ultrafast" + }, + "initial": { + "root": scene1 + } + } + }), + )?; + + examples::post("start", &json!({}))?; + + start_ffmpeg_send(IP, Some(INPUT_PORT), None, TestSample::TestPattern)?; + + thread::sleep(Duration::from_secs(5)); + + examples::post( + "output/output_1/update", + &json!({ + "video": { + "root": scene2, + } + }), + )?; + + Ok(()) +} diff --git a/integration_tests/examples/transition2.rs b/integration_tests/examples/view_border_transition.rs similarity index 74% rename from integration_tests/examples/transition2.rs rename to integration_tests/examples/view_border_transition.rs index f6b0f9331..72ed6f2fd 100644 --- a/integration_tests/examples/transition2.rs +++ b/integration_tests/examples/view_border_transition.rs @@ -12,8 +12,8 @@ use integration_tests::{ }; const VIDEO_RESOLUTION: Resolution = Resolution { - width: 640, - height: 360, + width: 1280, + height: 720, }; const IP: &str = "127.0.0.1"; @@ -53,25 +53,24 @@ fn client_code() -> Result<()> { { "type": "view", "id": "resized", - "width": VIDEO_RESOLUTION.width - 160, - "height": VIDEO_RESOLUTION.height - 90, - "top": 20.5, - "right": 20.5, - "border_width": 5, - "border_radius": 30, + "width": VIDEO_RESOLUTION.width, + "height": VIDEO_RESOLUTION.height, + "top": 0.0, + "right": 0.0, "background_color_rgba": "#0000FFFF", "border_color_rgba": "#FFFFFFFF", - "box_shadows": [ + "box_shadow": [ { - "offset_y": 60, - "offset_x": -60, - "blur_radius": 60, - "color_rgba": "#FFFF00FF", + "offset_y": 40, + "offset_x": 0, + "blur_radius": 40, + "color_rgba": "#00000088", } ], "children": [ { "type": "rescaler", + "mode": "fill", "child": { "type": "input_stream", "input_id": "input_1" @@ -89,28 +88,33 @@ fn client_code() -> Result<()> { { "type": "view", "id": "resized", - "width": VIDEO_RESOLUTION.width - 160*2, - "height": VIDEO_RESOLUTION.height - 90*2, - "top": 200.5, - "right": 200.5, + "width": 300, + "height": 300, + "top": (VIDEO_RESOLUTION.height as f32 - 330.0) / 2.0 , + "right": (VIDEO_RESOLUTION.width as f32 - 330.0) / 2.0, "border_radius": 50, - "border_width": 5, - "border_color_rgba": "#FFFF00FF", + "border_width": 15, "background_color_rgba": "#0000FFFF", - "box_shadows": [ + "border_color_rgba": "#FFFFFFFF", + "box_shadow": [ { - "offset_y": 60, - "offset_x": -60, + "offset_y": 40, + "offset_x": 0, "blur_radius": 40, - "color_rgba": "#FFFF00FF", + "color_rgba": "#00000088", } ], "transition": { - "duration_ms": 10000 + "duration_ms": 1500, + "easing_function": { + "function_name": "cubic_bezier", + "points": [0.33, 1, 0.68, 1] + } }, "children": [ { "type": "rescaler", + "mode": "fill", "child": { "type": "input_stream", "input_id": "input_1" @@ -124,8 +128,6 @@ fn client_code() -> Result<()> { examples::post( "output/output_1/register", &json!({ - //"type": "mp4", - //"path": "smooth2.mp4", "type": "rtp_stream", "ip": IP, "port": OUTPUT_PORT, @@ -160,8 +162,5 @@ fn client_code() -> Result<()> { }), )?; - // sleep(Duration::from_secs(12)); - // examples::post("output/output_1/unregister", &json!({}))?; - Ok(()) }