Skip to content

Commit

Permalink
video-daemon: update code to ubuntu 24 (#173)
Browse files Browse the repository at this point in the history
* update code to ubuntu 24

* make nokhwa happy

* make audio optional

* save
  • Loading branch information
darioalessandro authored Oct 14, 2024
1 parent f39332a commit c924c7a
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 337 deletions.
256 changes: 64 additions & 192 deletions video-daemon/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion video-daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ directories-next = "2.0.0"
env-libvpx-sys = { version = "5.1.3", features=["generate"] }
futures-util = { version = "0.3.28", features = ["sink"] }
image = "0.24.7"
nokhwa = { version = "0.10.4", features = ["input-native"] }
nokhwa = { git="https://github.com/security-union/nokhwa", branch="add-yuyv", features = ["input-native"] }
protobuf = "3.2.0"
quinn = "0.10.2"
rustls = {version = "0.21.7", features = ["dangerous_configuration"]}
Expand Down
13 changes: 7 additions & 6 deletions video-daemon/src/camera.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::video_encoder::Frame;
use crate::video_encoder::VideoEncoderBuilder;
use crate::yuyv_format::YuyvFormat;
use anyhow::Result;
use nokhwa::pixel_format::YuyvFormat;
use nokhwa::utils::RequestedFormat;
use nokhwa::utils::RequestedFormatType;

Expand Down Expand Up @@ -103,8 +103,8 @@ impl CameraDaemon {
self.handles.push(self.camera_thread()?);
let encoder = self.encoder_thread();
self.handles.push(encoder);
let fps = self.fps_thread();
self.handles.push(fps);
// let fps = self.fps_thread();
// self.handles.push(fps);
Ok(())
}

Expand Down Expand Up @@ -190,9 +190,10 @@ impl CameraDaemon {
let packet_wrapper = transform_video_chunk(&frame, &user_id);
if let Err(e) = quic_tx.try_send(packet_wrapper.write_to_bytes().unwrap()) {
error!("Unable to send packet: {:?}", e);
} else if let Err(e) = fps_tx.try_send(since_the_epoch().as_millis()) {
error!("Unable to send fps: {:?}", e);
}
}
// else if let Err(e) = fps_tx.try_send(since_the_epoch().as_millis()) {
// error!("Unable to send fps: {:?}", e);
// }
}
}
})
Expand Down
1 change: 0 additions & 1 deletion video-daemon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ pub mod fake_cert_verifier;
pub mod microphone;
pub mod quic;
pub mod video_encoder;
pub mod yuyv_format;
8 changes: 5 additions & 3 deletions video-daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ async fn main() {
let mut camera = CameraDaemon::from_config(camera_config, user_id.clone(), quic_tx.clone());
camera.start().expect("failed to start camera");
let mut microphone = MicrophoneDaemon::default();
microphone
.start(quic_tx, audio_device, user_id)
.expect("failed to start microphone");
if let Some(audio_device) = audio_device {
microphone
.start(quic_tx, audio_device, user_id)
.expect("failed to start microphone");
}
while let Some(data) = quic_rx.recv().await {
if let Err(e) = client.send(data).await {
match e {
Expand Down
4 changes: 2 additions & 2 deletions video-daemon/src/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ pub struct Opt {
#[clap(long = "video-device-index")]
pub video_device_index: usize,

#[clap(long = "audio-device", default_value = "default")]
pub audio_device: String,
#[clap(long = "audio-device")]
pub audio_device: Option<String>,
}

pub struct Client {
Expand Down
10 changes: 5 additions & 5 deletions video-daemon/src/video_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ pub struct VideoEncoderBuilder {
impl Default for VideoEncoderBuilder {
fn default() -> Self {
Self {
bitrate_kbps: 50,
bitrate_kbps: 200_000,
max_quantizer: 63,
min_quantizer: 50,
min_quantizer: 25,
resolution: (640, 480),
timebase: (1, 1000),
cpu_used: 4,
cpu_used: 5,
profile: 0,
}
}
Expand Down Expand Up @@ -72,8 +72,8 @@ impl VideoEncoderBuilder {
cfg.rc_target_bitrate = self.bitrate_kbps;
cfg.rc_min_quantizer = self.min_quantizer;
cfg.rc_max_quantizer = self.max_quantizer;
cfg.g_threads = 8;
cfg.g_lag_in_frames = 0;
cfg.g_threads = 2;
cfg.g_lag_in_frames = 1;
cfg.g_error_resilient = VPX_ERROR_RESILIENT_DEFAULT;
cfg.g_pass = vpx_enc_pass::VPX_RC_ONE_PASS;
cfg.g_profile = self.profile;
Expand Down
127 changes: 0 additions & 127 deletions video-daemon/src/yuyv_format.rs

This file was deleted.

23 changes: 23 additions & 0 deletions video-daemon/start_cameras.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Function to handle Ctrl+C (SIGINT)
cleanup() {
echo "Caught Ctrl+C, killing all processes..."
kill $PID1 $PID2
wait $PID1 $PID2 2>/dev/null
exit
}

# Trap Ctrl+C signal
trap cleanup SIGINT

# Run the first process in the background and capture its PID
RUST_LOG=info cargo run --release -- --user-id pi-1 --video-device-index 4 --meeting-id test https://transport.rustlemania.com &
PID1=$!

# Run the second process in the background and capture its PID
RUST_LOG=info cargo run --release -- --user-id pi-2 --video-device-index 0 --meeting-id test https://transport.rustlemania.com &
PID2=$!

# Wait for all background processes to finish
wait $PID1 $PID2

0 comments on commit c924c7a

Please sign in to comment.