Merge pull request #17 from Polochon-street/tentative-thread-safing
Tentative of thread safing stuff
This commit is contained in:
commit
bd6ff422a7
4 changed files with 33 additions and 19 deletions
|
@ -1,5 +1,8 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## bliss 0.3.2
|
||||||
|
* Fixed a rare ffmpeg multithreading bug.
|
||||||
|
|
||||||
## bliss 0.3.1
|
## bliss 0.3.1
|
||||||
* Show error message when song storage fails in the Library trait.
|
* Show error message when song storage fails in the Library trait.
|
||||||
* Added a `distance` module containing euclidean and cosine distance.
|
* Added a `distance` module containing euclidean and cosine distance.
|
||||||
|
|
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -75,7 +75,7 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bliss-audio"
|
name = "bliss-audio"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bliss-audio-aubio-rs",
|
"bliss-audio-aubio-rs",
|
||||||
"crossbeam",
|
"crossbeam",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "bliss-audio"
|
name = "bliss-audio"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
authors = ["Polochon-street <polochonstreet@gmx.fr>"]
|
authors = ["Polochon-street <polochonstreet@gmx.fr>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "GPL-3.0-only"
|
license = "GPL-3.0-only"
|
||||||
|
|
45
src/song.rs
45
src/song.rs
|
@ -23,7 +23,6 @@ use ::log::warn;
|
||||||
use core::ops::Index;
|
use core::ops::Index;
|
||||||
use crossbeam::thread;
|
use crossbeam::thread;
|
||||||
use ffmpeg_next::codec::threading::{Config, Type as ThreadingType};
|
use ffmpeg_next::codec::threading::{Config, Type as ThreadingType};
|
||||||
use ffmpeg_next::software::resampling::context::Context;
|
|
||||||
use ffmpeg_next::util;
|
use ffmpeg_next::util;
|
||||||
use ffmpeg_next::util::channel_layout::ChannelLayout;
|
use ffmpeg_next::util::channel_layout::ChannelLayout;
|
||||||
use ffmpeg_next::util::error::Error;
|
use ffmpeg_next::util::error::Error;
|
||||||
|
@ -437,23 +436,19 @@ impl Song {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
codec.set_channel_layout(in_channel_layout);
|
codec.set_channel_layout(in_channel_layout);
|
||||||
let resample_context = ffmpeg::software::resampling::context::Context::get(
|
|
||||||
codec.format(),
|
|
||||||
in_channel_layout,
|
|
||||||
codec.rate(),
|
|
||||||
Sample::F32(Type::Packed),
|
|
||||||
ffmpeg::util::channel_layout::ChannelLayout::MONO,
|
|
||||||
SAMPLE_RATE,
|
|
||||||
)
|
|
||||||
.map_err(|e| {
|
|
||||||
BlissError::DecodingError(format!(
|
|
||||||
"while trying to allocate resampling context: {:?}",
|
|
||||||
e
|
|
||||||
))
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
let child = std_thread::spawn(move || resample_frame(rx, resample_context, sample_array));
|
let in_codec_format = codec.format();
|
||||||
|
let in_codec_rate = codec.rate();
|
||||||
|
let child = std_thread::spawn(move || {
|
||||||
|
resample_frame(
|
||||||
|
rx,
|
||||||
|
in_codec_format,
|
||||||
|
in_channel_layout,
|
||||||
|
in_codec_rate,
|
||||||
|
sample_array,
|
||||||
|
)
|
||||||
|
});
|
||||||
for (s, packet) in format.packets() {
|
for (s, packet) in format.packets() {
|
||||||
if s.index() != stream {
|
if s.index() != stream {
|
||||||
continue;
|
continue;
|
||||||
|
@ -542,9 +537,25 @@ pub(crate) struct InternalSong {
|
||||||
|
|
||||||
fn resample_frame(
|
fn resample_frame(
|
||||||
rx: Receiver<Audio>,
|
rx: Receiver<Audio>,
|
||||||
mut resample_context: Context,
|
in_codec_format: Sample,
|
||||||
|
in_channel_layout: ChannelLayout,
|
||||||
|
in_rate: u32,
|
||||||
mut sample_array: Vec<f32>,
|
mut sample_array: Vec<f32>,
|
||||||
) -> BlissResult<Vec<f32>> {
|
) -> BlissResult<Vec<f32>> {
|
||||||
|
let mut resample_context = ffmpeg::software::resampling::context::Context::get(
|
||||||
|
in_codec_format,
|
||||||
|
in_channel_layout,
|
||||||
|
in_rate,
|
||||||
|
Sample::F32(Type::Packed),
|
||||||
|
ffmpeg::util::channel_layout::ChannelLayout::MONO,
|
||||||
|
SAMPLE_RATE,
|
||||||
|
)
|
||||||
|
.map_err(|e| {
|
||||||
|
BlissError::DecodingError(format!(
|
||||||
|
"while trying to allocate resampling context: {:?}",
|
||||||
|
e
|
||||||
|
))
|
||||||
|
})?;
|
||||||
let mut resampled = ffmpeg::frame::Audio::empty();
|
let mut resampled = ffmpeg::frame::Audio::empty();
|
||||||
for decoded in rx.iter() {
|
for decoded in rx.iter() {
|
||||||
resampled = ffmpeg::frame::Audio::empty();
|
resampled = ffmpeg::frame::Audio::empty();
|
||||||
|
|
Loading…
Reference in a new issue