Skip to content

Commit

Permalink
Working microphone
Browse files Browse the repository at this point in the history
  • Loading branch information
griffobeid committed Dec 19, 2023
1 parent 3c1a17f commit 9d6e356
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
49 changes: 32 additions & 17 deletions video-daemon/src/microphone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use opus::Channels;
use protobuf::{MessageField, Message};
use tokio::sync::mpsc::Sender;
use types::protos::packet_wrapper::PacketWrapper;
use types::protos::packet_wrapper::packet_wrapper::PacketType;
use std::sync::Arc;
use std::sync::atomic::AtomicBool;
use std::thread::JoinHandle;
Expand Down Expand Up @@ -137,34 +139,47 @@ fn start_microphone(device: String, quic_tx: Sender<Vec<u8>>, email: String, sto
fn encode_and_send_i16(input: &[i16], encoder: &mut opus::Encoder, quic_tx: &Sender<Vec<u8>>, email: String) -> anyhow::Result<()>
{
let output = encoder.encode_vec( input, 1024)?;
let output = convert_to_media_packet(output, email, 0);
let output = output.write_to_bytes()?;
info!("Encoded {} samples", output.len());
let output = transform_audio_chunk(output, email, 0);
let output = output?.write_to_bytes()?;
quic_tx.try_send(output)?;
Ok(())
}

fn encode_and_send_f32(input: &[f32], encoder: &mut opus::Encoder, quic_tx: &Sender<Vec<u8>>, email: String) -> anyhow::Result<()>
{
let output = encoder.encode_vec_float(input, 1024)?;
let output = convert_to_media_packet(output, email, 0);
let output = output.write_to_bytes()?;
info!("Encoded {} samples", output.len());
let output = transform_audio_chunk(output, email, 0);
let output = output?.write_to_bytes()?;
quic_tx.try_send(output)?;
Ok(())
}

fn convert_to_media_packet(data: Vec<u8>, email: String, sequence: u64) -> MediaPacket {
MediaPacket {
media_type: MediaType::AUDIO.into(),
data,
email,
// TODO: Do we need to include the timestamp?
timestamp: 0.0,
// TODO: Do we need to include the duration?
duration: 0.0,
video_metadata: MessageField(Some(Box::new(VideoMetadata {
sequence,
fn transform_audio_chunk(data: Vec<u8>, email: String, sequence: u64) -> anyhow::Result<PacketWrapper> {
Ok(PacketWrapper {
packet_type: PacketType::MEDIA.into(),
email: email.clone(),
data: MediaPacket {
media_type: MediaType::AUDIO.into(),
data,
email,
frame_type: String::from("key"),
timestamp: get_micros_now(),
// TODO: Duration of the audio in microseconds.
duration: 0.0,
video_metadata: MessageField(Some(Box::new(VideoMetadata {
sequence,
..Default::default()
}))),
..Default::default()
}))),
}.write_to_bytes()?,
..Default::default()
}
})
}

fn get_micros_now() -> f64 {
let now = std::time::SystemTime::now();
let duration = now.duration_since(std::time::UNIX_EPOCH).unwrap();
duration.as_micros() as f64
}
1 change: 1 addition & 0 deletions yew-ui/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions yew-ui/static/tailwind.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
! tailwindcss v3.3.6 | MIT License | https://tailwindcss.com
! tailwindcss v3.4.0 | MIT License | https://tailwindcss.com
*/

/*
Expand Down Expand Up @@ -32,9 +32,11 @@
4. Use the user's configured `sans` font-family by default.
5. Use the user's configured `sans` font-feature-settings by default.
6. Use the user's configured `sans` font-variation-settings by default.
7. Disable tap highlights on iOS
*/

html {
html,
:host {
line-height: 1.5;
/* 1 */
-webkit-text-size-adjust: 100%;
Expand All @@ -44,12 +46,14 @@ html {
-o-tab-size: 4;
tab-size: 4;
/* 3 */
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
font-family: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
/* 4 */
font-feature-settings: normal;
/* 5 */
font-variation-settings: normal;
/* 6 */
-webkit-tap-highlight-color: transparent;
/* 7 */
}

/*
Expand Down

0 comments on commit 9d6e356

Please sign in to comment.