Skip to content

Commit

Permalink
fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
wkozyra95 committed Nov 4, 2024
1 parent 5b9917e commit fdabdb7
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 34 deletions.
7 changes: 2 additions & 5 deletions compositor_render/src/scene/rescaler_component/layout.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::time::Duration;

use log::info;

use crate::{
scene::{
layout::StatefulLayoutComponent, BorderRadius, HorizontalAlign, RGBAColor, RescaleMode,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
154 changes: 154 additions & 0 deletions integration_tests/examples/rescaler_border_transition.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -160,8 +162,5 @@ fn client_code() -> Result<()> {
}),
)?;

// sleep(Duration::from_secs(12));
// examples::post("output/output_1/unregister", &json!({}))?;

Ok(())
}

0 comments on commit fdabdb7

Please sign in to comment.