Add buffer limit to audio fetch
This commit is contained in:
parent
60b5f2ed60
commit
f2cea03e27
4 changed files with 15 additions and 3 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -1167,9 +1167,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
version = "0.8.5"
|
||||
version = "0.8.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
|
||||
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"windows-targets",
|
||||
|
|
|
@ -12,6 +12,7 @@ pub struct Metadata {
|
|||
pub cover: DynamicImage,
|
||||
pub size: u32,
|
||||
pub bytes_received: u32,
|
||||
pub bytes_handled: u32,
|
||||
}
|
||||
|
||||
impl Metadata {
|
||||
|
@ -26,6 +27,7 @@ impl Metadata {
|
|||
cover: default_cover(),
|
||||
size: 0,
|
||||
bytes_received: 0,
|
||||
bytes_handled: 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ use crate::{
|
|||
utils::Error,
|
||||
};
|
||||
|
||||
pub const AUDIO_FILE_BUFFER: u32 = 5_000_000; // 5MB
|
||||
|
||||
pub enum PlayerEvent {
|
||||
AddSongList(Vec<Song>),
|
||||
UpdateCover(DynamicImage),
|
||||
|
|
|
@ -9,7 +9,7 @@ use crate::{
|
|||
utils::{default_cover, Error},
|
||||
};
|
||||
|
||||
use super::{errors::PlayerError, Player, PlayerEvent};
|
||||
use super::{errors::PlayerError, Player, PlayerEvent, AUDIO_FILE_BUFFER};
|
||||
|
||||
impl Player {
|
||||
pub fn begin(&mut self) -> Result<(), Error> {
|
||||
|
@ -100,6 +100,14 @@ impl Player {
|
|||
}
|
||||
|
||||
fn recv_chunk(&mut self, chunk: Vec<u8>) -> Result<(), Error> {
|
||||
if self.tui_root.metadata.bytes_received - self.tui_root.metadata.bytes_handled
|
||||
> AUDIO_FILE_BUFFER
|
||||
{
|
||||
// requeue the new chunk since we don't need it decoded just yet. Mostly for massive hr+ files
|
||||
self.player_chan_in
|
||||
.send(PlayerEvent::AddAudioChunk(chunk))?;
|
||||
return Ok(());
|
||||
}
|
||||
self.tui_root.metadata.bytes_received += chunk.len() as u32;
|
||||
self.audio_chan.send(AudioEvent::DecodeChunk(chunk))?;
|
||||
if self.tui_root.metadata.bytes_pending() {
|
||||
|
|
Loading…
Reference in a new issue