Skip to content

Commit

Permalink
fix voice packet send timing
Browse files Browse the repository at this point in the history
  • Loading branch information
rkusa committed Oct 28, 2019
1 parent 2528794 commit 0285e0d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.9.2] - 2019-10-28
### Fixed
- In some cases stations stopped transmitting every ~0.5 secs should be fixed
- Restore consistent ~3sec pause between reports

## [0.9.1] - 2019-10-14
### Fixed
- Do not SPAM logs when connection to SRS is lost #18
Expand Down
2 changes: 1 addition & 1 deletion datis/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "datis"
version = "0.9.1"
version = "0.9.2"
authors = ["Markus Ast <[email protected]>"]
edition = "2018"

Expand Down
43 changes: 19 additions & 24 deletions datis/src/srs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,19 +260,30 @@ fn audio_broadcast(

data.set_position(0);
let start = Instant::now();
let mut size = 0;
let mut audio = PacketReader::new(data);
let mut id: u64 = 1;
while let Some(pck) = audio.read_packet()? {
let pck_size = pck.data.len();
if pck_size == 0 {
if pck.data.len() == 0 {
continue;
}
size += pck_size;
let frame = pack_frame(&sguid, id, station.atis_freq, &pck.data)?;
stream.write_all(&frame)?;

// wait for the current ~playtime before sending the next package
let playtime = Duration::from_millis(id * 20);
let elapsed = start.elapsed();
if playtime > elapsed {
thread::sleep(playtime - elapsed);
}

id += 1;

if ctx.should_stop() {
return Ok(false);
}
}

'recv: loop {
// check whether the TCP connection is still alive (by trying to read and it and expect it to time out)
match io::copy(&mut stream, &mut sink) {
Ok(bytes_read) if bytes_read == 0 => {
Expand All @@ -281,34 +292,18 @@ fn audio_broadcast(
return Ok(true);
}
Err(err) => match err.kind() {
io::ErrorKind::TimedOut => {}
io::ErrorKind::TimedOut => {
break 'recv;
}
_ => {
return Err(err.into());
}
},
_ => {}
}

// wait for the current ~playtime before sending the next package
let secs = (size * 8) as f64 / 1024.0 / 32.0; // 32 kBit/s
let playtime = Duration::from_millis((secs * 1000.0) as u64);
let elapsed = start.elapsed();
if playtime > elapsed {
thread::sleep(playtime - elapsed);
}

if ctx.should_stop() {
return Ok(false);
}
}

debug!("TOTAL SIZE: {}", size);

// 32 kBit/s
let secs = (size * 8) as f64 / 1024.0 / 32.0;
debug!("SECONDS: {}", secs);

let playtime = Duration::from_millis((secs * 1000.0) as u64);
let playtime = Duration::from_millis(id * 20);
let elapsed = Instant::now() - start;
if playtime > elapsed {
thread::sleep(playtime - elapsed);
Expand Down
2 changes: 1 addition & 1 deletion mod/Mods/tech/DATIS/entry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declare_plugin("DATIS", {
"datis.dll",
},

version = "0.3.0",
version = "0.9.2",
state = "installed",
developerName = "github.com/rkusa",

Expand Down

0 comments on commit 0285e0d

Please sign in to comment.