feat: Atem wrapper
This commit is contained in:
@@ -12,3 +12,4 @@ color-eyre = "0.5.11"
|
||||
env_logger = "0.9.0"
|
||||
log = "0.4.14"
|
||||
tokio = "1.14.0"
|
||||
tokio-util = "0.7.10"
|
||||
|
||||
+31
-35
@@ -1,16 +1,20 @@
|
||||
use std::{sync::Arc, time::Duration};
|
||||
use std::{
|
||||
net::{Ipv4Addr, SocketAddrV4},
|
||||
str::FromStr,
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use atem_connection_rs::{
|
||||
atem_lib::atem_socket::AtemSocket,
|
||||
commands::{
|
||||
command_base::{BasicWritableCommand, SerializableCommand},
|
||||
mix_effects::program_input::ProgramInput,
|
||||
},
|
||||
atem::Atem,
|
||||
atem_lib::atem_socket::{AtemSocket, AtemSocketMessage},
|
||||
commands::mix_effects::program_input::ProgramInput,
|
||||
};
|
||||
|
||||
use clap::Parser;
|
||||
use color_eyre::Report;
|
||||
use tokio::{task::yield_now, time::sleep};
|
||||
use tokio::time::sleep;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
/// ATEM Rust Library Test App
|
||||
#[derive(Parser, Debug)]
|
||||
@@ -27,44 +31,36 @@ async fn main() {
|
||||
|
||||
setup_logging().unwrap();
|
||||
|
||||
let switch_to_source_1 = ProgramInput::new(0, 1);
|
||||
let switch_to_source_2 = ProgramInput::new(0, 2);
|
||||
let (socket_message_tx, socket_message_rx) =
|
||||
tokio::sync::mpsc::channel::<AtemSocketMessage>(10);
|
||||
let (atem_event_tx, atem_event_rx) = tokio::sync::mpsc::unbounded_channel();
|
||||
let cancel = CancellationToken::new();
|
||||
let cancel_task = cancel.clone();
|
||||
|
||||
let atem = tokio::sync::RwLock::new(AtemSocket::default());
|
||||
let atem = Arc::new(atem);
|
||||
let mut atem_socket = AtemSocket::new(atem_event_tx);
|
||||
tokio::spawn(async move {
|
||||
atem_socket.run(socket_message_rx, cancel_task).await;
|
||||
});
|
||||
|
||||
let atem = Arc::new(Atem::new(socket_message_tx));
|
||||
let atem_thread = atem.clone();
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
atem_thread.write().await.tick().await;
|
||||
|
||||
yield_now().await;
|
||||
}
|
||||
atem_thread.run(atem_event_rx, cancel).await;
|
||||
});
|
||||
atem.write().await.connect(args.ip, 9910).await.ok();
|
||||
|
||||
let mut tracking_id = 0;
|
||||
let address = Ipv4Addr::from_str(&args.ip).unwrap();
|
||||
let socket = SocketAddrV4::new(address, 9910);
|
||||
atem.connect(socket.into()).await;
|
||||
|
||||
loop {
|
||||
tracking_id += 1;
|
||||
sleep(Duration::from_millis(5000)).await;
|
||||
atem.write()
|
||||
.await
|
||||
.send_command(
|
||||
&switch_to_source_1.payload(atem_connection_rs::enums::ProtocolVersion::Unknown),
|
||||
switch_to_source_1.get_raw_name(),
|
||||
tracking_id,
|
||||
)
|
||||
log::info!("Switch to source 1");
|
||||
atem.send_commands(vec![Box::new(ProgramInput::new(0, 1))])
|
||||
.await;
|
||||
tracking_id += 1;
|
||||
sleep(Duration::from_millis(5000)).await;
|
||||
atem.write()
|
||||
.await
|
||||
.send_command(
|
||||
&switch_to_source_2.payload(atem_connection_rs::enums::ProtocolVersion::Unknown),
|
||||
switch_to_source_2.get_raw_name(),
|
||||
tracking_id,
|
||||
)
|
||||
log::info!("Switch to source 2");
|
||||
atem.send_commands(vec![Box::new(ProgramInput::new(0, 2))])
|
||||
.await;
|
||||
tracking_id += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user