Skip to content

Commit

Permalink
Add function simplifying creating new test examples (#624)
Browse files Browse the repository at this point in the history
  • Loading branch information
brzep authored Jul 19, 2024
1 parent 4af2185 commit a3b1a1c
Show file tree
Hide file tree
Showing 25 changed files with 1,113 additions and 625 deletions.
1 change: 1 addition & 0 deletions compositor_pipeline/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub struct Queue {
clock: Clock,
}

#[derive(Debug)]
pub(super) struct QueueVideoOutput {
pub(super) pts: Duration,
pub(super) frames: HashMap<InputId, PipelineEvent<Frame>>,
Expand Down
6 changes: 5 additions & 1 deletion integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ license = "BUSL-1.1"
default = ["web_renderer"]
update_snapshots = []
decklink = ["live_compositor/decklink"]
web_renderer = ["dep:compositor_chromium", "live_compositor/web_renderer"]
web_renderer = [
"dep:compositor_chromium",
"compositor_render/web_renderer",
"live_compositor/web_renderer",
]

[dependencies]
live_compositor = { workspace = true }
Expand Down
49 changes: 13 additions & 36 deletions integration_tests/examples/aac_rtp_input.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
use anyhow::Result;
use compositor_api::types::Resolution;
use live_compositor::server;
use log::{error, info};
use serde_json::json;
use std::{
env,
thread::{self},
time::Duration,
};
use std::time::Duration;

use integration_tests::examples::{
self, download_file, start_ffplay, start_websocket_thread, stream_audio, stream_video,
use integration_tests::{
examples::{self, run_example},
ffmpeg::{start_ffmpeg_receive, start_ffmpeg_send},
};

const BUNNY_FILE_URL: &str =
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4";
const BUNNY_FILE_PATH: &str = "examples/assets/BigBuckBunny.mp4";
const VIDEO_RESOLUTION: Resolution = Resolution {
width: 1280,
height: 720,
Expand All @@ -28,27 +20,12 @@ const OUTPUT_VIDEO_PORT: u16 = 8010;
const OUTPUT_AUDIO_PORT: u16 = 8012;

fn main() {
env::set_var("LIVE_COMPOSITOR_WEB_RENDERER_ENABLE", "0");
ffmpeg_next::format::network::init();

thread::spawn(|| {
if let Err(err) = start_example_client_code() {
error!("{err}")
}
});

server::run();
run_example(client_code);
}

fn start_example_client_code() -> Result<()> {
info!("[example] Start listening on output port.");
start_ffplay(IP, OUTPUT_VIDEO_PORT, Some(OUTPUT_AUDIO_PORT))?;
start_websocket_thread();
fn client_code() -> Result<()> {
start_ffmpeg_receive(Some(OUTPUT_VIDEO_PORT), Some(OUTPUT_AUDIO_PORT))?;

info!("[example] Download sample.");
let bunny_path = download_file(BUNNY_FILE_URL, BUNNY_FILE_PATH)?;

info!("[example] Send register input request.");
examples::post(
"input/input_1/register",
&json!({
Expand All @@ -60,7 +37,6 @@ fn start_example_client_code() -> Result<()> {
}),
)?;

info!("[example] Send register input request.");
examples::post(
"input/input_2/register",
&json!({
Expand All @@ -78,7 +54,6 @@ fn start_example_client_code() -> Result<()> {
}),
)?;

info!("[example] Send register output request.");
examples::post(
"output/output_1/register",
&json!({
Expand All @@ -105,7 +80,6 @@ fn start_example_client_code() -> Result<()> {
}),
)?;

info!("[example] Send register output request.");
examples::post(
"output/output_2/register",
&json!({
Expand All @@ -128,11 +102,14 @@ fn start_example_client_code() -> Result<()> {

std::thread::sleep(Duration::from_millis(500));

info!("[example] Start pipeline");
examples::post("start", &json!({}))?;

stream_video(IP, INPUT_1_PORT, bunny_path.clone())?;
stream_audio(IP, INPUT_2_PORT, bunny_path, "aac")?;
start_ffmpeg_send(
IP,
Some(INPUT_1_PORT),
Some(INPUT_2_PORT),
examples::TestSample::BigBuckBunnyAAC,
)?;

Ok(())
}
65 changes: 19 additions & 46 deletions integration_tests/examples/audio.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
use anyhow::Result;
use compositor_api::types::Resolution;
use live_compositor::server;
use log::{error, info};
use serde_json::json;
use std::{
env,
thread::{self},
time::Duration,
};
use std::time::Duration;

use integration_tests::examples::{
self, download_file, start_ffplay, start_websocket_thread, stream_audio, stream_video,
use integration_tests::{
examples::{self, run_example, TestSample},
ffmpeg::{start_ffmpeg_receive, start_ffmpeg_send},
};

const BUNNY_FILE_URL: &str =
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4";
const ELEPHANT_DREAM_FILE_URL: &str =
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4";
const BUNNY_FILE_PATH: &str = "examples/assets/BigBuckBunny.mp4";
const ELEPHANT_DREAM_FILE_PATH: &str = "examples/assets/ElephantsDream.mp4";
const VIDEO_RESOLUTION: Resolution = Resolution {
width: 1280,
height: 720,
Expand All @@ -33,30 +22,12 @@ const OUTPUT_VIDEO_PORT: u16 = 8010;
const OUTPUT_AUDIO_PORT: u16 = 8012;

fn main() {
env::set_var("LIVE_COMPOSITOR_WEB_RENDERER_ENABLE", "0");
ffmpeg_next::format::network::init();

thread::spawn(|| {
if let Err(err) = start_example_client_code() {
error!("{err}")
}
});

server::run();
run_example(client_code);
}

fn start_example_client_code() -> Result<()> {
info!("[example] Start listening on output port.");
start_ffplay(IP, OUTPUT_VIDEO_PORT, Some(OUTPUT_AUDIO_PORT))?;
start_websocket_thread();

info!("[example] Download sample.");
let bunny_path = download_file(BUNNY_FILE_URL, BUNNY_FILE_PATH)?;
fn client_code() -> Result<()> {
start_ffmpeg_receive(Some(OUTPUT_VIDEO_PORT), Some(OUTPUT_AUDIO_PORT))?;

info!("[example] Download sample.");
let elephant_path = download_file(ELEPHANT_DREAM_FILE_URL, ELEPHANT_DREAM_FILE_PATH)?;

info!("[example] Send register input request.");
examples::post(
"input/input_1/register",
&json!({
Expand All @@ -68,7 +39,6 @@ fn start_example_client_code() -> Result<()> {
}),
)?;

info!("[example] Send register input request.");
examples::post(
"input/input_2/register",
&json!({
Expand All @@ -80,7 +50,6 @@ fn start_example_client_code() -> Result<()> {
}),
)?;

info!("[example] Send register input request.");
examples::post(
"input/input_3/register",
&json!({
Expand All @@ -92,7 +61,6 @@ fn start_example_client_code() -> Result<()> {
}),
)?;

info!("[example] Send register input request.");
examples::post(
"input/input_4/register",
&json!({
Expand All @@ -104,7 +72,6 @@ fn start_example_client_code() -> Result<()> {
}),
)?;

info!("[example] Send register output request.");
examples::post(
"output/output_1/register",
&json!({
Expand Down Expand Up @@ -140,7 +107,6 @@ fn start_example_client_code() -> Result<()> {
}),
)?;

info!("[example] Send register output request.");
examples::post(
"output/output_2/register",
&json!({
Expand All @@ -164,13 +130,20 @@ fn start_example_client_code() -> Result<()> {

std::thread::sleep(Duration::from_millis(500));

info!("[example] Start pipeline");
examples::post("start", &json!({}))?;

stream_video(IP, INPUT_1_PORT, bunny_path.clone())?;
stream_audio(IP, INPUT_2_PORT, bunny_path, "libopus")?;
stream_video(IP, INPUT_3_PORT, elephant_path.clone())?;
stream_audio(IP, INPUT_4_PORT, elephant_path, "libopus")?;
start_ffmpeg_send(
IP,
Some(INPUT_1_PORT),
Some(INPUT_2_PORT),
TestSample::BigBuckBunny,
)?;
start_ffmpeg_send(
IP,
Some(INPUT_3_PORT),
Some(INPUT_4_PORT),
TestSample::ElephantsDream,
)?;

Ok(())
}
46 changes: 8 additions & 38 deletions integration_tests/examples/decklink.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use anyhow::Result;
use compositor_api::types::Resolution;
use live_compositor::server;
use log::{error, info};
use serde_json::json;
use std::{
process::{Command, Stdio},
thread,
time::Duration,
};
use std::time::Duration;

use integration_tests::examples::{self, start_websocket_thread};
use integration_tests::{
examples::{self, run_example},
gstreamer::start_gst_receive_tcp,
};

const VIDEO_RESOLUTION: Resolution = Resolution {
width: 1280,
Expand All @@ -20,23 +17,10 @@ const IP: &str = "127.0.0.1";
const OUTPUT_VIDEO_PORT: u16 = 8002;

fn main() {
ffmpeg_next::format::network::init();

thread::spawn(|| {
if let Err(err) = start_example_client_code() {
error!("{err}")
}
});

server::run();
run_example(client_code);
}

fn start_example_client_code() -> Result<()> {
info!("[example] Start listening on output port.");
thread::sleep(Duration::from_secs(2));
start_websocket_thread();

info!("[example] Send register input request.");
fn client_code() -> Result<()> {
examples::post(
"input/input_1/register",
&json!({
Expand All @@ -46,7 +30,6 @@ fn start_example_client_code() -> Result<()> {
}),
)?;

info!("[example] Send register output video request.");
examples::post(
"output/output_1/register",
&json!({
Expand Down Expand Up @@ -97,23 +80,10 @@ fn start_example_client_code() -> Result<()> {
}),
)?;

let gst_output_command = [
"gst-launch-1.0 -v ",
"rtpptdemux name=demux ",
&format!("tcpclientsrc host={IP} port={OUTPUT_VIDEO_PORT} ! \"application/x-rtp-stream\" ! rtpstreamdepay ! queue ! demux. "),
"demux.src_96 ! \"application/x-rtp,media=video,clock-rate=90000,encoding-name=H264\" ! queue ! rtph264depay ! decodebin ! videoconvert ! autovideosink ",
"demux.src_97 ! \"application/x-rtp,media=audio,clock-rate=48000,encoding-name=OPUS\" ! queue ! rtpopusdepay ! decodebin ! audioconvert ! autoaudiosink ",
].concat();
Command::new("bash")
.arg("-c")
.arg(gst_output_command)
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()?;
start_gst_receive_tcp(IP, OUTPUT_VIDEO_PORT, true, false)?;

std::thread::sleep(Duration::from_millis(1000));

info!("[example] Start pipeline");
examples::post("start", &json!({}))?;

Ok(())
Expand Down
Loading

0 comments on commit a3b1a1c

Please sign in to comment.