Skip to content

Commit

Permalink
Merge pull request #61 from Polochon-street/ffmpeg6
Browse files Browse the repository at this point in the history
Bump ffmpeg to 6.0
  • Loading branch information
Polochon-street committed Mar 16, 2023
2 parents 97f563d + 0fc9f8d commit 743f779
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
#Changelog

## bliss 0.6.7
* Fix compatibility for ffmpeg 6.0, and bump ffmpeg version to 6.0

## bliss 0.6.6
* Add a `delete_everything_else` function in `library`'s update functions.
* Use Rust 2021
Expand Down
16 changes: 9 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
@@ -1,6 +1,7 @@
[package]
name = "bliss-audio"
version = "0.6.6"
version = "0.6.7"
build = "build.rs"
authors = ["Polochon-street <polochonstreet@gmx.fr>"]
edition = "2021"
license = "GPL-3.0-only"
Expand Down Expand Up @@ -41,7 +42,8 @@ lazy_static = "1.4.0"
rayon = "1.5.0"
crossbeam = "0.8.0"
noisy_float = "0.2.0"
ffmpeg-next = "5.1.1"
ffmpeg-next = "6.0.0"
ffmpeg-sys-next = { version = "6.0.1", default-features = false }
log = "0.4.14"
env_logger = "0.8.3"
thiserror = "1.0.24"
Expand Down
12 changes: 12 additions & 0 deletions build.rs
@@ -0,0 +1,12 @@
use std::env;

fn main() {
for (name, _value) in env::vars() {
if name.starts_with("DEP_FFMPEG_") {
println!(
r#"cargo:rustc-cfg=feature="{}""#,
name["DEP_FFMPEG_".len()..name.len()].to_lowercase()
);
}
}
}
1 change: 0 additions & 1 deletion src/library.rs
Expand Up @@ -1051,7 +1051,6 @@ impl<Config: AppConfigTrait> Library<Config> {
internal_analysis: stmt
.query_map(params![song_path], |row| row.get(0))
.unwrap()
.into_iter()
.map(|x| x.unwrap())
.collect::<Vec<f32>>()
.try_into()
Expand Down
23 changes: 14 additions & 9 deletions src/song.rs
Expand Up @@ -459,6 +459,7 @@ impl Song {
context.set_threading(Config {
kind: ThreadingType::Frame,
count: 0,
#[cfg(not(feature = "ffmpeg_6_0"))]
safe: true,
});
let decoder = context.decoder().audio().map_err(|e| {
Expand Down Expand Up @@ -519,11 +520,11 @@ impl Song {
t => Some(t.to_string()),
};
};
let in_channel_layout = {
let (empty_in_channel_layout, in_channel_layout) = {
if decoder.channel_layout() == ChannelLayout::empty() {
ChannelLayout::default(decoder.channels().into())
(true, ChannelLayout::default(decoder.channels().into()))
} else {
decoder.channel_layout()
(false, decoder.channel_layout())
}
};
decoder.set_channel_layout(in_channel_layout);
Expand All @@ -538,6 +539,7 @@ impl Song {
in_channel_layout,
in_codec_rate,
sample_array,
empty_in_channel_layout,
)
});
for (s, packet) in ictx.packets() {
Expand Down Expand Up @@ -646,6 +648,7 @@ fn resample_frame(
in_channel_layout: ChannelLayout,
in_rate: u32,
mut sample_array: Vec<f32>,
empty_in_channel_layout: bool,
) -> BlissResult<Vec<f32>> {
let mut resample_context = ffmpeg::software::resampling::context::Context::get(
in_codec_format,
Expand All @@ -660,15 +663,17 @@ fn resample_frame(
"while trying to allocate resampling context: {e:?}",
))
})?;

let mut resampled = ffmpeg::frame::Audio::empty();
let mut something_happened = false;
for decoded in rx.iter() {
if in_codec_format != decoded.format()
for mut decoded in rx.iter() {
// If the decoded layout is empty, it means we forced the
// "in_channel_layout" to something default, not that
// the format is wrong.
if empty_in_channel_layout && decoded.channel_layout() == ChannelLayout::empty() {
decoded.set_channel_layout(in_channel_layout);
} else if in_codec_format != decoded.format()
|| (in_channel_layout != decoded.channel_layout())
// If the decoded layout is empty, it means we forced the
// "in_channel_layout" to something default, not that
// the format is wrong.
&& (decoded.channel_layout() != ChannelLayout::empty())
|| in_rate != decoded.rate()
{
warn!("received decoded packet with wrong format; file might be corrupted.");
Expand Down

0 comments on commit 743f779

Please sign in to comment.