use super::msg::{
CcdToKernel,
KernelToCcd,
};
use crossbeam_channel::{Sender,Receiver};
use crate::macros::{
skip_trace,
ok_trace,
};
use crate::collection::{
Album,
Collection,
Keychain,
ArtistKey,
AlbumKey,
SongKey,
Art,
};
impl super::Ccd {
#[inline(always)]
pub(super) fn priv_convert_art(to_kernel: &Sender<CcdToKernel>, collection: Collection) -> Collection {
let threads = super::threads_for_albums(collection.albums.len());
if threads == 1 {
Self::convert_art_singlethread(&to_kernel, collection)
} else {
Self::convert_art_multithread(&to_kernel, collection, threads)
}
}
#[inline(always)]
fn convert_art_multithread(to_kernel: &Sender<CcdToKernel>, mut collection: Collection, threads: usize) -> Collection {
std::thread::scope(|scope| {
for albums in collection.albums.chunks_mut(threads) {
let to_k = to_kernel.clone();
scope.spawn(move || {
Self::convert_art_worker(to_kernel, albums);
});
}
});
collection
}
#[inline(always)]
fn convert_art_singlethread(to_kernel: &Sender<CcdToKernel>, mut collection: Collection) -> Collection {
Self::convert_art_worker(to_kernel, &mut collection.albums);
collection
}
#[inline(always)]
fn convert_art_worker(to_kernel: &Sender<CcdToKernel>, albums: &mut [Album]) {
for album in albums {
let bytes = album.art_bytes.take();
let art = match bytes {
Some(b) => {
ok_trace!(album.title);
Art::Known(super::art_from_known(&b))
},
None => {
skip_trace!(album.title);
Art::Unknown
},
};
album.art = art;
}
}
}