mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Harmonize thread names and debug messages
This commit is contained in:
parent
8d35b4b860
commit
0e3ffe5394
3 changed files with 54 additions and 16 deletions
|
@ -81,7 +81,7 @@ struct PlayerInternal {
|
||||||
player_id: usize,
|
player_id: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
static PLAYER_COUNTER: AtomicUsize = AtomicUsize::new(0);
|
pub static PLAYER_COUNTER: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
|
||||||
enum PlayerCommand {
|
enum PlayerCommand {
|
||||||
Load {
|
Load {
|
||||||
|
@ -507,11 +507,11 @@ impl Player {
|
||||||
|
|
||||||
impl Drop for Player {
|
impl Drop for Player {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
debug!("Shutting down player thread ...");
|
debug!("Shutting down <Player> thread ...");
|
||||||
self.commands = None;
|
self.commands = None;
|
||||||
if let Some(handle) = self.thread_handle.take() {
|
if let Some(handle) = self.thread_handle.take() {
|
||||||
if let Err(e) = handle.join() {
|
if let Err(e) = handle.join() {
|
||||||
error!("Player thread Error: {:?}", e);
|
error!("<Player> thread Error: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1953,7 +1953,12 @@ impl PlayerInternal {
|
||||||
let load_handles_clone = self.load_handles.clone();
|
let load_handles_clone = self.load_handles.clone();
|
||||||
let handle = tokio::runtime::Handle::current();
|
let handle = tokio::runtime::Handle::current();
|
||||||
|
|
||||||
let thread_name = format!("loader:{}", spotify_id.to_uri().unwrap_or_default());
|
// The player increments the player id when it gets it...
|
||||||
|
let thread_name = format!(
|
||||||
|
"loader:{}:{}",
|
||||||
|
PLAYER_COUNTER.load(Ordering::Relaxed).saturating_sub(1),
|
||||||
|
spotify_id.to_uri().unwrap_or_default()
|
||||||
|
);
|
||||||
|
|
||||||
let builder = thread::Builder::new().name(thread_name.clone());
|
let builder = thread::Builder::new().name(thread_name.clone());
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,14 @@ use std::{
|
||||||
collections::{vec_deque, VecDeque},
|
collections::{vec_deque, VecDeque},
|
||||||
marker::Send,
|
marker::Send,
|
||||||
process::exit,
|
process::exit,
|
||||||
|
sync::atomic::Ordering,
|
||||||
sync::mpsc,
|
sync::mpsc,
|
||||||
thread,
|
thread,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{InterpolationQuality, SampleRate},
|
config::{InterpolationQuality, SampleRate},
|
||||||
|
player::PLAYER_COUNTER,
|
||||||
RESAMPLER_INPUT_SIZE, SAMPLE_RATE as SOURCE_SAMPLE_RATE,
|
RESAMPLER_INPUT_SIZE, SAMPLE_RATE as SOURCE_SAMPLE_RATE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -287,8 +289,8 @@ impl ResampleWorker {
|
||||||
}
|
}
|
||||||
ResampleTask::Terminate => {
|
ResampleTask::Terminate => {
|
||||||
match thread::current().name() {
|
match thread::current().name() {
|
||||||
Some(name) => debug!("drop <ResampleWorker> [{name}] thread"),
|
Some(name) => debug!("<ResampleWorker> [{name}] thread finished"),
|
||||||
None => debug!("drop <ResampleWorker> thread"),
|
None => debug!("<ResampleWorker> thread finished"),
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -353,6 +355,7 @@ impl ResampleWorker {
|
||||||
|
|
||||||
impl Drop for ResampleWorker {
|
impl Drop for ResampleWorker {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
|
debug!("Shutting down <ResampleWorker> thread ...");
|
||||||
self.task_sender
|
self.task_sender
|
||||||
.take()
|
.take()
|
||||||
.and_then(|sender| sender.send(ResampleTask::Terminate).ok());
|
.and_then(|sender| sender.send(ResampleTask::Terminate).ok());
|
||||||
|
@ -399,8 +402,11 @@ impl StereoInterleavedResampler {
|
||||||
_ => {
|
_ => {
|
||||||
debug!("Interpolation Quality: {interpolation_quality}");
|
debug!("Interpolation Quality: {interpolation_quality}");
|
||||||
|
|
||||||
let left_thread_name = "resampler:left".to_string();
|
// The player increments the player id when it gets it...
|
||||||
let right_thread_name = "resampler:right".to_string();
|
let player_id = PLAYER_COUNTER.load(Ordering::Relaxed).saturating_sub(1);
|
||||||
|
|
||||||
|
let left_thread_name = format!("resampler:{player_id}:left");
|
||||||
|
let right_thread_name = format!("resampler:{player_id}:right");
|
||||||
|
|
||||||
match interpolation_quality {
|
match interpolation_quality {
|
||||||
InterpolationQuality::Low => {
|
InterpolationQuality::Low => {
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use log::{debug, error, warn};
|
use log::{debug, error, warn};
|
||||||
|
|
||||||
use std::{collections::HashMap, process::Command, thread};
|
use std::{collections::HashMap, process::exit, process::Command, sync::atomic::Ordering, thread};
|
||||||
|
|
||||||
use librespot::{
|
use librespot::{
|
||||||
metadata::audio::UniqueFields,
|
metadata::audio::UniqueFields,
|
||||||
playback::player::{PlayerEvent, PlayerEventChannel, SinkStatus},
|
playback::player::{PlayerEvent, PlayerEventChannel, SinkStatus, PLAYER_COUNTER},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct EventHandler {
|
pub struct EventHandler {
|
||||||
|
@ -14,9 +14,25 @@ pub struct EventHandler {
|
||||||
impl EventHandler {
|
impl EventHandler {
|
||||||
pub fn new(mut player_events: PlayerEventChannel, onevent: &str) -> Self {
|
pub fn new(mut player_events: PlayerEventChannel, onevent: &str) -> Self {
|
||||||
let on_event = onevent.to_string();
|
let on_event = onevent.to_string();
|
||||||
let thread_handle = Some(thread::spawn(move || loop {
|
|
||||||
|
// The player increments the player id when it gets it...
|
||||||
|
let thread_name = format!(
|
||||||
|
"event-handler:{}",
|
||||||
|
PLAYER_COUNTER.load(Ordering::Relaxed).saturating_sub(1)
|
||||||
|
);
|
||||||
|
|
||||||
|
let builder = thread::Builder::new().name(thread_name.clone());
|
||||||
|
|
||||||
|
let thread_handle = match builder.spawn(move || loop {
|
||||||
match player_events.blocking_recv() {
|
match player_events.blocking_recv() {
|
||||||
None => break,
|
None => {
|
||||||
|
match thread::current().name() {
|
||||||
|
Some(name) => debug!("<EventHandler> [{name}] thread finished"),
|
||||||
|
None => debug!("<EventHandler> thread finished"),
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
Some(event) => {
|
Some(event) => {
|
||||||
let mut env_vars = HashMap::new();
|
let mut env_vars = HashMap::new();
|
||||||
|
|
||||||
|
@ -245,18 +261,29 @@ impl EventHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}) {
|
||||||
|
Ok(handle) => {
|
||||||
|
debug!("Created <EventHandler> [{thread_name}] thread");
|
||||||
|
handle
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
error!("Error creating <EventHandler> [{thread_name}] thread: {e}");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Self { thread_handle }
|
Self {
|
||||||
|
thread_handle: Some(thread_handle),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for EventHandler {
|
impl Drop for EventHandler {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
debug!("Shutting down EventHandler thread ...");
|
debug!("Shutting down <EventHandler> thread ...");
|
||||||
if let Some(handle) = self.thread_handle.take() {
|
if let Some(handle) = self.thread_handle.take() {
|
||||||
if let Err(e) = handle.join() {
|
if let Err(e) = handle.join() {
|
||||||
error!("EventHandler thread Error: {:?}", e);
|
error!("<EventHandler> thread Error: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue