Skip to content

Commit d768f23

Browse files
committed
Increase stat rate to 1 per second
1 parent fab4827 commit d768f23

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

src/main.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use message::{process_slim_msg, process_stream_msg};
1919
use simple_logger::SimpleLogger;
2020
use slimproto::{
2121
proto::{ClientMessage, SLIM_PORT},
22-
status::StatusData,
22+
status::{StatusCode, StatusData},
2323
};
2424

2525
mod audio_out;
@@ -151,11 +151,7 @@ fn main() -> anyhow::Result<()> {
151151
let skip = Arc::new(AtomicCell::new(Duration::ZERO));
152152
let (slim_tx_in, slim_tx_out) = bounded(1);
153153
let (slim_rx_in, slim_rx_out) = bounded(1);
154-
proto::run(
155-
cli.server,
156-
slim_rx_in.clone(),
157-
slim_tx_out.clone(),
158-
);
154+
proto::run(cli.server, slim_rx_in.clone(), slim_tx_out.clone());
159155

160156
let volume = Arc::new(Mutex::new(vec![1.0f32, 1.0]));
161157
let (stream_in, stream_out) = bounded(10);
@@ -164,8 +160,8 @@ fn main() -> anyhow::Result<()> {
164160
let stream_idx = select.recv(&stream_out);
165161

166162
loop {
167-
match select.select() {
168-
op if op.index() == slim_idx => match op.recv(&slim_rx_out)? {
163+
match select.select_timeout(Duration::from_secs(1)) {
164+
Ok(op) if op.index() == slim_idx => match op.recv(&slim_rx_out)? {
169165
Some(msg) => process_slim_msg(
170166
&mut output,
171167
msg,
@@ -192,7 +188,7 @@ fn main() -> anyhow::Result<()> {
192188
}
193189
},
194190

195-
op if op.index() == stream_idx => {
191+
Ok(op) if op.index() == stream_idx => {
196192
let msg = op.recv(&stream_out)?;
197193
process_stream_msg(
198194
msg,
@@ -205,8 +201,25 @@ fn main() -> anyhow::Result<()> {
205201
&cli.quiet,
206202
);
207203
}
208-
209-
_ => {}
204+
205+
Ok(_) => {}
206+
207+
Err(_) => {
208+
let play_time = match output {
209+
Some(ref output) => output.get_dur(),
210+
None => Duration::ZERO,
211+
};
212+
213+
if let Ok(mut status) = status.lock() {
214+
// info!("Sending status update - jiffies: {:?}", status.get_jiffies());
215+
status.set_elapsed_milli_seconds(play_time.as_millis() as u32);
216+
status.set_elapsed_seconds(play_time.as_secs() as u32);
217+
// status.set_timestamp(ts);
218+
219+
let msg = status.make_status_message(StatusCode::Timer);
220+
slim_tx_in.send(msg).ok();
221+
}
222+
}
210223
}
211224
}
212225
}

0 commit comments

Comments
 (0)