commit 33155c6ce252f98d24dc2db118ce77508ba2fb26 Author: Micha Glave Date: Wed Apr 1 13:55:11 2020 +0200 Adding a transpiled version of [Ralph Irving's squeezelite](https://github.com/ralph-irving/squeezelite). Transpiled by c2rust: `c2rust transpile --binary main compile_commands.json -r --reduce-type-annotations -o ../squeezers -- -I/usr/lib/clang/9.0.1/include` diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..09f468f --- /dev/null +++ b/.gitignore @@ -0,0 +1,81 @@ +# ---> Rust +# Generated by Cargo +# will have compiled files and executables +/target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# ---> JetBrains +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + + diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..2f033ab --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,29 @@ +[workspace] +members = [ +] + +[package] +name = "squeezers" +authors = ["C2Rust"] +version = "0.0.0" +publish = false +edition = "2018" +autobins = false + +[lib] +name = "squeezers" +path = "lib.rs" +crate-type = ["staticlib", "rlib"] + + +[[bin]] +path = "src/main.rs" +name = "main" + +[dependencies] +c2rust-bitfields = "0.3" +c2rust-asm-casts = "0.1" +libc = "0.2" + + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..c1127bb --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +Squeezelite v1.9.x, Copyright 2012-2015 Adrian Smith, 2015-2019 Ralph Irving. + +See the squeezelite manpage for usage details. +https://ralph-irving.github.io/squeezelite.html + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Contains dsd2pcm library Copyright 2009, 2011 Sebastian Gesemann which +is subject to its own license. + +Contains the Daphile Project full dsd patch Copyright 2013-2017 Daphile, +which is subject to its own license. + +Option to allow server side upsampling for PCM streams (-W) from +squeezelite-R2 (c) Marco Curti 2015, marcoc1712@gmail.com. + +RaspberryPi minimal GPIO Interface +http://abyz.me.uk/rpi/pigpio/examples.html#Misc_minimal_gpio. + +This software uses libraries from the FFmpeg project under +the LGPLv2.1 and its source can be downloaded from +https://sourceforge.net/projects/lmsclients/files/source/ diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..13d7cc9 --- /dev/null +++ b/build.rs @@ -0,0 +1,13 @@ +#[cfg(all(unix, not(target_os = "macos")))] +fn main() { + + // add unix dependencies below + // println!("cargo:rustc-flags=-l readline"); +} + +#[cfg(target_os = "macos")] +fn main() { + + // add macos dependencies below + // println!("cargo:rustc-flags=-l edit"); +} diff --git a/lib.rs b/lib.rs new file mode 100644 index 0000000..5e14886 --- /dev/null +++ b/lib.rs @@ -0,0 +1,51 @@ +#![allow(dead_code)] +#![allow(mutable_transmutes)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(unused_assignments)] +#![allow(unused_mut)] +#![feature(asm)] +#![feature(c_variadic)] +#![feature(const_raw_ptr_to_usize_cast)] +#![feature(extern_types)] +#![feature(main)] +#![feature(ptr_wrapping_offset_from)] +#![feature(register_tool)] +#![register_tool(c2rust)] + +#[path = "src/internal.rs"] +pub mod internal; +#[path = "src/squeezelite_h.rs"] +pub mod squeezelite_h; +#[path = "src/stdarg_h.rs"] +pub mod stdarg_h; +#[path = "src/stddef_h.rs"] +pub mod stddef_h; +#[path = "src/stdlib.rs"] +pub mod stdlib; +#[macro_use] +extern crate c2rust_bitfields; +#[macro_use] +extern crate c2rust_asm_casts; +extern crate libc; + +pub mod src { + pub mod buffer; + pub mod decode; + pub mod faad; + pub mod flac; + pub mod mad; + pub mod mpg; + pub mod output; + pub mod output_alsa; + pub mod output_pa; + pub mod output_pack; + pub mod output_pulse; + pub mod output_stdout; + pub mod pcm; + pub mod slimproto; + pub mod stream; + pub mod utils; + pub mod vorbis; +} // mod src diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 0000000..fc40182 --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +nightly-2019-12-05 diff --git a/src/buffer.rs b/src/buffer.rs new file mode 100644 index 0000000..c102c32 --- /dev/null +++ b/src/buffer.rs @@ -0,0 +1,227 @@ +use ::libc; + +pub use crate::stddef_h::size_t; +pub use crate::stdlib::__uint8_t; +pub use crate::stdlib::u_int8_t; + +pub use crate::squeezelite_h::buffer; +pub use crate::squeezelite_h::u8_t; +pub use crate::stdlib::__pthread_internal_list; +pub use crate::stdlib::__pthread_list_t; +pub use crate::stdlib::__pthread_mutex_s; +use crate::stdlib::free; +use crate::stdlib::malloc; +pub use crate::stdlib::pthread_mutex_destroy; +pub use crate::stdlib::pthread_mutex_init; +pub use crate::stdlib::pthread_mutex_lock; +pub use crate::stdlib::pthread_mutex_t; +pub use crate::stdlib::pthread_mutex_unlock; +pub use crate::stdlib::pthread_mutexattr_destroy; +pub use crate::stdlib::pthread_mutexattr_init; +pub use crate::stdlib::pthread_mutexattr_setprotocol; +pub use crate::stdlib::pthread_mutexattr_t; +pub use crate::stdlib::C2RustUnnamed_0; +pub use crate::stdlib::PTHREAD_PRIO_INHERIT; +pub use crate::stdlib::PTHREAD_PRIO_NONE; +pub use crate::stdlib::PTHREAD_PRIO_PROTECT; +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +// fifo bufffers +// _* called with muxtex locked +#[inline] + +unsafe extern "C" fn _buf_used(mut buf: *mut crate::squeezelite_h::buffer) -> libc::c_uint { + return if (*buf).writep >= (*buf).readp { + (*buf).writep.wrapping_offset_from((*buf).readp) as libc::c_long as libc::c_ulong + } else { + (*buf).size.wrapping_sub( + (*buf).readp.wrapping_offset_from((*buf).writep) as libc::c_long as libc::c_ulong, + ) + } as libc::c_uint; +} +#[no_mangle] + +pub unsafe extern "C" fn _buf_space(mut buf: *mut crate::squeezelite_h::buffer) -> libc::c_uint { + return (*buf) + .size + .wrapping_sub(_buf_used(buf) as libc::c_ulong) + .wrapping_sub(1 as libc::c_int as libc::c_ulong) as libc::c_uint; + // reduce by one as full same as empty otherwise +} +#[no_mangle] + +pub unsafe extern "C" fn _buf_cont_read( + mut buf: *mut crate::squeezelite_h::buffer, +) -> libc::c_uint { + return if (*buf).writep >= (*buf).readp { + (*buf).writep.wrapping_offset_from((*buf).readp) as libc::c_long + } else { + (*buf).wrap.wrapping_offset_from((*buf).readp) as libc::c_long + } as libc::c_uint; +} +#[no_mangle] + +pub unsafe extern "C" fn _buf_cont_write( + mut buf: *mut crate::squeezelite_h::buffer, +) -> libc::c_uint { + return if (*buf).writep >= (*buf).readp { + (*buf).wrap.wrapping_offset_from((*buf).writep) as libc::c_long + } else { + (*buf).readp.wrapping_offset_from((*buf).writep) as libc::c_long + } as libc::c_uint; +} +#[no_mangle] + +pub unsafe extern "C" fn _buf_inc_readp( + mut buf: *mut crate::squeezelite_h::buffer, + mut by: libc::c_uint, +) { + (*buf).readp = (*buf).readp.offset(by as isize); + if (*buf).readp >= (*buf).wrap { + (*buf).readp = (*buf).readp.offset(-((*buf).size as isize)) + }; +} +#[no_mangle] + +pub unsafe extern "C" fn _buf_inc_writep( + mut buf: *mut crate::squeezelite_h::buffer, + mut by: libc::c_uint, +) { + (*buf).writep = (*buf).writep.offset(by as isize); + if (*buf).writep >= (*buf).wrap { + (*buf).writep = (*buf).writep.offset(-((*buf).size as isize)) + }; +} +#[no_mangle] + +pub unsafe extern "C" fn buf_flush(mut buf: *mut crate::squeezelite_h::buffer) { + crate::stdlib::pthread_mutex_lock(&mut (*buf).mutex); + (*buf).readp = (*buf).buf; + (*buf).writep = (*buf).buf; + crate::stdlib::pthread_mutex_unlock(&mut (*buf).mutex); +} +// adjust buffer to multiple of mod bytes so reading in multiple always wraps on frame boundary +#[no_mangle] + +pub unsafe extern "C" fn buf_adjust( + mut buf: *mut crate::squeezelite_h::buffer, + mut mod_0: crate::stddef_h::size_t, +) { + let mut size: crate::stddef_h::size_t = 0; + crate::stdlib::pthread_mutex_lock(&mut (*buf).mutex); + size = + ((*buf).base_size.wrapping_div(mod_0) as libc::c_uint as libc::c_ulong).wrapping_mul(mod_0); + (*buf).readp = (*buf).buf; + (*buf).writep = (*buf).buf; + (*buf).wrap = (*buf).buf.offset(size as isize); + (*buf).size = size; + crate::stdlib::pthread_mutex_unlock(&mut (*buf).mutex); +} +// called with mutex locked to resize, does not retain contents, reverts to original size if fails +#[no_mangle] + +pub unsafe extern "C" fn _buf_resize( + mut buf: *mut crate::squeezelite_h::buffer, + mut size: crate::stddef_h::size_t, +) { + crate::stdlib::free((*buf).buf as *mut libc::c_void); + (*buf).buf = crate::stdlib::malloc(size) as *mut crate::squeezelite_h::u8_t; + if (*buf).buf.is_null() { + size = (*buf).size; + (*buf).buf = crate::stdlib::malloc(size) as *mut crate::squeezelite_h::u8_t; + if (*buf).buf.is_null() { + size = 0 as libc::c_int as crate::stddef_h::size_t + } + } + (*buf).readp = (*buf).buf; + (*buf).writep = (*buf).buf; + (*buf).wrap = (*buf).buf.offset(size as isize); + (*buf).size = size; + (*buf).base_size = size; +} +#[no_mangle] + +pub unsafe extern "C" fn buf_init( + mut buf: *mut crate::squeezelite_h::buffer, + mut size: crate::stddef_h::size_t, +) { + (*buf).buf = crate::stdlib::malloc(size) as *mut crate::squeezelite_h::u8_t; + (*buf).readp = (*buf).buf; + (*buf).writep = (*buf).buf; + (*buf).wrap = (*buf).buf.offset(size as isize); + (*buf).size = size; + (*buf).base_size = size; + let mut attr = crate::stdlib::pthread_mutexattr_t { __size: [0; 4] }; + crate::stdlib::pthread_mutexattr_init(&mut attr); + crate::stdlib::pthread_mutexattr_setprotocol( + &mut attr, + crate::stdlib::PTHREAD_PRIO_INHERIT as libc::c_int, + ); + crate::stdlib::pthread_mutex_init(&mut (*buf).mutex, &mut attr); + crate::stdlib::pthread_mutexattr_destroy(&mut attr); +} +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Additions (c) Paul Hermann, 2015-2017 under the same license terms + * -Control of Raspberry pi GPIO for amplifier power + * -Launch script on power status change from LMS + */ +// make may define: PORTAUDIO, SELFPIPE, RESAMPLE, RESAMPLE_MP, VISEXPORT, GPIO, IR, DSD, LINKALL to influence build +// build detection +// dynamically loaded libraries at run time +// !LINKALL +// config options +// do not reduce as icy-meta max is 4080 +/* SUN */ +/* SUN */ +// printf/scanf formats for u64_t +// logging +// utils.c (non logging) +// buffer.c +// _* called with mutex locked +#[no_mangle] + +pub unsafe extern "C" fn buf_destroy(mut buf: *mut crate::squeezelite_h::buffer) { + if !(*buf).buf.is_null() { + crate::stdlib::free((*buf).buf as *mut libc::c_void); + (*buf).buf = 0 as *mut crate::squeezelite_h::u8_t; + (*buf).size = 0 as libc::c_int as crate::stddef_h::size_t; + (*buf).base_size = 0 as libc::c_int as crate::stddef_h::size_t; + crate::stdlib::pthread_mutex_destroy(&mut (*buf).mutex); + }; +} diff --git a/src/decode.rs b/src/decode.rs new file mode 100644 index 0000000..34082e3 --- /dev/null +++ b/src/decode.rs @@ -0,0 +1,669 @@ +use ::libc; + +pub use crate::stddef_h::size_t; +pub use crate::stdlib::__int32_t; +pub use crate::stdlib::__uint32_t; +pub use crate::stdlib::__uint64_t; +pub use crate::stdlib::__uint8_t; +pub use crate::stdlib::__useconds_t; +pub use crate::stdlib::int32_t; + +pub use crate::squeezelite_h::_buf_used; +pub use crate::squeezelite_h::buffer; +pub use crate::squeezelite_h::codec; +pub use crate::squeezelite_h::decode_state; +pub use crate::squeezelite_h::decodestate; +pub use crate::squeezelite_h::disconnect_code; +pub use crate::squeezelite_h::fade_dir; +pub use crate::squeezelite_h::fade_mode; +pub use crate::squeezelite_h::fade_state; +pub use crate::squeezelite_h::frames_t; +pub use crate::squeezelite_h::lDEBUG; +pub use crate::squeezelite_h::lERROR; +pub use crate::squeezelite_h::lINFO; +pub use crate::squeezelite_h::lSDEBUG; +pub use crate::squeezelite_h::lWARN; +pub use crate::squeezelite_h::log_level; +pub use crate::squeezelite_h::output_format; +pub use crate::squeezelite_h::output_state; +pub use crate::squeezelite_h::outputstate; +pub use crate::squeezelite_h::s32_t; +pub use crate::squeezelite_h::stream_state; +pub use crate::squeezelite_h::streamstate; +pub use crate::squeezelite_h::u32_t; +pub use crate::squeezelite_h::u64_t; +pub use crate::squeezelite_h::u8_t; +pub use crate::squeezelite_h::C2RustUnnamed_1; +pub use crate::squeezelite_h::DECODE_COMPLETE; +pub use crate::squeezelite_h::DECODE_ERROR; +pub use crate::squeezelite_h::DECODE_READY; +pub use crate::squeezelite_h::DECODE_RUNNING; +pub use crate::squeezelite_h::DECODE_STOPPED; +pub use crate::squeezelite_h::DISCONNECT; +pub use crate::squeezelite_h::DISCONNECT_OK; +pub use crate::squeezelite_h::FADE_ACTIVE; +pub use crate::squeezelite_h::FADE_CROSS; +pub use crate::squeezelite_h::FADE_CROSSFADE; +pub use crate::squeezelite_h::FADE_DOWN; +pub use crate::squeezelite_h::FADE_DUE; +pub use crate::squeezelite_h::FADE_IN; +pub use crate::squeezelite_h::FADE_INACTIVE; +pub use crate::squeezelite_h::FADE_INOUT; +pub use crate::squeezelite_h::FADE_NONE; +pub use crate::squeezelite_h::FADE_OUT; +pub use crate::squeezelite_h::FADE_UP; +pub use crate::squeezelite_h::LOCAL_DISCONNECT; +pub use crate::squeezelite_h::OUTPUT_BUFFER; +pub use crate::squeezelite_h::OUTPUT_OFF; +pub use crate::squeezelite_h::OUTPUT_PAUSE_FRAMES; +pub use crate::squeezelite_h::OUTPUT_RUNNING; +pub use crate::squeezelite_h::OUTPUT_SKIP_FRAMES; +pub use crate::squeezelite_h::OUTPUT_START_AT; +pub use crate::squeezelite_h::OUTPUT_STOPPED; +pub use crate::squeezelite_h::RECV_HEADERS; +pub use crate::squeezelite_h::REMOTE_DISCONNECT; +pub use crate::squeezelite_h::S16_LE; +pub use crate::squeezelite_h::S24_3LE; +pub use crate::squeezelite_h::S24_LE; +pub use crate::squeezelite_h::S32_LE; +pub use crate::squeezelite_h::SEND_HEADERS; +pub use crate::squeezelite_h::STOPPED; +pub use crate::squeezelite_h::STREAMING_BUFFERING; +pub use crate::squeezelite_h::STREAMING_FILE; +pub use crate::squeezelite_h::STREAMING_HTTP; +pub use crate::squeezelite_h::STREAMING_WAIT; +pub use crate::squeezelite_h::TIMEOUT; +pub use crate::squeezelite_h::UNREACHABLE; +pub use crate::src::buffer::_buf_space; +pub use crate::src::faad::register_faad; +pub use crate::src::flac::register_flac; +pub use crate::src::mad::register_mad; +pub use crate::src::mpg::register_mpg; +pub use crate::src::output::_checkfade; +pub use crate::src::pcm::register_pcm; +pub use crate::src::slimproto::wake_controller; +pub use crate::src::utils::logprint; +pub use crate::src::utils::logtime; +pub use crate::src::vorbis::register_vorbis; +pub use crate::stdlib::__pthread_internal_list; +pub use crate::stdlib::__pthread_list_t; +pub use crate::stdlib::__pthread_mutex_s; +use crate::stdlib::pthread_attr_destroy; +use crate::stdlib::pthread_attr_init; +use crate::stdlib::pthread_attr_setstacksize; +pub use crate::stdlib::pthread_attr_t; +use crate::stdlib::pthread_create; +use crate::stdlib::pthread_join; +use crate::stdlib::pthread_mutex_destroy; +use crate::stdlib::pthread_mutex_init; +use crate::stdlib::pthread_mutex_lock; +pub use crate::stdlib::pthread_mutex_t; +use crate::stdlib::pthread_mutex_unlock; +pub use crate::stdlib::pthread_mutexattr_t; +pub use crate::stdlib::pthread_t; +use crate::stdlib::strstr; +pub use crate::stdlib::u_int32_t; +pub use crate::stdlib::u_int64_t; +pub use crate::stdlib::u_int8_t; +use crate::stdlib::usleep; +extern "C" { + #[no_mangle] + pub static mut streambuf: *mut crate::squeezelite_h::buffer; + #[no_mangle] + pub static mut outputbuf: *mut crate::squeezelite_h::buffer; + #[no_mangle] + pub static mut stream: crate::squeezelite_h::streamstate; + #[no_mangle] + pub static mut output: crate::squeezelite_h::outputstate; +} +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +// decode thread +#[no_mangle] + +pub static mut loglevel: crate::squeezelite_h::log_level = crate::squeezelite_h::lERROR; +#[no_mangle] + +pub static mut decode: crate::squeezelite_h::decodestate = crate::squeezelite_h::decodestate { + state: crate::squeezelite_h::DECODE_STOPPED, + new_stream: false, + mutex: crate::stdlib::pthread_mutex_t { + __data: crate::stdlib::__pthread_mutex_s { + __lock: 0, + __count: 0, + __owner: 0, + __nusers: 0, + __kind: 0, + __spins: 0, + __elision: 0, + __list: crate::stdlib::__pthread_list_t { + __prev: 0 as *const crate::stdlib::__pthread_internal_list + as *mut crate::stdlib::__pthread_internal_list, + __next: 0 as *const crate::stdlib::__pthread_internal_list + as *mut crate::stdlib::__pthread_internal_list, + }, + }, + }, +}; +#[no_mangle] + +pub static mut codecs: [*mut crate::squeezelite_h::codec; 10] = + [0 as *const crate::squeezelite_h::codec as *mut crate::squeezelite_h::codec; 10]; +#[no_mangle] + +pub static mut codec: *mut crate::squeezelite_h::codec = + 0 as *const crate::squeezelite_h::codec as *mut crate::squeezelite_h::codec; + +static mut flac_container: crate::squeezelite_h::u8_t = '?' as i32 as crate::squeezelite_h::u8_t; + +static mut running: bool = 1 as libc::c_int != 0; + +unsafe extern "C" fn decode_thread() -> *mut libc::c_void { + while running { + let mut bytes: crate::stddef_h::size_t = 0; + let mut space: crate::stddef_h::size_t = 0; + let mut min_space: crate::stddef_h::size_t = 0; + let mut toend: bool = false; + let mut ran = 0 as libc::c_int != 0; + crate::stdlib::pthread_mutex_lock(&mut (*streambuf).mutex); + bytes = crate::squeezelite_h::_buf_used(streambuf) as crate::stddef_h::size_t; + toend = stream.state as libc::c_uint + <= crate::squeezelite_h::DISCONNECT as libc::c_int as libc::c_uint; + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + space = crate::src::buffer::_buf_space(outputbuf) as crate::stddef_h::size_t; + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + crate::stdlib::pthread_mutex_lock(&mut decode.mutex); + if decode.state as libc::c_uint + == crate::squeezelite_h::DECODE_RUNNING as libc::c_int as libc::c_uint + && !codec.is_null() + { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d streambuf bytes: %u outputbuf space: %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"decode_thread\x00", + )) + .as_ptr(), + 76 as libc::c_int, + bytes, + space, + ); + } + min_space = (*codec).min_space as crate::stddef_h::size_t; + if space > min_space + && (bytes > (*codec).min_read_bytes as libc::c_ulong || toend as libc::c_int != 0) + { + decode.state = (*codec).decode.expect("non-null function pointer")(); + if decode.state as libc::c_uint + != crate::squeezelite_h::DECODE_RUNNING as libc::c_int as libc::c_uint + { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d decode %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"decode_thread\x00", + )) + .as_ptr(), + 101 as libc::c_int, + if decode.state as libc::c_uint + == crate::squeezelite_h::DECODE_COMPLETE as libc::c_int + as libc::c_uint + { + b"complete\x00" as *const u8 as *const libc::c_char + } else { + b"error\x00" as *const u8 as *const libc::c_char + }, + ); + } + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + if output.fade_mode as u64 != 0 { + crate::src::output::_checkfade(0 as libc::c_int != 0); + } + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + crate::src::slimproto::wake_controller(); + } + ran = 1 as libc::c_int != 0 + } + } + crate::stdlib::pthread_mutex_unlock(&mut decode.mutex); + if !ran { + crate::stdlib::usleep(100000 as libc::c_int as crate::stdlib::__useconds_t); + } + } + return 0 as *mut libc::c_void; +} + +unsafe extern "C" fn sort_codecs(mut pry: libc::c_int, mut ptr: *mut crate::squeezelite_h::codec) { + static mut priority: [libc::c_int; 10] = [0; 10]; + let mut i: libc::c_int = 0; + let mut tpry: libc::c_int = 0; + let mut tptr = 0 as *mut crate::squeezelite_h::codec; + i = 0 as libc::c_int; + while i < 10 as libc::c_int { + if codecs[i as usize].is_null() { + codecs[i as usize] = ptr; + priority[i as usize] = pry; + return; + } + if pry < priority[i as usize] { + tptr = codecs[i as usize]; + codecs[i as usize] = ptr; + ptr = tptr; + tpry = priority[i as usize]; + priority[i as usize] = pry; + pry = tpry + } + i += 1 + } +} + +static mut thread: crate::stdlib::pthread_t = 0; +#[no_mangle] + +pub unsafe extern "C" fn decode_init( + mut level: crate::squeezelite_h::log_level, + mut include_codecs: *const libc::c_char, + mut exclude_codecs: *const libc::c_char, +) { + let mut i: libc::c_int = 0; + let mut order_codecs = 0 as *mut libc::c_char; + loglevel = level; + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d init decode\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"decode_init\x00")).as_ptr(), + 154 as libc::c_int, + ); + } + // register codecs + // dsf,dff,alc,wma,wmap,wmal,aac,spt,ogg,ogf,flc,aif,pcm,mp3 + i = 0 as libc::c_int; + if crate::stdlib::strstr( + exclude_codecs, + b"aac\x00" as *const u8 as *const libc::c_char, + ) + .is_null() + && (include_codecs.is_null() || { + order_codecs = crate::stdlib::strstr( + include_codecs, + b"aac\x00" as *const u8 as *const libc::c_char, + ); + !order_codecs.is_null() + }) + { + sort_codecs( + if !include_codecs.is_null() { + order_codecs.wrapping_offset_from(include_codecs) as libc::c_long + } else { + i as libc::c_long + } as libc::c_int, + crate::src::faad::register_faad(), + ); + } + if crate::stdlib::strstr( + exclude_codecs, + b"ogg\x00" as *const u8 as *const libc::c_char, + ) + .is_null() + && (include_codecs.is_null() || { + order_codecs = crate::stdlib::strstr( + include_codecs, + b"ogg\x00" as *const u8 as *const libc::c_char, + ); + !order_codecs.is_null() + }) + { + sort_codecs( + if !include_codecs.is_null() { + order_codecs.wrapping_offset_from(include_codecs) as libc::c_long + } else { + i as libc::c_long + } as libc::c_int, + crate::src::vorbis::register_vorbis(), + ); + } + if crate::stdlib::strstr( + exclude_codecs, + b"flac\x00" as *const u8 as *const libc::c_char, + ) + .is_null() + && (include_codecs.is_null() || { + order_codecs = crate::stdlib::strstr( + include_codecs, + b"flac\x00" as *const u8 as *const libc::c_char, + ); + !order_codecs.is_null() + }) + { + sort_codecs( + if !include_codecs.is_null() { + order_codecs.wrapping_offset_from(include_codecs) as libc::c_long + } else { + i as libc::c_long + } as libc::c_int, + crate::src::flac::register_flac(), + ); + } + if crate::stdlib::strstr( + exclude_codecs, + b"pcm\x00" as *const u8 as *const libc::c_char, + ) + .is_null() + && (include_codecs.is_null() || { + order_codecs = crate::stdlib::strstr( + include_codecs, + b"pcm\x00" as *const u8 as *const libc::c_char, + ); + !order_codecs.is_null() + }) + { + sort_codecs( + if !include_codecs.is_null() { + order_codecs.wrapping_offset_from(include_codecs) as libc::c_long + } else { + i as libc::c_long + } as libc::c_int, + crate::src::pcm::register_pcm(), + ); + } + // try mad then mpg for mp3 unless command line option passed + if !(!crate::stdlib::strstr( + exclude_codecs, + b"mp3\x00" as *const u8 as *const libc::c_char, + ) + .is_null() + || !crate::stdlib::strstr( + exclude_codecs, + b"mad\x00" as *const u8 as *const libc::c_char, + ) + .is_null()) + && (include_codecs.is_null() + || { + order_codecs = crate::stdlib::strstr( + include_codecs, + b"mp3\x00" as *const u8 as *const libc::c_char, + ); + !order_codecs.is_null() + } + || { + order_codecs = crate::stdlib::strstr( + include_codecs, + b"mad\x00" as *const u8 as *const libc::c_char, + ); + !order_codecs.is_null() + }) + { + sort_codecs( + if !include_codecs.is_null() { + order_codecs.wrapping_offset_from(include_codecs) as libc::c_long + } else { + i as libc::c_long + } as libc::c_int, + crate::src::mad::register_mad(), + ); + } else if !(!crate::stdlib::strstr( + exclude_codecs, + b"mp3\x00" as *const u8 as *const libc::c_char, + ) + .is_null() + || !crate::stdlib::strstr( + exclude_codecs, + b"mpg\x00" as *const u8 as *const libc::c_char, + ) + .is_null()) + && (include_codecs.is_null() + || { + order_codecs = crate::stdlib::strstr( + include_codecs, + b"mp3\x00" as *const u8 as *const libc::c_char, + ); + !order_codecs.is_null() + } + || { + order_codecs = crate::stdlib::strstr( + include_codecs, + b"mpg\x00" as *const u8 as *const libc::c_char, + ); + !order_codecs.is_null() + }) + { + sort_codecs( + if !include_codecs.is_null() { + order_codecs.wrapping_offset_from(include_codecs) as libc::c_long + } else { + i as libc::c_long + } as libc::c_int, + crate::src::mpg::register_mpg(), + ); + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d include codecs: %s exclude codecs: %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"decode_init\x00")).as_ptr(), + 195 as libc::c_int, + if !include_codecs.is_null() { + include_codecs + } else { + b"\x00" as *const u8 as *const libc::c_char + }, + exclude_codecs, + ); + } + crate::stdlib::pthread_mutex_init( + &mut decode.mutex, + 0 as *const crate::stdlib::pthread_mutexattr_t, + ); + let mut attr = crate::stdlib::pthread_attr_t { __size: [0; 56] }; + crate::stdlib::pthread_attr_init(&mut attr); + crate::stdlib::pthread_attr_setstacksize( + &mut attr, + (16384 as libc::c_int + 128 as libc::c_int * 1024 as libc::c_int) + as crate::stddef_h::size_t, + ); + crate::stdlib::pthread_create( + &mut thread, + &mut attr, + ::std::mem::transmute::< + Option *mut libc::c_void>, + Option *mut libc::c_void>, + >(Some(::std::mem::transmute::< + unsafe extern "C" fn() -> *mut libc::c_void, + unsafe extern "C" fn() -> *mut libc::c_void, + >(decode_thread))), + 0 as *mut libc::c_void, + ); + crate::stdlib::pthread_attr_destroy(&mut attr); + decode.new_stream = 1 as libc::c_int != 0; + decode.state = crate::squeezelite_h::DECODE_STOPPED; +} +#[no_mangle] + +pub unsafe extern "C" fn decode_close() { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d close decode\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"decode_close\x00")) + .as_ptr(), + 222 as libc::c_int, + ); + } + crate::stdlib::pthread_mutex_lock(&mut decode.mutex); + if !codec.is_null() { + (*codec).close.expect("non-null function pointer")(); + codec = 0 as *mut crate::squeezelite_h::codec + } + running = 0 as libc::c_int != 0; + crate::stdlib::pthread_mutex_unlock(&mut decode.mutex); + crate::stdlib::pthread_join(thread, 0 as *mut *mut libc::c_void); + crate::stdlib::pthread_mutex_destroy(&mut decode.mutex); +} +#[no_mangle] + +pub unsafe extern "C" fn decode_flush() { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d decode flush\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"decode_flush\x00")) + .as_ptr(), + 237 as libc::c_int, + ); + } + crate::stdlib::pthread_mutex_lock(&mut decode.mutex); + decode.state = crate::squeezelite_h::DECODE_STOPPED; + crate::stdlib::pthread_mutex_unlock(&mut decode.mutex); +} +#[no_mangle] + +pub unsafe extern "C" fn decode_newstream( + mut sample_rate: libc::c_uint, + mut supported_rates: *mut libc::c_uint, +) -> libc::c_uint { + // called with O locked to get sample rate for potentially processed output stream + // release O mutex during process_newstream as it can take some time + return sample_rate; +} +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Additions (c) Paul Hermann, 2015-2017 under the same license terms + * -Control of Raspberry pi GPIO for amplifier power + * -Launch script on power status change from LMS + */ +// make may define: PORTAUDIO, SELFPIPE, RESAMPLE, RESAMPLE_MP, VISEXPORT, GPIO, IR, DSD, LINKALL to influence build +// build detection +// dynamically loaded libraries at run time +// !LINKALL +// config options +// do not reduce as icy-meta max is 4080 +/* SUN */ +/* SUN */ +// printf/scanf formats for u64_t +// logging +// utils.c (non logging) +// buffer.c +// _* called with mutex locked +// slimproto.c +// stream.c +// decode.c +#[no_mangle] + +pub unsafe extern "C" fn codec_open( + mut format: crate::squeezelite_h::u8_t, + mut sample_size: crate::squeezelite_h::u8_t, + mut sample_rate: crate::squeezelite_h::u8_t, + mut channels: crate::squeezelite_h::u8_t, + mut endianness: crate::squeezelite_h::u8_t, +) { + let mut i: libc::c_int = 0; + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d codec open: \'%c\'\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"codec_open\x00")).as_ptr(), + 265 as libc::c_int, + format as libc::c_int, + ); + } + crate::stdlib::pthread_mutex_lock(&mut decode.mutex); + decode.new_stream = 1 as libc::c_int != 0; + decode.state = crate::squeezelite_h::DECODE_STOPPED; + // potentially changed within codec when processing enabled + // find the required codec + i = 0 as libc::c_int; + while i < 10 as libc::c_int { + if !codecs[i as usize].is_null() + && (*codecs[i as usize]).id as libc::c_int == format as libc::c_int + { + // close codec if format or flac container changed + if !codec.is_null() + && (codec != codecs[i as usize] + || (*codecs[i as usize]).id as libc::c_int == 'f' as i32 + && flac_container as libc::c_int != sample_size as libc::c_int) + { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d closing codec: \'%c\'\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>( + b"codec_open\x00", + )) + .as_ptr(), + 283 as libc::c_int, + (*codec).id as libc::c_int, + ); + } + (*codec).close.expect("non-null function pointer")(); + } + codec = codecs[i as usize]; + if (*codec).id as libc::c_int == 'f' as i32 { + flac_container = sample_size + } + (*codec).open.expect("non-null function pointer")( + sample_size, + sample_rate, + channels, + endianness, + ); + decode.state = crate::squeezelite_h::DECODE_READY; + crate::stdlib::pthread_mutex_unlock(&mut decode.mutex); + return; + } + i += 1 + } + crate::stdlib::pthread_mutex_unlock(&mut decode.mutex); + crate::src::utils::logprint( + b"%s %s:%d codec not found\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"codec_open\x00")).as_ptr(), + 303 as libc::c_int, + ); +} diff --git a/src/faad.rs b/src/faad.rs new file mode 100644 index 0000000..4016806 --- /dev/null +++ b/src/faad.rs @@ -0,0 +1,1553 @@ +use ::libc; + +pub use crate::stddef_h::size_t; +pub use crate::stdlib::__int32_t; +pub use crate::stdlib::__uint32_t; +pub use crate::stdlib::__uint64_t; +pub use crate::stdlib::__uint8_t; +pub use crate::stdlib::int32_t; + +pub use crate::stdlib::__pthread_internal_list; +pub use crate::stdlib::__pthread_list_t; +pub use crate::stdlib::__pthread_mutex_s; +pub use crate::stdlib::pthread_mutex_t; +pub use crate::stdlib::u_int32_t; +pub use crate::stdlib::u_int64_t; +pub use crate::stdlib::u_int8_t; + +pub use crate::squeezelite_h::buffer; +pub use crate::squeezelite_h::codec; +pub use crate::squeezelite_h::decode_state; +pub use crate::squeezelite_h::decodestate; +pub use crate::squeezelite_h::disconnect_code; +pub use crate::squeezelite_h::fade_dir; +pub use crate::squeezelite_h::fade_mode; +pub use crate::squeezelite_h::fade_state; +pub use crate::squeezelite_h::frames_t; +pub use crate::squeezelite_h::lDEBUG; +pub use crate::squeezelite_h::lERROR; +pub use crate::squeezelite_h::lINFO; +pub use crate::squeezelite_h::lSDEBUG; +pub use crate::squeezelite_h::lWARN; +pub use crate::squeezelite_h::log_level; +pub use crate::squeezelite_h::output_format; +pub use crate::squeezelite_h::output_state; +pub use crate::squeezelite_h::outputstate; +pub use crate::squeezelite_h::s32_t; +pub use crate::squeezelite_h::stream_state; +pub use crate::squeezelite_h::streamstate; +pub use crate::squeezelite_h::u32_t; +pub use crate::squeezelite_h::u64_t; +pub use crate::squeezelite_h::u8_t; +pub use crate::squeezelite_h::C2RustUnnamed_1; +pub use crate::squeezelite_h::_buf_used; +pub use crate::squeezelite_h::DECODE_COMPLETE; +pub use crate::squeezelite_h::DECODE_ERROR; +pub use crate::squeezelite_h::DECODE_READY; +pub use crate::squeezelite_h::DECODE_RUNNING; +pub use crate::squeezelite_h::DECODE_STOPPED; +pub use crate::squeezelite_h::DISCONNECT; +pub use crate::squeezelite_h::DISCONNECT_OK; +pub use crate::squeezelite_h::FADE_ACTIVE; +pub use crate::squeezelite_h::FADE_CROSS; +pub use crate::squeezelite_h::FADE_CROSSFADE; +pub use crate::squeezelite_h::FADE_DOWN; +pub use crate::squeezelite_h::FADE_DUE; +pub use crate::squeezelite_h::FADE_IN; +pub use crate::squeezelite_h::FADE_INACTIVE; +pub use crate::squeezelite_h::FADE_INOUT; +pub use crate::squeezelite_h::FADE_NONE; +pub use crate::squeezelite_h::FADE_OUT; +pub use crate::squeezelite_h::FADE_UP; +pub use crate::squeezelite_h::LOCAL_DISCONNECT; +pub use crate::squeezelite_h::OUTPUT_BUFFER; +pub use crate::squeezelite_h::OUTPUT_OFF; +pub use crate::squeezelite_h::OUTPUT_PAUSE_FRAMES; +pub use crate::squeezelite_h::OUTPUT_RUNNING; +pub use crate::squeezelite_h::OUTPUT_SKIP_FRAMES; +pub use crate::squeezelite_h::OUTPUT_START_AT; +pub use crate::squeezelite_h::OUTPUT_STOPPED; +pub use crate::squeezelite_h::RECV_HEADERS; +pub use crate::squeezelite_h::REMOTE_DISCONNECT; +pub use crate::squeezelite_h::S16_LE; +pub use crate::squeezelite_h::S24_3LE; +pub use crate::squeezelite_h::S24_LE; +pub use crate::squeezelite_h::S32_LE; +pub use crate::squeezelite_h::SEND_HEADERS; +pub use crate::squeezelite_h::STOPPED; +pub use crate::squeezelite_h::STREAMING_BUFFERING; +pub use crate::squeezelite_h::STREAMING_FILE; +pub use crate::squeezelite_h::STREAMING_HTTP; +pub use crate::squeezelite_h::STREAMING_WAIT; +pub use crate::squeezelite_h::TIMEOUT; +pub use crate::squeezelite_h::UNREACHABLE; +pub use crate::src::buffer::_buf_cont_read; +pub use crate::src::buffer::_buf_cont_write; +pub use crate::src::buffer::_buf_inc_readp; +pub use crate::src::buffer::_buf_inc_writep; +pub use crate::src::decode::decode_newstream; +pub use crate::src::output::_checkfade; +pub use crate::src::utils::logprint; +pub use crate::src::utils::logtime; +pub use crate::src::utils::unpackN; +use crate::stdlib::sscanf; +pub use crate::stdlib::NeAACDecConfiguration; +pub use crate::stdlib::NeAACDecConfigurationPtr; +pub use crate::stdlib::NeAACDecFrameInfo; +pub use crate::stdlib::NeAACDecHandle; + +use crate::stdlib::dlerror; +use crate::stdlib::dlopen; +use crate::stdlib::dlsym; +use crate::stdlib::free; +use crate::stdlib::malloc; +use crate::stdlib::memcmp; +use crate::stdlib::memcpy; +use crate::stdlib::pthread_mutex_lock; +use crate::stdlib::pthread_mutex_unlock; +use crate::stdlib::strcmp; +extern "C" { + #[no_mangle] + pub static mut loglevel: crate::squeezelite_h::log_level; + #[no_mangle] + pub static mut streambuf: *mut crate::squeezelite_h::buffer; + #[no_mangle] + pub static mut outputbuf: *mut crate::squeezelite_h::buffer; + #[no_mangle] + pub static mut stream: crate::squeezelite_h::streamstate; + #[no_mangle] + pub static mut output: crate::squeezelite_h::outputstate; + #[no_mangle] + pub static mut decode: crate::squeezelite_h::decodestate; +} + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct faad { + pub hAac: crate::stdlib::NeAACDecHandle, + pub type_0: crate::squeezelite_h::u8_t, + pub consume: crate::squeezelite_h::u32_t, + pub pos: crate::squeezelite_h::u32_t, + pub sample: crate::squeezelite_h::u32_t, + pub nextchunk: crate::squeezelite_h::u32_t, + pub stsc: *mut libc::c_void, + pub skip: crate::squeezelite_h::u32_t, + pub samples: crate::squeezelite_h::u64_t, + pub sttssamples: crate::squeezelite_h::u64_t, + pub empty: bool, + pub chunkinfo: *mut chunk_table, + pub NeAACDecGetCurrentConfiguration: Option< + unsafe extern "C" fn( + _: crate::stdlib::NeAACDecHandle, + ) -> crate::stdlib::NeAACDecConfigurationPtr, + >, + pub NeAACDecSetConfiguration: Option< + unsafe extern "C" fn( + _: crate::stdlib::NeAACDecHandle, + _: crate::stdlib::NeAACDecConfigurationPtr, + ) -> libc::c_uchar, + >, + pub NeAACDecOpen: Option crate::stdlib::NeAACDecHandle>, + pub NeAACDecClose: Option ()>, + pub NeAACDecInit: Option< + unsafe extern "C" fn( + _: crate::stdlib::NeAACDecHandle, + _: *mut libc::c_uchar, + _: libc::c_ulong, + _: *mut libc::c_ulong, + _: *mut libc::c_uchar, + ) -> libc::c_long, + >, + pub NeAACDecInit2: Option< + unsafe extern "C" fn( + _: crate::stdlib::NeAACDecHandle, + _: *mut libc::c_uchar, + _: libc::c_ulong, + _: *mut libc::c_ulong, + _: *mut libc::c_uchar, + ) -> libc::c_char, + >, + pub NeAACDecDecode: Option< + unsafe extern "C" fn( + _: crate::stdlib::NeAACDecHandle, + _: *mut crate::stdlib::NeAACDecFrameInfo, + _: *mut libc::c_uchar, + _: libc::c_ulong, + ) -> *mut libc::c_void, + >, + pub NeAACDecGetErrorMessage: + Option *mut libc::c_char>, +} + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct chunk_table { + pub sample: crate::squeezelite_h::u32_t, + pub offset: crate::squeezelite_h::u32_t, +} + +static mut a: *mut faad = 0 as *const faad as *mut faad; +// minimal code for mp4 file parsing to extract audio config and find media data +// adapted from faad2/common/mp4ff +#[no_mangle] + +pub unsafe extern "C" fn mp4_desc_length( + mut buf: *mut *mut crate::squeezelite_h::u8_t, +) -> crate::squeezelite_h::u32_t { + let mut b: crate::squeezelite_h::u8_t = 0; + let mut num_bytes = 0 as libc::c_int as crate::squeezelite_h::u8_t; + let mut length = 0 as libc::c_int as crate::squeezelite_h::u32_t; + loop { + b = **buf; + *buf = (*buf).offset(1 as libc::c_int as isize); + num_bytes = num_bytes.wrapping_add(1); + length = + length << 7 as libc::c_int | (b as libc::c_int & 0x7f as libc::c_int) as libc::c_uint; + if !(b as libc::c_int & 0x80 as libc::c_int != 0 + && (num_bytes as libc::c_int) < 4 as libc::c_int) + { + break; + } + } + return length; +} +// read mp4 header to extract config data + +unsafe extern "C" fn read_mp4_header( + mut samplerate_p: *mut libc::c_ulong, + mut channels_p: *mut libc::c_uchar, +) -> libc::c_int { + let mut bytes = if crate::squeezelite_h::_buf_used(streambuf) + < crate::src::buffer::_buf_cont_read(streambuf) + { + crate::squeezelite_h::_buf_used(streambuf) + } else { + crate::src::buffer::_buf_cont_read(streambuf) + } as crate::stddef_h::size_t; + let mut type_0: [libc::c_char; 5] = [0; 5]; + let mut len: crate::squeezelite_h::u32_t = 0; + while bytes >= 8 as libc::c_int as libc::c_ulong { + // count trak to find the first playable one + static mut trak: libc::c_uint = 0; + static mut play: libc::c_uint = 0; + let mut consume: crate::squeezelite_h::u32_t = 0; + len = crate::src::utils::unpackN((*streambuf).readp as *mut crate::squeezelite_h::u32_t); + crate::stdlib::memcpy( + type_0.as_mut_ptr() as *mut libc::c_void, + (*streambuf).readp.offset(4 as libc::c_int as isize) as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ); + type_0[4 as libc::c_int as usize] = '\u{0}' as i32 as libc::c_char; + if crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"moov\x00" as *const u8 as *const libc::c_char, + ) == 0 + { + trak = 0 as libc::c_int as libc::c_uint; + play = 0 as libc::c_int as libc::c_uint + } + if crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"trak\x00" as *const u8 as *const libc::c_char, + ) == 0 + { + trak = trak.wrapping_add(1) + } + // extract audio config from within esds and pass to DecInit2 + if crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"esds\x00" as *const u8 as *const libc::c_char, + ) == 0 + && bytes > len as libc::c_ulong + { + let mut config_len: libc::c_uint = 0; + let mut ptr = (*streambuf).readp.offset(12 as libc::c_int as isize); + let fresh0 = ptr; + ptr = ptr.offset(1); + if *fresh0 as libc::c_int == 0x3 as libc::c_int { + mp4_desc_length(&mut ptr); + ptr = ptr.offset(4 as libc::c_int as isize) + } else { + ptr = ptr.offset(3 as libc::c_int as isize) + } + mp4_desc_length(&mut ptr); + ptr = ptr.offset(13 as libc::c_int as isize); + let fresh1 = ptr; + ptr = ptr.offset(1); + if *fresh1 as libc::c_int != 0x5 as libc::c_int { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d error parsing esds\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>( + b"read_mp4_header\x00", + )) + .as_ptr(), + 146 as libc::c_int, + ); + } + return -(1 as libc::c_int); + } + config_len = mp4_desc_length(&mut ptr); + if (*a).NeAACDecInit2.expect("non-null function pointer")( + (*a).hAac, + ptr, + config_len as libc::c_ulong, + samplerate_p, + channels_p, + ) as libc::c_int + == 0 as libc::c_int + { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d playable aac track: %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>( + b"read_mp4_header\x00", + )) + .as_ptr(), + 151 as libc::c_int, + trak, + ); + } + play = trak + } + } + // extract the total number of samples from stts + if crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"stts\x00" as *const u8 as *const libc::c_char, + ) == 0 + && bytes > len as libc::c_ulong + { + let mut i: crate::squeezelite_h::u32_t = 0; + let mut ptr_0 = (*streambuf).readp.offset(12 as libc::c_int as isize); + let mut entries = crate::src::utils::unpackN(ptr_0 as *mut crate::squeezelite_h::u32_t); + ptr_0 = ptr_0.offset(4 as libc::c_int as isize); + i = 0 as libc::c_int as crate::squeezelite_h::u32_t; + while i < entries { + let mut count = + crate::src::utils::unpackN(ptr_0 as *mut crate::squeezelite_h::u32_t); + let mut size = crate::src::utils::unpackN( + ptr_0.offset(4 as libc::c_int as isize) as *mut crate::squeezelite_h::u32_t + ); + (*a).sttssamples = ((*a).sttssamples as libc::c_ulong) + .wrapping_add(count.wrapping_mul(size) as libc::c_ulong) + as crate::squeezelite_h::u64_t + as crate::squeezelite_h::u64_t; + ptr_0 = ptr_0.offset(8 as libc::c_int as isize); + i = i.wrapping_add(1) + } + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d total number of samples contained in stts: %lu\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>( + b"read_mp4_header\x00", + )) + .as_ptr(), + 168 as libc::c_int, + (*a).sttssamples, + ); + } + } + // stash sample to chunk info, assume it comes before stco + if crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"stsc\x00" as *const u8 as *const libc::c_char, + ) == 0 + && bytes > len as libc::c_ulong + && (*a).chunkinfo.is_null() + { + (*a).stsc = crate::stdlib::malloc( + len.wrapping_sub(12 as libc::c_int as libc::c_uint) as libc::c_ulong + ); + if (*a).stsc.is_null() { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d malloc fail\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>( + b"read_mp4_header\x00", + )) + .as_ptr(), + 175 as libc::c_int, + ); + } + return -(1 as libc::c_int); + } + crate::stdlib::memcpy( + (*a).stsc, + (*streambuf).readp.offset(12 as libc::c_int as isize) as *const libc::c_void, + len.wrapping_sub(12 as libc::c_int as libc::c_uint) as libc::c_ulong, + ); + } + // build offsets table from stco and stored stsc + if crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"stco\x00" as *const u8 as *const libc::c_char, + ) == 0 + && bytes > len as libc::c_ulong + && play == trak + { + let mut i_0: crate::squeezelite_h::u32_t = 0; + // extract chunk offsets + let mut ptr_1 = (*streambuf).readp.offset(12 as libc::c_int as isize); + let mut entries_0 = + crate::src::utils::unpackN(ptr_1 as *mut crate::squeezelite_h::u32_t); + ptr_1 = ptr_1.offset(4 as libc::c_int as isize); + (*a).chunkinfo = crate::stdlib::malloc( + (::std::mem::size_of::() as libc::c_ulong).wrapping_mul( + entries_0.wrapping_add(1 as libc::c_int as libc::c_uint) as libc::c_ulong, + ), + ) as *mut chunk_table; + if (*a).chunkinfo.is_null() { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d malloc fail\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>( + b"read_mp4_header\x00", + )) + .as_ptr(), + 190 as libc::c_int, + ); + } + return -(1 as libc::c_int); + } + i_0 = 0 as libc::c_int as crate::squeezelite_h::u32_t; + while i_0 < entries_0 { + (*(*a).chunkinfo.offset(i_0 as isize)).offset = + crate::src::utils::unpackN(ptr_1 as *mut crate::squeezelite_h::u32_t); + (*(*a).chunkinfo.offset(i_0 as isize)).sample = + 0 as libc::c_int as crate::squeezelite_h::u32_t; + ptr_1 = ptr_1.offset(4 as libc::c_int as isize); + i_0 = i_0.wrapping_add(1) + } + (*(*a).chunkinfo.offset(i_0 as isize)).sample = + 0 as libc::c_int as crate::squeezelite_h::u32_t; + (*(*a).chunkinfo.offset(i_0 as isize)).offset = + 0 as libc::c_int as crate::squeezelite_h::u32_t; + // fill in first sample id for each chunk from stored stsc + if !(*a).stsc.is_null() { + let mut stsc_entries = + crate::src::utils::unpackN((*a).stsc as *mut crate::squeezelite_h::u32_t); + let mut sample = 0 as libc::c_int as crate::squeezelite_h::u32_t; + let mut last = 0 as libc::c_int as crate::squeezelite_h::u32_t; + let mut last_samples = 0 as libc::c_int as crate::squeezelite_h::u32_t; + let mut ptr_2 = ((*a).stsc as *mut crate::squeezelite_h::u8_t) + .offset(4 as libc::c_int as isize); + loop { + let fresh2 = stsc_entries; + stsc_entries = stsc_entries.wrapping_sub(1); + if !(fresh2 != 0) { + break; + } + let mut first = + crate::src::utils::unpackN(ptr_2 as *mut crate::squeezelite_h::u32_t); + let mut samples = + crate::src::utils::unpackN(ptr_2.offset(4 as libc::c_int as isize) + as *mut crate::squeezelite_h::u32_t); + if last != 0 { + i_0 = last.wrapping_sub(1 as libc::c_int as libc::c_uint); + while i_0 < first.wrapping_sub(1 as libc::c_int as libc::c_uint) { + (*(*a).chunkinfo.offset(i_0 as isize)).sample = sample; + sample = (sample as libc::c_uint).wrapping_add(last_samples) + as crate::squeezelite_h::u32_t + as crate::squeezelite_h::u32_t; + i_0 = i_0.wrapping_add(1) + } + } + if stsc_entries == 0 as libc::c_int as libc::c_uint { + i_0 = first.wrapping_sub(1 as libc::c_int as libc::c_uint); + while i_0 < entries_0 { + (*(*a).chunkinfo.offset(i_0 as isize)).sample = sample; + sample = (sample as libc::c_uint).wrapping_add(samples) + as crate::squeezelite_h::u32_t + as crate::squeezelite_h::u32_t; + i_0 = i_0.wrapping_add(1) + } + } + last = first; + last_samples = samples; + ptr_2 = ptr_2.offset(12 as libc::c_int as isize) + } + crate::stdlib::free((*a).stsc); + (*a).stsc = 0 as *mut libc::c_void + } + } + // found media data, advance to start of first chunk and return + if crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"mdat\x00" as *const u8 as *const libc::c_char, + ) == 0 + { + crate::src::buffer::_buf_inc_readp(streambuf, 8 as libc::c_int as libc::c_uint); + (*a).pos = ((*a).pos as libc::c_uint).wrapping_add(8 as libc::c_int as libc::c_uint) + as crate::squeezelite_h::u32_t + as crate::squeezelite_h::u32_t; + bytes = (bytes as libc::c_ulong).wrapping_sub(8 as libc::c_int as libc::c_ulong) + as crate::stddef_h::size_t as crate::stddef_h::size_t; + if play != 0 { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d type: mdat len: %u pos: %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>( + b"read_mp4_header\x00", + )) + .as_ptr(), + 236 as libc::c_int, + len, + (*a).pos, + ); + } + if !(*a).chunkinfo.is_null() + && (*(*a).chunkinfo.offset(0 as libc::c_int as isize)).offset > (*a).pos + { + let mut skip = (*(*a).chunkinfo.offset(0 as libc::c_int as isize)) + .offset + .wrapping_sub((*a).pos); + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d skipping: %u\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>( + b"read_mp4_header\x00", + )) + .as_ptr(), + 239 as libc::c_int, + skip, + ); + } + if skip as libc::c_ulong <= bytes { + crate::src::buffer::_buf_inc_readp(streambuf, skip); + (*a).pos = ((*a).pos as libc::c_uint).wrapping_add(skip) + as crate::squeezelite_h::u32_t + as crate::squeezelite_h::u32_t + } else { + (*a).consume = skip + } + } + (*a).nextchunk = 1 as libc::c_int as crate::squeezelite_h::u32_t; + (*a).sample = (*a).nextchunk; + return 1 as libc::c_int; + } else { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d type: mdat len: %u, no playable track found\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>( + b"read_mp4_header\x00", + )) + .as_ptr(), + 250 as libc::c_int, + len, + ); + } + return -(1 as libc::c_int); + } + } + // parse key-value atoms within ilst ---- entries to get encoder padding within iTunSMPB entry for gapless + if crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"----\x00" as *const u8 as *const libc::c_char, + ) == 0 + && bytes > len as libc::c_ulong + { + let mut ptr_3 = (*streambuf).readp.offset(8 as libc::c_int as isize); + let mut remain = len.wrapping_sub(8 as libc::c_int as libc::c_uint); + let mut size_0: crate::squeezelite_h::u32_t = 0; + if crate::stdlib::memcmp( + ptr_3.offset(4 as libc::c_int as isize) as *const libc::c_void, + b"mean\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ) == 0 + && { + size_0 = crate::src::utils::unpackN(ptr_3 as *mut crate::squeezelite_h::u32_t); + (size_0) < remain + } + { + ptr_3 = ptr_3.offset(size_0 as isize); + remain = (remain as libc::c_uint).wrapping_sub(size_0) + as crate::squeezelite_h::u32_t + as crate::squeezelite_h::u32_t + } + if crate::stdlib::memcmp( + ptr_3.offset(4 as libc::c_int as isize) as *const libc::c_void, + b"name\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ) == 0 + && { + size_0 = crate::src::utils::unpackN(ptr_3 as *mut crate::squeezelite_h::u32_t); + (size_0) < remain + } + && crate::stdlib::memcmp( + ptr_3.offset(12 as libc::c_int as isize) as *const libc::c_void, + b"iTunSMPB\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 8 as libc::c_int as libc::c_ulong, + ) == 0 + { + ptr_3 = ptr_3.offset(size_0 as isize); + remain = (remain as libc::c_uint).wrapping_sub(size_0) + as crate::squeezelite_h::u32_t + as crate::squeezelite_h::u32_t + } + if crate::stdlib::memcmp( + ptr_3.offset(4 as libc::c_int as isize) as *const libc::c_void, + b"data\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ) == 0 + && remain > (16 as libc::c_int + 48 as libc::c_int) as libc::c_uint + { + // data is stored as hex strings: 0 start end samples + let mut b: crate::squeezelite_h::u32_t = 0; + let mut c: crate::squeezelite_h::u32_t = 0; + let mut d: crate::squeezelite_h::u64_t = 0; + if crate::stdlib::sscanf( + ptr_3.offset(16 as libc::c_int as isize) as *const libc::c_char, + b"%x %x %x %lx\x00" as *const u8 as *const libc::c_char, + &mut b as *mut crate::squeezelite_h::u32_t, + &mut b as *mut crate::squeezelite_h::u32_t, + &mut c as *mut crate::squeezelite_h::u32_t, + &mut d as *mut crate::squeezelite_h::u64_t, + ) == 4 as libc::c_int + { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d iTunSMPB start: %u end: %u samples: %lu\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>( + b"read_mp4_header\x00", + )) + .as_ptr(), + 269 as libc::c_int, + b, + c, + d, + ); + } + if (*a).sttssamples != 0 + && (*a).sttssamples < (b.wrapping_add(c) as libc::c_ulong).wrapping_add(d) + { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d reducing samples as stts count is less\n\x00" + as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>( + b"read_mp4_header\x00", + )) + .as_ptr(), + 271 as libc::c_int, + ); + } + d = (*a) + .sttssamples + .wrapping_sub(b.wrapping_add(c) as libc::c_ulong) + } + (*a).skip = b; + (*a).samples = d + } + } + } + // default to consuming entire box + consume = len; + // read into these boxes so reduce consume + if crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"moov\x00" as *const u8 as *const libc::c_char, + ) == 0 + || crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"trak\x00" as *const u8 as *const libc::c_char, + ) == 0 + || crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"mdia\x00" as *const u8 as *const libc::c_char, + ) == 0 + || crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"minf\x00" as *const u8 as *const libc::c_char, + ) == 0 + || crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"stbl\x00" as *const u8 as *const libc::c_char, + ) == 0 + || crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"udta\x00" as *const u8 as *const libc::c_char, + ) == 0 + || crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"ilst\x00" as *const u8 as *const libc::c_char, + ) == 0 + { + consume = 8 as libc::c_int as crate::squeezelite_h::u32_t + } + // special cases which mix mix data in the enclosing box which we want to read into + if crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"stsd\x00" as *const u8 as *const libc::c_char, + ) == 0 + { + consume = 16 as libc::c_int as crate::squeezelite_h::u32_t + } + if crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"mp4a\x00" as *const u8 as *const libc::c_char, + ) == 0 + { + consume = 36 as libc::c_int as crate::squeezelite_h::u32_t + } + if crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"meta\x00" as *const u8 as *const libc::c_char, + ) == 0 + { + consume = 12 as libc::c_int as crate::squeezelite_h::u32_t + } + // consume rest of box if it has been parsed (all in the buffer) or is not one we want to parse + if bytes >= consume as libc::c_ulong { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d type: %s len: %u consume: %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>( + b"read_mp4_header\x00", + )) + .as_ptr(), + 295 as libc::c_int, + type_0.as_mut_ptr(), + len, + consume, + ); + } + crate::src::buffer::_buf_inc_readp(streambuf, consume); + (*a).pos = ((*a).pos as libc::c_uint).wrapping_add(consume) + as crate::squeezelite_h::u32_t + as crate::squeezelite_h::u32_t; + bytes = (bytes as libc::c_ulong).wrapping_sub(consume as libc::c_ulong) + as crate::stddef_h::size_t as crate::stddef_h::size_t + } else { + if crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"esds\x00" as *const u8 as *const libc::c_char, + ) == 0 + || crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"stts\x00" as *const u8 as *const libc::c_char, + ) == 0 + || crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"stsc\x00" as *const u8 as *const libc::c_char, + ) == 0 + || crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"stco\x00" as *const u8 as *const libc::c_char, + ) == 0 + || crate::stdlib::strcmp( + type_0.as_mut_ptr(), + b"----\x00" as *const u8 as *const libc::c_char, + ) == 0 + { + break; + } + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d type: %s len: %u consume: %u - partial consume: %u\n\x00" + as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>( + b"read_mp4_header\x00", + )) + .as_ptr(), + 301 as libc::c_int, + type_0.as_mut_ptr(), + len, + consume, + bytes, + ); + } + crate::src::buffer::_buf_inc_readp(streambuf, bytes as libc::c_uint); + (*a).pos = ((*a).pos as libc::c_ulong).wrapping_add(bytes) + as crate::squeezelite_h::u32_t + as crate::squeezelite_h::u32_t; + (*a).consume = + (consume as libc::c_ulong).wrapping_sub(bytes) as crate::squeezelite_h::u32_t; + break; + } + } + return 0 as libc::c_int; +} + +unsafe extern "C" fn faad_decode() -> crate::squeezelite_h::decode_state { + let mut bytes_total: crate::stddef_h::size_t = 0; + let mut bytes_wrap: crate::stddef_h::size_t = 0; + let mut info = crate::stdlib::NeAACDecFrameInfo { + bytesconsumed: 0, + samples: 0, + channels: 0, + error: 0, + samplerate: 0, + sbr: 0, + object_type: 0, + header_type: 0, + num_front_channels: 0, + num_side_channels: 0, + num_back_channels: 0, + num_lfe_channels: 0, + channel_position: [0; 64], + ps: 0, + }; + let mut iptr = 0 as *mut crate::squeezelite_h::s32_t; + let mut endstream: bool = false; + let mut frames: crate::squeezelite_h::frames_t = 0; + crate::stdlib::pthread_mutex_lock(&mut (*streambuf).mutex); + bytes_total = crate::squeezelite_h::_buf_used(streambuf) as crate::stddef_h::size_t; + bytes_wrap = if bytes_total < crate::src::buffer::_buf_cont_read(streambuf) as libc::c_ulong { + bytes_total + } else { + crate::src::buffer::_buf_cont_read(streambuf) as libc::c_ulong + }; + if stream.state as libc::c_uint + <= crate::squeezelite_h::DISCONNECT as libc::c_int as libc::c_uint + && bytes_total == 0 + { + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + return crate::squeezelite_h::DECODE_COMPLETE; + } + if (*a).consume != 0 { + let mut consume = if ((*a).consume as libc::c_ulong) < bytes_wrap { + (*a).consume as libc::c_ulong + } else { + bytes_wrap + } as crate::squeezelite_h::u32_t; + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d consume: %u of %u\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"faad_decode\x00")) + .as_ptr(), + 333 as libc::c_int, + consume, + (*a).consume, + ); + } + crate::src::buffer::_buf_inc_readp(streambuf, consume); + (*a).pos = ((*a).pos as libc::c_uint).wrapping_add(consume) as crate::squeezelite_h::u32_t + as crate::squeezelite_h::u32_t; + (*a).consume = ((*a).consume as libc::c_uint).wrapping_sub(consume) + as crate::squeezelite_h::u32_t as crate::squeezelite_h::u32_t; + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + return crate::squeezelite_h::DECODE_RUNNING; + } + if decode.new_stream { + let mut found = 0 as libc::c_int; + static mut channels: libc::c_uchar = 0; + static mut samplerate: libc::c_ulong = 0; + if (*a).type_0 as libc::c_int == '2' as i32 { + // adts stream - seek for header + while bytes_wrap >= 2 as libc::c_int as libc::c_ulong + && (*(*streambuf).readp as libc::c_int != 0xff as libc::c_int + || *(*streambuf).readp.offset(1 as libc::c_int as isize) as libc::c_int + & 0xf6 as libc::c_int + != 0xf0 as libc::c_int) + { + crate::src::buffer::_buf_inc_readp(streambuf, 1 as libc::c_int as libc::c_uint); + bytes_total = bytes_total.wrapping_sub(1); + bytes_wrap = bytes_wrap.wrapping_sub(1) + } + if bytes_wrap >= 2 as libc::c_int as libc::c_ulong { + let mut n = (*a).NeAACDecInit.expect("non-null function pointer")( + (*a).hAac, + (*streambuf).readp, + bytes_wrap, + &mut samplerate, + &mut channels, + ); + if n < 0 as libc::c_int as libc::c_long { + found = -(1 as libc::c_int) + } else { + crate::src::buffer::_buf_inc_readp(streambuf, n as libc::c_uint); + found = 1 as libc::c_int + } + } + } else { + // mp4 - read header + found = read_mp4_header(&mut samplerate, &mut channels) + } + if found == 1 as libc::c_int { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d samplerate: %u channels: %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"faad_decode\x00")) + .as_ptr(), + 373 as libc::c_int, + samplerate, + channels as libc::c_int, + ); + } + bytes_total = crate::squeezelite_h::_buf_used(streambuf) as crate::stddef_h::size_t; + bytes_wrap = + if bytes_total < crate::src::buffer::_buf_cont_read(streambuf) as libc::c_ulong { + bytes_total + } else { + crate::src::buffer::_buf_cont_read(streambuf) as libc::c_ulong + }; + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d setting track_start\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"faad_decode\x00")) + .as_ptr(), + 378 as libc::c_int, + ); + } + output.next_sample_rate = crate::src::decode::decode_newstream( + samplerate as libc::c_uint, + output.supported_rates.as_mut_ptr(), + ); + output.track_start = (*outputbuf).writep; + if output.fade_mode as u64 != 0 { + crate::src::output::_checkfade(1 as libc::c_int != 0); + } + decode.new_stream = 0 as libc::c_int != 0; + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + } else if found == -(1 as libc::c_int) { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d error reading stream header\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"faad_decode\x00")) + .as_ptr(), + 388 as libc::c_int, + ); + } + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + return crate::squeezelite_h::DECODE_ERROR; + } else { + // not finished header parsing come back next time + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + return crate::squeezelite_h::DECODE_RUNNING; + } + } + if bytes_wrap < 2048 as libc::c_int as libc::c_ulong + && bytes_total > 2048 as libc::c_int as libc::c_ulong + { + // make a local copy of frames which may have wrapped round the end of streambuf + let mut buf: [crate::squeezelite_h::u8_t; 2048] = [0; 2048]; + crate::stdlib::memcpy( + buf.as_mut_ptr() as *mut libc::c_void, + (*streambuf).readp as *const libc::c_void, + bytes_wrap, + ); + crate::stdlib::memcpy( + buf.as_mut_ptr().offset(bytes_wrap as isize) as *mut libc::c_void, + (*streambuf).buf as *const libc::c_void, + (2048 as libc::c_int as libc::c_ulong).wrapping_sub(bytes_wrap), + ); + iptr = (*a).NeAACDecDecode.expect("non-null function pointer")( + (*a).hAac, + &mut info, + buf.as_mut_ptr(), + 2048 as libc::c_int as libc::c_ulong, + ) as *mut crate::squeezelite_h::s32_t + } else { + iptr = (*a).NeAACDecDecode.expect("non-null function pointer")( + (*a).hAac, + &mut info, + (*streambuf).readp, + bytes_wrap, + ) as *mut crate::squeezelite_h::s32_t + } + if info.error != 0 { + if loglevel as libc::c_uint >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d error: %u %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"faad_decode\x00")) + .as_ptr(), + 415 as libc::c_int, + info.error as libc::c_int, + (*a).NeAACDecGetErrorMessage + .expect("non-null function pointer")(info.error), + ); + } + } + endstream = 0 as libc::c_int != 0; + // mp4 end of chunk - skip to next offset + if !(*a).chunkinfo.is_null() + && (*(*a).chunkinfo.offset((*a).nextchunk as isize)).offset != 0 + && { + let fresh3 = (*a).sample; + (*a).sample = (*a).sample.wrapping_add(1); + (fresh3) == (*(*a).chunkinfo.offset((*a).nextchunk as isize)).sample + } + { + if (*(*a).chunkinfo.offset((*a).nextchunk as isize)).offset > (*a).pos { + let mut skip = (*(*a).chunkinfo.offset((*a).nextchunk as isize)) + .offset + .wrapping_sub((*a).pos); + if skip as libc::c_ulong != info.bytesconsumed { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d skipping to next chunk pos: %u consumed: %u != skip: %u\n\x00" + as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>( + b"faad_decode\x00", + )) + .as_ptr(), + 426 as libc::c_int, + (*a).pos, + info.bytesconsumed, + skip, + ); + } + } + if bytes_total >= skip as libc::c_ulong { + crate::src::buffer::_buf_inc_readp(streambuf, skip); + (*a).pos = ((*a).pos as libc::c_uint).wrapping_add(skip) + as crate::squeezelite_h::u32_t + as crate::squeezelite_h::u32_t + } else { + (*a).consume = skip + } + (*a).nextchunk = (*a).nextchunk.wrapping_add(1) + } else { + crate::src::utils::logprint( + b"%s %s:%d error: need to skip backwards!\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"faad_decode\x00")) + .as_ptr(), + 436 as libc::c_int, + ); + endstream = 1 as libc::c_int != 0 + } + // adts and mp4 when not at end of chunk + } else if info.bytesconsumed != 0 as libc::c_int as libc::c_ulong { + crate::src::buffer::_buf_inc_readp(streambuf, info.bytesconsumed as libc::c_uint); + (*a).pos = ((*a).pos as libc::c_ulong).wrapping_add(info.bytesconsumed) + as crate::squeezelite_h::u32_t as crate::squeezelite_h::u32_t + // error which doesn't advance streambuf - end + } else { + endstream = 1 as libc::c_int != 0 + } + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + if endstream { + if loglevel as libc::c_uint >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d unable to decode further\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"faad_decode\x00")) + .as_ptr(), + 454 as libc::c_int, + ); + } + return crate::squeezelite_h::DECODE_ERROR; + } + if info.samples == 0 { + (*a).empty = 1 as libc::c_int != 0; + return crate::squeezelite_h::DECODE_RUNNING; + } + frames = + info.samples.wrapping_div(info.channels as libc::c_ulong) as crate::squeezelite_h::frames_t; + if (*a).skip != 0 { + let mut skip_0: crate::squeezelite_h::u32_t = 0; + if (*a).empty { + (*a).empty = 0 as libc::c_int != 0; + (*a).skip = ((*a).skip as libc::c_uint).wrapping_sub(frames) + as crate::squeezelite_h::u32_t + as crate::squeezelite_h::u32_t; + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d gapless: first frame empty, skipped %u frames at start\n\x00" + as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"faad_decode\x00")) + .as_ptr(), + 470 as libc::c_int, + frames, + ); + } + } + skip_0 = if frames < (*a).skip { + frames + } else { + (*a).skip + }; + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d gapless: skipping %u frames at start\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"faad_decode\x00")) + .as_ptr(), + 473 as libc::c_int, + skip_0, + ); + } + frames = (frames as libc::c_uint).wrapping_sub(skip_0) as crate::squeezelite_h::frames_t + as crate::squeezelite_h::frames_t; + (*a).skip = ((*a).skip as libc::c_uint).wrapping_sub(skip_0) as crate::squeezelite_h::u32_t + as crate::squeezelite_h::u32_t; + iptr = iptr.offset(skip_0.wrapping_mul(info.channels as libc::c_uint) as isize) + } + if (*a).samples != 0 { + if (*a).samples < frames as libc::c_ulong { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d gapless: trimming %u frames from end\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"faad_decode\x00")) + .as_ptr(), + 481 as libc::c_int, + (frames as libc::c_ulong).wrapping_sub((*a).samples), + ); + } + frames = (*a).samples as crate::squeezelite_h::frames_t + } + (*a).samples = ((*a).samples as libc::c_ulong).wrapping_sub(frames as libc::c_ulong) + as crate::squeezelite_h::u64_t as crate::squeezelite_h::u64_t + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d write %u frames\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"faad_decode\x00")).as_ptr(), + 487 as libc::c_int, + frames, + ); + } + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + while frames > 0 as libc::c_int as libc::c_uint { + let mut f: crate::squeezelite_h::frames_t = 0; + let mut count: crate::squeezelite_h::frames_t = 0; + let mut optr = 0 as *mut crate::squeezelite_h::s32_t; + f = crate::src::buffer::_buf_cont_write(outputbuf) + .wrapping_div(8 as libc::c_int as libc::c_uint); + optr = (*outputbuf).writep as *mut crate::squeezelite_h::s32_t; + f = if f < frames { f } else { frames }; + count = f; + if info.channels as libc::c_int == 2 as libc::c_int { + loop { + let fresh4 = count; + count = count.wrapping_sub(1); + if !(fresh4 != 0) { + break; + } + let fresh5 = iptr; + iptr = iptr.offset(1); + let fresh6 = optr; + optr = optr.offset(1); + *fresh6 = *fresh5 << 8 as libc::c_int; + let fresh7 = iptr; + iptr = iptr.offset(1); + let fresh8 = optr; + optr = optr.offset(1); + *fresh8 = *fresh7 << 8 as libc::c_int + } + } else if info.channels as libc::c_int == 1 as libc::c_int { + loop { + let fresh9 = count; + count = count.wrapping_sub(1); + if !(fresh9 != 0) { + break; + } + let fresh10 = optr; + optr = optr.offset(1); + *fresh10 = *iptr << 8 as libc::c_int; + let fresh11 = iptr; + iptr = iptr.offset(1); + let fresh12 = optr; + optr = optr.offset(1); + *fresh12 = *fresh11 << 8 as libc::c_int + } + } else if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d unsupported number of channels\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"faad_decode\x00")) + .as_ptr(), + 519 as libc::c_int, + ); + } + frames = (frames as libc::c_uint).wrapping_sub(f) as crate::squeezelite_h::frames_t + as crate::squeezelite_h::frames_t; + crate::src::buffer::_buf_inc_writep( + outputbuf, + f.wrapping_mul(8 as libc::c_int as libc::c_uint), + ); + } + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + return crate::squeezelite_h::DECODE_RUNNING; +} + +unsafe extern "C" fn faad_open( + mut size: crate::squeezelite_h::u8_t, + mut rate: crate::squeezelite_h::u8_t, + mut chan: crate::squeezelite_h::u8_t, + mut endianness: crate::squeezelite_h::u8_t, +) { + let mut conf = 0 as *mut crate::stdlib::NeAACDecConfiguration; + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d opening %s stream\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"faad_open\x00")).as_ptr(), + 541 as libc::c_int, + if size as libc::c_int == '2' as i32 { + b"adts\x00" as *const u8 as *const libc::c_char + } else { + b"mp4\x00" as *const u8 as *const libc::c_char + }, + ); + } + (*a).type_0 = size; + (*a).nextchunk = 0 as libc::c_int as crate::squeezelite_h::u32_t; + (*a).sample = (*a).nextchunk; + (*a).consume = (*a).sample; + (*a).pos = (*a).consume; + if !(*a).chunkinfo.is_null() { + crate::stdlib::free((*a).chunkinfo as *mut libc::c_void); + } + if !(*a).stsc.is_null() { + crate::stdlib::free((*a).stsc); + } + (*a).chunkinfo = 0 as *mut chunk_table; + (*a).stsc = 0 as *mut libc::c_void; + (*a).skip = 0 as libc::c_int as crate::squeezelite_h::u32_t; + (*a).samples = 0 as libc::c_int as crate::squeezelite_h::u64_t; + (*a).sttssamples = 0 as libc::c_int as crate::squeezelite_h::u64_t; + (*a).empty = 0 as libc::c_int != 0; + if !(*a).hAac.is_null() { + (*a).NeAACDecClose.expect("non-null function pointer")((*a).hAac); + } + (*a).hAac = (*a).NeAACDecOpen.expect("non-null function pointer")(); + conf = (*a) + .NeAACDecGetCurrentConfiguration + .expect("non-null function pointer")((*a).hAac); + (*conf).outputFormat = 2 as libc::c_int as libc::c_uchar; + (*conf).downMatrix = 1 as libc::c_int as libc::c_uchar; + if (*a) + .NeAACDecSetConfiguration + .expect("non-null function pointer")((*a).hAac, conf) + == 0 + { + if loglevel as libc::c_uint >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d error setting config\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"faad_open\x00")) + .as_ptr(), + 570 as libc::c_int, + ); + } + }; +} + +unsafe extern "C" fn faad_close() { + (*a).NeAACDecClose.expect("non-null function pointer")((*a).hAac); + (*a).hAac = 0 as *mut libc::c_void; + if !(*a).chunkinfo.is_null() { + crate::stdlib::free((*a).chunkinfo as *mut libc::c_void); + (*a).chunkinfo = 0 as *mut chunk_table + } + if !(*a).stsc.is_null() { + crate::stdlib::free((*a).stsc); + (*a).stsc = 0 as *mut libc::c_void + }; +} + +unsafe extern "C" fn load_faad() -> bool { + let mut handle = crate::stdlib::dlopen( + b"libfaad.so.2\x00" as *const u8 as *const libc::c_char, + 0x2 as libc::c_int, + ); + let mut err = 0 as *mut libc::c_char; + if handle.is_null() { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d dlerror: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"load_faad\x00")) + .as_ptr(), + 593 as libc::c_int, + crate::stdlib::dlerror(), + ); + } + return 0 as libc::c_int != 0; + } + (*a).NeAACDecGetCurrentConfiguration = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: crate::stdlib::NeAACDecHandle, + ) -> crate::stdlib::NeAACDecConfigurationPtr, + >, + >(crate::stdlib::dlsym( + handle, + b"NeAACDecGetCurrentConfiguration\x00" as *const u8 as *const libc::c_char, + )); + (*a).NeAACDecSetConfiguration = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: crate::stdlib::NeAACDecHandle, + _: crate::stdlib::NeAACDecConfigurationPtr, + ) -> libc::c_uchar, + >, + >(crate::stdlib::dlsym( + handle, + b"NeAACDecSetConfiguration\x00" as *const u8 as *const libc::c_char, + )); + (*a).NeAACDecOpen = ::std::mem::transmute::< + *mut libc::c_void, + Option crate::stdlib::NeAACDecHandle>, + >(crate::stdlib::dlsym( + handle, + b"NeAACDecOpen\x00" as *const u8 as *const libc::c_char, + )); + (*a).NeAACDecClose = ::std::mem::transmute::< + *mut libc::c_void, + Option ()>, + >(crate::stdlib::dlsym( + handle, + b"NeAACDecClose\x00" as *const u8 as *const libc::c_char, + )); + (*a).NeAACDecInit = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: crate::stdlib::NeAACDecHandle, + _: *mut libc::c_uchar, + _: libc::c_ulong, + _: *mut libc::c_ulong, + _: *mut libc::c_uchar, + ) -> libc::c_long, + >, + >(crate::stdlib::dlsym( + handle, + b"NeAACDecInit\x00" as *const u8 as *const libc::c_char, + )); + (*a).NeAACDecInit2 = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: crate::stdlib::NeAACDecHandle, + _: *mut libc::c_uchar, + _: libc::c_ulong, + _: *mut libc::c_ulong, + _: *mut libc::c_uchar, + ) -> libc::c_char, + >, + >(crate::stdlib::dlsym( + handle, + b"NeAACDecInit2\x00" as *const u8 as *const libc::c_char, + )); + (*a).NeAACDecDecode = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: crate::stdlib::NeAACDecHandle, + _: *mut crate::stdlib::NeAACDecFrameInfo, + _: *mut libc::c_uchar, + _: libc::c_ulong, + ) -> *mut libc::c_void, + >, + >(crate::stdlib::dlsym( + handle, + b"NeAACDecDecode\x00" as *const u8 as *const libc::c_char, + )); + (*a).NeAACDecGetErrorMessage = ::std::mem::transmute::< + *mut libc::c_void, + Option *mut libc::c_char>, + >(crate::stdlib::dlsym( + handle, + b"NeAACDecGetErrorMessage\x00" as *const u8 as *const libc::c_char, + )); + err = crate::stdlib::dlerror(); + if !err.is_null() { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d dlerror: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"load_faad\x00")) + .as_ptr(), + 607 as libc::c_int, + err, + ); + } + return 0 as libc::c_int != 0; + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d loaded libfaad.so.2\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"load_faad\x00")).as_ptr(), + 611 as libc::c_int, + ); + } + return 1 as libc::c_int != 0; +} +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Additions (c) Paul Hermann, 2015-2017 under the same license terms + * -Control of Raspberry pi GPIO for amplifier power + * -Launch script on power status change from LMS + */ +// make may define: PORTAUDIO, SELFPIPE, RESAMPLE, RESAMPLE_MP, VISEXPORT, GPIO, IR, DSD, LINKALL to influence build +// build detection +// dynamically loaded libraries at run time +// !LINKALL +// config options +// do not reduce as icy-meta max is 4080 +/* SUN */ +/* SUN */ +// printf/scanf formats for u64_t +// logging +// utils.c (non logging) +// buffer.c +// _* called with mutex locked +// slimproto.c +// stream.c +// decode.c +// output.c output_alsa.c output_pa.c output_pack.c +// frames played at the point delay is measured +// ordered largest first so [0] is max_rate +// set in decode thread +// set in decode thread +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// _* called with mutex locked +// output_alsa.c +// output_pa.c +// output_pulse.c +// output_stdout.c +// output_pack.c +// output_vis.c +// dop.c +// codecs +#[no_mangle] + +pub unsafe extern "C" fn register_faad() -> *mut crate::squeezelite_h::codec { + static mut ret: crate::squeezelite_h::codec = unsafe { + { + let mut init = crate::squeezelite_h::codec { + id: 'a' as i32 as libc::c_char, + types: b"aac\x00" as *const u8 as *const libc::c_char as *mut libc::c_char, + min_read_bytes: 2048 as libc::c_int as libc::c_uint, + min_space: 20480 as libc::c_int as libc::c_uint, + open: Some( + faad_open + as unsafe extern "C" fn( + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + ) -> (), + ), + close: Some(faad_close as unsafe extern "C" fn() -> ()), + decode: Some( + faad_decode as unsafe extern "C" fn() -> crate::squeezelite_h::decode_state, + ), + }; + init + } + }; + a = crate::stdlib::malloc(::std::mem::size_of::() as libc::c_ulong) as *mut faad; + if a.is_null() { + return 0 as *mut crate::squeezelite_h::codec; + } + (*a).hAac = 0 as *mut libc::c_void; + (*a).chunkinfo = 0 as *mut chunk_table; + (*a).stsc = 0 as *mut libc::c_void; + if !load_faad() { + return 0 as *mut crate::squeezelite_h::codec; + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d using faad to decode aac\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>(b"register_faad\x00")) + .as_ptr(), + 641 as libc::c_int, + ); + } + return &mut ret; +} diff --git a/src/flac.rs b/src/flac.rs new file mode 100644 index 0000000..28e883a --- /dev/null +++ b/src/flac.rs @@ -0,0 +1,927 @@ +use ::c2rust_bitfields; +use ::libc; + +pub use crate::stddef_h::size_t; +pub use crate::stdlib::__int32_t; +pub use crate::stdlib::__uint16_t; +pub use crate::stdlib::__uint32_t; +pub use crate::stdlib::__uint64_t; +pub use crate::stdlib::__uint8_t; +pub use crate::stdlib::int32_t; + +pub use crate::stdlib::__pthread_internal_list; +pub use crate::stdlib::__pthread_list_t; +pub use crate::stdlib::__pthread_mutex_s; +pub use crate::stdlib::pthread_mutex_t; +pub use crate::stdlib::u_int32_t; +pub use crate::stdlib::u_int64_t; +pub use crate::stdlib::u_int8_t; + +pub use crate::squeezelite_h::buffer; +pub use crate::squeezelite_h::codec; +pub use crate::squeezelite_h::decode_state; +pub use crate::squeezelite_h::decodestate; +pub use crate::squeezelite_h::disconnect_code; +pub use crate::squeezelite_h::fade_dir; +pub use crate::squeezelite_h::fade_mode; +pub use crate::squeezelite_h::fade_state; +pub use crate::squeezelite_h::frames_t; +pub use crate::squeezelite_h::lDEBUG; +pub use crate::squeezelite_h::lERROR; +pub use crate::squeezelite_h::lINFO; +pub use crate::squeezelite_h::lSDEBUG; +pub use crate::squeezelite_h::lWARN; +pub use crate::squeezelite_h::log_level; +pub use crate::squeezelite_h::output_format; +pub use crate::squeezelite_h::output_state; +pub use crate::squeezelite_h::outputstate; +pub use crate::squeezelite_h::s32_t; +pub use crate::squeezelite_h::stream_state; +pub use crate::squeezelite_h::streamstate; +pub use crate::squeezelite_h::u32_t; +pub use crate::squeezelite_h::u64_t; +pub use crate::squeezelite_h::u8_t; +pub use crate::squeezelite_h::C2RustUnnamed_1; +pub use crate::squeezelite_h::_buf_used; +pub use crate::squeezelite_h::DECODE_COMPLETE; +pub use crate::squeezelite_h::DECODE_ERROR; +pub use crate::squeezelite_h::DECODE_READY; +pub use crate::squeezelite_h::DECODE_RUNNING; +pub use crate::squeezelite_h::DECODE_STOPPED; +pub use crate::squeezelite_h::DISCONNECT; +pub use crate::squeezelite_h::DISCONNECT_OK; +pub use crate::squeezelite_h::FADE_ACTIVE; +pub use crate::squeezelite_h::FADE_CROSS; +pub use crate::squeezelite_h::FADE_CROSSFADE; +pub use crate::squeezelite_h::FADE_DOWN; +pub use crate::squeezelite_h::FADE_DUE; +pub use crate::squeezelite_h::FADE_IN; +pub use crate::squeezelite_h::FADE_INACTIVE; +pub use crate::squeezelite_h::FADE_INOUT; +pub use crate::squeezelite_h::FADE_NONE; +pub use crate::squeezelite_h::FADE_OUT; +pub use crate::squeezelite_h::FADE_UP; +pub use crate::squeezelite_h::LOCAL_DISCONNECT; +pub use crate::squeezelite_h::OUTPUT_BUFFER; +pub use crate::squeezelite_h::OUTPUT_OFF; +pub use crate::squeezelite_h::OUTPUT_PAUSE_FRAMES; +pub use crate::squeezelite_h::OUTPUT_RUNNING; +pub use crate::squeezelite_h::OUTPUT_SKIP_FRAMES; +pub use crate::squeezelite_h::OUTPUT_START_AT; +pub use crate::squeezelite_h::OUTPUT_STOPPED; +pub use crate::squeezelite_h::RECV_HEADERS; +pub use crate::squeezelite_h::REMOTE_DISCONNECT; +pub use crate::squeezelite_h::S16_LE; +pub use crate::squeezelite_h::S24_3LE; +pub use crate::squeezelite_h::S24_LE; +pub use crate::squeezelite_h::S32_LE; +pub use crate::squeezelite_h::SEND_HEADERS; +pub use crate::squeezelite_h::STOPPED; +pub use crate::squeezelite_h::STREAMING_BUFFERING; +pub use crate::squeezelite_h::STREAMING_FILE; +pub use crate::squeezelite_h::STREAMING_HTTP; +pub use crate::squeezelite_h::STREAMING_WAIT; +pub use crate::squeezelite_h::TIMEOUT; +pub use crate::squeezelite_h::UNREACHABLE; +pub use crate::src::buffer::_buf_cont_read; +pub use crate::src::buffer::_buf_cont_write; +pub use crate::src::buffer::_buf_inc_readp; +pub use crate::src::buffer::_buf_inc_writep; +pub use crate::src::buffer::_buf_space; +pub use crate::src::decode::decode_newstream; +pub use crate::src::output::_checkfade; +pub use crate::src::utils::logprint; +pub use crate::src::utils::logtime; +use crate::stdlib::malloc; +use crate::stdlib::memcpy; +pub use crate::stdlib::uint16_t; +pub use crate::stdlib::uint32_t; +pub use crate::stdlib::uint64_t; +pub use crate::stdlib::uint8_t; +pub use crate::stdlib::C2RustUnnamed_4; +pub use crate::stdlib::C2RustUnnamed_5; +pub use crate::stdlib::C2RustUnnamed_6; +pub use crate::stdlib::C2RustUnnamed_7; +pub use crate::stdlib::FLAC__ChannelAssignment; +pub use crate::stdlib::FLAC__EntropyCodingMethod; +pub use crate::stdlib::FLAC__EntropyCodingMethodType; +pub use crate::stdlib::FLAC__EntropyCodingMethod_PartitionedRice; +pub use crate::stdlib::FLAC__EntropyCodingMethod_PartitionedRiceContents; +pub use crate::stdlib::FLAC__Frame; +pub use crate::stdlib::FLAC__FrameFooter; +pub use crate::stdlib::FLAC__FrameHeader; +pub use crate::stdlib::FLAC__FrameNumberType; +pub use crate::stdlib::FLAC__MetadataType; +pub use crate::stdlib::FLAC__StreamDecoder; +pub use crate::stdlib::FLAC__StreamDecoderEofCallback; +pub use crate::stdlib::FLAC__StreamDecoderErrorCallback; +pub use crate::stdlib::FLAC__StreamDecoderErrorStatus; +pub use crate::stdlib::FLAC__StreamDecoderInitStatus; +pub use crate::stdlib::FLAC__StreamDecoderLengthCallback; +pub use crate::stdlib::FLAC__StreamDecoderLengthStatus; +pub use crate::stdlib::FLAC__StreamDecoderMetadataCallback; +pub use crate::stdlib::FLAC__StreamDecoderPrivate; +pub use crate::stdlib::FLAC__StreamDecoderProtected; +pub use crate::stdlib::FLAC__StreamDecoderReadCallback; +pub use crate::stdlib::FLAC__StreamDecoderReadStatus; +pub use crate::stdlib::FLAC__StreamDecoderSeekCallback; +pub use crate::stdlib::FLAC__StreamDecoderSeekStatus; +pub use crate::stdlib::FLAC__StreamDecoderState; +pub use crate::stdlib::FLAC__StreamDecoderTellCallback; +pub use crate::stdlib::FLAC__StreamDecoderTellStatus; +pub use crate::stdlib::FLAC__StreamDecoderWriteCallback; +pub use crate::stdlib::FLAC__StreamDecoderWriteStatus; +pub use crate::stdlib::FLAC__StreamMetadata; +pub use crate::stdlib::FLAC__StreamMetadata_Application; +pub use crate::stdlib::FLAC__StreamMetadata_CueSheet; +pub use crate::stdlib::FLAC__StreamMetadata_CueSheet_Index; +pub use crate::stdlib::FLAC__StreamMetadata_CueSheet_Track; +pub use crate::stdlib::FLAC__StreamMetadata_Padding; +pub use crate::stdlib::FLAC__StreamMetadata_Picture; +pub use crate::stdlib::FLAC__StreamMetadata_Picture_Type; +pub use crate::stdlib::FLAC__StreamMetadata_SeekPoint; +pub use crate::stdlib::FLAC__StreamMetadata_SeekTable; +pub use crate::stdlib::FLAC__StreamMetadata_StreamInfo; +pub use crate::stdlib::FLAC__StreamMetadata_Unknown; +pub use crate::stdlib::FLAC__StreamMetadata_VorbisComment; +pub use crate::stdlib::FLAC__StreamMetadata_VorbisComment_Entry; +pub use crate::stdlib::FLAC__Subframe; +pub use crate::stdlib::FLAC__SubframeType; +pub use crate::stdlib::FLAC__Subframe_Constant; +pub use crate::stdlib::FLAC__Subframe_Fixed; +pub use crate::stdlib::FLAC__Subframe_LPC; +pub use crate::stdlib::FLAC__Subframe_Verbatim; +pub use crate::stdlib::FLAC__bool; +pub use crate::stdlib::FLAC__byte; +pub use crate::stdlib::FLAC__int32; +pub use crate::stdlib::FLAC__uint16; +pub use crate::stdlib::FLAC__uint32; +pub use crate::stdlib::FLAC__uint64; +pub use crate::stdlib::FLAC__uint8; +pub use crate::stdlib::FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; +pub use crate::stdlib::FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE; +pub use crate::stdlib::FLAC__CHANNEL_ASSIGNMENT_MID_SIDE; +pub use crate::stdlib::FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE; +pub use crate::stdlib::FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE; +pub use crate::stdlib::FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2; +pub use crate::stdlib::FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER; +pub use crate::stdlib::FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER; +pub use crate::stdlib::FLAC__MAX_METADATA_TYPE; +pub use crate::stdlib::FLAC__METADATA_TYPE_APPLICATION; +pub use crate::stdlib::FLAC__METADATA_TYPE_CUESHEET; +pub use crate::stdlib::FLAC__METADATA_TYPE_PADDING; +pub use crate::stdlib::FLAC__METADATA_TYPE_PICTURE; +pub use crate::stdlib::FLAC__METADATA_TYPE_SEEKTABLE; +pub use crate::stdlib::FLAC__METADATA_TYPE_STREAMINFO; +pub use crate::stdlib::FLAC__METADATA_TYPE_UNDEFINED; +pub use crate::stdlib::FLAC__METADATA_TYPE_VORBIS_COMMENT; +pub use crate::stdlib::FLAC__STREAM_DECODER_ABORTED; +pub use crate::stdlib::FLAC__STREAM_DECODER_END_OF_STREAM; +pub use crate::stdlib::FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER; +pub use crate::stdlib::FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH; +pub use crate::stdlib::FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC; +pub use crate::stdlib::FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM; +pub use crate::stdlib::FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED; +pub use crate::stdlib::FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE; +pub use crate::stdlib::FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS; +pub use crate::stdlib::FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR; +pub use crate::stdlib::FLAC__STREAM_DECODER_INIT_STATUS_OK; +pub use crate::stdlib::FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER; +pub use crate::stdlib::FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR; +pub use crate::stdlib::FLAC__STREAM_DECODER_LENGTH_STATUS_OK; +pub use crate::stdlib::FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED; +pub use crate::stdlib::FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; +pub use crate::stdlib::FLAC__STREAM_DECODER_OGG_ERROR; +pub use crate::stdlib::FLAC__STREAM_DECODER_READ_FRAME; +pub use crate::stdlib::FLAC__STREAM_DECODER_READ_METADATA; +pub use crate::stdlib::FLAC__STREAM_DECODER_READ_STATUS_ABORT; +pub use crate::stdlib::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; +pub use crate::stdlib::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; +pub use crate::stdlib::FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; +pub use crate::stdlib::FLAC__STREAM_DECODER_SEARCH_FOR_METADATA; +pub use crate::stdlib::FLAC__STREAM_DECODER_SEEK_ERROR; +pub use crate::stdlib::FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; +pub use crate::stdlib::FLAC__STREAM_DECODER_SEEK_STATUS_OK; +pub use crate::stdlib::FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED; +pub use crate::stdlib::FLAC__STREAM_DECODER_TELL_STATUS_ERROR; +pub use crate::stdlib::FLAC__STREAM_DECODER_TELL_STATUS_OK; +pub use crate::stdlib::FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED; +pub use crate::stdlib::FLAC__STREAM_DECODER_UNINITIALIZED; +pub use crate::stdlib::FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; +pub use crate::stdlib::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_BAND; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_FISH; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED; +pub use crate::stdlib::FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE; +pub use crate::stdlib::FLAC__SUBFRAME_TYPE_CONSTANT; +pub use crate::stdlib::FLAC__SUBFRAME_TYPE_FIXED; +pub use crate::stdlib::FLAC__SUBFRAME_TYPE_LPC; +pub use crate::stdlib::FLAC__SUBFRAME_TYPE_VERBATIM; + +use crate::stdlib::dlerror; +use crate::stdlib::dlopen; +use crate::stdlib::dlsym; +use crate::stdlib::pthread_mutex_lock; +use crate::stdlib::pthread_mutex_unlock; +extern "C" { + #[no_mangle] + pub static mut loglevel: crate::squeezelite_h::log_level; + #[no_mangle] + pub static mut streambuf: *mut crate::squeezelite_h::buffer; + #[no_mangle] + pub static mut outputbuf: *mut crate::squeezelite_h::buffer; + #[no_mangle] + pub static mut stream: crate::squeezelite_h::streamstate; + #[no_mangle] + pub static mut output: crate::squeezelite_h::outputstate; + #[no_mangle] + pub static mut decode: crate::squeezelite_h::decodestate; +} +/* + * Squeezelite - lightweight headless squeezeplay emulator for linux + * + * (c) Adrian Smith 2012, triode1@btinternet.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct flac { + pub decoder: *mut crate::stdlib::FLAC__StreamDecoder, + pub FLAC__StreamDecoderErrorStatusString: *mut *const libc::c_char, + pub FLAC__StreamDecoderStateString: *mut *const libc::c_char, + pub FLAC__stream_decoder_new: + Option *mut crate::stdlib::FLAC__StreamDecoder>, + pub FLAC__stream_decoder_reset: Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::FLAC__StreamDecoder, + ) -> crate::stdlib::FLAC__bool, + >, + pub FLAC__stream_decoder_delete: + Option ()>, + pub FLAC__stream_decoder_init_stream: Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::FLAC__StreamDecoder, + _: crate::stdlib::FLAC__StreamDecoderReadCallback, + _: crate::stdlib::FLAC__StreamDecoderSeekCallback, + _: crate::stdlib::FLAC__StreamDecoderTellCallback, + _: crate::stdlib::FLAC__StreamDecoderLengthCallback, + _: crate::stdlib::FLAC__StreamDecoderEofCallback, + _: crate::stdlib::FLAC__StreamDecoderWriteCallback, + _: crate::stdlib::FLAC__StreamDecoderMetadataCallback, + _: crate::stdlib::FLAC__StreamDecoderErrorCallback, + _: *mut libc::c_void, + ) -> crate::stdlib::FLAC__StreamDecoderInitStatus, + >, + pub FLAC__stream_decoder_init_ogg_stream: Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::FLAC__StreamDecoder, + _: crate::stdlib::FLAC__StreamDecoderReadCallback, + _: crate::stdlib::FLAC__StreamDecoderSeekCallback, + _: crate::stdlib::FLAC__StreamDecoderTellCallback, + _: crate::stdlib::FLAC__StreamDecoderLengthCallback, + _: crate::stdlib::FLAC__StreamDecoderEofCallback, + _: crate::stdlib::FLAC__StreamDecoderWriteCallback, + _: crate::stdlib::FLAC__StreamDecoderMetadataCallback, + _: crate::stdlib::FLAC__StreamDecoderErrorCallback, + _: *mut libc::c_void, + ) -> crate::stdlib::FLAC__StreamDecoderInitStatus, + >, + pub FLAC__stream_decoder_process_single: Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::FLAC__StreamDecoder, + ) -> crate::stdlib::FLAC__bool, + >, + pub FLAC__stream_decoder_get_state: Option< + unsafe extern "C" fn( + _: *const crate::stdlib::FLAC__StreamDecoder, + ) -> crate::stdlib::FLAC__StreamDecoderState, + >, +} + +static mut f: *mut flac = 0 as *const flac as *mut flac; + +unsafe extern "C" fn read_cb( + mut decoder: *const crate::stdlib::FLAC__StreamDecoder, + mut buffer: *mut crate::stdlib::FLAC__byte, + mut want: *mut crate::stddef_h::size_t, + mut client_data: *mut libc::c_void, +) -> crate::stdlib::FLAC__StreamDecoderReadStatus { + let mut bytes: crate::stddef_h::size_t = 0; + let mut end: bool = false; + crate::stdlib::pthread_mutex_lock(&mut (*streambuf).mutex); + bytes = if crate::squeezelite_h::_buf_used(streambuf) + < crate::src::buffer::_buf_cont_read(streambuf) + { + crate::squeezelite_h::_buf_used(streambuf) + } else { + crate::src::buffer::_buf_cont_read(streambuf) + } as crate::stddef_h::size_t; + bytes = if bytes < *want { bytes } else { *want }; + end = stream.state as libc::c_uint + <= crate::squeezelite_h::DISCONNECT as libc::c_int as libc::c_uint + && bytes == 0 as libc::c_int as libc::c_ulong; + crate::stdlib::memcpy( + buffer as *mut libc::c_void, + (*streambuf).readp as *const libc::c_void, + bytes, + ); + crate::src::buffer::_buf_inc_readp(streambuf, bytes as libc::c_uint); + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + *want = bytes; + return if end as libc::c_int != 0 { + crate::stdlib::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM as libc::c_int + } else { + crate::stdlib::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE as libc::c_int + } as crate::stdlib::FLAC__StreamDecoderReadStatus; +} + +unsafe extern "C" fn write_cb( + mut decoder: *const crate::stdlib::FLAC__StreamDecoder, + mut frame: *const crate::stdlib::FLAC__Frame, + mut buffer: *const *const crate::stdlib::FLAC__int32, + mut client_data: *mut libc::c_void, +) -> crate::stdlib::FLAC__StreamDecoderWriteStatus { + let mut frames = (*frame).header.blocksize as crate::stddef_h::size_t; + let mut bits_per_sample = (*frame).header.bits_per_sample; + let mut channels = (*frame).header.channels; + let mut lptr = *buffer.offset(0 as libc::c_int as isize) as *mut crate::stdlib::FLAC__int32; + let mut rptr = *buffer.offset(if channels > 1 as libc::c_int as libc::c_uint { + 1 as libc::c_int + } else { + 0 as libc::c_int + } as isize) as *mut crate::stdlib::FLAC__int32; + if decode.new_stream { + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d setting track_start\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"write_cb\x00")).as_ptr(), + 128 as libc::c_int, + ); + } + output.track_start = (*outputbuf).writep; + decode.new_stream = 0 as libc::c_int != 0; + output.next_sample_rate = crate::src::decode::decode_newstream( + (*frame).header.sample_rate, + output.supported_rates.as_mut_ptr(), + ); + if output.fade_mode as u64 != 0 { + crate::src::output::_checkfade(1 as libc::c_int != 0); + } + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + } + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + while frames > 0 as libc::c_int as libc::c_ulong { + let mut f_0: crate::squeezelite_h::frames_t = 0; + let mut count: crate::squeezelite_h::frames_t = 0; + let mut optr = 0 as *mut crate::squeezelite_h::s32_t; + optr = (*outputbuf).writep as *mut crate::squeezelite_h::s32_t; + f_0 = (if crate::src::buffer::_buf_space(outputbuf) + < crate::src::buffer::_buf_cont_write(outputbuf) + { + crate::src::buffer::_buf_space(outputbuf) + } else { + crate::src::buffer::_buf_cont_write(outputbuf) + }) + .wrapping_div(8 as libc::c_int as libc::c_uint); + f_0 = if (f_0 as libc::c_ulong) < frames { + f_0 as libc::c_ulong + } else { + frames + } as crate::squeezelite_h::frames_t; + count = f_0; + if bits_per_sample == 8 as libc::c_int as libc::c_uint { + loop { + let fresh0 = count; + count = count.wrapping_sub(1); + if !(fresh0 != 0) { + break; + } + let fresh1 = lptr; + lptr = lptr.offset(1); + let fresh2 = optr; + optr = optr.offset(1); + *fresh2 = *fresh1 << 24 as libc::c_int; + let fresh3 = rptr; + rptr = rptr.offset(1); + let fresh4 = optr; + optr = optr.offset(1); + *fresh4 = *fresh3 << 24 as libc::c_int + } + } else if bits_per_sample == 16 as libc::c_int as libc::c_uint { + loop { + let fresh5 = count; + count = count.wrapping_sub(1); + if !(fresh5 != 0) { + break; + } + let fresh6 = lptr; + lptr = lptr.offset(1); + let fresh7 = optr; + optr = optr.offset(1); + *fresh7 = *fresh6 << 16 as libc::c_int; + let fresh8 = rptr; + rptr = rptr.offset(1); + let fresh9 = optr; + optr = optr.offset(1); + *fresh9 = *fresh8 << 16 as libc::c_int + } + } else if bits_per_sample == 24 as libc::c_int as libc::c_uint { + loop { + let fresh10 = count; + count = count.wrapping_sub(1); + if !(fresh10 != 0) { + break; + } + let fresh11 = lptr; + lptr = lptr.offset(1); + let fresh12 = optr; + optr = optr.offset(1); + *fresh12 = *fresh11 << 8 as libc::c_int; + let fresh13 = rptr; + rptr = rptr.offset(1); + let fresh14 = optr; + optr = optr.offset(1); + *fresh14 = *fresh13 << 8 as libc::c_int + } + } else if bits_per_sample == 32 as libc::c_int as libc::c_uint { + loop { + let fresh15 = count; + count = count.wrapping_sub(1); + if !(fresh15 != 0) { + break; + } + let fresh16 = lptr; + lptr = lptr.offset(1); + let fresh17 = optr; + optr = optr.offset(1); + *fresh17 = *fresh16; + let fresh18 = rptr; + rptr = rptr.offset(1); + let fresh19 = optr; + optr = optr.offset(1); + *fresh19 = *fresh18 + } + } else { + crate::src::utils::logprint( + b"%s %s:%d unsupported bits per sample: %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"write_cb\x00")).as_ptr(), + 200 as libc::c_int, + bits_per_sample, + ); + } + frames = (frames as libc::c_ulong).wrapping_sub(f_0 as libc::c_ulong) + as crate::stddef_h::size_t as crate::stddef_h::size_t; + crate::src::buffer::_buf_inc_writep( + outputbuf, + f_0.wrapping_mul(8 as libc::c_int as libc::c_uint), + ); + } + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + return crate::stdlib::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; +} + +unsafe extern "C" fn error_cb( + mut decoder: *const crate::stdlib::FLAC__StreamDecoder, + mut status: crate::stdlib::FLAC__StreamDecoderErrorStatus, + mut client_data: *mut libc::c_void, +) { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d flac error: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"error_cb\x00")).as_ptr(), + 220 as libc::c_int, + *(*f) + .FLAC__StreamDecoderErrorStatusString + .offset(status as isize), + ); + }; +} + +unsafe extern "C" fn flac_open( + mut sample_size: crate::squeezelite_h::u8_t, + mut sample_rate: crate::squeezelite_h::u8_t, + mut channels: crate::squeezelite_h::u8_t, + mut endianness: crate::squeezelite_h::u8_t, +) { + if !(*f).decoder.is_null() { + (*f).FLAC__stream_decoder_reset + .expect("non-null function pointer")((*f).decoder); + } else { + (*f).decoder = (*f) + .FLAC__stream_decoder_new + .expect("non-null function pointer")() + } + if sample_size as libc::c_int == 'o' as i32 { + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d ogg/flac container - using init_ogg_stream\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"flac_open\x00")) + .as_ptr(), + 231 as libc::c_int, + ); + } + (*f).FLAC__stream_decoder_init_ogg_stream + .expect("non-null function pointer")( + (*f).decoder, + Some( + read_cb + as unsafe extern "C" fn( + _: *const crate::stdlib::FLAC__StreamDecoder, + _: *mut crate::stdlib::FLAC__byte, + _: *mut crate::stddef_h::size_t, + _: *mut libc::c_void, + ) + -> crate::stdlib::FLAC__StreamDecoderReadStatus, + ), + None, + None, + None, + None, + Some( + write_cb + as unsafe extern "C" fn( + _: *const crate::stdlib::FLAC__StreamDecoder, + _: *const crate::stdlib::FLAC__Frame, + _: *const *const crate::stdlib::FLAC__int32, + _: *mut libc::c_void, + ) + -> crate::stdlib::FLAC__StreamDecoderWriteStatus, + ), + None, + Some( + error_cb + as unsafe extern "C" fn( + _: *const crate::stdlib::FLAC__StreamDecoder, + _: crate::stdlib::FLAC__StreamDecoderErrorStatus, + _: *mut libc::c_void, + ) -> (), + ), + 0 as *mut libc::c_void, + ); + } else { + (*f).FLAC__stream_decoder_init_stream + .expect("non-null function pointer")( + (*f).decoder, + Some( + read_cb + as unsafe extern "C" fn( + _: *const crate::stdlib::FLAC__StreamDecoder, + _: *mut crate::stdlib::FLAC__byte, + _: *mut crate::stddef_h::size_t, + _: *mut libc::c_void, + ) + -> crate::stdlib::FLAC__StreamDecoderReadStatus, + ), + None, + None, + None, + None, + Some( + write_cb + as unsafe extern "C" fn( + _: *const crate::stdlib::FLAC__StreamDecoder, + _: *const crate::stdlib::FLAC__Frame, + _: *const *const crate::stdlib::FLAC__int32, + _: *mut libc::c_void, + ) + -> crate::stdlib::FLAC__StreamDecoderWriteStatus, + ), + None, + Some( + error_cb + as unsafe extern "C" fn( + _: *const crate::stdlib::FLAC__StreamDecoder, + _: crate::stdlib::FLAC__StreamDecoderErrorStatus, + _: *mut libc::c_void, + ) -> (), + ), + 0 as *mut libc::c_void, + ); + }; +} + +unsafe extern "C" fn flac_close() { + (*f).FLAC__stream_decoder_delete + .expect("non-null function pointer")((*f).decoder); + (*f).decoder = 0 as *mut crate::stdlib::FLAC__StreamDecoder; +} + +unsafe extern "C" fn flac_decode() -> crate::squeezelite_h::decode_state { + let mut ok = (*f) + .FLAC__stream_decoder_process_single + .expect("non-null function pointer")((*f).decoder) + != 0; + let mut state = (*f) + .FLAC__stream_decoder_get_state + .expect("non-null function pointer")((*f).decoder); + if !ok + && state as libc::c_uint + != crate::stdlib::FLAC__STREAM_DECODER_END_OF_STREAM as libc::c_int as libc::c_uint + { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d flac error: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"flac_decode\x00")) + .as_ptr(), + 249 as libc::c_int, + *(*f).FLAC__StreamDecoderStateString.offset(state as isize), + ); + } + } + if state as libc::c_uint + == crate::stdlib::FLAC__STREAM_DECODER_END_OF_STREAM as libc::c_int as libc::c_uint + { + return crate::squeezelite_h::DECODE_COMPLETE; + } else if state as libc::c_uint + > crate::stdlib::FLAC__STREAM_DECODER_END_OF_STREAM as libc::c_int as libc::c_uint + { + return crate::squeezelite_h::DECODE_ERROR; + } else { + return crate::squeezelite_h::DECODE_RUNNING; + }; +} + +unsafe extern "C" fn load_flac() -> bool { + let mut handle = crate::stdlib::dlopen( + b"libFLAC.so.8\x00" as *const u8 as *const libc::c_char, + 0x2 as libc::c_int, + ); + let mut err = 0 as *mut libc::c_char; + if handle.is_null() { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d dlerror: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"load_flac\x00")) + .as_ptr(), + 267 as libc::c_int, + crate::stdlib::dlerror(), + ); + } + return 0 as libc::c_int != 0; + } + (*f).FLAC__StreamDecoderErrorStatusString = crate::stdlib::dlsym( + handle, + b"FLAC__StreamDecoderErrorStatusString\x00" as *const u8 as *const libc::c_char, + ) as *mut *const libc::c_char; + (*f).FLAC__StreamDecoderStateString = crate::stdlib::dlsym( + handle, + b"FLAC__StreamDecoderStateString\x00" as *const u8 as *const libc::c_char, + ) as *mut *const libc::c_char; + (*f).FLAC__stream_decoder_new = ::std::mem::transmute::< + *mut libc::c_void, + Option *mut crate::stdlib::FLAC__StreamDecoder>, + >(crate::stdlib::dlsym( + handle, + b"FLAC__stream_decoder_new\x00" as *const u8 as *const libc::c_char, + )); + (*f).FLAC__stream_decoder_reset = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::FLAC__StreamDecoder, + ) -> crate::stdlib::FLAC__bool, + >, + >(crate::stdlib::dlsym( + handle, + b"FLAC__stream_decoder_reset\x00" as *const u8 as *const libc::c_char, + )); + (*f).FLAC__stream_decoder_delete = ::std::mem::transmute::< + *mut libc::c_void, + Option ()>, + >(crate::stdlib::dlsym( + handle, + b"FLAC__stream_decoder_delete\x00" as *const u8 as *const libc::c_char, + )); + (*f).FLAC__stream_decoder_init_stream = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::FLAC__StreamDecoder, + _: crate::stdlib::FLAC__StreamDecoderReadCallback, + _: crate::stdlib::FLAC__StreamDecoderSeekCallback, + _: crate::stdlib::FLAC__StreamDecoderTellCallback, + _: crate::stdlib::FLAC__StreamDecoderLengthCallback, + _: crate::stdlib::FLAC__StreamDecoderEofCallback, + _: crate::stdlib::FLAC__StreamDecoderWriteCallback, + _: crate::stdlib::FLAC__StreamDecoderMetadataCallback, + _: crate::stdlib::FLAC__StreamDecoderErrorCallback, + _: *mut libc::c_void, + ) -> crate::stdlib::FLAC__StreamDecoderInitStatus, + >, + >(crate::stdlib::dlsym( + handle, + b"FLAC__stream_decoder_init_stream\x00" as *const u8 as *const libc::c_char, + )); + (*f).FLAC__stream_decoder_init_ogg_stream = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::FLAC__StreamDecoder, + _: crate::stdlib::FLAC__StreamDecoderReadCallback, + _: crate::stdlib::FLAC__StreamDecoderSeekCallback, + _: crate::stdlib::FLAC__StreamDecoderTellCallback, + _: crate::stdlib::FLAC__StreamDecoderLengthCallback, + _: crate::stdlib::FLAC__StreamDecoderEofCallback, + _: crate::stdlib::FLAC__StreamDecoderWriteCallback, + _: crate::stdlib::FLAC__StreamDecoderMetadataCallback, + _: crate::stdlib::FLAC__StreamDecoderErrorCallback, + _: *mut libc::c_void, + ) -> crate::stdlib::FLAC__StreamDecoderInitStatus, + >, + >(crate::stdlib::dlsym( + handle, + b"FLAC__stream_decoder_init_ogg_stream\x00" as *const u8 as *const libc::c_char, + )); + (*f).FLAC__stream_decoder_process_single = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::FLAC__StreamDecoder, + ) -> crate::stdlib::FLAC__bool, + >, + >(crate::stdlib::dlsym( + handle, + b"FLAC__stream_decoder_process_single\x00" as *const u8 as *const libc::c_char, + )); + (*f).FLAC__stream_decoder_get_state = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: *const crate::stdlib::FLAC__StreamDecoder, + ) -> crate::stdlib::FLAC__StreamDecoderState, + >, + >(crate::stdlib::dlsym( + handle, + b"FLAC__stream_decoder_get_state\x00" as *const u8 as *const libc::c_char, + )); + err = crate::stdlib::dlerror(); + if !err.is_null() { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d dlerror: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"load_flac\x00")) + .as_ptr(), + 282 as libc::c_int, + err, + ); + } + return 0 as libc::c_int != 0; + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d loaded libFLAC.so.8\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"load_flac\x00")).as_ptr(), + 286 as libc::c_int, + ); + } + return 1 as libc::c_int != 0; +} +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Additions (c) Paul Hermann, 2015-2017 under the same license terms + * -Control of Raspberry pi GPIO for amplifier power + * -Launch script on power status change from LMS + */ +// make may define: PORTAUDIO, SELFPIPE, RESAMPLE, RESAMPLE_MP, VISEXPORT, GPIO, IR, DSD, LINKALL to influence build +// build detection +// dynamically loaded libraries at run time +// !LINKALL +// config options +// do not reduce as icy-meta max is 4080 +/* SUN */ +/* SUN */ +// printf/scanf formats for u64_t +// logging +// utils.c (non logging) +// buffer.c +// _* called with mutex locked +// slimproto.c +// stream.c +// decode.c +// output.c output_alsa.c output_pa.c output_pack.c +// frames played at the point delay is measured +// ordered largest first so [0] is max_rate +// set in decode thread +// set in decode thread +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// _* called with mutex locked +// output_alsa.c +// output_pa.c +// output_pulse.c +// output_stdout.c +// output_pack.c +// output_vis.c +// dop.c +// codecs +#[no_mangle] + +pub unsafe extern "C" fn register_flac() -> *mut crate::squeezelite_h::codec { + static mut ret: crate::squeezelite_h::codec = unsafe { + { + let mut init = crate::squeezelite_h::codec { + id: 'f' as i32 as libc::c_char, + types: b"ogf,flc\x00" as *const u8 as *const libc::c_char as *mut libc::c_char, + min_read_bytes: 16384 as libc::c_int as libc::c_uint, + min_space: 204800 as libc::c_int as libc::c_uint, + open: Some( + flac_open + as unsafe extern "C" fn( + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + ) -> (), + ), + close: Some(flac_close as unsafe extern "C" fn() -> ()), + decode: Some( + flac_decode as unsafe extern "C" fn() -> crate::squeezelite_h::decode_state, + ), + }; + init + } + }; + f = crate::stdlib::malloc(::std::mem::size_of::() as libc::c_ulong) as *mut flac; + if f.is_null() { + return 0 as *mut crate::squeezelite_h::codec; + } + (*f).decoder = 0 as *mut crate::stdlib::FLAC__StreamDecoder; + if !load_flac() { + return 0 as *mut crate::squeezelite_h::codec; + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d using flac to decode ogf,flc\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>(b"register_flac\x00")) + .as_ptr(), + 314 as libc::c_int, + ); + } + return &mut ret; +} diff --git a/src/internal.rs b/src/internal.rs new file mode 100644 index 0000000..bfe0b43 --- /dev/null +++ b/src/internal.rs @@ -0,0 +1,9 @@ +pub type __builtin_va_list = [crate::internal::__va_list_tag; 1]; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct __va_list_tag { + pub gp_offset: libc::c_uint, + pub fp_offset: libc::c_uint, + pub overflow_arg_area: *mut libc::c_void, + pub reg_save_area: *mut libc::c_void, +} diff --git a/src/mad.rs b/src/mad.rs new file mode 100644 index 0000000..1ec1a51 --- /dev/null +++ b/src/mad.rs @@ -0,0 +1,989 @@ +use ::libc; + +pub use crate::stddef_h::size_t; +pub use crate::stdlib::__int32_t; +pub use crate::stdlib::__uint32_t; +pub use crate::stdlib::__uint64_t; +pub use crate::stdlib::__uint8_t; +pub use crate::stdlib::int32_t; + +pub use crate::stdlib::__pthread_internal_list; +pub use crate::stdlib::__pthread_list_t; +pub use crate::stdlib::__pthread_mutex_s; +pub use crate::stdlib::pthread_mutex_t; +pub use crate::stdlib::u_int32_t; +pub use crate::stdlib::u_int64_t; +pub use crate::stdlib::u_int8_t; + +pub use crate::squeezelite_h::buffer; +pub use crate::squeezelite_h::codec; +pub use crate::squeezelite_h::decode_state; +pub use crate::squeezelite_h::decodestate; +pub use crate::squeezelite_h::disconnect_code; +pub use crate::squeezelite_h::fade_dir; +pub use crate::squeezelite_h::fade_mode; +pub use crate::squeezelite_h::fade_state; +pub use crate::squeezelite_h::frames_t; +pub use crate::squeezelite_h::lDEBUG; +pub use crate::squeezelite_h::lERROR; +pub use crate::squeezelite_h::lINFO; +pub use crate::squeezelite_h::lSDEBUG; +pub use crate::squeezelite_h::lWARN; +pub use crate::squeezelite_h::log_level; +pub use crate::squeezelite_h::output_format; +pub use crate::squeezelite_h::output_state; +pub use crate::squeezelite_h::outputstate; +pub use crate::squeezelite_h::s32_t; +pub use crate::squeezelite_h::stream_state; +pub use crate::squeezelite_h::streamstate; +pub use crate::squeezelite_h::u32_t; +pub use crate::squeezelite_h::u64_t; +pub use crate::squeezelite_h::u8_t; +pub use crate::squeezelite_h::C2RustUnnamed_1; +pub use crate::squeezelite_h::_buf_used; +pub use crate::squeezelite_h::DECODE_COMPLETE; +pub use crate::squeezelite_h::DECODE_ERROR; +pub use crate::squeezelite_h::DECODE_READY; +pub use crate::squeezelite_h::DECODE_RUNNING; +pub use crate::squeezelite_h::DECODE_STOPPED; +pub use crate::squeezelite_h::DISCONNECT; +pub use crate::squeezelite_h::DISCONNECT_OK; +pub use crate::squeezelite_h::FADE_ACTIVE; +pub use crate::squeezelite_h::FADE_CROSS; +pub use crate::squeezelite_h::FADE_CROSSFADE; +pub use crate::squeezelite_h::FADE_DOWN; +pub use crate::squeezelite_h::FADE_DUE; +pub use crate::squeezelite_h::FADE_IN; +pub use crate::squeezelite_h::FADE_INACTIVE; +pub use crate::squeezelite_h::FADE_INOUT; +pub use crate::squeezelite_h::FADE_NONE; +pub use crate::squeezelite_h::FADE_OUT; +pub use crate::squeezelite_h::FADE_UP; +pub use crate::squeezelite_h::LOCAL_DISCONNECT; +pub use crate::squeezelite_h::OUTPUT_BUFFER; +pub use crate::squeezelite_h::OUTPUT_OFF; +pub use crate::squeezelite_h::OUTPUT_PAUSE_FRAMES; +pub use crate::squeezelite_h::OUTPUT_RUNNING; +pub use crate::squeezelite_h::OUTPUT_SKIP_FRAMES; +pub use crate::squeezelite_h::OUTPUT_START_AT; +pub use crate::squeezelite_h::OUTPUT_STOPPED; +pub use crate::squeezelite_h::RECV_HEADERS; +pub use crate::squeezelite_h::REMOTE_DISCONNECT; +pub use crate::squeezelite_h::S16_LE; +pub use crate::squeezelite_h::S24_3LE; +pub use crate::squeezelite_h::S24_LE; +pub use crate::squeezelite_h::S32_LE; +pub use crate::squeezelite_h::SEND_HEADERS; +pub use crate::squeezelite_h::STOPPED; +pub use crate::squeezelite_h::STREAMING_BUFFERING; +pub use crate::squeezelite_h::STREAMING_FILE; +pub use crate::squeezelite_h::STREAMING_HTTP; +pub use crate::squeezelite_h::STREAMING_WAIT; +pub use crate::squeezelite_h::TIMEOUT; +pub use crate::squeezelite_h::UNREACHABLE; +pub use crate::src::buffer::_buf_cont_read; +pub use crate::src::buffer::_buf_cont_write; +pub use crate::src::buffer::_buf_inc_readp; +pub use crate::src::buffer::_buf_inc_writep; +pub use crate::src::buffer::_buf_space; +pub use crate::src::decode::decode_newstream; +pub use crate::src::output::_checkfade; +pub use crate::src::utils::logprint; +pub use crate::src::utils::logtime; +pub use crate::src::utils::unpackN; +use crate::stdlib::dlerror; +use crate::stdlib::dlopen; +use crate::stdlib::dlsym; +use crate::stdlib::free; +pub use crate::stdlib::mad_bitptr; +pub use crate::stdlib::mad_emphasis; +pub use crate::stdlib::mad_error; +pub use crate::stdlib::mad_fixed_t; +pub use crate::stdlib::mad_frame; +pub use crate::stdlib::mad_header; +pub use crate::stdlib::mad_layer; +pub use crate::stdlib::mad_mode; +pub use crate::stdlib::mad_pcm; +pub use crate::stdlib::mad_stream; +pub use crate::stdlib::mad_synth; +pub use crate::stdlib::mad_timer_t; +use crate::stdlib::malloc; +use crate::stdlib::memcmp; +use crate::stdlib::memcpy; +use crate::stdlib::memmove; +use crate::stdlib::memset; +use crate::stdlib::pthread_mutex_lock; +use crate::stdlib::pthread_mutex_unlock; +pub use crate::stdlib::MAD_EMPHASIS_50_15_US; +pub use crate::stdlib::MAD_EMPHASIS_CCITT_J_17; +pub use crate::stdlib::MAD_EMPHASIS_NONE; +pub use crate::stdlib::MAD_EMPHASIS_RESERVED; +pub use crate::stdlib::MAD_ERROR_BADBIGVALUES; +pub use crate::stdlib::MAD_ERROR_BADBITALLOC; +pub use crate::stdlib::MAD_ERROR_BADBITRATE; +pub use crate::stdlib::MAD_ERROR_BADBLOCKTYPE; +pub use crate::stdlib::MAD_ERROR_BADCRC; +pub use crate::stdlib::MAD_ERROR_BADDATAPTR; +pub use crate::stdlib::MAD_ERROR_BADEMPHASIS; +pub use crate::stdlib::MAD_ERROR_BADFRAMELEN; +pub use crate::stdlib::MAD_ERROR_BADHUFFDATA; +pub use crate::stdlib::MAD_ERROR_BADHUFFTABLE; +pub use crate::stdlib::MAD_ERROR_BADLAYER; +pub use crate::stdlib::MAD_ERROR_BADMODE; +pub use crate::stdlib::MAD_ERROR_BADPART3LEN; +pub use crate::stdlib::MAD_ERROR_BADSAMPLERATE; +pub use crate::stdlib::MAD_ERROR_BADSCALEFACTOR; +pub use crate::stdlib::MAD_ERROR_BADSCFSI; +pub use crate::stdlib::MAD_ERROR_BADSTEREO; +pub use crate::stdlib::MAD_ERROR_BUFLEN; +pub use crate::stdlib::MAD_ERROR_BUFPTR; +pub use crate::stdlib::MAD_ERROR_LOSTSYNC; +pub use crate::stdlib::MAD_ERROR_NOMEM; +pub use crate::stdlib::MAD_ERROR_NONE; +pub use crate::stdlib::MAD_LAYER_I; +pub use crate::stdlib::MAD_LAYER_II; +pub use crate::stdlib::MAD_LAYER_III; +pub use crate::stdlib::MAD_MODE_DUAL_CHANNEL; +pub use crate::stdlib::MAD_MODE_JOINT_STEREO; +pub use crate::stdlib::MAD_MODE_SINGLE_CHANNEL; +pub use crate::stdlib::MAD_MODE_STEREO; +extern "C" { + #[no_mangle] + pub static mut loglevel: crate::squeezelite_h::log_level; + #[no_mangle] + pub static mut streambuf: *mut crate::squeezelite_h::buffer; + #[no_mangle] + pub static mut outputbuf: *mut crate::squeezelite_h::buffer; + #[no_mangle] + pub static mut stream: crate::squeezelite_h::streamstate; + #[no_mangle] + pub static mut output: crate::squeezelite_h::outputstate; + #[no_mangle] + pub static mut decode: crate::squeezelite_h::decodestate; +} +// local buffer used by decoder: FIXME merge with any other decoders needing one? + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct mad { + pub readbuf: *mut crate::squeezelite_h::u8_t, + pub readbuf_len: libc::c_uint, + pub stream: crate::stdlib::mad_stream, + pub frame: crate::stdlib::mad_frame, + pub synth: crate::stdlib::mad_synth, + pub last_error: crate::stdlib::mad_error, + pub checktags: libc::c_int, + pub consume: crate::squeezelite_h::u32_t, + pub skip: crate::squeezelite_h::u32_t, + pub samples: crate::squeezelite_h::u64_t, + pub padding: crate::squeezelite_h::u32_t, + pub mad_stream_init: Option ()>, + pub mad_frame_init: Option ()>, + pub mad_synth_init: Option ()>, + pub mad_frame_finish: Option ()>, + pub mad_stream_finish: Option ()>, + pub mad_stream_buffer: Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::mad_stream, + _: *const libc::c_uchar, + _: libc::c_ulong, + ) -> (), + >, + pub mad_frame_decode: Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::mad_frame, + _: *mut crate::stdlib::mad_stream, + ) -> libc::c_int, + >, + pub mad_synth_frame: Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::mad_synth, + _: *const crate::stdlib::mad_frame, + ) -> (), + >, + pub mad_stream_errorstr: + Option *const libc::c_char>, +} + +static mut m: *mut mad = 0 as *const mad as *mut mad; +// based on libmad minimad.c scale +#[inline] + +unsafe extern "C" fn scale(mut sample: crate::stdlib::mad_fixed_t) -> crate::squeezelite_h::u32_t { + sample = (sample as libc::c_long + + ((1 as libc::c_long) << 28 as libc::c_int - 24 as libc::c_int)) + as crate::stdlib::mad_fixed_t; + if sample >= 0x10000000 as libc::c_long as crate::stdlib::mad_fixed_t { + sample = 0x10000000 as libc::c_long as crate::stdlib::mad_fixed_t - 1 as libc::c_int + } else if sample < -(0x10000000 as libc::c_long as crate::stdlib::mad_fixed_t) { + sample = -(0x10000000 as libc::c_long as crate::stdlib::mad_fixed_t) + } + return ((sample >> 28 as libc::c_int + 1 as libc::c_int - 24 as libc::c_int) + << 8 as libc::c_int) as crate::squeezelite_h::u32_t; +} +// check for id3.2 tag at start of file - http://id3.org/id3v2.4.0-structure, return length + +unsafe extern "C" fn _check_id3_tag(mut bytes: crate::stddef_h::size_t) -> libc::c_uint { + let mut ptr = (*streambuf).readp; + let mut size = 0 as libc::c_int as crate::squeezelite_h::u32_t; + if bytes > 10 as libc::c_int as libc::c_ulong + && *ptr as libc::c_int == 'I' as i32 + && *ptr.offset(1 as libc::c_int as isize) as libc::c_int == 'D' as i32 + && *ptr.offset(2 as libc::c_int as isize) as libc::c_int == '3' as i32 + { + // size is encoded as syncsafe integer, add 10 if footer present + if (*ptr.offset(6 as libc::c_int as isize) as libc::c_int) < 0x80 as libc::c_int + && (*ptr.offset(7 as libc::c_int as isize) as libc::c_int) < 0x80 as libc::c_int + && (*ptr.offset(8 as libc::c_int as isize) as libc::c_int) < 0x80 as libc::c_int + && (*ptr.offset(9 as libc::c_int as isize) as libc::c_int) < 0x80 as libc::c_int + { + size = (10 as libc::c_int + + ((*ptr.offset(6 as libc::c_int as isize) as libc::c_int) << 21 as libc::c_int) + + ((*ptr.offset(7 as libc::c_int as isize) as libc::c_int) << 14 as libc::c_int) + + ((*ptr.offset(8 as libc::c_int as isize) as libc::c_int) << 7 as libc::c_int) + + *ptr.offset(9 as libc::c_int as isize) as libc::c_int + + (if *ptr.offset(5 as libc::c_int as isize) as libc::c_int & 0x10 as libc::c_int + != 0 + { + 10 as libc::c_int + } else { + 0 as libc::c_int + })) as crate::squeezelite_h::u32_t; + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d id3.2 tag len: %u\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>( + b"_check_id3_tag\x00", + )) + .as_ptr(), + 111 as libc::c_int, + size, + ); + } + } + } + return size; +} +// check for lame gapless params, don't advance streambuf + +unsafe extern "C" fn _check_lame_header(mut bytes: crate::stddef_h::size_t) { + let mut ptr = (*streambuf).readp; + if *ptr as libc::c_int == 0xff as libc::c_int + && *ptr.offset(1 as libc::c_int as isize) as libc::c_int & 0xf0 as libc::c_int + == 0xf0 as libc::c_int + && bytes > 180 as libc::c_int as libc::c_ulong + { + let mut frame_count = 0 as libc::c_int as crate::squeezelite_h::u32_t; + let mut enc_delay = 0 as libc::c_int as crate::squeezelite_h::u32_t; + let mut enc_padding = 0 as libc::c_int as crate::squeezelite_h::u32_t; + let mut flags: crate::squeezelite_h::u8_t = 0; + // 2 channels + if crate::stdlib::memcmp( + ptr.offset(36 as libc::c_int as isize) as *const libc::c_void, + b"Xing\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ) == 0 + || crate::stdlib::memcmp( + ptr.offset(36 as libc::c_int as isize) as *const libc::c_void, + b"Info\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ) == 0 + { + ptr = ptr.offset((36 as libc::c_int + 7 as libc::c_int) as isize) + // mono + } else if crate::stdlib::memcmp( + ptr.offset(21 as libc::c_int as isize) as *const libc::c_void, + b"Xing\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ) == 0 + || crate::stdlib::memcmp( + ptr.offset(21 as libc::c_int as isize) as *const libc::c_void, + b"Info\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ) == 0 + { + ptr = ptr.offset((21 as libc::c_int + 7 as libc::c_int) as isize) + } + flags = *ptr; + if flags as libc::c_int & 0x1 as libc::c_int != 0 { + frame_count = crate::src::utils::unpackN( + ptr.offset(1 as libc::c_int as isize) as *mut crate::squeezelite_h::u32_t + ); + ptr = ptr.offset(4 as libc::c_int as isize) + } + if flags as libc::c_int & 0x2 as libc::c_int != 0 { + ptr = ptr.offset(4 as libc::c_int as isize) + } + if flags as libc::c_int & 0x4 as libc::c_int != 0 { + ptr = ptr.offset(100 as libc::c_int as isize) + } + if flags as libc::c_int & 0x8 as libc::c_int != 0 { + ptr = ptr.offset(4 as libc::c_int as isize) + } + if crate::stdlib::memcmp( + ptr.offset(1 as libc::c_int as isize) as *const libc::c_void, + b"LAME\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ) != 0 + { + return; + } + ptr = ptr.offset(22 as libc::c_int as isize); + enc_delay = (((*ptr as libc::c_int) << 4 as libc::c_int + | *ptr.offset(1 as libc::c_int as isize) as libc::c_int >> 4 as libc::c_int) + + 529 as libc::c_int) as crate::squeezelite_h::u32_t; + enc_padding = ((*ptr.offset(1 as libc::c_int as isize) as libc::c_int & 0xf as libc::c_int) + << 8 as libc::c_int + | *ptr.offset(2 as libc::c_int as isize) as libc::c_int) + as crate::squeezelite_h::u32_t; + enc_padding = if enc_padding > 529 as libc::c_int as libc::c_uint { + enc_padding.wrapping_sub(529 as libc::c_int as libc::c_uint) + } else { + 0 as libc::c_int as libc::c_uint + }; + // add one frame to initial skip for this (empty) frame + (*m).skip = enc_delay.wrapping_add(1152 as libc::c_int as libc::c_uint); + (*m).samples = frame_count + .wrapping_mul(1152 as libc::c_int as libc::c_uint) + .wrapping_sub(enc_delay) + .wrapping_sub(enc_padding) as crate::squeezelite_h::u64_t; + (*m).padding = enc_padding; + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d gapless: skip: %u samples: %lu delay: %u padding: %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 19], &[libc::c_char; 19]>( + b"_check_lame_header\x00", + )) + .as_ptr(), + 160 as libc::c_int, + (*m).skip, + (*m).samples, + enc_delay, + enc_padding, + ); + } + }; +} + +unsafe extern "C" fn mad_decode() -> crate::squeezelite_h::decode_state { + let mut bytes: crate::stddef_h::size_t = 0; + let mut eos = 0 as libc::c_int != 0; + crate::stdlib::pthread_mutex_lock(&mut (*streambuf).mutex); + bytes = if crate::squeezelite_h::_buf_used(streambuf) + < crate::src::buffer::_buf_cont_read(streambuf) + { + crate::squeezelite_h::_buf_used(streambuf) + } else { + crate::src::buffer::_buf_cont_read(streambuf) + } as crate::stddef_h::size_t; + if (*m).checktags != 0 { + if (*m).checktags == 1 as libc::c_int { + (*m).consume = _check_id3_tag(bytes); + (*m).checktags = 2 as libc::c_int + } + if (*m).consume != 0 { + let mut consume = if ((*m).consume as libc::c_ulong) < bytes { + (*m).consume as libc::c_ulong + } else { + bytes + } as crate::squeezelite_h::u32_t; + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d consume: %u of %u\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"mad_decode\x00")) + .as_ptr(), + 178 as libc::c_int, + consume, + (*m).consume, + ); + } + crate::src::buffer::_buf_inc_readp(streambuf, consume); + (*m).consume = ((*m).consume as libc::c_uint).wrapping_sub(consume) + as crate::squeezelite_h::u32_t + as crate::squeezelite_h::u32_t; + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + return crate::squeezelite_h::DECODE_RUNNING; + } + if (*m).checktags == 2 as libc::c_int { + if stream.meta_interval == 0 { + _check_lame_header(bytes); + } + (*m).checktags = 0 as libc::c_int + } + } + if !(*m).stream.next_frame.is_null() && (*m).readbuf_len != 0 { + (*m).readbuf_len = ((*m).readbuf_len as libc::c_long + - (*m).stream.next_frame.wrapping_offset_from((*m).readbuf) as libc::c_long) + as libc::c_uint; + crate::stdlib::memmove( + (*m).readbuf as *mut libc::c_void, + (*m).stream.next_frame as *const libc::c_void, + (*m).readbuf_len as libc::c_ulong, + ); + } + bytes = if bytes + < (2048 as libc::c_int as libc::c_uint).wrapping_sub((*m).readbuf_len) as libc::c_ulong + { + bytes + } else { + (2048 as libc::c_int as libc::c_uint).wrapping_sub((*m).readbuf_len) as libc::c_ulong + }; + crate::stdlib::memcpy( + (*m).readbuf.offset((*m).readbuf_len as isize) as *mut libc::c_void, + (*streambuf).readp as *const libc::c_void, + bytes, + ); + (*m).readbuf_len = + ((*m).readbuf_len as libc::c_ulong).wrapping_add(bytes) as libc::c_uint as libc::c_uint; + crate::src::buffer::_buf_inc_readp(streambuf, bytes as libc::c_uint); + if stream.state as libc::c_uint + <= crate::squeezelite_h::DISCONNECT as libc::c_int as libc::c_uint + && crate::squeezelite_h::_buf_used(streambuf) == 0 as libc::c_int as libc::c_uint + { + eos = 1 as libc::c_int != 0; + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d end of stream\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"mad_decode\x00")) + .as_ptr(), + 204 as libc::c_int, + ); + } + crate::stdlib::memset( + (*m).readbuf.offset((*m).readbuf_len as isize) as *mut libc::c_void, + 0 as libc::c_int, + 8 as libc::c_int as libc::c_ulong, + ); + (*m).readbuf_len = (*m) + .readbuf_len + .wrapping_add(8 as libc::c_int as libc::c_uint) + } + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + (*m).mad_stream_buffer.expect("non-null function pointer")( + &mut (*m).stream, + (*m).readbuf, + (*m).readbuf_len as libc::c_ulong, + ); + loop { + let mut frames: crate::stddef_h::size_t = 0; + let mut iptrl = 0 as *mut crate::squeezelite_h::s32_t; + let mut iptrr = 0 as *mut crate::squeezelite_h::s32_t; + let mut max_frames: libc::c_uint = 0; + if (*m).mad_frame_decode.expect("non-null function pointer")( + &mut (*m).frame, + &mut (*m).stream, + ) == -(1 as libc::c_int) + { + let mut ret = crate::squeezelite_h::DECODE_STOPPED; + if !eos + && (*m).stream.error as libc::c_uint + == crate::stdlib::MAD_ERROR_BUFLEN as libc::c_int as libc::c_uint + { + ret = crate::squeezelite_h::DECODE_RUNNING + } else if eos as libc::c_int != 0 + && ((*m).stream.error as libc::c_uint + == crate::stdlib::MAD_ERROR_BUFLEN as libc::c_int as libc::c_uint + || (*m).stream.error as libc::c_uint + == crate::stdlib::MAD_ERROR_LOSTSYNC as libc::c_int as libc::c_uint + || (*m).stream.error as libc::c_uint + == crate::stdlib::MAD_ERROR_BADBITRATE as libc::c_int as libc::c_uint) + { + ret = crate::squeezelite_h::DECODE_COMPLETE + } else if (*m).stream.error as libc::c_uint & 0xff00 as libc::c_int as libc::c_uint == 0 + { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d mad_frame_decode error: %s - stopping decoder\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>( + b"mad_decode\x00", + )) + .as_ptr(), + 227 as libc::c_int, + (*m).mad_stream_errorstr.expect("non-null function pointer")( + &mut (*m).stream, + ), + ); + } + ret = crate::squeezelite_h::DECODE_COMPLETE + } else { + if (*m).stream.error as libc::c_uint != (*m).last_error as libc::c_uint { + // suppress repeat error messages + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d mad_frame_decode error: %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>( + b"mad_decode\x00", + )) + .as_ptr(), + 232 as libc::c_int, + (*m).mad_stream_errorstr.expect("non-null function pointer")( + &mut (*m).stream, + ), + ); + } + } + ret = crate::squeezelite_h::DECODE_RUNNING + } + (*m).last_error = (*m).stream.error; + return ret; + } + (*m).mad_synth_frame.expect("non-null function pointer")(&mut (*m).synth, &mut (*m).frame); + if decode.new_stream { + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d setting track_start\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"mad_decode\x00")) + .as_ptr(), + 244 as libc::c_int, + ); + } + output.next_sample_rate = crate::src::decode::decode_newstream( + (*m).synth.pcm.samplerate, + output.supported_rates.as_mut_ptr(), + ); + output.track_start = (*outputbuf).writep; + if output.fade_mode as u64 != 0 { + crate::src::output::_checkfade(1 as libc::c_int != 0); + } + decode.new_stream = 0 as libc::c_int != 0; + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + } + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + max_frames = crate::src::buffer::_buf_space(outputbuf) + .wrapping_div(8 as libc::c_int as libc::c_uint); + if (*m).synth.pcm.length as libc::c_uint > max_frames { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d too many samples - dropping samples\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"mad_decode\x00")) + .as_ptr(), + 263 as libc::c_int, + ); + } + (*m).synth.pcm.length = max_frames as libc::c_ushort + } + frames = (*m).synth.pcm.length as crate::stddef_h::size_t; + iptrl = (*m).synth.pcm.samples[0 as libc::c_int as usize].as_mut_ptr(); + iptrr = (*m).synth.pcm.samples + [((*m).synth.pcm.channels as libc::c_int - 1 as libc::c_int) as usize] + .as_mut_ptr(); + if (*m).skip != 0 { + let mut skip = if ((*m).skip as libc::c_ulong) < frames { + (*m).skip as libc::c_ulong + } else { + frames + } as crate::squeezelite_h::u32_t; + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d gapless: skipping %u frames at start\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"mad_decode\x00")) + .as_ptr(), + 273 as libc::c_int, + skip, + ); + } + frames = (frames as libc::c_ulong).wrapping_sub(skip as libc::c_ulong) + as crate::stddef_h::size_t as crate::stddef_h::size_t; + (*m).skip = ((*m).skip as libc::c_uint).wrapping_sub(skip) + as crate::squeezelite_h::u32_t + as crate::squeezelite_h::u32_t; + iptrl = iptrl.offset(skip as isize); + iptrr = iptrr.offset(skip as isize) + } + if (*m).samples != 0 { + if (*m).samples < frames { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d gapless: trimming %u frames from end\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>( + b"mad_decode\x00", + )) + .as_ptr(), + 282 as libc::c_int, + frames.wrapping_sub((*m).samples), + ); + } + frames = (*m).samples + } + (*m).samples = ((*m).samples as libc::c_ulong).wrapping_sub(frames) + as crate::squeezelite_h::u64_t + as crate::squeezelite_h::u64_t; + if (*m).samples > 0 as libc::c_int as libc::c_ulong + && eos as libc::c_int != 0 + && !(*(*m).stream.next_frame.offset(0 as libc::c_int as isize) as libc::c_int + == 0xff as libc::c_int + && *(*m).stream.next_frame.offset(1 as libc::c_int as isize) as libc::c_int + & 0xf0 as libc::c_int + == 0xf0 as libc::c_int) + { + // this is the last frame to be decoded, but more samples expected so we must have skipped, remove padding + // note this only works if the padding is less than one frame of 1152 bytes otherswise some gap will remain + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d gapless: early end - trimming padding from end\n\x00" + as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>( + b"mad_decode\x00", + )) + .as_ptr(), + 289 as libc::c_int, + ); + } + if frames >= (*m).padding as libc::c_ulong { + frames = (frames as libc::c_ulong).wrapping_sub((*m).padding as libc::c_ulong) + as crate::stddef_h::size_t + as crate::stddef_h::size_t + } else { + frames = 0 as libc::c_int as crate::stddef_h::size_t + } + (*m).samples = 0 as libc::c_int as crate::squeezelite_h::u64_t + } + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d write %u frames\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"mad_decode\x00")) + .as_ptr(), + 299 as libc::c_int, + frames, + ); + } + while frames > 0 as libc::c_int as libc::c_ulong { + let mut f: crate::stddef_h::size_t = 0; + let mut count: crate::stddef_h::size_t = 0; + let mut optr = 0 as *mut crate::squeezelite_h::s32_t; + f = if frames + < crate::src::buffer::_buf_cont_write(outputbuf) + .wrapping_div(8 as libc::c_int as libc::c_uint) + as libc::c_ulong + { + frames + } else { + crate::src::buffer::_buf_cont_write(outputbuf) + .wrapping_div(8 as libc::c_int as libc::c_uint) as libc::c_ulong + }; + optr = (*outputbuf).writep as *mut crate::squeezelite_h::s32_t; + count = f; + loop { + let fresh0 = count; + count = count.wrapping_sub(1); + if !(fresh0 != 0) { + break; + } + let fresh1 = iptrl; + iptrl = iptrl.offset(1); + let fresh2 = optr; + optr = optr.offset(1); + *fresh2 = scale(*fresh1) as crate::squeezelite_h::s32_t; + let fresh3 = iptrr; + iptrr = iptrr.offset(1); + let fresh4 = optr; + optr = optr.offset(1); + *fresh4 = scale(*fresh3) as crate::squeezelite_h::s32_t + } + frames = (frames as libc::c_ulong).wrapping_sub(f) as crate::stddef_h::size_t + as crate::stddef_h::size_t; + crate::src::buffer::_buf_inc_writep( + outputbuf, + f.wrapping_mul(8 as libc::c_int as libc::c_ulong) as libc::c_uint, + ); + } + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + } +} + +unsafe extern "C" fn mad_open( + mut size: crate::squeezelite_h::u8_t, + mut rate: crate::squeezelite_h::u8_t, + mut chan: crate::squeezelite_h::u8_t, + mut endianness: crate::squeezelite_h::u8_t, +) { + if (*m).readbuf.is_null() { + (*m).readbuf = + crate::stdlib::malloc((2048 as libc::c_int + 8 as libc::c_int) as libc::c_ulong) + as *mut crate::squeezelite_h::u8_t + } + (*m).checktags = 1 as libc::c_int; + (*m).consume = 0 as libc::c_int as crate::squeezelite_h::u32_t; + (*m).skip = 529 as libc::c_int as crate::squeezelite_h::u32_t; + (*m).samples = 0 as libc::c_int as crate::squeezelite_h::u64_t; + (*m).readbuf_len = 0 as libc::c_int as libc::c_uint; + (*m).last_error = crate::stdlib::MAD_ERROR_NONE; + (*m).mad_stream_init.expect("non-null function pointer")(&mut (*m).stream); + (*m).mad_frame_init.expect("non-null function pointer")(&mut (*m).frame); + (*m).mad_synth_init.expect("non-null function pointer")(&mut (*m).synth); +} + +unsafe extern "C" fn mad_close() { + // macro only in current version + (*m).mad_frame_finish.expect("non-null function pointer")(&mut (*m).frame); + (*m).mad_stream_finish.expect("non-null function pointer")(&mut (*m).stream); + crate::stdlib::free((*m).readbuf as *mut libc::c_void); + (*m).readbuf = 0 as *mut crate::squeezelite_h::u8_t; +} + +unsafe extern "C" fn load_mad() -> bool { + let mut handle = crate::stdlib::dlopen( + b"libmad.so.0\x00" as *const u8 as *const libc::c_char, + 0x2 as libc::c_int, + ); + let mut err = 0 as *mut libc::c_char; + if handle.is_null() { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d dlerror: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"load_mad\x00")).as_ptr(), + 366 as libc::c_int, + crate::stdlib::dlerror(), + ); + } + return 0 as libc::c_int != 0; + } + (*m).mad_stream_init = ::std::mem::transmute::< + *mut libc::c_void, + Option ()>, + >(crate::stdlib::dlsym( + handle, + b"mad_stream_init\x00" as *const u8 as *const libc::c_char, + )); + (*m).mad_frame_init = ::std::mem::transmute::< + *mut libc::c_void, + Option ()>, + >(crate::stdlib::dlsym( + handle, + b"mad_frame_init\x00" as *const u8 as *const libc::c_char, + )); + (*m).mad_synth_init = ::std::mem::transmute::< + *mut libc::c_void, + Option ()>, + >(crate::stdlib::dlsym( + handle, + b"mad_synth_init\x00" as *const u8 as *const libc::c_char, + )); + (*m).mad_frame_finish = ::std::mem::transmute::< + *mut libc::c_void, + Option ()>, + >(crate::stdlib::dlsym( + handle, + b"mad_frame_finish\x00" as *const u8 as *const libc::c_char, + )); + (*m).mad_stream_finish = ::std::mem::transmute::< + *mut libc::c_void, + Option ()>, + >(crate::stdlib::dlsym( + handle, + b"mad_stream_finish\x00" as *const u8 as *const libc::c_char, + )); + (*m).mad_stream_buffer = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::mad_stream, + _: *const libc::c_uchar, + _: libc::c_ulong, + ) -> (), + >, + >(crate::stdlib::dlsym( + handle, + b"mad_stream_buffer\x00" as *const u8 as *const libc::c_char, + )); + (*m).mad_frame_decode = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::mad_frame, + _: *mut crate::stdlib::mad_stream, + ) -> libc::c_int, + >, + >(crate::stdlib::dlsym( + handle, + b"mad_frame_decode\x00" as *const u8 as *const libc::c_char, + )); + (*m).mad_synth_frame = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::mad_synth, + _: *const crate::stdlib::mad_frame, + ) -> (), + >, + >(crate::stdlib::dlsym( + handle, + b"mad_synth_frame\x00" as *const u8 as *const libc::c_char, + )); + (*m).mad_stream_errorstr = ::std::mem::transmute::< + *mut libc::c_void, + Option *const libc::c_char>, + >(crate::stdlib::dlsym( + handle, + b"mad_stream_errorstr\x00" as *const u8 as *const libc::c_char, + )); + err = crate::stdlib::dlerror(); + if !err.is_null() { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d dlerror: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"load_mad\x00")).as_ptr(), + 381 as libc::c_int, + err, + ); + } + return 0 as libc::c_int != 0; + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d loaded libmad.so.0\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"load_mad\x00")).as_ptr(), + 385 as libc::c_int, + ); + } + return 1 as libc::c_int != 0; +} +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Additions (c) Paul Hermann, 2015-2017 under the same license terms + * -Control of Raspberry pi GPIO for amplifier power + * -Launch script on power status change from LMS + */ +// make may define: PORTAUDIO, SELFPIPE, RESAMPLE, RESAMPLE_MP, VISEXPORT, GPIO, IR, DSD, LINKALL to influence build +// build detection +// dynamically loaded libraries at run time +// !LINKALL +// config options +// do not reduce as icy-meta max is 4080 +/* SUN */ +/* SUN */ +// printf/scanf formats for u64_t +// logging +// utils.c (non logging) +// buffer.c +// _* called with mutex locked +// slimproto.c +// stream.c +// decode.c +// output.c output_alsa.c output_pa.c output_pack.c +// frames played at the point delay is measured +// ordered largest first so [0] is max_rate +// set in decode thread +// set in decode thread +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// _* called with mutex locked +// output_alsa.c +// output_pa.c +// output_pulse.c +// output_stdout.c +// output_pack.c +// output_vis.c +// dop.c +// codecs +#[no_mangle] + +pub unsafe extern "C" fn register_mad() -> *mut crate::squeezelite_h::codec { + static mut ret: crate::squeezelite_h::codec = unsafe { + { + let mut init = crate::squeezelite_h::codec { + id: 'm' as i32 as libc::c_char, + types: b"mp3\x00" as *const u8 as *const libc::c_char as *mut libc::c_char, + min_read_bytes: 2048 as libc::c_int as libc::c_uint, + min_space: 206800 as libc::c_int as libc::c_uint, + open: Some( + mad_open + as unsafe extern "C" fn( + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + ) -> (), + ), + close: Some(mad_close as unsafe extern "C" fn() -> ()), + decode: Some( + mad_decode as unsafe extern "C" fn() -> crate::squeezelite_h::decode_state, + ), + }; + init + } + }; + m = crate::stdlib::malloc(::std::mem::size_of::() as libc::c_ulong) as *mut mad; + if m.is_null() { + return 0 as *mut crate::squeezelite_h::codec; + } + (*m).readbuf = 0 as *mut crate::squeezelite_h::u8_t; + (*m).readbuf_len = 0 as libc::c_int as libc::c_uint; + if !load_mad() { + return 0 as *mut crate::squeezelite_h::codec; + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d using mad to decode mp3\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"register_mad\x00")) + .as_ptr(), + 414 as libc::c_int, + ); + } + return &mut ret; +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..4ebfbf7 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,1014 @@ +#![allow( + dead_code, + mutable_transmutes, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] +#![register_tool(c2rust)] +#![feature(const_raw_ptr_to_usize_cast, extern_types, main, register_tool)] +pub mod stddef_h { + pub type size_t = libc::c_ulong; +} +pub mod squeezelite_h { + extern "C" { + #[no_mangle] + pub fn output_close_stdout(); + + #[no_mangle] + pub fn output_init_stdout( + level: crate::squeezelite_h::log_level, + output_buf_size: libc::c_uint, + params: *mut libc::c_char, + rates: *mut libc::c_uint, + rate_delay: libc::c_uint, + ); + + #[no_mangle] + pub fn output_close_alsa(); + + #[no_mangle] + pub fn output_init_alsa( + level: crate::squeezelite_h::log_level, + device: *const libc::c_char, + output_buf_size: libc::c_uint, + params: *mut libc::c_char, + rates: *mut libc::c_uint, + rate_delay: libc::c_uint, + rt_priority: libc::c_uint, + idle: libc::c_uint, + mixer_device: *mut libc::c_char, + volume_mixer: *mut libc::c_char, + mixer_unmute: bool, + mixer_linear: bool, + ); + + #[no_mangle] + pub fn list_mixers(output_device: *const libc::c_char); + + #[no_mangle] + pub fn list_devices(); + + #[no_mangle] + pub fn decode_close(); + + #[no_mangle] + pub fn decode_init( + level: crate::squeezelite_h::log_level, + include_codecs: *const libc::c_char, + exclude_codecs: *const libc::c_char, + ); + + #[no_mangle] + pub fn stream_close(); + + #[no_mangle] + pub fn stream_init(level: crate::squeezelite_h::log_level, stream_buf_size: libc::c_uint); + + #[no_mangle] + pub fn slimproto_stop(); + + #[no_mangle] + pub fn slimproto( + level: crate::squeezelite_h::log_level, + server: *mut libc::c_char, + mac: *mut crate::squeezelite_h::u8_t, + name: *const libc::c_char, + namefile: *const libc::c_char, + modelname: *const libc::c_char, + maxSampleRate: libc::c_int, + ); + + #[no_mangle] + pub fn get_mac(mac: *mut crate::squeezelite_h::u8_t); + + #[no_mangle] + pub fn next_param(src: *mut libc::c_char, c: libc::c_char) -> *mut libc::c_char; + + #[no_mangle] + pub fn logprint(fmt: *const libc::c_char, _: ...); + + #[no_mangle] + pub fn logtime() -> *const libc::c_char; + } + pub type u8_t = crate::stdlib::u_int8_t; + + pub type log_level = libc::c_uint; + + pub const lSDEBUG: crate::squeezelite_h::log_level = 4; + + pub const lDEBUG: crate::squeezelite_h::log_level = 3; + + pub const lINFO: crate::squeezelite_h::log_level = 2; + + pub const lWARN: crate::squeezelite_h::log_level = 1; + + pub const lERROR: crate::squeezelite_h::log_level = 0; +} +pub mod stdlib { + extern "C" { + #[no_mangle] + pub fn __errno_location() -> *mut libc::c_int; + #[no_mangle] + pub fn signal( + __sig: libc::c_int, + __handler: crate::stdlib::__sighandler_t, + ) -> crate::stdlib::__sighandler_t; + #[no_mangle] + pub static mut stderr: *mut crate::stdlib::FILE; + + #[no_mangle] + pub fn fclose(__stream: *mut crate::stdlib::FILE) -> libc::c_int; + + #[no_mangle] + pub fn fopen(_: *const libc::c_char, _: *const libc::c_char) -> *mut crate::stdlib::FILE; + + #[no_mangle] + pub fn freopen( + __filename: *const libc::c_char, + __modes: *const libc::c_char, + __stream: *mut crate::stdlib::FILE, + ) -> *mut crate::stdlib::FILE; + + #[no_mangle] + pub fn fprintf(_: *mut crate::stdlib::FILE, _: *const libc::c_char, _: ...) -> libc::c_int; + + #[no_mangle] + pub fn printf(_: *const libc::c_char, _: ...) -> libc::c_int; + #[no_mangle] + pub fn atoi(__nptr: *const libc::c_char) -> libc::c_int; + + #[no_mangle] + pub fn strtoul( + _: *const libc::c_char, + _: *mut *mut libc::c_char, + _: libc::c_int, + ) -> libc::c_ulong; + + #[no_mangle] + pub fn free(__ptr: *mut libc::c_void); + + #[no_mangle] + pub fn exit(_: libc::c_int) -> !; + + #[no_mangle] + pub fn realpath( + __name: *const libc::c_char, + __resolved: *mut libc::c_char, + ) -> *mut libc::c_char; + #[no_mangle] + pub fn strcat(_: *mut libc::c_char, _: *const libc::c_char) -> *mut libc::c_char; + + #[no_mangle] + pub fn strcmp(_: *const libc::c_char, _: *const libc::c_char) -> libc::c_int; + + #[no_mangle] + pub fn strncmp( + _: *const libc::c_char, + _: *const libc::c_char, + _: libc::c_ulong, + ) -> libc::c_int; + + #[no_mangle] + pub fn strstr(_: *const libc::c_char, _: *const libc::c_char) -> *mut libc::c_char; + + #[no_mangle] + pub fn strtok(_: *mut libc::c_char, _: *const libc::c_char) -> *mut libc::c_char; + + #[no_mangle] + pub fn strlen(_: *const libc::c_char) -> libc::c_ulong; + + #[no_mangle] + pub fn strerror(_: libc::c_int) -> *mut libc::c_char; + pub type _IO_wide_data; + + pub type _IO_codecvt; + + pub type _IO_marker; + #[no_mangle] + pub fn getpid() -> crate::stdlib::__pid_t; + + #[no_mangle] + pub fn unlink(__name: *const libc::c_char) -> libc::c_int; + + #[no_mangle] + pub fn daemon(__nochdir: libc::c_int, __noclose: libc::c_int) -> libc::c_int; + } + pub type FILE = crate::stdlib::_IO_FILE; + pub type __sighandler_t = Option ()>; + #[repr(C)] + #[derive(Copy, Clone)] + pub struct _IO_FILE { + pub _flags: libc::c_int, + pub _IO_read_ptr: *mut libc::c_char, + pub _IO_read_end: *mut libc::c_char, + pub _IO_read_base: *mut libc::c_char, + pub _IO_write_base: *mut libc::c_char, + pub _IO_write_ptr: *mut libc::c_char, + pub _IO_write_end: *mut libc::c_char, + pub _IO_buf_base: *mut libc::c_char, + pub _IO_buf_end: *mut libc::c_char, + pub _IO_save_base: *mut libc::c_char, + pub _IO_backup_base: *mut libc::c_char, + pub _IO_save_end: *mut libc::c_char, + pub _markers: *mut crate::stdlib::_IO_marker, + pub _chain: *mut crate::stdlib::_IO_FILE, + pub _fileno: libc::c_int, + pub _flags2: libc::c_int, + pub _old_offset: crate::stdlib::__off_t, + pub _cur_column: libc::c_ushort, + pub _vtable_offset: libc::c_schar, + pub _shortbuf: [libc::c_char; 1], + pub _lock: *mut libc::c_void, + pub _offset: crate::stdlib::__off64_t, + pub _codecvt: *mut crate::stdlib::_IO_codecvt, + pub _wide_data: *mut crate::stdlib::_IO_wide_data, + pub _freeres_list: *mut crate::stdlib::_IO_FILE, + pub _freeres_buf: *mut libc::c_void, + pub __pad5: crate::stddef_h::size_t, + pub _mode: libc::c_int, + pub _unused2: [libc::c_char; 20], + } + + pub type _IO_lock_t = (); + pub type u_int8_t = crate::stdlib::__uint8_t; + pub type __uint8_t = libc::c_uchar; + + pub type __off_t = libc::c_long; + + pub type __off64_t = libc::c_long; + + pub type __pid_t = libc::c_int; +} +use ::squeezers::*; + +pub use crate::stddef_h::size_t; + +pub use crate::stdlib::_IO_codecvt; +pub use crate::stdlib::_IO_lock_t; +pub use crate::stdlib::_IO_marker; +pub use crate::stdlib::_IO_wide_data; +pub use crate::stdlib::__off64_t; +pub use crate::stdlib::__off_t; +pub use crate::stdlib::__pid_t; +pub use crate::stdlib::__uint8_t; +pub use crate::stdlib::u_int8_t; +pub use crate::stdlib::FILE; +pub use crate::stdlib::_IO_FILE; + +pub use crate::squeezelite_h::decode_close; +pub use crate::squeezelite_h::decode_init; +pub use crate::squeezelite_h::get_mac; +pub use crate::squeezelite_h::lDEBUG; +pub use crate::squeezelite_h::lERROR; +pub use crate::squeezelite_h::lINFO; +pub use crate::squeezelite_h::lSDEBUG; +pub use crate::squeezelite_h::lWARN; +pub use crate::squeezelite_h::list_devices; +pub use crate::squeezelite_h::list_mixers; +pub use crate::squeezelite_h::log_level; +pub use crate::squeezelite_h::logprint; +pub use crate::squeezelite_h::logtime; +pub use crate::squeezelite_h::next_param; +pub use crate::squeezelite_h::output_close_alsa; +pub use crate::squeezelite_h::output_close_stdout; +pub use crate::squeezelite_h::output_init_alsa; +pub use crate::squeezelite_h::output_init_stdout; +pub use crate::squeezelite_h::slimproto; +pub use crate::squeezelite_h::slimproto_stop; +pub use crate::squeezelite_h::stream_close; +pub use crate::squeezelite_h::stream_init; +pub use crate::squeezelite_h::u8_t; +use crate::stdlib::__errno_location; +pub use crate::stdlib::__sighandler_t; +use crate::stdlib::atoi; +use crate::stdlib::daemon; +use crate::stdlib::exit; +use crate::stdlib::fclose; +use crate::stdlib::fopen; +use crate::stdlib::fprintf; +use crate::stdlib::free; +use crate::stdlib::freopen; +use crate::stdlib::getpid; +use crate::stdlib::printf; +use crate::stdlib::realpath; +pub use crate::stdlib::signal; +use crate::stdlib::stderr; +use crate::stdlib::strcat; +use crate::stdlib::strcmp; +use crate::stdlib::strerror; +use crate::stdlib::strlen; +use crate::stdlib::strncmp; +use crate::stdlib::strstr; +use crate::stdlib::strtok; +use crate::stdlib::strtoul; +use crate::stdlib::unlink; +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2020, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Additions (c) Paul Hermann, 2015-2017 under the same license terms + * -Control of Raspberry pi GPIO for amplifier power + * -Launch script on power status change from LMS + */ + +unsafe extern "C" fn usage(mut argv0: *const libc::c_char) { + crate::stdlib::printf(b"Squeezelite v1.9.7-1218, Copyright 2012-2015 Adrian Smith, 2015-2020 Ralph Irving. See -t for license terms\nUsage: %s [options]\n -s [:]\tConnect to specified server, otherwise uses autodiscovery to find server\n -o \tSpecify output device, default \"default\", - = output to stdout\n -l \t\t\tList output devices\n -a :

::\tSpecify ALSA params to open output device, b = buffer time in ms or size in bytes, p = period count or size in bytes, f sample format (16|24|24_3|32), m = use mmap (0|1)\n -a \t\tSpecify sample format (16|24|32) of output file when using -o - to output samples to stdout (interleaved little endian only)\n -b :\tSpecify internal Stream and Output buffer sizes in Kbytes\n -c ,\tRestrict codecs to those specified, otherwise load all available codecs; known codecs: flac,pcm,mp3,ogg,aac (mad,mpg for specific mp3 codec)\n \t\t\tCodecs reported to LMS in order listed, allowing codec priority refinement.\n -C \t\tClose output device when idle after timeout seconds, default is to keep it open while player is \'on\'\n -d =\tSet logging level, logs: all|slimproto|stream|decode|output, level: info|debug|sdebug\n -e ,\tExplicitly exclude native support of one or more codecs; known codecs: flac,pcm,mp3,ogg,aac (mad,mpg for specific mp3 codec)\n -f \t\tWrite debug to logfile\n -m \t\tSet mac address, format: ab:cd:ef:12:34:56\n -M \tSet the squeezelite player model name sent to the server (default: SqueezeLite)\n -n \t\tSet the player name\n -N \t\tStore player name in filename to allow server defined name changes to be shared between servers (not supported with -n)\n -W\t\t\tRead wave and aiff format from header, ignore server parameters\n -p \t\tSet real time priority of output thread (1-99)\n -P \t\tStore the process id (PID) in filename\n -r [:]\tSample rates supported, allows output to be off when squeezelite is started; rates = |-|,,; delay = optional delay switching rates in ms\n -O \tSpecify mixer device, defaults to \'output device\'\n -L \t\t\tList volume controls for output device\n -U \t\tUnmute ALSA control and set to full volume (not supported with -V)\n -V \t\tUse ALSA control for volume adjustment, otherwise use software volume adjustment\n -X \t\t\tUse linear volume adjustments instead of in terms of dB (only for hardware volume control)\n -z \t\t\tDaemonize\n -t \t\t\tLicense terms\n -? \t\t\tDisplay this help text\n\nBuild options: LINUX ALSA EVENTFD\n\n\x00" + as *const u8 as *const libc::c_char, argv0); +} + +unsafe extern "C" fn license() { + crate::stdlib::printf(b"Squeezelite v1.9.7-1218, Copyright 2012-2015 Adrian Smith, 2015-2020 Ralph Irving.\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see .\n\nOption to allow server side upsampling for PCM streams (-W) from\nsqueezelite-R2 (c) Marco Curti 2015, marcoc1712@gmail.com.\n\n\x00" + as *const u8 as *const libc::c_char); +} + +unsafe extern "C" fn sighandler(mut signum: libc::c_int) { + crate::squeezelite_h::slimproto_stop(); + // remove ourselves in case above does not work, second SIGINT will cause non gracefull shutdown + crate::stdlib::signal(signum, None); // set later +} + +unsafe fn main_0(mut argc: libc::c_int, mut argv: *mut *mut libc::c_char) -> libc::c_int { + let mut server = 0 as *mut libc::c_char; + let mut output_device = b"default\x00" as *const u8 as *const libc::c_char as *mut libc::c_char; + let mut include_codecs = 0 as *mut libc::c_char; + let mut exclude_codecs = b"\x00" as *const u8 as *const libc::c_char as *mut libc::c_char; + let mut name = 0 as *mut libc::c_char; + let mut namefile = 0 as *mut libc::c_char; + let mut modelname = 0 as *mut libc::c_char; + extern "C" { + #[no_mangle] + pub static mut pcm_check_header: bool; + } + extern "C" { + #[no_mangle] + pub static mut user_rates: bool; + } + let mut logfile = 0 as *mut libc::c_char; + let mut mac: [crate::squeezelite_h::u8_t; 6] = [0; 6]; + let mut stream_buf_size = + (2 as libc::c_int * 1024 as libc::c_int * 1024 as libc::c_int) as libc::c_uint; + let mut output_buf_size = 0 as libc::c_int as libc::c_uint; + let mut rates: [libc::c_uint; 18] = [ + 0 as libc::c_int as libc::c_uint, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + ]; + let mut rate_delay = 0 as libc::c_int as libc::c_uint; + let mut resample = 0 as *mut libc::c_char; + let mut output_params = 0 as *mut libc::c_char; + let mut idle = 0 as libc::c_int as libc::c_uint; + let mut daemonize = 0 as libc::c_int != 0; + let mut pidfile = 0 as *mut libc::c_char; + let mut pidfp = 0 as *mut crate::stdlib::FILE; + let mut rt_priority = 45 as libc::c_int as libc::c_uint; + let mut mixer_device = output_device; + let mut output_mixer = 0 as *mut libc::c_char; + let mut output_mixer_unmute = 0 as libc::c_int != 0; + let mut linear_volume = 0 as libc::c_int != 0; + let mut log_output = crate::squeezelite_h::lWARN; + let mut log_stream = crate::squeezelite_h::lWARN; + let mut log_decode = crate::squeezelite_h::lWARN; + let mut log_slimproto = crate::squeezelite_h::lWARN; + let mut maxSampleRate = 0 as libc::c_int; + let mut optarg = 0 as *mut libc::c_char; + let mut optind = 1 as libc::c_int; + let mut i: libc::c_int = 0; + let mut cmdline: [libc::c_char; 512] = + *::std::mem::transmute::<&[u8; 512], + &mut [libc::c_char; 512]>(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"); + crate::squeezelite_h::get_mac(mac.as_mut_ptr()); + i = 0 as libc::c_int; + while i < argc + && crate::stdlib::strlen(*argv.offset(i as isize)) + .wrapping_add(crate::stdlib::strlen(cmdline.as_mut_ptr())) + .wrapping_add(2 as libc::c_int as libc::c_ulong) + < 512 as libc::c_int as libc::c_ulong + { + crate::stdlib::strcat(cmdline.as_mut_ptr(), *argv.offset(i as isize)); + crate::stdlib::strcat( + cmdline.as_mut_ptr(), + b" \x00" as *const u8 as *const libc::c_char, + ); + i += 1 + } + while optind < argc + && crate::stdlib::strlen(*argv.offset(optind as isize)) >= 2 as libc::c_int as libc::c_ulong + && *(*argv.offset(optind as isize)).offset(0 as libc::c_int as isize) as libc::c_int + == '-' as i32 + { + let mut opt = (*argv.offset(optind as isize)).offset(1 as libc::c_int as isize); + if !crate::stdlib::strstr( + b"oabcCdefmMnNpPrsUVO\x00" as *const u8 as *const libc::c_char, + opt, + ) + .is_null() + && optind < argc - 1 as libc::c_int + { + optarg = *argv.offset((optind + 1 as libc::c_int) as isize); + optind += 2 as libc::c_int + } else if !crate::stdlib::strstr(b"ltz?WLX\x00" as *const u8 as *const libc::c_char, opt) + .is_null() + { + optarg = 0 as *mut libc::c_char; + optind += 1 as libc::c_int + } else { + crate::stdlib::fprintf( + crate::stdlib::stderr, + b"\nOption error: -%s\n\n\x00" as *const u8 as *const libc::c_char, + opt, + ); + usage(*argv.offset(0 as libc::c_int as isize)); + crate::stdlib::exit(1 as libc::c_int); + } + let mut current_block_129: u64; + match *opt.offset(0 as libc::c_int as isize) as libc::c_int { + 111 => { + output_device = optarg; + mixer_device = optarg; + current_block_129 = 10517665100358322178; + } + 97 => { + output_params = optarg; + current_block_129 = 10517665100358322178; + } + 98 => { + let mut s = crate::squeezelite_h::next_param(optarg, ':' as i32 as libc::c_char); + let mut o = crate::squeezelite_h::next_param( + 0 as *mut libc::c_char, + ':' as i32 as libc::c_char, + ); + if !s.is_null() { + stream_buf_size = (crate::stdlib::atoi(s) * 1024 as libc::c_int) as libc::c_uint + } + if !o.is_null() { + output_buf_size = (crate::stdlib::atoi(o) * 1024 as libc::c_int) as libc::c_uint + } + current_block_129 = 10517665100358322178; + } + 99 => { + include_codecs = optarg; + current_block_129 = 10517665100358322178; + } + 67 => { + if crate::stdlib::atoi(optarg) > 0 as libc::c_int { + idle = (crate::stdlib::atoi(optarg) * 1000 as libc::c_int) as libc::c_uint + } + current_block_129 = 10517665100358322178; + } + 101 => { + exclude_codecs = optarg; + current_block_129 = 10517665100358322178; + } + 100 => { + let mut l = + crate::stdlib::strtok(optarg, b"=\x00" as *const u8 as *const libc::c_char); + let mut v = crate::stdlib::strtok( + 0 as *mut libc::c_char, + b"=\x00" as *const u8 as *const libc::c_char, + ); + let mut new = crate::squeezelite_h::lWARN; + if !l.is_null() && !v.is_null() { + if crate::stdlib::strcmp(v, b"info\x00" as *const u8 as *const libc::c_char) + == 0 + { + new = crate::squeezelite_h::lINFO + } + if crate::stdlib::strcmp(v, b"debug\x00" as *const u8 as *const libc::c_char) + == 0 + { + new = crate::squeezelite_h::lDEBUG + } + if crate::stdlib::strcmp(v, b"sdebug\x00" as *const u8 as *const libc::c_char) + == 0 + { + new = crate::squeezelite_h::lSDEBUG + } + if crate::stdlib::strcmp(l, b"all\x00" as *const u8 as *const libc::c_char) == 0 + || crate::stdlib::strcmp( + l, + b"slimproto\x00" as *const u8 as *const libc::c_char, + ) == 0 + { + log_slimproto = new + } + if crate::stdlib::strcmp(l, b"all\x00" as *const u8 as *const libc::c_char) == 0 + || crate::stdlib::strcmp( + l, + b"stream\x00" as *const u8 as *const libc::c_char, + ) == 0 + { + log_stream = new + } + if crate::stdlib::strcmp(l, b"all\x00" as *const u8 as *const libc::c_char) == 0 + || crate::stdlib::strcmp( + l, + b"decode\x00" as *const u8 as *const libc::c_char, + ) == 0 + { + log_decode = new + } + if crate::stdlib::strcmp(l, b"all\x00" as *const u8 as *const libc::c_char) == 0 + || crate::stdlib::strcmp( + l, + b"output\x00" as *const u8 as *const libc::c_char, + ) == 0 + { + log_output = new + } + } else { + crate::stdlib::fprintf( + crate::stdlib::stderr, + b"\nDebug settings error: -d %s\n\n\x00" as *const u8 + as *const libc::c_char, + optarg, + ); + usage(*argv.offset(0 as libc::c_int as isize)); + crate::stdlib::exit(1 as libc::c_int); + } + current_block_129 = 10517665100358322178; + } + 102 => { + logfile = optarg; + current_block_129 = 10517665100358322178; + } + 109 => { + let mut byte = 0 as libc::c_int; + let mut tmp = 0 as *mut libc::c_char; + if crate::stdlib::strncmp( + optarg, + b"00:04:20\x00" as *const u8 as *const libc::c_char, + 8 as libc::c_int as libc::c_ulong, + ) == 0 + { + crate::squeezelite_h::logprint(b"%s %s:%d ignoring mac address from hardware player range 00:04:20:**:**:**\n\x00" + as *const u8 as *const libc::c_char, + crate::squeezelite_h::logtime(), + (*::std::mem::transmute::<&[u8; 5], + &[libc::c_char; 5]>(b"main\x00")).as_ptr(), + 453 as libc::c_int); + } else { + let mut t = + crate::stdlib::strtok(optarg, b":\x00" as *const u8 as *const libc::c_char); + while !t.is_null() && byte < 6 as libc::c_int { + let fresh0 = byte; + byte = byte + 1; + mac[fresh0 as usize] = + crate::stdlib::strtoul(t, &mut tmp, 16 as libc::c_int) + as crate::squeezelite_h::u8_t; + t = crate::stdlib::strtok( + 0 as *mut libc::c_char, + b":\x00" as *const u8 as *const libc::c_char, + ) + } + } + current_block_129 = 10517665100358322178; + } + 77 => { + modelname = optarg; + current_block_129 = 10517665100358322178; + } + 114 => { + let mut rstr = crate::squeezelite_h::next_param(optarg, ':' as i32 as libc::c_char); + let mut dstr = crate::squeezelite_h::next_param( + 0 as *mut libc::c_char, + ':' as i32 as libc::c_char, + ); + if !rstr.is_null() + && !crate::stdlib::strstr(rstr, b",\x00" as *const u8 as *const libc::c_char) + .is_null() + { + // parse sample rates and sort them + let mut r = crate::squeezelite_h::next_param(rstr, ',' as i32 as libc::c_char); + let mut tmp_0: [libc::c_uint; 18] = [ + 0 as libc::c_int as libc::c_uint, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + ]; + let mut i_0: libc::c_int = 0; + let mut j: libc::c_int = 0; + let mut last = 999999 as libc::c_int; + i_0 = 0 as libc::c_int; + while !r.is_null() && i_0 < 18 as libc::c_int { + tmp_0[i_0 as usize] = crate::stdlib::atoi(r) as libc::c_uint; + r = crate::squeezelite_h::next_param( + 0 as *mut libc::c_char, + ',' as i32 as libc::c_char, + ); + i_0 += 1 + } + i_0 = 0 as libc::c_int; + while i_0 < 18 as libc::c_int { + let mut largest = 0 as libc::c_int; + j = 0 as libc::c_int; + while j < 18 as libc::c_int { + if tmp_0[j as usize] > largest as libc::c_uint + && tmp_0[j as usize] < last as libc::c_uint + { + largest = tmp_0[j as usize] as libc::c_int + } + j += 1 + } + last = largest; + rates[i_0 as usize] = last as libc::c_uint; + i_0 += 1 + } + } else if !rstr.is_null() { + // optstr is - or , extract rates from test rates within this range + let mut ref_0: [libc::c_uint; 18] = [ + 768000 as libc::c_int as libc::c_uint, + 705600 as libc::c_int as libc::c_uint, + 384000 as libc::c_int as libc::c_uint, + 352800 as libc::c_int as libc::c_uint, + 192000 as libc::c_int as libc::c_uint, + 176400 as libc::c_int as libc::c_uint, + 96000 as libc::c_int as libc::c_uint, + 88200 as libc::c_int as libc::c_uint, + 48000 as libc::c_int as libc::c_uint, + 44100 as libc::c_int as libc::c_uint, + 32000 as libc::c_int as libc::c_uint, + 24000 as libc::c_int as libc::c_uint, + 22500 as libc::c_int as libc::c_uint, + 16000 as libc::c_int as libc::c_uint, + 12000 as libc::c_int as libc::c_uint, + 11025 as libc::c_int as libc::c_uint, + 8000 as libc::c_int as libc::c_uint, + 0 as libc::c_int as libc::c_uint, + ]; + let mut str1 = + crate::squeezelite_h::next_param(rstr, '-' as i32 as libc::c_char); + let mut str2 = crate::squeezelite_h::next_param( + 0 as *mut libc::c_char, + '-' as i32 as libc::c_char, + ); + let mut max = if !str2.is_null() { + crate::stdlib::atoi(str2) as libc::c_uint + } else if !str1.is_null() { + crate::stdlib::atoi(str1) as libc::c_uint + } else { + ref_0[0 as libc::c_int as usize] + }; + let mut min = if !str1.is_null() && !str2.is_null() { + crate::stdlib::atoi(str1) + } else { + 0 as libc::c_int + } as libc::c_uint; + let mut tmp_1: libc::c_uint = 0; + let mut i_1: libc::c_int = 0; + let mut j_0: libc::c_int = 0; + if max < min { + tmp_1 = max; + max = min; + min = tmp_1 + } + rates[0 as libc::c_int as usize] = max; + i_1 = 0 as libc::c_int; + j_0 = 1 as libc::c_int; + while i_1 < 18 as libc::c_int { + if ref_0[i_1 as usize] < rates[(j_0 - 1 as libc::c_int) as usize] + && ref_0[i_1 as usize] >= min + { + let fresh1 = j_0; + j_0 = j_0 + 1; + rates[fresh1 as usize] = ref_0[i_1 as usize] + } + i_1 += 1 + } + } + if !dstr.is_null() { + rate_delay = crate::stdlib::atoi(dstr) as libc::c_uint + } + if rates[0 as libc::c_int as usize] != 0 { + user_rates = 1 as libc::c_int != 0 + } + current_block_129 = 10517665100358322178; + } + 115 => { + server = optarg; + current_block_129 = 10517665100358322178; + } + 110 => { + name = optarg; + current_block_129 = 10517665100358322178; + } + 78 => { + namefile = optarg; + current_block_129 = 10517665100358322178; + } + 87 => { + pcm_check_header = 1 as libc::c_int != 0; + current_block_129 = 10517665100358322178; + } + 112 => { + rt_priority = crate::stdlib::atoi(optarg) as libc::c_uint; + if rt_priority > 99 as libc::c_int as libc::c_uint + || rt_priority < 1 as libc::c_int as libc::c_uint + { + crate::stdlib::fprintf( + crate::stdlib::stderr, + b"\nError: invalid priority: %s\n\n\x00" as *const u8 + as *const libc::c_char, + optarg, + ); + usage(*argv.offset(0 as libc::c_int as isize)); + crate::stdlib::exit(1 as libc::c_int); + } + current_block_129 = 10517665100358322178; + } + 80 => { + pidfile = optarg; + current_block_129 = 10517665100358322178; + } + 108 => { + crate::squeezelite_h::list_devices(); + crate::stdlib::exit(0 as libc::c_int); + } + 79 => { + mixer_device = optarg; + current_block_129 = 10517665100358322178; + } + 76 => { + crate::squeezelite_h::list_mixers(mixer_device); + crate::stdlib::exit(0 as libc::c_int); + } + 88 => { + linear_volume = 1 as libc::c_int != 0; + current_block_129 = 10517665100358322178; + } + 85 => { + output_mixer_unmute = 1 as libc::c_int != 0; + current_block_129 = 17662379048890589436; + } + 86 => { + current_block_129 = 17662379048890589436; + } + 122 => { + daemonize = 1 as libc::c_int != 0; + current_block_129 = 10517665100358322178; + } + 116 => { + license(); + crate::stdlib::exit(0 as libc::c_int); + } + 63 => { + usage(*argv.offset(0 as libc::c_int as isize)); + crate::stdlib::exit(0 as libc::c_int); + } + _ => { + crate::stdlib::fprintf( + crate::stdlib::stderr, + b"Arg error: %s\n\x00" as *const u8 as *const libc::c_char, + *argv.offset(optind as isize), + ); + current_block_129 = 10517665100358322178; + } + } + match current_block_129 { + 17662379048890589436 => { + if !output_mixer.is_null() { + crate::stdlib::fprintf( + crate::stdlib::stderr, + b"-U and -V option should not be used at same time\n\x00" as *const u8 + as *const libc::c_char, + ); + crate::stdlib::exit(1 as libc::c_int); + } + output_mixer = optarg + } + _ => {} + } + } + // warn if command line includes something which isn't parsed + if optind < argc { + crate::stdlib::fprintf( + crate::stdlib::stderr, + b"\nError: command line argument error\n\n\x00" as *const u8 as *const libc::c_char, + ); + usage(*argv.offset(0 as libc::c_int as isize)); + crate::stdlib::exit(1 as libc::c_int); + } + crate::stdlib::signal( + 2 as libc::c_int, + Some(sighandler as unsafe extern "C" fn(_: libc::c_int) -> ()), + ); + crate::stdlib::signal( + 15 as libc::c_int, + Some(sighandler as unsafe extern "C" fn(_: libc::c_int) -> ()), + ); + crate::stdlib::signal( + 3 as libc::c_int, + Some(sighandler as unsafe extern "C" fn(_: libc::c_int) -> ()), + ); + crate::stdlib::signal( + 1 as libc::c_int, + Some(sighandler as unsafe extern "C" fn(_: libc::c_int) -> ()), + ); + // set the output buffer size if not specified on the command line, take account of resampling + if output_buf_size == 0 { + output_buf_size = + (44100 as libc::c_int * 8 as libc::c_int * 10 as libc::c_int) as libc::c_uint; + if !resample.is_null() { + let mut scale = 8 as libc::c_int as libc::c_uint; + if rates[0 as libc::c_int as usize] != 0 { + scale = rates[0 as libc::c_int as usize] + .wrapping_div(44100 as libc::c_int as libc::c_uint); + if scale > 8 as libc::c_int as libc::c_uint { + scale = 8 as libc::c_int as libc::c_uint + } + if scale < 1 as libc::c_int as libc::c_uint { + scale = 1 as libc::c_int as libc::c_uint + } + } + output_buf_size = output_buf_size.wrapping_mul(scale) + } + } + if !logfile.is_null() { + if crate::stdlib::freopen( + logfile, + b"a\x00" as *const u8 as *const libc::c_char, + crate::stdlib::stderr, + ) + .is_null() + { + crate::stdlib::fprintf( + crate::stdlib::stderr, + b"error opening logfile %s: %s\n\x00" as *const u8 as *const libc::c_char, + logfile, + crate::stdlib::strerror(*crate::stdlib::__errno_location()), + ); + } else if log_output as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + || log_stream as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + || log_decode as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + || log_slimproto as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::stdlib::fprintf( + crate::stdlib::stderr, + b"\n%s\n\x00" as *const u8 as *const libc::c_char, + cmdline.as_mut_ptr(), + ); + } + } + if !pidfile.is_null() { + pidfp = crate::stdlib::fopen(pidfile, b"w\x00" as *const u8 as *const libc::c_char); + if pidfp.is_null() { + crate::stdlib::fprintf( + crate::stdlib::stderr, + b"Error opening pidfile %s: %s\n\x00" as *const u8 as *const libc::c_char, + pidfile, + crate::stdlib::strerror(*crate::stdlib::__errno_location()), + ); + crate::stdlib::exit(1 as libc::c_int); + } + pidfile = crate::stdlib::realpath(pidfile, 0 as *mut libc::c_char) + // daemonize will change cwd + } + if daemonize { + if crate::stdlib::daemon( + 0 as libc::c_int, + if !logfile.is_null() { + 1 as libc::c_int + } else { + 0 as libc::c_int + }, + ) != 0 + { + crate::stdlib::fprintf( + crate::stdlib::stderr, + b"error daemonizing: %s\n\x00" as *const u8 as *const libc::c_char, + crate::stdlib::strerror(*crate::stdlib::__errno_location()), + ); + } + } + if !pidfp.is_null() { + crate::stdlib::fprintf( + pidfp, + b"%d\n\x00" as *const u8 as *const libc::c_char, + crate::stdlib::getpid(), + ); + crate::stdlib::fclose(pidfp); + } + crate::squeezelite_h::stream_init(log_stream, stream_buf_size); + if crate::stdlib::strcmp(output_device, b"-\x00" as *const u8 as *const libc::c_char) == 0 { + crate::squeezelite_h::output_init_stdout( + log_output, + output_buf_size, + output_params, + rates.as_mut_ptr(), + rate_delay, + ); + } else { + crate::squeezelite_h::output_init_alsa( + log_output, + output_device, + output_buf_size, + output_params, + rates.as_mut_ptr(), + rate_delay, + rt_priority, + idle, + mixer_device, + output_mixer, + output_mixer_unmute, + linear_volume, + ); + } + crate::squeezelite_h::decode_init(log_decode, include_codecs, exclude_codecs); + if !name.is_null() && !namefile.is_null() { + crate::stdlib::fprintf( + crate::stdlib::stderr, + b"-n and -N option should not be used at same time\n\x00" as *const u8 + as *const libc::c_char, + ); + crate::stdlib::exit(1 as libc::c_int); + } + crate::squeezelite_h::slimproto( + log_slimproto, + server, + mac.as_mut_ptr(), + name, + namefile, + modelname, + maxSampleRate, + ); + crate::squeezelite_h::decode_close(); + crate::squeezelite_h::stream_close(); + if crate::stdlib::strcmp(output_device, b"-\x00" as *const u8 as *const libc::c_char) == 0 { + crate::squeezelite_h::output_close_stdout(); + } else { + crate::squeezelite_h::output_close_alsa(); + } + if !pidfile.is_null() { + crate::stdlib::unlink(pidfile); + crate::stdlib::free(pidfile as *mut libc::c_void); + } + crate::stdlib::exit(0 as libc::c_int); +} +#[main] +pub fn main() { + let mut args: Vec<*mut libc::c_char> = Vec::new(); + for arg in ::std::env::args() { + args.push( + ::std::ffi::CString::new(arg) + .expect("Failed to convert argument into CString.") + .into_raw(), + ); + } + args.push(::std::ptr::null_mut()); + unsafe { + ::std::process::exit(main_0( + (args.len() - 1) as libc::c_int, + args.as_mut_ptr() as *mut *mut libc::c_char, + ) as i32) + } +} diff --git a/src/mpg.rs b/src/mpg.rs new file mode 100644 index 0000000..5fe1a00 --- /dev/null +++ b/src/mpg.rs @@ -0,0 +1,742 @@ +use ::libc; + +pub use crate::stddef_h::size_t; + +pub use crate::stdlib::__int16_t; +pub use crate::stdlib::__int32_t; +pub use crate::stdlib::__pthread_internal_list; +pub use crate::stdlib::__pthread_list_t; +pub use crate::stdlib::__pthread_mutex_s; +pub use crate::stdlib::__uint32_t; +pub use crate::stdlib::__uint64_t; +pub use crate::stdlib::__uint8_t; +pub use crate::stdlib::int16_t; +pub use crate::stdlib::int32_t; +pub use crate::stdlib::pthread_mutex_t; +pub use crate::stdlib::u_int32_t; +pub use crate::stdlib::u_int64_t; +pub use crate::stdlib::u_int8_t; + +pub use crate::squeezelite_h::buffer; +pub use crate::squeezelite_h::codec; +pub use crate::squeezelite_h::decode_state; +pub use crate::squeezelite_h::decodestate; +pub use crate::squeezelite_h::disconnect_code; +pub use crate::squeezelite_h::fade_dir; +pub use crate::squeezelite_h::fade_mode; +pub use crate::squeezelite_h::fade_state; +pub use crate::squeezelite_h::frames_t; +pub use crate::squeezelite_h::lDEBUG; +pub use crate::squeezelite_h::lERROR; +pub use crate::squeezelite_h::lINFO; +pub use crate::squeezelite_h::lSDEBUG; +pub use crate::squeezelite_h::lWARN; +pub use crate::squeezelite_h::log_level; +pub use crate::squeezelite_h::output_format; +pub use crate::squeezelite_h::output_state; +pub use crate::squeezelite_h::outputstate; +pub use crate::squeezelite_h::s16_t; +pub use crate::squeezelite_h::s32_t; +pub use crate::squeezelite_h::stream_state; +pub use crate::squeezelite_h::streamstate; +pub use crate::squeezelite_h::u32_t; +pub use crate::squeezelite_h::u64_t; +pub use crate::squeezelite_h::u8_t; +pub use crate::squeezelite_h::C2RustUnnamed_1; +pub use crate::squeezelite_h::_buf_used; +pub use crate::squeezelite_h::DECODE_COMPLETE; +pub use crate::squeezelite_h::DECODE_ERROR; +pub use crate::squeezelite_h::DECODE_READY; +pub use crate::squeezelite_h::DECODE_RUNNING; +pub use crate::squeezelite_h::DECODE_STOPPED; +pub use crate::squeezelite_h::DISCONNECT; +pub use crate::squeezelite_h::DISCONNECT_OK; +pub use crate::squeezelite_h::FADE_ACTIVE; +pub use crate::squeezelite_h::FADE_CROSS; +pub use crate::squeezelite_h::FADE_CROSSFADE; +pub use crate::squeezelite_h::FADE_DOWN; +pub use crate::squeezelite_h::FADE_DUE; +pub use crate::squeezelite_h::FADE_IN; +pub use crate::squeezelite_h::FADE_INACTIVE; +pub use crate::squeezelite_h::FADE_INOUT; +pub use crate::squeezelite_h::FADE_NONE; +pub use crate::squeezelite_h::FADE_OUT; +pub use crate::squeezelite_h::FADE_UP; +pub use crate::squeezelite_h::LOCAL_DISCONNECT; +pub use crate::squeezelite_h::OUTPUT_BUFFER; +pub use crate::squeezelite_h::OUTPUT_OFF; +pub use crate::squeezelite_h::OUTPUT_PAUSE_FRAMES; +pub use crate::squeezelite_h::OUTPUT_RUNNING; +pub use crate::squeezelite_h::OUTPUT_SKIP_FRAMES; +pub use crate::squeezelite_h::OUTPUT_START_AT; +pub use crate::squeezelite_h::OUTPUT_STOPPED; +pub use crate::squeezelite_h::RECV_HEADERS; +pub use crate::squeezelite_h::REMOTE_DISCONNECT; +pub use crate::squeezelite_h::S16_LE; +pub use crate::squeezelite_h::S24_3LE; +pub use crate::squeezelite_h::S24_LE; +pub use crate::squeezelite_h::S32_LE; +pub use crate::squeezelite_h::SEND_HEADERS; +pub use crate::squeezelite_h::STOPPED; +pub use crate::squeezelite_h::STREAMING_BUFFERING; +pub use crate::squeezelite_h::STREAMING_FILE; +pub use crate::squeezelite_h::STREAMING_HTTP; +pub use crate::squeezelite_h::STREAMING_WAIT; +pub use crate::squeezelite_h::TIMEOUT; +pub use crate::squeezelite_h::UNREACHABLE; +pub use crate::src::buffer::_buf_cont_read; +pub use crate::src::buffer::_buf_cont_write; +pub use crate::src::buffer::_buf_inc_readp; +pub use crate::src::buffer::_buf_inc_writep; +pub use crate::src::buffer::_buf_space; +pub use crate::src::decode::decode_newstream; +pub use crate::src::output::_checkfade; +pub use crate::src::utils::logprint; +pub use crate::src::utils::logtime; +use crate::stdlib::malloc; +pub use crate::stdlib::mpg123_enc_enum; +pub use crate::stdlib::mpg123_errors; +pub use crate::stdlib::mpg123_feature_set; +pub use crate::stdlib::mpg123_handle; +pub use crate::stdlib::mpg123_handle_struct; +pub use crate::stdlib::MPG123_BAD_ALIGN; +pub use crate::stdlib::MPG123_BAD_BAND; +pub use crate::stdlib::MPG123_BAD_BUFFER; +pub use crate::stdlib::MPG123_BAD_CHANNEL; +pub use crate::stdlib::MPG123_BAD_CUSTOM_IO; +pub use crate::stdlib::MPG123_BAD_DECODER; +pub use crate::stdlib::MPG123_BAD_DECODER_SETUP; +pub use crate::stdlib::MPG123_BAD_FILE; +pub use crate::stdlib::MPG123_BAD_HANDLE; +pub use crate::stdlib::MPG123_BAD_INDEX_PAR; +pub use crate::stdlib::MPG123_BAD_KEY; +pub use crate::stdlib::MPG123_BAD_OUTFORMAT; +pub use crate::stdlib::MPG123_BAD_PARAM; +pub use crate::stdlib::MPG123_BAD_PARS; +pub use crate::stdlib::MPG123_BAD_RATE; +pub use crate::stdlib::MPG123_BAD_RVA; +pub use crate::stdlib::MPG123_BAD_TYPES; +pub use crate::stdlib::MPG123_BAD_VALUE; +pub use crate::stdlib::MPG123_BAD_WHENCE; +pub use crate::stdlib::MPG123_DONE; +pub use crate::stdlib::MPG123_ENC_16; +pub use crate::stdlib::MPG123_ENC_24; +pub use crate::stdlib::MPG123_ENC_32; +pub use crate::stdlib::MPG123_ENC_8; +pub use crate::stdlib::MPG123_ENC_ALAW_8; +pub use crate::stdlib::MPG123_ENC_ANY; +pub use crate::stdlib::MPG123_ENC_FLOAT; +pub use crate::stdlib::MPG123_ENC_FLOAT_32; +pub use crate::stdlib::MPG123_ENC_FLOAT_64; +pub use crate::stdlib::MPG123_ENC_SIGNED; +pub use crate::stdlib::MPG123_ENC_SIGNED_16; +pub use crate::stdlib::MPG123_ENC_SIGNED_24; +pub use crate::stdlib::MPG123_ENC_SIGNED_32; +pub use crate::stdlib::MPG123_ENC_SIGNED_8; +pub use crate::stdlib::MPG123_ENC_ULAW_8; +pub use crate::stdlib::MPG123_ENC_UNSIGNED_16; +pub use crate::stdlib::MPG123_ENC_UNSIGNED_24; +pub use crate::stdlib::MPG123_ENC_UNSIGNED_32; +pub use crate::stdlib::MPG123_ENC_UNSIGNED_8; +pub use crate::stdlib::MPG123_ERR; +pub use crate::stdlib::MPG123_ERR_16TO8TABLE; +pub use crate::stdlib::MPG123_ERR_NULL; +pub use crate::stdlib::MPG123_ERR_READER; +pub use crate::stdlib::MPG123_FEATURE_ABI_UTF8OPEN; +pub use crate::stdlib::MPG123_FEATURE_DECODE_ACCURATE; +pub use crate::stdlib::MPG123_FEATURE_DECODE_DOWNSAMPLE; +pub use crate::stdlib::MPG123_FEATURE_DECODE_LAYER1; +pub use crate::stdlib::MPG123_FEATURE_DECODE_LAYER2; +pub use crate::stdlib::MPG123_FEATURE_DECODE_LAYER3; +pub use crate::stdlib::MPG123_FEATURE_DECODE_NTOM; +pub use crate::stdlib::MPG123_FEATURE_EQUALIZER; +pub use crate::stdlib::MPG123_FEATURE_INDEX; +pub use crate::stdlib::MPG123_FEATURE_OUTPUT_16BIT; +pub use crate::stdlib::MPG123_FEATURE_OUTPUT_32BIT; +pub use crate::stdlib::MPG123_FEATURE_OUTPUT_8BIT; +pub use crate::stdlib::MPG123_FEATURE_PARSE_ICY; +pub use crate::stdlib::MPG123_FEATURE_PARSE_ID3V2; +pub use crate::stdlib::MPG123_FEATURE_TIMEOUT_READ; +pub use crate::stdlib::MPG123_INDEX_FAIL; +pub use crate::stdlib::MPG123_INT_OVERFLOW; +pub use crate::stdlib::MPG123_LFS_OVERFLOW; +pub use crate::stdlib::MPG123_LSEEK_FAILED; +pub use crate::stdlib::MPG123_MISSING_FEATURE; +pub use crate::stdlib::MPG123_NEED_MORE; +pub use crate::stdlib::MPG123_NEW_FORMAT; +pub use crate::stdlib::MPG123_NOT_INITIALIZED; +pub use crate::stdlib::MPG123_NO_8BIT; +pub use crate::stdlib::MPG123_NO_BUFFERS; +pub use crate::stdlib::MPG123_NO_GAPLESS; +pub use crate::stdlib::MPG123_NO_INDEX; +pub use crate::stdlib::MPG123_NO_READER; +pub use crate::stdlib::MPG123_NO_RELSEEK; +pub use crate::stdlib::MPG123_NO_SEEK; +pub use crate::stdlib::MPG123_NO_SEEK_FROM_END; +pub use crate::stdlib::MPG123_NO_SPACE; +pub use crate::stdlib::MPG123_NO_TIMEOUT; +pub use crate::stdlib::MPG123_NULL_BUFFER; +pub use crate::stdlib::MPG123_NULL_POINTER; +pub use crate::stdlib::MPG123_OK; +pub use crate::stdlib::MPG123_OUT_OF_MEM; +pub use crate::stdlib::MPG123_OUT_OF_SYNC; +pub use crate::stdlib::MPG123_RESYNC_FAIL; + +use crate::stdlib::dlerror; +use crate::stdlib::dlopen; +use crate::stdlib::dlsym; +use crate::stdlib::pthread_mutex_lock; +use crate::stdlib::pthread_mutex_unlock; +extern "C" { + #[no_mangle] + pub static mut loglevel: crate::squeezelite_h::log_level; + #[no_mangle] + pub static mut streambuf: *mut crate::squeezelite_h::buffer; + #[no_mangle] + pub static mut outputbuf: *mut crate::squeezelite_h::buffer; + #[no_mangle] + pub static mut stream: crate::squeezelite_h::streamstate; + #[no_mangle] + pub static mut output: crate::squeezelite_h::outputstate; + #[no_mangle] + pub static mut decode: crate::squeezelite_h::decodestate; +} + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct mpg { + pub h: *mut crate::stdlib::mpg123_handle, + pub use16bit: bool, + pub mpg123_init: Option libc::c_int>, + pub mpg123_feature: + Option libc::c_int>, + pub mpg123_rates: Option< + unsafe extern "C" fn(_: *mut *const libc::c_long, _: *mut crate::stddef_h::size_t) -> (), + >, + pub mpg123_format_none: + Option libc::c_int>, + pub mpg123_format: Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::mpg123_handle, + _: libc::c_long, + _: libc::c_int, + _: libc::c_int, + ) -> libc::c_int, + >, + pub mpg123_new: Option< + unsafe extern "C" fn( + _: *const libc::c_char, + _: *mut libc::c_int, + ) -> *mut crate::stdlib::mpg123_handle, + >, + pub mpg123_delete: Option ()>, + pub mpg123_open_feed: + Option libc::c_int>, + pub mpg123_decode: Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::mpg123_handle, + _: *const libc::c_uchar, + _: crate::stddef_h::size_t, + _: *mut libc::c_uchar, + _: crate::stddef_h::size_t, + _: *mut crate::stddef_h::size_t, + ) -> libc::c_int, + >, + pub mpg123_getformat: Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::mpg123_handle, + _: *mut libc::c_long, + _: *mut libc::c_int, + _: *mut libc::c_int, + ) -> libc::c_int, + >, + pub mpg123_plain_strerror: Option *const libc::c_char>, +} + +static mut m: *mut mpg = 0 as *const mpg as *mut mpg; + +unsafe extern "C" fn mpg_decode() -> crate::squeezelite_h::decode_state { + let mut bytes: crate::stddef_h::size_t = 0; + let mut space: crate::stddef_h::size_t = 0; + let mut size: crate::stddef_h::size_t = 0; + let mut ret: libc::c_int = 0; + let mut write_buf = 0 as *mut crate::squeezelite_h::u8_t; + crate::stdlib::pthread_mutex_lock(&mut (*streambuf).mutex); + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + bytes = if crate::squeezelite_h::_buf_used(streambuf) + < crate::src::buffer::_buf_cont_read(streambuf) + { + crate::squeezelite_h::_buf_used(streambuf) + } else { + crate::src::buffer::_buf_cont_read(streambuf) + } as crate::stddef_h::size_t; + space = if crate::src::buffer::_buf_space(outputbuf) + < crate::src::buffer::_buf_cont_write(outputbuf) + { + crate::src::buffer::_buf_space(outputbuf) + } else { + crate::src::buffer::_buf_cont_write(outputbuf) + } as crate::stddef_h::size_t; + write_buf = (*outputbuf).writep; + bytes = if bytes < 512 as libc::c_int as libc::c_ulong { + bytes + } else { + 512 as libc::c_int as libc::c_ulong + }; + space = if space < (32 as libc::c_int * 1024 as libc::c_int) as libc::c_ulong { + space + } else { + (32 as libc::c_int * 1024 as libc::c_int) as libc::c_ulong + }; + if (*m).use16bit { + space = space + .wrapping_div(8 as libc::c_int as libc::c_ulong) + .wrapping_mul(4 as libc::c_int as libc::c_ulong) + } + // only get the new stream information on first call so we can reset decode.direct appropriately + if decode.new_stream { + space = 0 as libc::c_int as crate::stddef_h::size_t + } + ret = (*m).mpg123_decode.expect("non-null function pointer")( + (*m).h, + (*streambuf).readp, + bytes, + write_buf, + space, + &mut size, + ); + if ret == crate::stdlib::MPG123_NEW_FORMAT as libc::c_int { + if decode.new_stream { + let mut rate: libc::c_long = 0; + let mut channels: libc::c_int = 0; + let mut enc: libc::c_int = 0; + (*m).mpg123_getformat.expect("non-null function pointer")( + (*m).h, + &mut rate, + &mut channels, + &mut enc, + ); + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d setting track_start\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"mpg_decode\x00")) + .as_ptr(), + 125 as libc::c_int, + ); + } + output.next_sample_rate = crate::src::decode::decode_newstream( + rate as libc::c_uint, + output.supported_rates.as_mut_ptr(), + ); + output.track_start = (*outputbuf).writep; + if output.fade_mode as u64 != 0 { + crate::src::output::_checkfade(1 as libc::c_int != 0); + } + decode.new_stream = 0 as libc::c_int != 0 + } else if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d format change mid stream - not supported\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"mpg_decode\x00")) + .as_ptr(), + 135 as libc::c_int, + ); + } + } + // expand 16bit output to 32bit samples + if (*m).use16bit { + let mut iptr = 0 as *mut crate::squeezelite_h::s16_t; + let mut optr = 0 as *mut crate::squeezelite_h::s32_t; + let mut count = size.wrapping_div(2 as libc::c_int as libc::c_ulong); + size = count.wrapping_mul(4 as libc::c_int as libc::c_ulong); + iptr = (write_buf as *mut crate::squeezelite_h::s16_t).offset(count as isize); + optr = (write_buf as *mut crate::squeezelite_h::s32_t).offset(count as isize); + loop { + let fresh0 = count; + count = count.wrapping_sub(1); + if !(fresh0 != 0) { + break; + } + iptr = iptr.offset(-1); + optr = optr.offset(-1); + *optr = (*iptr as libc::c_int) << 16 as libc::c_int + } + } + crate::src::buffer::_buf_inc_readp(streambuf, bytes as libc::c_uint); + crate::src::buffer::_buf_inc_writep(outputbuf, size as libc::c_uint); + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + if loglevel as libc::c_uint >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d write %u frames\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"mpg_decode\x00")).as_ptr(), + 163 as libc::c_int, + size.wrapping_div(8 as libc::c_int as libc::c_ulong), + ); + } + if ret == crate::stdlib::MPG123_DONE as libc::c_int + || bytes == 0 as libc::c_int as libc::c_ulong + && size == 0 as libc::c_int as libc::c_ulong + && stream.state as libc::c_uint + <= crate::squeezelite_h::DISCONNECT as libc::c_int as libc::c_uint + { + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d stream complete\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"mpg_decode\x00")) + .as_ptr(), + 167 as libc::c_int, + ); + } + return crate::squeezelite_h::DECODE_COMPLETE; + } + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + if ret == crate::stdlib::MPG123_ERR as libc::c_int { + if loglevel as libc::c_uint >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d Error\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"mpg_decode\x00")) + .as_ptr(), + 174 as libc::c_int, + ); + } + return crate::squeezelite_h::DECODE_COMPLETE; + } + // OK and NEED_MORE keep running + return crate::squeezelite_h::DECODE_RUNNING; +} + +unsafe extern "C" fn mpg_open( + mut size: crate::squeezelite_h::u8_t, + mut rate: crate::squeezelite_h::u8_t, + mut chan: crate::squeezelite_h::u8_t, + mut endianness: crate::squeezelite_h::u8_t, +) { + let mut err: libc::c_int = 0; + let mut list = 0 as *const libc::c_long; + let mut count: crate::stddef_h::size_t = 0; + let mut i: crate::stddef_h::size_t = 0; + if !(*m).h.is_null() { + (*m).mpg123_delete.expect("non-null function pointer")((*m).h); + } + (*m).h = + (*m).mpg123_new.expect("non-null function pointer")(0 as *const libc::c_char, &mut err); + if (*m).h.is_null() { + if loglevel as libc::c_uint >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d new error: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"mpg_open\x00")).as_ptr(), + 194 as libc::c_int, + (*m).mpg123_plain_strerror + .expect("non-null function pointer")(err), + ); + } + } + // restrict output to 32bit or 16bit signed 2 channel based on library capability + (*m).mpg123_rates.expect("non-null function pointer")(&mut list, &mut count); + (*m).mpg123_format_none.expect("non-null function pointer")((*m).h); + i = 0 as libc::c_int as crate::stddef_h::size_t; + while i < count { + (*m).mpg123_format.expect("non-null function pointer")( + (*m).h, + *list.offset(i as isize), + 2 as libc::c_int, + if (*m).use16bit as libc::c_int != 0 { + crate::stdlib::MPG123_ENC_SIGNED_16 as libc::c_int + } else { + crate::stdlib::MPG123_ENC_SIGNED_32 as libc::c_int + }, + ); + i = i.wrapping_add(1) + } + err = (*m).mpg123_open_feed.expect("non-null function pointer")((*m).h); + if err != 0 { + if loglevel as libc::c_uint >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d open feed error: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"mpg_open\x00")).as_ptr(), + 207 as libc::c_int, + (*m).mpg123_plain_strerror + .expect("non-null function pointer")(err), + ); + } + }; +} + +unsafe extern "C" fn mpg_close() { + (*m).mpg123_delete.expect("non-null function pointer")((*m).h); + (*m).h = 0 as *mut crate::stdlib::mpg123_handle; +} + +unsafe extern "C" fn load_mpg() -> bool { + let mut handle = crate::stdlib::dlopen( + b"libmpg123.so.0\x00" as *const u8 as *const libc::c_char, + 0x2 as libc::c_int, + ); + let mut err = 0 as *mut libc::c_char; + if handle.is_null() { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d dlerror: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"load_mpg\x00")).as_ptr(), + 222 as libc::c_int, + crate::stdlib::dlerror(), + ); + } + return 0 as libc::c_int != 0; + } + (*m).mpg123_init = ::std::mem::transmute::< + *mut libc::c_void, + Option libc::c_int>, + >(crate::stdlib::dlsym( + handle, + b"mpg123_init\x00" as *const u8 as *const libc::c_char, + )); + (*m).mpg123_feature = ::std::mem::transmute::< + *mut libc::c_void, + Option libc::c_int>, + >(crate::stdlib::dlsym( + handle, + b"mpg123_feature\x00" as *const u8 as *const libc::c_char, + )); + (*m).mpg123_rates = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: *mut *const libc::c_long, + _: *mut crate::stddef_h::size_t, + ) -> (), + >, + >(crate::stdlib::dlsym( + handle, + b"mpg123_rates\x00" as *const u8 as *const libc::c_char, + )); + (*m).mpg123_format_none = ::std::mem::transmute::< + *mut libc::c_void, + Option libc::c_int>, + >(crate::stdlib::dlsym( + handle, + b"mpg123_format_none\x00" as *const u8 as *const libc::c_char, + )); + (*m).mpg123_format = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::mpg123_handle, + _: libc::c_long, + _: libc::c_int, + _: libc::c_int, + ) -> libc::c_int, + >, + >(crate::stdlib::dlsym( + handle, + b"mpg123_format\x00" as *const u8 as *const libc::c_char, + )); + (*m).mpg123_new = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: *const libc::c_char, + _: *mut libc::c_int, + ) -> *mut crate::stdlib::mpg123_handle, + >, + >(crate::stdlib::dlsym( + handle, + b"mpg123_new\x00" as *const u8 as *const libc::c_char, + )); + (*m).mpg123_delete = ::std::mem::transmute::< + *mut libc::c_void, + Option ()>, + >(crate::stdlib::dlsym( + handle, + b"mpg123_delete\x00" as *const u8 as *const libc::c_char, + )); + (*m).mpg123_open_feed = ::std::mem::transmute::< + *mut libc::c_void, + Option libc::c_int>, + >(crate::stdlib::dlsym( + handle, + b"mpg123_open_feed\x00" as *const u8 as *const libc::c_char, + )); + (*m).mpg123_decode = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::mpg123_handle, + _: *const libc::c_uchar, + _: crate::stddef_h::size_t, + _: *mut libc::c_uchar, + _: crate::stddef_h::size_t, + _: *mut crate::stddef_h::size_t, + ) -> libc::c_int, + >, + >(crate::stdlib::dlsym( + handle, + b"mpg123_decode\x00" as *const u8 as *const libc::c_char, + )); + (*m).mpg123_getformat = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::mpg123_handle, + _: *mut libc::c_long, + _: *mut libc::c_int, + _: *mut libc::c_int, + ) -> libc::c_int, + >, + >(crate::stdlib::dlsym( + handle, + b"mpg123_getformat\x00" as *const u8 as *const libc::c_char, + )); + (*m).mpg123_plain_strerror = ::std::mem::transmute::< + *mut libc::c_void, + Option *const libc::c_char>, + >(crate::stdlib::dlsym( + handle, + b"mpg123_plain_strerror\x00" as *const u8 as *const libc::c_char, + )); + err = crate::stdlib::dlerror(); + if !err.is_null() { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d dlerror: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"load_mpg\x00")).as_ptr(), + 239 as libc::c_int, + err, + ); + } + return 0 as libc::c_int != 0; + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d loaded libmpg123.so.0\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"load_mpg\x00")).as_ptr(), + 243 as libc::c_int, + ); + } + return 1 as libc::c_int != 0; +} +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Additions (c) Paul Hermann, 2015-2017 under the same license terms + * -Control of Raspberry pi GPIO for amplifier power + * -Launch script on power status change from LMS + */ +// make may define: PORTAUDIO, SELFPIPE, RESAMPLE, RESAMPLE_MP, VISEXPORT, GPIO, IR, DSD, LINKALL to influence build +// build detection +// dynamically loaded libraries at run time +// !LINKALL +// config options +// do not reduce as icy-meta max is 4080 +/* SUN */ +/* SUN */ +// printf/scanf formats for u64_t +// logging +// utils.c (non logging) +// buffer.c +// _* called with mutex locked +// slimproto.c +// stream.c +// decode.c +// output.c output_alsa.c output_pa.c output_pack.c +// frames played at the point delay is measured +// ordered largest first so [0] is max_rate +// set in decode thread +// set in decode thread +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// _* called with mutex locked +// output_alsa.c +// output_pa.c +// output_pulse.c +// output_stdout.c +// output_pack.c +// output_vis.c +// dop.c +// codecs +#[no_mangle] + +pub unsafe extern "C" fn register_mpg() -> *mut crate::squeezelite_h::codec { + static mut ret: crate::squeezelite_h::codec = unsafe { + { + let mut init = crate::squeezelite_h::codec { + id: 'm' as i32 as libc::c_char, + types: b"mp3\x00" as *const u8 as *const libc::c_char as *mut libc::c_char, + min_read_bytes: 512 as libc::c_int as libc::c_uint, + min_space: (32 as libc::c_int * 1024 as libc::c_int) as libc::c_uint, + open: Some( + mpg_open + as unsafe extern "C" fn( + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + ) -> (), + ), + close: Some(mpg_close as unsafe extern "C" fn() -> ()), + decode: Some( + mpg_decode as unsafe extern "C" fn() -> crate::squeezelite_h::decode_state, + ), + }; + init + } + }; + m = crate::stdlib::malloc(::std::mem::size_of::() as libc::c_ulong) as *mut mpg; + if m.is_null() { + return 0 as *mut crate::squeezelite_h::codec; + } + (*m).h = 0 as *mut crate::stdlib::mpg123_handle; + if !load_mpg() { + return 0 as *mut crate::squeezelite_h::codec; + } + (*m).mpg123_init.expect("non-null function pointer")(); + (*m).use16bit = (*m).mpg123_feature.expect("non-null function pointer")( + crate::stdlib::MPG123_FEATURE_OUTPUT_32BIT, + ) != 0; + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d using mpg to decode mp3\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"register_mpg\x00")) + .as_ptr(), + 275 as libc::c_int, + ); + } + return &mut ret; +} diff --git a/src/output.rs b/src/output.rs new file mode 100644 index 0000000..099636e --- /dev/null +++ b/src/output.rs @@ -0,0 +1,1152 @@ +use ::libc; + +pub use crate::stddef_h::size_t; +pub use crate::stdlib::__int32_t; +pub use crate::stdlib::__uint32_t; +pub use crate::stdlib::__uint8_t; +pub use crate::stdlib::int32_t; + +pub use crate::squeezelite_h::_buf_used; +pub use crate::squeezelite_h::buffer; +pub use crate::squeezelite_h::fade_dir; +pub use crate::squeezelite_h::fade_mode; +pub use crate::squeezelite_h::fade_state; +pub use crate::squeezelite_h::frames_t; +pub use crate::squeezelite_h::gain; +pub use crate::squeezelite_h::lDEBUG; +pub use crate::squeezelite_h::lERROR; +pub use crate::squeezelite_h::lINFO; +pub use crate::squeezelite_h::lSDEBUG; +pub use crate::squeezelite_h::lWARN; +pub use crate::squeezelite_h::log_level; +pub use crate::squeezelite_h::output_format; +pub use crate::squeezelite_h::output_state; +pub use crate::squeezelite_h::outputstate; +pub use crate::squeezelite_h::s32_t; +pub use crate::squeezelite_h::to_gain; +pub use crate::squeezelite_h::u32_t; +pub use crate::squeezelite_h::u8_t; +pub use crate::squeezelite_h::C2RustUnnamed_1; +pub use crate::squeezelite_h::FADE_ACTIVE; +pub use crate::squeezelite_h::FADE_CROSS; +pub use crate::squeezelite_h::FADE_CROSSFADE; +pub use crate::squeezelite_h::FADE_DOWN; +pub use crate::squeezelite_h::FADE_DUE; +pub use crate::squeezelite_h::FADE_IN; +pub use crate::squeezelite_h::FADE_INACTIVE; +pub use crate::squeezelite_h::FADE_INOUT; +pub use crate::squeezelite_h::FADE_NONE; +pub use crate::squeezelite_h::FADE_OUT; +pub use crate::squeezelite_h::FADE_UP; +pub use crate::squeezelite_h::OUTPUT_BUFFER; +pub use crate::squeezelite_h::OUTPUT_OFF; +pub use crate::squeezelite_h::OUTPUT_PAUSE_FRAMES; +pub use crate::squeezelite_h::OUTPUT_RUNNING; +pub use crate::squeezelite_h::OUTPUT_SKIP_FRAMES; +pub use crate::squeezelite_h::OUTPUT_START_AT; +pub use crate::squeezelite_h::OUTPUT_STOPPED; +pub use crate::squeezelite_h::S16_LE; +pub use crate::squeezelite_h::S24_3LE; +pub use crate::squeezelite_h::S24_LE; +pub use crate::squeezelite_h::S32_LE; +pub use crate::src::buffer::_buf_cont_read; +pub use crate::src::buffer::_buf_inc_readp; +pub use crate::src::buffer::_buf_resize; +pub use crate::src::buffer::buf_destroy; +pub use crate::src::buffer::buf_flush; +pub use crate::src::buffer::buf_init; +pub use crate::src::output_alsa::test_open; +pub use crate::src::slimproto::wake_controller; +pub use crate::src::utils::gettime_ms; +pub use crate::src::utils::logprint; +pub use crate::src::utils::logtime; +pub use crate::src::utils::touch_memory; +pub use crate::stdlib::__pthread_internal_list; +pub use crate::stdlib::__pthread_list_t; +pub use crate::stdlib::__pthread_mutex_s; +pub use crate::stdlib::pthread_mutex_t; +use crate::stdlib::sprintf; +pub use crate::stdlib::u_int32_t; +pub use crate::stdlib::u_int8_t; + +use crate::stdlib::exit; +use crate::stdlib::free; +use crate::stdlib::malloc; +use crate::stdlib::memset; +use crate::stdlib::pthread_mutex_lock; +use crate::stdlib::pthread_mutex_unlock; +use crate::stdlib::strcat; +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +// Common output function + +static mut loglevel: crate::squeezelite_h::log_level = crate::squeezelite_h::lERROR; +#[no_mangle] + +pub static mut output: crate::squeezelite_h::outputstate = crate::squeezelite_h::outputstate { + state: crate::squeezelite_h::OUTPUT_STOPPED, + format: crate::squeezelite_h::S32_LE, + device: 0 as *const libc::c_char, + buffer: 0, + period: 0, + track_started: false, + write_cb: None, + start_frames: 0, + frames_played: 0, + frames_played_dmp: 0, + current_sample_rate: 0, + supported_rates: [0; 18], + default_sample_rate: 0, + error_opening: false, + device_frames: 0, + updated: 0, + track_start_time: 0, + current_replay_gain: 0, + c2rust_unnamed: crate::squeezelite_h::C2RustUnnamed_1 { pause_frames: 0 }, + next_sample_rate: 0, + track_start: 0 as *const crate::squeezelite_h::u8_t as *mut crate::squeezelite_h::u8_t, + gainL: 0, + gainR: 0, + invert: false, + next_replay_gain: 0, + threshold: 0, + fade: crate::squeezelite_h::FADE_INACTIVE, + fade_start: 0 as *const crate::squeezelite_h::u8_t as *mut crate::squeezelite_h::u8_t, + fade_end: 0 as *const crate::squeezelite_h::u8_t as *mut crate::squeezelite_h::u8_t, + fade_dir: 0 as crate::squeezelite_h::fade_dir, + fade_mode: crate::squeezelite_h::FADE_NONE, + fade_secs: 0, + rate_delay: 0, + delay_active: false, + stop_time: 0, + idle_to: 0, +}; + +static mut buf: crate::squeezelite_h::buffer = crate::squeezelite_h::buffer { + buf: 0 as *const crate::squeezelite_h::u8_t as *mut crate::squeezelite_h::u8_t, + readp: 0 as *const crate::squeezelite_h::u8_t as *mut crate::squeezelite_h::u8_t, + writep: 0 as *const crate::squeezelite_h::u8_t as *mut crate::squeezelite_h::u8_t, + wrap: 0 as *const crate::squeezelite_h::u8_t as *mut crate::squeezelite_h::u8_t, + size: 0, + base_size: 0, + mutex: crate::stdlib::pthread_mutex_t { + __data: crate::stdlib::__pthread_mutex_s { + __lock: 0, + __count: 0, + __owner: 0, + __nusers: 0, + __kind: 0, + __spins: 0, + __elision: 0, + __list: crate::stdlib::__pthread_list_t { + __prev: 0 as *const crate::stdlib::__pthread_internal_list + as *mut crate::stdlib::__pthread_internal_list, + __next: 0 as *const crate::stdlib::__pthread_internal_list + as *mut crate::stdlib::__pthread_internal_list, + }, + }, + }, +}; +#[no_mangle] + +pub static mut outputbuf: *mut crate::squeezelite_h::buffer = + unsafe { &buf as *const crate::squeezelite_h::buffer as *mut crate::squeezelite_h::buffer }; +#[no_mangle] + +pub static mut silencebuf: *mut crate::squeezelite_h::u8_t = + 0 as *const crate::squeezelite_h::u8_t as *mut crate::squeezelite_h::u8_t; +#[no_mangle] + +pub static mut user_rates: bool = 0 as libc::c_int != 0; +// functions starting _* are called with mutex locked +#[no_mangle] + +pub unsafe extern "C" fn _output_frames( + mut avail: crate::squeezelite_h::frames_t, +) -> crate::squeezelite_h::frames_t { + let mut frames: crate::squeezelite_h::frames_t = 0; + let mut size: crate::squeezelite_h::frames_t = 0; + let mut silence: bool = false; + let mut cross_gain_in = 0 as libc::c_int; + let mut cross_gain_out = 0 as libc::c_int; + let mut cross_ptr = 0 as *mut crate::squeezelite_h::s32_t; + let mut gainL = if output.current_replay_gain != 0 { + crate::squeezelite_h::gain( + output.gainL as crate::squeezelite_h::s32_t, + output.current_replay_gain as crate::squeezelite_h::s32_t, + ) as libc::c_uint + } else { + output.gainL + } as crate::squeezelite_h::s32_t; + let mut gainR = if output.current_replay_gain != 0 { + crate::squeezelite_h::gain( + output.gainR as crate::squeezelite_h::s32_t, + output.current_replay_gain as crate::squeezelite_h::s32_t, + ) as libc::c_uint + } else { + output.gainR + } as crate::squeezelite_h::s32_t; + if output.invert { + gainL = -gainL; + gainR = -gainR + } + frames = + crate::squeezelite_h::_buf_used(outputbuf).wrapping_div(8 as libc::c_int as libc::c_uint); + silence = 0 as libc::c_int != 0; + // start when threshold met + if output.state as libc::c_int == crate::squeezelite_h::OUTPUT_BUFFER as libc::c_int + && frames + > output + .threshold + .wrapping_mul(output.next_sample_rate) + .wrapping_div(10 as libc::c_int as libc::c_uint) + && frames > output.start_frames + { + output.state = crate::squeezelite_h::OUTPUT_RUNNING; + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d start buffer frames: %u\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>(b"_output_frames\x00")) + .as_ptr(), + 64 as libc::c_int, + frames, + ); + } + crate::src::slimproto::wake_controller(); + } + // skip ahead - consume outputbuf but play nothing + if output.state as libc::c_int == crate::squeezelite_h::OUTPUT_SKIP_FRAMES as libc::c_int { + if frames > 0 as libc::c_int as libc::c_uint { + let mut skip = if frames < output.c2rust_unnamed.skip_frames { + frames + } else { + output.c2rust_unnamed.skip_frames + }; + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d skip %u of %u frames\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>( + b"_output_frames\x00", + )) + .as_ptr(), + 72 as libc::c_int, + skip, + output.c2rust_unnamed.skip_frames, + ); + } + frames = (frames as libc::c_uint).wrapping_sub(skip) as crate::squeezelite_h::frames_t + as crate::squeezelite_h::frames_t; + output.frames_played = output.frames_played.wrapping_add(skip); + while skip > 0 as libc::c_int as libc::c_uint { + let mut cont_frames = if skip + < crate::src::buffer::_buf_cont_read(outputbuf) + .wrapping_div(8 as libc::c_int as libc::c_uint) + { + skip + } else { + crate::src::buffer::_buf_cont_read(outputbuf) + .wrapping_div(8 as libc::c_int as libc::c_uint) + }; + skip = (skip as libc::c_uint).wrapping_sub(cont_frames) + as crate::squeezelite_h::frames_t + as crate::squeezelite_h::frames_t; + crate::src::buffer::_buf_inc_readp( + outputbuf, + cont_frames.wrapping_mul(8 as libc::c_int as libc::c_uint), + ); + } + } + output.state = crate::squeezelite_h::OUTPUT_RUNNING + } + // pause frames - play silence for required frames + if output.state as libc::c_int == crate::squeezelite_h::OUTPUT_PAUSE_FRAMES as libc::c_int { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d pause %u frames\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>(b"_output_frames\x00")) + .as_ptr(), + 86 as libc::c_int, + output.c2rust_unnamed.pause_frames, + ); + } + if output.c2rust_unnamed.pause_frames == 0 as libc::c_int as libc::c_uint { + output.state = crate::squeezelite_h::OUTPUT_RUNNING + } else { + silence = 1 as libc::c_int != 0; + frames = if avail < output.c2rust_unnamed.pause_frames { + avail + } else { + output.c2rust_unnamed.pause_frames + }; + frames = if frames < 2048 as libc::c_int as libc::c_uint { + frames + } else { + 2048 as libc::c_int as libc::c_uint + }; + output.c2rust_unnamed.pause_frames = + (output.c2rust_unnamed.pause_frames as libc::c_uint).wrapping_sub(frames) + as crate::squeezelite_h::u32_t as crate::squeezelite_h::u32_t + } + } + // start at - play silence until jiffies reached + if output.state as libc::c_int == crate::squeezelite_h::OUTPUT_START_AT as libc::c_int { + let mut now = crate::src::utils::gettime_ms(); + if now >= output.c2rust_unnamed.start_at + || output.c2rust_unnamed.start_at + > now.wrapping_add(10000 as libc::c_int as libc::c_uint) + { + output.state = crate::squeezelite_h::OUTPUT_RUNNING + } else { + let mut delta_frames = output + .c2rust_unnamed + .start_at + .wrapping_sub(now) + .wrapping_mul(output.current_sample_rate) + .wrapping_div(1000 as libc::c_int as libc::c_uint); + silence = 1 as libc::c_int != 0; + frames = if avail < delta_frames { + avail + } else { + delta_frames + }; + frames = if frames < 2048 as libc::c_int as libc::c_uint { + frames + } else { + 2048 as libc::c_int as libc::c_uint + } + } + } + // play silence if buffering or no frames + if output.state as libc::c_int <= crate::squeezelite_h::OUTPUT_BUFFER as libc::c_int + || frames == 0 as libc::c_int as libc::c_uint + { + silence = 1 as libc::c_int != 0; + frames = if avail < 2048 as libc::c_int as libc::c_uint { + avail + } else { + 2048 as libc::c_int as libc::c_uint + } + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d avail: %d frames: %d silence: %d\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>(b"_output_frames\x00")) + .as_ptr(), + 116 as libc::c_int, + avail, + frames, + silence as libc::c_int, + ); + } + frames = if frames < avail { frames } else { avail }; + size = frames; + while size > 0 as libc::c_int as libc::c_uint { + let mut out_frames: crate::squeezelite_h::frames_t = 0; + let mut cont_frames_0 = crate::src::buffer::_buf_cont_read(outputbuf) + .wrapping_div(8 as libc::c_int as libc::c_uint); + let mut wrote: libc::c_int = 0; + if !output.track_start.is_null() && !silence { + if output.track_start == (*outputbuf).readp { + let mut delay = 0 as libc::c_int as libc::c_uint; + if output.current_sample_rate != output.next_sample_rate { + delay = output.rate_delay + } + frames = (frames as libc::c_uint).wrapping_sub(size) + as crate::squeezelite_h::frames_t + as crate::squeezelite_h::frames_t; + // add silence delay in two halves, before and after track start on rate or pcm-dop change + if delay != 0 { + output.state = crate::squeezelite_h::OUTPUT_PAUSE_FRAMES; // first delay - don't process track start + if !output.delay_active { + output.c2rust_unnamed.pause_frames = output + .current_sample_rate + .wrapping_mul(delay) + .wrapping_div(2000 as libc::c_int as libc::c_uint); + output.delay_active = 1 as libc::c_int != 0; + break; + } else { + output.c2rust_unnamed.pause_frames = output + .next_sample_rate + .wrapping_mul(delay) + .wrapping_div(2000 as libc::c_int as libc::c_uint); + output.delay_active = 0 as libc::c_int != 0 + // second delay - process track start + } + } + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d track start sample rate: %u replay_gain: %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>( + b"_output_frames\x00", + )) + .as_ptr(), + 149 as libc::c_int, + output.next_sample_rate, + output.next_replay_gain, + ); + } + output.frames_played = 0 as libc::c_int as libc::c_uint; + output.track_started = 1 as libc::c_int != 0; + output.track_start_time = crate::src::utils::gettime_ms(); + output.current_sample_rate = output.next_sample_rate; + if output.fade as libc::c_uint + == crate::squeezelite_h::FADE_INACTIVE as libc::c_int as libc::c_uint + || output.fade_mode as libc::c_uint + != crate::squeezelite_h::FADE_CROSSFADE as libc::c_int as libc::c_uint + { + output.current_replay_gain = output.next_replay_gain + } + output.track_start = 0 as *mut crate::squeezelite_h::u8_t; + break; + } else if output.track_start > (*outputbuf).readp { + // reduce cont_frames so we find the next track start at beginning of next chunk + cont_frames_0 = if (cont_frames_0 as libc::c_long) + < output.track_start.wrapping_offset_from((*outputbuf).readp) as libc::c_long + / 8 as libc::c_int as libc::c_long + { + cont_frames_0 as libc::c_long + } else { + (output.track_start.wrapping_offset_from((*outputbuf).readp) as libc::c_long) + / 8 as libc::c_int as libc::c_long + } as crate::squeezelite_h::frames_t + } + } + if output.fade as libc::c_uint != 0 && !silence { + if output.fade as libc::c_uint + == crate::squeezelite_h::FADE_DUE as libc::c_int as libc::c_uint + { + if output.fade_start == (*outputbuf).readp { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d fade start reached\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>( + b"_output_frames\x00", + )) + .as_ptr(), + 177 as libc::c_int, + ); + } + output.fade = crate::squeezelite_h::FADE_ACTIVE + } else if output.fade_start > (*outputbuf).readp { + cont_frames_0 = if (cont_frames_0 as libc::c_long) + < output.fade_start.wrapping_offset_from((*outputbuf).readp) as libc::c_long + / 8 as libc::c_int as libc::c_long + { + cont_frames_0 as libc::c_long + } else { + (output.fade_start.wrapping_offset_from((*outputbuf).readp) as libc::c_long) + / 8 as libc::c_int as libc::c_long + } as crate::squeezelite_h::frames_t + } + } + if output.fade as libc::c_uint + == crate::squeezelite_h::FADE_ACTIVE as libc::c_int as libc::c_uint + { + // find position within fade + let mut cur_f = if (*outputbuf).readp >= output.fade_start { + ((*outputbuf).readp.wrapping_offset_from(output.fade_start) as libc::c_long) + / 8 as libc::c_int as libc::c_long + } else { + ((*outputbuf) + .readp + .offset((*outputbuf).size as isize) + .wrapping_offset_from(output.fade_start) + as libc::c_long) + / 8 as libc::c_int as libc::c_long + } as crate::squeezelite_h::frames_t; + let mut dur_f = if output.fade_end >= output.fade_start { + (output.fade_end.wrapping_offset_from(output.fade_start) as libc::c_long) + / 8 as libc::c_int as libc::c_long + } else { + (output + .fade_end + .offset((*outputbuf).size as isize) + .wrapping_offset_from(output.fade_start) + as libc::c_long) + / 8 as libc::c_int as libc::c_long + } as crate::squeezelite_h::frames_t; + if cur_f >= dur_f { + if output.fade_mode as libc::c_uint + == crate::squeezelite_h::FADE_INOUT as libc::c_int as libc::c_uint + && output.fade_dir as libc::c_uint + == crate::squeezelite_h::FADE_DOWN as libc::c_int as libc::c_uint + { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d fade down complete, starting fade up\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>( + b"_output_frames\x00", + )) + .as_ptr(), + 191 as libc::c_int, + ); + } + output.fade_dir = crate::squeezelite_h::FADE_UP; + output.fade_start = (*outputbuf).readp; + output.fade_end = (*outputbuf) + .readp + .offset(dur_f.wrapping_mul(8 as libc::c_int as libc::c_uint) as isize); + if output.fade_end >= (*outputbuf).wrap { + output.fade_end = output.fade_end.offset(-((*outputbuf).size as isize)) + } + cur_f = 0 as libc::c_int as crate::squeezelite_h::frames_t + } else if output.fade_mode as libc::c_uint + == crate::squeezelite_h::FADE_CROSSFADE as libc::c_int as libc::c_uint + { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d crossfade complete\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>( + b"_output_frames\x00", + )) + .as_ptr(), + 200 as libc::c_int, + ); + } + if crate::squeezelite_h::_buf_used(outputbuf) + >= dur_f.wrapping_mul(8 as libc::c_int as libc::c_uint) + { + crate::src::buffer::_buf_inc_readp( + outputbuf, + dur_f.wrapping_mul(8 as libc::c_int as libc::c_uint), + ); + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d skipped crossfaded start\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>( + b"_output_frames\x00", + )) + .as_ptr(), + 203 as libc::c_int, + ); + } + } else if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d unable to skip crossfaded start\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>( + b"_output_frames\x00", + )) + .as_ptr(), + 205 as libc::c_int, + ); + } + output.fade = crate::squeezelite_h::FADE_INACTIVE; + output.current_replay_gain = output.next_replay_gain + } else { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d fade complete\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>( + b"_output_frames\x00", + )) + .as_ptr(), + 210 as libc::c_int, + ); + } + output.fade = crate::squeezelite_h::FADE_INACTIVE + } + } + // if fade in progress set fade gain, ensure cont_frames reduced so we get to end of fade at start of chunk + if output.fade as u64 != 0 { + if output.fade_end > (*outputbuf).readp { + cont_frames_0 = if (cont_frames_0 as libc::c_long) + < output.fade_end.wrapping_offset_from((*outputbuf).readp) + as libc::c_long + / 8 as libc::c_int as libc::c_long + { + cont_frames_0 as libc::c_long + } else { + (output.fade_end.wrapping_offset_from((*outputbuf).readp) + as libc::c_long) + / 8 as libc::c_int as libc::c_long + } as crate::squeezelite_h::frames_t + } + if output.fade_dir as libc::c_uint + == crate::squeezelite_h::FADE_UP as libc::c_int as libc::c_uint + || output.fade_dir as libc::c_uint + == crate::squeezelite_h::FADE_DOWN as libc::c_int as libc::c_uint + { + // fade in, in-out, out handled via altering standard gain + let mut fade_gain: crate::squeezelite_h::s32_t = 0; + if output.fade_dir as libc::c_uint + == crate::squeezelite_h::FADE_DOWN as libc::c_int as libc::c_uint + { + cur_f = dur_f.wrapping_sub(cur_f) + } + fade_gain = crate::squeezelite_h::to_gain( + cur_f as libc::c_float / dur_f as libc::c_float, + ); + gainL = crate::squeezelite_h::gain(gainL, fade_gain); + gainR = crate::squeezelite_h::gain(gainR, fade_gain); + if output.invert { + gainL = -gainL; + gainR = -gainR + } + } + if output.fade_dir as libc::c_uint + == crate::squeezelite_h::FADE_CROSS as libc::c_int as libc::c_uint + { + // cross fade requires special treatment - performed later based on these values + // support different replay gain for old and new track by retaining old value until crossfade completes + if crate::squeezelite_h::_buf_used(outputbuf) + .wrapping_div(8 as libc::c_int as libc::c_uint) + > dur_f.wrapping_add(size) + { + cross_gain_in = crate::squeezelite_h::to_gain( + cur_f as libc::c_float / dur_f as libc::c_float, + ); + cross_gain_out = 0x10000 as libc::c_int - cross_gain_in; + if output.current_replay_gain != 0 { + cross_gain_out = crate::squeezelite_h::gain( + cross_gain_out, + output.current_replay_gain as crate::squeezelite_h::s32_t, + ) + } + if output.next_replay_gain != 0 { + cross_gain_in = crate::squeezelite_h::gain( + cross_gain_in, + output.next_replay_gain as crate::squeezelite_h::s32_t, + ) + } + gainL = output.gainL as crate::squeezelite_h::s32_t; + gainR = output.gainR as crate::squeezelite_h::s32_t; + if output.invert { + gainL = -gainL; + gainR = -gainR + } + cross_ptr = + output + .fade_end + .offset(cur_f.wrapping_mul(8 as libc::c_int as libc::c_uint) + as isize) + as *mut crate::squeezelite_h::s32_t + } else { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d unable to continue crossfade - too few samples\n\x00" + as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>( + b"_output_frames\x00", + )) + .as_ptr(), + 247 as libc::c_int, + ); + } + output.fade = crate::squeezelite_h::FADE_INACTIVE + } + } + } + } + } + out_frames = if !silence { + if size < cont_frames_0 { + size + } else { + cont_frames_0 + } + } else { + size + }; + wrote = output.write_cb.expect("non-null function pointer")( + out_frames, + silence, + gainL, + gainR, + cross_gain_in, + cross_gain_out, + &mut cross_ptr, + ); + if wrote <= 0 as libc::c_int { + frames = (frames as libc::c_uint).wrapping_sub(size) as crate::squeezelite_h::frames_t + as crate::squeezelite_h::frames_t; + break; + } else { + out_frames = wrote as crate::squeezelite_h::frames_t; + size = (size as libc::c_uint).wrapping_sub(out_frames) as crate::squeezelite_h::frames_t + as crate::squeezelite_h::frames_t; + if !silence { + crate::src::buffer::_buf_inc_readp( + outputbuf, + out_frames.wrapping_mul(8 as libc::c_int as libc::c_uint), + ); + output.frames_played = output.frames_played.wrapping_add(out_frames) + } + } + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d wrote %u frames\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>(b"_output_frames\x00")) + .as_ptr(), + 276 as libc::c_int, + frames, + ); + } + return frames; +} +// _* called with mutex locked +#[no_mangle] + +pub unsafe extern "C" fn _checkfade(mut start: bool) { + let mut bytes: crate::squeezelite_h::frames_t = 0; + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d fade mode: %u duration: %u %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"_checkfade\x00")).as_ptr(), + 284 as libc::c_int, + output.fade_mode as libc::c_uint, + output.fade_secs, + if start as libc::c_int != 0 { + b"track-start\x00" as *const u8 as *const libc::c_char + } else { + b"track-end\x00" as *const u8 as *const libc::c_char + }, + ); + } + bytes = output + .next_sample_rate + .wrapping_mul(8 as libc::c_int as libc::c_uint) + .wrapping_mul(output.fade_secs); + if output.fade_mode as libc::c_uint + == crate::squeezelite_h::FADE_INOUT as libc::c_int as libc::c_uint + { + /* align on a frame boundary */ + bytes = bytes + .wrapping_div(2 as libc::c_int as libc::c_uint) + .wrapping_div(8 as libc::c_int as libc::c_uint) + .wrapping_mul(8 as libc::c_int as libc::c_uint) + } // shorter than full buffer otherwise start and end align + if start as libc::c_int != 0 + && (output.fade_mode as libc::c_uint + == crate::squeezelite_h::FADE_IN as libc::c_int as libc::c_uint + || output.fade_mode as libc::c_uint + == crate::squeezelite_h::FADE_INOUT as libc::c_int as libc::c_uint + && crate::squeezelite_h::_buf_used(outputbuf) == 0 as libc::c_int as libc::c_uint) + { + bytes = if (bytes as libc::c_ulong) + < (*outputbuf) + .size + .wrapping_sub(8 as libc::c_int as libc::c_ulong) + { + bytes as libc::c_ulong + } else { + (*outputbuf) + .size + .wrapping_sub(8 as libc::c_int as libc::c_ulong) + } as crate::squeezelite_h::frames_t; // max of current remaining samples from previous track + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d fade IN: %u frames\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"_checkfade\x00")) + .as_ptr(), + 294 as libc::c_int, + bytes.wrapping_div(8 as libc::c_int as libc::c_uint), + ); // max of 90% of outputbuf as we consume additional buffer during crossfade + } + output.fade = crate::squeezelite_h::FADE_DUE; + output.fade_dir = crate::squeezelite_h::FADE_UP; + output.fade_start = (*outputbuf).writep; + output.fade_end = output.fade_start.offset(bytes as isize); + if output.fade_end >= (*outputbuf).wrap { + output.fade_end = output.fade_end.offset(-((*outputbuf).size as isize)) + } + } + if !start + && (output.fade_mode as libc::c_uint + == crate::squeezelite_h::FADE_OUT as libc::c_int as libc::c_uint + || output.fade_mode as libc::c_uint + == crate::squeezelite_h::FADE_INOUT as libc::c_int as libc::c_uint) + { + bytes = if crate::squeezelite_h::_buf_used(outputbuf) < bytes { + crate::squeezelite_h::_buf_used(outputbuf) + } else { + bytes + }; + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d fade %s: %u frames\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"_checkfade\x00")) + .as_ptr(), + 306 as libc::c_int, + if output.fade_mode as libc::c_uint + == crate::squeezelite_h::FADE_INOUT as libc::c_int as libc::c_uint + { + b"IN-OUT\x00" as *const u8 as *const libc::c_char + } else { + b"OUT\x00" as *const u8 as *const libc::c_char + }, + bytes.wrapping_div(8 as libc::c_int as libc::c_uint), + ); + } + output.fade = crate::squeezelite_h::FADE_DUE; + output.fade_dir = crate::squeezelite_h::FADE_DOWN; + output.fade_start = (*outputbuf).writep.offset(-(bytes as isize)); + if output.fade_start < (*outputbuf).buf { + output.fade_start = output.fade_start.offset((*outputbuf).size as isize) + } + output.fade_end = (*outputbuf).writep + } + if start as libc::c_int != 0 + && output.fade_mode as libc::c_uint + == crate::squeezelite_h::FADE_CROSSFADE as libc::c_int as libc::c_uint + { + if crate::squeezelite_h::_buf_used(outputbuf) != 0 as libc::c_int as libc::c_uint { + if output.next_sample_rate != output.current_sample_rate { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d crossfade disabled as sample rates differ\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>( + b"_checkfade\x00", + )) + .as_ptr(), + 319 as libc::c_int, + ); + } + return; + } + bytes = if bytes < crate::squeezelite_h::_buf_used(outputbuf) { + bytes + } else { + crate::squeezelite_h::_buf_used(outputbuf) + }; + bytes = if bytes + < ((*outputbuf).size as libc::c_double * 0.9f64) as crate::squeezelite_h::frames_t + { + bytes + } else { + ((*outputbuf).size as libc::c_double * 0.9f64) as crate::squeezelite_h::frames_t + }; + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d CROSSFADE: %u frames\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"_checkfade\x00")) + .as_ptr(), + 324 as libc::c_int, + bytes.wrapping_div(8 as libc::c_int as libc::c_uint), + ); + } + output.fade = crate::squeezelite_h::FADE_DUE; + output.fade_dir = crate::squeezelite_h::FADE_CROSS; + output.fade_start = (*outputbuf).writep.offset(-(bytes as isize)); + if output.fade_start < (*outputbuf).buf { + output.fade_start = output.fade_start.offset((*outputbuf).size as isize) + } + output.fade_end = (*outputbuf).writep; + output.track_start = output.fade_start + } else if (*outputbuf).size + == (44100 as libc::c_int * 8 as libc::c_int * 10 as libc::c_int) as libc::c_ulong + && (*outputbuf).readp == (*outputbuf).buf + { + // if default setting used and nothing in buffer attempt to resize to provide full crossfade support + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d resize outputbuf for crossfade\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"_checkfade\x00")) + .as_ptr(), + 335 as libc::c_int, + ); + } + crate::src::buffer::_buf_resize( + outputbuf, + (44100 as libc::c_int * 8 as libc::c_int * 10 as libc::c_int * 12 as libc::c_int + / 10 as libc::c_int) as crate::stddef_h::size_t, + ); + crate::src::utils::touch_memory((*outputbuf).buf, (*outputbuf).size); + } + }; +} +#[no_mangle] + +pub unsafe extern "C" fn output_init_common( + mut level: crate::squeezelite_h::log_level, + mut device: *const libc::c_char, + mut output_buf_size: libc::c_uint, + mut rates: *mut libc::c_uint, + mut idle: libc::c_uint, +) { + let mut i: libc::c_uint = 0; + loglevel = level; + output_buf_size = output_buf_size + .wrapping_sub(output_buf_size.wrapping_rem(8 as libc::c_int as libc::c_uint)); + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d outputbuf size: %u\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 19], &[libc::c_char; 19]>(b"output_init_common\x00")) + .as_ptr(), + 350 as libc::c_int, + output_buf_size, + ); + } + crate::src::buffer::buf_init(outputbuf, output_buf_size as crate::stddef_h::size_t); + if (*outputbuf).buf.is_null() { + crate::src::utils::logprint( + b"%s %s:%d unable to malloc output buffer\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 19], &[libc::c_char; 19]>(b"output_init_common\x00")) + .as_ptr(), + 354 as libc::c_int, + ); + crate::stdlib::exit(0 as libc::c_int); + } + silencebuf = crate::stdlib::malloc((2048 as libc::c_int * 8 as libc::c_int) as libc::c_ulong) + as *mut crate::squeezelite_h::u8_t; + if silencebuf.is_null() { + crate::src::utils::logprint( + b"%s %s:%d unable to malloc silence buffer\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 19], &[libc::c_char; 19]>(b"output_init_common\x00")) + .as_ptr(), + 360 as libc::c_int, + ); + crate::stdlib::exit(0 as libc::c_int); + } + crate::stdlib::memset( + silencebuf as *mut libc::c_void, + 0 as libc::c_int, + (2048 as libc::c_int * 8 as libc::c_int) as libc::c_ulong, + ); + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d idle timeout: %u\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 19], &[libc::c_char; 19]>(b"output_init_common\x00")) + .as_ptr(), + 374 as libc::c_int, + idle, + ); + } + output.state = if idle != 0 { + crate::squeezelite_h::OUTPUT_OFF as libc::c_int + } else { + crate::squeezelite_h::OUTPUT_STOPPED as libc::c_int + } as crate::squeezelite_h::output_state; + output.device = device; + output.fade = crate::squeezelite_h::FADE_INACTIVE; + output.invert = 0 as libc::c_int != 0; + output.error_opening = 0 as libc::c_int != 0; + output.idle_to = idle; + /* Skip test_open for stdout, set default sample rates */ + if *output.device.offset(0 as libc::c_int as isize) as libc::c_int == '-' as i32 { + i = 0 as libc::c_int as libc::c_uint; + while i < 18 as libc::c_int as libc::c_uint { + output.supported_rates[i as usize] = *rates.offset(i as isize); + i = i.wrapping_add(1) + } + } else if !crate::src::output_alsa::test_open( + output.device, + output.supported_rates.as_mut_ptr(), + user_rates, + ) { + crate::src::utils::logprint( + b"%s %s:%d unable to open output device: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 19], &[libc::c_char; 19]>(b"output_init_common\x00")) + .as_ptr(), + 391 as libc::c_int, + output.device, + ); + crate::stdlib::exit(0 as libc::c_int); + } + if user_rates { + i = 0 as libc::c_int as libc::c_uint; + while i < 18 as libc::c_int as libc::c_uint { + output.supported_rates[i as usize] = *rates.offset(i as isize); + i = i.wrapping_add(1) + } + } + // set initial sample rate, preferring 44100 + i = 0 as libc::c_int as libc::c_uint; + while i < 18 as libc::c_int as libc::c_uint { + if output.supported_rates[i as usize] == 44100 as libc::c_int as libc::c_uint { + output.default_sample_rate = 44100 as libc::c_int as libc::c_uint; + break; + } else { + i = i.wrapping_add(1) + } + } + if output.default_sample_rate == 0 { + output.default_sample_rate = output.supported_rates[0 as libc::c_int as usize] + } + output.current_sample_rate = output.default_sample_rate; + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + let mut rates_buf: [libc::c_char; 180] = + *::std::mem::transmute::<&[u8; 180], + &mut [libc::c_char; 180]>(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"); + i = 0 as libc::c_int as libc::c_uint; + while output.supported_rates[i as usize] != 0 { + let mut s: [libc::c_char; 10] = [0; 10]; + crate::stdlib::sprintf( + s.as_mut_ptr(), + b"%d \x00" as *const u8 as *const libc::c_char, + output.supported_rates[i as usize], + ); + crate::stdlib::strcat(rates_buf.as_mut_ptr(), s.as_mut_ptr()); + i = i.wrapping_add(1) + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d supported rates: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 19], &[libc::c_char; 19]>( + b"output_init_common\x00", + )) + .as_ptr(), + 422 as libc::c_int, + rates_buf.as_mut_ptr(), + ); + } + }; +} +#[no_mangle] + +pub unsafe extern "C" fn output_close_common() { + crate::src::buffer::buf_destroy(outputbuf); + crate::stdlib::free(silencebuf as *mut libc::c_void); +} +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Additions (c) Paul Hermann, 2015-2017 under the same license terms + * -Control of Raspberry pi GPIO for amplifier power + * -Launch script on power status change from LMS + */ +// make may define: PORTAUDIO, SELFPIPE, RESAMPLE, RESAMPLE_MP, VISEXPORT, GPIO, IR, DSD, LINKALL to influence build +// build detection +// dynamically loaded libraries at run time +// !LINKALL +// config options +// do not reduce as icy-meta max is 4080 +/* SUN */ +/* SUN */ +// printf/scanf formats for u64_t +// logging +// utils.c (non logging) +// buffer.c +// _* called with mutex locked +// slimproto.c +// stream.c +// decode.c +// output.c output_alsa.c output_pa.c output_pack.c +// frames played at the point delay is measured +// ordered largest first so [0] is max_rate +// set in decode thread +// set in decode thread +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +#[no_mangle] + +pub unsafe extern "C" fn output_flush() { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d flush output buffer\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"output_flush\x00")) + .as_ptr(), + 435 as libc::c_int, + ); + } + crate::src::buffer::buf_flush(outputbuf); + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + output.fade = crate::squeezelite_h::FADE_INACTIVE; + if output.state as libc::c_int != crate::squeezelite_h::OUTPUT_OFF as libc::c_int { + output.state = crate::squeezelite_h::OUTPUT_STOPPED; + if output.error_opening { + output.current_sample_rate = output.default_sample_rate + } + output.delay_active = 0 as libc::c_int != 0 + } + output.frames_played = 0 as libc::c_int as libc::c_uint; + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); +} diff --git a/src/output_alsa.rs b/src/output_alsa.rs new file mode 100644 index 0000000..408d7f3 --- /dev/null +++ b/src/output_alsa.rs @@ -0,0 +1,2390 @@ +use ::libc; + +pub use crate::internal::__builtin_va_list; +pub use crate::internal::__va_list_tag; +pub use crate::stdarg_h::va_list; +pub use crate::stddef_h::size_t; + +pub use crate::stdlib::_IO_codecvt; +pub use crate::stdlib::_IO_lock_t; +pub use crate::stdlib::_IO_marker; +pub use crate::stdlib::_IO_wide_data; +pub use crate::stdlib::__int32_t; +pub use crate::stdlib::__off64_t; +pub use crate::stdlib::__off_t; +pub use crate::stdlib::__uint32_t; +pub use crate::stdlib::__uint8_t; +pub use crate::stdlib::__useconds_t; +pub use crate::stdlib::int32_t; +pub use crate::stdlib::FILE; +pub use crate::stdlib::_IO_FILE; + +pub use crate::stdlib::__pthread_internal_list; +pub use crate::stdlib::__pthread_list_t; +pub use crate::stdlib::__pthread_mutex_s; +pub use crate::stdlib::pthread_attr_t; +pub use crate::stdlib::pthread_mutex_t; +pub use crate::stdlib::pthread_t; +pub use crate::stdlib::sched_param; +pub use crate::stdlib::u_int32_t; +pub use crate::stdlib::u_int8_t; + +pub use crate::squeezelite_h::_apply_cross; +pub use crate::squeezelite_h::_apply_gain; +pub use crate::squeezelite_h::buffer; +pub use crate::squeezelite_h::fade_dir; +pub use crate::squeezelite_h::fade_mode; +pub use crate::squeezelite_h::fade_state; +pub use crate::squeezelite_h::frames_t; +pub use crate::squeezelite_h::lDEBUG; +pub use crate::squeezelite_h::lERROR; +pub use crate::squeezelite_h::lINFO; +pub use crate::squeezelite_h::lSDEBUG; +pub use crate::squeezelite_h::lWARN; +pub use crate::squeezelite_h::log_level; +pub use crate::squeezelite_h::output_format; +pub use crate::squeezelite_h::output_state; +pub use crate::squeezelite_h::outputstate; +pub use crate::squeezelite_h::s32_t; +pub use crate::squeezelite_h::u32_t; +pub use crate::squeezelite_h::u8_t; +pub use crate::squeezelite_h::C2RustUnnamed_1; +pub use crate::squeezelite_h::FADE_ACTIVE; +pub use crate::squeezelite_h::FADE_CROSS; +pub use crate::squeezelite_h::FADE_CROSSFADE; +pub use crate::squeezelite_h::FADE_DOWN; +pub use crate::squeezelite_h::FADE_DUE; +pub use crate::squeezelite_h::FADE_IN; +pub use crate::squeezelite_h::FADE_INACTIVE; +pub use crate::squeezelite_h::FADE_INOUT; +pub use crate::squeezelite_h::FADE_NONE; +pub use crate::squeezelite_h::FADE_OUT; +pub use crate::squeezelite_h::FADE_UP; +pub use crate::squeezelite_h::OUTPUT_BUFFER; +pub use crate::squeezelite_h::OUTPUT_OFF; +pub use crate::squeezelite_h::OUTPUT_PAUSE_FRAMES; +pub use crate::squeezelite_h::OUTPUT_RUNNING; +pub use crate::squeezelite_h::OUTPUT_SKIP_FRAMES; +pub use crate::squeezelite_h::OUTPUT_START_AT; +pub use crate::squeezelite_h::OUTPUT_STOPPED; +pub use crate::squeezelite_h::S16_LE; +pub use crate::squeezelite_h::S24_3LE; +pub use crate::squeezelite_h::S24_LE; +pub use crate::squeezelite_h::S32_LE; +pub use crate::src::output::_output_frames; +pub use crate::src::output::output_close_common; +pub use crate::src::output::output_init_common; +pub use crate::src::output_pack::_scale_and_pack_frames; +pub use crate::src::utils::gettime_ms; +pub use crate::src::utils::logprint; +pub use crate::src::utils::logtime; +pub use crate::src::utils::next_param; +pub use crate::src::utils::touch_memory; +use crate::stdlib::__errno_location; +pub use crate::stdlib::_snd_mixer; +pub use crate::stdlib::_snd_mixer_class; +pub use crate::stdlib::_snd_mixer_elem; +pub use crate::stdlib::_snd_mixer_selem_channel_id; +pub use crate::stdlib::_snd_mixer_selem_id; +pub use crate::stdlib::_snd_output; +pub use crate::stdlib::_snd_pcm; +pub use crate::stdlib::_snd_pcm_access; +pub use crate::stdlib::_snd_pcm_channel_area; +pub use crate::stdlib::_snd_pcm_format; +pub use crate::stdlib::_snd_pcm_hw_params; +pub use crate::stdlib::_snd_pcm_state; +pub use crate::stdlib::_snd_pcm_stream; +use crate::stdlib::atoi; +use crate::stdlib::fflush; +use crate::stdlib::fprintf; +use crate::stdlib::free; +use crate::stdlib::malloc; +use crate::stdlib::memcpy; +use crate::stdlib::memset; +use crate::stdlib::printf; +pub use crate::stdlib::snd_lib_error_handler_t; +pub use crate::stdlib::snd_lib_error_set_handler; +pub use crate::stdlib::snd_mixer_attach; +pub use crate::stdlib::snd_mixer_class_t; +pub use crate::stdlib::snd_mixer_close; +pub use crate::stdlib::snd_mixer_elem_next; +pub use crate::stdlib::snd_mixer_elem_t; +pub use crate::stdlib::snd_mixer_find_selem; +pub use crate::stdlib::snd_mixer_first_elem; +pub use crate::stdlib::snd_mixer_load; +pub use crate::stdlib::snd_mixer_open; +pub use crate::stdlib::snd_mixer_selem_channel_id_t; +pub use crate::stdlib::snd_mixer_selem_get_id; +pub use crate::stdlib::snd_mixer_selem_get_playback_dB_range; +pub use crate::stdlib::snd_mixer_selem_get_playback_volume; +pub use crate::stdlib::snd_mixer_selem_get_playback_volume_range; +pub use crate::stdlib::snd_mixer_selem_has_playback_switch; +pub use crate::stdlib::snd_mixer_selem_has_playback_volume; +pub use crate::stdlib::snd_mixer_selem_id_get_index; +pub use crate::stdlib::snd_mixer_selem_id_get_name; +pub use crate::stdlib::snd_mixer_selem_id_set_index; +pub use crate::stdlib::snd_mixer_selem_id_set_name; +pub use crate::stdlib::snd_mixer_selem_id_sizeof; +pub use crate::stdlib::snd_mixer_selem_id_t; +pub use crate::stdlib::snd_mixer_selem_register; +pub use crate::stdlib::snd_mixer_selem_regopt; +pub use crate::stdlib::snd_mixer_selem_regopt_abstract; +pub use crate::stdlib::snd_mixer_selem_set_playback_dB; +pub use crate::stdlib::snd_mixer_selem_set_playback_switch_all; +pub use crate::stdlib::snd_mixer_selem_set_playback_volume; +pub use crate::stdlib::snd_mixer_t; +pub use crate::stdlib::snd_output_stdio_attach; +pub use crate::stdlib::snd_output_t; +pub use crate::stdlib::snd_pcm_access_t; +pub use crate::stdlib::snd_pcm_avail_update; +pub use crate::stdlib::snd_pcm_channel_area_t; +pub use crate::stdlib::snd_pcm_close; +pub use crate::stdlib::snd_pcm_delay; +pub use crate::stdlib::snd_pcm_dump; +pub use crate::stdlib::snd_pcm_format_name; +pub use crate::stdlib::snd_pcm_format_t; +pub use crate::stdlib::snd_pcm_hw_params; +pub use crate::stdlib::snd_pcm_hw_params_any; +pub use crate::stdlib::snd_pcm_hw_params_get_buffer_size; +pub use crate::stdlib::snd_pcm_hw_params_get_period_size; +pub use crate::stdlib::snd_pcm_hw_params_set_access; +pub use crate::stdlib::snd_pcm_hw_params_set_buffer_size_near; +pub use crate::stdlib::snd_pcm_hw_params_set_buffer_time_near; +pub use crate::stdlib::snd_pcm_hw_params_set_channels; +pub use crate::stdlib::snd_pcm_hw_params_set_format; +pub use crate::stdlib::snd_pcm_hw_params_set_period_size_near; +pub use crate::stdlib::snd_pcm_hw_params_set_periods_near; +pub use crate::stdlib::snd_pcm_hw_params_set_rate; +pub use crate::stdlib::snd_pcm_hw_params_set_rate_resample; +pub use crate::stdlib::snd_pcm_hw_params_sizeof; +pub use crate::stdlib::snd_pcm_hw_params_t; +pub use crate::stdlib::snd_pcm_hw_params_test_rate; +pub use crate::stdlib::snd_pcm_mmap_begin; +pub use crate::stdlib::snd_pcm_mmap_commit; +pub use crate::stdlib::snd_pcm_open; +pub use crate::stdlib::snd_pcm_recover; +pub use crate::stdlib::snd_pcm_sframes_t; +pub use crate::stdlib::snd_pcm_start; +pub use crate::stdlib::snd_pcm_state; +pub use crate::stdlib::snd_pcm_state_t; +pub use crate::stdlib::snd_pcm_stream_t; +pub use crate::stdlib::snd_pcm_t; +pub use crate::stdlib::snd_pcm_uframes_t; +pub use crate::stdlib::snd_pcm_wait; +pub use crate::stdlib::snd_pcm_writei; +pub use crate::stdlib::snd_strerror; +use crate::stdlib::stderr; +use crate::stdlib::strcmp; +use crate::stdlib::strcpy; +use crate::stdlib::strdup; +use crate::stdlib::strerror; +use crate::stdlib::strlen; +use crate::stdlib::strncmp; +use crate::stdlib::strrchr; +use crate::stdlib::strtok; +use crate::stdlib::vfprintf; +pub use crate::stdlib::SND_MIXER_SABSTRACT_BASIC; +pub use crate::stdlib::SND_MIXER_SABSTRACT_NONE; +pub use crate::stdlib::SND_MIXER_SCHN_FRONT_CENTER; +pub use crate::stdlib::SND_MIXER_SCHN_FRONT_LEFT; +pub use crate::stdlib::SND_MIXER_SCHN_FRONT_RIGHT; +pub use crate::stdlib::SND_MIXER_SCHN_LAST; +pub use crate::stdlib::SND_MIXER_SCHN_MONO; +pub use crate::stdlib::SND_MIXER_SCHN_REAR_CENTER; +pub use crate::stdlib::SND_MIXER_SCHN_REAR_LEFT; +pub use crate::stdlib::SND_MIXER_SCHN_REAR_RIGHT; +pub use crate::stdlib::SND_MIXER_SCHN_SIDE_LEFT; +pub use crate::stdlib::SND_MIXER_SCHN_SIDE_RIGHT; +pub use crate::stdlib::SND_MIXER_SCHN_UNKNOWN; +pub use crate::stdlib::SND_MIXER_SCHN_WOOFER; +pub use crate::stdlib::SND_PCM_ACCESS_LAST; +pub use crate::stdlib::SND_PCM_ACCESS_MMAP_COMPLEX; +pub use crate::stdlib::SND_PCM_ACCESS_MMAP_INTERLEAVED; +pub use crate::stdlib::SND_PCM_ACCESS_MMAP_NONINTERLEAVED; +pub use crate::stdlib::SND_PCM_ACCESS_RW_INTERLEAVED; +pub use crate::stdlib::SND_PCM_ACCESS_RW_NONINTERLEAVED; +pub use crate::stdlib::SND_PCM_FORMAT_A_LAW; +pub use crate::stdlib::SND_PCM_FORMAT_DSD_U16_BE; +pub use crate::stdlib::SND_PCM_FORMAT_DSD_U16_LE; +pub use crate::stdlib::SND_PCM_FORMAT_DSD_U32_BE; +pub use crate::stdlib::SND_PCM_FORMAT_DSD_U32_LE; +pub use crate::stdlib::SND_PCM_FORMAT_DSD_U8; +pub use crate::stdlib::SND_PCM_FORMAT_FLOAT; +pub use crate::stdlib::SND_PCM_FORMAT_FLOAT64; +pub use crate::stdlib::SND_PCM_FORMAT_FLOAT64_BE; +pub use crate::stdlib::SND_PCM_FORMAT_FLOAT64_LE; +pub use crate::stdlib::SND_PCM_FORMAT_FLOAT_BE; +pub use crate::stdlib::SND_PCM_FORMAT_FLOAT_LE; +pub use crate::stdlib::SND_PCM_FORMAT_G723_24; +pub use crate::stdlib::SND_PCM_FORMAT_G723_24_1B; +pub use crate::stdlib::SND_PCM_FORMAT_G723_40; +pub use crate::stdlib::SND_PCM_FORMAT_G723_40_1B; +pub use crate::stdlib::SND_PCM_FORMAT_GSM; +pub use crate::stdlib::SND_PCM_FORMAT_IEC958_SUBFRAME; +pub use crate::stdlib::SND_PCM_FORMAT_IEC958_SUBFRAME_BE; +pub use crate::stdlib::SND_PCM_FORMAT_IEC958_SUBFRAME_LE; +pub use crate::stdlib::SND_PCM_FORMAT_IMA_ADPCM; +pub use crate::stdlib::SND_PCM_FORMAT_LAST; +pub use crate::stdlib::SND_PCM_FORMAT_MPEG; +pub use crate::stdlib::SND_PCM_FORMAT_MU_LAW; +pub use crate::stdlib::SND_PCM_FORMAT_S16; +pub use crate::stdlib::SND_PCM_FORMAT_S16_BE; +pub use crate::stdlib::SND_PCM_FORMAT_S16_LE; +pub use crate::stdlib::SND_PCM_FORMAT_S18_3BE; +pub use crate::stdlib::SND_PCM_FORMAT_S18_3LE; +pub use crate::stdlib::SND_PCM_FORMAT_S20; +pub use crate::stdlib::SND_PCM_FORMAT_S20_3BE; +pub use crate::stdlib::SND_PCM_FORMAT_S20_3LE; +pub use crate::stdlib::SND_PCM_FORMAT_S20_BE; +pub use crate::stdlib::SND_PCM_FORMAT_S20_LE; +pub use crate::stdlib::SND_PCM_FORMAT_S24; +pub use crate::stdlib::SND_PCM_FORMAT_S24_3BE; +pub use crate::stdlib::SND_PCM_FORMAT_S24_3LE; +pub use crate::stdlib::SND_PCM_FORMAT_S24_BE; +pub use crate::stdlib::SND_PCM_FORMAT_S24_LE; +pub use crate::stdlib::SND_PCM_FORMAT_S32; +pub use crate::stdlib::SND_PCM_FORMAT_S32_BE; +pub use crate::stdlib::SND_PCM_FORMAT_S32_LE; +pub use crate::stdlib::SND_PCM_FORMAT_S8; +pub use crate::stdlib::SND_PCM_FORMAT_SPECIAL; +pub use crate::stdlib::SND_PCM_FORMAT_U16; +pub use crate::stdlib::SND_PCM_FORMAT_U16_BE; +pub use crate::stdlib::SND_PCM_FORMAT_U16_LE; +pub use crate::stdlib::SND_PCM_FORMAT_U18_3BE; +pub use crate::stdlib::SND_PCM_FORMAT_U18_3LE; +pub use crate::stdlib::SND_PCM_FORMAT_U20; +pub use crate::stdlib::SND_PCM_FORMAT_U20_3BE; +pub use crate::stdlib::SND_PCM_FORMAT_U20_3LE; +pub use crate::stdlib::SND_PCM_FORMAT_U20_BE; +pub use crate::stdlib::SND_PCM_FORMAT_U20_LE; +pub use crate::stdlib::SND_PCM_FORMAT_U24; +pub use crate::stdlib::SND_PCM_FORMAT_U24_3BE; +pub use crate::stdlib::SND_PCM_FORMAT_U24_3LE; +pub use crate::stdlib::SND_PCM_FORMAT_U24_BE; +pub use crate::stdlib::SND_PCM_FORMAT_U24_LE; +pub use crate::stdlib::SND_PCM_FORMAT_U32; +pub use crate::stdlib::SND_PCM_FORMAT_U32_BE; +pub use crate::stdlib::SND_PCM_FORMAT_U32_LE; +pub use crate::stdlib::SND_PCM_FORMAT_U8; +pub use crate::stdlib::SND_PCM_FORMAT_UNKNOWN; +pub use crate::stdlib::SND_PCM_STATE_DISCONNECTED; +pub use crate::stdlib::SND_PCM_STATE_DRAINING; +pub use crate::stdlib::SND_PCM_STATE_LAST; +pub use crate::stdlib::SND_PCM_STATE_OPEN; +pub use crate::stdlib::SND_PCM_STATE_PAUSED; +pub use crate::stdlib::SND_PCM_STATE_PREPARED; +pub use crate::stdlib::SND_PCM_STATE_PRIVATE1; +pub use crate::stdlib::SND_PCM_STATE_RUNNING; +pub use crate::stdlib::SND_PCM_STATE_SETUP; +pub use crate::stdlib::SND_PCM_STATE_SUSPENDED; +pub use crate::stdlib::SND_PCM_STATE_XRUN; +pub use crate::stdlib::SND_PCM_STREAM_CAPTURE; +pub use crate::stdlib::SND_PCM_STREAM_LAST; +pub use crate::stdlib::SND_PCM_STREAM_PLAYBACK; + +use crate::stdlib::floor; +use crate::stdlib::log10; +use crate::stdlib::mallopt; +use crate::stdlib::mlockall; +use crate::stdlib::pthread_attr_destroy; +use crate::stdlib::pthread_attr_init; +use crate::stdlib::pthread_attr_setstacksize; +use crate::stdlib::pthread_create; +use crate::stdlib::pthread_join; +use crate::stdlib::pthread_mutex_lock; +use crate::stdlib::pthread_mutex_unlock; +use crate::stdlib::pthread_setschedparam; +use crate::stdlib::sleep; +use crate::stdlib::snd_device_name_free_hint; +use crate::stdlib::snd_device_name_get_hint; +use crate::stdlib::snd_device_name_hint; +use crate::stdlib::usleep; +extern "C" { + #[no_mangle] + pub static mut silencebuf: *mut crate::squeezelite_h::u8_t; + #[no_mangle] + pub static mut output: crate::squeezelite_h::outputstate; + #[no_mangle] + pub static mut outputbuf: *mut crate::squeezelite_h::buffer; +} +// ouput device + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct C2RustUnnamed_12 { + pub device: [libc::c_char; 129], + pub ctl: *mut libc::c_char, + pub mixer_ctl: *mut libc::c_char, + pub format: crate::stdlib::snd_pcm_format_t, + pub buffer_size: crate::stdlib::snd_pcm_uframes_t, + pub period_size: crate::stdlib::snd_pcm_uframes_t, + pub rate: libc::c_uint, + pub mmap: bool, + pub reopen: bool, + pub write_buf: *mut crate::squeezelite_h::u8_t, + pub volume_mixer_name: *const libc::c_char, + pub mixer_linear: bool, + pub mixer_elem: *mut crate::stdlib::snd_mixer_elem_t, + pub mixer_handle: *mut crate::stdlib::snd_mixer_t, + pub mixer_min: libc::c_long, + pub mixer_max: libc::c_long, +} + +static mut fmts: [crate::stdlib::snd_pcm_format_t; 5] = [ + crate::stdlib::SND_PCM_FORMAT_S32_LE, + crate::stdlib::SND_PCM_FORMAT_S24_LE, + crate::stdlib::SND_PCM_FORMAT_S24_3LE, + crate::stdlib::SND_PCM_FORMAT_S16_LE, + crate::stdlib::SND_PCM_FORMAT_UNKNOWN, +]; + +static mut alsa: C2RustUnnamed_12 = C2RustUnnamed_12 { + device: [0; 129], + ctl: 0 as *const libc::c_char as *mut libc::c_char, + mixer_ctl: 0 as *const libc::c_char as *mut libc::c_char, + format: crate::stdlib::SND_PCM_FORMAT_S8, + buffer_size: 0, + period_size: 0, + rate: 0, + mmap: false, + reopen: false, + write_buf: 0 as *const crate::squeezelite_h::u8_t as *mut crate::squeezelite_h::u8_t, + volume_mixer_name: 0 as *const libc::c_char, + mixer_linear: false, + mixer_elem: 0 as *const crate::stdlib::snd_mixer_elem_t as *mut crate::stdlib::snd_mixer_elem_t, + mixer_handle: 0 as *const crate::stdlib::snd_mixer_t as *mut crate::stdlib::snd_mixer_t, + mixer_min: 0, + mixer_max: 0, +}; + +static mut pcmp: *mut crate::stdlib::snd_pcm_t = + 0 as *const crate::stdlib::snd_pcm_t as *mut crate::stdlib::snd_pcm_t; + +static mut loglevel: crate::squeezelite_h::log_level = crate::squeezelite_h::lERROR; + +static mut running: bool = 1 as libc::c_int != 0; + +unsafe extern "C" fn ctl4device(mut device: *const libc::c_char) -> *mut libc::c_char { + let mut ctl = 0 as *mut libc::c_char; + if crate::stdlib::strncmp( + device, + b"hw:\x00" as *const u8 as *const libc::c_char, + 3 as libc::c_int as libc::c_ulong, + ) == 0 + { + ctl = crate::stdlib::strdup(device) + } else if crate::stdlib::strncmp( + device, + b"plughw:\x00" as *const u8 as *const libc::c_char, + 7 as libc::c_int as libc::c_ulong, + ) == 0 + { + ctl = crate::stdlib::strdup(device.offset(4 as libc::c_int as isize)) + } + if !ctl.is_null() { + let mut comma = 0 as *mut libc::c_char; + comma = crate::stdlib::strrchr(ctl, ',' as i32); + if !comma.is_null() { + *comma = '\u{0}' as i32 as libc::c_char + } + } else { + ctl = crate::stdlib::strdup(device) + } + return ctl; +} +#[no_mangle] + +pub unsafe extern "C" fn list_devices() { + let mut hints = 0 as *mut *mut libc::c_void; + let mut n = 0 as *mut *mut libc::c_void; + if crate::stdlib::snd_device_name_hint( + -(1 as libc::c_int), + b"pcm\x00" as *const u8 as *const libc::c_char, + &mut hints, + ) >= 0 as libc::c_int + { + n = hints; + crate::stdlib::printf(b"Output devices:\n\x00" as *const u8 as *const libc::c_char); + while !(*n).is_null() { + let mut name = crate::stdlib::snd_device_name_get_hint( + *n, + b"NAME\x00" as *const u8 as *const libc::c_char, + ); + let mut desc = crate::stdlib::snd_device_name_get_hint( + *n, + b"DESC\x00" as *const u8 as *const libc::c_char, + ); + if !name.is_null() { + crate::stdlib::printf(b" %-30s\x00" as *const u8 as *const libc::c_char, name); + } + if !desc.is_null() { + let mut s1 = + crate::stdlib::strtok(desc, b"\n\x00" as *const u8 as *const libc::c_char); + let mut s2 = crate::stdlib::strtok( + 0 as *mut libc::c_char, + b"\n\x00" as *const u8 as *const libc::c_char, + ); + if !s1.is_null() { + crate::stdlib::printf(b" - %s\x00" as *const u8 as *const libc::c_char, s1); + } + if !s2.is_null() { + crate::stdlib::printf(b" - %s\x00" as *const u8 as *const libc::c_char, s2); + } + } + crate::stdlib::printf(b"\n\x00" as *const u8 as *const libc::c_char); + if !name.is_null() { + crate::stdlib::free(name as *mut libc::c_void); + } + if !desc.is_null() { + crate::stdlib::free(desc as *mut libc::c_void); + } + n = n.offset(1) + } + crate::stdlib::snd_device_name_free_hint(hints); + } + crate::stdlib::printf(b"\n\x00" as *const u8 as *const libc::c_char); +} +#[no_mangle] + +pub unsafe extern "C" fn list_mixers(mut output_device: *const libc::c_char) { + let mut err: libc::c_int = 0; + let mut handle = 0 as *mut crate::stdlib::snd_mixer_t; + let mut sid = 0 as *mut crate::stdlib::snd_mixer_selem_id_t; + let mut elem = 0 as *mut crate::stdlib::snd_mixer_elem_t; + let mut ctl = ctl4device(output_device); + let mut fresh0 = ::std::vec::from_elem(0, crate::stdlib::snd_mixer_selem_id_sizeof() as usize); + sid = fresh0.as_mut_ptr() as *mut crate::stdlib::snd_mixer_selem_id_t; + crate::stdlib::memset( + sid as *mut libc::c_void, + 0 as libc::c_int, + crate::stdlib::snd_mixer_selem_id_sizeof(), + ); + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d listing mixers for: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"list_mixers\x00")).as_ptr(), + 139 as libc::c_int, + output_device, + ); + } + err = crate::stdlib::snd_mixer_open(&mut handle, 0 as libc::c_int); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d open error: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"list_mixers\x00")).as_ptr(), + 142 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + return; + } + err = crate::stdlib::snd_mixer_attach(handle, ctl); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d attach error: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"list_mixers\x00")).as_ptr(), + 146 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + crate::stdlib::snd_mixer_close(handle); + crate::stdlib::free(ctl as *mut libc::c_void); + return; + } + crate::stdlib::free(ctl as *mut libc::c_void); + err = crate::stdlib::snd_mixer_selem_register( + handle, + 0 as *mut crate::stdlib::snd_mixer_selem_regopt, + 0 as *mut *mut crate::stdlib::snd_mixer_class_t, + ); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d register error: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"list_mixers\x00")).as_ptr(), + 153 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + crate::stdlib::snd_mixer_close(handle); + return; + } + err = crate::stdlib::snd_mixer_load(handle); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d load error: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"list_mixers\x00")).as_ptr(), + 158 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + crate::stdlib::snd_mixer_close(handle); + return; + } + crate::stdlib::printf( + b"Volume controls for %s\n\x00" as *const u8 as *const libc::c_char, + output_device, + ); + elem = crate::stdlib::snd_mixer_first_elem(handle); + while !elem.is_null() { + if crate::stdlib::snd_mixer_selem_has_playback_volume(elem) != 0 { + crate::stdlib::snd_mixer_selem_get_id(elem, sid); + crate::stdlib::printf( + b" %s\x00" as *const u8 as *const libc::c_char, + crate::stdlib::snd_mixer_selem_id_get_name(sid), + ); + if crate::stdlib::snd_mixer_selem_id_get_index(sid) != 0 { + crate::stdlib::printf( + b",%d\x00" as *const u8 as *const libc::c_char, + crate::stdlib::snd_mixer_selem_id_get_index(sid), + ); + } + crate::stdlib::printf(b"\n\x00" as *const u8 as *const libc::c_char); + } + elem = crate::stdlib::snd_mixer_elem_next(elem) + } + crate::stdlib::printf(b"\n\x00" as *const u8 as *const libc::c_char); + crate::stdlib::snd_mixer_close(handle); +} +// LMS volume map for SqueezePlay sends values in range ~ -72..0 dB + +unsafe extern "C" fn set_mixer(mut setmax: bool, mut ldB: libc::c_float, mut rdB: libc::c_float) { + let mut err: libc::c_int = 0; + let mut nleft: libc::c_long = 0; + let mut nright: libc::c_long = 0; + if alsa.mixer_linear { + let mut lraw: libc::c_long = 0; + let mut rraw: libc::c_long = 0; + if setmax { + rraw = alsa.mixer_max; + lraw = rraw + } else { + lraw = ((if ldB > -(72 as libc::c_int) as libc::c_float { + (72 as libc::c_int as libc::c_double) + crate::stdlib::floor(ldB as libc::c_double) + } else { + 0 as libc::c_int as libc::c_double + }) / 72 as libc::c_int as libc::c_double + * (alsa.mixer_max - alsa.mixer_min) as libc::c_double + + alsa.mixer_min as libc::c_double) as libc::c_long; + rraw = ((if rdB > -(72 as libc::c_int) as libc::c_float { + (72 as libc::c_int as libc::c_double) + crate::stdlib::floor(rdB as libc::c_double) + } else { + 0 as libc::c_int as libc::c_double + }) / 72 as libc::c_int as libc::c_double + * (alsa.mixer_max - alsa.mixer_min) as libc::c_double + + alsa.mixer_min as libc::c_double) as libc::c_long + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d setting vol raw [%ld..%ld]\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"set_mixer\x00")) + .as_ptr(), + 193 as libc::c_int, + alsa.mixer_min, + alsa.mixer_max, + ); + } + err = crate::stdlib::snd_mixer_selem_set_playback_volume( + alsa.mixer_elem, + crate::stdlib::SND_MIXER_SCHN_FRONT_LEFT, + lraw, + ); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d error setting left volume: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"set_mixer\x00")) + .as_ptr(), + 195 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + } + err = crate::stdlib::snd_mixer_selem_set_playback_volume( + alsa.mixer_elem, + crate::stdlib::SND_MIXER_SCHN_FRONT_RIGHT, + rraw, + ); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d error setting right volume: %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"set_mixer\x00")) + .as_ptr(), + 198 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + } + } else { + // set db directly + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d setting vol dB [%ld..%ld]\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"set_mixer\x00")) + .as_ptr(), + 202 as libc::c_int, + alsa.mixer_min, + alsa.mixer_max, + ); + } + if setmax { + // set to 0dB if available as this should be max volume for music recored at max pcm values + if alsa.mixer_max >= 0 as libc::c_int as libc::c_long + && alsa.mixer_min <= 0 as libc::c_int as libc::c_long + { + rdB = 0 as libc::c_int as libc::c_float; + ldB = rdB + } else { + rdB = alsa.mixer_max as libc::c_float; + ldB = rdB + } + } + err = crate::stdlib::snd_mixer_selem_set_playback_dB( + alsa.mixer_elem, + crate::stdlib::SND_MIXER_SCHN_FRONT_LEFT, + (100 as libc::c_int as libc::c_float * ldB) as libc::c_long, + 1 as libc::c_int, + ); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d error setting left volume: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"set_mixer\x00")) + .as_ptr(), + 212 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + } + err = crate::stdlib::snd_mixer_selem_set_playback_dB( + alsa.mixer_elem, + crate::stdlib::SND_MIXER_SCHN_FRONT_RIGHT, + (100 as libc::c_int as libc::c_float * rdB) as libc::c_long, + 1 as libc::c_int, + ); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d error setting right volume: %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"set_mixer\x00")) + .as_ptr(), + 215 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + } + } + err = crate::stdlib::snd_mixer_selem_get_playback_volume( + alsa.mixer_elem, + crate::stdlib::SND_MIXER_SCHN_FRONT_LEFT, + &mut nleft, + ); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d error getting left vol: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"set_mixer\x00")).as_ptr(), + 220 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + } + err = crate::stdlib::snd_mixer_selem_get_playback_volume( + alsa.mixer_elem, + crate::stdlib::SND_MIXER_SCHN_FRONT_RIGHT, + &mut nright, + ); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d error getting right vol: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"set_mixer\x00")).as_ptr(), + 223 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d %s left: %3.1fdB -> %ld right: %3.1fdB -> %ld\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"set_mixer\x00")).as_ptr(), + 226 as libc::c_int, + alsa.volume_mixer_name, + ldB as libc::c_double, + nleft, + rdB as libc::c_double, + nright, + ); + }; +} +#[no_mangle] + +pub unsafe extern "C" fn set_volume(mut left: libc::c_uint, mut right: libc::c_uint) { + let mut ldB: libc::c_float = 0.; + let mut rdB: libc::c_float = 0.; + if alsa.volume_mixer_name.is_null() { + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d setting internal gain left: %u right: %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"set_volume\x00")) + .as_ptr(), + 233 as libc::c_int, + left, + right, + ); + } + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + output.gainL = left; + output.gainR = right; + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + return; + } else { + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + output.gainL = 0x10000 as libc::c_int as crate::squeezelite_h::u32_t; + output.gainR = 0x10000 as libc::c_int as crate::squeezelite_h::u32_t; + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + } + // convert 16.16 fixed point to dB + ldB = (20 as libc::c_int as libc::c_double + * crate::stdlib::log10((left as libc::c_float / 65536.0f32) as libc::c_double)) + as libc::c_float; + rdB = (20 as libc::c_int as libc::c_double + * crate::stdlib::log10((right as libc::c_float / 65536.0f32) as libc::c_double)) + as libc::c_float; + set_mixer(0 as libc::c_int != 0, ldB, rdB); +} + +unsafe extern "C" fn alsa_error_handler( + mut file: *const libc::c_char, + mut line: libc::c_int, + mut function: *const libc::c_char, + mut err: libc::c_int, + mut fmt: *const libc::c_char, + mut args: ... +) -> *mut libc::c_void { + let mut args_0: ::std::ffi::VaListImpl; + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + && err == 0 as libc::c_int + || loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::stdlib::fprintf( + crate::stdlib::stderr, + b"%s ALSA %s:%d \x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + function, + line, + ); + args_0 = args.clone(); + crate::stdlib::vfprintf(crate::stdlib::stderr, fmt, args_0.as_va_list()); + crate::stdlib::fprintf( + crate::stdlib::stderr, + b"\n\x00" as *const u8 as *const libc::c_char, + ); + crate::stdlib::fflush(crate::stdlib::stderr); + } + return 0 as *mut libc::c_void; +} + +unsafe extern "C" fn alsa_close() { + let mut err: libc::c_int = 0; + err = crate::stdlib::snd_pcm_close(pcmp); + if err < 0 as libc::c_int { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d snd_pcm_close error: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"alsa_close\x00")) + .as_ptr(), + 268 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + } + }; +} +#[no_mangle] + +pub unsafe extern "C" fn test_open( + mut device: *const libc::c_char, + mut rates: *mut libc::c_uint, + mut userdef_rates: bool, +) -> bool { + let mut err: libc::c_int = 0; + let mut pcm = 0 as *mut crate::stdlib::snd_pcm_t; + let mut hw_params = 0 as *mut crate::stdlib::snd_pcm_hw_params_t; + let mut fresh1 = ::std::vec::from_elem(0, crate::stdlib::snd_pcm_hw_params_sizeof() as usize); + hw_params = fresh1.as_mut_ptr() as *mut crate::stdlib::snd_pcm_hw_params_t; + crate::stdlib::memset( + hw_params as *mut libc::c_void, + 0 as libc::c_int, + crate::stdlib::snd_pcm_hw_params_sizeof(), + ); + // open device + err = crate::stdlib::snd_pcm_open( + &mut pcm, + device, + crate::stdlib::SND_PCM_STREAM_PLAYBACK, + 0 as libc::c_int, + ); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d playback open error: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"test_open\x00")).as_ptr(), + 281 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + return 0 as libc::c_int != 0; + } + // get max params + err = crate::stdlib::snd_pcm_hw_params_any(pcm, hw_params); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d hwparam init error: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"test_open\x00")).as_ptr(), + 287 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + return 0 as libc::c_int != 0; + } + // find supported sample rates to enable client side resampling of non supported rates + if !userdef_rates { + let mut i: libc::c_uint = 0; + let mut ind: libc::c_uint = 0; + let mut ref_0: [libc::c_uint; 18] = [ + 768000 as libc::c_int as libc::c_uint, + 705600 as libc::c_int as libc::c_uint, + 384000 as libc::c_int as libc::c_uint, + 352800 as libc::c_int as libc::c_uint, + 192000 as libc::c_int as libc::c_uint, + 176400 as libc::c_int as libc::c_uint, + 96000 as libc::c_int as libc::c_uint, + 88200 as libc::c_int as libc::c_uint, + 48000 as libc::c_int as libc::c_uint, + 44100 as libc::c_int as libc::c_uint, + 32000 as libc::c_int as libc::c_uint, + 24000 as libc::c_int as libc::c_uint, + 22500 as libc::c_int as libc::c_uint, + 16000 as libc::c_int as libc::c_uint, + 12000 as libc::c_int as libc::c_uint, + 11025 as libc::c_int as libc::c_uint, + 8000 as libc::c_int as libc::c_uint, + 0 as libc::c_int as libc::c_uint, + ]; + i = 0 as libc::c_int as libc::c_uint; + ind = 0 as libc::c_int as libc::c_uint; + while ref_0[i as usize] != 0 { + if crate::stdlib::snd_pcm_hw_params_test_rate( + pcm, + hw_params, + ref_0[i as usize], + 0 as libc::c_int, + ) == 0 as libc::c_int + { + let fresh2 = ind; + ind = ind.wrapping_add(1); + *rates.offset(fresh2 as isize) = ref_0[i as usize] + } + i = i.wrapping_add(1) + } + } + err = crate::stdlib::snd_pcm_close(pcm); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d snd_pcm_close error: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"test_open\x00")).as_ptr(), + 304 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + return 0 as libc::c_int != 0; + } + return 1 as libc::c_int != 0; +} + +unsafe extern "C" fn pcm_probe(mut device: *const libc::c_char) -> bool { + let mut err: libc::c_int = 0; + let mut pcm = 0 as *mut crate::stdlib::snd_pcm_t; + err = crate::stdlib::snd_pcm_open( + &mut pcm, + device, + crate::stdlib::SND_PCM_STREAM_PLAYBACK, + 0 as libc::c_int, + ); + if err < 0 as libc::c_int { + return 0 as libc::c_int != 0; + } + err = crate::stdlib::snd_pcm_close(pcm); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d snd_pcm_close error: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"pcm_probe\x00")).as_ptr(), + 320 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + } + return 1 as libc::c_int != 0; +} + +unsafe extern "C" fn alsa_open( + mut device: *const libc::c_char, + mut sample_rate: libc::c_uint, + mut alsa_buffer: libc::c_uint, + mut alsa_period: libc::c_uint, +) -> libc::c_int { + let mut err: libc::c_int = 0; + let mut hw_params = 0 as *mut crate::stdlib::snd_pcm_hw_params_t; + let mut fresh3 = ::std::vec::from_elem(0, crate::stdlib::snd_pcm_hw_params_sizeof() as usize); + hw_params = fresh3.as_mut_ptr() as *mut crate::stdlib::snd_pcm_hw_params_t; + crate::stdlib::memset( + hw_params as *mut libc::c_void, + 0 as libc::c_int, + crate::stdlib::snd_pcm_hw_params_sizeof(), + ); + // close if already open + if !pcmp.is_null() { + alsa_close(); + } + // reset params + alsa.rate = 0 as libc::c_int as libc::c_uint; + alsa.period_size = 0 as libc::c_int as crate::stdlib::snd_pcm_uframes_t; + crate::stdlib::strcpy(alsa.device.as_mut_ptr(), device); + if crate::stdlib::strlen(device) + > (128 as libc::c_int - 4 as libc::c_int - 1 as libc::c_int) as libc::c_ulong + { + crate::src::utils::logprint( + b"%s %s:%d device name too long: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"alsa_open\x00")).as_ptr(), + 347 as libc::c_int, + device, + ); + return -(1 as libc::c_int); + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d opening device at: %u\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"alsa_open\x00")).as_ptr(), + 351 as libc::c_int, + sample_rate, + ); + } + let mut retry: bool = false; + loop { + // open device + err = crate::stdlib::snd_pcm_open( + &mut pcmp, + alsa.device.as_mut_ptr(), + crate::stdlib::SND_PCM_STREAM_PLAYBACK, + 0 as libc::c_int, + ); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d playback open error: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"alsa_open\x00")) + .as_ptr(), + 357 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + return err; + } + // init params + crate::stdlib::memset( + hw_params as *mut libc::c_void, + 0 as libc::c_int, + crate::stdlib::snd_pcm_hw_params_sizeof(), + ); + err = crate::stdlib::snd_pcm_hw_params_any(pcmp, hw_params); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d hwparam init error: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"alsa_open\x00")) + .as_ptr(), + 364 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + return err; + } + // open hw: devices without resampling, if sample rate fails try plughw: with resampling + let mut hw = crate::stdlib::strncmp( + alsa.device.as_mut_ptr(), + b"hw:\x00" as *const u8 as *const libc::c_char, + 3 as libc::c_int as libc::c_ulong, + ) == 0; + retry = 0 as libc::c_int != 0; + err = crate::stdlib::snd_pcm_hw_params_set_rate_resample( + pcmp, + hw_params, + !hw as libc::c_int as libc::c_uint, + ); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d resampling setup failed: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"alsa_open\x00")) + .as_ptr(), + 373 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + return err; + } + err = crate::stdlib::snd_pcm_hw_params_set_rate( + pcmp, + hw_params, + sample_rate, + 0 as libc::c_int, + ); + if err < 0 as libc::c_int { + if hw { + crate::stdlib::strcpy( + alsa.device.as_mut_ptr().offset(4 as libc::c_int as isize), + device, + ); + crate::stdlib::memcpy( + alsa.device.as_mut_ptr() as *mut libc::c_void, + b"plug\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ); + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d reopening device %s in plug mode as %s for resampling\n\x00" + as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>( + b"alsa_open\x00", + )) + .as_ptr(), + 381 as libc::c_int, + device, + alsa.device.as_mut_ptr(), + ); + } + crate::stdlib::snd_pcm_close(pcmp); + retry = 1 as libc::c_int != 0 + } + } + if !retry { + break; + } + } + // set access + if !alsa.mmap + || crate::stdlib::snd_pcm_hw_params_set_access( + pcmp, + hw_params, + crate::stdlib::SND_PCM_ACCESS_MMAP_INTERLEAVED, + ) < 0 as libc::c_int + { + err = crate::stdlib::snd_pcm_hw_params_set_access( + pcmp, + hw_params, + crate::stdlib::SND_PCM_ACCESS_RW_INTERLEAVED, + ); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d access type not available: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"alsa_open\x00")) + .as_ptr(), + 392 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + return err; + } + alsa.mmap = 0 as libc::c_int != 0 + } + // set the sample format + let mut fmt = if alsa.format as libc::c_int != 0 { + &mut alsa.format + } else { + fmts.as_mut_ptr() + }; + loop { + if crate::stdlib::snd_pcm_hw_params_set_format(pcmp, hw_params, *fmt) >= 0 as libc::c_int { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d opened device %s using format: %s sample rate: %u mmap: %u\n\x00" + as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"alsa_open\x00")) + .as_ptr(), + 422 as libc::c_int, + alsa.device.as_mut_ptr(), + crate::stdlib::snd_pcm_format_name(*fmt), + sample_rate, + alsa.mmap as libc::c_int, + ); + } + alsa.format = *fmt; + break; + } else { + if alsa.format as u64 != 0 { + crate::src::utils::logprint( + b"%s %s:%d unable to open audio device requested format: %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"alsa_open\x00")) + .as_ptr(), + 427 as libc::c_int, + crate::stdlib::snd_pcm_format_name(alsa.format), + ); + return -(1 as libc::c_int); + } + fmt = fmt.offset(1); + if *fmt as libc::c_int == crate::stdlib::SND_PCM_FORMAT_UNKNOWN as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d unable to open audio device with any supported format\n\x00" + as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"alsa_open\x00")) + .as_ptr(), + 432 as libc::c_int, + ); + return -(1 as libc::c_int); + } + if !(*fmt as libc::c_int != crate::stdlib::SND_PCM_FORMAT_UNKNOWN as libc::c_int) { + break; + } + } + } + // set the output format to be used by _scale_and_pack + match alsa.format as libc::c_int { + 10 => output.format = crate::squeezelite_h::S32_LE, + 6 => output.format = crate::squeezelite_h::S24_LE, + 32 => output.format = crate::squeezelite_h::S24_3LE, + 2 => output.format = crate::squeezelite_h::S16_LE, + _ => {} + } + // set channels + err = crate::stdlib::snd_pcm_hw_params_set_channels( + pcmp, + hw_params, + 2 as libc::c_int as libc::c_uint, + ); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d channel count not available: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"alsa_open\x00")).as_ptr(), + 465 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + return err; + } + // set period size - value of < 50 treated as period count, otherwise size in bytes + if alsa_period < 50 as libc::c_int as libc::c_uint { + let mut count = alsa_period; + err = crate::stdlib::snd_pcm_hw_params_set_periods_near( + pcmp, + hw_params, + &mut count, + 0 as *mut libc::c_int, + ); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d unable to set period count %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"alsa_open\x00")) + .as_ptr(), + 473 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + return err; + } + } else { + let mut size = alsa_period as crate::stdlib::snd_pcm_uframes_t; + let mut dir = 0 as libc::c_int; + err = crate::stdlib::snd_pcm_hw_params_set_period_size_near( + pcmp, hw_params, &mut size, &mut dir, + ); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d unable to set period size %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"alsa_open\x00")) + .as_ptr(), + 480 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + return err; + } + } + // set buffer size - value of < 500 treated as buffer time in ms, otherwise size in bytes + if alsa_buffer < 500 as libc::c_int as libc::c_uint { + let mut time = alsa_buffer.wrapping_mul(1000 as libc::c_int as libc::c_uint); + let mut dir_0 = 0 as libc::c_int; + err = crate::stdlib::snd_pcm_hw_params_set_buffer_time_near( + pcmp, hw_params, &mut time, &mut dir_0, + ); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d unable to set buffer time %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"alsa_open\x00")) + .as_ptr(), + 490 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + return err; + } + } else { + let mut size_0 = alsa_buffer as crate::stdlib::snd_pcm_uframes_t; + err = crate::stdlib::snd_pcm_hw_params_set_buffer_size_near(pcmp, hw_params, &mut size_0); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d unable to set buffer size %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"alsa_open\x00")) + .as_ptr(), + 496 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + return err; + } + } + // get period_size + err = crate::stdlib::snd_pcm_hw_params_get_period_size( + hw_params, + &mut alsa.period_size, + 0 as *mut libc::c_int, + ); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d unable to get period size: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"alsa_open\x00")).as_ptr(), + 503 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + return err; + } + // get buffer_size + err = crate::stdlib::snd_pcm_hw_params_get_buffer_size(hw_params, &mut alsa.buffer_size); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d unable to get buffer size: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"alsa_open\x00")).as_ptr(), + 509 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + return err; + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d buffer: %u period: %u -> buffer size: %u period size: %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"alsa_open\x00")).as_ptr(), + 513 as libc::c_int, + alsa_buffer, + alsa_period, + alsa.buffer_size, + alsa.period_size, + ); + } + // ensure we have two buffer sizes of samples before starting output + output.start_frames = alsa + .buffer_size + .wrapping_mul(2 as libc::c_int as libc::c_ulong) as libc::c_uint; + // create an intermediate buffer for non mmap case for all but NATIVE_FORMAT + // this is used to pack samples into the output format before calling writei + if !alsa.mmap + && alsa.write_buf.is_null() + && alsa.format as libc::c_int != crate::stdlib::SND_PCM_FORMAT_S32_LE as libc::c_int + { + alsa.write_buf = crate::stdlib::malloc( + alsa.buffer_size + .wrapping_mul(8 as libc::c_int as libc::c_ulong), + ) as *mut crate::squeezelite_h::u8_t; + if alsa.write_buf.is_null() { + crate::src::utils::logprint( + b"%s %s:%d unable to malloc write_buf\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"alsa_open\x00")) + .as_ptr(), + 523 as libc::c_int, + ); + return -(1 as libc::c_int); + } + } + // set params + err = crate::stdlib::snd_pcm_hw_params(pcmp, hw_params); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d unable to set hw params: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"alsa_open\x00")).as_ptr(), + 530 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + return err; + } + // dump info + if loglevel as libc::c_uint == crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint { + static mut debug_output: *mut crate::stdlib::snd_output_t = + 0 as *const crate::stdlib::snd_output_t as *mut crate::stdlib::snd_output_t; + crate::stdlib::snd_output_stdio_attach( + &mut debug_output, + crate::stdlib::stderr, + 0 as libc::c_int, + ); + crate::stdlib::snd_pcm_dump(pcmp, debug_output); + } + // this indicates we have opened the device ok + alsa.rate = sample_rate; + return 0 as libc::c_int; +} + +unsafe extern "C" fn _write_frames( + mut out_frames: crate::squeezelite_h::frames_t, + mut silence: bool, + mut gainL: crate::squeezelite_h::s32_t, + mut gainR: crate::squeezelite_h::s32_t, + mut cross_gain_in: crate::squeezelite_h::s32_t, + mut cross_gain_out: crate::squeezelite_h::s32_t, + mut cross_ptr: *mut *mut crate::squeezelite_h::s32_t, +) -> libc::c_int { + let mut areas = 0 as *const crate::stdlib::snd_pcm_channel_area_t; + let mut offset: crate::stdlib::snd_pcm_uframes_t = 0; + let mut outputptr = 0 as *mut libc::c_void; + let mut inputptr = 0 as *mut crate::squeezelite_h::s32_t; + let mut err: libc::c_int = 0; + if alsa.mmap { + let mut alsa_frames = out_frames as crate::stdlib::snd_pcm_uframes_t; + crate::stdlib::snd_pcm_avail_update(pcmp); + err = crate::stdlib::snd_pcm_mmap_begin(pcmp, &mut areas, &mut offset, &mut alsa_frames); + if err < 0 as libc::c_int { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d error from mmap_begin: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"_write_frames\x00", + )) + .as_ptr(), + 565 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + } + return -(1 as libc::c_int); + } + out_frames = alsa_frames as crate::squeezelite_h::frames_t + } + if !silence { + // applying cross fade is delayed until this point as mmap_begin can change out_frames + if output.fade as libc::c_uint + == crate::squeezelite_h::FADE_ACTIVE as libc::c_int as libc::c_uint + && output.fade_dir as libc::c_uint + == crate::squeezelite_h::FADE_CROSS as libc::c_int as libc::c_uint + && !(*cross_ptr).is_null() + { + crate::squeezelite_h::_apply_cross( + outputbuf, + out_frames, + cross_gain_in, + cross_gain_out, + cross_ptr, + ); + } + } + inputptr = if silence as libc::c_int != 0 { + silencebuf + } else { + (*outputbuf).readp + } as *mut crate::squeezelite_h::s32_t; + if alsa.mmap as libc::c_int != 0 + || alsa.format as libc::c_int != crate::stdlib::SND_PCM_FORMAT_S32_LE as libc::c_int + { + outputptr = if alsa.mmap as libc::c_int != 0 { + (*areas.offset(0 as libc::c_int as isize)).addr.offset( + ((*areas.offset(0 as libc::c_int as isize)).first as libc::c_ulong) + .wrapping_add(offset.wrapping_mul( + (*areas.offset(0 as libc::c_int as isize)).step as libc::c_ulong, + )) + .wrapping_div(8 as libc::c_int as libc::c_ulong) as isize, + ) + } else { + alsa.write_buf as *mut libc::c_void + }; + crate::src::output_pack::_scale_and_pack_frames( + outputptr, + inputptr, + out_frames, + gainL, + gainR, + output.format, + ); + } else { + outputptr = inputptr as *mut libc::c_void; + if !silence { + if gainL != 0x10000 as libc::c_int || gainR != 0x10000 as libc::c_int { + crate::squeezelite_h::_apply_gain(outputbuf, out_frames, gainL, gainR); + } + } + } + if alsa.mmap { + let mut w = crate::stdlib::snd_pcm_mmap_commit( + pcmp, + offset, + out_frames as crate::stdlib::snd_pcm_uframes_t, + ); + if w < 0 as libc::c_int as libc::c_long || w != out_frames as libc::c_long { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d mmap_commit error\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"_write_frames\x00", + )) + .as_ptr(), + 615 as libc::c_int, + ); + } + return -(1 as libc::c_int); + } + } else { + let mut w_0 = crate::stdlib::snd_pcm_writei( + pcmp, + outputptr, + out_frames as crate::stdlib::snd_pcm_uframes_t, + ); + if w_0 < 0 as libc::c_int as libc::c_long { + //if (w != -EAGAIN && ((err = snd_pcm_recover(pcmp, w, 1)) < 0)) { + err = crate::stdlib::snd_pcm_recover(pcmp, w_0 as libc::c_int, 1 as libc::c_int); + if err < 0 as libc::c_int { + static mut recover_count: libc::c_uint = 0 as libc::c_int as libc::c_uint; + if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + recover_count = recover_count.wrapping_add(1); + crate::src::utils::logprint( + b"%s %s:%d recover failed: %s [%u]\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"_write_frames\x00", + )) + .as_ptr(), + 626 as libc::c_int, + crate::stdlib::snd_strerror(err), + recover_count, + ); + } + if recover_count >= 10 as libc::c_int as libc::c_uint { + recover_count = 0 as libc::c_int as libc::c_uint; + alsa_close(); + pcmp = 0 as *mut crate::stdlib::snd_pcm_t + } + } + return -(1 as libc::c_int); + } else { + if w_0 != out_frames as libc::c_long { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d writei only wrote %u of %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"_write_frames\x00", + )) + .as_ptr(), + 636 as libc::c_int, + w_0, + out_frames, + ); + } + } + out_frames = w_0 as crate::squeezelite_h::frames_t + } + } + return out_frames as libc::c_int; +} + +unsafe extern "C" fn output_thread(mut arg: *mut libc::c_void) -> *mut libc::c_void { + let mut start = 1 as libc::c_int != 0; + let mut output_off = + output.state as libc::c_int == crate::squeezelite_h::OUTPUT_OFF as libc::c_int; + let mut probe_device = !arg.is_null(); + let mut err: libc::c_int = 0; + while running { + // disabled output - player is off + while output_off { + crate::stdlib::usleep(100000 as libc::c_int as crate::stdlib::__useconds_t); + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + output_off = + output.state as libc::c_int == crate::squeezelite_h::OUTPUT_OFF as libc::c_int; + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + if !running { + return 0 as *mut libc::c_void; + } + } + // wait until device returns - to allow usb audio devices to be turned off + if probe_device { + while !pcm_probe(output.device) { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d waiting for device %s to return\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"output_thread\x00", + )) + .as_ptr(), + 665 as libc::c_int, + output.device, + ); + } + crate::stdlib::sleep(5 as libc::c_int as libc::c_uint); + } + probe_device = 0 as libc::c_int != 0 + } + if pcmp.is_null() || alsa.rate != output.current_sample_rate { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d open output device: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"output_thread\x00", + )) + .as_ptr(), + 687 as libc::c_int, + output.device, + ); + } + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + // FIXME - some alsa hardware requires opening twice for a new sample rate to work + // this is a workaround which should be removed + if alsa.reopen { + alsa_open( + output.device, + output.current_sample_rate, + output.buffer, + output.period, + ); + } + if alsa_open( + output.device, + output.current_sample_rate, + output.buffer, + output.period, + ) != 0 + { + output.error_opening = 1 as libc::c_int != 0; + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + crate::stdlib::sleep(5 as libc::c_int as libc::c_uint); + continue; + } else { + output.error_opening = 0 as libc::c_int != 0; + start = 1 as libc::c_int != 0; + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + } + } + let mut state = crate::stdlib::snd_pcm_state(pcmp); + if state as libc::c_uint == crate::stdlib::SND_PCM_STATE_XRUN as libc::c_int as libc::c_uint + { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d XRUN\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"output_thread\x00", + )) + .as_ptr(), + 717 as libc::c_int, + ); + } + err = crate::stdlib::snd_pcm_recover(pcmp, -(32 as libc::c_int), 1 as libc::c_int); + if err < 0 as libc::c_int { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d XRUN recover failed: %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"output_thread\x00", + )) + .as_ptr(), + 719 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + } + } + start = 1 as libc::c_int != 0 + } else { + if state as libc::c_uint + == crate::stdlib::SND_PCM_STATE_SUSPENDED as libc::c_int as libc::c_uint + { + err = crate::stdlib::snd_pcm_recover(pcmp, -(86 as libc::c_int), 1 as libc::c_int); + if err < 0 as libc::c_int { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d SUSPEND recover failed: %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"output_thread\x00", + )) + .as_ptr(), + 725 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + } + } + } else if state as libc::c_uint + == crate::stdlib::SND_PCM_STATE_DISCONNECTED as libc::c_int as libc::c_uint + { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d Device %s no longer available\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"output_thread\x00", + )) + .as_ptr(), + 728 as libc::c_int, + output.device, + ); + } + alsa_close(); + pcmp = 0 as *mut crate::stdlib::snd_pcm_t; + probe_device = 1 as libc::c_int != 0; + continue; + } + let mut avail = crate::stdlib::snd_pcm_avail_update(pcmp); + if avail < 0 as libc::c_int as libc::c_long { + err = crate::stdlib::snd_pcm_recover(pcmp, avail as libc::c_int, 1 as libc::c_int); + if err < 0 as libc::c_int { + if err == -(19 as libc::c_int) { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d Device %s no longer available\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"output_thread\x00", + )) + .as_ptr(), + 740 as libc::c_int, + output.device, + ); + } + alsa_close(); + pcmp = 0 as *mut crate::stdlib::snd_pcm_t; + probe_device = 1 as libc::c_int != 0; + continue; + } else if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d recover failed: %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"output_thread\x00", + )) + .as_ptr(), + 746 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + } + } + start = 1 as libc::c_int != 0 + } else if (avail as libc::c_ulong) < alsa.period_size { + if start { + if alsa.mmap as libc::c_int != 0 && { + err = crate::stdlib::snd_pcm_start(pcmp); + (err) < 0 as libc::c_int + } { + err = crate::stdlib::snd_pcm_recover(pcmp, err, 1 as libc::c_int); + if !(err < 0 as libc::c_int) { + continue; + } + if err == -(19 as libc::c_int) { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d Device %s no longer available\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"output_thread\x00", + )) + .as_ptr(), + 757 as libc::c_int, + output.device, + ); + } + alsa_close(); + pcmp = 0 as *mut crate::stdlib::snd_pcm_t; + probe_device = 1 as libc::c_int != 0 + } else { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d start error: %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"output_thread\x00", + )) + .as_ptr(), + 763 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + } + crate::stdlib::usleep( + 10000 as libc::c_int as crate::stdlib::__useconds_t, + ); + } + } else { + start = 0 as libc::c_int != 0 + } + } else { + crate::stdlib::usleep(10000 as libc::c_int as crate::stdlib::__useconds_t); + err = crate::stdlib::snd_pcm_wait(pcmp, 1000 as libc::c_int); + if err <= 0 as libc::c_int { + if err == 0 as libc::c_int { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d pcm wait timeout\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"output_thread\x00", + )) + .as_ptr(), + 773 as libc::c_int, + ); + } + } + err = crate::stdlib::snd_pcm_recover(pcmp, err, 1 as libc::c_int); + if err < 0 as libc::c_int { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d pcm wait error: %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"output_thread\x00", + )) + .as_ptr(), + 776 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + } + } + start = 1 as libc::c_int != 0 + } + } + } else { + // restrict avail to within sensible limits as alsa drivers can return erroneous large values + // in writei mode restrict to period_size due to size of write_buf + if alsa.mmap { + avail = if (avail as libc::c_ulong) < alsa.buffer_size { + avail as libc::c_ulong + } else { + alsa.buffer_size + } as crate::stdlib::snd_pcm_sframes_t + } else { + avail = if (avail as libc::c_ulong) < alsa.period_size { + avail as libc::c_ulong + } else { + alsa.period_size + } as crate::stdlib::snd_pcm_sframes_t + } + // avoid spinning in cases where wait returns but no bytes available (seen with pulse audio) + if avail == 0 as libc::c_int as libc::c_long { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d avail 0 - sleeping\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"output_thread\x00", + )) + .as_ptr(), + 794 as libc::c_int, + ); + } + crate::stdlib::usleep(10000 as libc::c_int as crate::stdlib::__useconds_t); + } else { + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + // turn off if requested + if output.state as libc::c_int + == crate::squeezelite_h::OUTPUT_OFF as libc::c_int + { + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d disabling output\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"output_thread\x00", + )) + .as_ptr(), + 804 as libc::c_int, + ); + } + alsa_close(); + pcmp = 0 as *mut crate::stdlib::snd_pcm_t; + output_off = 1 as libc::c_int != 0 + } else { + // measure output delay + let mut delay: crate::stdlib::snd_pcm_sframes_t = 0; + err = crate::stdlib::snd_pcm_delay(pcmp, &mut delay); + if err < 0 as libc::c_int { + if err == -(32 as libc::c_int) { + // EPIPE indicates underrun - attempt to recover + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + continue; + } else if err == -(5 as libc::c_int) { + // EIO can occur with non existant pulse server + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + if loglevel as libc::c_uint + >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d snd_pcm_delay returns: EIO - sleeping\n\x00" + as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"output_thread\x00", + )) + .as_ptr(), + 833 as libc::c_int, + ); + } + crate::stdlib::usleep( + 100000 as libc::c_int as crate::stdlib::__useconds_t, + ); + continue; + } else if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d snd_pcm_delay returns: %d\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"output_thread\x00", + )) + .as_ptr(), + 837 as libc::c_int, + err, + ); + } + } else { + output.device_frames = delay as libc::c_uint; + output.updated = crate::src::utils::gettime_ms(); + output.frames_played_dmp = output.frames_played + } + // process frames + let mut wrote = crate::src::output::_output_frames( + avail as crate::squeezelite_h::frames_t, + ); + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + // some output devices such as alsa null refuse any data, avoid spinning + if wrote == 0 { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d wrote 0 - sleeping\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"output_thread\x00", + )) + .as_ptr(), + 852 as libc::c_int, + ); + } + crate::stdlib::usleep( + 10000 as libc::c_int as crate::stdlib::__useconds_t, + ); + } + } + } + } + } + } + return 0 as *mut libc::c_void; +} +#[no_mangle] + +pub unsafe extern "C" fn mixer_init_alsa( + mut device: *const libc::c_char, + mut mixer: *const libc::c_char, + mut mixer_index: libc::c_int, +) -> libc::c_int { + let mut err: libc::c_int = 0; + let mut sid = 0 as *mut crate::stdlib::snd_mixer_selem_id_t; + err = crate::stdlib::snd_mixer_open(&mut alsa.mixer_handle, 0 as libc::c_int); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d open error: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>(b"mixer_init_alsa\x00")) + .as_ptr(), + 865 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + return -(1 as libc::c_int); + } + err = crate::stdlib::snd_mixer_attach(alsa.mixer_handle, device); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d attach error: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>(b"mixer_init_alsa\x00")) + .as_ptr(), + 869 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + crate::stdlib::snd_mixer_close(alsa.mixer_handle); + return -(1 as libc::c_int); + } + err = crate::stdlib::snd_mixer_selem_register( + alsa.mixer_handle, + 0 as *mut crate::stdlib::snd_mixer_selem_regopt, + 0 as *mut *mut crate::stdlib::snd_mixer_class_t, + ); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d register error: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>(b"mixer_init_alsa\x00")) + .as_ptr(), + 874 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + crate::stdlib::snd_mixer_close(alsa.mixer_handle); + return -(1 as libc::c_int); + } + err = crate::stdlib::snd_mixer_load(alsa.mixer_handle); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d load error: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>(b"mixer_init_alsa\x00")) + .as_ptr(), + 879 as libc::c_int, + crate::stdlib::snd_strerror(err), + ); + crate::stdlib::snd_mixer_close(alsa.mixer_handle); + return -(1 as libc::c_int); + } + let mut fresh4 = ::std::vec::from_elem(0, crate::stdlib::snd_mixer_selem_id_sizeof() as usize); + sid = fresh4.as_mut_ptr() as *mut crate::stdlib::snd_mixer_selem_id_t; + crate::stdlib::memset( + sid as *mut libc::c_void, + 0 as libc::c_int, + crate::stdlib::snd_mixer_selem_id_sizeof(), + ); + crate::stdlib::snd_mixer_selem_id_set_index(sid, mixer_index as libc::c_uint); + crate::stdlib::snd_mixer_selem_id_set_name(sid, mixer); + alsa.mixer_elem = crate::stdlib::snd_mixer_find_selem(alsa.mixer_handle, sid); + if alsa.mixer_elem.is_null() { + crate::src::utils::logprint( + b"%s %s:%d error find selem %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>(b"mixer_init_alsa\x00")) + .as_ptr(), + 889 as libc::c_int, + alsa.mixer_handle, + ); + crate::stdlib::snd_mixer_close(alsa.mixer_handle); + return -(1 as libc::c_int); + } + if crate::stdlib::snd_mixer_selem_has_playback_switch(alsa.mixer_elem) != 0 { + crate::stdlib::snd_mixer_selem_set_playback_switch_all(alsa.mixer_elem, 1 as libc::c_int); + // unmute + } + err = crate::stdlib::snd_mixer_selem_get_playback_dB_range( + alsa.mixer_elem, + &mut alsa.mixer_min, + &mut alsa.mixer_max, + ); + if err < 0 as libc::c_int + || alsa.mixer_max - alsa.mixer_min < 1000 as libc::c_int as libc::c_long + || alsa.mixer_linear as libc::c_int != 0 + { + alsa.mixer_linear = 1 as libc::c_int != 0; + // unable to get db range or range is less than 10dB - ignore and set using raw values + err = crate::stdlib::snd_mixer_selem_get_playback_volume_range( + alsa.mixer_elem, + &mut alsa.mixer_min, + &mut alsa.mixer_max, + ); + if err < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d Unable to get volume raw range\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>(b"mixer_init_alsa\x00")) + .as_ptr(), + 905 as libc::c_int, + ); + return -(1 as libc::c_int); + } + } + return 0 as libc::c_int; +} + +static mut thread: crate::stdlib::pthread_t = 0; +#[no_mangle] + +pub unsafe extern "C" fn output_init_alsa( + mut level: crate::squeezelite_h::log_level, + mut device: *const libc::c_char, + mut output_buf_size: libc::c_uint, + mut params: *mut libc::c_char, + mut rates: *mut libc::c_uint, + mut rate_delay: libc::c_uint, + mut rt_priority: libc::c_uint, + mut idle: libc::c_uint, + mut mixer_device: *mut libc::c_char, + mut volume_mixer: *mut libc::c_char, + mut mixer_unmute: bool, + mut mixer_linear: bool, +) { + let mut alsa_buffer = 40 as libc::c_int as libc::c_uint; + let mut alsa_period = 4 as libc::c_int as libc::c_uint; + let mut alsa_sample_fmt = 0 as *mut libc::c_char; + let mut alsa_mmap = 1 as libc::c_int != 0; + let mut alsa_reopen = 0 as libc::c_int != 0; + let mut volume_mixer_name = + crate::src::utils::next_param(volume_mixer, ',' as i32 as libc::c_char); + let mut volume_mixer_index = + crate::src::utils::next_param(0 as *mut libc::c_char, ',' as i32 as libc::c_char); + let mut t = crate::src::utils::next_param(params, ':' as i32 as libc::c_char); + let mut c = crate::src::utils::next_param(0 as *mut libc::c_char, ':' as i32 as libc::c_char); + let mut s = crate::src::utils::next_param(0 as *mut libc::c_char, ':' as i32 as libc::c_char); + let mut m = crate::src::utils::next_param(0 as *mut libc::c_char, ':' as i32 as libc::c_char); + let mut r = crate::src::utils::next_param(0 as *mut libc::c_char, ':' as i32 as libc::c_char); + if !t.is_null() { + alsa_buffer = crate::stdlib::atoi(t) as libc::c_uint + } + if !c.is_null() { + alsa_period = crate::stdlib::atoi(c) as libc::c_uint + } + if !s.is_null() { + alsa_sample_fmt = s + } + if !m.is_null() { + alsa_mmap = crate::stdlib::atoi(m) != 0 + } + if !r.is_null() { + alsa_reopen = crate::stdlib::atoi(r) != 0 + } + loglevel = level; + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d init output\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 17], &[libc::c_char; 17]>(b"output_init_alsa\x00")) + .as_ptr(), + 939 as libc::c_int, + ); + } + crate::stdlib::memset( + &mut output as *mut crate::squeezelite_h::outputstate as *mut libc::c_void, + 0 as libc::c_int, + ::std::mem::size_of::() as libc::c_ulong, + ); + alsa.mmap = alsa_mmap; + alsa.write_buf = 0 as *mut crate::squeezelite_h::u8_t; + alsa.format = crate::stdlib::SND_PCM_FORMAT_S8; + alsa.reopen = alsa_reopen; + alsa.mixer_handle = 0 as *mut crate::stdlib::snd_mixer_t; + alsa.ctl = ctl4device(device); + alsa.mixer_ctl = if !mixer_device.is_null() { + ctl4device(mixer_device) + } else { + alsa.ctl + }; + alsa.volume_mixer_name = volume_mixer_name; + alsa.mixer_linear = mixer_linear; + output.format = crate::squeezelite_h::S32_LE; + output.buffer = alsa_buffer; + output.period = alsa_period; + output.start_frames = 0 as libc::c_int as libc::c_uint; + output.write_cb = Some( + _write_frames + as unsafe extern "C" fn( + _: crate::squeezelite_h::frames_t, + _: bool, + _: crate::squeezelite_h::s32_t, + _: crate::squeezelite_h::s32_t, + _: crate::squeezelite_h::s32_t, + _: crate::squeezelite_h::s32_t, + _: *mut *mut crate::squeezelite_h::s32_t, + ) -> libc::c_int, + ); + output.rate_delay = rate_delay; + if !alsa_sample_fmt.is_null() { + if crate::stdlib::strcmp( + alsa_sample_fmt, + b"32\x00" as *const u8 as *const libc::c_char, + ) == 0 + { + alsa.format = crate::stdlib::SND_PCM_FORMAT_S32_LE + } + if crate::stdlib::strcmp( + alsa_sample_fmt, + b"24\x00" as *const u8 as *const libc::c_char, + ) == 0 + { + alsa.format = crate::stdlib::SND_PCM_FORMAT_S24_LE + } + if crate::stdlib::strcmp( + alsa_sample_fmt, + b"24_3\x00" as *const u8 as *const libc::c_char, + ) == 0 + { + alsa.format = crate::stdlib::SND_PCM_FORMAT_S24_3LE + } + if crate::stdlib::strcmp( + alsa_sample_fmt, + b"16\x00" as *const u8 as *const libc::c_char, + ) == 0 + { + alsa.format = crate::stdlib::SND_PCM_FORMAT_S16_LE + } + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d requested alsa_buffer: %u alsa_period: %u format: %s mmap: %u\n\x00" + as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 17], &[libc::c_char; 17]>(b"output_init_alsa\x00")) + .as_ptr(), + 979 as libc::c_int, + output.buffer, + output.period, + if !alsa_sample_fmt.is_null() { + alsa_sample_fmt as *const libc::c_char + } else { + b"any\x00" as *const u8 as *const libc::c_char + }, + alsa.mmap as libc::c_int, + ); + } + crate::stdlib::snd_lib_error_set_handler(::std::mem::transmute::< + Option< + unsafe extern "C" fn( + _: *const libc::c_char, + _: libc::c_int, + _: *const libc::c_char, + _: libc::c_int, + _: *const libc::c_char, + _: ... + ) -> *mut libc::c_void, + >, + crate::stdlib::snd_lib_error_handler_t, + >(Some( + alsa_error_handler + as unsafe extern "C" fn( + _: *const libc::c_char, + _: libc::c_int, + _: *const libc::c_char, + _: libc::c_int, + _: *const libc::c_char, + _: ... + ) -> *mut libc::c_void, + ))); + crate::src::output::output_init_common(level, device, output_buf_size, rates, idle); + if !volume_mixer_name.is_null() { + if mixer_init_alsa( + alsa.mixer_ctl, + alsa.volume_mixer_name, + (if !volume_mixer_index.is_null() { + crate::stdlib::atoi(volume_mixer_index) + } else { + 0 as libc::c_int + }), + ) < 0 as libc::c_int + { + crate::src::utils::logprint( + b"%s %s:%d Initialization of mixer failed, reverting to software volume\n\x00" + as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 17], &[libc::c_char; 17]>(b"output_init_alsa\x00")) + .as_ptr(), + 989 as libc::c_int, + ); + alsa.mixer_handle = 0 as *mut crate::stdlib::snd_mixer_t; + alsa.volume_mixer_name = 0 as *const libc::c_char + } + } + if mixer_unmute as libc::c_int != 0 && !alsa.volume_mixer_name.is_null() { + set_mixer( + 1 as libc::c_int != 0, + 0 as libc::c_int as libc::c_float, + 0 as libc::c_int as libc::c_float, + ); + alsa.volume_mixer_name = 0 as *const libc::c_char + } + // RT linux - aim to avoid pagefaults by locking memory: + // https://rt.wiki.kernel.org/index.php/Threaded_RT-application_with_memory_locking_and_stack_handling_example + if crate::stdlib::mlockall(1 as libc::c_int | 2 as libc::c_int) == -(1 as libc::c_int) { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d unable to lock memory: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 17], &[libc::c_char; 17]>(b"output_init_alsa\x00")) + .as_ptr(), + 1003 as libc::c_int, + crate::stdlib::strerror(*crate::stdlib::__errno_location()), + ); + } + } else if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d memory locked\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 17], &[libc::c_char; 17]>(b"output_init_alsa\x00")) + .as_ptr(), + 1005 as libc::c_int, + ); + } + crate::stdlib::mallopt(-(1 as libc::c_int), -(1 as libc::c_int)); + crate::stdlib::mallopt(-(4 as libc::c_int), 0 as libc::c_int); + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d glibc detected using mallopt\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 17], &[libc::c_char; 17]>(b"output_init_alsa\x00")) + .as_ptr(), + 1011 as libc::c_int, + ); + } + crate::src::utils::touch_memory( + silencebuf, + (2048 as libc::c_int * 8 as libc::c_int) as crate::stddef_h::size_t, + ); + crate::src::utils::touch_memory((*outputbuf).buf, (*outputbuf).size); + // start output thread + let mut attr = crate::stdlib::pthread_attr_t { __size: [0; 56] }; + crate::stdlib::pthread_attr_init(&mut attr); + crate::stdlib::pthread_attr_setstacksize( + &mut attr, + (16384 as libc::c_int + 64 as libc::c_int * 1024 as libc::c_int) as crate::stddef_h::size_t, + ); + crate::stdlib::pthread_create( + &mut thread, + &mut attr, + Some(output_thread as unsafe extern "C" fn(_: *mut libc::c_void) -> *mut libc::c_void), + if *rates.offset(0 as libc::c_int as isize) != 0 { + b"probe\x00" as *const u8 as *const libc::c_char + } else { + 0 as *const libc::c_char + } as *mut libc::c_void, + ); + crate::stdlib::pthread_attr_destroy(&mut attr); + // try to set this thread to real-time scheduler class, only works as root or if user has permission + let mut param = crate::stdlib::sched_param { sched_priority: 0 }; + param.sched_priority = rt_priority as libc::c_int; + if crate::stdlib::pthread_setschedparam(thread, 1 as libc::c_int, &mut param) + != 0 as libc::c_int + { + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d unable to set output sched fifo: %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 17], &[libc::c_char; 17]>(b"output_init_alsa\x00")) + .as_ptr(), + 1029 as libc::c_int, + crate::stdlib::strerror(*crate::stdlib::__errno_location()), + ); + } + } else if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d set output sched fifo rt: %u\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 17], &[libc::c_char; 17]>(b"output_init_alsa\x00")) + .as_ptr(), + 1031 as libc::c_int, + param.sched_priority, + ); + }; +} +#[no_mangle] + +pub unsafe extern "C" fn output_close_alsa() { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d close output\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 18], &[libc::c_char; 18]>(b"output_close_alsa\x00")) + .as_ptr(), + 1036 as libc::c_int, + ); + } + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + running = 0 as libc::c_int != 0; + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + crate::stdlib::pthread_join(thread, 0 as *mut *mut libc::c_void); + if !alsa.write_buf.is_null() { + crate::stdlib::free(alsa.write_buf as *mut libc::c_void); + } + if !alsa.ctl.is_null() { + crate::stdlib::free(alsa.ctl as *mut libc::c_void); + } + if !alsa.mixer_ctl.is_null() { + crate::stdlib::free(alsa.mixer_ctl as *mut libc::c_void); + } + if !alsa.mixer_handle.is_null() { + crate::stdlib::snd_mixer_close(alsa.mixer_handle); + } + crate::src::output::output_close_common(); +} +// ALSA diff --git a/src/output_pa.rs b/src/output_pa.rs new file mode 100644 index 0000000..f86a2d8 --- /dev/null +++ b/src/output_pa.rs @@ -0,0 +1,23 @@ +use ::libc; +// PORTAUDIO +// Portaudio output +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ diff --git a/src/output_pack.rs b/src/output_pack.rs new file mode 100644 index 0000000..bcb5b16 --- /dev/null +++ b/src/output_pack.rs @@ -0,0 +1,324 @@ +use ::libc; + +pub use crate::squeezelite_h::frames_t; +pub use crate::squeezelite_h::output_format; +pub use crate::squeezelite_h::s32_t; +pub use crate::squeezelite_h::s64_t; +pub use crate::squeezelite_h::u32_t; +pub use crate::squeezelite_h::u8_t; +pub use crate::squeezelite_h::S16_LE; +pub use crate::squeezelite_h::S24_3LE; +pub use crate::squeezelite_h::S24_LE; +pub use crate::squeezelite_h::S32_LE; +pub use crate::stdlib::__int32_t; +pub use crate::stdlib::__int64_t; +pub use crate::stdlib::__uint32_t; +pub use crate::stdlib::__uint8_t; +pub use crate::stdlib::int32_t; +pub use crate::stdlib::int64_t; +use crate::stdlib::memcpy; +pub use crate::stdlib::u_int32_t; +pub use crate::stdlib::u_int8_t; +pub use crate::stdlib::uintptr_t; +// inlining these on windows prevents them being linkable... +#[inline] + +unsafe extern "C" fn gain( + mut gain_0: crate::squeezelite_h::s32_t, + mut sample: crate::squeezelite_h::s32_t, +) -> crate::squeezelite_h::s32_t { + let mut res = gain_0 as crate::squeezelite_h::s64_t * sample as crate::squeezelite_h::s64_t; + if res as libc::c_longlong > 0x7fffffffffff as libc::c_longlong { + res = 0x7fffffffffff as libc::c_longlong as crate::squeezelite_h::s64_t + } + if (res as libc::c_longlong) < -(0x7fffffffffff as libc::c_longlong) { + res = -(0x7fffffffffff as libc::c_longlong) as crate::squeezelite_h::s64_t + } + return (res >> 16 as libc::c_int) as crate::squeezelite_h::s32_t; +} +#[no_mangle] + +pub unsafe extern "C" fn _scale_and_pack_frames( + mut outputptr: *mut libc::c_void, + mut inputptr: *mut crate::squeezelite_h::s32_t, + mut cnt: crate::squeezelite_h::frames_t, + mut gainL: crate::squeezelite_h::s32_t, + mut gainR: crate::squeezelite_h::s32_t, + mut format: crate::squeezelite_h::output_format, +) { + match format as libc::c_uint { + 3 => { + let mut optr = outputptr as *mut crate::squeezelite_h::u32_t; + if gainL == 0x10000 as libc::c_int && gainR == 0x10000 as libc::c_int { + loop { + let fresh0 = cnt; + cnt = cnt.wrapping_sub(1); + if !(fresh0 != 0) { + break; + } + let fresh1 = optr; + optr = optr.offset(1); + *fresh1 = (*inputptr >> 16 as libc::c_int & 0xffff as libc::c_int) + as libc::c_uint + | *inputptr.offset(1 as libc::c_int as isize) as libc::c_uint + & 0xffff0000 as libc::c_uint; + inputptr = inputptr.offset(2 as libc::c_int as isize) + } + } else { + loop { + let fresh2 = cnt; + cnt = cnt.wrapping_sub(1); + if !(fresh2 != 0) { + break; + } + let fresh3 = optr; + optr = optr.offset(1); + *fresh3 = (gain(gainL, *inputptr) >> 16 as libc::c_int & 0xffff as libc::c_int) + as libc::c_uint + | gain(gainR, *inputptr.offset(1 as libc::c_int as isize)) as libc::c_uint + & 0xffff0000 as libc::c_uint; + inputptr = inputptr.offset(2 as libc::c_int as isize) + } + } + } + 1 => { + let mut optr_0 = outputptr as *mut crate::squeezelite_h::u32_t; + if gainL == 0x10000 as libc::c_int && gainR == 0x10000 as libc::c_int { + loop { + let fresh4 = cnt; + cnt = cnt.wrapping_sub(1); + if !(fresh4 != 0) { + break; + } + let fresh5 = inputptr; + inputptr = inputptr.offset(1); + let fresh6 = optr_0; + optr_0 = optr_0.offset(1); + *fresh6 = (*fresh5 >> 8 as libc::c_int) as crate::squeezelite_h::u32_t; + let fresh7 = inputptr; + inputptr = inputptr.offset(1); + let fresh8 = optr_0; + optr_0 = optr_0.offset(1); + *fresh8 = (*fresh7 >> 8 as libc::c_int) as crate::squeezelite_h::u32_t + } + } else { + loop { + let fresh9 = cnt; + cnt = cnt.wrapping_sub(1); + if !(fresh9 != 0) { + break; + } + let fresh10 = inputptr; + inputptr = inputptr.offset(1); + let fresh11 = optr_0; + optr_0 = optr_0.offset(1); + *fresh11 = + (gain(gainL, *fresh10) >> 8 as libc::c_int) as crate::squeezelite_h::u32_t; + let fresh12 = inputptr; + inputptr = inputptr.offset(1); + let fresh13 = optr_0; + optr_0 = optr_0.offset(1); + *fresh13 = + (gain(gainR, *fresh12) >> 8 as libc::c_int) as crate::squeezelite_h::u32_t + } + } + } + 2 => { + let mut optr_1 = outputptr as *mut crate::squeezelite_h::u8_t; + if gainL == 0x10000 as libc::c_int && gainR == 0x10000 as libc::c_int { + while cnt != 0 { + // attempt to do 32 bit memory accesses - move 2 frames at once: 16 bytes -> 12 bytes + // falls through to exception case when not aligned or if less than 2 frames to move + if optr_1 as crate::stdlib::uintptr_t & 0x3 as libc::c_int as libc::c_ulong + == 0 as libc::c_int as libc::c_ulong + && cnt >= 2 as libc::c_int as libc::c_uint + { + let mut o_ptr = + optr_1 as *mut libc::c_void as *mut crate::squeezelite_h::u32_t; + while cnt >= 2 as libc::c_int as libc::c_uint { + let fresh14 = inputptr; + inputptr = inputptr.offset(1); + let mut l1 = *fresh14; + let fresh15 = inputptr; + inputptr = inputptr.offset(1); + let mut r1 = *fresh15; + let fresh16 = inputptr; + inputptr = inputptr.offset(1); + let mut l2 = *fresh16; + let fresh17 = inputptr; + inputptr = inputptr.offset(1); + let mut r2 = *fresh17; + let fresh18 = o_ptr; + o_ptr = o_ptr.offset(1); + *fresh18 = (l1 as libc::c_uint & 0xffffff00 as libc::c_uint) + >> 8 as libc::c_int + | ((r1 & 0xff00 as libc::c_int) << 16 as libc::c_int) + as libc::c_uint; + let fresh19 = o_ptr; + o_ptr = o_ptr.offset(1); + *fresh19 = (r1 as libc::c_uint & 0xffff0000 as libc::c_uint) + >> 16 as libc::c_int + | ((l2 & 0xffff00 as libc::c_int) << 8 as libc::c_int) + as libc::c_uint; + let fresh20 = o_ptr; + o_ptr = o_ptr.offset(1); + *fresh20 = (l2 as libc::c_uint & 0xff000000 as libc::c_uint) + >> 24 as libc::c_int + | r2 as libc::c_uint & 0xffffff00 as libc::c_uint; + optr_1 = optr_1.offset(12 as libc::c_int as isize); + cnt = (cnt as libc::c_uint) + .wrapping_sub(2 as libc::c_int as libc::c_uint) + as crate::squeezelite_h::frames_t + as crate::squeezelite_h::frames_t + } + } else { + let fresh21 = inputptr; + inputptr = inputptr.offset(1); + let mut lsample = *fresh21; + let fresh22 = inputptr; + inputptr = inputptr.offset(1); + let mut rsample = *fresh22; + let fresh23 = optr_1; + optr_1 = optr_1.offset(1); + *fresh23 = ((lsample & 0xff00 as libc::c_int) >> 8 as libc::c_int) + as crate::squeezelite_h::u8_t; + let fresh24 = optr_1; + optr_1 = optr_1.offset(1); + *fresh24 = ((lsample & 0xff0000 as libc::c_int) >> 16 as libc::c_int) + as crate::squeezelite_h::u8_t; + let fresh25 = optr_1; + optr_1 = optr_1.offset(1); + *fresh25 = ((lsample as libc::c_uint & 0xff000000 as libc::c_uint) + >> 24 as libc::c_int) + as crate::squeezelite_h::u8_t; + let fresh26 = optr_1; + optr_1 = optr_1.offset(1); + *fresh26 = ((rsample & 0xff00 as libc::c_int) >> 8 as libc::c_int) + as crate::squeezelite_h::u8_t; + let fresh27 = optr_1; + optr_1 = optr_1.offset(1); + *fresh27 = ((rsample & 0xff0000 as libc::c_int) >> 16 as libc::c_int) + as crate::squeezelite_h::u8_t; + let fresh28 = optr_1; + optr_1 = optr_1.offset(1); + *fresh28 = ((rsample as libc::c_uint & 0xff000000 as libc::c_uint) + >> 24 as libc::c_int) + as crate::squeezelite_h::u8_t; + cnt = cnt.wrapping_sub(1) + } + } + } else { + while cnt != 0 { + // attempt to do 32 bit memory accesses - move 2 frames at once: 16 bytes -> 12 bytes + // falls through to exception case when not aligned or if less than 2 frames to move + if optr_1 as crate::stdlib::uintptr_t & 0x3 as libc::c_int as libc::c_ulong + == 0 as libc::c_int as libc::c_ulong + && cnt >= 2 as libc::c_int as libc::c_uint + { + let mut o_ptr_0 = + optr_1 as *mut libc::c_void as *mut crate::squeezelite_h::u32_t; + while cnt >= 2 as libc::c_int as libc::c_uint { + let fresh29 = inputptr; + inputptr = inputptr.offset(1); + let mut l1_0 = gain(gainL, *fresh29); + let fresh30 = inputptr; + inputptr = inputptr.offset(1); + let mut r1_0 = gain(gainR, *fresh30); + let fresh31 = inputptr; + inputptr = inputptr.offset(1); + let mut l2_0 = gain(gainL, *fresh31); + let fresh32 = inputptr; + inputptr = inputptr.offset(1); + let mut r2_0 = gain(gainR, *fresh32); + let fresh33 = o_ptr_0; + o_ptr_0 = o_ptr_0.offset(1); + *fresh33 = (l1_0 as libc::c_uint & 0xffffff00 as libc::c_uint) + >> 8 as libc::c_int + | ((r1_0 & 0xff00 as libc::c_int) << 16 as libc::c_int) + as libc::c_uint; + let fresh34 = o_ptr_0; + o_ptr_0 = o_ptr_0.offset(1); + *fresh34 = (r1_0 as libc::c_uint & 0xffff0000 as libc::c_uint) + >> 16 as libc::c_int + | ((l2_0 & 0xffff00 as libc::c_int) << 8 as libc::c_int) + as libc::c_uint; + let fresh35 = o_ptr_0; + o_ptr_0 = o_ptr_0.offset(1); + *fresh35 = (l2_0 as libc::c_uint & 0xff000000 as libc::c_uint) + >> 24 as libc::c_int + | r2_0 as libc::c_uint & 0xffffff00 as libc::c_uint; + optr_1 = optr_1.offset(12 as libc::c_int as isize); + cnt = (cnt as libc::c_uint) + .wrapping_sub(2 as libc::c_int as libc::c_uint) + as crate::squeezelite_h::frames_t + as crate::squeezelite_h::frames_t + } + } else { + let fresh36 = inputptr; + inputptr = inputptr.offset(1); + let mut lsample_0 = gain(gainL, *fresh36); + let fresh37 = inputptr; + inputptr = inputptr.offset(1); + let mut rsample_0 = gain(gainR, *fresh37); + let fresh38 = optr_1; + optr_1 = optr_1.offset(1); + *fresh38 = ((lsample_0 & 0xff00 as libc::c_int) >> 8 as libc::c_int) + as crate::squeezelite_h::u8_t; + let fresh39 = optr_1; + optr_1 = optr_1.offset(1); + *fresh39 = ((lsample_0 & 0xff0000 as libc::c_int) >> 16 as libc::c_int) + as crate::squeezelite_h::u8_t; + let fresh40 = optr_1; + optr_1 = optr_1.offset(1); + *fresh40 = ((lsample_0 as libc::c_uint & 0xff000000 as libc::c_uint) + >> 24 as libc::c_int) + as crate::squeezelite_h::u8_t; + let fresh41 = optr_1; + optr_1 = optr_1.offset(1); + *fresh41 = ((rsample_0 & 0xff00 as libc::c_int) >> 8 as libc::c_int) + as crate::squeezelite_h::u8_t; + let fresh42 = optr_1; + optr_1 = optr_1.offset(1); + *fresh42 = ((rsample_0 & 0xff0000 as libc::c_int) >> 16 as libc::c_int) + as crate::squeezelite_h::u8_t; + let fresh43 = optr_1; + optr_1 = optr_1.offset(1); + *fresh43 = ((rsample_0 as libc::c_uint & 0xff000000 as libc::c_uint) + >> 24 as libc::c_int) + as crate::squeezelite_h::u8_t; + cnt = cnt.wrapping_sub(1) + } + } + } + } + 0 => { + let mut optr_2 = outputptr as *mut crate::squeezelite_h::u32_t; + if gainL == 0x10000 as libc::c_int && gainR == 0x10000 as libc::c_int { + crate::stdlib::memcpy( + outputptr, + inputptr as *const libc::c_void, + cnt.wrapping_mul(8 as libc::c_int as libc::c_uint) as libc::c_ulong, + ); + } else { + loop { + let fresh44 = cnt; + cnt = cnt.wrapping_sub(1); + if !(fresh44 != 0) { + break; + } + let fresh45 = inputptr; + inputptr = inputptr.offset(1); + let fresh46 = optr_2; + optr_2 = optr_2.offset(1); + *fresh46 = gain(gainL, *fresh45) as crate::squeezelite_h::u32_t; + let fresh47 = inputptr; + inputptr = inputptr.offset(1); + let fresh48 = optr_2; + optr_2 = optr_2.offset(1); + *fresh48 = gain(gainR, *fresh47) as crate::squeezelite_h::u32_t + } + } + } + _ => {} + }; +} diff --git a/src/output_pulse.rs b/src/output_pulse.rs new file mode 100644 index 0000000..77f5f52 --- /dev/null +++ b/src/output_pulse.rs @@ -0,0 +1,25 @@ +use ::libc; +// Output using PulseAudio +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2020, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Additions (c) Paul Hermann, 2015-2017 under the same license terms + * -Control of Raspberry pi GPIO for amplifier power + * -Launch script on power status change from LMS + */ diff --git a/src/output_stdout.rs b/src/output_stdout.rs new file mode 100644 index 0000000..a3a0d25 --- /dev/null +++ b/src/output_stdout.rs @@ -0,0 +1,346 @@ +use ::libc; + +pub use crate::stddef_h::size_t; + +pub use crate::stdlib::_IO_codecvt; +pub use crate::stdlib::_IO_lock_t; +pub use crate::stdlib::_IO_marker; +pub use crate::stdlib::_IO_wide_data; +pub use crate::stdlib::__int32_t; +pub use crate::stdlib::__off64_t; +pub use crate::stdlib::__off_t; +pub use crate::stdlib::__uint32_t; +pub use crate::stdlib::__uint8_t; +pub use crate::stdlib::int32_t; +pub use crate::stdlib::FILE; +pub use crate::stdlib::_IO_FILE; + +pub use crate::squeezelite_h::_apply_cross; +pub use crate::squeezelite_h::buffer; +pub use crate::squeezelite_h::fade_dir; +pub use crate::squeezelite_h::fade_mode; +pub use crate::squeezelite_h::fade_state; +pub use crate::squeezelite_h::frames_t; +pub use crate::squeezelite_h::lDEBUG; +pub use crate::squeezelite_h::lERROR; +pub use crate::squeezelite_h::lINFO; +pub use crate::squeezelite_h::lSDEBUG; +pub use crate::squeezelite_h::lWARN; +pub use crate::squeezelite_h::log_level; +pub use crate::squeezelite_h::output_format; +pub use crate::squeezelite_h::output_state; +pub use crate::squeezelite_h::outputstate; +pub use crate::squeezelite_h::s32_t; +pub use crate::squeezelite_h::u32_t; +pub use crate::squeezelite_h::u8_t; +pub use crate::squeezelite_h::C2RustUnnamed_1; +pub use crate::squeezelite_h::FADE_ACTIVE; +pub use crate::squeezelite_h::FADE_CROSS; +pub use crate::squeezelite_h::FADE_CROSSFADE; +pub use crate::squeezelite_h::FADE_DOWN; +pub use crate::squeezelite_h::FADE_DUE; +pub use crate::squeezelite_h::FADE_IN; +pub use crate::squeezelite_h::FADE_INACTIVE; +pub use crate::squeezelite_h::FADE_INOUT; +pub use crate::squeezelite_h::FADE_NONE; +pub use crate::squeezelite_h::FADE_OUT; +pub use crate::squeezelite_h::FADE_UP; +pub use crate::squeezelite_h::OUTPUT_BUFFER; +pub use crate::squeezelite_h::OUTPUT_OFF; +pub use crate::squeezelite_h::OUTPUT_PAUSE_FRAMES; +pub use crate::squeezelite_h::OUTPUT_RUNNING; +pub use crate::squeezelite_h::OUTPUT_SKIP_FRAMES; +pub use crate::squeezelite_h::OUTPUT_START_AT; +pub use crate::squeezelite_h::OUTPUT_STOPPED; +pub use crate::squeezelite_h::S16_LE; +pub use crate::squeezelite_h::S24_3LE; +pub use crate::squeezelite_h::S24_LE; +pub use crate::squeezelite_h::S32_LE; +pub use crate::src::output::_output_frames; +pub use crate::src::output::output_close_common; +pub use crate::src::output::output_init_common; +pub use crate::src::output_pack::_scale_and_pack_frames; +pub use crate::src::utils::gettime_ms; +pub use crate::src::utils::logprint; +pub use crate::src::utils::logtime; +pub use crate::stdlib::__pthread_internal_list; +pub use crate::stdlib::__pthread_list_t; +pub use crate::stdlib::__pthread_mutex_s; +use crate::stdlib::free; +use crate::stdlib::fwrite; +use crate::stdlib::malloc; +use crate::stdlib::memset; +use crate::stdlib::pthread_attr_destroy; +use crate::stdlib::pthread_attr_init; +use crate::stdlib::pthread_attr_setstacksize; +pub use crate::stdlib::pthread_attr_t; +use crate::stdlib::pthread_create; +use crate::stdlib::pthread_mutex_lock; +pub use crate::stdlib::pthread_mutex_t; +use crate::stdlib::pthread_mutex_unlock; +pub use crate::stdlib::pthread_t; +use crate::stdlib::stdout; +use crate::stdlib::strcmp; +pub use crate::stdlib::u_int32_t; +pub use crate::stdlib::u_int8_t; +extern "C" { + #[no_mangle] + pub static mut output: crate::squeezelite_h::outputstate; + #[no_mangle] + pub static mut outputbuf: *mut crate::squeezelite_h::buffer; + #[no_mangle] + pub static mut silencebuf: *mut crate::squeezelite_h::u8_t; +} + +static mut loglevel: crate::squeezelite_h::log_level = crate::squeezelite_h::lERROR; + +static mut running: bool = 1 as libc::c_int != 0; +// buffer to hold output data so we can block on writing outside of output lock, allocated on init + +static mut buf: *mut crate::squeezelite_h::u8_t = + 0 as *const crate::squeezelite_h::u8_t as *mut crate::squeezelite_h::u8_t; + +static mut buffill: libc::c_uint = 0; + +static mut bytes_per_frame: libc::c_int = 0; + +unsafe extern "C" fn _stdout_write_frames( + mut out_frames: crate::squeezelite_h::frames_t, + mut silence: bool, + mut gainL: crate::squeezelite_h::s32_t, + mut gainR: crate::squeezelite_h::s32_t, + mut cross_gain_in: crate::squeezelite_h::s32_t, + mut cross_gain_out: crate::squeezelite_h::s32_t, + mut cross_ptr: *mut *mut crate::squeezelite_h::s32_t, +) -> libc::c_int { + let mut obuf = 0 as *mut crate::squeezelite_h::u8_t; + if !silence { + if output.fade as libc::c_uint + == crate::squeezelite_h::FADE_ACTIVE as libc::c_int as libc::c_uint + && output.fade_dir as libc::c_uint + == crate::squeezelite_h::FADE_CROSS as libc::c_int as libc::c_uint + && !(*cross_ptr).is_null() + { + crate::squeezelite_h::_apply_cross( + outputbuf, + out_frames, + cross_gain_in, + cross_gain_out, + cross_ptr, + ); + } + obuf = (*outputbuf).readp + } else { + obuf = silencebuf + } + crate::src::output_pack::_scale_and_pack_frames( + buf.offset(buffill.wrapping_mul(bytes_per_frame as libc::c_uint) as isize) + as *mut libc::c_void, + obuf as *mut libc::c_void as *mut crate::squeezelite_h::s32_t, + out_frames, + gainL, + gainR, + output.format, + ); + buffill = buffill.wrapping_add(out_frames); + return out_frames as libc::c_int; +} + +unsafe extern "C" fn output_thread() -> *mut libc::c_void { + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + match output.format as libc::c_uint { + 0 => bytes_per_frame = 4 as libc::c_int * 2 as libc::c_int, + 2 => bytes_per_frame = 3 as libc::c_int * 2 as libc::c_int, + 3 => bytes_per_frame = 2 as libc::c_int * 2 as libc::c_int, + _ => bytes_per_frame = 4 as libc::c_int * 2 as libc::c_int, + } + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + while running { + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + output.device_frames = 0 as libc::c_int as libc::c_uint; + output.updated = crate::src::utils::gettime_ms(); + output.frames_played_dmp = output.frames_played; + crate::src::output::_output_frames(2048 as libc::c_int as crate::squeezelite_h::frames_t); + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + if buffill != 0 { + crate::stdlib::fwrite( + buf as *const libc::c_void, + bytes_per_frame as libc::c_ulong, + buffill as libc::c_ulong, + crate::stdlib::stdout, + ); + buffill = 0 as libc::c_int as libc::c_uint + } + } + return 0 as *mut libc::c_void; +} + +static mut thread: crate::stdlib::pthread_t = 0; +#[no_mangle] + +pub unsafe extern "C" fn output_init_stdout( + mut level: crate::squeezelite_h::log_level, + mut output_buf_size: libc::c_uint, + mut params: *mut libc::c_char, + mut rates: *mut libc::c_uint, + mut rate_delay: libc::c_uint, +) { + loglevel = level; + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d init output stdout\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 19], &[libc::c_char; 19]>(b"output_init_stdout\x00")) + .as_ptr(), + 130 as libc::c_int, + ); + } + buf = crate::stdlib::malloc((2048 as libc::c_int * 8 as libc::c_int) as libc::c_ulong) + as *mut crate::squeezelite_h::u8_t; + if buf.is_null() { + crate::src::utils::logprint( + b"%s %s:%d unable to malloc buf\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 19], &[libc::c_char; 19]>(b"output_init_stdout\x00")) + .as_ptr(), + 134 as libc::c_int, + ); + return; + } + buffill = 0 as libc::c_int as libc::c_uint; + crate::stdlib::memset( + &mut output as *mut crate::squeezelite_h::outputstate as *mut libc::c_void, + 0 as libc::c_int, + ::std::mem::size_of::() as libc::c_ulong, + ); + output.format = crate::squeezelite_h::S32_LE; + output.start_frames = (2048 as libc::c_int * 2 as libc::c_int) as libc::c_uint; + output.write_cb = Some( + _stdout_write_frames + as unsafe extern "C" fn( + _: crate::squeezelite_h::frames_t, + _: bool, + _: crate::squeezelite_h::s32_t, + _: crate::squeezelite_h::s32_t, + _: crate::squeezelite_h::s32_t, + _: crate::squeezelite_h::s32_t, + _: *mut *mut crate::squeezelite_h::s32_t, + ) -> libc::c_int, + ); + output.rate_delay = rate_delay; + if !params.is_null() { + if crate::stdlib::strcmp(params, b"32\x00" as *const u8 as *const libc::c_char) == 0 { + output.format = crate::squeezelite_h::S32_LE + } + if crate::stdlib::strcmp(params, b"24\x00" as *const u8 as *const libc::c_char) == 0 { + output.format = crate::squeezelite_h::S24_3LE + } + if crate::stdlib::strcmp(params, b"16\x00" as *const u8 as *const libc::c_char) == 0 { + output.format = crate::squeezelite_h::S16_LE + } + } + // ensure output rate is specified to avoid test open + if *rates.offset(0 as libc::c_int as isize) == 0 { + *rates.offset(0 as libc::c_int as isize) = 44100 as libc::c_int as libc::c_uint + } + crate::src::output::output_init_common( + level, + b"-\x00" as *const u8 as *const libc::c_char, + output_buf_size, + rates, + 0 as libc::c_int as libc::c_uint, + ); + let mut attr = crate::stdlib::pthread_attr_t { __size: [0; 56] }; + crate::stdlib::pthread_attr_init(&mut attr); + crate::stdlib::pthread_attr_setstacksize( + &mut attr, + (16384 as libc::c_int + 64 as libc::c_int * 1024 as libc::c_int) as crate::stddef_h::size_t, + ); + crate::stdlib::pthread_create( + &mut thread, + &mut attr, + ::std::mem::transmute::< + Option *mut libc::c_void>, + Option *mut libc::c_void>, + >(Some(::std::mem::transmute::< + unsafe extern "C" fn() -> *mut libc::c_void, + unsafe extern "C" fn() -> *mut libc::c_void, + >(output_thread))), + 0 as *mut libc::c_void, + ); + crate::stdlib::pthread_attr_destroy(&mut attr); +} +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Additions (c) Paul Hermann, 2015-2017 under the same license terms + * -Control of Raspberry pi GPIO for amplifier power + * -Launch script on power status change from LMS + */ +// make may define: PORTAUDIO, SELFPIPE, RESAMPLE, RESAMPLE_MP, VISEXPORT, GPIO, IR, DSD, LINKALL to influence build +// build detection +// dynamically loaded libraries at run time +// !LINKALL +// config options +// do not reduce as icy-meta max is 4080 +/* SUN */ +/* SUN */ +// printf/scanf formats for u64_t +// logging +// utils.c (non logging) +// buffer.c +// _* called with mutex locked +// slimproto.c +// stream.c +// decode.c +// output.c output_alsa.c output_pa.c output_pack.c +// frames played at the point delay is measured +// ordered largest first so [0] is max_rate +// set in decode thread +// set in decode thread +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// _* called with mutex locked +// output_alsa.c +// output_pa.c +// output_pulse.c +// output_stdout.c +#[no_mangle] + +pub unsafe extern "C" fn output_close_stdout() { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d close output\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 20], &[libc::c_char; 20]>(b"output_close_stdout\x00")) + .as_ptr(), + 174 as libc::c_int, + ); + } + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + running = 0 as libc::c_int != 0; + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + crate::stdlib::free(buf as *mut libc::c_void); + crate::src::output::output_close_common(); +} diff --git a/src/pcm.rs b/src/pcm.rs new file mode 100644 index 0000000..054befd --- /dev/null +++ b/src/pcm.rs @@ -0,0 +1,1015 @@ +use ::libc; + +pub use crate::stddef_h::size_t; +pub use crate::stdlib::__int32_t; +pub use crate::stdlib::__uint32_t; +pub use crate::stdlib::__uint64_t; +pub use crate::stdlib::__uint8_t; +pub use crate::stdlib::int32_t; + +pub use crate::stdlib::__pthread_internal_list; +pub use crate::stdlib::__pthread_list_t; +pub use crate::stdlib::__pthread_mutex_s; +pub use crate::stdlib::pthread_mutex_t; +pub use crate::stdlib::u_int32_t; +pub use crate::stdlib::u_int64_t; +pub use crate::stdlib::u_int8_t; + +pub use crate::squeezelite_h::buffer; +pub use crate::squeezelite_h::codec; +pub use crate::squeezelite_h::decode_state; +pub use crate::squeezelite_h::decodestate; +pub use crate::squeezelite_h::disconnect_code; +pub use crate::squeezelite_h::fade_dir; +pub use crate::squeezelite_h::fade_mode; +pub use crate::squeezelite_h::fade_state; +pub use crate::squeezelite_h::frames_t; +pub use crate::squeezelite_h::lDEBUG; +pub use crate::squeezelite_h::lERROR; +pub use crate::squeezelite_h::lINFO; +pub use crate::squeezelite_h::lSDEBUG; +pub use crate::squeezelite_h::lWARN; +pub use crate::squeezelite_h::log_level; +pub use crate::squeezelite_h::output_format; +pub use crate::squeezelite_h::output_state; +pub use crate::squeezelite_h::outputstate; +pub use crate::squeezelite_h::s32_t; +pub use crate::squeezelite_h::stream_state; +pub use crate::squeezelite_h::streamstate; +pub use crate::squeezelite_h::u32_t; +pub use crate::squeezelite_h::u64_t; +pub use crate::squeezelite_h::u8_t; +pub use crate::squeezelite_h::C2RustUnnamed_1; +pub use crate::squeezelite_h::_buf_used; +pub use crate::squeezelite_h::DECODE_COMPLETE; +pub use crate::squeezelite_h::DECODE_ERROR; +pub use crate::squeezelite_h::DECODE_READY; +pub use crate::squeezelite_h::DECODE_RUNNING; +pub use crate::squeezelite_h::DECODE_STOPPED; +pub use crate::squeezelite_h::DISCONNECT; +pub use crate::squeezelite_h::DISCONNECT_OK; +pub use crate::squeezelite_h::FADE_ACTIVE; +pub use crate::squeezelite_h::FADE_CROSS; +pub use crate::squeezelite_h::FADE_CROSSFADE; +pub use crate::squeezelite_h::FADE_DOWN; +pub use crate::squeezelite_h::FADE_DUE; +pub use crate::squeezelite_h::FADE_IN; +pub use crate::squeezelite_h::FADE_INACTIVE; +pub use crate::squeezelite_h::FADE_INOUT; +pub use crate::squeezelite_h::FADE_NONE; +pub use crate::squeezelite_h::FADE_OUT; +pub use crate::squeezelite_h::FADE_UP; +pub use crate::squeezelite_h::LOCAL_DISCONNECT; +pub use crate::squeezelite_h::OUTPUT_BUFFER; +pub use crate::squeezelite_h::OUTPUT_OFF; +pub use crate::squeezelite_h::OUTPUT_PAUSE_FRAMES; +pub use crate::squeezelite_h::OUTPUT_RUNNING; +pub use crate::squeezelite_h::OUTPUT_SKIP_FRAMES; +pub use crate::squeezelite_h::OUTPUT_START_AT; +pub use crate::squeezelite_h::OUTPUT_STOPPED; +pub use crate::squeezelite_h::RECV_HEADERS; +pub use crate::squeezelite_h::REMOTE_DISCONNECT; +pub use crate::squeezelite_h::S16_LE; +pub use crate::squeezelite_h::S24_3LE; +pub use crate::squeezelite_h::S24_LE; +pub use crate::squeezelite_h::S32_LE; +pub use crate::squeezelite_h::SEND_HEADERS; +pub use crate::squeezelite_h::STOPPED; +pub use crate::squeezelite_h::STREAMING_BUFFERING; +pub use crate::squeezelite_h::STREAMING_FILE; +pub use crate::squeezelite_h::STREAMING_HTTP; +pub use crate::squeezelite_h::STREAMING_WAIT; +pub use crate::squeezelite_h::TIMEOUT; +pub use crate::squeezelite_h::UNREACHABLE; +pub use crate::src::buffer::_buf_cont_read; +pub use crate::src::buffer::_buf_cont_write; +pub use crate::src::buffer::_buf_inc_readp; +pub use crate::src::buffer::_buf_inc_writep; +pub use crate::src::buffer::_buf_space; +pub use crate::src::buffer::buf_adjust; +pub use crate::src::decode::decode_newstream; +pub use crate::src::output::_checkfade; +pub use crate::src::utils::logprint; +pub use crate::src::utils::logtime; +use crate::stdlib::memcmp; +use crate::stdlib::memcpy; +use crate::stdlib::pthread_mutex_lock; +use crate::stdlib::pthread_mutex_unlock; +extern "C" { + /* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + #[no_mangle] + pub static mut loglevel: crate::squeezelite_h::log_level; + #[no_mangle] + pub static mut streambuf: *mut crate::squeezelite_h::buffer; + #[no_mangle] + pub static mut outputbuf: *mut crate::squeezelite_h::buffer; + #[no_mangle] + pub static mut stream: crate::squeezelite_h::streamstate; + #[no_mangle] + pub static mut output: crate::squeezelite_h::outputstate; + #[no_mangle] + pub static mut decode: crate::squeezelite_h::decodestate; +} + +pub const AIFF: header_format = 2; + +pub type header_format = libc::c_uint; + +pub const WAVE: header_format = 1; + +pub const UNKNOWN: header_format = 0; +#[no_mangle] + +pub static mut pcm_check_header: bool = 0 as libc::c_int != 0; + +static mut sample_rates: [crate::squeezelite_h::u32_t; 17] = [ + 11025 as libc::c_int as crate::squeezelite_h::u32_t, + 22050 as libc::c_int as crate::squeezelite_h::u32_t, + 32000 as libc::c_int as crate::squeezelite_h::u32_t, + 44100 as libc::c_int as crate::squeezelite_h::u32_t, + 48000 as libc::c_int as crate::squeezelite_h::u32_t, + 8000 as libc::c_int as crate::squeezelite_h::u32_t, + 12000 as libc::c_int as crate::squeezelite_h::u32_t, + 16000 as libc::c_int as crate::squeezelite_h::u32_t, + 24000 as libc::c_int as crate::squeezelite_h::u32_t, + 96000 as libc::c_int as crate::squeezelite_h::u32_t, + 88200 as libc::c_int as crate::squeezelite_h::u32_t, + 176400 as libc::c_int as crate::squeezelite_h::u32_t, + 192000 as libc::c_int as crate::squeezelite_h::u32_t, + 352800 as libc::c_int as crate::squeezelite_h::u32_t, + 384000 as libc::c_int as crate::squeezelite_h::u32_t, + 705600 as libc::c_int as crate::squeezelite_h::u32_t, + 768000 as libc::c_int as crate::squeezelite_h::u32_t, +]; + +static mut sample_rate: crate::squeezelite_h::u32_t = 0; + +static mut sample_size: crate::squeezelite_h::u32_t = 0; + +static mut channels: crate::squeezelite_h::u32_t = 0; + +static mut bigendian: bool = false; + +static mut limit: bool = false; + +static mut audio_left: crate::squeezelite_h::u32_t = 0; + +static mut bytes_per_frame: crate::squeezelite_h::u32_t = 0; + +unsafe extern "C" fn _check_header() { + let mut ptr = (*streambuf).readp; + let mut bytes = if crate::squeezelite_h::_buf_used(streambuf) + < crate::src::buffer::_buf_cont_read(streambuf) + { + crate::squeezelite_h::_buf_used(streambuf) + } else { + crate::src::buffer::_buf_cont_read(streambuf) + }; + let mut format = UNKNOWN; + // simple parsing of wav and aiff headers and get to samples + if bytes > 12 as libc::c_int as libc::c_uint { + if crate::stdlib::memcmp( + ptr as *const libc::c_void, + b"RIFF\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ) == 0 + && crate::stdlib::memcmp( + ptr.offset(8 as libc::c_int as isize) as *const libc::c_void, + b"WAVE\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ) == 0 + { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d WAVE\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"_check_header\x00", + )) + .as_ptr(), + 80 as libc::c_int, + ); + } + format = WAVE + } else if crate::stdlib::memcmp( + ptr as *const libc::c_void, + b"FORM\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ) == 0 + && (crate::stdlib::memcmp( + ptr.offset(8 as libc::c_int as isize) as *const libc::c_void, + b"AIFF\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ) == 0 + || crate::stdlib::memcmp( + ptr.offset(8 as libc::c_int as isize) as *const libc::c_void, + b"AIFC\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ) == 0) + { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d AIFF\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"_check_header\x00", + )) + .as_ptr(), + 83 as libc::c_int, + ); + } + format = AIFF + } + } + if format as libc::c_uint != UNKNOWN as libc::c_int as libc::c_uint { + ptr = ptr.offset(12 as libc::c_int as isize); + bytes = bytes.wrapping_sub(12 as libc::c_int as libc::c_uint); + while bytes >= 8 as libc::c_int as libc::c_uint { + let mut id: [libc::c_char; 5] = [0; 5]; + let mut len: libc::c_uint = 0; + crate::stdlib::memcpy( + id.as_mut_ptr() as *mut libc::c_void, + ptr as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ); + id[4 as libc::c_int as usize] = '\u{0}' as i32 as libc::c_char; + if format as libc::c_uint == WAVE as libc::c_int as libc::c_uint { + len = (*ptr.offset(4 as libc::c_int as isize) as libc::c_int + | (*ptr.offset(5 as libc::c_int as isize) as libc::c_int) << 8 as libc::c_int + | (*ptr.offset(6 as libc::c_int as isize) as libc::c_int) << 16 as libc::c_int + | (*ptr.offset(7 as libc::c_int as isize) as libc::c_int) << 24 as libc::c_int) + as libc::c_uint + } else { + len = ((*ptr.offset(4 as libc::c_int as isize) as libc::c_int) << 24 as libc::c_int + | (*ptr.offset(5 as libc::c_int as isize) as libc::c_int) << 16 as libc::c_int + | (*ptr.offset(6 as libc::c_int as isize) as libc::c_int) << 8 as libc::c_int + | *ptr.offset(7 as libc::c_int as isize) as libc::c_int) + as libc::c_uint + } + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d header: %s len: %d\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"_check_header\x00", + )) + .as_ptr(), + 104 as libc::c_int, + id.as_mut_ptr(), + len, + ); + } + if format as libc::c_uint == WAVE as libc::c_int as libc::c_uint + && crate::stdlib::memcmp( + ptr as *const libc::c_void, + b"data\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ) == 0 + { + ptr = ptr.offset(8 as libc::c_int as isize); + crate::src::buffer::_buf_inc_readp( + streambuf, + ptr.wrapping_offset_from((*streambuf).readp) as libc::c_long as libc::c_uint, + ); + audio_left = len; + if audio_left == 0xffffffff as libc::c_uint + || audio_left == 0x7fffeffc as libc::c_int as libc::c_uint + { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d wav audio size unknown: %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"_check_header\x00", + )) + .as_ptr(), + 112 as libc::c_int, + audio_left, + ); + } + limit = 0 as libc::c_int != 0 + } else { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d wav audio size: %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"_check_header\x00", + )) + .as_ptr(), + 115 as libc::c_int, + audio_left, + ); + } + limit = 1 as libc::c_int != 0 + } + return; + } + if format as libc::c_uint == AIFF as libc::c_int as libc::c_uint + && crate::stdlib::memcmp( + ptr as *const libc::c_void, + b"SSND\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ) == 0 + && bytes >= 16 as libc::c_int as libc::c_uint + { + let mut offset = ((*ptr.offset(8 as libc::c_int as isize) as libc::c_int) + << 24 as libc::c_int + | (*ptr.offset(9 as libc::c_int as isize) as libc::c_int) << 16 as libc::c_int + | (*ptr.offset(10 as libc::c_int as isize) as libc::c_int) << 8 as libc::c_int + | *ptr.offset(11 as libc::c_int as isize) as libc::c_int) + as libc::c_uint; + // following 4 bytes is blocksize - ignored + ptr = ptr.offset((8 as libc::c_int + 8 as libc::c_int) as isize); + crate::src::buffer::_buf_inc_readp( + streambuf, + ptr.offset(offset as isize) + .wrapping_offset_from((*streambuf).readp) + as libc::c_long as libc::c_uint, + ); + // Reading from an upsampled stream, length could be wrong. + // Only use length in header for files. + if stream.state as libc::c_uint + == crate::squeezelite_h::STREAMING_FILE as libc::c_int as libc::c_uint + { + audio_left = len + .wrapping_sub(8 as libc::c_int as libc::c_uint) + .wrapping_sub(offset); + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d aif audio size: %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"_check_header\x00", + )) + .as_ptr(), + 131 as libc::c_int, + audio_left, + ); + } + limit = 1 as libc::c_int != 0 + } + return; + } + if format as libc::c_uint == WAVE as libc::c_int as libc::c_uint + && crate::stdlib::memcmp( + ptr as *const libc::c_void, + b"fmt \x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ) == 0 + && bytes >= 24 as libc::c_int as libc::c_uint + { + // override the server parsed values with our own + channels = (*ptr.offset(10 as libc::c_int as isize) as libc::c_int + | (*ptr.offset(11 as libc::c_int as isize) as libc::c_int) << 8 as libc::c_int) + as crate::squeezelite_h::u32_t; + sample_rate = (*ptr.offset(12 as libc::c_int as isize) as libc::c_int + | (*ptr.offset(13 as libc::c_int as isize) as libc::c_int) << 8 as libc::c_int + | (*ptr.offset(14 as libc::c_int as isize) as libc::c_int) << 16 as libc::c_int + | (*ptr.offset(15 as libc::c_int as isize) as libc::c_int) << 24 as libc::c_int) + as crate::squeezelite_h::u32_t; + sample_size = ((*ptr.offset(22 as libc::c_int as isize) as libc::c_int + | (*ptr.offset(23 as libc::c_int as isize) as libc::c_int) << 8 as libc::c_int) + / 8 as libc::c_int) + as crate::squeezelite_h::u32_t; + bigendian = 0 as libc::c_int != 0; + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d pcm size: %u rate: %u chan: %u bigendian: %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"_check_header\x00", + )) + .as_ptr(), + 143 as libc::c_int, + sample_size, + sample_rate, + channels, + bigendian as libc::c_int, + ); + } + } + if format as libc::c_uint == AIFF as libc::c_int as libc::c_uint + && crate::stdlib::memcmp( + ptr as *const libc::c_void, + b"COMM\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ) == 0 + && bytes >= 26 as libc::c_int as libc::c_uint + { + let mut exponent: libc::c_int = 0; + // override the server parsed values with our own + channels = ((*ptr.offset(8 as libc::c_int as isize) as libc::c_int) + << 8 as libc::c_int + | *ptr.offset(9 as libc::c_int as isize) as libc::c_int) + as crate::squeezelite_h::u32_t; + sample_size = + (((*ptr.offset(14 as libc::c_int as isize) as libc::c_int) << 8 as libc::c_int + | *ptr.offset(15 as libc::c_int as isize) as libc::c_int) + / 8 as libc::c_int) as crate::squeezelite_h::u32_t; + bigendian = 1 as libc::c_int != 0; + // sample rate is encoded as IEEE 80 bit extended format + // make some assumptions to simplify processing - only use first 32 bits of mantissa + exponent = ((*ptr.offset(16 as libc::c_int as isize) as libc::c_int + & 0x7f as libc::c_int) + << 8 as libc::c_int + | *ptr.offset(17 as libc::c_int as isize) as libc::c_int) + - 16383 as libc::c_int + - 31 as libc::c_int; + sample_rate = ((*ptr.offset(18 as libc::c_int as isize) as libc::c_int) + << 24 as libc::c_int + | (*ptr.offset(19 as libc::c_int as isize) as libc::c_int) << 16 as libc::c_int + | (*ptr.offset(20 as libc::c_int as isize) as libc::c_int) << 8 as libc::c_int + | *ptr.offset(21 as libc::c_int as isize) as libc::c_int) + as crate::squeezelite_h::u32_t; + while exponent < 0 as libc::c_int { + sample_rate >>= 1 as libc::c_int; + exponent += 1 + } + while exponent > 0 as libc::c_int { + sample_rate <<= 1 as libc::c_int; + exponent -= 1 + } + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d pcm size: %u rate: %u chan: %u bigendian: %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"_check_header\x00", + )) + .as_ptr(), + 158 as libc::c_int, + sample_size, + sample_rate, + channels, + bigendian as libc::c_int, + ); + } + } + if bytes >= len.wrapping_add(8 as libc::c_int as libc::c_uint) { + ptr = ptr.offset(len.wrapping_add(8 as libc::c_int as libc::c_uint) as isize); + bytes = bytes.wrapping_sub(len.wrapping_add(8 as libc::c_int as libc::c_uint)) + } else { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d run out of data\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"_check_header\x00", + )) + .as_ptr(), + 165 as libc::c_int, + ); + } + return; + } + } + } else if loglevel as libc::c_uint >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d unknown format - can\'t parse header\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>(b"_check_header\x00")) + .as_ptr(), + 171 as libc::c_int, + ); + }; +} + +unsafe extern "C" fn pcm_decode() -> crate::squeezelite_h::decode_state { + let mut bytes: libc::c_uint = 0; + let mut in_0: libc::c_uint = 0; + let mut out: libc::c_uint = 0; + let mut frames: crate::squeezelite_h::frames_t = 0; + let mut count: crate::squeezelite_h::frames_t = 0; + let mut optr = 0 as *mut crate::squeezelite_h::u32_t; + let mut iptr = 0 as *mut crate::squeezelite_h::u8_t; + let mut tmp: [crate::squeezelite_h::u8_t; 16] = [0; 16]; + crate::stdlib::pthread_mutex_lock(&mut (*streambuf).mutex); + if decode.new_stream as libc::c_int != 0 + && (stream.state as libc::c_uint + == crate::squeezelite_h::STREAMING_FILE as libc::c_int as libc::c_uint + || pcm_check_header as libc::c_int != 0) + { + _check_header(); + } + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + bytes = if crate::squeezelite_h::_buf_used(streambuf) + < crate::src::buffer::_buf_cont_read(streambuf) + { + crate::squeezelite_h::_buf_used(streambuf) + } else { + crate::src::buffer::_buf_cont_read(streambuf) + }; + out = (if crate::src::buffer::_buf_space(outputbuf) + < crate::src::buffer::_buf_cont_write(outputbuf) + { + crate::src::buffer::_buf_space(outputbuf) + } else { + crate::src::buffer::_buf_cont_write(outputbuf) + }) + .wrapping_div(8 as libc::c_int as libc::c_uint); + if stream.state as libc::c_uint + <= crate::squeezelite_h::DISCONNECT as libc::c_int as libc::c_uint + && bytes == 0 as libc::c_int as libc::c_uint + || limit as libc::c_int != 0 && audio_left == 0 as libc::c_int as libc::c_uint + { + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + return crate::squeezelite_h::DECODE_COMPLETE; + } + if decode.new_stream { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d setting track_start\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"pcm_decode\x00")) + .as_ptr(), + 206 as libc::c_int, + ); + } + output.track_start = (*outputbuf).writep; + decode.new_stream = 0 as libc::c_int != 0; + output.next_sample_rate = + crate::src::decode::decode_newstream(sample_rate, output.supported_rates.as_mut_ptr()); + if output.fade_mode as u64 != 0 { + crate::src::output::_checkfade(1 as libc::c_int != 0); + } + bytes_per_frame = channels.wrapping_mul(sample_size) + } + optr = (*outputbuf).writep as *mut crate::squeezelite_h::u32_t; + iptr = (*streambuf).readp; + in_0 = bytes.wrapping_div(bytes_per_frame); + // handle frame wrapping round end of streambuf + // - only need if resizing of streambuf does not avoid this, could occur in localfile case + if in_0 == 0 as libc::c_int as libc::c_uint + && bytes > 0 as libc::c_int as libc::c_uint + && crate::squeezelite_h::_buf_used(streambuf) >= bytes_per_frame + { + crate::stdlib::memcpy( + tmp.as_mut_ptr() as *mut libc::c_void, + iptr as *const libc::c_void, + bytes as libc::c_ulong, + ); + crate::stdlib::memcpy( + tmp.as_mut_ptr().offset(bytes as isize) as *mut libc::c_void, + (*streambuf).buf as *const libc::c_void, + bytes_per_frame.wrapping_sub(bytes) as libc::c_ulong, + ); + iptr = tmp.as_mut_ptr(); + in_0 = 1 as libc::c_int as libc::c_uint + } + frames = if in_0 < out { in_0 } else { out }; + frames = if frames < 4096 as libc::c_int as libc::c_uint { + frames + } else { + 4096 as libc::c_int as libc::c_uint + }; + if limit as libc::c_int != 0 && frames.wrapping_mul(bytes_per_frame) > audio_left { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d reached end of audio\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"pcm_decode\x00")) + .as_ptr(), + 261 as libc::c_int, + ); + } + frames = audio_left.wrapping_div(bytes_per_frame) + } + count = frames.wrapping_mul(channels); + if channels == 2 as libc::c_int as libc::c_uint { + if sample_size == 1 as libc::c_int as libc::c_uint { + loop { + let fresh0 = count; + count = count.wrapping_sub(1); + if !(fresh0 != 0) { + break; + } + let fresh1 = iptr; + iptr = iptr.offset(1); + let fresh2 = optr; + optr = optr.offset(1); + *fresh2 = + ((*fresh1 as libc::c_int) << 24 as libc::c_int) as crate::squeezelite_h::u32_t + } + } else if sample_size == 2 as libc::c_int as libc::c_uint { + if bigendian { + loop { + let fresh3 = count; + count = count.wrapping_sub(1); + if !(fresh3 != 0) { + break; + } + let fresh4 = optr; + optr = optr.offset(1); + *fresh4 = ((*iptr as libc::c_int) << 24 as libc::c_int + | (*iptr.offset(1 as libc::c_int as isize) as libc::c_int) + << 16 as libc::c_int) + as crate::squeezelite_h::u32_t; + iptr = iptr.offset(2 as libc::c_int as isize) + } + } else { + loop { + let fresh5 = count; + count = count.wrapping_sub(1); + if !(fresh5 != 0) { + break; + } + let fresh6 = optr; + optr = optr.offset(1); + *fresh6 = ((*iptr as libc::c_int) << 16 as libc::c_int + | (*iptr.offset(1 as libc::c_int as isize) as libc::c_int) + << 24 as libc::c_int) + as crate::squeezelite_h::u32_t; + iptr = iptr.offset(2 as libc::c_int as isize) + } + } + } else if sample_size == 3 as libc::c_int as libc::c_uint { + if bigendian { + loop { + let fresh7 = count; + count = count.wrapping_sub(1); + if !(fresh7 != 0) { + break; + } + let fresh8 = optr; + optr = optr.offset(1); + *fresh8 = ((*iptr as libc::c_int) << 24 as libc::c_int + | (*iptr.offset(1 as libc::c_int as isize) as libc::c_int) + << 16 as libc::c_int + | (*iptr.offset(2 as libc::c_int as isize) as libc::c_int) + << 8 as libc::c_int) + as crate::squeezelite_h::u32_t; + iptr = iptr.offset(3 as libc::c_int as isize) + } + } else { + loop { + let fresh9 = count; + count = count.wrapping_sub(1); + if !(fresh9 != 0) { + break; + } + let fresh10 = optr; + optr = optr.offset(1); + *fresh10 = ((*iptr as libc::c_int) << 8 as libc::c_int + | (*iptr.offset(1 as libc::c_int as isize) as libc::c_int) + << 16 as libc::c_int + | (*iptr.offset(2 as libc::c_int as isize) as libc::c_int) + << 24 as libc::c_int) + as crate::squeezelite_h::u32_t; + iptr = iptr.offset(3 as libc::c_int as isize) + } + } + } else if sample_size == 4 as libc::c_int as libc::c_uint { + if bigendian { + loop { + let fresh11 = count; + count = count.wrapping_sub(1); + if !(fresh11 != 0) { + break; + } + let fresh12 = optr; + optr = optr.offset(1); + *fresh12 = ((*iptr as libc::c_int) << 24 as libc::c_int + | (*iptr.offset(1 as libc::c_int as isize) as libc::c_int) + << 16 as libc::c_int + | (*iptr.offset(2 as libc::c_int as isize) as libc::c_int) + << 8 as libc::c_int + | *iptr.offset(3 as libc::c_int as isize) as libc::c_int) + as crate::squeezelite_h::u32_t; + iptr = iptr.offset(4 as libc::c_int as isize) + } + } else { + loop { + let fresh13 = count; + count = count.wrapping_sub(1); + if !(fresh13 != 0) { + break; + } + let fresh14 = optr; + optr = optr.offset(1); + *fresh14 = (*iptr as libc::c_int + | (*iptr.offset(1 as libc::c_int as isize) as libc::c_int) + << 8 as libc::c_int + | (*iptr.offset(2 as libc::c_int as isize) as libc::c_int) + << 16 as libc::c_int + | (*iptr.offset(3 as libc::c_int as isize) as libc::c_int) + << 24 as libc::c_int) + as crate::squeezelite_h::u32_t; + iptr = iptr.offset(4 as libc::c_int as isize) + } + } + } + } else if channels == 1 as libc::c_int as libc::c_uint { + if sample_size == 1 as libc::c_int as libc::c_uint { + loop { + let fresh15 = count; + count = count.wrapping_sub(1); + if !(fresh15 != 0) { + break; + } + let fresh16 = iptr; + iptr = iptr.offset(1); + *optr = + ((*fresh16 as libc::c_int) << 24 as libc::c_int) as crate::squeezelite_h::u32_t; + *optr.offset(1 as libc::c_int as isize) = *optr; + optr = optr.offset(2 as libc::c_int as isize) + } + } else if sample_size == 2 as libc::c_int as libc::c_uint { + if bigendian { + loop { + let fresh17 = count; + count = count.wrapping_sub(1); + if !(fresh17 != 0) { + break; + } + *optr = ((*iptr as libc::c_int) << 24 as libc::c_int + | (*iptr.offset(1 as libc::c_int as isize) as libc::c_int) + << 16 as libc::c_int) + as crate::squeezelite_h::u32_t; + *optr.offset(1 as libc::c_int as isize) = *optr; + iptr = iptr.offset(2 as libc::c_int as isize); + optr = optr.offset(2 as libc::c_int as isize) + } + } else { + loop { + let fresh18 = count; + count = count.wrapping_sub(1); + if !(fresh18 != 0) { + break; + } + *optr = ((*iptr as libc::c_int) << 16 as libc::c_int + | (*iptr.offset(1 as libc::c_int as isize) as libc::c_int) + << 24 as libc::c_int) + as crate::squeezelite_h::u32_t; + *optr.offset(1 as libc::c_int as isize) = *optr; + iptr = iptr.offset(2 as libc::c_int as isize); + optr = optr.offset(2 as libc::c_int as isize) + } + } + } else if sample_size == 3 as libc::c_int as libc::c_uint { + if bigendian { + loop { + let fresh19 = count; + count = count.wrapping_sub(1); + if !(fresh19 != 0) { + break; + } + *optr = ((*iptr as libc::c_int) << 24 as libc::c_int + | (*iptr.offset(1 as libc::c_int as isize) as libc::c_int) + << 16 as libc::c_int + | (*iptr.offset(2 as libc::c_int as isize) as libc::c_int) + << 8 as libc::c_int) + as crate::squeezelite_h::u32_t; + *optr.offset(1 as libc::c_int as isize) = *optr; + iptr = iptr.offset(3 as libc::c_int as isize); + optr = optr.offset(2 as libc::c_int as isize) + } + } else { + loop { + let fresh20 = count; + count = count.wrapping_sub(1); + if !(fresh20 != 0) { + break; + } + *optr = ((*iptr as libc::c_int) << 8 as libc::c_int + | (*iptr.offset(1 as libc::c_int as isize) as libc::c_int) + << 16 as libc::c_int + | (*iptr.offset(2 as libc::c_int as isize) as libc::c_int) + << 24 as libc::c_int) + as crate::squeezelite_h::u32_t; + *optr.offset(1 as libc::c_int as isize) = *optr; + iptr = iptr.offset(3 as libc::c_int as isize); + optr = optr.offset(2 as libc::c_int as isize) + } + } + } else if sample_size == 4 as libc::c_int as libc::c_uint { + if bigendian { + loop { + let fresh21 = count; + count = count.wrapping_sub(1); + if !(fresh21 != 0) { + break; + } + let fresh22 = optr; + optr = optr.offset(1); + *fresh22 = ((*iptr as libc::c_int) << 24 as libc::c_int + | (*iptr.offset(1 as libc::c_int as isize) as libc::c_int) + << 16 as libc::c_int + | (*iptr.offset(2 as libc::c_int as isize) as libc::c_int) + << 8 as libc::c_int + | *iptr.offset(3 as libc::c_int as isize) as libc::c_int) + as crate::squeezelite_h::u32_t; + *optr.offset(1 as libc::c_int as isize) = *optr; + iptr = iptr.offset(4 as libc::c_int as isize); + optr = optr.offset(2 as libc::c_int as isize) + } + } else { + loop { + let fresh23 = count; + count = count.wrapping_sub(1); + if !(fresh23 != 0) { + break; + } + let fresh24 = optr; + optr = optr.offset(1); + *fresh24 = (*iptr as libc::c_int + | (*iptr.offset(1 as libc::c_int as isize) as libc::c_int) + << 8 as libc::c_int + | (*iptr.offset(2 as libc::c_int as isize) as libc::c_int) + << 16 as libc::c_int + | (*iptr.offset(3 as libc::c_int as isize) as libc::c_int) + << 24 as libc::c_int) + as crate::squeezelite_h::u32_t; + *optr.offset(1 as libc::c_int as isize) = *optr; + iptr = iptr.offset(4 as libc::c_int as isize); + optr = optr.offset(2 as libc::c_int as isize) + } + } + } + } else { + crate::src::utils::logprint( + b"%s %s:%d unsupported channels\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"pcm_decode\x00")).as_ptr(), + 366 as libc::c_int, + ); + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d decoded %u frames\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"pcm_decode\x00")).as_ptr(), + 369 as libc::c_int, + frames, + ); + } + crate::src::buffer::_buf_inc_readp(streambuf, frames.wrapping_mul(bytes_per_frame)); + if limit { + audio_left = (audio_left as libc::c_uint).wrapping_sub(frames.wrapping_mul(bytes_per_frame)) + as crate::squeezelite_h::u32_t as crate::squeezelite_h::u32_t + } + crate::src::buffer::_buf_inc_writep( + outputbuf, + frames.wrapping_mul(8 as libc::c_int as libc::c_uint), + ); + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + return crate::squeezelite_h::DECODE_RUNNING; +} + +unsafe extern "C" fn pcm_open( + mut size: crate::squeezelite_h::u8_t, + mut rate: crate::squeezelite_h::u8_t, + mut chan: crate::squeezelite_h::u8_t, + mut endianness: crate::squeezelite_h::u8_t, +) { + sample_size = + (size as libc::c_int - '0' as i32 + 1 as libc::c_int) as crate::squeezelite_h::u32_t; + sample_rate = sample_rates[(rate as libc::c_int - '0' as i32) as usize]; + channels = (chan as libc::c_int - '0' as i32) as crate::squeezelite_h::u32_t; + bigendian = endianness as libc::c_int == '0' as i32; + limit = 0 as libc::c_int != 0; + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d pcm size: %u rate: %u chan: %u bigendian: %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"pcm_open\x00")).as_ptr(), + 397 as libc::c_int, + sample_size, + sample_rate, + channels, + bigendian as libc::c_int, + ); + } + crate::src::buffer::buf_adjust( + streambuf, + sample_size.wrapping_mul(channels) as crate::stddef_h::size_t, + ); +} + +unsafe extern "C" fn pcm_close() { + crate::src::buffer::buf_adjust(streambuf, 1 as libc::c_int as crate::stddef_h::size_t); +} +#[no_mangle] + +pub unsafe extern "C" fn register_pcm() -> *mut crate::squeezelite_h::codec { + if pcm_check_header { + static mut ret: crate::squeezelite_h::codec = unsafe { + { + let mut init = crate::squeezelite_h::codec { + id: 'p' as i32 as libc::c_char, + types: b"wav,aif,pcm\x00" as *const u8 as *const libc::c_char + as *mut libc::c_char, + min_read_bytes: 4096 as libc::c_int as libc::c_uint, + min_space: 102400 as libc::c_int as libc::c_uint, + open: Some( + pcm_open + as unsafe extern "C" fn( + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + ) -> (), + ), + close: Some(pcm_close as unsafe extern "C" fn() -> ()), + decode: Some( + pcm_decode as unsafe extern "C" fn() -> crate::squeezelite_h::decode_state, + ), + }; + init + } + }; + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d using pcm to decode wav,aif,pcm\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"register_pcm\x00")) + .as_ptr(), + 418 as libc::c_int, + ); + } + return &mut ret; + } else { + static mut ret_0: crate::squeezelite_h::codec = unsafe { + { + let mut init = crate::squeezelite_h::codec { + id: 'p' as i32 as libc::c_char, + types: b"aif,pcm\x00" as *const u8 as *const libc::c_char as *mut libc::c_char, + min_read_bytes: 4096 as libc::c_int as libc::c_uint, + min_space: 102400 as libc::c_int as libc::c_uint, + open: Some( + pcm_open + as unsafe extern "C" fn( + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + ) -> (), + ), + close: Some(pcm_close as unsafe extern "C" fn() -> ()), + decode: Some( + pcm_decode as unsafe extern "C" fn() -> crate::squeezelite_h::decode_state, + ), + }; + init + } + }; + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d using pcm to decode aif,pcm\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"register_pcm\x00")) + .as_ptr(), + 433 as libc::c_int, + ); + } + return &mut ret_0; + }; +} diff --git a/src/slimproto.rs b/src/slimproto.rs new file mode 100644 index 0000000..5f145a8 --- /dev/null +++ b/src/slimproto.rs @@ -0,0 +1,2542 @@ +// =============== BEGIN slimproto_h ================ + +// char header[] - added in sendRESP + +// S:N:Slimproto _http_metadata_handler +#[repr(C, packed)] +#[derive(Copy, Clone)] +pub struct META_header { + pub opcode: [libc::c_char; 4], + pub length: crate::squeezelite_h::u32_t, +} +// S:N:Slimproto _http_response_handler + +#[repr(C, packed)] +#[derive(Copy, Clone)] +pub struct RESP_header { + pub opcode: [libc::c_char; 4], + pub length: crate::squeezelite_h::u32_t, +} +// u8_t capabilities[]; +// S:N:Slimproto _stat_handler + +#[repr(C, packed)] +#[derive(Copy, Clone)] +pub struct STAT_packet { + pub opcode: [libc::c_char; 4], + pub length: crate::squeezelite_h::u32_t, + pub event: crate::squeezelite_h::u32_t, + pub num_crlf: crate::squeezelite_h::u8_t, + pub mas_initialized: crate::squeezelite_h::u8_t, + pub mas_mode: crate::squeezelite_h::u8_t, + pub stream_buffer_size: crate::squeezelite_h::u32_t, + pub stream_buffer_fullness: crate::squeezelite_h::u32_t, + pub bytes_received_H: crate::squeezelite_h::u32_t, + pub bytes_received_L: crate::squeezelite_h::u32_t, + pub signal_strength: crate::squeezelite_h::u16_t, + pub jiffies: crate::squeezelite_h::u32_t, + pub output_buffer_size: crate::squeezelite_h::u32_t, + pub output_buffer_fullness: crate::squeezelite_h::u32_t, + pub elapsed_seconds: crate::squeezelite_h::u32_t, + pub voltage: crate::squeezelite_h::u16_t, + pub elapsed_milliseconds: crate::squeezelite_h::u32_t, + pub server_timestamp: crate::squeezelite_h::u32_t, + pub error_code: crate::squeezelite_h::u16_t, +} +// S:N:Slimproto _disco_handler + +#[repr(C, packed)] +#[derive(Copy, Clone)] +pub struct DSCO_packet { + pub opcode: [libc::c_char; 4], + pub length: crate::squeezelite_h::u32_t, + pub reason: crate::squeezelite_h::u8_t, +} +// guids we don't use +// S:C:Commands + +#[repr(C, packed)] +#[derive(Copy, Clone)] +pub struct serv_packet { + pub opcode: [libc::c_char; 4], + pub server_ip: crate::squeezelite_h::u32_t, +} +// possible sync group +// S:P:Squeezebox2 + +#[repr(C, packed)] +#[derive(Copy, Clone)] +pub struct setd_packet { + pub opcode: [libc::c_char; 4], + pub id: crate::squeezelite_h::u8_t, + pub data: [libc::c_char; 0], +} +// char metadata[] +// S:N:Slimproto _http_setting_handler + +#[repr(C, packed)] +#[derive(Copy, Clone)] +pub struct SETD_header { + pub opcode: [libc::c_char; 4], + pub length: crate::squeezelite_h::u32_t, + pub id: crate::squeezelite_h::u8_t, +} +// S:P:Squeezebox2 + +#[repr(C, packed)] +#[derive(Copy, Clone)] +pub struct audg_packet { + pub opcode: [libc::c_char; 4], + pub old_gainL: crate::squeezelite_h::u32_t, + pub old_gainR: crate::squeezelite_h::u32_t, + pub adjust: crate::squeezelite_h::u8_t, + pub preamp: crate::squeezelite_h::u8_t, + pub gainL: crate::squeezelite_h::u32_t, + pub gainR: crate::squeezelite_h::u32_t, +} +//char request_string[]; +// S:P:Squeezebox2 + +#[repr(C, packed)] +#[derive(Copy, Clone)] +pub struct aude_packet { + pub opcode: [libc::c_char; 4], + pub enable_spdif: crate::squeezelite_h::u8_t, + pub enable_dac: crate::squeezelite_h::u8_t, +} +// codec open - this is an extension to slimproto to allow the server to read the header and then return decode params + +#[repr(C, packed)] +#[derive(Copy, Clone)] +pub struct codc_packet { + pub opcode: [libc::c_char; 4], + pub format: crate::squeezelite_h::u8_t, + pub pcm_sample_size: crate::squeezelite_h::u8_t, + pub pcm_sample_rate: crate::squeezelite_h::u8_t, + pub pcm_channels: crate::squeezelite_h::u8_t, + pub pcm_endianness: crate::squeezelite_h::u8_t, +} +// squence ids - unused +// S:P:Squeezebox2 + +#[repr(C, packed)] +#[derive(Copy, Clone)] +pub struct cont_packet { + pub opcode: [libc::c_char; 4], + pub metaint: crate::squeezelite_h::u32_t, + pub loop_0: crate::squeezelite_h::u8_t, +} +// data +// from S:P:Squeezebox stream_s + +#[repr(C, packed)] +#[derive(Copy, Clone)] +pub struct strm_packet { + pub opcode: [libc::c_char; 4], + pub command: libc::c_char, + pub autostart: crate::squeezelite_h::u8_t, + pub format: crate::squeezelite_h::u8_t, + pub pcm_sample_size: crate::squeezelite_h::u8_t, + pub pcm_sample_rate: crate::squeezelite_h::u8_t, + pub pcm_channels: crate::squeezelite_h::u8_t, + pub pcm_endianness: crate::squeezelite_h::u8_t, + pub threshold: crate::squeezelite_h::u8_t, + pub spdif_enable: crate::squeezelite_h::u8_t, + pub transition_period: crate::squeezelite_h::u8_t, + pub transition_type: crate::squeezelite_h::u8_t, + pub flags: crate::squeezelite_h::u8_t, + pub output_threshold: crate::squeezelite_h::u8_t, + pub slaves: crate::squeezelite_h::u8_t, + pub replay_gain: crate::squeezelite_h::u32_t, + pub server_port: crate::squeezelite_h::u16_t, + pub server_ip: crate::squeezelite_h::u32_t, +} +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +// packet formats for slimproto +// from S:N:Slimproto _hello_handler + +#[repr(C, packed)] +#[derive(Copy, Clone)] +pub struct HELO_packet { + pub opcode: [libc::c_char; 4], + pub length: crate::squeezelite_h::u32_t, + pub deviceid: crate::squeezelite_h::u8_t, + pub revision: crate::squeezelite_h::u8_t, + pub mac: [crate::squeezelite_h::u8_t; 6], + pub uuid: [crate::squeezelite_h::u8_t; 16], + pub wlan_channellist: crate::squeezelite_h::u16_t, + pub bytes_received_H: crate::squeezelite_h::u32_t, + pub bytes_received_L: crate::squeezelite_h::u32_t, + pub lang: [libc::c_char; 2], +} +use ::libc; + +pub use crate::stddef_h::size_t; + +pub use crate::stdlib::_IO_codecvt; +pub use crate::stdlib::_IO_lock_t; +pub use crate::stdlib::_IO_marker; +pub use crate::stdlib::_IO_wide_data; +pub use crate::stdlib::__int32_t; +pub use crate::stdlib::__off64_t; +pub use crate::stdlib::__off_t; +pub use crate::stdlib::__socklen_t; +pub use crate::stdlib::__ssize_t; +pub use crate::stdlib::__uint16_t; +pub use crate::stdlib::__uint32_t; +pub use crate::stdlib::__uint64_t; +pub use crate::stdlib::__uint8_t; +pub use crate::stdlib::__useconds_t; +pub use crate::stdlib::fclose; +pub use crate::stdlib::fgets; +pub use crate::stdlib::fopen; +pub use crate::stdlib::fputs; +pub use crate::stdlib::int32_t; +pub use crate::stdlib::snprintf; +pub use crate::stdlib::ssize_t; +pub use crate::stdlib::FILE; +pub use crate::stdlib::_IO_FILE; + +pub use crate::stdlib::__pthread_internal_list; +pub use crate::stdlib::__pthread_list_t; +pub use crate::stdlib::__pthread_mutex_s; +pub use crate::stdlib::pthread_mutex_t; +pub use crate::stdlib::u_int16_t; +pub use crate::stdlib::u_int32_t; +pub use crate::stdlib::u_int64_t; +pub use crate::stdlib::u_int8_t; + +pub use crate::stdlib::__socket_type; +pub use crate::stdlib::close; +pub use crate::stdlib::sa_family_t; +pub use crate::stdlib::sleep; +pub use crate::stdlib::socklen_t; +pub use crate::stdlib::uint16_t; +pub use crate::stdlib::uint32_t; +pub use crate::stdlib::uint64_t; +pub use crate::stdlib::usleep; +pub use crate::stdlib::SOCK_CLOEXEC; +pub use crate::stdlib::SOCK_DCCP; +pub use crate::stdlib::SOCK_DGRAM; +pub use crate::stdlib::SOCK_NONBLOCK; +pub use crate::stdlib::SOCK_PACKET; +pub use crate::stdlib::SOCK_RAW; +pub use crate::stdlib::SOCK_RDM; +pub use crate::stdlib::SOCK_SEQPACKET; +pub use crate::stdlib::SOCK_STREAM; + +pub use crate::squeezelite_h::_buf_used; +pub use crate::squeezelite_h::buffer; +pub use crate::squeezelite_h::codec; +pub use crate::squeezelite_h::decode_state; +pub use crate::squeezelite_h::decodestate; +pub use crate::squeezelite_h::disconnect_code; +pub use crate::squeezelite_h::event_type; +pub use crate::squeezelite_h::fade_dir; +pub use crate::squeezelite_h::fade_mode; +pub use crate::squeezelite_h::fade_state; +pub use crate::squeezelite_h::frames_t; +pub use crate::squeezelite_h::lDEBUG; +pub use crate::squeezelite_h::lERROR; +pub use crate::squeezelite_h::lINFO; +pub use crate::squeezelite_h::lSDEBUG; +pub use crate::squeezelite_h::lWARN; +pub use crate::squeezelite_h::log_level; +pub use crate::squeezelite_h::output_format; +pub use crate::squeezelite_h::output_state; +pub use crate::squeezelite_h::outputstate; +pub use crate::squeezelite_h::s32_t; +pub use crate::squeezelite_h::sockfd; +pub use crate::squeezelite_h::stream_state; +pub use crate::squeezelite_h::streamstate; +pub use crate::squeezelite_h::u16_t; +pub use crate::squeezelite_h::u32_t; +pub use crate::squeezelite_h::u64_t; +pub use crate::squeezelite_h::u8_t; +pub use crate::squeezelite_h::C2RustUnnamed_1; +pub use crate::squeezelite_h::DECODE_COMPLETE; +pub use crate::squeezelite_h::DECODE_ERROR; +pub use crate::squeezelite_h::DECODE_READY; +pub use crate::squeezelite_h::DECODE_RUNNING; +pub use crate::squeezelite_h::DECODE_STOPPED; +pub use crate::squeezelite_h::DISCONNECT; +pub use crate::squeezelite_h::DISCONNECT_OK; +pub use crate::squeezelite_h::EVENT_READ; +pub use crate::squeezelite_h::EVENT_TIMEOUT; +pub use crate::squeezelite_h::EVENT_WAKE; +pub use crate::squeezelite_h::FADE_ACTIVE; +pub use crate::squeezelite_h::FADE_CROSS; +pub use crate::squeezelite_h::FADE_CROSSFADE; +pub use crate::squeezelite_h::FADE_DOWN; +pub use crate::squeezelite_h::FADE_DUE; +pub use crate::squeezelite_h::FADE_IN; +pub use crate::squeezelite_h::FADE_INACTIVE; +pub use crate::squeezelite_h::FADE_INOUT; +pub use crate::squeezelite_h::FADE_NONE; +pub use crate::squeezelite_h::FADE_OUT; +pub use crate::squeezelite_h::FADE_UP; +pub use crate::squeezelite_h::LOCAL_DISCONNECT; +pub use crate::squeezelite_h::OUTPUT_BUFFER; +pub use crate::squeezelite_h::OUTPUT_OFF; +pub use crate::squeezelite_h::OUTPUT_PAUSE_FRAMES; +pub use crate::squeezelite_h::OUTPUT_RUNNING; +pub use crate::squeezelite_h::OUTPUT_SKIP_FRAMES; +pub use crate::squeezelite_h::OUTPUT_START_AT; +pub use crate::squeezelite_h::OUTPUT_STOPPED; +pub use crate::squeezelite_h::RECV_HEADERS; +pub use crate::squeezelite_h::REMOTE_DISCONNECT; +pub use crate::squeezelite_h::S16_LE; +pub use crate::squeezelite_h::S24_3LE; +pub use crate::squeezelite_h::S24_LE; +pub use crate::squeezelite_h::S32_LE; +pub use crate::squeezelite_h::SEND_HEADERS; +pub use crate::squeezelite_h::STOPPED; +pub use crate::squeezelite_h::STREAMING_BUFFERING; +pub use crate::squeezelite_h::STREAMING_FILE; +pub use crate::squeezelite_h::STREAMING_HTTP; +pub use crate::squeezelite_h::STREAMING_WAIT; +pub use crate::squeezelite_h::TIMEOUT; +pub use crate::squeezelite_h::UNREACHABLE; +pub use crate::src::buffer::buf_flush; +pub use crate::src::decode::codec_open; +pub use crate::src::decode::decode_flush; +pub use crate::src::output::output_flush; +pub use crate::src::output_alsa::set_volume; +pub use crate::src::stream::stream_disconnect; +pub use crate::src::stream::stream_file; +pub use crate::src::stream::stream_sock; +pub use crate::src::utils::connect_timeout; +pub use crate::src::utils::gettime_ms; +pub use crate::src::utils::logprint; +pub use crate::src::utils::logtime; +pub use crate::src::utils::packN; +pub use crate::src::utils::packn; +pub use crate::src::utils::server_addr; +pub use crate::src::utils::set_nonblock; +pub use crate::src::utils::set_readwake_handles; +pub use crate::src::utils::unpackN; +pub use crate::src::utils::wait_readwake; +use crate::stdlib::__errno_location; +pub use crate::stdlib::eventfd; +pub use crate::stdlib::eventfd_t; +pub use crate::stdlib::eventfd_write; +use crate::stdlib::free; +use crate::stdlib::getsockname; +pub use crate::stdlib::htonl; +pub use crate::stdlib::htons; +pub use crate::stdlib::in_addr; +pub use crate::stdlib::in_addr_t; +pub use crate::stdlib::in_port_t; +use crate::stdlib::inet_ntoa; +use crate::stdlib::malloc; +use crate::stdlib::memcpy; +use crate::stdlib::memset; +pub use crate::stdlib::nfds_t; +pub use crate::stdlib::ntohs; +pub use crate::stdlib::poll; +pub use crate::stdlib::pollfd; +use crate::stdlib::pthread_mutex_lock; +use crate::stdlib::pthread_mutex_unlock; +use crate::stdlib::recv; +use crate::stdlib::recvfrom; +use crate::stdlib::send; +use crate::stdlib::sendto; +use crate::stdlib::setsockopt; +pub use crate::stdlib::sockaddr; +pub use crate::stdlib::sockaddr_in; +use crate::stdlib::socket; +use crate::stdlib::strcat; +use crate::stdlib::strerror; +use crate::stdlib::strlen; +use crate::stdlib::strncat; +use crate::stdlib::strncmp; +use crate::stdlib::strncpy; +pub use crate::stdlib::C2RustUnnamed_0; +pub use crate::stdlib::MSG_BATCH; +pub use crate::stdlib::MSG_CMSG_CLOEXEC; +pub use crate::stdlib::MSG_CONFIRM; +pub use crate::stdlib::MSG_CTRUNC; +pub use crate::stdlib::MSG_DONTROUTE; +pub use crate::stdlib::MSG_DONTWAIT; +pub use crate::stdlib::MSG_EOR; +pub use crate::stdlib::MSG_ERRQUEUE; +pub use crate::stdlib::MSG_FASTOPEN; +pub use crate::stdlib::MSG_FIN; +pub use crate::stdlib::MSG_MORE; +pub use crate::stdlib::MSG_NOSIGNAL; +pub use crate::stdlib::MSG_OOB; +pub use crate::stdlib::MSG_PEEK; +pub use crate::stdlib::MSG_PROXY; +pub use crate::stdlib::MSG_RST; +pub use crate::stdlib::MSG_SYN; +pub use crate::stdlib::MSG_TRUNC; +pub use crate::stdlib::MSG_WAITALL; +pub use crate::stdlib::MSG_WAITFORONE; +pub use crate::stdlib::MSG_ZEROCOPY; +extern "C" { + #[no_mangle] + pub static mut streambuf: *mut crate::squeezelite_h::buffer; + #[no_mangle] + pub static mut outputbuf: *mut crate::squeezelite_h::buffer; + #[no_mangle] + pub static mut stream: crate::squeezelite_h::streamstate; + #[no_mangle] + pub static mut output: crate::squeezelite_h::outputstate; + #[no_mangle] + pub static mut decode: crate::squeezelite_h::decodestate; + #[no_mangle] + pub static mut codecs: [*mut crate::squeezelite_h::codec; 0]; +} + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct C2RustUnnamed_17 { + pub updated: crate::squeezelite_h::u32_t, + pub stream_start: crate::squeezelite_h::u32_t, + pub stream_full: crate::squeezelite_h::u32_t, + pub stream_size: crate::squeezelite_h::u32_t, + pub stream_bytes: crate::squeezelite_h::u64_t, + pub output_full: crate::squeezelite_h::u32_t, + pub output_size: crate::squeezelite_h::u32_t, + pub frames_played: crate::squeezelite_h::u32_t, + pub device_frames: crate::squeezelite_h::u32_t, + pub current_sample_rate: crate::squeezelite_h::u32_t, + pub last: crate::squeezelite_h::u32_t, + pub stream_state: crate::squeezelite_h::stream_state, +} + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct handler { + pub opcode: [libc::c_char; 5], + pub handler: + Option ()>, +} +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Additions (c) Paul Hermann, 2015-2017 under the same license terms + * -Control of Raspberry pi GPIO for amplifier power + * -Launch script on power status change from LMS + */ + +static mut loglevel: crate::squeezelite_h::log_level = crate::squeezelite_h::lERROR; +// 3483 + +static mut sock: crate::squeezelite_h::sockfd = -(1 as libc::c_int); + +static mut slimproto_ip: crate::stdlib::in_addr_t = 0 as libc::c_int as crate::stdlib::in_addr_t; +#[no_mangle] + +pub static mut wake_e: libc::c_int = 0; + +static mut status: C2RustUnnamed_17 = C2RustUnnamed_17 { + updated: 0, + stream_start: 0, + stream_full: 0, + stream_size: 0, + stream_bytes: 0, + output_full: 0, + output_size: 0, + frames_played: 0, + device_frames: 0, + current_sample_rate: 0, + last: 0, + stream_state: crate::squeezelite_h::STOPPED, +}; +#[no_mangle] + +pub static mut autostart: libc::c_int = 0; +#[no_mangle] + +pub static mut sentSTMu: bool = false; +#[no_mangle] + +pub static mut sentSTMo: bool = false; +#[no_mangle] + +pub static mut sentSTMl: bool = false; +#[no_mangle] + +pub static mut new_server: crate::squeezelite_h::u32_t = 0; +#[no_mangle] + +pub static mut new_server_cap: *mut libc::c_char = 0 as *const libc::c_char as *mut libc::c_char; +#[no_mangle] + +pub static mut player_name: [libc::c_char; 65] = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, +]; +#[no_mangle] + +pub static mut name_file: *const libc::c_char = 0 as *const libc::c_char; +#[no_mangle] + +pub unsafe extern "C" fn send_packet( + mut packet: *mut crate::squeezelite_h::u8_t, + mut len: crate::stddef_h::size_t, +) { + let mut ptr = packet; // squeezeplay + let mut try_0 = 0 as libc::c_int as libc::c_uint; + let mut n: crate::stdlib::ssize_t = 0; + while len != 0 { + n = crate::stdlib::send( + sock, + ptr as *const libc::c_void, + len, + crate::stdlib::MSG_NOSIGNAL as libc::c_int, + ); + if n <= 0 as libc::c_int as libc::c_long { + if n < 0 as libc::c_int as libc::c_long + && *crate::stdlib::__errno_location() == 11 as libc::c_int + && try_0 < 10 as libc::c_int as libc::c_uint + { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + try_0 = try_0.wrapping_add(1); + crate::src::utils::logprint( + b"%s %s:%d retrying (%d) writing to socket\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>( + b"send_packet\x00", + )) + .as_ptr(), + 104 as libc::c_int, + try_0, + ); + } + crate::stdlib::usleep(1000 as libc::c_int as crate::stdlib::__useconds_t); + } else { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d failed writing to socket: %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>( + b"send_packet\x00", + )) + .as_ptr(), + 108 as libc::c_int, + crate::stdlib::strerror(*crate::stdlib::__errno_location()), + ); + } + return; + } + } else { + ptr = ptr.offset(n as isize); + len = (len as libc::c_ulong).wrapping_sub(n as libc::c_ulong) as crate::stddef_h::size_t + as crate::stddef_h::size_t + } + } +} + +unsafe extern "C" fn sendHELO( + mut reconnect: bool, + mut fixed_cap: *const libc::c_char, + mut var_cap: *const libc::c_char, + mut mac: *mut crate::squeezelite_h::u8_t, +) { + let mut base_cap = 0 as *const libc::c_char; + let mut pkt = crate::src::slimproto::HELO_packet { + opcode: [0; 4], + length: 0, + deviceid: 0, + revision: 0, + mac: [0; 6], + uuid: [0; 16], + wlan_channellist: 0, + bytes_received_H: 0, + bytes_received_L: 0, + lang: [0; 2], + }; + base_cap = + b"Model=squeezelite,AccuratePlayPoints=1,HasDigitalOut=1,HasPolarityInversion=1,Firmware=v1.9.7-1218\x00" + as *const u8 as *const libc::c_char; + crate::stdlib::memset( + &mut pkt as *mut crate::src::slimproto::HELO_packet as *mut libc::c_void, + 0 as libc::c_int, + ::std::mem::size_of::() as libc::c_ulong, + ); + crate::stdlib::memcpy( + &mut pkt.opcode as *mut [libc::c_char; 4] as *mut libc::c_void, + b"HELO\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ); + pkt.length = crate::stdlib::htonl( + (::std::mem::size_of::() as libc::c_ulong) + .wrapping_sub(8 as libc::c_int as libc::c_ulong) + .wrapping_add(crate::stdlib::strlen(base_cap)) + .wrapping_add(crate::stdlib::strlen(fixed_cap)) + .wrapping_add(crate::stdlib::strlen(var_cap)) as crate::stdlib::uint32_t, + ); + pkt.deviceid = 12 as libc::c_int as crate::squeezelite_h::u8_t; + pkt.revision = 0 as libc::c_int as crate::squeezelite_h::u8_t; + crate::src::utils::packn( + &mut pkt.wlan_channellist, + if reconnect as libc::c_int != 0 { + 0x4000 as libc::c_int + } else { + 0 as libc::c_int + } as crate::squeezelite_h::u16_t, + ); + crate::src::utils::packN( + &mut pkt.bytes_received_H, + (status.stream_bytes >> 32 as libc::c_int) as crate::squeezelite_h::u32_t, + ); + crate::src::utils::packN( + &mut pkt.bytes_received_L, + (status.stream_bytes & 0xffffffff as libc::c_uint as libc::c_ulong) + as crate::squeezelite_h::u32_t, + ); + crate::stdlib::memcpy( + pkt.mac.as_mut_ptr() as *mut libc::c_void, + mac as *const libc::c_void, + 6 as libc::c_int as libc::c_ulong, + ); + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d mac: %02x:%02x:%02x:%02x:%02x:%02x\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"sendHELO\x00")).as_ptr(), + 142 as libc::c_int, + pkt.mac[0 as libc::c_int as usize] as libc::c_int, + pkt.mac[1 as libc::c_int as usize] as libc::c_int, + pkt.mac[2 as libc::c_int as usize] as libc::c_int, + pkt.mac[3 as libc::c_int as usize] as libc::c_int, + pkt.mac[4 as libc::c_int as usize] as libc::c_int, + pkt.mac[5 as libc::c_int as usize] as libc::c_int, + ); + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d cap: %s%s%s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"sendHELO\x00")).as_ptr(), + 144 as libc::c_int, + base_cap, + fixed_cap, + var_cap, + ); + } + send_packet( + &mut pkt as *mut crate::src::slimproto::HELO_packet as *mut crate::squeezelite_h::u8_t, + ::std::mem::size_of::() as libc::c_ulong, + ); + send_packet( + base_cap as *mut crate::squeezelite_h::u8_t, + crate::stdlib::strlen(base_cap), + ); + send_packet( + fixed_cap as *mut crate::squeezelite_h::u8_t, + crate::stdlib::strlen(fixed_cap), + ); + send_packet( + var_cap as *mut crate::squeezelite_h::u8_t, + crate::stdlib::strlen(var_cap), + ); +} + +unsafe extern "C" fn sendSTAT( + mut event: *const libc::c_char, + mut server_timestamp: crate::squeezelite_h::u32_t, +) { + let mut pkt = crate::src::slimproto::STAT_packet { + opcode: [0; 4], + length: 0, + event: 0, + num_crlf: 0, + mas_initialized: 0, + mas_mode: 0, + stream_buffer_size: 0, + stream_buffer_fullness: 0, + bytes_received_H: 0, + bytes_received_L: 0, + signal_strength: 0, + jiffies: 0, + output_buffer_size: 0, + output_buffer_fullness: 0, + elapsed_seconds: 0, + voltage: 0, + elapsed_milliseconds: 0, + server_timestamp: 0, + error_code: 0, + }; + let mut now = crate::src::utils::gettime_ms(); + let mut ms_played: crate::squeezelite_h::u32_t = 0; + if status.current_sample_rate != 0 + && status.frames_played != 0 + && status.frames_played > status.device_frames + { + ms_played = (status.frames_played.wrapping_sub(status.device_frames) + as crate::squeezelite_h::u64_t) + .wrapping_mul(1000 as libc::c_int as crate::squeezelite_h::u64_t) + .wrapping_div(status.current_sample_rate as crate::squeezelite_h::u64_t) + as crate::squeezelite_h::u32_t; + if now > status.updated { + ms_played = (ms_played as libc::c_uint).wrapping_add(now.wrapping_sub(status.updated)) + as crate::squeezelite_h::u32_t + as crate::squeezelite_h::u32_t + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d ms_played: %u (frames_played: %u device_frames: %u)\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"sendSTAT\x00")).as_ptr(), + 160 as libc::c_int, + ms_played, + status.frames_played, + status.device_frames, + ); + } + } else if status.frames_played != 0 && now > status.stream_start { + ms_played = now.wrapping_sub(status.stream_start); + if loglevel as libc::c_uint >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint(b"%s %s:%d ms_played: %u using elapsed time (frames_played: %u device_frames: %u)\n\x00" + as *const u8 as *const libc::c_char, crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], + &[libc::c_char; 9]>(b"sendSTAT\x00")).as_ptr(), + 163 as libc::c_int, ms_played, status.frames_played, + status.device_frames); + } + } else { + if loglevel as libc::c_uint >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d ms_played: 0\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"sendSTAT\x00")).as_ptr(), + 165 as libc::c_int, + ); + } + ms_played = 0 as libc::c_int as crate::squeezelite_h::u32_t + } + crate::stdlib::memset( + &mut pkt as *mut crate::src::slimproto::STAT_packet as *mut libc::c_void, + 0 as libc::c_int, + ::std::mem::size_of::() as libc::c_ulong, + ); + crate::stdlib::memcpy( + &mut pkt.opcode as *mut [libc::c_char; 4] as *mut libc::c_void, + b"STAT\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ); + pkt.length = crate::stdlib::htonl( + (::std::mem::size_of::() as libc::c_ulong) + .wrapping_sub(8 as libc::c_int as libc::c_ulong) as crate::stdlib::uint32_t, + ); + crate::stdlib::memcpy( + &mut pkt.event as *mut crate::squeezelite_h::u32_t as *mut libc::c_void, + event as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ); + // num_crlf + // mas_initialized; mas_mode; + crate::src::utils::packN(&mut pkt.stream_buffer_fullness, status.stream_full); + crate::src::utils::packN(&mut pkt.stream_buffer_size, status.stream_size); + crate::src::utils::packN( + &mut pkt.bytes_received_H, + (status.stream_bytes >> 32 as libc::c_int) as crate::squeezelite_h::u32_t, + ); + crate::src::utils::packN( + &mut pkt.bytes_received_L, + (status.stream_bytes & 0xffffffff as libc::c_uint as libc::c_ulong) + as crate::squeezelite_h::u32_t, + ); + pkt.signal_strength = 0xffff as libc::c_int as crate::squeezelite_h::u16_t; + crate::src::utils::packN(&mut pkt.jiffies, now); + crate::src::utils::packN(&mut pkt.output_buffer_size, status.output_size); + crate::src::utils::packN(&mut pkt.output_buffer_fullness, status.output_full); + crate::src::utils::packN( + &mut pkt.elapsed_seconds, + ms_played.wrapping_div(1000 as libc::c_int as libc::c_uint), + ); + // voltage; + crate::src::utils::packN(&mut pkt.elapsed_milliseconds, ms_played); // keep this is server format - don't unpack/pack + pkt.server_timestamp = server_timestamp; + // error_code; + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d STAT: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"sendSTAT\x00")).as_ptr(), + 189 as libc::c_int, + event, + ); // id 0 is playername S:P:Squeezebox2 + } // STMt replay_gain is no longer used to track latency, but support it + if loglevel as libc::c_uint == crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint { + if loglevel as libc::c_uint >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint(b"%s %s:%d received bytesL: %u streambuf: %u outputbuf: %u calc elapsed: %u real elapsed: %u (diff: %d) device: %u delay: %d\n\x00" + as *const u8 as *const libc::c_char, crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], + &[libc::c_char; 9]>(b"sendSTAT\x00")).as_ptr(), + 194 as libc::c_int, status.stream_bytes as crate::squeezelite_h::u32_t, + status.stream_full, status.output_full, ms_played, + now.wrapping_sub(status.stream_start), + ms_played.wrapping_sub(now).wrapping_add(status.stream_start), + status.device_frames.wrapping_mul(1000 as libc::c_int as + libc::c_uint).wrapping_div(status.current_sample_rate), + now.wrapping_sub(status.updated)); // keep in network byte order + } + } // keep in network byte order + send_packet( + &mut pkt as *mut crate::src::slimproto::STAT_packet as *mut crate::squeezelite_h::u8_t, + ::std::mem::size_of::() as libc::c_ulong, + ); +} + +unsafe extern "C" fn sendDSCO(mut disconnect: crate::squeezelite_h::disconnect_code) { + let mut pkt = crate::src::slimproto::DSCO_packet { + opcode: [0; 4], + length: 0, + reason: 0, + }; + crate::stdlib::memset( + &mut pkt as *mut crate::src::slimproto::DSCO_packet as *mut libc::c_void, + 0 as libc::c_int, + ::std::mem::size_of::() as libc::c_ulong, + ); + crate::stdlib::memcpy( + &mut pkt.opcode as *mut [libc::c_char; 4] as *mut libc::c_void, + b"DSCO\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ); + pkt.length = crate::stdlib::htonl( + (::std::mem::size_of::() as libc::c_ulong) + .wrapping_sub(8 as libc::c_int as libc::c_ulong) as crate::stdlib::uint32_t, + ); + pkt.reason = (disconnect as libc::c_uint & 0xff as libc::c_int as libc::c_uint) + as crate::squeezelite_h::u8_t; + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d DSCO: %d\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"sendDSCO\x00")).as_ptr(), + 208 as libc::c_int, + disconnect as libc::c_uint, + ); + } + send_packet( + &mut pkt as *mut crate::src::slimproto::DSCO_packet as *mut crate::squeezelite_h::u8_t, + ::std::mem::size_of::() as libc::c_ulong, + ); +} + +unsafe extern "C" fn sendRESP(mut header: *const libc::c_char, mut len: crate::stddef_h::size_t) { + let mut pkt_header = crate::src::slimproto::RESP_header { + opcode: [0; 4], + length: 0, + }; + crate::stdlib::memset( + &mut pkt_header as *mut crate::src::slimproto::RESP_header as *mut libc::c_void, + 0 as libc::c_int, + ::std::mem::size_of::() as libc::c_ulong, + ); + crate::stdlib::memcpy( + &mut pkt_header.opcode as *mut [libc::c_char; 4] as *mut libc::c_void, + b"RESP\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ); + pkt_header.length = crate::stdlib::htonl( + (::std::mem::size_of::() as libc::c_ulong) + .wrapping_add(len) + .wrapping_sub(8 as libc::c_int as libc::c_ulong) as crate::stdlib::uint32_t, + ); + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d RESP\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"sendRESP\x00")).as_ptr(), + 220 as libc::c_int, + ); + } + send_packet( + &mut pkt_header as *mut crate::src::slimproto::RESP_header + as *mut crate::squeezelite_h::u8_t, + ::std::mem::size_of::() as libc::c_ulong, + ); + send_packet(header as *mut crate::squeezelite_h::u8_t, len); +} + +unsafe extern "C" fn sendMETA(mut meta: *const libc::c_char, mut len: crate::stddef_h::size_t) { + let mut pkt_header = crate::src::slimproto::META_header { + opcode: [0; 4], + length: 0, + }; + crate::stdlib::memset( + &mut pkt_header as *mut crate::src::slimproto::META_header as *mut libc::c_void, + 0 as libc::c_int, + ::std::mem::size_of::() as libc::c_ulong, + ); + crate::stdlib::memcpy( + &mut pkt_header.opcode as *mut [libc::c_char; 4] as *mut libc::c_void, + b"META\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ); + pkt_header.length = crate::stdlib::htonl( + (::std::mem::size_of::() as libc::c_ulong) + .wrapping_add(len) + .wrapping_sub(8 as libc::c_int as libc::c_ulong) as crate::stdlib::uint32_t, + ); + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d META\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"sendMETA\x00")).as_ptr(), + 233 as libc::c_int, + ); + } + send_packet( + &mut pkt_header as *mut crate::src::slimproto::META_header + as *mut crate::squeezelite_h::u8_t, + ::std::mem::size_of::() as libc::c_ulong, + ); + send_packet(meta as *mut crate::squeezelite_h::u8_t, len); +} + +unsafe extern "C" fn sendSETDName(mut name: *const libc::c_char) { + let mut pkt_header = crate::src::slimproto::SETD_header { + opcode: [0; 4], + length: 0, + id: 0, + }; + crate::stdlib::memset( + &mut pkt_header as *mut crate::src::slimproto::SETD_header as *mut libc::c_void, + 0 as libc::c_int, + ::std::mem::size_of::() as libc::c_ulong, + ); + crate::stdlib::memcpy( + &mut pkt_header.opcode as *mut [libc::c_char; 4] as *mut libc::c_void, + b"SETD\x00" as *const u8 as *const libc::c_char as *const libc::c_void, + 4 as libc::c_int as libc::c_ulong, + ); + pkt_header.id = 0 as libc::c_int as crate::squeezelite_h::u8_t; + pkt_header.length = crate::stdlib::htonl( + (::std::mem::size_of::() as libc::c_ulong) + .wrapping_add(crate::stdlib::strlen(name)) + .wrapping_add(1 as libc::c_int as libc::c_ulong) + .wrapping_sub(8 as libc::c_int as libc::c_ulong) as crate::stdlib::uint32_t, + ); + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d set playername: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"sendSETDName\x00")) + .as_ptr(), + 248 as libc::c_int, + name, + ); + } + send_packet( + &mut pkt_header as *mut crate::src::slimproto::SETD_header + as *mut crate::squeezelite_h::u8_t, + ::std::mem::size_of::() as libc::c_ulong, + ); + send_packet( + name as *mut crate::squeezelite_h::u8_t, + crate::stdlib::strlen(name).wrapping_add(1 as libc::c_int as libc::c_ulong), + ); +} + +unsafe extern "C" fn process_strm(mut pkt: *mut crate::squeezelite_h::u8_t, mut len: libc::c_int) { + let mut strm = pkt as *mut crate::src::slimproto::strm_packet; + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d strm command %c\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"process_strm\x00")) + .as_ptr(), + 274 as libc::c_int, + (*strm).command as libc::c_int, + ); + } + let mut current_block_78: u64; + match (*strm).command as libc::c_int { + 116 => { + sendSTAT( + b"STMt\x00" as *const u8 as *const libc::c_char, + (*strm).replay_gain, + ); + } + 113 => { + crate::src::decode::decode_flush(); + crate::src::output::output_flush(); + status.frames_played = 0 as libc::c_int as crate::squeezelite_h::u32_t; + crate::src::stream::stream_disconnect(); + sendSTAT( + b"STMf\x00" as *const u8 as *const libc::c_char, + 0 as libc::c_int as crate::squeezelite_h::u32_t, + ); + crate::src::buffer::buf_flush(streambuf); + } + 102 => { + crate::src::decode::decode_flush(); + crate::src::output::output_flush(); + status.frames_played = 0 as libc::c_int as crate::squeezelite_h::u32_t; + if crate::src::stream::stream_disconnect() { + sendSTAT( + b"STMf\x00" as *const u8 as *const libc::c_char, + 0 as libc::c_int as crate::squeezelite_h::u32_t, + ); + } + crate::src::buffer::buf_flush(streambuf); + } + 112 => { + let mut interval = crate::src::utils::unpackN(&mut (*strm).replay_gain); + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + output.c2rust_unnamed.pause_frames = interval + .wrapping_mul(status.current_sample_rate) + .wrapping_div(1000 as libc::c_int as libc::c_uint); + if interval != 0 { + output.state = crate::squeezelite_h::OUTPUT_PAUSE_FRAMES + } else { + output.state = crate::squeezelite_h::OUTPUT_STOPPED; + output.stop_time = crate::src::utils::gettime_ms() + } + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + if interval == 0 { + sendSTAT( + b"STMp\x00" as *const u8 as *const libc::c_char, + 0 as libc::c_int as crate::squeezelite_h::u32_t, + ); + } + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d pause interval: %u\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"process_strm\x00")) + .as_ptr(), + 310 as libc::c_int, + interval, + ); + } + } + 97 => { + let mut interval_0 = crate::src::utils::unpackN(&mut (*strm).replay_gain); + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + output.c2rust_unnamed.skip_frames = interval_0 + .wrapping_mul(status.current_sample_rate) + .wrapping_div(1000 as libc::c_int as libc::c_uint); + output.state = crate::squeezelite_h::OUTPUT_SKIP_FRAMES; + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d skip ahead interval: %u\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"process_strm\x00")) + .as_ptr(), + 320 as libc::c_int, + interval_0, + ); + } + } + 117 => { + let mut jiffies = crate::src::utils::unpackN(&mut (*strm).replay_gain); + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + output.state = if jiffies != 0 { + crate::squeezelite_h::OUTPUT_START_AT as libc::c_int + } else { + crate::squeezelite_h::OUTPUT_RUNNING as libc::c_int + } as crate::squeezelite_h::output_state; + output.c2rust_unnamed.start_at = jiffies; + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d unpause at: %u now: %u\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"process_strm\x00")) + .as_ptr(), + 331 as libc::c_int, + jiffies, + crate::src::utils::gettime_ms(), + ); + } + sendSTAT( + b"STMr\x00" as *const u8 as *const libc::c_char, + 0 as libc::c_int as crate::squeezelite_h::u32_t, + ); + } + 115 => { + let mut header_len = (len as libc::c_ulong) + .wrapping_sub( + ::std::mem::size_of::() as libc::c_ulong + ) as libc::c_uint; + let mut header = pkt.offset(::std::mem::size_of::() + as libc::c_ulong as isize) as *mut libc::c_char; + let mut ip = (*strm).server_ip; + let mut port = (*strm).server_port; + if ip == 0 as libc::c_int as libc::c_uint { + ip = slimproto_ip + } + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint(b"%s %s:%d strm s autostart: %c transition period: %u transition type: %u codec: %c\n\x00" + as *const u8 as *const libc::c_char, crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], + &[libc::c_char; 13]>(b"process_strm\x00")).as_ptr(), + 344 as libc::c_int, (*strm).autostart as libc::c_int, + (*strm).transition_period as libc::c_int, + (*strm).transition_type as libc::c_int - '0' as i32, + (*strm).format as libc::c_int); + } + autostart = (*strm).autostart as libc::c_int - '0' as i32; + sendSTAT( + b"STMf\x00" as *const u8 as *const libc::c_char, + 0 as libc::c_int as crate::squeezelite_h::u32_t, + ); + if header_len > (4096 as libc::c_int - 1 as libc::c_int) as libc::c_uint { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d header too long: %u\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>( + b"process_strm\x00", + )) + .as_ptr(), + 350 as libc::c_int, + header_len, + ); + } + } else { + if (*strm).format as libc::c_int != '?' as i32 { + crate::src::decode::codec_open( + (*strm).format, + (*strm).pcm_sample_size, + (*strm).pcm_sample_rate, + (*strm).pcm_channels, + (*strm).pcm_endianness, + ); + current_block_78 = 12758904613967585247; + } else if autostart >= 2 as libc::c_int { + // extension to slimproto to allow server to detect codec from response header and send back in codc message + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d streaming unknown codec\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>( + b"process_strm\x00", + )) + .as_ptr(), + 357 as libc::c_int, + ); + } + current_block_78 = 12758904613967585247; + } else { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d unknown codec requires autostart >= 2\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>( + b"process_strm\x00", + )) + .as_ptr(), + 359 as libc::c_int, + ); + } + current_block_78 = 15587532755333643506; + } + match current_block_78 { + 15587532755333643506 => {} + _ => { + if ip == 0x100007f as libc::c_int as libc::c_uint + && port as libc::c_int == 0x9b0d as libc::c_int + { + // extension to slimproto for LocalPlayer - header is filename not http header, don't expect cont + crate::src::stream::stream_file( + header, + header_len as crate::stddef_h::size_t, + ((*strm).threshold as libc::c_int * 1024 as libc::c_int) + as libc::c_uint, + ); + autostart -= 2 as libc::c_int + } else { + crate::src::stream::stream_sock( + ip, + port, + header, + header_len as crate::stddef_h::size_t, + ((*strm).threshold as libc::c_int * 1024 as libc::c_int) + as libc::c_uint, + autostart >= 2 as libc::c_int, + ); + } + sendSTAT( + b"STMc\x00" as *const u8 as *const libc::c_char, + 0 as libc::c_int as crate::squeezelite_h::u32_t, + ); + sentSTMl = 0 as libc::c_int != 0; + sentSTMo = sentSTMl; + sentSTMu = sentSTMo; + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + output.threshold = (*strm).output_threshold as libc::c_uint; + output.next_replay_gain = + crate::src::utils::unpackN(&mut (*strm).replay_gain); + output.fade_mode = ((*strm).transition_type as libc::c_int - '0' as i32) + as crate::squeezelite_h::fade_mode; + output.fade_secs = (*strm).transition_period as libc::c_uint; + output.invert = + (*strm).flags as libc::c_int & 0x3 as libc::c_int == 0x3 as libc::c_int; + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d set fade mode: %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>( + b"process_strm\x00", + )) + .as_ptr(), + 377 as libc::c_int, + output.fade_mode as libc::c_uint, + ); + } + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + } + } + } + } + _ => { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d unhandled strm %c\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"process_strm\x00")) + .as_ptr(), + 382 as libc::c_int, + (*strm).command as libc::c_int, + ); + } + } + }; +} + +unsafe extern "C" fn process_cont(mut pkt: *mut crate::squeezelite_h::u8_t, mut len: libc::c_int) { + let mut cont = pkt as *mut crate::src::slimproto::cont_packet; + (*cont).metaint = crate::src::utils::unpackN(&mut (*cont).metaint); + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d cont metaint: %u loop: %u\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"process_cont\x00")) + .as_ptr(), + 391 as libc::c_int, + (*cont).metaint, + (*cont).loop_0 as libc::c_int, + ); + } + if autostart > 1 as libc::c_int { + autostart -= 2 as libc::c_int; + crate::stdlib::pthread_mutex_lock(&mut (*streambuf).mutex); + if stream.state as libc::c_uint + == crate::squeezelite_h::STREAMING_WAIT as libc::c_int as libc::c_uint + { + stream.state = crate::squeezelite_h::STREAMING_BUFFERING; + stream.meta_next = (*cont).metaint; + stream.meta_interval = stream.meta_next + } + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + wake_controller(); + }; +} + +unsafe extern "C" fn process_codc(mut pkt: *mut crate::squeezelite_h::u8_t, mut len: libc::c_int) { + let mut codc = pkt as *mut crate::src::slimproto::codc_packet; + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d codc: %c\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"process_codc\x00")) + .as_ptr(), + 408 as libc::c_int, + (*codc).format as libc::c_int, + ); + } + crate::src::decode::codec_open( + (*codc).format, + (*codc).pcm_sample_size, + (*codc).pcm_sample_rate, + (*codc).pcm_channels, + (*codc).pcm_endianness, + ); +} + +unsafe extern "C" fn process_aude(mut pkt: *mut crate::squeezelite_h::u8_t, mut len: libc::c_int) { + let mut aude = pkt as *mut crate::src::slimproto::aude_packet; + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d enable spdif: %d dac: %d\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"process_aude\x00")) + .as_ptr(), + 415 as libc::c_int, + (*aude).enable_spdif as libc::c_int, + (*aude).enable_dac as libc::c_int, + ); + } + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + if (*aude).enable_spdif == 0 + && output.state as libc::c_int != crate::squeezelite_h::OUTPUT_OFF as libc::c_int + { + output.state = crate::squeezelite_h::OUTPUT_OFF + } + if (*aude).enable_spdif as libc::c_int != 0 + && output.state as libc::c_int == crate::squeezelite_h::OUTPUT_OFF as libc::c_int + && output.idle_to == 0 + { + output.state = crate::squeezelite_h::OUTPUT_STOPPED; + output.stop_time = crate::src::utils::gettime_ms() + } + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); +} + +unsafe extern "C" fn process_audg(mut pkt: *mut crate::squeezelite_h::u8_t, mut len: libc::c_int) { + let mut audg = pkt as *mut crate::src::slimproto::audg_packet; + (*audg).gainL = crate::src::utils::unpackN(&mut (*audg).gainL); + (*audg).gainR = crate::src::utils::unpackN(&mut (*audg).gainR); + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d audg gainL: %u gainR: %u adjust: %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"process_audg\x00")) + .as_ptr(), + 433 as libc::c_int, + (*audg).gainL, + (*audg).gainR, + (*audg).adjust as libc::c_int, + ); + } + crate::src::output_alsa::set_volume( + if (*audg).adjust as libc::c_int != 0 { + (*audg).gainL + } else { + 0x10000 as libc::c_int as libc::c_uint + }, + if (*audg).adjust as libc::c_int != 0 { + (*audg).gainR + } else { + 0x10000 as libc::c_int as libc::c_uint + }, + ); +} + +unsafe extern "C" fn process_setd(mut pkt: *mut crate::squeezelite_h::u8_t, mut len: libc::c_int) { + let mut setd = pkt as *mut crate::src::slimproto::setd_packet; + // handle player name query and change + if (*setd).id as libc::c_int == 0 as libc::c_int { + if len == 5 as libc::c_int { + if crate::stdlib::strlen(player_name.as_mut_ptr()) != 0 { + sendSETDName(player_name.as_mut_ptr()); + } + } else if len > 5 as libc::c_int { + crate::stdlib::strncpy( + player_name.as_mut_ptr(), + (*setd).data.as_mut_ptr(), + 64 as libc::c_int as libc::c_ulong, + ); + player_name[64 as libc::c_int as usize] = '\u{0}' as i32 as libc::c_char; + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d set name: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"process_setd\x00")) + .as_ptr(), + 450 as libc::c_int, + (*setd).data.as_mut_ptr(), + ); + } + // confirm change to server + sendSETDName((*setd).data.as_mut_ptr()); + // write name to name_file if -N option set + if !name_file.is_null() { + let mut fp = + crate::stdlib::fopen(name_file, b"w\x00" as *const u8 as *const libc::c_char); // length pack 'n' + if !fp.is_null() { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d storing name in %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>( + b"process_setd\x00", + )) + .as_ptr(), + 457 as libc::c_int, + name_file, + ); + } + crate::stdlib::fputs(player_name.as_mut_ptr(), fp); + crate::stdlib::fclose(fp); + } else if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d unable to store new name in %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>( + b"process_setd\x00", + )) + .as_ptr(), + 461 as libc::c_int, + name_file, + ); + } + } + } + }; +} + +unsafe extern "C" fn process_serv(mut pkt: *mut crate::squeezelite_h::u8_t, mut len: libc::c_int) { + let mut serv = pkt as *mut crate::src::slimproto::serv_packet; + let mut slimproto_port = 0 as libc::c_int as libc::c_uint; + let mut squeezeserver: [libc::c_char; 22] = + *::std::mem::transmute::<&[u8; 22], &mut [libc::c_char; 22]>(b"mysqueezebox.com:3483\x00"); + if *pkt.offset(4 as libc::c_int as isize) as libc::c_int == 0 as libc::c_int + && *pkt.offset(5 as libc::c_int as isize) as libc::c_int == 0 as libc::c_int + && *pkt.offset(6 as libc::c_int as isize) as libc::c_int == 0 as libc::c_int + && *pkt.offset(7 as libc::c_int as isize) as libc::c_int == 1 as libc::c_int + { + crate::src::utils::server_addr( + squeezeserver.as_mut_ptr(), + &mut new_server, + &mut slimproto_port, + ); + } else { + new_server = (*serv).server_ip + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d switch server\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"process_serv\x00")) + .as_ptr(), + 483 as libc::c_int, + ); + } + if (len as libc::c_ulong) + .wrapping_sub(::std::mem::size_of::() as libc::c_ulong) + == 10 as libc::c_int as libc::c_ulong + { + if new_server_cap.is_null() { + new_server_cap = crate::stdlib::malloc( + (13 as libc::c_int + 10 as libc::c_int + 1 as libc::c_int) as libc::c_ulong, + ) as *mut libc::c_char + } + *new_server_cap.offset(0 as libc::c_int as isize) = '\u{0}' as i32 as libc::c_char; + crate::stdlib::strcat( + new_server_cap, + b",SyncgroupID=\x00" as *const u8 as *const libc::c_char, + ); + crate::stdlib::strncat( + new_server_cap, + pkt.offset( + ::std::mem::size_of::() as libc::c_ulong + as isize, + ) as *const libc::c_char, + 10 as libc::c_int as libc::c_ulong, + ); + } else if !new_server_cap.is_null() { + crate::stdlib::free(new_server_cap as *mut libc::c_void); + new_server_cap = 0 as *mut libc::c_char + }; +} + +static mut handlers: [handler; 8] = unsafe { + [ + { + let mut init = handler { + opcode: [115, 116, 114, 109, 0], + handler: Some( + process_strm + as unsafe extern "C" fn( + _: *mut crate::squeezelite_h::u8_t, + _: libc::c_int, + ) -> (), + ), + }; + init + }, + { + let mut init = handler { + opcode: [99, 111, 110, 116, 0], + handler: Some( + process_cont + as unsafe extern "C" fn( + _: *mut crate::squeezelite_h::u8_t, + _: libc::c_int, + ) -> (), + ), + }; + init + }, + { + let mut init = handler { + opcode: [99, 111, 100, 99, 0], + handler: Some( + process_codc + as unsafe extern "C" fn( + _: *mut crate::squeezelite_h::u8_t, + _: libc::c_int, + ) -> (), + ), + }; + init + }, + { + let mut init = handler { + opcode: [97, 117, 100, 101, 0], + handler: Some( + process_aude + as unsafe extern "C" fn( + _: *mut crate::squeezelite_h::u8_t, + _: libc::c_int, + ) -> (), + ), + }; + init + }, + { + let mut init = handler { + opcode: [97, 117, 100, 103, 0], + handler: Some( + process_audg + as unsafe extern "C" fn( + _: *mut crate::squeezelite_h::u8_t, + _: libc::c_int, + ) -> (), + ), + }; + init + }, + { + let mut init = handler { + opcode: [115, 101, 116, 100, 0], + handler: Some( + process_setd + as unsafe extern "C" fn( + _: *mut crate::squeezelite_h::u8_t, + _: libc::c_int, + ) -> (), + ), + }; + init + }, + { + let mut init = handler { + opcode: [115, 101, 114, 118, 0], + handler: Some( + process_serv + as unsafe extern "C" fn( + _: *mut crate::squeezelite_h::u8_t, + _: libc::c_int, + ) -> (), + ), + }; + init + }, + { + let mut init = handler { + opcode: [0, 0, 0, 0, 0], + handler: None, + }; + init + }, + ] +}; + +unsafe extern "C" fn process(mut pack: *mut crate::squeezelite_h::u8_t, mut len: libc::c_int) { + let mut h = handlers.as_mut_ptr(); + while (*h).handler.is_some() + && crate::stdlib::strncmp( + pack as *mut libc::c_char, + (*h).opcode.as_mut_ptr(), + 4 as libc::c_int as libc::c_ulong, + ) != 0 + { + h = h.offset(1) + } + if (*h).handler.is_some() { + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 8], &[libc::c_char; 8]>(b"process\x00")).as_ptr(), + 521 as libc::c_int, + (*h).opcode.as_mut_ptr(), + ); + } + (*h).handler.expect("non-null function pointer")(pack, len); + } else { + *pack.offset(4 as libc::c_int as isize) = '\u{0}' as i32 as crate::squeezelite_h::u8_t; + if loglevel as libc::c_uint >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d unhandled %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 8], &[libc::c_char; 8]>(b"process\x00")).as_ptr(), + 525 as libc::c_int, + pack as *mut libc::c_char, + ); + } + }; +} + +static mut running: bool = false; + +unsafe extern "C" fn slimproto_run() { + static mut buffer: [crate::squeezelite_h::u8_t; 4096] = [0; 4096]; + let mut expect = 0 as libc::c_int; + let mut got = 0 as libc::c_int; + let mut now: crate::squeezelite_h::u32_t = 0; + static mut last: crate::squeezelite_h::u32_t = 0 as libc::c_int as crate::squeezelite_h::u32_t; + let mut ehandles: [crate::stdlib::pollfd; 2] = [crate::stdlib::pollfd { + fd: 0, + events: 0, + revents: 0, + }; 2]; + let mut timeouts = 0 as libc::c_int; + crate::src::utils::set_readwake_handles(ehandles.as_mut_ptr(), sock, wake_e); + while running as libc::c_int != 0 && new_server == 0 { + let mut wake = 0 as libc::c_int != 0; + let mut ev = crate::squeezelite_h::EVENT_TIMEOUT; + ev = crate::src::utils::wait_readwake(ehandles.as_mut_ptr(), 1000 as libc::c_int); + if ev as libc::c_uint != crate::squeezelite_h::EVENT_TIMEOUT as libc::c_int as libc::c_uint + { + if ev as libc::c_uint == crate::squeezelite_h::EVENT_READ as libc::c_int as libc::c_uint + { + if expect > 0 as libc::c_int { + let mut n = crate::stdlib::recv( + sock, + buffer.as_mut_ptr().offset(got as isize) as *mut libc::c_void, + expect as crate::stddef_h::size_t, + 0 as libc::c_int, + ) as libc::c_int; + if n <= 0 as libc::c_int { + if n < 0 as libc::c_int + && *crate::stdlib::__errno_location() == 11 as libc::c_int + { + continue; + } + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d error reading from socket: %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"slimproto_run\x00", + )) + .as_ptr(), + 557 as libc::c_int, + if n != 0 { + crate::stdlib::strerror(*crate::stdlib::__errno_location()) + as *const libc::c_char + } else { + b"closed\x00" as *const u8 as *const libc::c_char + }, + ); + } + return; + } else { + expect -= n; + got += n; + if expect == 0 as libc::c_int { + process(buffer.as_mut_ptr(), got); + got = 0 as libc::c_int + } + } + } else if expect == 0 as libc::c_int { + let mut n_0 = crate::stdlib::recv( + sock, + buffer.as_mut_ptr().offset(got as isize) as *mut libc::c_void, + (2 as libc::c_int - got) as crate::stddef_h::size_t, + 0 as libc::c_int, + ) as libc::c_int; + if n_0 <= 0 as libc::c_int { + if n_0 < 0 as libc::c_int + && *crate::stdlib::__errno_location() == 11 as libc::c_int + { + continue; + } + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d error reading from socket: %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"slimproto_run\x00", + )) + .as_ptr(), + 572 as libc::c_int, + if n_0 != 0 { + crate::stdlib::strerror(*crate::stdlib::__errno_location()) + as *const libc::c_char + } else { + b"closed\x00" as *const u8 as *const libc::c_char + }, + ); + } + return; + } else { + got += n_0; + if got == 2 as libc::c_int { + expect = (buffer[0 as libc::c_int as usize] as libc::c_int) + << 8 as libc::c_int + | buffer[1 as libc::c_int as usize] as libc::c_int; + got = 0 as libc::c_int; + if expect > 4096 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d FATAL: slimproto packet too big: %d > %d\n\x00" + as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"slimproto_run\x00", + )) + .as_ptr(), + 580 as libc::c_int, + expect, + 4096 as libc::c_int, + ); + return; + } + } + } + } else { + crate::src::utils::logprint( + b"%s %s:%d FATAL: negative expect\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"slimproto_run\x00", + )) + .as_ptr(), + 585 as libc::c_int, + ); + return; + } + } + if ev as libc::c_uint == crate::squeezelite_h::EVENT_WAKE as libc::c_int as libc::c_uint + { + wake = 1 as libc::c_int != 0 + } + timeouts = 0 as libc::c_int + } else { + timeouts += 1; + if timeouts > 35 as libc::c_int { + // expect message from server every 5 seconds, but 30 seconds on mysb.com so timeout after 35 seconds + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d No messages from server - connection dead\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"slimproto_run\x00", + )) + .as_ptr(), + 600 as libc::c_int, + ); + } + return; + } + } + // update playback state when woken or every 100ms + now = crate::src::utils::gettime_ms(); + if wake as libc::c_int != 0 + || now.wrapping_sub(last) > 100 as libc::c_int as libc::c_uint + || last > now + { + let mut _sendSTMs = 0 as libc::c_int != 0; + let mut _sendDSCO = 0 as libc::c_int != 0; + let mut _sendRESP = 0 as libc::c_int != 0; + let mut _sendMETA = 0 as libc::c_int != 0; + let mut _sendSTMd = 0 as libc::c_int != 0; + let mut _sendSTMt = 0 as libc::c_int != 0; + let mut _sendSTMl = 0 as libc::c_int != 0; + let mut _sendSTMu = 0 as libc::c_int != 0; + let mut _sendSTMo = 0 as libc::c_int != 0; + let mut _sendSTMn = 0 as libc::c_int != 0; + let mut _stream_disconnect = 0 as libc::c_int != 0; + let mut _start_output = 0 as libc::c_int != 0; + let mut _decode_state = crate::squeezelite_h::DECODE_STOPPED; + let mut disconnect_code = crate::squeezelite_h::DISCONNECT_OK; + static mut header: [libc::c_char; 4096] = [0; 4096]; + let mut header_len = 0 as libc::c_int as crate::stddef_h::size_t; + last = now; + crate::stdlib::pthread_mutex_lock(&mut (*streambuf).mutex); + status.stream_full = crate::squeezelite_h::_buf_used(streambuf); + status.stream_size = (*streambuf).size as crate::squeezelite_h::u32_t; + status.stream_bytes = stream.bytes; + status.stream_state = stream.state; + if stream.state as libc::c_uint + == crate::squeezelite_h::DISCONNECT as libc::c_int as libc::c_uint + { + disconnect_code = stream.disconnect; + stream.state = crate::squeezelite_h::STOPPED; + _sendDSCO = 1 as libc::c_int != 0 + } + if !stream.sent_headers + && (stream.state as libc::c_uint + == crate::squeezelite_h::STREAMING_HTTP as libc::c_int as libc::c_uint + || stream.state as libc::c_uint + == crate::squeezelite_h::STREAMING_WAIT as libc::c_int as libc::c_uint + || stream.state as libc::c_uint + == crate::squeezelite_h::STREAMING_BUFFERING as libc::c_int as libc::c_uint) + { + header_len = stream.header_len; + crate::stdlib::memcpy( + header.as_mut_ptr() as *mut libc::c_void, + stream.header as *const libc::c_void, + header_len, + ); + _sendRESP = 1 as libc::c_int != 0; + stream.sent_headers = 1 as libc::c_int != 0 + } + if stream.meta_send { + header_len = stream.header_len; + crate::stdlib::memcpy( + header.as_mut_ptr() as *mut libc::c_void, + stream.header as *const libc::c_void, + header_len, + ); + _sendMETA = 1 as libc::c_int != 0; + stream.meta_send = 0 as libc::c_int != 0 + } + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + crate::stdlib::pthread_mutex_lock(&mut decode.mutex); + if (status.stream_state as libc::c_uint + == crate::squeezelite_h::STREAMING_HTTP as libc::c_int as libc::c_uint + || status.stream_state as libc::c_uint + == crate::squeezelite_h::STREAMING_FILE as libc::c_int as libc::c_uint + || status.stream_state as libc::c_uint + == crate::squeezelite_h::DISCONNECT as libc::c_int as libc::c_uint + && stream.disconnect as libc::c_uint + == crate::squeezelite_h::DISCONNECT_OK as libc::c_int as libc::c_uint) + && !sentSTMl + && decode.state as libc::c_uint + == crate::squeezelite_h::DECODE_READY as libc::c_int as libc::c_uint + { + if autostart == 0 as libc::c_int { + decode.state = crate::squeezelite_h::DECODE_RUNNING; + _sendSTMl = 1 as libc::c_int != 0; + sentSTMl = 1 as libc::c_int != 0 + } else if autostart == 1 as libc::c_int { + decode.state = crate::squeezelite_h::DECODE_RUNNING; + _start_output = 1 as libc::c_int != 0 + } + // autostart 2 and 3 require cont to be received first + } + if decode.state as libc::c_uint + == crate::squeezelite_h::DECODE_COMPLETE as libc::c_int as libc::c_uint + || decode.state as libc::c_uint + == crate::squeezelite_h::DECODE_ERROR as libc::c_int as libc::c_uint + { + if decode.state as libc::c_uint + == crate::squeezelite_h::DECODE_COMPLETE as libc::c_int as libc::c_uint + { + _sendSTMd = 1 as libc::c_int != 0 + } + if decode.state as libc::c_uint + == crate::squeezelite_h::DECODE_ERROR as libc::c_int as libc::c_uint + { + _sendSTMn = 1 as libc::c_int != 0 + } + decode.state = crate::squeezelite_h::DECODE_STOPPED; + if status.stream_state as libc::c_uint + == crate::squeezelite_h::STREAMING_HTTP as libc::c_int as libc::c_uint + || status.stream_state as libc::c_uint + == crate::squeezelite_h::STREAMING_FILE as libc::c_int as libc::c_uint + { + _stream_disconnect = 1 as libc::c_int != 0 + } + } + _decode_state = decode.state; + crate::stdlib::pthread_mutex_unlock(&mut decode.mutex); + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + status.output_full = crate::squeezelite_h::_buf_used(outputbuf); + status.output_size = (*outputbuf).size as crate::squeezelite_h::u32_t; + status.frames_played = output.frames_played_dmp; + status.current_sample_rate = output.current_sample_rate; + status.updated = output.updated; + status.device_frames = output.device_frames; + if output.track_started { + _sendSTMs = 1 as libc::c_int != 0; + output.track_started = 0 as libc::c_int != 0; + status.stream_start = output.track_start_time + } + if _start_output as libc::c_int != 0 + && (output.state as libc::c_int + == crate::squeezelite_h::OUTPUT_STOPPED as libc::c_int + || output.state as libc::c_int + == crate::squeezelite_h::OUTPUT_OFF as libc::c_int) + { + output.state = crate::squeezelite_h::OUTPUT_BUFFER + } + if output.state as libc::c_int == crate::squeezelite_h::OUTPUT_RUNNING as libc::c_int + && !sentSTMu + && status.output_full == 0 as libc::c_int as libc::c_uint + && status.stream_state as libc::c_uint + <= crate::squeezelite_h::DISCONNECT as libc::c_int as libc::c_uint + && _decode_state as libc::c_uint + == crate::squeezelite_h::DECODE_STOPPED as libc::c_int as libc::c_uint + { + _sendSTMu = 1 as libc::c_int != 0; + sentSTMu = 1 as libc::c_int != 0; + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d output underrun\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"slimproto_run\x00", + )) + .as_ptr(), + 709 as libc::c_int, + ); + } + output.state = crate::squeezelite_h::OUTPUT_STOPPED; + output.stop_time = now + } + if output.state as libc::c_int == crate::squeezelite_h::OUTPUT_RUNNING as libc::c_int + && !sentSTMo + && status.output_full == 0 as libc::c_int as libc::c_uint + && status.stream_state as libc::c_uint + == crate::squeezelite_h::STREAMING_HTTP as libc::c_int as libc::c_uint + { + _sendSTMo = 1 as libc::c_int != 0; + sentSTMo = 1 as libc::c_int != 0 + } + if output.state as libc::c_int == crate::squeezelite_h::OUTPUT_STOPPED as libc::c_int + && output.idle_to != 0 + && now.wrapping_sub(output.stop_time) > output.idle_to + { + output.state = crate::squeezelite_h::OUTPUT_OFF; + if loglevel as libc::c_uint + >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d output timeout\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"slimproto_run\x00", + )) + .as_ptr(), + 720 as libc::c_int, + ); + } + } + if output.state as libc::c_int == crate::squeezelite_h::OUTPUT_RUNNING as libc::c_int + && now.wrapping_sub(status.last) > 1000 as libc::c_int as libc::c_uint + { + _sendSTMt = 1 as libc::c_int != 0; + status.last = now + } + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + if _stream_disconnect { + crate::src::stream::stream_disconnect(); + } + // send packets once locks released as packet sending can block + if _sendDSCO { + sendDSCO(disconnect_code); + } + if _sendSTMs { + sendSTAT( + b"STMs\x00" as *const u8 as *const libc::c_char, + 0 as libc::c_int as crate::squeezelite_h::u32_t, + ); + } + if _sendSTMd { + sendSTAT( + b"STMd\x00" as *const u8 as *const libc::c_char, + 0 as libc::c_int as crate::squeezelite_h::u32_t, + ); + } + if _sendSTMt { + sendSTAT( + b"STMt\x00" as *const u8 as *const libc::c_char, + 0 as libc::c_int as crate::squeezelite_h::u32_t, + ); + } + if _sendSTMl { + sendSTAT( + b"STMl\x00" as *const u8 as *const libc::c_char, + 0 as libc::c_int as crate::squeezelite_h::u32_t, + ); + } + if _sendSTMu { + sendSTAT( + b"STMu\x00" as *const u8 as *const libc::c_char, + 0 as libc::c_int as crate::squeezelite_h::u32_t, + ); + } + if _sendSTMo { + sendSTAT( + b"STMo\x00" as *const u8 as *const libc::c_char, + 0 as libc::c_int as crate::squeezelite_h::u32_t, + ); + } + if _sendSTMn { + sendSTAT( + b"STMn\x00" as *const u8 as *const libc::c_char, + 0 as libc::c_int as crate::squeezelite_h::u32_t, + ); + } + if _sendRESP { + sendRESP(header.as_mut_ptr(), header_len); + } + if _sendMETA { + sendMETA(header.as_mut_ptr(), header_len); + } + } + } +} +// called from other threads to wake state machine above +#[no_mangle] + +pub unsafe extern "C" fn wake_controller() { + crate::stdlib::eventfd_write(wake_e, 1 as libc::c_int as crate::stdlib::eventfd_t); +} +#[no_mangle] + +pub unsafe extern "C" fn discover_server( + mut default_server: *mut libc::c_char, +) -> crate::stdlib::in_addr_t { + let mut d = crate::stdlib::sockaddr_in { + sin_family: 0, + sin_port: 0, + sin_addr: crate::stdlib::in_addr { s_addr: 0 }, + sin_zero: [0; 8], + }; + let mut s = crate::stdlib::sockaddr_in { + sin_family: 0, + sin_port: 0, + sin_addr: crate::stdlib::in_addr { s_addr: 0 }, + sin_zero: [0; 8], + }; + let mut buf = 0 as *mut libc::c_char; + let mut pollinfo = crate::stdlib::pollfd { + fd: 0, + events: 0, + revents: 0, + }; + let mut port: libc::c_uint = 0; + let mut disc_sock = crate::stdlib::socket( + 2 as libc::c_int, + crate::stdlib::SOCK_DGRAM as libc::c_int, + 0 as libc::c_int, + ); + let mut enable = 1 as libc::c_int as crate::stdlib::socklen_t; + crate::stdlib::setsockopt( + disc_sock, + 1 as libc::c_int, + 6 as libc::c_int, + &mut enable as *mut crate::stdlib::socklen_t as *const libc::c_void, + ::std::mem::size_of::() as libc::c_ulong + as crate::stdlib::socklen_t, + ); + buf = b"e\x00" as *const u8 as *const libc::c_char as *mut libc::c_char; + crate::stdlib::memset( + &mut d as *mut crate::stdlib::sockaddr_in as *mut libc::c_void, + 0 as libc::c_int, + ::std::mem::size_of::() as libc::c_ulong, + ); + d.sin_family = 2 as libc::c_int as crate::stdlib::sa_family_t; + d.sin_port = crate::stdlib::htons(3483 as libc::c_int as crate::stdlib::uint16_t); + d.sin_addr.s_addr = crate::stdlib::htonl(0xffffffff as libc::c_uint); + pollinfo.fd = disc_sock; + pollinfo.events = 0x1 as libc::c_int as libc::c_short; + loop { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d sending discovery\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>(b"discover_server\x00")) + .as_ptr(), + 788 as libc::c_int, + ); + } + crate::stdlib::memset( + &mut s as *mut crate::stdlib::sockaddr_in as *mut libc::c_void, + 0 as libc::c_int, + ::std::mem::size_of::() as libc::c_ulong, + ); + if crate::stdlib::sendto( + disc_sock, + buf as *const libc::c_void, + 1 as libc::c_int as crate::stddef_h::size_t, + 0 as libc::c_int, + &mut d as *mut crate::stdlib::sockaddr_in as *mut crate::stdlib::sockaddr, + ::std::mem::size_of::() as libc::c_ulong + as crate::stdlib::socklen_t, + ) < 0 as libc::c_int as libc::c_long + { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d error sending disovery\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>( + b"discover_server\x00", + )) + .as_ptr(), + 792 as libc::c_int, + ); + } + } + if crate::stdlib::poll( + &mut pollinfo, + 1 as libc::c_int as crate::stdlib::nfds_t, + 5000 as libc::c_int, + ) == 1 as libc::c_int + { + let mut readbuf: [libc::c_char; 10] = [0; 10]; + let mut slen = ::std::mem::size_of::() as libc::c_ulong + as crate::stdlib::socklen_t; + crate::stdlib::recvfrom( + disc_sock, + readbuf.as_mut_ptr() as *mut libc::c_void, + 10 as libc::c_int as crate::stddef_h::size_t, + 0 as libc::c_int, + &mut s as *mut crate::stdlib::sockaddr_in as *mut crate::stdlib::sockaddr, + &mut slen, + ); + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d got response from: %s:%d\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>( + b"discover_server\x00", + )) + .as_ptr(), + 799 as libc::c_int, + crate::stdlib::inet_ntoa(s.sin_addr), + crate::stdlib::ntohs(s.sin_port) as libc::c_int, + ); + } + } + if !default_server.is_null() { + crate::src::utils::server_addr(default_server, &mut s.sin_addr.s_addr, &mut port); + } + if !(s.sin_addr.s_addr == 0 as libc::c_int as libc::c_uint && running as libc::c_int != 0) { + break; + } + } + crate::stdlib::close(disc_sock); + return s.sin_addr.s_addr; +} +#[no_mangle] + +pub unsafe extern "C" fn slimproto( + mut level: crate::squeezelite_h::log_level, + mut server: *mut libc::c_char, + mut mac: *mut crate::squeezelite_h::u8_t, + mut name: *const libc::c_char, + mut namefile: *const libc::c_char, + mut modelname: *const libc::c_char, + mut maxSampleRate: libc::c_int, +) { + let mut serv_addr = crate::stdlib::sockaddr_in { + sin_family: 0, + sin_port: 0, + sin_addr: crate::stdlib::in_addr { s_addr: 0 }, + sin_zero: [0; 8], + }; + static mut fixed_cap: [libc::c_char; 256] = [0; 256]; + static mut var_cap: [libc::c_char; 128] = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + ]; + let mut reconnect = 0 as libc::c_int != 0; + let mut failed_connect = 0 as libc::c_int as libc::c_uint; + let mut slimproto_port = 0 as libc::c_int as libc::c_uint; + let mut previous_server = 0 as libc::c_int as crate::stdlib::in_addr_t; + let mut i: libc::c_int = 0; + crate::stdlib::memset( + &mut status as *mut C2RustUnnamed_17 as *mut libc::c_void, + 0 as libc::c_int, + ::std::mem::size_of::() as libc::c_ulong, + ); + wake_e = crate::stdlib::eventfd(0 as libc::c_int as libc::c_uint, 0 as libc::c_int); + loglevel = level; + running = 1 as libc::c_int != 0; + if !server.is_null() { + crate::src::utils::server_addr(server, &mut slimproto_ip, &mut slimproto_port); + } + if slimproto_ip == 0 { + slimproto_ip = discover_server(server) + } + if slimproto_port == 0 { + slimproto_port = 3483 as libc::c_int as libc::c_uint + } + if !name.is_null() { + crate::stdlib::strncpy( + player_name.as_mut_ptr(), + name, + 64 as libc::c_int as libc::c_ulong, + ); + player_name[64 as libc::c_int as usize] = '\u{0}' as i32 as libc::c_char + } + if !namefile.is_null() { + let mut fp = 0 as *mut crate::stdlib::FILE; + name_file = namefile; + fp = crate::stdlib::fopen(namefile, b"r\x00" as *const u8 as *const libc::c_char); + if !fp.is_null() { + if crate::stdlib::fgets(player_name.as_mut_ptr(), 64 as libc::c_int, fp).is_null() { + player_name[64 as libc::c_int as usize] = '\u{0}' as i32 as libc::c_char + } else { + // strip any \n from fgets response + let mut len = crate::stdlib::strlen(player_name.as_mut_ptr()) as libc::c_int; + if len > 0 as libc::c_int + && player_name[(len - 1 as libc::c_int) as usize] as libc::c_int == '\n' as i32 + { + player_name[(len - 1 as libc::c_int) as usize] = '\u{0}' as i32 as libc::c_char + } + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d retrieved name %s from %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>( + b"slimproto\x00", + )) + .as_ptr(), + 862 as libc::c_int, + player_name.as_mut_ptr(), + name_file, + ); + } + } + crate::stdlib::fclose(fp); + } + } + if !running { + return; + } + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + crate::stdlib::snprintf( + fixed_cap.as_mut_ptr(), + 256 as libc::c_int as libc::c_ulong, + b",ModelName=%s,MaxSampleRate=%u\x00" as *const u8 as *const libc::c_char, + if !modelname.is_null() { + modelname + } else { + b"SqueezeLite\x00" as *const u8 as *const libc::c_char + }, + if maxSampleRate > 0 as libc::c_int { + maxSampleRate as libc::c_uint + } else { + output.supported_rates[0 as libc::c_int as usize] + }, + ); + i = 0 as libc::c_int; + while i < 10 as libc::c_int { + if !(*codecs.as_mut_ptr().offset(i as isize)).is_null() + && (**codecs.as_mut_ptr().offset(i as isize)).id as libc::c_int != 0 + && crate::stdlib::strlen(fixed_cap.as_mut_ptr()) + < (256 as libc::c_int - 10 as libc::c_int) as libc::c_ulong + { + crate::stdlib::strcat( + fixed_cap.as_mut_ptr(), + b",\x00" as *const u8 as *const libc::c_char, + ); + crate::stdlib::strcat( + fixed_cap.as_mut_ptr(), + (**codecs.as_mut_ptr().offset(i as isize)).types, + ); + } + i += 1 + } + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + crate::stdlib::memset( + &mut serv_addr as *mut crate::stdlib::sockaddr_in as *mut libc::c_void, + 0 as libc::c_int, + ::std::mem::size_of::() as libc::c_ulong, + ); + serv_addr.sin_family = 2 as libc::c_int as crate::stdlib::sa_family_t; + serv_addr.sin_addr.s_addr = slimproto_ip; + serv_addr.sin_port = crate::stdlib::htons(slimproto_port as crate::stdlib::uint16_t); + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d connecting to %s:%d\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"slimproto\x00")).as_ptr(), + 887 as libc::c_int, + crate::stdlib::inet_ntoa(serv_addr.sin_addr), + crate::stdlib::ntohs(serv_addr.sin_port) as libc::c_int, + ); + } + new_server = 0 as libc::c_int as crate::squeezelite_h::u32_t; + while running { + if new_server != 0 { + previous_server = slimproto_ip; + serv_addr.sin_addr.s_addr = new_server; + slimproto_ip = serv_addr.sin_addr.s_addr; + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d switching server to %s:%d\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"slimproto\x00")) + .as_ptr(), + 896 as libc::c_int, + crate::stdlib::inet_ntoa(serv_addr.sin_addr), + crate::stdlib::ntohs(serv_addr.sin_port) as libc::c_int, + ); + } + new_server = 0 as libc::c_int as crate::squeezelite_h::u32_t; + reconnect = 0 as libc::c_int != 0 + } + sock = crate::stdlib::socket( + 2 as libc::c_int, + crate::stdlib::SOCK_STREAM as libc::c_int, + 0 as libc::c_int, + ); + crate::src::utils::set_nonblock(sock); + if crate::src::utils::connect_timeout( + sock, + &mut serv_addr as *mut crate::stdlib::sockaddr_in as *mut crate::stdlib::sockaddr, + ::std::mem::size_of::() as libc::c_ulong + as crate::stdlib::socklen_t, + 5 as libc::c_int, + ) != 0 as libc::c_int + { + if previous_server != 0 { + serv_addr.sin_addr.s_addr = previous_server; + slimproto_ip = serv_addr.sin_addr.s_addr; + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint(b"%s %s:%d new server not reachable, reverting to previous server %s:%d\n\x00" + as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], + &[libc::c_char; 10]>(b"slimproto\x00")).as_ptr(), + 910 as libc::c_int, + crate::stdlib::inet_ntoa(serv_addr.sin_addr), + crate::stdlib::ntohs(serv_addr.sin_port) as libc::c_int); + } + } else { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d unable to connect to server %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>( + b"slimproto\x00", + )) + .as_ptr(), + 912 as libc::c_int, + failed_connect, + ); + } + crate::stdlib::sleep(5 as libc::c_int as libc::c_uint); + } + // rediscover server if it was not set at startup + if server.is_null() && { + failed_connect = failed_connect.wrapping_add(1); + (failed_connect) > 5 as libc::c_int as libc::c_uint + } { + serv_addr.sin_addr.s_addr = discover_server(0 as *mut libc::c_char); + slimproto_ip = serv_addr.sin_addr.s_addr + } + } else { + let mut our_addr = crate::stdlib::sockaddr_in { + sin_family: 0, + sin_port: 0, + sin_addr: crate::stdlib::in_addr { s_addr: 0 }, + sin_zero: [0; 8], + }; + let mut len_0: crate::stdlib::socklen_t = 0; + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d connected\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>(b"slimproto\x00")) + .as_ptr(), + 926 as libc::c_int, + ); + } + var_cap[0 as libc::c_int as usize] = '\u{0}' as i32 as libc::c_char; + failed_connect = 0 as libc::c_int as libc::c_uint; + // check if this is a local player now we are connected & signal to server via 'loc' format + // this requires LocalPlayer server plugin to enable direct file access + len_0 = ::std::mem::size_of::() as libc::c_ulong + as crate::stdlib::socklen_t; + crate::stdlib::getsockname( + sock, + &mut our_addr as *mut crate::stdlib::sockaddr_in as *mut crate::stdlib::sockaddr, + &mut len_0, + ); + if our_addr.sin_addr.s_addr == serv_addr.sin_addr.s_addr { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d local player\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 10], &[libc::c_char; 10]>( + b"slimproto\x00", + )) + .as_ptr(), + 937 as libc::c_int, + ); + } + crate::stdlib::strcat( + var_cap.as_mut_ptr(), + b",loc\x00" as *const u8 as *const libc::c_char, + ); + } + // add on any capablity to be sent to the new server + if !new_server_cap.is_null() { + crate::stdlib::strcat(var_cap.as_mut_ptr(), new_server_cap); + crate::stdlib::free(new_server_cap as *mut libc::c_void); + new_server_cap = 0 as *mut libc::c_char + } + sendHELO(reconnect, fixed_cap.as_mut_ptr(), var_cap.as_mut_ptr(), mac); + slimproto_run(); + if !reconnect { + reconnect = 1 as libc::c_int != 0 + } + crate::stdlib::usleep(100000 as libc::c_int as crate::stdlib::__useconds_t); + } + previous_server = 0 as libc::c_int as crate::stdlib::in_addr_t; + crate::stdlib::close(sock); + } +} +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Additions (c) Paul Hermann, 2015-2017 under the same license terms + * -Control of Raspberry pi GPIO for amplifier power + * -Launch script on power status change from LMS + */ +// make may define: PORTAUDIO, SELFPIPE, RESAMPLE, RESAMPLE_MP, VISEXPORT, GPIO, IR, DSD, LINKALL to influence build +// build detection +// dynamically loaded libraries at run time +// !LINKALL +// config options +// do not reduce as icy-meta max is 4080 +/* SUN */ +/* SUN */ +// printf/scanf formats for u64_t +// logging +// utils.c (non logging) +// buffer.c +// _* called with mutex locked +// slimproto.c +#[no_mangle] + +pub unsafe extern "C" fn slimproto_stop() { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d slimproto stop\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>(b"slimproto_stop\x00")) + .as_ptr(), + 966 as libc::c_int, + ); + } + running = 0 as libc::c_int != 0; +} diff --git a/src/squeezelite_h.rs b/src/squeezelite_h.rs new file mode 100644 index 0000000..a6bc1fb --- /dev/null +++ b/src/squeezelite_h.rs @@ -0,0 +1,207 @@ +extern "C" { + #[no_mangle] + pub fn _buf_used(buf: *mut crate::squeezelite_h::buffer) -> libc::c_uint; + + #[no_mangle] + pub fn to_gain(f: libc::c_float) -> crate::squeezelite_h::s32_t; + + #[no_mangle] + pub fn gain( + gain_0: crate::squeezelite_h::s32_t, + sample: crate::squeezelite_h::s32_t, + ) -> crate::squeezelite_h::s32_t; + + #[no_mangle] + pub fn _apply_cross( + outputbuf_0: *mut crate::squeezelite_h::buffer, + out_frames: crate::squeezelite_h::frames_t, + cross_gain_in: crate::squeezelite_h::s32_t, + cross_gain_out: crate::squeezelite_h::s32_t, + cross_ptr: *mut *mut crate::squeezelite_h::s32_t, + ); + + #[no_mangle] + pub fn _apply_gain( + outputbuf_0: *mut crate::squeezelite_h::buffer, + count: crate::squeezelite_h::frames_t, + gainL: crate::squeezelite_h::s32_t, + gainR: crate::squeezelite_h::s32_t, + ); +} +// =============== BEGIN squeezelite_h ================ +pub type s16_t = crate::stdlib::int16_t; +#[repr(C)] +#[derive(Copy, Clone)] +pub union C2RustUnnamed_1 { + pub pause_frames: crate::squeezelite_h::u32_t, + pub skip_frames: crate::squeezelite_h::u32_t, + pub start_at: crate::squeezelite_h::u32_t, +} +pub type u32_t = crate::stdlib::u_int32_t; +pub type u64_t = crate::stdlib::u_int64_t; +pub type s32_t = crate::stdlib::int32_t; +pub type frames_t = crate::squeezelite_h::u32_t; +pub type log_level = libc::c_uint; +pub type stream_state = libc::c_uint; +pub type disconnect_code = libc::c_uint; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct streamstate { + pub state: crate::squeezelite_h::stream_state, + pub disconnect: crate::squeezelite_h::disconnect_code, + pub header: *mut libc::c_char, + pub header_len: crate::stddef_h::size_t, + pub sent_headers: bool, + pub cont_wait: bool, + pub bytes: crate::squeezelite_h::u64_t, + pub threshold: libc::c_uint, + pub meta_interval: crate::squeezelite_h::u32_t, + pub meta_next: crate::squeezelite_h::u32_t, + pub meta_left: crate::squeezelite_h::u32_t, + pub meta_send: bool, +} +pub type decode_state = libc::c_uint; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct decodestate { + pub state: crate::squeezelite_h::decode_state, + pub new_stream: bool, + pub mutex: crate::stdlib::pthread_mutex_t, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct codec { + pub id: libc::c_char, + pub types: *mut libc::c_char, + pub min_read_bytes: libc::c_uint, + pub min_space: libc::c_uint, + pub open: Option< + unsafe extern "C" fn( + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + ) -> (), + >, + pub close: Option ()>, + pub decode: Option crate::squeezelite_h::decode_state>, +} +pub type fade_mode = libc::c_uint; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct outputstate { + pub state: crate::squeezelite_h::output_state, + pub format: crate::squeezelite_h::output_format, + pub device: *const libc::c_char, + pub buffer: libc::c_uint, + pub period: libc::c_uint, + pub track_started: bool, + pub write_cb: Option< + unsafe extern "C" fn( + _: crate::squeezelite_h::frames_t, + _: bool, + _: crate::squeezelite_h::s32_t, + _: crate::squeezelite_h::s32_t, + _: crate::squeezelite_h::s32_t, + _: crate::squeezelite_h::s32_t, + _: *mut *mut crate::squeezelite_h::s32_t, + ) -> libc::c_int, + >, + pub start_frames: libc::c_uint, + pub frames_played: libc::c_uint, + pub frames_played_dmp: libc::c_uint, + pub current_sample_rate: libc::c_uint, + pub supported_rates: [libc::c_uint; 18], + pub default_sample_rate: libc::c_uint, + pub error_opening: bool, + pub device_frames: libc::c_uint, + pub updated: crate::squeezelite_h::u32_t, + pub track_start_time: crate::squeezelite_h::u32_t, + pub current_replay_gain: crate::squeezelite_h::u32_t, + pub c2rust_unnamed: crate::squeezelite_h::C2RustUnnamed_1, + pub next_sample_rate: libc::c_uint, + pub track_start: *mut crate::squeezelite_h::u8_t, + pub gainL: crate::squeezelite_h::u32_t, + pub gainR: crate::squeezelite_h::u32_t, + pub invert: bool, + pub next_replay_gain: crate::squeezelite_h::u32_t, + pub threshold: libc::c_uint, + pub fade: crate::squeezelite_h::fade_state, + pub fade_start: *mut crate::squeezelite_h::u8_t, + pub fade_end: *mut crate::squeezelite_h::u8_t, + pub fade_dir: crate::squeezelite_h::fade_dir, + pub fade_mode: crate::squeezelite_h::fade_mode, + pub fade_secs: libc::c_uint, + pub rate_delay: libc::c_uint, + pub delay_active: bool, + pub stop_time: crate::squeezelite_h::u32_t, + pub idle_to: crate::squeezelite_h::u32_t, +} +pub type fade_dir = libc::c_uint; +pub type fade_state = libc::c_uint; +pub type output_format = libc::c_uint; +pub type output_state = libc::c_int; +pub type s64_t = crate::stdlib::int64_t; +pub const lSDEBUG: crate::squeezelite_h::log_level = 4; +pub const lDEBUG: crate::squeezelite_h::log_level = 3; +pub const lINFO: crate::squeezelite_h::log_level = 2; +pub const lWARN: crate::squeezelite_h::log_level = 1; +pub const lERROR: crate::squeezelite_h::log_level = 0; +pub const RECV_HEADERS: crate::squeezelite_h::stream_state = 7; +pub const SEND_HEADERS: crate::squeezelite_h::stream_state = 6; +pub const STREAMING_HTTP: crate::squeezelite_h::stream_state = 5; +pub const STREAMING_FILE: crate::squeezelite_h::stream_state = 4; +pub const STREAMING_BUFFERING: crate::squeezelite_h::stream_state = 3; +pub const STREAMING_WAIT: crate::squeezelite_h::stream_state = 2; +pub const DISCONNECT: crate::squeezelite_h::stream_state = 1; +pub const STOPPED: crate::squeezelite_h::stream_state = 0; +pub const TIMEOUT: crate::squeezelite_h::disconnect_code = 4; +pub const UNREACHABLE: crate::squeezelite_h::disconnect_code = 3; +pub const REMOTE_DISCONNECT: crate::squeezelite_h::disconnect_code = 2; +pub const LOCAL_DISCONNECT: crate::squeezelite_h::disconnect_code = 1; +pub const DISCONNECT_OK: crate::squeezelite_h::disconnect_code = 0; +pub const DECODE_ERROR: crate::squeezelite_h::decode_state = 4; +pub const DECODE_COMPLETE: crate::squeezelite_h::decode_state = 3; +pub const DECODE_RUNNING: crate::squeezelite_h::decode_state = 2; +pub const DECODE_READY: crate::squeezelite_h::decode_state = 1; +pub const DECODE_STOPPED: crate::squeezelite_h::decode_state = 0; +pub const FADE_INOUT: crate::squeezelite_h::fade_mode = 4; +pub const FADE_OUT: crate::squeezelite_h::fade_mode = 3; +pub const FADE_IN: crate::squeezelite_h::fade_mode = 2; +pub const FADE_CROSSFADE: crate::squeezelite_h::fade_mode = 1; +pub const FADE_NONE: crate::squeezelite_h::fade_mode = 0; +pub const FADE_CROSS: crate::squeezelite_h::fade_dir = 3; +pub const FADE_DOWN: crate::squeezelite_h::fade_dir = 2; +pub const FADE_UP: crate::squeezelite_h::fade_dir = 1; +pub const FADE_ACTIVE: crate::squeezelite_h::fade_state = 2; +pub const FADE_DUE: crate::squeezelite_h::fade_state = 1; +pub const FADE_INACTIVE: crate::squeezelite_h::fade_state = 0; +pub const S16_LE: crate::squeezelite_h::output_format = 3; +pub const S24_3LE: crate::squeezelite_h::output_format = 2; +pub const S24_LE: crate::squeezelite_h::output_format = 1; +pub const S32_LE: crate::squeezelite_h::output_format = 0; +pub const OUTPUT_START_AT: crate::squeezelite_h::output_state = 5; +pub const OUTPUT_SKIP_FRAMES: crate::squeezelite_h::output_state = 4; +pub const OUTPUT_PAUSE_FRAMES: crate::squeezelite_h::output_state = 3; +pub const OUTPUT_RUNNING: crate::squeezelite_h::output_state = 2; +pub const OUTPUT_BUFFER: crate::squeezelite_h::output_state = 1; +pub const OUTPUT_STOPPED: crate::squeezelite_h::output_state = 0; +pub const OUTPUT_OFF: crate::squeezelite_h::output_state = -1; +pub type u16_t = crate::stdlib::u_int16_t; +pub type sockfd = libc::c_int; +pub type event_type = libc::c_uint; +pub const EVENT_WAKE: crate::squeezelite_h::event_type = 2; +pub const EVENT_READ: crate::squeezelite_h::event_type = 1; +pub const EVENT_TIMEOUT: crate::squeezelite_h::event_type = 0; +pub type u8_t = crate::stdlib::u_int8_t; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct buffer { + pub buf: *mut crate::squeezelite_h::u8_t, + pub readp: *mut crate::squeezelite_h::u8_t, + pub writep: *mut crate::squeezelite_h::u8_t, + pub wrap: *mut crate::squeezelite_h::u8_t, + pub size: crate::stddef_h::size_t, + pub base_size: crate::stddef_h::size_t, + pub mutex: crate::stdlib::pthread_mutex_t, +} diff --git a/src/stdarg_h.rs b/src/stdarg_h.rs new file mode 100644 index 0000000..e4e1cf5 --- /dev/null +++ b/src/stdarg_h.rs @@ -0,0 +1 @@ +pub type va_list = crate::internal::__builtin_va_list; diff --git a/src/stddef_h.rs b/src/stddef_h.rs new file mode 100644 index 0000000..c6b69b1 --- /dev/null +++ b/src/stddef_h.rs @@ -0,0 +1 @@ +pub type size_t = libc::c_ulong; diff --git a/src/stdlib.rs b/src/stdlib.rs new file mode 100644 index 0000000..0561403 --- /dev/null +++ b/src/stdlib.rs @@ -0,0 +1,2259 @@ +extern "C" { + #[no_mangle] + pub fn snd_device_name_free_hint(hints: *mut *mut libc::c_void) -> libc::c_int; + + #[no_mangle] + pub fn snd_device_name_get_hint( + hint: *const libc::c_void, + id: *const libc::c_char, + ) -> *mut libc::c_char; + + #[no_mangle] + pub fn snd_device_name_hint( + card: libc::c_int, + iface: *const libc::c_char, + hints: *mut *mut *mut libc::c_void, + ) -> libc::c_int; + #[no_mangle] + pub fn dlopen(__file: *const libc::c_char, __mode: libc::c_int) -> *mut libc::c_void; + + #[no_mangle] + pub fn dlsym(__handle: *mut libc::c_void, __name: *const libc::c_char) -> *mut libc::c_void; + + #[no_mangle] + pub fn dlerror() -> *mut libc::c_char; + #[no_mangle] + pub fn __errno_location() -> *mut libc::c_int; + #[no_mangle] + pub fn snd_lib_error_set_handler( + handler: crate::stdlib::snd_lib_error_handler_t, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_strerror(errnum: libc::c_int) -> *const libc::c_char; + #[no_mangle] + pub fn eventfd_read(__fd: libc::c_int, __value: *mut crate::stdlib::eventfd_t) -> libc::c_int; + + #[no_mangle] + pub fn eventfd(__count: libc::c_uint, __flags: libc::c_int) -> libc::c_int; + + #[no_mangle] + pub fn eventfd_write(__fd: libc::c_int, __value: crate::stdlib::eventfd_t) -> libc::c_int; + #[no_mangle] + pub fn open(__file: *const libc::c_char, __oflag: libc::c_int, _: ...) -> libc::c_int; + + #[no_mangle] + pub fn fcntl(__fd: libc::c_int, __cmd: libc::c_int, _: ...) -> libc::c_int; + #[no_mangle] + pub fn ntohs(__netshort: crate::stdlib::uint16_t) -> crate::stdlib::uint16_t; + + #[no_mangle] + pub fn htonl(__hostlong: crate::stdlib::uint32_t) -> crate::stdlib::uint32_t; + + #[no_mangle] + pub fn htons(__hostshort: crate::stdlib::uint16_t) -> crate::stdlib::uint16_t; + #[no_mangle] + pub fn strftime( + __s: *mut libc::c_char, + __maxsize: crate::stddef_h::size_t, + __format: *const libc::c_char, + __tp: *const crate::stdlib::tm, + ) -> crate::stddef_h::size_t; + + #[no_mangle] + pub fn localtime(__timer: *const crate::stdlib::time_t) -> *mut crate::stdlib::tm; + + #[no_mangle] + pub fn clock_gettime( + __clock_id: crate::stdlib::clockid_t, + __tp: *mut crate::stdlib::timespec, + ) -> libc::c_int; + #[no_mangle] + pub fn inet_ntoa(__in: crate::stdlib::in_addr) -> *mut libc::c_char; + #[no_mangle] + pub fn ioctl(__fd: libc::c_int, __request: libc::c_ulong, _: ...) -> libc::c_int; + #[no_mangle] + pub fn mallopt(__param: libc::c_int, __val: libc::c_int) -> libc::c_int; + #[no_mangle] + pub fn log10(_: libc::c_double) -> libc::c_double; + + #[no_mangle] + pub fn floor(_: libc::c_double) -> libc::c_double; + pub type _snd_mixer; + + pub type _snd_mixer_class; + + pub type _snd_mixer_elem; + + pub type _snd_mixer_selem_id; + + #[no_mangle] + pub fn snd_mixer_selem_id_set_index( + obj: *mut crate::stdlib::snd_mixer_selem_id_t, + val: libc::c_uint, + ); + + #[no_mangle] + pub fn snd_mixer_selem_id_set_name( + obj: *mut crate::stdlib::snd_mixer_selem_id_t, + val: *const libc::c_char, + ); + + #[no_mangle] + pub fn snd_mixer_find_selem( + mixer: *mut crate::stdlib::snd_mixer_t, + id: *const crate::stdlib::snd_mixer_selem_id_t, + ) -> *mut crate::stdlib::snd_mixer_elem_t; + + #[no_mangle] + pub fn snd_mixer_selem_has_playback_switch( + elem: *mut crate::stdlib::snd_mixer_elem_t, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_mixer_selem_set_playback_switch_all( + elem: *mut crate::stdlib::snd_mixer_elem_t, + value: libc::c_int, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_mixer_selem_get_playback_dB_range( + elem: *mut crate::stdlib::snd_mixer_elem_t, + min: *mut libc::c_long, + max: *mut libc::c_long, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_mixer_selem_get_playback_volume_range( + elem: *mut crate::stdlib::snd_mixer_elem_t, + min: *mut libc::c_long, + max: *mut libc::c_long, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_mixer_selem_set_playback_volume( + elem: *mut crate::stdlib::snd_mixer_elem_t, + channel: crate::stdlib::snd_mixer_selem_channel_id_t, + value: libc::c_long, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_mixer_selem_set_playback_dB( + elem: *mut crate::stdlib::snd_mixer_elem_t, + channel: crate::stdlib::snd_mixer_selem_channel_id_t, + value: libc::c_long, + dir: libc::c_int, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_mixer_selem_get_playback_volume( + elem: *mut crate::stdlib::snd_mixer_elem_t, + channel: crate::stdlib::snd_mixer_selem_channel_id_t, + value: *mut libc::c_long, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_mixer_selem_id_sizeof() -> crate::stddef_h::size_t; + + #[no_mangle] + pub fn snd_mixer_open( + mixer: *mut *mut crate::stdlib::snd_mixer_t, + mode: libc::c_int, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_mixer_attach( + mixer: *mut crate::stdlib::snd_mixer_t, + name: *const libc::c_char, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_mixer_selem_register( + mixer: *mut crate::stdlib::snd_mixer_t, + options: *mut crate::stdlib::snd_mixer_selem_regopt, + classp: *mut *mut crate::stdlib::snd_mixer_class_t, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_mixer_load(mixer: *mut crate::stdlib::snd_mixer_t) -> libc::c_int; + + #[no_mangle] + pub fn snd_mixer_first_elem( + mixer: *mut crate::stdlib::snd_mixer_t, + ) -> *mut crate::stdlib::snd_mixer_elem_t; + + #[no_mangle] + pub fn snd_mixer_elem_next( + elem: *mut crate::stdlib::snd_mixer_elem_t, + ) -> *mut crate::stdlib::snd_mixer_elem_t; + + #[no_mangle] + pub fn snd_mixer_selem_has_playback_volume( + elem: *mut crate::stdlib::snd_mixer_elem_t, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_mixer_selem_get_id( + element: *mut crate::stdlib::snd_mixer_elem_t, + id: *mut crate::stdlib::snd_mixer_selem_id_t, + ); + + #[no_mangle] + pub fn snd_mixer_selem_id_get_name( + obj: *const crate::stdlib::snd_mixer_selem_id_t, + ) -> *const libc::c_char; + + #[no_mangle] + pub fn snd_mixer_selem_id_get_index( + obj: *const crate::stdlib::snd_mixer_selem_id_t, + ) -> libc::c_uint; + + #[no_mangle] + pub fn snd_mixer_close(mixer: *mut crate::stdlib::snd_mixer_t) -> libc::c_int; + #[no_mangle] + pub fn mlockall(__flags: libc::c_int) -> libc::c_int; + pub type mpg123_handle_struct; + #[no_mangle] + pub fn getaddrinfo( + __name: *const libc::c_char, + __service: *const libc::c_char, + __req: *const crate::stdlib::addrinfo, + __pai: *mut *mut crate::stdlib::addrinfo, + ) -> libc::c_int; + + #[no_mangle] + pub fn freeaddrinfo(__ai: *mut crate::stdlib::addrinfo); + pub type _snd_output; + + #[no_mangle] + pub fn snd_output_stdio_attach( + outputp: *mut *mut crate::stdlib::snd_output_t, + fp: *mut crate::stdlib::FILE, + _close: libc::c_int, + ) -> libc::c_int; + pub type _snd_pcm; + + pub type _snd_pcm_hw_params; + + #[no_mangle] + pub fn snd_pcm_open( + pcm: *mut *mut crate::stdlib::snd_pcm_t, + name: *const libc::c_char, + stream: crate::stdlib::snd_pcm_stream_t, + mode: libc::c_int, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_close(pcm: *mut crate::stdlib::snd_pcm_t) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_hw_params( + pcm: *mut crate::stdlib::snd_pcm_t, + params: *mut crate::stdlib::snd_pcm_hw_params_t, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_start(pcm: *mut crate::stdlib::snd_pcm_t) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_state(pcm: *mut crate::stdlib::snd_pcm_t) -> crate::stdlib::snd_pcm_state_t; + + #[no_mangle] + pub fn snd_pcm_delay( + pcm: *mut crate::stdlib::snd_pcm_t, + delayp: *mut crate::stdlib::snd_pcm_sframes_t, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_avail_update( + pcm: *mut crate::stdlib::snd_pcm_t, + ) -> crate::stdlib::snd_pcm_sframes_t; + + #[no_mangle] + pub fn snd_pcm_writei( + pcm: *mut crate::stdlib::snd_pcm_t, + buffer: *const libc::c_void, + size: crate::stdlib::snd_pcm_uframes_t, + ) -> crate::stdlib::snd_pcm_sframes_t; + + #[no_mangle] + pub fn snd_pcm_wait(pcm: *mut crate::stdlib::snd_pcm_t, timeout: libc::c_int) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_recover( + pcm: *mut crate::stdlib::snd_pcm_t, + err: libc::c_int, + silent: libc::c_int, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_hw_params_any( + pcm: *mut crate::stdlib::snd_pcm_t, + params: *mut crate::stdlib::snd_pcm_hw_params_t, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_hw_params_sizeof() -> crate::stddef_h::size_t; + + #[no_mangle] + pub fn snd_pcm_hw_params_set_access( + pcm: *mut crate::stdlib::snd_pcm_t, + params: *mut crate::stdlib::snd_pcm_hw_params_t, + _access: crate::stdlib::snd_pcm_access_t, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_hw_params_set_format( + pcm: *mut crate::stdlib::snd_pcm_t, + params: *mut crate::stdlib::snd_pcm_hw_params_t, + val: crate::stdlib::snd_pcm_format_t, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_hw_params_set_channels( + pcm: *mut crate::stdlib::snd_pcm_t, + params: *mut crate::stdlib::snd_pcm_hw_params_t, + val: libc::c_uint, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_hw_params_test_rate( + pcm: *mut crate::stdlib::snd_pcm_t, + params: *mut crate::stdlib::snd_pcm_hw_params_t, + val: libc::c_uint, + dir: libc::c_int, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_hw_params_set_rate( + pcm: *mut crate::stdlib::snd_pcm_t, + params: *mut crate::stdlib::snd_pcm_hw_params_t, + val: libc::c_uint, + dir: libc::c_int, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_hw_params_set_rate_resample( + pcm: *mut crate::stdlib::snd_pcm_t, + params: *mut crate::stdlib::snd_pcm_hw_params_t, + val: libc::c_uint, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_hw_params_get_period_size( + params: *const crate::stdlib::snd_pcm_hw_params_t, + frames: *mut crate::stdlib::snd_pcm_uframes_t, + dir: *mut libc::c_int, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_hw_params_set_period_size_near( + pcm: *mut crate::stdlib::snd_pcm_t, + params: *mut crate::stdlib::snd_pcm_hw_params_t, + val: *mut crate::stdlib::snd_pcm_uframes_t, + dir: *mut libc::c_int, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_hw_params_set_periods_near( + pcm: *mut crate::stdlib::snd_pcm_t, + params: *mut crate::stdlib::snd_pcm_hw_params_t, + val: *mut libc::c_uint, + dir: *mut libc::c_int, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_hw_params_set_buffer_time_near( + pcm: *mut crate::stdlib::snd_pcm_t, + params: *mut crate::stdlib::snd_pcm_hw_params_t, + val: *mut libc::c_uint, + dir: *mut libc::c_int, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_hw_params_get_buffer_size( + params: *const crate::stdlib::snd_pcm_hw_params_t, + val: *mut crate::stdlib::snd_pcm_uframes_t, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_hw_params_set_buffer_size_near( + pcm: *mut crate::stdlib::snd_pcm_t, + params: *mut crate::stdlib::snd_pcm_hw_params_t, + val: *mut crate::stdlib::snd_pcm_uframes_t, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_format_name(format: crate::stdlib::snd_pcm_format_t) -> *const libc::c_char; + + #[no_mangle] + pub fn snd_pcm_dump( + pcm: *mut crate::stdlib::snd_pcm_t, + out: *mut crate::stdlib::snd_output_t, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_mmap_begin( + pcm: *mut crate::stdlib::snd_pcm_t, + areas: *mut *const crate::stdlib::snd_pcm_channel_area_t, + offset: *mut crate::stdlib::snd_pcm_uframes_t, + frames: *mut crate::stdlib::snd_pcm_uframes_t, + ) -> libc::c_int; + + #[no_mangle] + pub fn snd_pcm_mmap_commit( + pcm: *mut crate::stdlib::snd_pcm_t, + offset: crate::stdlib::snd_pcm_uframes_t, + frames: crate::stdlib::snd_pcm_uframes_t, + ) -> crate::stdlib::snd_pcm_sframes_t; + #[no_mangle] + pub fn poll( + __fds: *mut crate::stdlib::pollfd, + __nfds: crate::stdlib::nfds_t, + __timeout: libc::c_int, + ) -> libc::c_int; + #[no_mangle] + pub fn pthread_create( + __newthread: *mut crate::stdlib::pthread_t, + __attr: *const crate::stdlib::pthread_attr_t, + __start_routine: Option *mut libc::c_void>, + __arg: *mut libc::c_void, + ) -> libc::c_int; + + #[no_mangle] + pub fn pthread_join( + __th: crate::stdlib::pthread_t, + __thread_return: *mut *mut libc::c_void, + ) -> libc::c_int; + + #[no_mangle] + pub fn pthread_attr_init(__attr: *mut crate::stdlib::pthread_attr_t) -> libc::c_int; + + #[no_mangle] + pub fn pthread_attr_destroy(__attr: *mut crate::stdlib::pthread_attr_t) -> libc::c_int; + + #[no_mangle] + pub fn pthread_attr_setstacksize( + __attr: *mut crate::stdlib::pthread_attr_t, + __stacksize: crate::stddef_h::size_t, + ) -> libc::c_int; + + #[no_mangle] + pub fn pthread_mutex_init( + __mutex: *mut crate::stdlib::pthread_mutex_t, + __mutexattr: *const crate::stdlib::pthread_mutexattr_t, + ) -> libc::c_int; + + #[no_mangle] + pub fn pthread_mutex_destroy(__mutex: *mut crate::stdlib::pthread_mutex_t) -> libc::c_int; + + #[no_mangle] + pub fn pthread_mutex_lock(__mutex: *mut crate::stdlib::pthread_mutex_t) -> libc::c_int; + + #[no_mangle] + pub fn pthread_mutex_unlock(__mutex: *mut crate::stdlib::pthread_mutex_t) -> libc::c_int; + + #[no_mangle] + pub fn pthread_mutexattr_init(__attr: *mut crate::stdlib::pthread_mutexattr_t) -> libc::c_int; + + #[no_mangle] + pub fn pthread_mutexattr_destroy( + __attr: *mut crate::stdlib::pthread_mutexattr_t, + ) -> libc::c_int; + + #[no_mangle] + pub fn pthread_mutexattr_setprotocol( + __attr: *mut crate::stdlib::pthread_mutexattr_t, + __protocol: libc::c_int, + ) -> libc::c_int; + + #[no_mangle] + pub fn pthread_setschedparam( + __target_thread: crate::stdlib::pthread_t, + __policy: libc::c_int, + __param: *const crate::stdlib::sched_param, + ) -> libc::c_int; + #[no_mangle] + pub fn select( + __nfds: libc::c_int, + __readfds: *mut crate::stdlib::fd_set, + __writefds: *mut crate::stdlib::fd_set, + __exceptfds: *mut crate::stdlib::fd_set, + __timeout: *mut crate::stdlib::timeval, + ) -> libc::c_int; + #[no_mangle] + pub fn sscanf(_: *const libc::c_char, _: *const libc::c_char, _: ...) -> libc::c_int; + + #[no_mangle] + pub fn sprintf(_: *mut libc::c_char, _: *const libc::c_char, _: ...) -> libc::c_int; + + #[no_mangle] + pub static mut stdout: *mut crate::stdlib::FILE; + + #[no_mangle] + pub fn fwrite( + _: *const libc::c_void, + _: libc::c_ulong, + _: libc::c_ulong, + _: *mut crate::stdlib::FILE, + ) -> libc::c_ulong; + + #[no_mangle] + pub fn fopen(_: *const libc::c_char, _: *const libc::c_char) -> *mut crate::stdlib::FILE; + + #[no_mangle] + pub fn snprintf( + _: *mut libc::c_char, + _: libc::c_ulong, + _: *const libc::c_char, + _: ... + ) -> libc::c_int; + + #[no_mangle] + pub fn fclose(__stream: *mut crate::stdlib::FILE) -> libc::c_int; + + #[no_mangle] + pub fn fgets( + __s: *mut libc::c_char, + __n: libc::c_int, + __stream: *mut crate::stdlib::FILE, + ) -> *mut libc::c_char; + + #[no_mangle] + pub fn fputs(__s: *const libc::c_char, __stream: *mut crate::stdlib::FILE) -> libc::c_int; + + #[no_mangle] + pub static mut stderr: *mut crate::stdlib::FILE; + + #[no_mangle] + pub fn fflush(__stream: *mut crate::stdlib::FILE) -> libc::c_int; + + #[no_mangle] + pub fn fprintf(_: *mut crate::stdlib::FILE, _: *const libc::c_char, _: ...) -> libc::c_int; + + #[no_mangle] + pub fn printf(_: *const libc::c_char, _: ...) -> libc::c_int; + + #[no_mangle] + pub fn vfprintf( + _: *mut crate::stdlib::FILE, + _: *const libc::c_char, + _: ::std::ffi::VaList, + ) -> libc::c_int; + #[no_mangle] + pub fn getenv(__name: *const libc::c_char) -> *mut libc::c_char; + + #[no_mangle] + pub fn exit(_: libc::c_int) -> !; + + #[no_mangle] + pub fn malloc(_: libc::c_ulong) -> *mut libc::c_void; + + #[no_mangle] + pub fn free(__ptr: *mut libc::c_void); + + #[no_mangle] + pub fn atoi(__nptr: *const libc::c_char) -> libc::c_int; + pub type FLAC__StreamDecoderPrivate; + + pub type FLAC__StreamDecoderProtected; + #[no_mangle] + pub fn memcpy( + _: *mut libc::c_void, + _: *const libc::c_void, + _: libc::c_ulong, + ) -> *mut libc::c_void; + + #[no_mangle] + pub fn memcmp(_: *const libc::c_void, _: *const libc::c_void, _: libc::c_ulong) -> libc::c_int; + + #[no_mangle] + pub fn strcmp(_: *const libc::c_char, _: *const libc::c_char) -> libc::c_int; + + #[no_mangle] + pub fn memmove( + _: *mut libc::c_void, + _: *const libc::c_void, + _: libc::c_ulong, + ) -> *mut libc::c_void; + + #[no_mangle] + pub fn memset(_: *mut libc::c_void, _: libc::c_int, _: libc::c_ulong) -> *mut libc::c_void; + + #[no_mangle] + pub fn strchr(_: *const libc::c_char, _: libc::c_int) -> *mut libc::c_char; + + #[no_mangle] + pub fn strstr(_: *const libc::c_char, _: *const libc::c_char) -> *mut libc::c_char; + + #[no_mangle] + pub fn strcat(_: *mut libc::c_char, _: *const libc::c_char) -> *mut libc::c_char; + + #[no_mangle] + pub fn strncpy( + _: *mut libc::c_char, + _: *const libc::c_char, + _: libc::c_ulong, + ) -> *mut libc::c_char; + + #[no_mangle] + pub fn strncat( + _: *mut libc::c_char, + _: *const libc::c_char, + _: libc::c_ulong, + ) -> *mut libc::c_char; + + #[no_mangle] + pub fn strcpy(_: *mut libc::c_char, _: *const libc::c_char) -> *mut libc::c_char; + + #[no_mangle] + pub fn strncmp(_: *const libc::c_char, _: *const libc::c_char, _: libc::c_ulong) + -> libc::c_int; + + #[no_mangle] + pub fn strdup(_: *const libc::c_char) -> *mut libc::c_char; + + #[no_mangle] + pub fn strrchr(_: *const libc::c_char, _: libc::c_int) -> *mut libc::c_char; + + #[no_mangle] + pub fn strtok(_: *mut libc::c_char, _: *const libc::c_char) -> *mut libc::c_char; + + #[no_mangle] + pub fn strlen(_: *const libc::c_char) -> libc::c_ulong; + + #[no_mangle] + pub fn strerror(_: libc::c_int) -> *mut libc::c_char; + pub type _IO_wide_data; + + pub type _IO_codecvt; + + pub type _IO_marker; + #[no_mangle] + pub fn connect( + __fd: libc::c_int, + __addr: *const crate::stdlib::sockaddr, + __len: crate::stdlib::socklen_t, + ) -> libc::c_int; + + #[no_mangle] + pub fn getsockopt( + __fd: libc::c_int, + __level: libc::c_int, + __optname: libc::c_int, + __optval: *mut libc::c_void, + __optlen: *mut crate::stdlib::socklen_t, + ) -> libc::c_int; + + #[no_mangle] + pub fn socket( + __domain: libc::c_int, + __type: libc::c_int, + __protocol: libc::c_int, + ) -> libc::c_int; + + #[no_mangle] + pub fn getsockname( + __fd: libc::c_int, + __addr: *mut crate::stdlib::sockaddr, + __len: *mut crate::stdlib::socklen_t, + ) -> libc::c_int; + + #[no_mangle] + pub fn send( + __fd: libc::c_int, + __buf: *const libc::c_void, + __n: crate::stddef_h::size_t, + __flags: libc::c_int, + ) -> crate::stdlib::ssize_t; + + #[no_mangle] + pub fn recv( + __fd: libc::c_int, + __buf: *mut libc::c_void, + __n: crate::stddef_h::size_t, + __flags: libc::c_int, + ) -> crate::stdlib::ssize_t; + + #[no_mangle] + pub fn sendto( + __fd: libc::c_int, + __buf: *const libc::c_void, + __n: crate::stddef_h::size_t, + __flags: libc::c_int, + __addr: *const crate::stdlib::sockaddr, + __addr_len: crate::stdlib::socklen_t, + ) -> crate::stdlib::ssize_t; + + #[no_mangle] + pub fn recvfrom( + __fd: libc::c_int, + __buf: *mut libc::c_void, + __n: crate::stddef_h::size_t, + __flags: libc::c_int, + __addr: *mut crate::stdlib::sockaddr, + __addr_len: *mut crate::stdlib::socklen_t, + ) -> crate::stdlib::ssize_t; + + #[no_mangle] + pub fn setsockopt( + __fd: libc::c_int, + __level: libc::c_int, + __optname: libc::c_int, + __optval: *const libc::c_void, + __optlen: crate::stdlib::socklen_t, + ) -> libc::c_int; + #[no_mangle] + pub fn gettimeofday( + __tv: *mut crate::stdlib::timeval, + __tz: crate::stdlib::__timezone_ptr_t, + ) -> libc::c_int; + #[no_mangle] + pub fn sysconf(__name: libc::c_int) -> libc::c_long; + + #[no_mangle] + pub fn usleep(__useconds: crate::stdlib::__useconds_t) -> libc::c_int; + + #[no_mangle] + pub fn close(__fd: libc::c_int) -> libc::c_int; + + #[no_mangle] + pub fn read( + __fd: libc::c_int, + __buf: *mut libc::c_void, + __nbytes: crate::stddef_h::size_t, + ) -> crate::stdlib::ssize_t; + + #[no_mangle] + pub fn sleep(__seconds: libc::c_uint) -> libc::c_uint; +} +// =============== BEGIN FILE_h ================ +pub type FILE = crate::stdlib::_IO_FILE; +// ================ END FILE_h ================ +// =============== BEGIN clockid_t_h ================ +pub type clockid_t = crate::stdlib::__clockid_t; +// ================ END clockid_t_h ================ +// =============== BEGIN codec_h ================ +#[repr(C)] +#[derive(Copy, Clone)] +pub struct vorbis_info { + pub version: libc::c_int, + pub channels: libc::c_int, + pub rate: libc::c_long, + pub bitrate_upper: libc::c_long, + pub bitrate_nominal: libc::c_long, + pub bitrate_lower: libc::c_long, + pub bitrate_window: libc::c_long, + pub codec_setup: *mut libc::c_void, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct vorbis_comment { + pub user_comments: *mut *mut libc::c_char, + pub comment_lengths: *mut libc::c_int, + pub comments: libc::c_int, + pub vendor: *mut libc::c_char, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct vorbis_dsp_state { + pub analysisp: libc::c_int, + pub vi: *mut crate::stdlib::vorbis_info, + pub pcm: *mut *mut libc::c_float, + pub pcmret: *mut *mut libc::c_float, + pub pcm_storage: libc::c_int, + pub pcm_current: libc::c_int, + pub pcm_returned: libc::c_int, + pub preextrapolate: libc::c_int, + pub eofflag: libc::c_int, + pub lW: libc::c_long, + pub W: libc::c_long, + pub nW: libc::c_long, + pub centerW: libc::c_long, + pub granulepos: crate::stdlib::ogg_int64_t, + pub sequence: crate::stdlib::ogg_int64_t, + pub glue_bits: crate::stdlib::ogg_int64_t, + pub time_bits: crate::stdlib::ogg_int64_t, + pub floor_bits: crate::stdlib::ogg_int64_t, + pub res_bits: crate::stdlib::ogg_int64_t, + pub backend_state: *mut libc::c_void, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct vorbis_block { + pub pcm: *mut *mut libc::c_float, + pub opb: crate::stdlib::oggpack_buffer, + pub lW: libc::c_long, + pub W: libc::c_long, + pub nW: libc::c_long, + pub pcmend: libc::c_int, + pub mode: libc::c_int, + pub eofflag: libc::c_int, + pub granulepos: crate::stdlib::ogg_int64_t, + pub sequence: crate::stdlib::ogg_int64_t, + pub vd: *mut crate::stdlib::vorbis_dsp_state, + pub localstore: *mut libc::c_void, + pub localtop: libc::c_long, + pub localalloc: libc::c_long, + pub totaluse: libc::c_long, + pub reap: *mut crate::stdlib::alloc_chain, + pub glue_bits: libc::c_long, + pub time_bits: libc::c_long, + pub floor_bits: libc::c_long, + pub res_bits: libc::c_long, + pub internal: *mut libc::c_void, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct alloc_chain { + pub ptr: *mut libc::c_void, + pub next: *mut crate::stdlib::alloc_chain, +} +// ================ END codec_h ================ +// =============== BEGIN config_types_h ================ +pub type ogg_int64_t = crate::stdlib::int64_t; +// ================ END config_types_h ================ +// =============== BEGIN confname_h ================ +pub const _SC_THREAD_ROBUST_PRIO_PROTECT: crate::stdlib::C2RustUnnamed_0 = 248; +pub const _SC_THREAD_ROBUST_PRIO_INHERIT: crate::stdlib::C2RustUnnamed_0 = 247; +pub const _SC_XOPEN_STREAMS: crate::stdlib::C2RustUnnamed_0 = 246; +pub const _SC_TRACE_USER_EVENT_MAX: crate::stdlib::C2RustUnnamed_0 = 245; +pub const _SC_TRACE_SYS_MAX: crate::stdlib::C2RustUnnamed_0 = 244; +pub const _SC_TRACE_NAME_MAX: crate::stdlib::C2RustUnnamed_0 = 243; +pub const _SC_TRACE_EVENT_NAME_MAX: crate::stdlib::C2RustUnnamed_0 = 242; +pub const _SC_SS_REPL_MAX: crate::stdlib::C2RustUnnamed_0 = 241; +pub const _SC_V7_LPBIG_OFFBIG: crate::stdlib::C2RustUnnamed_0 = 240; +pub const _SC_V7_LP64_OFF64: crate::stdlib::C2RustUnnamed_0 = 239; +pub const _SC_V7_ILP32_OFFBIG: crate::stdlib::C2RustUnnamed_0 = 238; +pub const _SC_V7_ILP32_OFF32: crate::stdlib::C2RustUnnamed_0 = 237; +pub const _SC_RAW_SOCKETS: crate::stdlib::C2RustUnnamed_0 = 236; +pub const _SC_IPV6: crate::stdlib::C2RustUnnamed_0 = 235; +pub const _SC_LEVEL4_CACHE_LINESIZE: crate::stdlib::C2RustUnnamed_0 = 199; +pub const _SC_LEVEL4_CACHE_ASSOC: crate::stdlib::C2RustUnnamed_0 = 198; +pub const _SC_LEVEL4_CACHE_SIZE: crate::stdlib::C2RustUnnamed_0 = 197; +pub const _SC_LEVEL3_CACHE_LINESIZE: crate::stdlib::C2RustUnnamed_0 = 196; +pub const _SC_LEVEL3_CACHE_ASSOC: crate::stdlib::C2RustUnnamed_0 = 195; +pub const _SC_LEVEL3_CACHE_SIZE: crate::stdlib::C2RustUnnamed_0 = 194; +pub const _SC_LEVEL2_CACHE_LINESIZE: crate::stdlib::C2RustUnnamed_0 = 193; +pub const _SC_LEVEL2_CACHE_ASSOC: crate::stdlib::C2RustUnnamed_0 = 192; +pub const _SC_LEVEL2_CACHE_SIZE: crate::stdlib::C2RustUnnamed_0 = 191; +pub const _SC_LEVEL1_DCACHE_LINESIZE: crate::stdlib::C2RustUnnamed_0 = 190; +pub const _SC_LEVEL1_DCACHE_ASSOC: crate::stdlib::C2RustUnnamed_0 = 189; +pub const _SC_LEVEL1_DCACHE_SIZE: crate::stdlib::C2RustUnnamed_0 = 188; +pub const _SC_LEVEL1_ICACHE_LINESIZE: crate::stdlib::C2RustUnnamed_0 = 187; +pub const _SC_LEVEL1_ICACHE_ASSOC: crate::stdlib::C2RustUnnamed_0 = 186; +pub const _SC_LEVEL1_ICACHE_SIZE: crate::stdlib::C2RustUnnamed_0 = 185; +pub const _SC_TRACE_LOG: crate::stdlib::C2RustUnnamed_0 = 184; +pub const _SC_TRACE_INHERIT: crate::stdlib::C2RustUnnamed_0 = 183; +pub const _SC_TRACE_EVENT_FILTER: crate::stdlib::C2RustUnnamed_0 = 182; +pub const _SC_TRACE: crate::stdlib::C2RustUnnamed_0 = 181; +pub const _SC_HOST_NAME_MAX: crate::stdlib::C2RustUnnamed_0 = 180; +pub const _SC_V6_LPBIG_OFFBIG: crate::stdlib::C2RustUnnamed_0 = 179; +pub const _SC_V6_LP64_OFF64: crate::stdlib::C2RustUnnamed_0 = 178; +pub const _SC_V6_ILP32_OFFBIG: crate::stdlib::C2RustUnnamed_0 = 177; +pub const _SC_V6_ILP32_OFF32: crate::stdlib::C2RustUnnamed_0 = 176; +pub const _SC_2_PBS_CHECKPOINT: crate::stdlib::C2RustUnnamed_0 = 175; +pub const _SC_STREAMS: crate::stdlib::C2RustUnnamed_0 = 174; +pub const _SC_SYMLOOP_MAX: crate::stdlib::C2RustUnnamed_0 = 173; +pub const _SC_2_PBS_TRACK: crate::stdlib::C2RustUnnamed_0 = 172; +pub const _SC_2_PBS_MESSAGE: crate::stdlib::C2RustUnnamed_0 = 171; +pub const _SC_2_PBS_LOCATE: crate::stdlib::C2RustUnnamed_0 = 170; +pub const _SC_2_PBS_ACCOUNTING: crate::stdlib::C2RustUnnamed_0 = 169; +pub const _SC_2_PBS: crate::stdlib::C2RustUnnamed_0 = 168; +pub const _SC_USER_GROUPS_R: crate::stdlib::C2RustUnnamed_0 = 167; +pub const _SC_USER_GROUPS: crate::stdlib::C2RustUnnamed_0 = 166; +pub const _SC_TYPED_MEMORY_OBJECTS: crate::stdlib::C2RustUnnamed_0 = 165; +pub const _SC_TIMEOUTS: crate::stdlib::C2RustUnnamed_0 = 164; +pub const _SC_SYSTEM_DATABASE_R: crate::stdlib::C2RustUnnamed_0 = 163; +pub const _SC_SYSTEM_DATABASE: crate::stdlib::C2RustUnnamed_0 = 162; +pub const _SC_THREAD_SPORADIC_SERVER: crate::stdlib::C2RustUnnamed_0 = 161; +pub const _SC_SPORADIC_SERVER: crate::stdlib::C2RustUnnamed_0 = 160; +pub const _SC_SPAWN: crate::stdlib::C2RustUnnamed_0 = 159; +pub const _SC_SIGNALS: crate::stdlib::C2RustUnnamed_0 = 158; +pub const _SC_SHELL: crate::stdlib::C2RustUnnamed_0 = 157; +pub const _SC_REGEX_VERSION: crate::stdlib::C2RustUnnamed_0 = 156; +pub const _SC_REGEXP: crate::stdlib::C2RustUnnamed_0 = 155; +pub const _SC_SPIN_LOCKS: crate::stdlib::C2RustUnnamed_0 = 154; +pub const _SC_READER_WRITER_LOCKS: crate::stdlib::C2RustUnnamed_0 = 153; +pub const _SC_NETWORKING: crate::stdlib::C2RustUnnamed_0 = 152; +pub const _SC_SINGLE_PROCESS: crate::stdlib::C2RustUnnamed_0 = 151; +pub const _SC_MULTI_PROCESS: crate::stdlib::C2RustUnnamed_0 = 150; +pub const _SC_MONOTONIC_CLOCK: crate::stdlib::C2RustUnnamed_0 = 149; +pub const _SC_FILE_SYSTEM: crate::stdlib::C2RustUnnamed_0 = 148; +pub const _SC_FILE_LOCKING: crate::stdlib::C2RustUnnamed_0 = 147; +pub const _SC_FILE_ATTRIBUTES: crate::stdlib::C2RustUnnamed_0 = 146; +pub const _SC_PIPE: crate::stdlib::C2RustUnnamed_0 = 145; +pub const _SC_FIFO: crate::stdlib::C2RustUnnamed_0 = 144; +pub const _SC_FD_MGMT: crate::stdlib::C2RustUnnamed_0 = 143; +pub const _SC_DEVICE_SPECIFIC_R: crate::stdlib::C2RustUnnamed_0 = 142; +pub const _SC_DEVICE_SPECIFIC: crate::stdlib::C2RustUnnamed_0 = 141; +pub const _SC_DEVICE_IO: crate::stdlib::C2RustUnnamed_0 = 140; +pub const _SC_THREAD_CPUTIME: crate::stdlib::C2RustUnnamed_0 = 139; +pub const _SC_CPUTIME: crate::stdlib::C2RustUnnamed_0 = 138; +pub const _SC_CLOCK_SELECTION: crate::stdlib::C2RustUnnamed_0 = 137; +pub const _SC_C_LANG_SUPPORT_R: crate::stdlib::C2RustUnnamed_0 = 136; +pub const _SC_C_LANG_SUPPORT: crate::stdlib::C2RustUnnamed_0 = 135; +pub const _SC_BASE: crate::stdlib::C2RustUnnamed_0 = 134; +pub const _SC_BARRIERS: crate::stdlib::C2RustUnnamed_0 = 133; +pub const _SC_ADVISORY_INFO: crate::stdlib::C2RustUnnamed_0 = 132; +pub const _SC_XOPEN_REALTIME_THREADS: crate::stdlib::C2RustUnnamed_0 = 131; +pub const _SC_XOPEN_REALTIME: crate::stdlib::C2RustUnnamed_0 = 130; +pub const _SC_XOPEN_LEGACY: crate::stdlib::C2RustUnnamed_0 = 129; +pub const _SC_XBS5_LPBIG_OFFBIG: crate::stdlib::C2RustUnnamed_0 = 128; +pub const _SC_XBS5_LP64_OFF64: crate::stdlib::C2RustUnnamed_0 = 127; +pub const _SC_XBS5_ILP32_OFFBIG: crate::stdlib::C2RustUnnamed_0 = 126; +pub const _SC_XBS5_ILP32_OFF32: crate::stdlib::C2RustUnnamed_0 = 125; +pub const _SC_NL_TEXTMAX: crate::stdlib::C2RustUnnamed_0 = 124; +pub const _SC_NL_SETMAX: crate::stdlib::C2RustUnnamed_0 = 123; +pub const _SC_NL_NMAX: crate::stdlib::C2RustUnnamed_0 = 122; +pub const _SC_NL_MSGMAX: crate::stdlib::C2RustUnnamed_0 = 121; +pub const _SC_NL_LANGMAX: crate::stdlib::C2RustUnnamed_0 = 120; +pub const _SC_NL_ARGMAX: crate::stdlib::C2RustUnnamed_0 = 119; +pub const _SC_USHRT_MAX: crate::stdlib::C2RustUnnamed_0 = 118; +pub const _SC_ULONG_MAX: crate::stdlib::C2RustUnnamed_0 = 117; +pub const _SC_UINT_MAX: crate::stdlib::C2RustUnnamed_0 = 116; +pub const _SC_UCHAR_MAX: crate::stdlib::C2RustUnnamed_0 = 115; +pub const _SC_SHRT_MIN: crate::stdlib::C2RustUnnamed_0 = 114; +pub const _SC_SHRT_MAX: crate::stdlib::C2RustUnnamed_0 = 113; +pub const _SC_SCHAR_MIN: crate::stdlib::C2RustUnnamed_0 = 112; +pub const _SC_SCHAR_MAX: crate::stdlib::C2RustUnnamed_0 = 111; +pub const _SC_SSIZE_MAX: crate::stdlib::C2RustUnnamed_0 = 110; +pub const _SC_NZERO: crate::stdlib::C2RustUnnamed_0 = 109; +pub const _SC_MB_LEN_MAX: crate::stdlib::C2RustUnnamed_0 = 108; +pub const _SC_WORD_BIT: crate::stdlib::C2RustUnnamed_0 = 107; +pub const _SC_LONG_BIT: crate::stdlib::C2RustUnnamed_0 = 106; +pub const _SC_INT_MIN: crate::stdlib::C2RustUnnamed_0 = 105; +pub const _SC_INT_MAX: crate::stdlib::C2RustUnnamed_0 = 104; +pub const _SC_CHAR_MIN: crate::stdlib::C2RustUnnamed_0 = 103; +pub const _SC_CHAR_MAX: crate::stdlib::C2RustUnnamed_0 = 102; +pub const _SC_CHAR_BIT: crate::stdlib::C2RustUnnamed_0 = 101; +pub const _SC_XOPEN_XPG4: crate::stdlib::C2RustUnnamed_0 = 100; +pub const _SC_XOPEN_XPG3: crate::stdlib::C2RustUnnamed_0 = 99; +pub const _SC_XOPEN_XPG2: crate::stdlib::C2RustUnnamed_0 = 98; +pub const _SC_2_UPE: crate::stdlib::C2RustUnnamed_0 = 97; +pub const _SC_2_C_VERSION: crate::stdlib::C2RustUnnamed_0 = 96; +pub const _SC_2_CHAR_TERM: crate::stdlib::C2RustUnnamed_0 = 95; +pub const _SC_XOPEN_SHM: crate::stdlib::C2RustUnnamed_0 = 94; +pub const _SC_XOPEN_ENH_I18N: crate::stdlib::C2RustUnnamed_0 = 93; +pub const _SC_XOPEN_CRYPT: crate::stdlib::C2RustUnnamed_0 = 92; +pub const _SC_XOPEN_UNIX: crate::stdlib::C2RustUnnamed_0 = 91; +pub const _SC_XOPEN_XCU_VERSION: crate::stdlib::C2RustUnnamed_0 = 90; +pub const _SC_XOPEN_VERSION: crate::stdlib::C2RustUnnamed_0 = 89; +pub const _SC_PASS_MAX: crate::stdlib::C2RustUnnamed_0 = 88; +pub const _SC_ATEXIT_MAX: crate::stdlib::C2RustUnnamed_0 = 87; +pub const _SC_AVPHYS_PAGES: crate::stdlib::C2RustUnnamed_0 = 86; +pub const _SC_PHYS_PAGES: crate::stdlib::C2RustUnnamed_0 = 85; +pub const _SC_NPROCESSORS_ONLN: crate::stdlib::C2RustUnnamed_0 = 84; +pub const _SC_NPROCESSORS_CONF: crate::stdlib::C2RustUnnamed_0 = 83; +pub const _SC_THREAD_PROCESS_SHARED: crate::stdlib::C2RustUnnamed_0 = 82; +pub const _SC_THREAD_PRIO_PROTECT: crate::stdlib::C2RustUnnamed_0 = 81; +pub const _SC_THREAD_PRIO_INHERIT: crate::stdlib::C2RustUnnamed_0 = 80; +pub const _SC_THREAD_PRIORITY_SCHEDULING: crate::stdlib::C2RustUnnamed_0 = 79; +pub const _SC_THREAD_ATTR_STACKSIZE: crate::stdlib::C2RustUnnamed_0 = 78; +pub const _SC_THREAD_ATTR_STACKADDR: crate::stdlib::C2RustUnnamed_0 = 77; +pub const _SC_THREAD_THREADS_MAX: crate::stdlib::C2RustUnnamed_0 = 76; +pub const _SC_THREAD_STACK_MIN: crate::stdlib::C2RustUnnamed_0 = 75; +pub const _SC_THREAD_KEYS_MAX: crate::stdlib::C2RustUnnamed_0 = 74; +pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: crate::stdlib::C2RustUnnamed_0 = 73; +pub const _SC_TTY_NAME_MAX: crate::stdlib::C2RustUnnamed_0 = 72; +pub const _SC_LOGIN_NAME_MAX: crate::stdlib::C2RustUnnamed_0 = 71; +pub const _SC_GETPW_R_SIZE_MAX: crate::stdlib::C2RustUnnamed_0 = 70; +pub const _SC_GETGR_R_SIZE_MAX: crate::stdlib::C2RustUnnamed_0 = 69; +pub const _SC_THREAD_SAFE_FUNCTIONS: crate::stdlib::C2RustUnnamed_0 = 68; +pub const _SC_THREADS: crate::stdlib::C2RustUnnamed_0 = 67; +pub const _SC_T_IOV_MAX: crate::stdlib::C2RustUnnamed_0 = 66; +pub const _SC_PII_OSI_M: crate::stdlib::C2RustUnnamed_0 = 65; +pub const _SC_PII_OSI_CLTS: crate::stdlib::C2RustUnnamed_0 = 64; +pub const _SC_PII_OSI_COTS: crate::stdlib::C2RustUnnamed_0 = 63; +pub const _SC_PII_INTERNET_DGRAM: crate::stdlib::C2RustUnnamed_0 = 62; +pub const _SC_PII_INTERNET_STREAM: crate::stdlib::C2RustUnnamed_0 = 61; +pub const _SC_IOV_MAX: crate::stdlib::C2RustUnnamed_0 = 60; +pub const _SC_UIO_MAXIOV: crate::stdlib::C2RustUnnamed_0 = 60; +pub const _SC_SELECT: crate::stdlib::C2RustUnnamed_0 = 59; +pub const _SC_POLL: crate::stdlib::C2RustUnnamed_0 = 58; +pub const _SC_PII_OSI: crate::stdlib::C2RustUnnamed_0 = 57; +pub const _SC_PII_INTERNET: crate::stdlib::C2RustUnnamed_0 = 56; +pub const _SC_PII_SOCKET: crate::stdlib::C2RustUnnamed_0 = 55; +pub const _SC_PII_XTI: crate::stdlib::C2RustUnnamed_0 = 54; +pub const _SC_PII: crate::stdlib::C2RustUnnamed_0 = 53; +pub const _SC_2_LOCALEDEF: crate::stdlib::C2RustUnnamed_0 = 52; +pub const _SC_2_SW_DEV: crate::stdlib::C2RustUnnamed_0 = 51; +pub const _SC_2_FORT_RUN: crate::stdlib::C2RustUnnamed_0 = 50; +pub const _SC_2_FORT_DEV: crate::stdlib::C2RustUnnamed_0 = 49; +pub const _SC_2_C_DEV: crate::stdlib::C2RustUnnamed_0 = 48; +pub const _SC_2_C_BIND: crate::stdlib::C2RustUnnamed_0 = 47; +pub const _SC_2_VERSION: crate::stdlib::C2RustUnnamed_0 = 46; +pub const _SC_CHARCLASS_NAME_MAX: crate::stdlib::C2RustUnnamed_0 = 45; +pub const _SC_RE_DUP_MAX: crate::stdlib::C2RustUnnamed_0 = 44; +pub const _SC_LINE_MAX: crate::stdlib::C2RustUnnamed_0 = 43; +pub const _SC_EXPR_NEST_MAX: crate::stdlib::C2RustUnnamed_0 = 42; +pub const _SC_EQUIV_CLASS_MAX: crate::stdlib::C2RustUnnamed_0 = 41; +pub const _SC_COLL_WEIGHTS_MAX: crate::stdlib::C2RustUnnamed_0 = 40; +pub const _SC_BC_STRING_MAX: crate::stdlib::C2RustUnnamed_0 = 39; +pub const _SC_BC_SCALE_MAX: crate::stdlib::C2RustUnnamed_0 = 38; +pub const _SC_BC_DIM_MAX: crate::stdlib::C2RustUnnamed_0 = 37; +pub const _SC_BC_BASE_MAX: crate::stdlib::C2RustUnnamed_0 = 36; +pub const _SC_TIMER_MAX: crate::stdlib::C2RustUnnamed_0 = 35; +pub const _SC_SIGQUEUE_MAX: crate::stdlib::C2RustUnnamed_0 = 34; +pub const _SC_SEM_VALUE_MAX: crate::stdlib::C2RustUnnamed_0 = 33; +pub const _SC_SEM_NSEMS_MAX: crate::stdlib::C2RustUnnamed_0 = 32; +pub const _SC_RTSIG_MAX: crate::stdlib::C2RustUnnamed_0 = 31; +pub const _SC_PAGESIZE: crate::stdlib::C2RustUnnamed_0 = 30; +pub const _SC_VERSION: crate::stdlib::C2RustUnnamed_0 = 29; +pub const _SC_MQ_PRIO_MAX: crate::stdlib::C2RustUnnamed_0 = 28; +pub const _SC_MQ_OPEN_MAX: crate::stdlib::C2RustUnnamed_0 = 27; +pub const _SC_DELAYTIMER_MAX: crate::stdlib::C2RustUnnamed_0 = 26; +pub const _SC_AIO_PRIO_DELTA_MAX: crate::stdlib::C2RustUnnamed_0 = 25; +pub const _SC_AIO_MAX: crate::stdlib::C2RustUnnamed_0 = 24; +pub const _SC_AIO_LISTIO_MAX: crate::stdlib::C2RustUnnamed_0 = 23; +pub const _SC_SHARED_MEMORY_OBJECTS: crate::stdlib::C2RustUnnamed_0 = 22; +pub const _SC_SEMAPHORES: crate::stdlib::C2RustUnnamed_0 = 21; +pub const _SC_MESSAGE_PASSING: crate::stdlib::C2RustUnnamed_0 = 20; +pub const _SC_MEMORY_PROTECTION: crate::stdlib::C2RustUnnamed_0 = 19; +pub const _SC_MEMLOCK_RANGE: crate::stdlib::C2RustUnnamed_0 = 18; +pub const _SC_MEMLOCK: crate::stdlib::C2RustUnnamed_0 = 17; +pub const _SC_MAPPED_FILES: crate::stdlib::C2RustUnnamed_0 = 16; +pub const _SC_FSYNC: crate::stdlib::C2RustUnnamed_0 = 15; +pub const _SC_SYNCHRONIZED_IO: crate::stdlib::C2RustUnnamed_0 = 14; +pub const _SC_PRIORITIZED_IO: crate::stdlib::C2RustUnnamed_0 = 13; +pub const _SC_ASYNCHRONOUS_IO: crate::stdlib::C2RustUnnamed_0 = 12; +pub const _SC_TIMERS: crate::stdlib::C2RustUnnamed_0 = 11; +pub const _SC_PRIORITY_SCHEDULING: crate::stdlib::C2RustUnnamed_0 = 10; +pub const _SC_REALTIME_SIGNALS: crate::stdlib::C2RustUnnamed_0 = 9; +pub const _SC_SAVED_IDS: crate::stdlib::C2RustUnnamed_0 = 8; +pub const _SC_JOB_CONTROL: crate::stdlib::C2RustUnnamed_0 = 7; +pub const _SC_TZNAME_MAX: crate::stdlib::C2RustUnnamed_0 = 6; +pub const _SC_STREAM_MAX: crate::stdlib::C2RustUnnamed_0 = 5; +pub const _SC_OPEN_MAX: crate::stdlib::C2RustUnnamed_0 = 4; +pub const _SC_NGROUPS_MAX: crate::stdlib::C2RustUnnamed_0 = 3; +pub const _SC_CLK_TCK: crate::stdlib::C2RustUnnamed_0 = 2; +pub const _SC_CHILD_MAX: crate::stdlib::C2RustUnnamed_0 = 1; +pub const _SC_ARG_MAX: crate::stdlib::C2RustUnnamed_0 = 0; +// ================ END confname_h ================ +// =============== BEGIN error_h ================ +pub type snd_lib_error_handler_t = Option< + unsafe extern "C" fn( + _: *const libc::c_char, + _: libc::c_int, + _: *const libc::c_char, + _: libc::c_int, + _: *const libc::c_char, + _: ... + ) -> (), +>; +// ================ END error_h ================ +// =============== BEGIN eventfd_h ================ +pub type eventfd_t = crate::stdlib::uint64_t; +// ================ END eventfd_h ================ +// =============== BEGIN fmt123_h ================ +pub type mpg123_enc_enum = libc::c_uint; +pub const MPG123_ENC_SIGNED_32: crate::stdlib::mpg123_enc_enum = 4480; +pub const MPG123_ENC_SIGNED_16: crate::stdlib::mpg123_enc_enum = 208; +pub const MPG123_ENC_ANY: crate::stdlib::mpg123_enc_enum = 30719; +pub const MPG123_ENC_FLOAT_64: crate::stdlib::mpg123_enc_enum = 1024; +pub const MPG123_ENC_FLOAT_32: crate::stdlib::mpg123_enc_enum = 512; +pub const MPG123_ENC_UNSIGNED_24: crate::stdlib::mpg123_enc_enum = 24576; +pub const MPG123_ENC_SIGNED_24: crate::stdlib::mpg123_enc_enum = 20608; +pub const MPG123_ENC_UNSIGNED_32: crate::stdlib::mpg123_enc_enum = 8448; +pub const MPG123_ENC_ALAW_8: crate::stdlib::mpg123_enc_enum = 8; +pub const MPG123_ENC_ULAW_8: crate::stdlib::mpg123_enc_enum = 4; +pub const MPG123_ENC_SIGNED_8: crate::stdlib::mpg123_enc_enum = 130; +pub const MPG123_ENC_UNSIGNED_8: crate::stdlib::mpg123_enc_enum = 1; +pub const MPG123_ENC_UNSIGNED_16: crate::stdlib::mpg123_enc_enum = 96; +pub const MPG123_ENC_FLOAT: crate::stdlib::mpg123_enc_enum = 3584; +pub const MPG123_ENC_SIGNED: crate::stdlib::mpg123_enc_enum = 128; +pub const MPG123_ENC_32: crate::stdlib::mpg123_enc_enum = 256; +pub const MPG123_ENC_24: crate::stdlib::mpg123_enc_enum = 16384; +pub const MPG123_ENC_16: crate::stdlib::mpg123_enc_enum = 64; +pub const MPG123_ENC_8: crate::stdlib::mpg123_enc_enum = 15; +// ================ END fmt123_h ================ +// =============== BEGIN format_h ================ +#[repr(C)] +#[derive(Copy, Clone)] +pub union C2RustUnnamed_4 { + pub stream_info: crate::stdlib::FLAC__StreamMetadata_StreamInfo, + pub padding: crate::stdlib::FLAC__StreamMetadata_Padding, + pub application: crate::stdlib::FLAC__StreamMetadata_Application, + pub seek_table: crate::stdlib::FLAC__StreamMetadata_SeekTable, + pub vorbis_comment: crate::stdlib::FLAC__StreamMetadata_VorbisComment, + pub cue_sheet: crate::stdlib::FLAC__StreamMetadata_CueSheet, + pub picture: crate::stdlib::FLAC__StreamMetadata_Picture, + pub unknown: crate::stdlib::FLAC__StreamMetadata_Unknown, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union C2RustUnnamed_5 { + pub constant: crate::stdlib::FLAC__Subframe_Constant, + pub fixed: crate::stdlib::FLAC__Subframe_Fixed, + pub lpc: crate::stdlib::FLAC__Subframe_LPC, + pub verbatim: crate::stdlib::FLAC__Subframe_Verbatim, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union C2RustUnnamed_6 { + pub partitioned_rice: crate::stdlib::FLAC__EntropyCodingMethod_PartitionedRice, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union C2RustUnnamed_7 { + pub frame_number: crate::stdlib::FLAC__uint32, + pub sample_number: crate::stdlib::FLAC__uint64, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__StreamMetadata { + pub type_0: crate::stdlib::FLAC__MetadataType, + pub is_last: crate::stdlib::FLAC__bool, + pub length: crate::stdlib::uint32_t, + pub data: crate::stdlib::C2RustUnnamed_4, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__Frame { + pub header: crate::stdlib::FLAC__FrameHeader, + pub subframes: [crate::stdlib::FLAC__Subframe; 8], + pub footer: crate::stdlib::FLAC__FrameFooter, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__StreamMetadata_Unknown { + pub data: *mut crate::stdlib::FLAC__byte, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__StreamMetadata_Picture { + pub type_0: crate::stdlib::FLAC__StreamMetadata_Picture_Type, + pub mime_type: *mut libc::c_char, + pub description: *mut crate::stdlib::FLAC__byte, + pub width: crate::stdlib::FLAC__uint32, + pub height: crate::stdlib::FLAC__uint32, + pub depth: crate::stdlib::FLAC__uint32, + pub colors: crate::stdlib::FLAC__uint32, + pub data_length: crate::stdlib::FLAC__uint32, + pub data: *mut crate::stdlib::FLAC__byte, +} +pub type FLAC__StreamMetadata_Picture_Type = libc::c_uint; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__StreamMetadata_CueSheet { + pub media_catalog_number: [libc::c_char; 129], + pub lead_in: crate::stdlib::FLAC__uint64, + pub is_cd: crate::stdlib::FLAC__bool, + pub num_tracks: crate::stdlib::uint32_t, + pub tracks: *mut crate::stdlib::FLAC__StreamMetadata_CueSheet_Track, +} +#[repr(C)] +#[derive(Copy, Clone, BitfieldStruct)] +pub struct FLAC__StreamMetadata_CueSheet_Track { + pub offset: crate::stdlib::FLAC__uint64, + pub number: crate::stdlib::FLAC__byte, + pub isrc: [libc::c_char; 13], + #[bitfield(name = "type_0", ty = "uint32_t", bits = "0..=0")] + #[bitfield(name = "pre_emphasis", ty = "uint32_t", bits = "1..=1")] + pub type_0_pre_emphasis: [u8; 1], + pub num_indices: crate::stdlib::FLAC__byte, + pub indices: *mut crate::stdlib::FLAC__StreamMetadata_CueSheet_Index, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__StreamMetadata_CueSheet_Index { + pub offset: crate::stdlib::FLAC__uint64, + pub number: crate::stdlib::FLAC__byte, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__StreamMetadata_VorbisComment { + pub vendor_string: crate::stdlib::FLAC__StreamMetadata_VorbisComment_Entry, + pub num_comments: crate::stdlib::FLAC__uint32, + pub comments: *mut crate::stdlib::FLAC__StreamMetadata_VorbisComment_Entry, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__StreamMetadata_VorbisComment_Entry { + pub length: crate::stdlib::FLAC__uint32, + pub entry: *mut crate::stdlib::FLAC__byte, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__StreamMetadata_SeekTable { + pub num_points: crate::stdlib::uint32_t, + pub points: *mut crate::stdlib::FLAC__StreamMetadata_SeekPoint, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__StreamMetadata_SeekPoint { + pub sample_number: crate::stdlib::FLAC__uint64, + pub stream_offset: crate::stdlib::FLAC__uint64, + pub frame_samples: crate::stdlib::uint32_t, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__StreamMetadata_Application { + pub id: [crate::stdlib::FLAC__byte; 4], + pub data: *mut crate::stdlib::FLAC__byte, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__StreamMetadata_Padding { + pub dummy: libc::c_int, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__StreamMetadata_StreamInfo { + pub min_blocksize: crate::stdlib::uint32_t, + pub max_blocksize: crate::stdlib::uint32_t, + pub min_framesize: crate::stdlib::uint32_t, + pub max_framesize: crate::stdlib::uint32_t, + pub sample_rate: crate::stdlib::uint32_t, + pub channels: crate::stdlib::uint32_t, + pub bits_per_sample: crate::stdlib::uint32_t, + pub total_samples: crate::stdlib::FLAC__uint64, + pub md5sum: [crate::stdlib::FLAC__byte; 16], +} +pub type FLAC__MetadataType = libc::c_uint; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__FrameFooter { + pub crc: crate::stdlib::FLAC__uint16, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__Subframe { + pub type_0: crate::stdlib::FLAC__SubframeType, + pub data: crate::stdlib::C2RustUnnamed_5, + pub wasted_bits: crate::stdlib::uint32_t, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__Subframe_Verbatim { + pub data: *const crate::stdlib::FLAC__int32, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__Subframe_LPC { + pub entropy_coding_method: crate::stdlib::FLAC__EntropyCodingMethod, + pub order: crate::stdlib::uint32_t, + pub qlp_coeff_precision: crate::stdlib::uint32_t, + pub quantization_level: libc::c_int, + pub qlp_coeff: [crate::stdlib::FLAC__int32; 32], + pub warmup: [crate::stdlib::FLAC__int32; 32], + pub residual: *const crate::stdlib::FLAC__int32, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__EntropyCodingMethod { + pub type_0: crate::stdlib::FLAC__EntropyCodingMethodType, + pub data: crate::stdlib::C2RustUnnamed_6, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__EntropyCodingMethod_PartitionedRice { + pub order: crate::stdlib::uint32_t, + pub contents: *const crate::stdlib::FLAC__EntropyCodingMethod_PartitionedRiceContents, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__EntropyCodingMethod_PartitionedRiceContents { + pub parameters: *mut crate::stdlib::uint32_t, + pub raw_bits: *mut crate::stdlib::uint32_t, + pub capacity_by_order: crate::stdlib::uint32_t, +} +pub type FLAC__EntropyCodingMethodType = libc::c_uint; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__Subframe_Fixed { + pub entropy_coding_method: crate::stdlib::FLAC__EntropyCodingMethod, + pub order: crate::stdlib::uint32_t, + pub warmup: [crate::stdlib::FLAC__int32; 4], + pub residual: *const crate::stdlib::FLAC__int32, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__Subframe_Constant { + pub value: crate::stdlib::FLAC__int32, +} +pub type FLAC__SubframeType = libc::c_uint; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__FrameHeader { + pub blocksize: crate::stdlib::uint32_t, + pub sample_rate: crate::stdlib::uint32_t, + pub channels: crate::stdlib::uint32_t, + pub channel_assignment: crate::stdlib::FLAC__ChannelAssignment, + pub bits_per_sample: crate::stdlib::uint32_t, + pub number_type: crate::stdlib::FLAC__FrameNumberType, + pub number: crate::stdlib::C2RustUnnamed_7, + pub crc: crate::stdlib::FLAC__uint8, +} +pub type FLAC__FrameNumberType = libc::c_uint; +pub type FLAC__ChannelAssignment = libc::c_uint; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 21; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 20; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 19; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 18; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_FISH: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 17; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 16; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 15; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 14; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 13; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 12; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 11; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_BAND: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 10; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 9; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 8; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 7; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 6; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 5; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 4; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 3; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 2; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 1; +pub const FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER: + crate::stdlib::FLAC__StreamMetadata_Picture_Type = 0; +pub const FLAC__MAX_METADATA_TYPE: crate::stdlib::FLAC__MetadataType = 126; +pub const FLAC__METADATA_TYPE_UNDEFINED: crate::stdlib::FLAC__MetadataType = 7; +pub const FLAC__METADATA_TYPE_PICTURE: crate::stdlib::FLAC__MetadataType = 6; +pub const FLAC__METADATA_TYPE_CUESHEET: crate::stdlib::FLAC__MetadataType = 5; +pub const FLAC__METADATA_TYPE_VORBIS_COMMENT: crate::stdlib::FLAC__MetadataType = 4; +pub const FLAC__METADATA_TYPE_SEEKTABLE: crate::stdlib::FLAC__MetadataType = 3; +pub const FLAC__METADATA_TYPE_APPLICATION: crate::stdlib::FLAC__MetadataType = 2; +pub const FLAC__METADATA_TYPE_PADDING: crate::stdlib::FLAC__MetadataType = 1; +pub const FLAC__METADATA_TYPE_STREAMINFO: crate::stdlib::FLAC__MetadataType = 0; +pub const FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2: + crate::stdlib::FLAC__EntropyCodingMethodType = 1; +pub const FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE: + crate::stdlib::FLAC__EntropyCodingMethodType = 0; +pub const FLAC__SUBFRAME_TYPE_LPC: crate::stdlib::FLAC__SubframeType = 3; +pub const FLAC__SUBFRAME_TYPE_FIXED: crate::stdlib::FLAC__SubframeType = 2; +pub const FLAC__SUBFRAME_TYPE_VERBATIM: crate::stdlib::FLAC__SubframeType = 1; +pub const FLAC__SUBFRAME_TYPE_CONSTANT: crate::stdlib::FLAC__SubframeType = 0; +pub const FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER: crate::stdlib::FLAC__FrameNumberType = 1; +pub const FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER: crate::stdlib::FLAC__FrameNumberType = 0; +pub const FLAC__CHANNEL_ASSIGNMENT_MID_SIDE: crate::stdlib::FLAC__ChannelAssignment = 3; +pub const FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE: crate::stdlib::FLAC__ChannelAssignment = 2; +pub const FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE: crate::stdlib::FLAC__ChannelAssignment = 1; +pub const FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT: crate::stdlib::FLAC__ChannelAssignment = 0; +// ================ END format_h ================ +// =============== BEGIN if_h ================ +#[repr(C)] +#[derive(Copy, Clone)] +pub union C2RustUnnamed_20 { + pub ifru_addr: crate::stdlib::sockaddr, + pub ifru_dstaddr: crate::stdlib::sockaddr, + pub ifru_broadaddr: crate::stdlib::sockaddr, + pub ifru_netmask: crate::stdlib::sockaddr, + pub ifru_hwaddr: crate::stdlib::sockaddr, + pub ifru_flags: libc::c_short, + pub ifru_ivalue: libc::c_int, + pub ifru_mtu: libc::c_int, + pub ifru_map: crate::stdlib::ifmap, + pub ifru_slave: [libc::c_char; 16], + pub ifru_newname: [libc::c_char; 16], + pub ifru_data: crate::stdlib::__caddr_t, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union C2RustUnnamed_21 { + pub ifrn_name: [libc::c_char; 16], +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union C2RustUnnamed_22 { + pub ifcu_buf: crate::stdlib::__caddr_t, + pub ifcu_req: *mut crate::stdlib::ifreq, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct ifmap { + pub mem_start: libc::c_ulong, + pub mem_end: libc::c_ulong, + pub base_addr: libc::c_ushort, + pub irq: libc::c_uchar, + pub dma: libc::c_uchar, + pub port: libc::c_uchar, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct ifreq { + pub ifr_ifrn: crate::stdlib::C2RustUnnamed_21, + pub ifr_ifru: crate::stdlib::C2RustUnnamed_20, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct ifconf { + pub ifc_len: libc::c_int, + pub ifc_ifcu: crate::stdlib::C2RustUnnamed_22, +} +// ================ END if_h ================ +// =============== BEGIN in_h ================ +pub type in_addr_t = crate::stdlib::uint32_t; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct in_addr { + pub s_addr: crate::stdlib::in_addr_t, +} +pub type in_port_t = crate::stdlib::uint16_t; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct sockaddr_in { + pub sin_family: crate::stdlib::sa_family_t, + pub sin_port: crate::stdlib::in_port_t, + pub sin_addr: crate::stdlib::in_addr, + pub sin_zero: [libc::c_uchar; 8], +} +// ================ END in_h ================ +// =============== BEGIN mad_h ================ +pub type mad_fixed_t = libc::c_int; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct mad_stream { + pub buffer: *const libc::c_uchar, + pub bufend: *const libc::c_uchar, + pub skiplen: libc::c_ulong, + pub sync: libc::c_int, + pub freerate: libc::c_ulong, + pub this_frame: *const libc::c_uchar, + pub next_frame: *const libc::c_uchar, + pub ptr: crate::stdlib::mad_bitptr, + pub anc_ptr: crate::stdlib::mad_bitptr, + pub anc_bitlen: libc::c_uint, + pub main_data: *mut [libc::c_uchar; 2567], + pub md_len: libc::c_uint, + pub options: libc::c_int, + pub error: crate::stdlib::mad_error, +} +pub type mad_error = libc::c_uint; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct mad_bitptr { + pub byte: *const libc::c_uchar, + pub cache: libc::c_ushort, + pub left: libc::c_ushort, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct mad_frame { + pub header: crate::stdlib::mad_header, + pub options: libc::c_int, + pub sbsample: [[[crate::stdlib::mad_fixed_t; 32]; 36]; 2], + pub overlap: *mut [[[crate::stdlib::mad_fixed_t; 18]; 32]; 2], +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct mad_header { + pub layer: crate::stdlib::mad_layer, + pub mode: crate::stdlib::mad_mode, + pub mode_extension: libc::c_int, + pub emphasis: crate::stdlib::mad_emphasis, + pub bitrate: libc::c_ulong, + pub samplerate: libc::c_uint, + pub crc_check: libc::c_ushort, + pub crc_target: libc::c_ushort, + pub flags: libc::c_int, + pub private_bits: libc::c_int, + pub duration: crate::stdlib::mad_timer_t, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct mad_timer_t { + pub seconds: libc::c_long, + pub fraction: libc::c_ulong, +} +pub type mad_emphasis = libc::c_uint; +pub type mad_mode = libc::c_uint; +pub type mad_layer = libc::c_uint; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct mad_synth { + pub filter: [[[[[crate::stdlib::mad_fixed_t; 8]; 16]; 2]; 2]; 2], + pub phase: libc::c_uint, + pub pcm: crate::stdlib::mad_pcm, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct mad_pcm { + pub samplerate: libc::c_uint, + pub channels: libc::c_ushort, + pub length: libc::c_ushort, + pub samples: [[crate::stdlib::mad_fixed_t; 1152]; 2], +} +pub const MAD_ERROR_BADSTEREO: crate::stdlib::mad_error = 569; +pub const MAD_ERROR_BADHUFFDATA: crate::stdlib::mad_error = 568; +pub const MAD_ERROR_BADHUFFTABLE: crate::stdlib::mad_error = 567; +pub const MAD_ERROR_BADPART3LEN: crate::stdlib::mad_error = 566; +pub const MAD_ERROR_BADDATAPTR: crate::stdlib::mad_error = 565; +pub const MAD_ERROR_BADSCFSI: crate::stdlib::mad_error = 564; +pub const MAD_ERROR_BADBLOCKTYPE: crate::stdlib::mad_error = 563; +pub const MAD_ERROR_BADBIGVALUES: crate::stdlib::mad_error = 562; +pub const MAD_ERROR_BADFRAMELEN: crate::stdlib::mad_error = 561; +pub const MAD_ERROR_BADMODE: crate::stdlib::mad_error = 546; +pub const MAD_ERROR_BADSCALEFACTOR: crate::stdlib::mad_error = 545; +pub const MAD_ERROR_BADBITALLOC: crate::stdlib::mad_error = 529; +pub const MAD_ERROR_BADCRC: crate::stdlib::mad_error = 513; +pub const MAD_ERROR_BADEMPHASIS: crate::stdlib::mad_error = 261; +pub const MAD_ERROR_BADSAMPLERATE: crate::stdlib::mad_error = 260; +pub const MAD_ERROR_BADBITRATE: crate::stdlib::mad_error = 259; +pub const MAD_ERROR_BADLAYER: crate::stdlib::mad_error = 258; +pub const MAD_ERROR_LOSTSYNC: crate::stdlib::mad_error = 257; +pub const MAD_ERROR_NOMEM: crate::stdlib::mad_error = 49; +pub const MAD_ERROR_BUFPTR: crate::stdlib::mad_error = 2; +pub const MAD_ERROR_BUFLEN: crate::stdlib::mad_error = 1; +pub const MAD_ERROR_NONE: crate::stdlib::mad_error = 0; +pub const MAD_EMPHASIS_RESERVED: crate::stdlib::mad_emphasis = 2; +pub const MAD_EMPHASIS_CCITT_J_17: crate::stdlib::mad_emphasis = 3; +pub const MAD_EMPHASIS_50_15_US: crate::stdlib::mad_emphasis = 1; +pub const MAD_EMPHASIS_NONE: crate::stdlib::mad_emphasis = 0; +pub const MAD_MODE_STEREO: crate::stdlib::mad_mode = 3; +pub const MAD_MODE_JOINT_STEREO: crate::stdlib::mad_mode = 2; +pub const MAD_MODE_DUAL_CHANNEL: crate::stdlib::mad_mode = 1; +pub const MAD_MODE_SINGLE_CHANNEL: crate::stdlib::mad_mode = 0; +pub const MAD_LAYER_III: crate::stdlib::mad_layer = 3; +pub const MAD_LAYER_II: crate::stdlib::mad_layer = 2; +pub const MAD_LAYER_I: crate::stdlib::mad_layer = 1; +// ================ END mad_h ================ +// =============== BEGIN mixer_h ================ +pub type snd_mixer_t = crate::stdlib::_snd_mixer; +pub type snd_mixer_class_t = crate::stdlib::_snd_mixer_class; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct snd_mixer_selem_regopt { + pub ver: libc::c_int, + pub abstract_0: crate::stdlib::snd_mixer_selem_regopt_abstract, + pub device: *const libc::c_char, + pub playback_pcm: *mut crate::stdlib::snd_pcm_t, + pub capture_pcm: *mut crate::stdlib::snd_pcm_t, +} +pub type snd_mixer_selem_regopt_abstract = libc::c_uint; +pub type snd_mixer_elem_t = crate::stdlib::_snd_mixer_elem; +pub type snd_mixer_selem_id_t = crate::stdlib::_snd_mixer_selem_id; +pub type snd_mixer_selem_channel_id_t = crate::stdlib::_snd_mixer_selem_channel_id; +pub type _snd_mixer_selem_channel_id = libc::c_int; +pub const SND_MIXER_SABSTRACT_BASIC: crate::stdlib::snd_mixer_selem_regopt_abstract = 1; +pub const SND_MIXER_SABSTRACT_NONE: crate::stdlib::snd_mixer_selem_regopt_abstract = 0; +pub const SND_MIXER_SCHN_MONO: crate::stdlib::_snd_mixer_selem_channel_id = 0; +pub const SND_MIXER_SCHN_LAST: crate::stdlib::_snd_mixer_selem_channel_id = 31; +pub const SND_MIXER_SCHN_REAR_CENTER: crate::stdlib::_snd_mixer_selem_channel_id = 8; +pub const SND_MIXER_SCHN_SIDE_RIGHT: crate::stdlib::_snd_mixer_selem_channel_id = 7; +pub const SND_MIXER_SCHN_SIDE_LEFT: crate::stdlib::_snd_mixer_selem_channel_id = 6; +pub const SND_MIXER_SCHN_WOOFER: crate::stdlib::_snd_mixer_selem_channel_id = 5; +pub const SND_MIXER_SCHN_FRONT_CENTER: crate::stdlib::_snd_mixer_selem_channel_id = 4; +pub const SND_MIXER_SCHN_REAR_RIGHT: crate::stdlib::_snd_mixer_selem_channel_id = 3; +pub const SND_MIXER_SCHN_REAR_LEFT: crate::stdlib::_snd_mixer_selem_channel_id = 2; +pub const SND_MIXER_SCHN_FRONT_RIGHT: crate::stdlib::_snd_mixer_selem_channel_id = 1; +pub const SND_MIXER_SCHN_FRONT_LEFT: crate::stdlib::_snd_mixer_selem_channel_id = 0; +pub const SND_MIXER_SCHN_UNKNOWN: crate::stdlib::_snd_mixer_selem_channel_id = -1; +// ================ END mixer_h ================ +// =============== BEGIN mpg123_h ================ +pub type mpg123_handle = crate::stdlib::mpg123_handle_struct; +pub type mpg123_feature_set = libc::c_uint; +pub type mpg123_errors = libc::c_int; +pub const MPG123_ERR: crate::stdlib::mpg123_errors = -1; +pub const MPG123_DONE: crate::stdlib::mpg123_errors = -12; +pub const MPG123_FEATURE_EQUALIZER: crate::stdlib::mpg123_feature_set = 14; +pub const MPG123_FEATURE_TIMEOUT_READ: crate::stdlib::mpg123_feature_set = 13; +pub const MPG123_FEATURE_PARSE_ICY: crate::stdlib::mpg123_feature_set = 12; +pub const MPG123_FEATURE_DECODE_NTOM: crate::stdlib::mpg123_feature_set = 11; +pub const MPG123_FEATURE_DECODE_DOWNSAMPLE: crate::stdlib::mpg123_feature_set = 10; +pub const MPG123_FEATURE_DECODE_ACCURATE: crate::stdlib::mpg123_feature_set = 9; +pub const MPG123_FEATURE_DECODE_LAYER3: crate::stdlib::mpg123_feature_set = 8; +pub const MPG123_FEATURE_DECODE_LAYER2: crate::stdlib::mpg123_feature_set = 7; +pub const MPG123_FEATURE_DECODE_LAYER1: crate::stdlib::mpg123_feature_set = 6; +pub const MPG123_FEATURE_PARSE_ID3V2: crate::stdlib::mpg123_feature_set = 5; +pub const MPG123_FEATURE_INDEX: crate::stdlib::mpg123_feature_set = 4; +pub const MPG123_FEATURE_OUTPUT_32BIT: crate::stdlib::mpg123_feature_set = 3; +pub const MPG123_FEATURE_OUTPUT_16BIT: crate::stdlib::mpg123_feature_set = 2; +pub const MPG123_FEATURE_OUTPUT_8BIT: crate::stdlib::mpg123_feature_set = 1; +pub const MPG123_FEATURE_ABI_UTF8OPEN: crate::stdlib::mpg123_feature_set = 0; +pub const MPG123_NEW_FORMAT: crate::stdlib::mpg123_errors = -11; +pub const MPG123_INT_OVERFLOW: crate::stdlib::mpg123_errors = 43; +pub const MPG123_LFS_OVERFLOW: crate::stdlib::mpg123_errors = 42; +pub const MPG123_BAD_CUSTOM_IO: crate::stdlib::mpg123_errors = 41; +pub const MPG123_LSEEK_FAILED: crate::stdlib::mpg123_errors = 40; +pub const MPG123_BAD_VALUE: crate::stdlib::mpg123_errors = 39; +pub const MPG123_MISSING_FEATURE: crate::stdlib::mpg123_errors = 38; +pub const MPG123_BAD_DECODER_SETUP: crate::stdlib::mpg123_errors = 37; +pub const MPG123_INDEX_FAIL: crate::stdlib::mpg123_errors = 36; +pub const MPG123_NO_INDEX: crate::stdlib::mpg123_errors = 35; +pub const MPG123_BAD_KEY: crate::stdlib::mpg123_errors = 34; +pub const MPG123_NULL_POINTER: crate::stdlib::mpg123_errors = 33; +pub const MPG123_NO_RELSEEK: crate::stdlib::mpg123_errors = 32; +pub const MPG123_NULL_BUFFER: crate::stdlib::mpg123_errors = 31; +pub const MPG123_BAD_ALIGN: crate::stdlib::mpg123_errors = 30; +pub const MPG123_NO_8BIT: crate::stdlib::mpg123_errors = 29; +pub const MPG123_RESYNC_FAIL: crate::stdlib::mpg123_errors = 28; +pub const MPG123_OUT_OF_SYNC: crate::stdlib::mpg123_errors = 27; +pub const MPG123_BAD_INDEX_PAR: crate::stdlib::mpg123_errors = 26; +pub const MPG123_BAD_PARS: crate::stdlib::mpg123_errors = 25; +pub const MPG123_NO_READER: crate::stdlib::mpg123_errors = 24; +pub const MPG123_NO_SEEK: crate::stdlib::mpg123_errors = 23; +pub const MPG123_BAD_FILE: crate::stdlib::mpg123_errors = 22; +pub const MPG123_NO_TIMEOUT: crate::stdlib::mpg123_errors = 21; +pub const MPG123_BAD_WHENCE: crate::stdlib::mpg123_errors = 20; +pub const MPG123_NO_SEEK_FROM_END: crate::stdlib::mpg123_errors = 19; +pub const MPG123_ERR_READER: crate::stdlib::mpg123_errors = 18; +pub const MPG123_ERR_NULL: crate::stdlib::mpg123_errors = 17; +pub const MPG123_BAD_BAND: crate::stdlib::mpg123_errors = 16; +pub const MPG123_BAD_TYPES: crate::stdlib::mpg123_errors = 15; +pub const MPG123_NO_SPACE: crate::stdlib::mpg123_errors = 14; +pub const MPG123_NO_GAPLESS: crate::stdlib::mpg123_errors = 13; +pub const MPG123_BAD_RVA: crate::stdlib::mpg123_errors = 12; +pub const MPG123_NO_BUFFERS: crate::stdlib::mpg123_errors = 11; +pub const MPG123_BAD_HANDLE: crate::stdlib::mpg123_errors = 10; +pub const MPG123_BAD_DECODER: crate::stdlib::mpg123_errors = 9; +pub const MPG123_NOT_INITIALIZED: crate::stdlib::mpg123_errors = 8; +pub const MPG123_OUT_OF_MEM: crate::stdlib::mpg123_errors = 7; +pub const MPG123_BAD_BUFFER: crate::stdlib::mpg123_errors = 6; +pub const MPG123_BAD_PARAM: crate::stdlib::mpg123_errors = 5; +pub const MPG123_ERR_16TO8TABLE: crate::stdlib::mpg123_errors = 4; +pub const MPG123_BAD_RATE: crate::stdlib::mpg123_errors = 3; +pub const MPG123_BAD_CHANNEL: crate::stdlib::mpg123_errors = 2; +pub const MPG123_BAD_OUTFORMAT: crate::stdlib::mpg123_errors = 1; +pub const MPG123_OK: crate::stdlib::mpg123_errors = 0; +pub const MPG123_NEED_MORE: crate::stdlib::mpg123_errors = -10; +// ================ END mpg123_h ================ +// =============== BEGIN neaacdec_h ================ +#[repr(C)] +#[derive(Copy, Clone)] +pub struct NeAACDecFrameInfo { + pub bytesconsumed: libc::c_ulong, + pub samples: libc::c_ulong, + pub channels: libc::c_uchar, + pub error: libc::c_uchar, + pub samplerate: libc::c_ulong, + pub sbr: libc::c_uchar, + pub object_type: libc::c_uchar, + pub header_type: libc::c_uchar, + pub num_front_channels: libc::c_uchar, + pub num_side_channels: libc::c_uchar, + pub num_back_channels: libc::c_uchar, + pub num_lfe_channels: libc::c_uchar, + pub channel_position: [libc::c_uchar; 64], + pub ps: libc::c_uchar, +} +pub type NeAACDecHandle = *mut libc::c_void; +pub type NeAACDecConfigurationPtr = *mut crate::stdlib::NeAACDecConfiguration; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct NeAACDecConfiguration { + pub defObjectType: libc::c_uchar, + pub defSampleRate: libc::c_ulong, + pub outputFormat: libc::c_uchar, + pub downMatrix: libc::c_uchar, + pub useOldADTSFormat: libc::c_uchar, + pub dontUpSampleImplicitSBR: libc::c_uchar, +} +// ================ END neaacdec_h ================ +// =============== BEGIN netdb_h ================ +#[repr(C)] +#[derive(Copy, Clone)] +pub struct addrinfo { + pub ai_flags: libc::c_int, + pub ai_family: libc::c_int, + pub ai_socktype: libc::c_int, + pub ai_protocol: libc::c_int, + pub ai_addrlen: crate::stdlib::socklen_t, + pub ai_addr: *mut crate::stdlib::sockaddr, + pub ai_canonname: *mut libc::c_char, + pub ai_next: *mut crate::stdlib::addrinfo, +} +// ================ END netdb_h ================ +// =============== BEGIN ogg_h ================ +#[repr(C)] +#[derive(Copy, Clone)] +pub struct ogg_sync_state { + pub data: *mut libc::c_uchar, + pub storage: libc::c_int, + pub fill: libc::c_int, + pub returned: libc::c_int, + pub unsynced: libc::c_int, + pub headerbytes: libc::c_int, + pub bodybytes: libc::c_int, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct ogg_stream_state { + pub body_data: *mut libc::c_uchar, + pub body_storage: libc::c_long, + pub body_fill: libc::c_long, + pub body_returned: libc::c_long, + pub lacing_vals: *mut libc::c_int, + pub granule_vals: *mut crate::stdlib::ogg_int64_t, + pub lacing_storage: libc::c_long, + pub lacing_fill: libc::c_long, + pub lacing_packet: libc::c_long, + pub lacing_returned: libc::c_long, + pub header: [libc::c_uchar; 282], + pub header_fill: libc::c_int, + pub e_o_s: libc::c_int, + pub b_o_s: libc::c_int, + pub serialno: libc::c_long, + pub pageno: libc::c_long, + pub packetno: crate::stdlib::ogg_int64_t, + pub granulepos: crate::stdlib::ogg_int64_t, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct oggpack_buffer { + pub endbyte: libc::c_long, + pub endbit: libc::c_int, + pub buffer: *mut libc::c_uchar, + pub ptr: *mut libc::c_uchar, + pub storage: libc::c_long, +} +// ================ END ogg_h ================ +// =============== BEGIN ordinals_h ================ +pub type FLAC__int32 = crate::stdlib::int32_t; +pub type FLAC__bool = libc::c_int; +pub type FLAC__uint64 = crate::stdlib::uint64_t; +pub type FLAC__byte = crate::stdlib::FLAC__uint8; +pub type FLAC__uint8 = crate::stdlib::uint8_t; +pub type FLAC__uint32 = crate::stdlib::uint32_t; +pub type FLAC__uint16 = crate::stdlib::uint16_t; +// ================ END ordinals_h ================ +// =============== BEGIN output_h ================ +pub type snd_output_t = crate::stdlib::_snd_output; +// ================ END output_h ================ +// =============== BEGIN pcm_h ================ +pub type snd_pcm_t = crate::stdlib::_snd_pcm; +pub type snd_pcm_uframes_t = libc::c_ulong; +pub type snd_pcm_format_t = crate::stdlib::_snd_pcm_format; +pub type _snd_pcm_format = libc::c_int; +pub type snd_pcm_hw_params_t = crate::stdlib::_snd_pcm_hw_params; +pub type snd_pcm_stream_t = crate::stdlib::_snd_pcm_stream; +pub type _snd_pcm_stream = libc::c_uint; +pub type snd_pcm_sframes_t = libc::c_long; +pub type snd_pcm_state_t = crate::stdlib::_snd_pcm_state; +pub type _snd_pcm_state = libc::c_uint; +pub type snd_pcm_access_t = crate::stdlib::_snd_pcm_access; +pub type _snd_pcm_access = libc::c_uint; +pub type snd_pcm_channel_area_t = crate::stdlib::_snd_pcm_channel_area; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct _snd_pcm_channel_area { + pub addr: *mut libc::c_void, + pub first: libc::c_uint, + pub step: libc::c_uint, +} +pub const SND_PCM_FORMAT_U20: crate::stdlib::_snd_pcm_format = 27; +pub const SND_PCM_FORMAT_S20: crate::stdlib::_snd_pcm_format = 25; +pub const SND_PCM_FORMAT_IEC958_SUBFRAME: crate::stdlib::_snd_pcm_format = 18; +pub const SND_PCM_FORMAT_FLOAT64: crate::stdlib::_snd_pcm_format = 16; +pub const SND_PCM_FORMAT_FLOAT: crate::stdlib::_snd_pcm_format = 14; +pub const SND_PCM_FORMAT_U32: crate::stdlib::_snd_pcm_format = 12; +pub const SND_PCM_FORMAT_S32: crate::stdlib::_snd_pcm_format = 10; +pub const SND_PCM_FORMAT_U24: crate::stdlib::_snd_pcm_format = 8; +pub const SND_PCM_FORMAT_S24: crate::stdlib::_snd_pcm_format = 6; +pub const SND_PCM_FORMAT_U16: crate::stdlib::_snd_pcm_format = 4; +pub const SND_PCM_FORMAT_S16: crate::stdlib::_snd_pcm_format = 2; +pub const SND_PCM_FORMAT_LAST: crate::stdlib::_snd_pcm_format = 52; +pub const SND_PCM_FORMAT_DSD_U32_BE: crate::stdlib::_snd_pcm_format = 52; +pub const SND_PCM_FORMAT_DSD_U16_BE: crate::stdlib::_snd_pcm_format = 51; +pub const SND_PCM_FORMAT_DSD_U32_LE: crate::stdlib::_snd_pcm_format = 50; +pub const SND_PCM_FORMAT_DSD_U16_LE: crate::stdlib::_snd_pcm_format = 49; +pub const SND_PCM_FORMAT_DSD_U8: crate::stdlib::_snd_pcm_format = 48; +pub const SND_PCM_FORMAT_G723_40_1B: crate::stdlib::_snd_pcm_format = 47; +pub const SND_PCM_FORMAT_G723_40: crate::stdlib::_snd_pcm_format = 46; +pub const SND_PCM_FORMAT_G723_24_1B: crate::stdlib::_snd_pcm_format = 45; +pub const SND_PCM_FORMAT_G723_24: crate::stdlib::_snd_pcm_format = 44; +pub const SND_PCM_FORMAT_U18_3BE: crate::stdlib::_snd_pcm_format = 43; +pub const SND_PCM_FORMAT_U18_3LE: crate::stdlib::_snd_pcm_format = 42; +pub const SND_PCM_FORMAT_S18_3BE: crate::stdlib::_snd_pcm_format = 41; +pub const SND_PCM_FORMAT_S18_3LE: crate::stdlib::_snd_pcm_format = 40; +pub const SND_PCM_FORMAT_U20_3BE: crate::stdlib::_snd_pcm_format = 39; +pub const SND_PCM_FORMAT_U20_3LE: crate::stdlib::_snd_pcm_format = 38; +pub const SND_PCM_FORMAT_S20_3BE: crate::stdlib::_snd_pcm_format = 37; +pub const SND_PCM_FORMAT_S20_3LE: crate::stdlib::_snd_pcm_format = 36; +pub const SND_PCM_FORMAT_U24_3BE: crate::stdlib::_snd_pcm_format = 35; +pub const SND_PCM_FORMAT_U24_3LE: crate::stdlib::_snd_pcm_format = 34; +pub const SND_PCM_FORMAT_S24_3BE: crate::stdlib::_snd_pcm_format = 33; +pub const SND_PCM_FORMAT_S24_3LE: crate::stdlib::_snd_pcm_format = 32; +pub const SND_PCM_FORMAT_SPECIAL: crate::stdlib::_snd_pcm_format = 31; +pub const SND_PCM_FORMAT_U20_BE: crate::stdlib::_snd_pcm_format = 28; +pub const SND_PCM_FORMAT_U20_LE: crate::stdlib::_snd_pcm_format = 27; +pub const SND_PCM_FORMAT_S20_BE: crate::stdlib::_snd_pcm_format = 26; +pub const SND_PCM_FORMAT_S20_LE: crate::stdlib::_snd_pcm_format = 25; +pub const SND_PCM_FORMAT_GSM: crate::stdlib::_snd_pcm_format = 24; +pub const SND_PCM_FORMAT_MPEG: crate::stdlib::_snd_pcm_format = 23; +pub const SND_PCM_FORMAT_IMA_ADPCM: crate::stdlib::_snd_pcm_format = 22; +pub const SND_PCM_FORMAT_A_LAW: crate::stdlib::_snd_pcm_format = 21; +pub const SND_PCM_FORMAT_MU_LAW: crate::stdlib::_snd_pcm_format = 20; +pub const SND_PCM_FORMAT_IEC958_SUBFRAME_BE: crate::stdlib::_snd_pcm_format = 19; +pub const SND_PCM_FORMAT_IEC958_SUBFRAME_LE: crate::stdlib::_snd_pcm_format = 18; +pub const SND_PCM_FORMAT_FLOAT64_BE: crate::stdlib::_snd_pcm_format = 17; +pub const SND_PCM_FORMAT_FLOAT64_LE: crate::stdlib::_snd_pcm_format = 16; +pub const SND_PCM_FORMAT_FLOAT_BE: crate::stdlib::_snd_pcm_format = 15; +pub const SND_PCM_FORMAT_FLOAT_LE: crate::stdlib::_snd_pcm_format = 14; +pub const SND_PCM_FORMAT_U32_BE: crate::stdlib::_snd_pcm_format = 13; +pub const SND_PCM_FORMAT_U32_LE: crate::stdlib::_snd_pcm_format = 12; +pub const SND_PCM_FORMAT_S32_BE: crate::stdlib::_snd_pcm_format = 11; +pub const SND_PCM_FORMAT_S32_LE: crate::stdlib::_snd_pcm_format = 10; +pub const SND_PCM_FORMAT_U24_BE: crate::stdlib::_snd_pcm_format = 9; +pub const SND_PCM_FORMAT_U24_LE: crate::stdlib::_snd_pcm_format = 8; +pub const SND_PCM_FORMAT_S24_BE: crate::stdlib::_snd_pcm_format = 7; +pub const SND_PCM_FORMAT_S24_LE: crate::stdlib::_snd_pcm_format = 6; +pub const SND_PCM_FORMAT_U16_BE: crate::stdlib::_snd_pcm_format = 5; +pub const SND_PCM_FORMAT_U16_LE: crate::stdlib::_snd_pcm_format = 4; +pub const SND_PCM_FORMAT_S16_BE: crate::stdlib::_snd_pcm_format = 3; +pub const SND_PCM_FORMAT_S16_LE: crate::stdlib::_snd_pcm_format = 2; +pub const SND_PCM_FORMAT_U8: crate::stdlib::_snd_pcm_format = 1; +pub const SND_PCM_FORMAT_S8: crate::stdlib::_snd_pcm_format = 0; +pub const SND_PCM_FORMAT_UNKNOWN: crate::stdlib::_snd_pcm_format = -1; +pub const SND_PCM_STREAM_LAST: crate::stdlib::_snd_pcm_stream = 1; +pub const SND_PCM_STREAM_CAPTURE: crate::stdlib::_snd_pcm_stream = 1; +pub const SND_PCM_STREAM_PLAYBACK: crate::stdlib::_snd_pcm_stream = 0; +pub const SND_PCM_STATE_DISCONNECTED: crate::stdlib::_snd_pcm_state = 8; +pub const SND_PCM_STATE_PRIVATE1: crate::stdlib::_snd_pcm_state = 1024; +pub const SND_PCM_STATE_LAST: crate::stdlib::_snd_pcm_state = 8; +pub const SND_PCM_STATE_SUSPENDED: crate::stdlib::_snd_pcm_state = 7; +pub const SND_PCM_STATE_PAUSED: crate::stdlib::_snd_pcm_state = 6; +pub const SND_PCM_STATE_DRAINING: crate::stdlib::_snd_pcm_state = 5; +pub const SND_PCM_STATE_XRUN: crate::stdlib::_snd_pcm_state = 4; +pub const SND_PCM_STATE_RUNNING: crate::stdlib::_snd_pcm_state = 3; +pub const SND_PCM_STATE_PREPARED: crate::stdlib::_snd_pcm_state = 2; +pub const SND_PCM_STATE_SETUP: crate::stdlib::_snd_pcm_state = 1; +pub const SND_PCM_STATE_OPEN: crate::stdlib::_snd_pcm_state = 0; +pub const SND_PCM_ACCESS_LAST: crate::stdlib::_snd_pcm_access = 4; +pub const SND_PCM_ACCESS_RW_NONINTERLEAVED: crate::stdlib::_snd_pcm_access = 4; +pub const SND_PCM_ACCESS_RW_INTERLEAVED: crate::stdlib::_snd_pcm_access = 3; +pub const SND_PCM_ACCESS_MMAP_COMPLEX: crate::stdlib::_snd_pcm_access = 2; +pub const SND_PCM_ACCESS_MMAP_NONINTERLEAVED: crate::stdlib::_snd_pcm_access = 1; +pub const SND_PCM_ACCESS_MMAP_INTERLEAVED: crate::stdlib::_snd_pcm_access = 0; +// ================ END pcm_h ================ +// =============== BEGIN poll_h ================ +pub type nfds_t = libc::c_ulong; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct pollfd { + pub fd: libc::c_int, + pub events: libc::c_short, + pub revents: libc::c_short, +} +// ================ END poll_h ================ +// =============== BEGIN pthread_h ================ +pub type C2RustUnnamed_0 = libc::c_uint; +pub const PTHREAD_PRIO_PROTECT: crate::stdlib::C2RustUnnamed_0 = 2; +pub const PTHREAD_PRIO_INHERIT: crate::stdlib::C2RustUnnamed_0 = 1; +pub const PTHREAD_PRIO_NONE: crate::stdlib::C2RustUnnamed_0 = 0; +// ================ END pthread_h ================ +// =============== BEGIN pthreadtypes_h ================ +pub type pthread_t = libc::c_ulong; +#[repr(C)] +#[derive(Copy, Clone)] +pub union pthread_attr_t { + pub __size: [libc::c_char; 56], + pub __align: libc::c_long, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union pthread_mutexattr_t { + pub __size: [libc::c_char; 4], + pub __align: libc::c_int, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union pthread_mutex_t { + pub __data: crate::stdlib::__pthread_mutex_s, + pub __size: [libc::c_char; 40], + pub __align: libc::c_long, +} +// ================ END pthreadtypes_h ================ +// =============== BEGIN select_h ================ +pub type __fd_mask = libc::c_long; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct fd_set { + pub __fds_bits: [crate::stdlib::__fd_mask; 16], +} +// ================ END select_h ================ +// =============== BEGIN sockaddr_h ================ +pub type sa_family_t = libc::c_ushort; +// ================ END sockaddr_h ================ +// =============== BEGIN socket_h ================ +#[repr(C)] +#[derive(Copy, Clone)] +pub struct sockaddr { + pub sa_family: crate::stdlib::sa_family_t, + pub sa_data: [libc::c_char; 14], +} +pub const MSG_CMSG_CLOEXEC: crate::stdlib::C2RustUnnamed_0 = 1073741824; +pub const MSG_FASTOPEN: crate::stdlib::C2RustUnnamed_0 = 536870912; +pub const MSG_ZEROCOPY: crate::stdlib::C2RustUnnamed_0 = 67108864; +pub const MSG_BATCH: crate::stdlib::C2RustUnnamed_0 = 262144; +pub const MSG_WAITFORONE: crate::stdlib::C2RustUnnamed_0 = 65536; +pub const MSG_MORE: crate::stdlib::C2RustUnnamed_0 = 32768; +pub const MSG_NOSIGNAL: crate::stdlib::C2RustUnnamed_0 = 16384; +pub const MSG_ERRQUEUE: crate::stdlib::C2RustUnnamed_0 = 8192; +pub const MSG_RST: crate::stdlib::C2RustUnnamed_0 = 4096; +pub const MSG_CONFIRM: crate::stdlib::C2RustUnnamed_0 = 2048; +pub const MSG_SYN: crate::stdlib::C2RustUnnamed_0 = 1024; +pub const MSG_FIN: crate::stdlib::C2RustUnnamed_0 = 512; +pub const MSG_WAITALL: crate::stdlib::C2RustUnnamed_0 = 256; +pub const MSG_EOR: crate::stdlib::C2RustUnnamed_0 = 128; +pub const MSG_DONTWAIT: crate::stdlib::C2RustUnnamed_0 = 64; +pub const MSG_TRUNC: crate::stdlib::C2RustUnnamed_0 = 32; +pub const MSG_PROXY: crate::stdlib::C2RustUnnamed_0 = 16; +pub const MSG_CTRUNC: crate::stdlib::C2RustUnnamed_0 = 8; +pub const MSG_DONTROUTE: crate::stdlib::C2RustUnnamed_0 = 4; +pub const MSG_PEEK: crate::stdlib::C2RustUnnamed_0 = 2; +pub const MSG_OOB: crate::stdlib::C2RustUnnamed_0 = 1; +pub const MSG_TRYHARD: crate::stdlib::C2RustUnnamed_0 = 4; +// ================ END socket_h ================ +// =============== BEGIN socket_type_h ================ +pub type __socket_type = libc::c_uint; +pub const SOCK_NONBLOCK: crate::stdlib::__socket_type = 2048; +pub const SOCK_CLOEXEC: crate::stdlib::__socket_type = 524288; +pub const SOCK_PACKET: crate::stdlib::__socket_type = 10; +pub const SOCK_DCCP: crate::stdlib::__socket_type = 6; +pub const SOCK_SEQPACKET: crate::stdlib::__socket_type = 5; +pub const SOCK_RDM: crate::stdlib::__socket_type = 4; +pub const SOCK_RAW: crate::stdlib::__socket_type = 3; +pub const SOCK_DGRAM: crate::stdlib::__socket_type = 2; +pub const SOCK_STREAM: crate::stdlib::__socket_type = 1; +// ================ END socket_type_h ================ +// =============== BEGIN stdint_h ================ +pub type uintptr_t = libc::c_ulong; +// ================ END stdint_h ================ +// =============== BEGIN stdint_intn_h ================ +pub type int16_t = crate::stdlib::__int16_t; +pub type int32_t = crate::stdlib::__int32_t; +pub type int64_t = crate::stdlib::__int64_t; +// ================ END stdint_intn_h ================ +// =============== BEGIN stdint_uintn_h ================ +pub type uint8_t = crate::stdlib::__uint8_t; +pub type uint16_t = crate::stdlib::__uint16_t; +pub type uint32_t = crate::stdlib::__uint32_t; +pub type uint64_t = crate::stdlib::__uint64_t; +// ================ END stdint_uintn_h ================ +// =============== BEGIN stdio_h ================ +pub type ssize_t = crate::stdlib::__ssize_t; +// ================ END stdio_h ================ +// =============== BEGIN stream_decoder_h ================ +pub type FLAC__StreamDecoderState = libc::c_uint; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FLAC__StreamDecoder { + pub protected_: *mut crate::stdlib::FLAC__StreamDecoderProtected, + pub private_: *mut crate::stdlib::FLAC__StreamDecoderPrivate, +} +pub type FLAC__StreamDecoderErrorCallback = Option< + unsafe extern "C" fn( + _: *const crate::stdlib::FLAC__StreamDecoder, + _: crate::stdlib::FLAC__StreamDecoderErrorStatus, + _: *mut libc::c_void, + ) -> (), +>; +pub type FLAC__StreamDecoderErrorStatus = libc::c_uint; +pub type FLAC__StreamDecoderMetadataCallback = Option< + unsafe extern "C" fn( + _: *const crate::stdlib::FLAC__StreamDecoder, + _: *const crate::stdlib::FLAC__StreamMetadata, + _: *mut libc::c_void, + ) -> (), +>; +pub type FLAC__StreamDecoderWriteCallback = Option< + unsafe extern "C" fn( + _: *const crate::stdlib::FLAC__StreamDecoder, + _: *const crate::stdlib::FLAC__Frame, + _: *const *const crate::stdlib::FLAC__int32, + _: *mut libc::c_void, + ) -> crate::stdlib::FLAC__StreamDecoderWriteStatus, +>; +pub type FLAC__StreamDecoderWriteStatus = libc::c_uint; +pub type FLAC__StreamDecoderEofCallback = Option< + unsafe extern "C" fn( + _: *const crate::stdlib::FLAC__StreamDecoder, + _: *mut libc::c_void, + ) -> crate::stdlib::FLAC__bool, +>; +pub type FLAC__StreamDecoderLengthCallback = Option< + unsafe extern "C" fn( + _: *const crate::stdlib::FLAC__StreamDecoder, + _: *mut crate::stdlib::FLAC__uint64, + _: *mut libc::c_void, + ) -> crate::stdlib::FLAC__StreamDecoderLengthStatus, +>; +pub type FLAC__StreamDecoderLengthStatus = libc::c_uint; +pub type FLAC__StreamDecoderTellCallback = Option< + unsafe extern "C" fn( + _: *const crate::stdlib::FLAC__StreamDecoder, + _: *mut crate::stdlib::FLAC__uint64, + _: *mut libc::c_void, + ) -> crate::stdlib::FLAC__StreamDecoderTellStatus, +>; +pub type FLAC__StreamDecoderTellStatus = libc::c_uint; +pub type FLAC__StreamDecoderSeekCallback = Option< + unsafe extern "C" fn( + _: *const crate::stdlib::FLAC__StreamDecoder, + _: crate::stdlib::FLAC__uint64, + _: *mut libc::c_void, + ) -> crate::stdlib::FLAC__StreamDecoderSeekStatus, +>; +pub type FLAC__StreamDecoderSeekStatus = libc::c_uint; +pub type FLAC__StreamDecoderReadCallback = Option< + unsafe extern "C" fn( + _: *const crate::stdlib::FLAC__StreamDecoder, + _: *mut crate::stdlib::FLAC__byte, + _: *mut crate::stddef_h::size_t, + _: *mut libc::c_void, + ) -> crate::stdlib::FLAC__StreamDecoderReadStatus, +>; +pub type FLAC__StreamDecoderReadStatus = libc::c_uint; +pub type FLAC__StreamDecoderInitStatus = libc::c_uint; +pub const FLAC__STREAM_DECODER_END_OF_STREAM: crate::stdlib::FLAC__StreamDecoderState = 4; +pub const FLAC__STREAM_DECODER_UNINITIALIZED: crate::stdlib::FLAC__StreamDecoderState = 9; +pub const FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR: crate::stdlib::FLAC__StreamDecoderState = 8; +pub const FLAC__STREAM_DECODER_ABORTED: crate::stdlib::FLAC__StreamDecoderState = 7; +pub const FLAC__STREAM_DECODER_SEEK_ERROR: crate::stdlib::FLAC__StreamDecoderState = 6; +pub const FLAC__STREAM_DECODER_OGG_ERROR: crate::stdlib::FLAC__StreamDecoderState = 5; +pub const FLAC__STREAM_DECODER_READ_FRAME: crate::stdlib::FLAC__StreamDecoderState = 3; +pub const FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC: crate::stdlib::FLAC__StreamDecoderState = 2; +pub const FLAC__STREAM_DECODER_READ_METADATA: crate::stdlib::FLAC__StreamDecoderState = 1; +pub const FLAC__STREAM_DECODER_SEARCH_FOR_METADATA: crate::stdlib::FLAC__StreamDecoderState = 0; +pub const FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM: + crate::stdlib::FLAC__StreamDecoderErrorStatus = 3; +pub const FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH: + crate::stdlib::FLAC__StreamDecoderErrorStatus = 2; +pub const FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER: + crate::stdlib::FLAC__StreamDecoderErrorStatus = 1; +pub const FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC: + crate::stdlib::FLAC__StreamDecoderErrorStatus = 0; +pub const FLAC__STREAM_DECODER_WRITE_STATUS_ABORT: crate::stdlib::FLAC__StreamDecoderWriteStatus = + 1; +pub const FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE: + crate::stdlib::FLAC__StreamDecoderWriteStatus = 0; +pub const FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED: + crate::stdlib::FLAC__StreamDecoderLengthStatus = 2; +pub const FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR: crate::stdlib::FLAC__StreamDecoderLengthStatus = + 1; +pub const FLAC__STREAM_DECODER_LENGTH_STATUS_OK: crate::stdlib::FLAC__StreamDecoderLengthStatus = 0; +pub const FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED: + crate::stdlib::FLAC__StreamDecoderTellStatus = 2; +pub const FLAC__STREAM_DECODER_TELL_STATUS_ERROR: crate::stdlib::FLAC__StreamDecoderTellStatus = 1; +pub const FLAC__STREAM_DECODER_TELL_STATUS_OK: crate::stdlib::FLAC__StreamDecoderTellStatus = 0; +pub const FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED: + crate::stdlib::FLAC__StreamDecoderSeekStatus = 2; +pub const FLAC__STREAM_DECODER_SEEK_STATUS_ERROR: crate::stdlib::FLAC__StreamDecoderSeekStatus = 1; +pub const FLAC__STREAM_DECODER_SEEK_STATUS_OK: crate::stdlib::FLAC__StreamDecoderSeekStatus = 0; +pub const FLAC__STREAM_DECODER_READ_STATUS_ABORT: crate::stdlib::FLAC__StreamDecoderReadStatus = 2; +pub const FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM: + crate::stdlib::FLAC__StreamDecoderReadStatus = 1; +pub const FLAC__STREAM_DECODER_READ_STATUS_CONTINUE: crate::stdlib::FLAC__StreamDecoderReadStatus = + 0; +pub const FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED: + crate::stdlib::FLAC__StreamDecoderInitStatus = 5; +pub const FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE: + crate::stdlib::FLAC__StreamDecoderInitStatus = 4; +pub const FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR: + crate::stdlib::FLAC__StreamDecoderInitStatus = 3; +pub const FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS: + crate::stdlib::FLAC__StreamDecoderInitStatus = 2; +pub const FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER: + crate::stdlib::FLAC__StreamDecoderInitStatus = 1; +pub const FLAC__STREAM_DECODER_INIT_STATUS_OK: crate::stdlib::FLAC__StreamDecoderInitStatus = 0; +// ================ END stream_decoder_h ================ +// =============== BEGIN struct_FILE_h ================ +#[repr(C)] +#[derive(Copy, Clone)] +pub struct _IO_FILE { + pub _flags: libc::c_int, + pub _IO_read_ptr: *mut libc::c_char, + pub _IO_read_end: *mut libc::c_char, + pub _IO_read_base: *mut libc::c_char, + pub _IO_write_base: *mut libc::c_char, + pub _IO_write_ptr: *mut libc::c_char, + pub _IO_write_end: *mut libc::c_char, + pub _IO_buf_base: *mut libc::c_char, + pub _IO_buf_end: *mut libc::c_char, + pub _IO_save_base: *mut libc::c_char, + pub _IO_backup_base: *mut libc::c_char, + pub _IO_save_end: *mut libc::c_char, + pub _markers: *mut crate::stdlib::_IO_marker, + pub _chain: *mut crate::stdlib::_IO_FILE, + pub _fileno: libc::c_int, + pub _flags2: libc::c_int, + pub _old_offset: crate::stdlib::__off_t, + pub _cur_column: libc::c_ushort, + pub _vtable_offset: libc::c_schar, + pub _shortbuf: [libc::c_char; 1], + pub _lock: *mut libc::c_void, + pub _offset: crate::stdlib::__off64_t, + pub _codecvt: *mut crate::stdlib::_IO_codecvt, + pub _wide_data: *mut crate::stdlib::_IO_wide_data, + pub _freeres_list: *mut crate::stdlib::_IO_FILE, + pub _freeres_buf: *mut libc::c_void, + pub __pad5: crate::stddef_h::size_t, + pub _mode: libc::c_int, + pub _unused2: [libc::c_char; 20], +} +pub type _IO_lock_t = (); +// ================ END struct_FILE_h ================ +// =============== BEGIN struct_sched_param_h ================ +#[repr(C)] +#[derive(Copy, Clone)] +pub struct sched_param { + pub sched_priority: libc::c_int, +} +// ================ END struct_sched_param_h ================ +// =============== BEGIN struct_timespec_h ================ +#[repr(C)] +#[derive(Copy, Clone)] +pub struct timespec { + pub tv_sec: crate::stdlib::__time_t, + pub tv_nsec: crate::stdlib::__syscall_slong_t, +} +// ================ END struct_timespec_h ================ +// =============== BEGIN struct_timeval_h ================ +#[repr(C)] +#[derive(Copy, Clone)] +pub struct timeval { + pub tv_sec: crate::stdlib::__time_t, + pub tv_usec: crate::stdlib::__suseconds_t, +} +// ================ END struct_timeval_h ================ +// =============== BEGIN struct_tm_h ================ +#[repr(C)] +#[derive(Copy, Clone)] +pub struct tm { + pub tm_sec: libc::c_int, + pub tm_min: libc::c_int, + pub tm_hour: libc::c_int, + pub tm_mday: libc::c_int, + pub tm_mon: libc::c_int, + pub tm_year: libc::c_int, + pub tm_wday: libc::c_int, + pub tm_yday: libc::c_int, + pub tm_isdst: libc::c_int, + pub tm_gmtoff: libc::c_long, + pub tm_zone: *const libc::c_char, +} +// ================ END struct_tm_h ================ +// =============== BEGIN sys_types_h ================ +pub type u_int32_t = crate::stdlib::__uint32_t; +pub type u_int64_t = crate::stdlib::__uint64_t; +pub type u_int16_t = crate::stdlib::__uint16_t; +pub type u_int8_t = crate::stdlib::__uint8_t; +// ================ END sys_types_h ================ +// =============== BEGIN thread_shared_types_h ================ +#[repr(C)] +#[derive(Copy, Clone)] +pub struct __pthread_internal_list { + pub __prev: *mut crate::stdlib::__pthread_internal_list, + pub __next: *mut crate::stdlib::__pthread_internal_list, +} +pub type __pthread_list_t = crate::stdlib::__pthread_internal_list; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct __pthread_mutex_s { + pub __lock: libc::c_int, + pub __count: libc::c_uint, + pub __owner: libc::c_int, + pub __nusers: libc::c_uint, + pub __kind: libc::c_int, + pub __spins: libc::c_short, + pub __elision: libc::c_short, + pub __list: crate::stdlib::__pthread_list_t, +} +// ================ END thread_shared_types_h ================ +// =============== BEGIN time_h ================ +#[repr(C)] +#[derive(Copy, Clone)] +pub struct timezone { + pub tz_minuteswest: libc::c_int, + pub tz_dsttime: libc::c_int, +} +pub type __timezone_ptr_t = *mut crate::stdlib::timezone; +// ================ END time_h ================ +// =============== BEGIN time_t_h ================ +pub type time_t = crate::stdlib::__time_t; +// ================ END time_t_h ================ +// =============== BEGIN types_h ================ +pub type __uint16_t = libc::c_ushort; +pub type __int16_t = libc::c_short; +pub type __time_t = libc::c_long; +pub type __suseconds_t = libc::c_long; +pub type __clockid_t = libc::c_int; +pub type __syscall_slong_t = libc::c_long; +pub type __caddr_t = *mut libc::c_char; +pub type __int32_t = libc::c_int; +pub type __uint32_t = libc::c_uint; +pub type __uint64_t = libc::c_ulong; +pub type __useconds_t = libc::c_uint; +pub type __int64_t = libc::c_long; +pub type __ssize_t = libc::c_long; +pub type __socklen_t = libc::c_uint; +pub type __uint8_t = libc::c_uchar; +pub type __off_t = libc::c_long; +pub type __off64_t = libc::c_long; +// ================ END types_h ================ +// =============== BEGIN unistd_h ================ +pub type socklen_t = crate::stdlib::__socklen_t; +// ================ END unistd_h ================ +// =============== BEGIN vorbisfile_h ================ +#[repr(C)] +#[derive(Copy, Clone)] +pub struct OggVorbis_File { + pub datasource: *mut libc::c_void, + pub seekable: libc::c_int, + pub offset: crate::stdlib::ogg_int64_t, + pub end: crate::stdlib::ogg_int64_t, + pub oy: crate::stdlib::ogg_sync_state, + pub links: libc::c_int, + pub offsets: *mut crate::stdlib::ogg_int64_t, + pub dataoffsets: *mut crate::stdlib::ogg_int64_t, + pub serialnos: *mut libc::c_long, + pub pcmlengths: *mut crate::stdlib::ogg_int64_t, + pub vi: *mut crate::stdlib::vorbis_info, + pub vc: *mut crate::stdlib::vorbis_comment, + pub pcm_offset: crate::stdlib::ogg_int64_t, + pub ready_state: libc::c_int, + pub current_serialno: libc::c_long, + pub current_link: libc::c_int, + pub bittrack: libc::c_double, + pub samptrack: libc::c_double, + pub os: crate::stdlib::ogg_stream_state, + pub vd: crate::stdlib::vorbis_dsp_state, + pub vb: crate::stdlib::vorbis_block, + pub callbacks: crate::stdlib::ov_callbacks, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct ov_callbacks { + pub read_func: Option< + unsafe extern "C" fn( + _: *mut libc::c_void, + _: crate::stddef_h::size_t, + _: crate::stddef_h::size_t, + _: *mut libc::c_void, + ) -> crate::stddef_h::size_t, + >, + pub seek_func: Option< + unsafe extern "C" fn( + _: *mut libc::c_void, + _: crate::stdlib::ogg_int64_t, + _: libc::c_int, + ) -> libc::c_int, + >, + pub close_func: Option libc::c_int>, + pub tell_func: Option libc::c_long>, +} diff --git a/src/stream.rs b/src/stream.rs new file mode 100644 index 0000000..4919067 --- /dev/null +++ b/src/stream.rs @@ -0,0 +1,1128 @@ +use ::libc; + +pub use crate::stddef_h::size_t; +pub use crate::stdlib::__socklen_t; +pub use crate::stdlib::__ssize_t; +pub use crate::stdlib::__uint16_t; +pub use crate::stdlib::__uint32_t; +pub use crate::stdlib::__uint64_t; +pub use crate::stdlib::__uint8_t; +pub use crate::stdlib::__useconds_t; +pub use crate::stdlib::ssize_t; + +pub use crate::stdlib::__pthread_internal_list; +pub use crate::stdlib::__pthread_list_t; +pub use crate::stdlib::__pthread_mutex_s; +pub use crate::stdlib::__socket_type; +pub use crate::stdlib::close; +pub use crate::stdlib::pthread_attr_t; +pub use crate::stdlib::pthread_mutex_t; +pub use crate::stdlib::pthread_t; +pub use crate::stdlib::read; +pub use crate::stdlib::sa_family_t; +pub use crate::stdlib::socklen_t; +pub use crate::stdlib::u_int16_t; +pub use crate::stdlib::u_int32_t; +pub use crate::stdlib::u_int64_t; +pub use crate::stdlib::u_int8_t; +pub use crate::stdlib::uint16_t; +pub use crate::stdlib::uint32_t; +pub use crate::stdlib::usleep; +pub use crate::stdlib::SOCK_CLOEXEC; +pub use crate::stdlib::SOCK_DCCP; +pub use crate::stdlib::SOCK_DGRAM; +pub use crate::stdlib::SOCK_NONBLOCK; +pub use crate::stdlib::SOCK_PACKET; +pub use crate::stdlib::SOCK_RAW; +pub use crate::stdlib::SOCK_RDM; +pub use crate::stdlib::SOCK_SEQPACKET; +pub use crate::stdlib::SOCK_STREAM; + +pub use crate::squeezelite_h::buffer; +pub use crate::squeezelite_h::disconnect_code; +pub use crate::squeezelite_h::lDEBUG; +pub use crate::squeezelite_h::lERROR; +pub use crate::squeezelite_h::lINFO; +pub use crate::squeezelite_h::lSDEBUG; +pub use crate::squeezelite_h::lWARN; +pub use crate::squeezelite_h::log_level; +pub use crate::squeezelite_h::sockfd; +pub use crate::squeezelite_h::stream_state; +pub use crate::squeezelite_h::streamstate; +pub use crate::squeezelite_h::u16_t; +pub use crate::squeezelite_h::u32_t; +pub use crate::squeezelite_h::u64_t; +pub use crate::squeezelite_h::u8_t; +pub use crate::squeezelite_h::DISCONNECT; +pub use crate::squeezelite_h::DISCONNECT_OK; +pub use crate::squeezelite_h::LOCAL_DISCONNECT; +pub use crate::squeezelite_h::RECV_HEADERS; +pub use crate::squeezelite_h::REMOTE_DISCONNECT; +pub use crate::squeezelite_h::SEND_HEADERS; +pub use crate::squeezelite_h::STOPPED; +pub use crate::squeezelite_h::STREAMING_BUFFERING; +pub use crate::squeezelite_h::STREAMING_FILE; +pub use crate::squeezelite_h::STREAMING_HTTP; +pub use crate::squeezelite_h::STREAMING_WAIT; +pub use crate::squeezelite_h::TIMEOUT; +pub use crate::squeezelite_h::UNREACHABLE; +pub use crate::src::buffer::_buf_cont_write; +pub use crate::src::buffer::_buf_inc_writep; +pub use crate::src::buffer::_buf_space; +pub use crate::src::buffer::buf_destroy; +pub use crate::src::buffer::buf_flush; +pub use crate::src::buffer::buf_init; +pub use crate::src::slimproto::wake_controller; +pub use crate::src::utils::connect_timeout; +pub use crate::src::utils::logprint; +pub use crate::src::utils::logtime; +pub use crate::src::utils::set_nonblock; +pub use crate::src::utils::touch_memory; +use crate::stdlib::__errno_location; +use crate::stdlib::exit; +use crate::stdlib::free; +pub use crate::stdlib::in_addr; +pub use crate::stdlib::in_addr_t; +pub use crate::stdlib::in_port_t; +use crate::stdlib::inet_ntoa; +use crate::stdlib::malloc; +use crate::stdlib::memcpy; +use crate::stdlib::memset; +pub use crate::stdlib::nfds_t; +pub use crate::stdlib::ntohs; +use crate::stdlib::open; +pub use crate::stdlib::poll; +pub use crate::stdlib::pollfd; +use crate::stdlib::pthread_attr_destroy; +use crate::stdlib::pthread_attr_init; +use crate::stdlib::pthread_attr_setstacksize; +use crate::stdlib::pthread_create; +use crate::stdlib::pthread_join; +use crate::stdlib::pthread_mutex_lock; +use crate::stdlib::pthread_mutex_unlock; +use crate::stdlib::recv; +use crate::stdlib::send; +pub use crate::stdlib::sockaddr; +pub use crate::stdlib::sockaddr_in; +use crate::stdlib::socket; +use crate::stdlib::strerror; +pub use crate::stdlib::C2RustUnnamed_0; +pub use crate::stdlib::MSG_BATCH; +pub use crate::stdlib::MSG_CMSG_CLOEXEC; +pub use crate::stdlib::MSG_CONFIRM; +pub use crate::stdlib::MSG_CTRUNC; +pub use crate::stdlib::MSG_DONTROUTE; +pub use crate::stdlib::MSG_DONTWAIT; +pub use crate::stdlib::MSG_EOR; +pub use crate::stdlib::MSG_ERRQUEUE; +pub use crate::stdlib::MSG_FASTOPEN; +pub use crate::stdlib::MSG_FIN; +pub use crate::stdlib::MSG_MORE; +pub use crate::stdlib::MSG_NOSIGNAL; +pub use crate::stdlib::MSG_OOB; +pub use crate::stdlib::MSG_PEEK; +pub use crate::stdlib::MSG_PROXY; +pub use crate::stdlib::MSG_RST; +pub use crate::stdlib::MSG_SYN; +pub use crate::stdlib::MSG_TRUNC; +pub use crate::stdlib::MSG_TRYHARD; +pub use crate::stdlib::MSG_WAITALL; +pub use crate::stdlib::MSG_WAITFORONE; +pub use crate::stdlib::MSG_ZEROCOPY; +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +// stream thread + +static mut loglevel: crate::squeezelite_h::log_level = crate::squeezelite_h::lERROR; + +static mut buf: crate::squeezelite_h::buffer = crate::squeezelite_h::buffer { + buf: 0 as *const crate::squeezelite_h::u8_t as *mut crate::squeezelite_h::u8_t, + readp: 0 as *const crate::squeezelite_h::u8_t as *mut crate::squeezelite_h::u8_t, + writep: 0 as *const crate::squeezelite_h::u8_t as *mut crate::squeezelite_h::u8_t, + wrap: 0 as *const crate::squeezelite_h::u8_t as *mut crate::squeezelite_h::u8_t, + size: 0, + base_size: 0, + mutex: crate::stdlib::pthread_mutex_t { + __data: crate::stdlib::__pthread_mutex_s { + __lock: 0, + __count: 0, + __owner: 0, + __nusers: 0, + __kind: 0, + __spins: 0, + __elision: 0, + __list: crate::stdlib::__pthread_list_t { + __prev: 0 as *const crate::stdlib::__pthread_internal_list + as *mut crate::stdlib::__pthread_internal_list, + __next: 0 as *const crate::stdlib::__pthread_internal_list + as *mut crate::stdlib::__pthread_internal_list, + }, + }, + }, +}; +#[no_mangle] + +pub static mut streambuf: *mut crate::squeezelite_h::buffer = + unsafe { &buf as *const crate::squeezelite_h::buffer as *mut crate::squeezelite_h::buffer }; + +static mut fd: crate::squeezelite_h::sockfd = 0; +#[no_mangle] + +pub static mut stream: crate::squeezelite_h::streamstate = crate::squeezelite_h::streamstate { + state: crate::squeezelite_h::STOPPED, + disconnect: crate::squeezelite_h::DISCONNECT_OK, + header: 0 as *const libc::c_char as *mut libc::c_char, + header_len: 0, + sent_headers: false, + cont_wait: false, + bytes: 0, + threshold: 0, + meta_interval: 0, + meta_next: 0, + meta_left: 0, + meta_send: false, +}; + +unsafe extern "C" fn send_header() -> bool { + let mut ptr = stream.header; + let mut len = stream.header_len as libc::c_int; + let mut try_0 = 0 as libc::c_int as libc::c_uint; + let mut n: crate::stdlib::ssize_t = 0; + while len != 0 { + n = crate::stdlib::send( + fd, + ptr as *const libc::c_void, + len as crate::stddef_h::size_t, + crate::stdlib::MSG_NOSIGNAL as libc::c_int, + ); + if n <= 0 as libc::c_int as libc::c_long { + if n < 0 as libc::c_int as libc::c_long + && *crate::stdlib::__errno_location() == 11 as libc::c_int + && try_0 < 10 as libc::c_int as libc::c_uint + { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint + { + try_0 = try_0.wrapping_add(1); + crate::src::utils::logprint( + b"%s %s:%d retrying (%d) writing to socket\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>( + b"send_header\x00", + )) + .as_ptr(), + 114 as libc::c_int, + try_0, + ); + } + crate::stdlib::usleep(1000 as libc::c_int as crate::stdlib::__useconds_t); + } else { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d failed writing to socket: %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>( + b"send_header\x00", + )) + .as_ptr(), + 118 as libc::c_int, + crate::stdlib::strerror(*crate::stdlib::__errno_location()), + ); + } + stream.disconnect = crate::squeezelite_h::LOCAL_DISCONNECT; + stream.state = crate::squeezelite_h::DISCONNECT; + crate::src::slimproto::wake_controller(); + return 0 as libc::c_int != 0; + } + } else { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d wrote %d bytes to socket\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"send_header\x00")) + .as_ptr(), + 124 as libc::c_int, + n, + ); + } + ptr = ptr.offset(n as isize); + len = (len as libc::c_long - n) as libc::c_int + } + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d wrote header\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"send_header\x00")).as_ptr(), + 128 as libc::c_int, + ); + } + return 1 as libc::c_int != 0; +} + +static mut running: bool = 1 as libc::c_int != 0; + +unsafe extern "C" fn _disconnect( + mut state: crate::squeezelite_h::stream_state, + mut disconnect: crate::squeezelite_h::disconnect_code, +) { + stream.state = state; + stream.disconnect = disconnect; + crate::stdlib::close(fd); + fd = -(1 as libc::c_int); + crate::src::slimproto::wake_controller(); +} + +unsafe extern "C" fn stream_thread() -> *mut libc::c_void { + while running { + let mut pollinfo = crate::stdlib::pollfd { + fd: 0, + events: 0, + revents: 0, + }; + let mut space: crate::stddef_h::size_t = 0; + crate::stdlib::pthread_mutex_lock(&mut (*streambuf).mutex); + space = if crate::src::buffer::_buf_space(streambuf) + < crate::src::buffer::_buf_cont_write(streambuf) + { + crate::src::buffer::_buf_space(streambuf) + } else { + crate::src::buffer::_buf_cont_write(streambuf) + } as crate::stddef_h::size_t; + if fd < 0 as libc::c_int + || space == 0 + || stream.state as libc::c_uint + <= crate::squeezelite_h::STREAMING_WAIT as libc::c_int as libc::c_uint + { + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + crate::stdlib::usleep(100000 as libc::c_int as crate::stdlib::__useconds_t); + } else if stream.state as libc::c_uint + == crate::squeezelite_h::STREAMING_FILE as libc::c_int as libc::c_uint + { + let mut n = crate::stdlib::read(fd, (*streambuf).writep as *mut libc::c_void, space) + as libc::c_int; + if n == 0 as libc::c_int { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d end of stream\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"stream_thread\x00", + )) + .as_ptr(), + 170 as libc::c_int, + ); + } + _disconnect( + crate::squeezelite_h::DISCONNECT, + crate::squeezelite_h::DISCONNECT_OK, + ); + } + if n > 0 as libc::c_int { + crate::src::buffer::_buf_inc_writep(streambuf, n as libc::c_uint); + stream.bytes = (stream.bytes as libc::c_ulong).wrapping_add(n as libc::c_ulong) + as crate::squeezelite_h::u64_t + as crate::squeezelite_h::u64_t; + if loglevel as libc::c_uint + >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d streambuf read %d bytes\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"stream_thread\x00", + )) + .as_ptr(), + 176 as libc::c_int, + n, + ); + } + } + if n < 0 as libc::c_int { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d error reading: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"stream_thread\x00", + )) + .as_ptr(), + 179 as libc::c_int, + crate::stdlib::strerror(*crate::stdlib::__errno_location()), + ); + } + _disconnect( + crate::squeezelite_h::DISCONNECT, + crate::squeezelite_h::REMOTE_DISCONNECT, + ); + } + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + } else { + pollinfo.fd = fd; + pollinfo.events = 0x1 as libc::c_int as libc::c_short; + if stream.state as libc::c_uint + == crate::squeezelite_h::SEND_HEADERS as libc::c_int as libc::c_uint + { + pollinfo.events = + (pollinfo.events as libc::c_int | 0x4 as libc::c_int) as libc::c_short + } + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + if crate::stdlib::poll( + &mut pollinfo, + 1 as libc::c_int as crate::stdlib::nfds_t, + 100 as libc::c_int, + ) != 0 + { + crate::stdlib::pthread_mutex_lock(&mut (*streambuf).mutex); + // check socket has not been closed while in poll + if fd < 0 as libc::c_int { + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + } else if pollinfo.revents as libc::c_int & 0x4 as libc::c_int != 0 + && stream.state as libc::c_uint + == crate::squeezelite_h::SEND_HEADERS as libc::c_int as libc::c_uint + { + if send_header() { + stream.state = crate::squeezelite_h::RECV_HEADERS + } + stream.header_len = 0 as libc::c_int as crate::stddef_h::size_t; + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + } else { + if pollinfo.revents as libc::c_int & (0x1 as libc::c_int | 0x10 as libc::c_int) + != 0 + { + // get response headers + if stream.state as libc::c_uint + == crate::squeezelite_h::RECV_HEADERS as libc::c_int as libc::c_uint + { + // read one byte at a time to catch end of header + let mut c: libc::c_char = 0; + static mut endtok: libc::c_int = 0; + let mut n_0 = crate::stdlib::recv( + fd, + &mut c as *mut libc::c_char as *mut libc::c_void, + 1 as libc::c_int as crate::stddef_h::size_t, + 0 as libc::c_int, + ) as libc::c_int; + if n_0 <= 0 as libc::c_int { + if n_0 < 0 as libc::c_int + && *crate::stdlib::__errno_location() == 11 as libc::c_int + { + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + continue; + } else { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int + as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d error reading headers: %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::< + &[u8; 14], + &[libc::c_char; 14], + >( + b"stream_thread\x00" + )) + .as_ptr(), + 229 as libc::c_int, + if n_0 != 0 { + crate::stdlib::strerror( + *crate::stdlib::__errno_location(), + ) + as *const libc::c_char + } else { + b"closed\x00" as *const u8 as *const libc::c_char + }, + ); + } + _disconnect( + crate::squeezelite_h::STOPPED, + crate::squeezelite_h::LOCAL_DISCONNECT, + ); + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + continue; + } + } else { + *stream.header.offset(stream.header_len as isize) = c; + stream.header_len = stream.header_len.wrapping_add(1); + if stream.header_len + > (4096 as libc::c_int - 1 as libc::c_int) as libc::c_ulong + { + crate::src::utils::logprint( + b"%s %s:%d received headers too long: %u\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"stream_thread\x00", + )) + .as_ptr(), + 239 as libc::c_int, + stream.header_len, + ); + _disconnect( + crate::squeezelite_h::DISCONNECT, + crate::squeezelite_h::LOCAL_DISCONNECT, + ); + } + if stream.header_len > 1 as libc::c_int as libc::c_ulong + && (c as libc::c_int == '\r' as i32 + || c as libc::c_int == '\n' as i32) + { + endtok += 1; + if endtok == 4 as libc::c_int { + *stream.header.offset(stream.header_len as isize) = + '\u{0}' as i32 as libc::c_char; + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int + as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d headers: len: %d\n%s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::< + &[u8; 14], + &[libc::c_char; 14], + >( + b"stream_thread\x00" + )) + .as_ptr(), + 247 as libc::c_int, + stream.header_len, + stream.header, + ); + } + stream.state = if stream.cont_wait as libc::c_int != 0 { + crate::squeezelite_h::STREAMING_WAIT as libc::c_int + } else { + crate::squeezelite_h::STREAMING_BUFFERING as libc::c_int + } + as crate::squeezelite_h::stream_state; + crate::src::slimproto::wake_controller(); + } + } else { + endtok = 0 as libc::c_int + } + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + continue; + } + } else if stream.meta_interval != 0 + && stream.meta_next == 0 as libc::c_int as libc::c_uint + { + if stream.meta_left == 0 as libc::c_int as libc::c_uint { + // receive icy meta data + // read meta length + let mut c_0: crate::squeezelite_h::u8_t = 0; + let mut n_1 = crate::stdlib::recv( + fd, + &mut c_0 as *mut crate::squeezelite_h::u8_t + as *mut libc::c_void, + 1 as libc::c_int as crate::stddef_h::size_t, + 0 as libc::c_int, + ) as libc::c_int; + if n_1 <= 0 as libc::c_int { + if n_1 < 0 as libc::c_int + && *crate::stdlib::__errno_location() == 11 as libc::c_int + { + crate::stdlib::pthread_mutex_unlock( + &mut (*streambuf).mutex, + ); + continue; + } else { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int + as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d error reading icy meta: %s\n\x00" + as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::< + &[u8; 14], + &[libc::c_char; 14], + >( + b"stream_thread\x00" + )) + .as_ptr(), + 271 as libc::c_int, + if n_1 != 0 { + crate::stdlib::strerror( + *crate::stdlib::__errno_location(), + ) + as *const libc::c_char + } else { + b"closed\x00" as *const u8 + as *const libc::c_char + }, + ); + } + _disconnect( + crate::squeezelite_h::STOPPED, + crate::squeezelite_h::LOCAL_DISCONNECT, + ); + crate::stdlib::pthread_mutex_unlock( + &mut (*streambuf).mutex, + ); + continue; + } + } else { + stream.meta_left = (16 as libc::c_int * c_0 as libc::c_int) + as crate::squeezelite_h::u32_t; + stream.header_len = 0 as libc::c_int as crate::stddef_h::size_t + } + // amount of received meta data + // MAX_HEADER must be more than meta max of 16 * 255 + } + if stream.meta_left != 0 { + let mut n_2 = crate::stdlib::recv( + fd, + stream.header.offset(stream.header_len as isize) + as *mut libc::c_void, + stream.meta_left as crate::stddef_h::size_t, + 0 as libc::c_int, + ) as libc::c_int; + if n_2 <= 0 as libc::c_int { + if n_2 < 0 as libc::c_int + && *crate::stdlib::__errno_location() == 11 as libc::c_int + { + crate::stdlib::pthread_mutex_unlock( + &mut (*streambuf).mutex, + ); + continue; + } else { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int + as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d error reading icy meta: %s\n\x00" + as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::< + &[u8; 14], + &[libc::c_char; 14], + >( + b"stream_thread\x00" + )) + .as_ptr(), + 288 as libc::c_int, + if n_2 != 0 { + crate::stdlib::strerror( + *crate::stdlib::__errno_location(), + ) + as *const libc::c_char + } else { + b"closed\x00" as *const u8 + as *const libc::c_char + }, + ); + } + _disconnect( + crate::squeezelite_h::STOPPED, + crate::squeezelite_h::LOCAL_DISCONNECT, + ); + crate::stdlib::pthread_mutex_unlock( + &mut (*streambuf).mutex, + ); + continue; + } + } else { + stream.meta_left = (stream.meta_left as libc::c_uint) + .wrapping_sub(n_2 as libc::c_uint) + as crate::squeezelite_h::u32_t + as crate::squeezelite_h::u32_t; + stream.header_len = (stream.header_len as libc::c_ulong) + .wrapping_add(n_2 as libc::c_ulong) + as crate::stddef_h::size_t + as crate::stddef_h::size_t + } + } + if stream.meta_left == 0 as libc::c_int as libc::c_uint { + if stream.header_len != 0 { + *stream.header.offset(stream.header_len as isize) = + '\u{0}' as i32 as libc::c_char; + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int + as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d icy meta: len: %u\n%s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::< + &[u8; 14], + &[libc::c_char; 14], + >( + b"stream_thread\x00" + )) + .as_ptr(), + 300 as libc::c_int, + stream.header_len, + stream.header, + ); + } + stream.meta_send = 1 as libc::c_int != 0; + crate::src::slimproto::wake_controller(); + } + stream.meta_next = stream.meta_interval; + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + continue; + } + // stream body into streambuf + } else { + let mut n_3: libc::c_int = 0; + space = if crate::src::buffer::_buf_space(streambuf) + < crate::src::buffer::_buf_cont_write(streambuf) + { + crate::src::buffer::_buf_space(streambuf) + } else { + crate::src::buffer::_buf_cont_write(streambuf) + } as crate::stddef_h::size_t; + if stream.meta_interval != 0 { + space = if space < stream.meta_next as libc::c_ulong { + space + } else { + stream.meta_next as libc::c_ulong + } + } + n_3 = crate::stdlib::recv( + fd, + (*streambuf).writep as *mut libc::c_void, + space, + 0 as libc::c_int, + ) as libc::c_int; + if n_3 == 0 as libc::c_int { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d end of stream\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"stream_thread\x00", + )) + .as_ptr(), + 320 as libc::c_int, + ); + } + _disconnect( + crate::squeezelite_h::DISCONNECT, + crate::squeezelite_h::DISCONNECT_OK, + ); + } + if n_3 < 0 as libc::c_int + && *crate::stdlib::__errno_location() != 11 as libc::c_int + { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d error reading: %s\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"stream_thread\x00", + )) + .as_ptr(), + 324 as libc::c_int, + crate::stdlib::strerror(*crate::stdlib::__errno_location()), + ); + } + _disconnect( + crate::squeezelite_h::DISCONNECT, + crate::squeezelite_h::REMOTE_DISCONNECT, + ); + } + if n_3 > 0 as libc::c_int { + crate::src::buffer::_buf_inc_writep(streambuf, n_3 as libc::c_uint); + stream.bytes = (stream.bytes as libc::c_ulong) + .wrapping_add(n_3 as libc::c_ulong) + as crate::squeezelite_h::u64_t + as crate::squeezelite_h::u64_t; + if stream.meta_interval != 0 { + stream.meta_next = (stream.meta_next as libc::c_uint) + .wrapping_sub(n_3 as libc::c_uint) + as crate::squeezelite_h::u32_t + as crate::squeezelite_h::u32_t + } + if stream.state as libc::c_uint + == crate::squeezelite_h::STREAMING_BUFFERING as libc::c_int + as libc::c_uint + && stream.bytes > stream.threshold as libc::c_ulong + { + stream.state = crate::squeezelite_h::STREAMING_HTTP; + crate::src::slimproto::wake_controller(); + } + if loglevel as libc::c_uint + >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d streambuf read %d bytes\n\x00" as *const u8 + as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"stream_thread\x00", + )) + .as_ptr(), + 344 as libc::c_int, + n_3, + ); + } + } else { + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + continue; + } + } + } + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + } + } else if loglevel as libc::c_uint + >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d poll timeout\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"stream_thread\x00", + )) + .as_ptr(), + 352 as libc::c_int, + ); + } + } + } + return 0 as *mut libc::c_void; +} + +static mut thread: crate::stdlib::pthread_t = 0; +#[no_mangle] + +pub unsafe extern "C" fn stream_init( + mut level: crate::squeezelite_h::log_level, + mut stream_buf_size: libc::c_uint, +) { + loglevel = level; + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d init stream\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"stream_init\x00")).as_ptr(), + 370 as libc::c_int, + ); + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d streambuf size: %u\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"stream_init\x00")).as_ptr(), + 371 as libc::c_int, + stream_buf_size, + ); + } + crate::src::buffer::buf_init(streambuf, stream_buf_size as crate::stddef_h::size_t); + if (*streambuf).buf.is_null() { + crate::src::utils::logprint( + b"%s %s:%d unable to malloc buffer\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"stream_init\x00")).as_ptr(), + 375 as libc::c_int, + ); + crate::stdlib::exit(0 as libc::c_int); + } + stream.state = crate::squeezelite_h::STOPPED; + stream.header = + crate::stdlib::malloc(4096 as libc::c_int as libc::c_ulong) as *mut libc::c_char; + *stream.header = '\u{0}' as i32 as libc::c_char; + fd = -(1 as libc::c_int); + crate::src::utils::touch_memory((*streambuf).buf, (*streambuf).size); + let mut attr = crate::stdlib::pthread_attr_t { __size: [0; 56] }; + crate::stdlib::pthread_attr_init(&mut attr); + crate::stdlib::pthread_attr_setstacksize( + &mut attr, + (16384 as libc::c_int + 64 as libc::c_int * 1024 as libc::c_int) as crate::stddef_h::size_t, + ); + crate::stdlib::pthread_create( + &mut thread, + &mut attr, + ::std::mem::transmute::< + Option *mut libc::c_void>, + Option *mut libc::c_void>, + >(Some(::std::mem::transmute::< + unsafe extern "C" fn() -> *mut libc::c_void, + unsafe extern "C" fn() -> *mut libc::c_void, + >(stream_thread))), + 0 as *mut libc::c_void, + ); + crate::stdlib::pthread_attr_destroy(&mut attr); +} +#[no_mangle] + +pub unsafe extern "C" fn stream_close() { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d close stream\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"stream_close\x00")) + .as_ptr(), + 424 as libc::c_int, + ); + } + crate::stdlib::pthread_mutex_lock(&mut (*streambuf).mutex); + running = 0 as libc::c_int != 0; + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + crate::stdlib::pthread_join(thread, 0 as *mut *mut libc::c_void); + crate::stdlib::free(stream.header as *mut libc::c_void); + crate::src::buffer::buf_destroy(streambuf); +} +#[no_mangle] + +pub unsafe extern "C" fn stream_file( + mut header: *const libc::c_char, + mut header_len: crate::stddef_h::size_t, + mut threshold: libc::c_uint, +) { + crate::src::buffer::buf_flush(streambuf); + crate::stdlib::pthread_mutex_lock(&mut (*streambuf).mutex); + stream.header_len = header_len; + crate::stdlib::memcpy( + stream.header as *mut libc::c_void, + header as *const libc::c_void, + header_len, + ); + *stream.header.offset(header_len as isize) = '\u{0}' as i32 as libc::c_char; + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d opening local file: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"stream_file\x00")).as_ptr(), + 444 as libc::c_int, + stream.header, + ); + } + fd = crate::stdlib::open(stream.header, 0 as libc::c_int); + stream.state = crate::squeezelite_h::STREAMING_FILE; + if fd < 0 as libc::c_int { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d can\'t open file: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"stream_file\x00")) + .as_ptr(), + 454 as libc::c_int, + stream.header, + ); + } + stream.state = crate::squeezelite_h::DISCONNECT + } + crate::src::slimproto::wake_controller(); + stream.cont_wait = 0 as libc::c_int != 0; + stream.meta_interval = 0 as libc::c_int as crate::squeezelite_h::u32_t; + stream.meta_next = 0 as libc::c_int as crate::squeezelite_h::u32_t; + stream.meta_left = 0 as libc::c_int as crate::squeezelite_h::u32_t; + stream.meta_send = 0 as libc::c_int != 0; + stream.sent_headers = 0 as libc::c_int != 0; + stream.bytes = 0 as libc::c_int as crate::squeezelite_h::u64_t; + stream.threshold = threshold; + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); +} + +unsafe extern "C" fn _tcp_connect( + mut ip: crate::squeezelite_h::u32_t, + mut port: crate::squeezelite_h::u16_t, +) -> libc::c_int { + let mut addr = crate::stdlib::sockaddr_in { + sin_family: 0, + sin_port: 0, + sin_addr: crate::stdlib::in_addr { s_addr: 0 }, + sin_zero: [0; 8], + }; + let mut sock = crate::stdlib::socket( + 2 as libc::c_int, + crate::stdlib::SOCK_STREAM as libc::c_int, + 0 as libc::c_int, + ); + if sock < 0 as libc::c_int { + crate::src::utils::logprint( + b"%s %s:%d failed to create socket\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"_tcp_connect\x00")) + .as_ptr(), + 477 as libc::c_int, + ); + return -(1 as libc::c_int); + } + crate::stdlib::memset( + &mut addr as *mut crate::stdlib::sockaddr_in as *mut libc::c_void, + 0 as libc::c_int, + ::std::mem::size_of::() as libc::c_ulong, + ); + addr.sin_family = 2 as libc::c_int as crate::stdlib::sa_family_t; + addr.sin_addr.s_addr = ip; + addr.sin_port = port; + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d connecting to %s:%d\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"_tcp_connect\x00")) + .as_ptr(), + 486 as libc::c_int, + crate::stdlib::inet_ntoa(addr.sin_addr), + crate::stdlib::ntohs(addr.sin_port) as libc::c_int, + ); + } + crate::src::utils::set_nonblock(sock); + if crate::src::utils::connect_timeout( + sock, + &mut addr as *mut crate::stdlib::sockaddr_in as *mut crate::stdlib::sockaddr, + ::std::mem::size_of::() as libc::c_ulong + as crate::stdlib::socklen_t, + 10 as libc::c_int, + ) < 0 as libc::c_int + { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d unable to connect to server\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 13], &[libc::c_char; 13]>(b"_tcp_connect\x00")) + .as_ptr(), + 492 as libc::c_int, + ); + } + crate::stdlib::close(sock); + return -(1 as libc::c_int); + } + return sock; +} +#[no_mangle] + +pub unsafe extern "C" fn stream_sock( + mut ip: crate::squeezelite_h::u32_t, + mut port: crate::squeezelite_h::u16_t, + mut header: *const libc::c_char, + mut header_len: crate::stddef_h::size_t, + mut threshold: libc::c_uint, + mut cont_wait: bool, +) { + let mut sock = _tcp_connect(ip, port); + if sock < 0 as libc::c_int { + crate::stdlib::pthread_mutex_lock(&mut (*streambuf).mutex); + stream.state = crate::squeezelite_h::DISCONNECT; + stream.disconnect = crate::squeezelite_h::UNREACHABLE; + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + return; + } + crate::src::buffer::buf_flush(streambuf); + crate::stdlib::pthread_mutex_lock(&mut (*streambuf).mutex); + fd = sock; + stream.state = crate::squeezelite_h::SEND_HEADERS; + stream.cont_wait = cont_wait; + stream.meta_interval = 0 as libc::c_int as crate::squeezelite_h::u32_t; + stream.meta_next = 0 as libc::c_int as crate::squeezelite_h::u32_t; + stream.meta_left = 0 as libc::c_int as crate::squeezelite_h::u32_t; + stream.meta_send = 0 as libc::c_int != 0; + stream.header_len = header_len; + crate::stdlib::memcpy( + stream.header as *mut libc::c_void, + header as *const libc::c_void, + header_len, + ); + *stream.header.offset(header_len as isize) = '\u{0}' as i32 as libc::c_char; + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d header: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"stream_sock\x00")).as_ptr(), + 577 as libc::c_int, + stream.header, + ); + } + stream.sent_headers = 0 as libc::c_int != 0; + stream.bytes = 0 as libc::c_int as crate::squeezelite_h::u64_t; + stream.threshold = threshold; + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); +} +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Additions (c) Paul Hermann, 2015-2017 under the same license terms + * -Control of Raspberry pi GPIO for amplifier power + * -Launch script on power status change from LMS + */ +// make may define: PORTAUDIO, SELFPIPE, RESAMPLE, RESAMPLE_MP, VISEXPORT, GPIO, IR, DSD, LINKALL to influence build +// build detection +// dynamically loaded libraries at run time +// !LINKALL +// config options +// do not reduce as icy-meta max is 4080 +/* SUN */ +/* SUN */ +// printf/scanf formats for u64_t +// logging +// utils.c (non logging) +// buffer.c +// _* called with mutex locked +// slimproto.c +// stream.c +#[no_mangle] + +pub unsafe extern "C" fn stream_disconnect() -> bool { + let mut disc = 0 as libc::c_int != 0; + crate::stdlib::pthread_mutex_lock(&mut (*streambuf).mutex); + if fd != -(1 as libc::c_int) { + crate::stdlib::close(fd); + fd = -(1 as libc::c_int); + disc = 1 as libc::c_int != 0 + } + stream.state = crate::squeezelite_h::STOPPED; + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + return disc; +} diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..0d3cb97 --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,817 @@ +use ::c2rust_asm_casts; +use ::libc; + +pub use crate::internal::__builtin_va_list; +pub use crate::internal::__va_list_tag; +pub use crate::stdarg_h::va_list; +pub use crate::stddef_h::size_t; +use c2rust_asm_casts::AsmCastTrait; + +pub use crate::stdlib::_IO_codecvt; +pub use crate::stdlib::_IO_lock_t; +pub use crate::stdlib::_IO_marker; +pub use crate::stdlib::_IO_wide_data; +pub use crate::stdlib::__caddr_t; +pub use crate::stdlib::__clockid_t; +pub use crate::stdlib::__off64_t; +pub use crate::stdlib::__off_t; +pub use crate::stdlib::__socklen_t; +pub use crate::stdlib::__suseconds_t; +pub use crate::stdlib::__syscall_slong_t; +pub use crate::stdlib::__time_t; +pub use crate::stdlib::__uint16_t; +pub use crate::stdlib::__uint32_t; +pub use crate::stdlib::__uint64_t; +pub use crate::stdlib::__uint8_t; +pub use crate::stdlib::clockid_t; +pub use crate::stdlib::time_t; +pub use crate::stdlib::timespec; +pub use crate::stdlib::timeval; +pub use crate::stdlib::u_int16_t; +pub use crate::stdlib::u_int32_t; +pub use crate::stdlib::u_int8_t; +pub use crate::stdlib::FILE; +pub use crate::stdlib::_IO_FILE; + +pub use crate::stdlib::__fd_mask; +pub use crate::stdlib::__socket_type; +pub use crate::stdlib::close; +pub use crate::stdlib::fd_set; +pub use crate::stdlib::sa_family_t; +pub use crate::stdlib::select; +pub use crate::stdlib::sockaddr; +pub use crate::stdlib::socklen_t; +pub use crate::stdlib::sysconf; +pub use crate::stdlib::uint16_t; +pub use crate::stdlib::uint32_t; +pub use crate::stdlib::uint64_t; +pub use crate::stdlib::C2RustUnnamed_0; +pub use crate::stdlib::SOCK_CLOEXEC; +pub use crate::stdlib::SOCK_DCCP; +pub use crate::stdlib::SOCK_DGRAM; +pub use crate::stdlib::SOCK_NONBLOCK; +pub use crate::stdlib::SOCK_PACKET; +pub use crate::stdlib::SOCK_RAW; +pub use crate::stdlib::SOCK_RDM; +pub use crate::stdlib::SOCK_SEQPACKET; +pub use crate::stdlib::SOCK_STREAM; +pub use crate::stdlib::_SC_2_CHAR_TERM; +pub use crate::stdlib::_SC_2_C_BIND; +pub use crate::stdlib::_SC_2_C_DEV; +pub use crate::stdlib::_SC_2_C_VERSION; +pub use crate::stdlib::_SC_2_FORT_DEV; +pub use crate::stdlib::_SC_2_FORT_RUN; +pub use crate::stdlib::_SC_2_LOCALEDEF; +pub use crate::stdlib::_SC_2_PBS; +pub use crate::stdlib::_SC_2_PBS_ACCOUNTING; +pub use crate::stdlib::_SC_2_PBS_CHECKPOINT; +pub use crate::stdlib::_SC_2_PBS_LOCATE; +pub use crate::stdlib::_SC_2_PBS_MESSAGE; +pub use crate::stdlib::_SC_2_PBS_TRACK; +pub use crate::stdlib::_SC_2_SW_DEV; +pub use crate::stdlib::_SC_2_UPE; +pub use crate::stdlib::_SC_2_VERSION; +pub use crate::stdlib::_SC_ADVISORY_INFO; +pub use crate::stdlib::_SC_AIO_LISTIO_MAX; +pub use crate::stdlib::_SC_AIO_MAX; +pub use crate::stdlib::_SC_AIO_PRIO_DELTA_MAX; +pub use crate::stdlib::_SC_ARG_MAX; +pub use crate::stdlib::_SC_ASYNCHRONOUS_IO; +pub use crate::stdlib::_SC_ATEXIT_MAX; +pub use crate::stdlib::_SC_AVPHYS_PAGES; +pub use crate::stdlib::_SC_BARRIERS; +pub use crate::stdlib::_SC_BASE; +pub use crate::stdlib::_SC_BC_BASE_MAX; +pub use crate::stdlib::_SC_BC_DIM_MAX; +pub use crate::stdlib::_SC_BC_SCALE_MAX; +pub use crate::stdlib::_SC_BC_STRING_MAX; +pub use crate::stdlib::_SC_CHARCLASS_NAME_MAX; +pub use crate::stdlib::_SC_CHAR_BIT; +pub use crate::stdlib::_SC_CHAR_MAX; +pub use crate::stdlib::_SC_CHAR_MIN; +pub use crate::stdlib::_SC_CHILD_MAX; +pub use crate::stdlib::_SC_CLK_TCK; +pub use crate::stdlib::_SC_CLOCK_SELECTION; +pub use crate::stdlib::_SC_COLL_WEIGHTS_MAX; +pub use crate::stdlib::_SC_CPUTIME; +pub use crate::stdlib::_SC_C_LANG_SUPPORT; +pub use crate::stdlib::_SC_C_LANG_SUPPORT_R; +pub use crate::stdlib::_SC_DELAYTIMER_MAX; +pub use crate::stdlib::_SC_DEVICE_IO; +pub use crate::stdlib::_SC_DEVICE_SPECIFIC; +pub use crate::stdlib::_SC_DEVICE_SPECIFIC_R; +pub use crate::stdlib::_SC_EQUIV_CLASS_MAX; +pub use crate::stdlib::_SC_EXPR_NEST_MAX; +pub use crate::stdlib::_SC_FD_MGMT; +pub use crate::stdlib::_SC_FIFO; +pub use crate::stdlib::_SC_FILE_ATTRIBUTES; +pub use crate::stdlib::_SC_FILE_LOCKING; +pub use crate::stdlib::_SC_FILE_SYSTEM; +pub use crate::stdlib::_SC_FSYNC; +pub use crate::stdlib::_SC_GETGR_R_SIZE_MAX; +pub use crate::stdlib::_SC_GETPW_R_SIZE_MAX; +pub use crate::stdlib::_SC_HOST_NAME_MAX; +pub use crate::stdlib::_SC_INT_MAX; +pub use crate::stdlib::_SC_INT_MIN; +pub use crate::stdlib::_SC_IOV_MAX; +pub use crate::stdlib::_SC_IPV6; +pub use crate::stdlib::_SC_JOB_CONTROL; +pub use crate::stdlib::_SC_LEVEL1_DCACHE_ASSOC; +pub use crate::stdlib::_SC_LEVEL1_DCACHE_LINESIZE; +pub use crate::stdlib::_SC_LEVEL1_DCACHE_SIZE; +pub use crate::stdlib::_SC_LEVEL1_ICACHE_ASSOC; +pub use crate::stdlib::_SC_LEVEL1_ICACHE_LINESIZE; +pub use crate::stdlib::_SC_LEVEL1_ICACHE_SIZE; +pub use crate::stdlib::_SC_LEVEL2_CACHE_ASSOC; +pub use crate::stdlib::_SC_LEVEL2_CACHE_LINESIZE; +pub use crate::stdlib::_SC_LEVEL2_CACHE_SIZE; +pub use crate::stdlib::_SC_LEVEL3_CACHE_ASSOC; +pub use crate::stdlib::_SC_LEVEL3_CACHE_LINESIZE; +pub use crate::stdlib::_SC_LEVEL3_CACHE_SIZE; +pub use crate::stdlib::_SC_LEVEL4_CACHE_ASSOC; +pub use crate::stdlib::_SC_LEVEL4_CACHE_LINESIZE; +pub use crate::stdlib::_SC_LEVEL4_CACHE_SIZE; +pub use crate::stdlib::_SC_LINE_MAX; +pub use crate::stdlib::_SC_LOGIN_NAME_MAX; +pub use crate::stdlib::_SC_LONG_BIT; +pub use crate::stdlib::_SC_MAPPED_FILES; +pub use crate::stdlib::_SC_MB_LEN_MAX; +pub use crate::stdlib::_SC_MEMLOCK; +pub use crate::stdlib::_SC_MEMLOCK_RANGE; +pub use crate::stdlib::_SC_MEMORY_PROTECTION; +pub use crate::stdlib::_SC_MESSAGE_PASSING; +pub use crate::stdlib::_SC_MONOTONIC_CLOCK; +pub use crate::stdlib::_SC_MQ_OPEN_MAX; +pub use crate::stdlib::_SC_MQ_PRIO_MAX; +pub use crate::stdlib::_SC_MULTI_PROCESS; +pub use crate::stdlib::_SC_NETWORKING; +pub use crate::stdlib::_SC_NGROUPS_MAX; +pub use crate::stdlib::_SC_NL_ARGMAX; +pub use crate::stdlib::_SC_NL_LANGMAX; +pub use crate::stdlib::_SC_NL_MSGMAX; +pub use crate::stdlib::_SC_NL_NMAX; +pub use crate::stdlib::_SC_NL_SETMAX; +pub use crate::stdlib::_SC_NL_TEXTMAX; +pub use crate::stdlib::_SC_NPROCESSORS_CONF; +pub use crate::stdlib::_SC_NPROCESSORS_ONLN; +pub use crate::stdlib::_SC_NZERO; +pub use crate::stdlib::_SC_OPEN_MAX; +pub use crate::stdlib::_SC_PAGESIZE; +pub use crate::stdlib::_SC_PASS_MAX; +pub use crate::stdlib::_SC_PHYS_PAGES; +pub use crate::stdlib::_SC_PII; +pub use crate::stdlib::_SC_PII_INTERNET; +pub use crate::stdlib::_SC_PII_INTERNET_DGRAM; +pub use crate::stdlib::_SC_PII_INTERNET_STREAM; +pub use crate::stdlib::_SC_PII_OSI; +pub use crate::stdlib::_SC_PII_OSI_CLTS; +pub use crate::stdlib::_SC_PII_OSI_COTS; +pub use crate::stdlib::_SC_PII_OSI_M; +pub use crate::stdlib::_SC_PII_SOCKET; +pub use crate::stdlib::_SC_PII_XTI; +pub use crate::stdlib::_SC_PIPE; +pub use crate::stdlib::_SC_POLL; +pub use crate::stdlib::_SC_PRIORITIZED_IO; +pub use crate::stdlib::_SC_PRIORITY_SCHEDULING; +pub use crate::stdlib::_SC_RAW_SOCKETS; +pub use crate::stdlib::_SC_READER_WRITER_LOCKS; +pub use crate::stdlib::_SC_REALTIME_SIGNALS; +pub use crate::stdlib::_SC_REGEXP; +pub use crate::stdlib::_SC_REGEX_VERSION; +pub use crate::stdlib::_SC_RE_DUP_MAX; +pub use crate::stdlib::_SC_RTSIG_MAX; +pub use crate::stdlib::_SC_SAVED_IDS; +pub use crate::stdlib::_SC_SCHAR_MAX; +pub use crate::stdlib::_SC_SCHAR_MIN; +pub use crate::stdlib::_SC_SELECT; +pub use crate::stdlib::_SC_SEMAPHORES; +pub use crate::stdlib::_SC_SEM_NSEMS_MAX; +pub use crate::stdlib::_SC_SEM_VALUE_MAX; +pub use crate::stdlib::_SC_SHARED_MEMORY_OBJECTS; +pub use crate::stdlib::_SC_SHELL; +pub use crate::stdlib::_SC_SHRT_MAX; +pub use crate::stdlib::_SC_SHRT_MIN; +pub use crate::stdlib::_SC_SIGNALS; +pub use crate::stdlib::_SC_SIGQUEUE_MAX; +pub use crate::stdlib::_SC_SINGLE_PROCESS; +pub use crate::stdlib::_SC_SPAWN; +pub use crate::stdlib::_SC_SPIN_LOCKS; +pub use crate::stdlib::_SC_SPORADIC_SERVER; +pub use crate::stdlib::_SC_SSIZE_MAX; +pub use crate::stdlib::_SC_SS_REPL_MAX; +pub use crate::stdlib::_SC_STREAMS; +pub use crate::stdlib::_SC_STREAM_MAX; +pub use crate::stdlib::_SC_SYMLOOP_MAX; +pub use crate::stdlib::_SC_SYNCHRONIZED_IO; +pub use crate::stdlib::_SC_SYSTEM_DATABASE; +pub use crate::stdlib::_SC_SYSTEM_DATABASE_R; +pub use crate::stdlib::_SC_THREADS; +pub use crate::stdlib::_SC_THREAD_ATTR_STACKADDR; +pub use crate::stdlib::_SC_THREAD_ATTR_STACKSIZE; +pub use crate::stdlib::_SC_THREAD_CPUTIME; +pub use crate::stdlib::_SC_THREAD_DESTRUCTOR_ITERATIONS; +pub use crate::stdlib::_SC_THREAD_KEYS_MAX; +pub use crate::stdlib::_SC_THREAD_PRIORITY_SCHEDULING; +pub use crate::stdlib::_SC_THREAD_PRIO_INHERIT; +pub use crate::stdlib::_SC_THREAD_PRIO_PROTECT; +pub use crate::stdlib::_SC_THREAD_PROCESS_SHARED; +pub use crate::stdlib::_SC_THREAD_ROBUST_PRIO_INHERIT; +pub use crate::stdlib::_SC_THREAD_ROBUST_PRIO_PROTECT; +pub use crate::stdlib::_SC_THREAD_SAFE_FUNCTIONS; +pub use crate::stdlib::_SC_THREAD_SPORADIC_SERVER; +pub use crate::stdlib::_SC_THREAD_STACK_MIN; +pub use crate::stdlib::_SC_THREAD_THREADS_MAX; +pub use crate::stdlib::_SC_TIMEOUTS; +pub use crate::stdlib::_SC_TIMERS; +pub use crate::stdlib::_SC_TIMER_MAX; +pub use crate::stdlib::_SC_TRACE; +pub use crate::stdlib::_SC_TRACE_EVENT_FILTER; +pub use crate::stdlib::_SC_TRACE_EVENT_NAME_MAX; +pub use crate::stdlib::_SC_TRACE_INHERIT; +pub use crate::stdlib::_SC_TRACE_LOG; +pub use crate::stdlib::_SC_TRACE_NAME_MAX; +pub use crate::stdlib::_SC_TRACE_SYS_MAX; +pub use crate::stdlib::_SC_TRACE_USER_EVENT_MAX; +pub use crate::stdlib::_SC_TTY_NAME_MAX; +pub use crate::stdlib::_SC_TYPED_MEMORY_OBJECTS; +pub use crate::stdlib::_SC_TZNAME_MAX; +pub use crate::stdlib::_SC_T_IOV_MAX; +pub use crate::stdlib::_SC_UCHAR_MAX; +pub use crate::stdlib::_SC_UINT_MAX; +pub use crate::stdlib::_SC_UIO_MAXIOV; +pub use crate::stdlib::_SC_ULONG_MAX; +pub use crate::stdlib::_SC_USER_GROUPS; +pub use crate::stdlib::_SC_USER_GROUPS_R; +pub use crate::stdlib::_SC_USHRT_MAX; +pub use crate::stdlib::_SC_V6_ILP32_OFF32; +pub use crate::stdlib::_SC_V6_ILP32_OFFBIG; +pub use crate::stdlib::_SC_V6_LP64_OFF64; +pub use crate::stdlib::_SC_V6_LPBIG_OFFBIG; +pub use crate::stdlib::_SC_V7_ILP32_OFF32; +pub use crate::stdlib::_SC_V7_ILP32_OFFBIG; +pub use crate::stdlib::_SC_V7_LP64_OFF64; +pub use crate::stdlib::_SC_V7_LPBIG_OFFBIG; +pub use crate::stdlib::_SC_VERSION; +pub use crate::stdlib::_SC_WORD_BIT; +pub use crate::stdlib::_SC_XBS5_ILP32_OFF32; +pub use crate::stdlib::_SC_XBS5_ILP32_OFFBIG; +pub use crate::stdlib::_SC_XBS5_LP64_OFF64; +pub use crate::stdlib::_SC_XBS5_LPBIG_OFFBIG; +pub use crate::stdlib::_SC_XOPEN_CRYPT; +pub use crate::stdlib::_SC_XOPEN_ENH_I18N; +pub use crate::stdlib::_SC_XOPEN_LEGACY; +pub use crate::stdlib::_SC_XOPEN_REALTIME; +pub use crate::stdlib::_SC_XOPEN_REALTIME_THREADS; +pub use crate::stdlib::_SC_XOPEN_SHM; +pub use crate::stdlib::_SC_XOPEN_STREAMS; +pub use crate::stdlib::_SC_XOPEN_UNIX; +pub use crate::stdlib::_SC_XOPEN_VERSION; +pub use crate::stdlib::_SC_XOPEN_XCU_VERSION; +pub use crate::stdlib::_SC_XOPEN_XPG2; +pub use crate::stdlib::_SC_XOPEN_XPG3; +pub use crate::stdlib::_SC_XOPEN_XPG4; + +pub use crate::stdlib::__timezone_ptr_t; +pub use crate::stdlib::gettimeofday; +pub use crate::stdlib::in_addr; +pub use crate::stdlib::in_addr_t; +pub use crate::stdlib::in_port_t; +pub use crate::stdlib::nfds_t; +pub use crate::stdlib::poll; +pub use crate::stdlib::pollfd; +pub use crate::stdlib::sockaddr_in; +pub use crate::stdlib::timezone; +pub use crate::stdlib::tm; + +pub use crate::squeezelite_h::event_type; +pub use crate::squeezelite_h::sockfd; +pub use crate::squeezelite_h::u16_t; +pub use crate::squeezelite_h::u32_t; +pub use crate::squeezelite_h::u8_t; +pub use crate::squeezelite_h::EVENT_READ; +pub use crate::squeezelite_h::EVENT_TIMEOUT; +pub use crate::squeezelite_h::EVENT_WAKE; +use crate::stdlib::__errno_location; +pub use crate::stdlib::addrinfo; +use crate::stdlib::atoi; +pub use crate::stdlib::eventfd_read; +pub use crate::stdlib::eventfd_t; +use crate::stdlib::fflush; +pub use crate::stdlib::freeaddrinfo; +pub use crate::stdlib::getaddrinfo; +use crate::stdlib::getenv; +pub use crate::stdlib::ifconf; +pub use crate::stdlib::ifmap; +pub use crate::stdlib::ifreq; +use crate::stdlib::memcpy; +use crate::stdlib::memset; +use crate::stdlib::sprintf; +use crate::stdlib::sscanf; +use crate::stdlib::stderr; +use crate::stdlib::strchr; +use crate::stdlib::strlen; +use crate::stdlib::strncpy; +use crate::stdlib::strtok; +use crate::stdlib::vfprintf; +pub use crate::stdlib::C2RustUnnamed_20; +pub use crate::stdlib::C2RustUnnamed_21; +pub use crate::stdlib::C2RustUnnamed_22; + +use crate::stdlib::clock_gettime; +use crate::stdlib::connect; +use crate::stdlib::fcntl; +use crate::stdlib::getsockopt; +use crate::stdlib::ioctl; +use crate::stdlib::localtime; +use crate::stdlib::socket; +use crate::stdlib::strftime; +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +// logging functions +#[no_mangle] + +pub unsafe extern "C" fn logtime() -> *const libc::c_char { + static mut buf: [libc::c_char; 100] = [0; 100]; + let mut tv = crate::stdlib::timeval { + tv_sec: 0, + tv_usec: 0, + }; + crate::stdlib::gettimeofday(&mut tv, 0 as *mut crate::stdlib::timezone); + crate::stdlib::strftime( + buf.as_mut_ptr(), + ::std::mem::size_of::<[libc::c_char; 100]>() as libc::c_ulong, + b"[%T.\x00" as *const u8 as *const libc::c_char, + crate::stdlib::localtime(&mut tv.tv_sec), + ); + crate::stdlib::sprintf( + buf.as_mut_ptr() + .offset(crate::stdlib::strlen(buf.as_mut_ptr()) as isize), + b"%06ld]\x00" as *const u8 as *const libc::c_char, + tv.tv_usec, + ); + return buf.as_mut_ptr(); +} +#[no_mangle] + +pub unsafe extern "C" fn logprint(mut fmt: *const libc::c_char, mut args: ...) { + let mut args_0: ::std::ffi::VaListImpl; + args_0 = args.clone(); + crate::stdlib::vfprintf(crate::stdlib::stderr, fmt, args_0.as_va_list()); + crate::stdlib::fflush(crate::stdlib::stderr); +} +// cmdline parsing +#[no_mangle] + +pub unsafe extern "C" fn next_param( + mut src: *mut libc::c_char, + mut c: libc::c_char, +) -> *mut libc::c_char { + static mut str: *mut libc::c_char = 0 as *const libc::c_char as *mut libc::c_char; + let mut ptr = 0 as *mut libc::c_char; + let mut ret = 0 as *mut libc::c_char; + if !src.is_null() { + str = src + } + if !str.is_null() && { + ptr = crate::stdlib::strchr(str, c as libc::c_int); + !ptr.is_null() + } { + ret = str; + *ptr = '\u{0}' as i32 as libc::c_char; + str = ptr.offset(1 as libc::c_int as isize) + } else { + ret = str; + str = 0 as *mut libc::c_char + } + return if !ret.is_null() && *ret.offset(0 as libc::c_int as isize) as libc::c_int != 0 { + ret + } else { + 0 as *mut libc::c_char + }; +} +// clock +#[no_mangle] + +pub unsafe extern "C" fn gettime_ms() -> crate::squeezelite_h::u32_t { + let mut ts = crate::stdlib::timespec { + tv_sec: 0, + tv_nsec: 0, + }; + if crate::stdlib::clock_gettime(1 as libc::c_int, &mut ts) == 0 { + return (ts.tv_sec * 1000 as libc::c_int as libc::c_long + + ts.tv_nsec / 1000000 as libc::c_int as libc::c_long) + as crate::squeezelite_h::u32_t; + } + let mut tv = crate::stdlib::timeval { + tv_sec: 0, + tv_usec: 0, + }; + crate::stdlib::gettimeofday(&mut tv, 0 as *mut crate::stdlib::timezone); + return (tv.tv_sec * 1000 as libc::c_int as libc::c_long + + tv.tv_usec / 1000 as libc::c_int as libc::c_long) + as crate::squeezelite_h::u32_t; +} +// mac address +// search first 4 interfaces returned by IFCONF +#[no_mangle] + +pub unsafe extern "C" fn get_mac(mut mac: *mut crate::squeezelite_h::u8_t) { + let mut utmac = 0 as *mut libc::c_char; + let mut ifc = crate::stdlib::ifconf { + ifc_len: 0, + ifc_ifcu: crate::stdlib::C2RustUnnamed_22 { + ifcu_buf: 0 as *mut libc::c_char, + }, + }; + let mut ifr = 0 as *mut crate::stdlib::ifreq; + let mut ifend = 0 as *mut crate::stdlib::ifreq; + let mut ifreq = crate::stdlib::ifreq { + ifr_ifrn: crate::stdlib::C2RustUnnamed_21 { ifrn_name: [0; 16] }, + ifr_ifru: crate::stdlib::C2RustUnnamed_20 { + ifru_addr: crate::stdlib::sockaddr { + sa_family: 0, + sa_data: [0; 14], + }, + }, + }; + let mut ifs: [crate::stdlib::ifreq; 4] = [crate::stdlib::ifreq { + ifr_ifrn: crate::stdlib::C2RustUnnamed_21 { ifrn_name: [0; 16] }, + ifr_ifru: crate::stdlib::C2RustUnnamed_20 { + ifru_addr: crate::stdlib::sockaddr { + sa_family: 0, + sa_data: [0; 14], + }, + }, + }; 4]; + utmac = crate::stdlib::getenv(b"UTMAC\x00" as *const u8 as *const libc::c_char); + if !utmac.is_null() { + if crate::stdlib::strlen(utmac) == 17 as libc::c_int as libc::c_ulong { + if crate::stdlib::sscanf( + utmac, + b"%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx\x00" as *const u8 as *const libc::c_char, + &mut *mac.offset(0 as libc::c_int as isize) as *mut crate::squeezelite_h::u8_t, + &mut *mac.offset(1 as libc::c_int as isize) as *mut crate::squeezelite_h::u8_t, + &mut *mac.offset(2 as libc::c_int as isize) as *mut crate::squeezelite_h::u8_t, + &mut *mac.offset(3 as libc::c_int as isize) as *mut crate::squeezelite_h::u8_t, + &mut *mac.offset(4 as libc::c_int as isize) as *mut crate::squeezelite_h::u8_t, + &mut *mac.offset(5 as libc::c_int as isize) as *mut crate::squeezelite_h::u8_t, + ) == 6 as libc::c_int + { + return; + } + } + } + let ref mut fresh0 = *mac.offset(5 as libc::c_int as isize); + *fresh0 = 0 as libc::c_int as crate::squeezelite_h::u8_t; + let ref mut fresh1 = *mac.offset(4 as libc::c_int as isize); + *fresh1 = *fresh0; + let ref mut fresh2 = *mac.offset(3 as libc::c_int as isize); + *fresh2 = *fresh1; + let ref mut fresh3 = *mac.offset(2 as libc::c_int as isize); + *fresh3 = *fresh2; + let ref mut fresh4 = *mac.offset(1 as libc::c_int as isize); + *fresh4 = *fresh3; + *mac.offset(0 as libc::c_int as isize) = *fresh4; + let mut s = crate::stdlib::socket( + 2 as libc::c_int, + crate::stdlib::SOCK_DGRAM as libc::c_int, + 0 as libc::c_int, + ); + ifc.ifc_len = + ::std::mem::size_of::<[crate::stdlib::ifreq; 4]>() as libc::c_ulong as libc::c_int; + ifc.ifc_ifcu.ifcu_req = ifs.as_mut_ptr(); + if crate::stdlib::ioctl( + s, + 0x8912 as libc::c_int as libc::c_ulong, + &mut ifc as *mut crate::stdlib::ifconf, + ) == 0 as libc::c_int + { + ifend = ifs.as_mut_ptr().offset( + (ifc.ifc_len as libc::c_ulong) + .wrapping_div(::std::mem::size_of::() as libc::c_ulong) + as isize, + ); + ifr = ifc.ifc_ifcu.ifcu_req; + while ifr < ifend { + if (*ifr).ifr_ifru.ifru_addr.sa_family as libc::c_int == 2 as libc::c_int { + crate::stdlib::strncpy( + ifreq.ifr_ifrn.ifrn_name.as_mut_ptr(), + (*ifr).ifr_ifrn.ifrn_name.as_mut_ptr(), + (::std::mem::size_of::<[libc::c_char; 16]>() as libc::c_ulong) + .wrapping_sub(1 as libc::c_int as libc::c_ulong), + ); + if crate::stdlib::ioctl( + s, + 0x8927 as libc::c_int as libc::c_ulong, + &mut ifreq as *mut crate::stdlib::ifreq, + ) == 0 as libc::c_int + { + crate::stdlib::memcpy( + mac as *mut libc::c_void, + ifreq.ifr_ifru.ifru_hwaddr.sa_data.as_mut_ptr() as *const libc::c_void, + 6 as libc::c_int as libc::c_ulong, + ); + if *mac.offset(0 as libc::c_int as isize) as libc::c_int + + *mac.offset(1 as libc::c_int as isize) as libc::c_int + + *mac.offset(2 as libc::c_int as isize) as libc::c_int + != 0 as libc::c_int + { + break; + } + } + } + ifr = ifr.offset(1) + } + } + crate::stdlib::close(s); +} +#[no_mangle] + +pub unsafe extern "C" fn set_nonblock(mut s: crate::squeezelite_h::sockfd) { + let mut flags = crate::stdlib::fcntl(s, 3 as libc::c_int, 0 as libc::c_int); + crate::stdlib::fcntl(s, 4 as libc::c_int, flags | 0o4000 as libc::c_int); +} +// connect for socket already set to non blocking with timeout in seconds +#[no_mangle] + +pub unsafe extern "C" fn connect_timeout( + mut sock: crate::squeezelite_h::sockfd, + mut addr: *const crate::stdlib::sockaddr, + mut addrlen: crate::stdlib::socklen_t, + mut timeout: libc::c_int, +) -> libc::c_int { + let mut w = crate::stdlib::fd_set { + __fds_bits: [0; 16], + }; + let mut e = crate::stdlib::fd_set { + __fds_bits: [0; 16], + }; + let mut tval = crate::stdlib::timeval { + tv_sec: 0, + tv_usec: 0, + }; + if crate::stdlib::connect(sock, addr, addrlen) < 0 as libc::c_int { + if *crate::stdlib::__errno_location() != 115 as libc::c_int { + return -(1 as libc::c_int); + } + } + let mut __d0: libc::c_int = 0; + let mut __d1: libc::c_int = 0; + let fresh5 = &mut __d0; + let fresh6; + let fresh7 = &mut __d1; + let fresh8; + let fresh9 = (::std::mem::size_of::() as libc::c_ulong) + .wrapping_div(::std::mem::size_of::() as libc::c_ulong); + let fresh10 = &mut *w.__fds_bits.as_mut_ptr().offset(0 as libc::c_int as isize) + as *mut crate::stdlib::__fd_mask; + asm!("cld; rep; stosq" : "={cx}" (fresh6), "={di}" (fresh8) : "{ax}" + (0 as libc::c_int), "0" + (c2rust_asm_casts::AsmCast::cast_in(fresh5, fresh9)), "1" + (c2rust_asm_casts::AsmCast::cast_in(fresh7, fresh10)) : "memory" : + "volatile"); + c2rust_asm_casts::AsmCast::cast_out(fresh5, fresh9, fresh6); + c2rust_asm_casts::AsmCast::cast_out(fresh7, fresh10, fresh8); + w.__fds_bits[(sock + / (8 as libc::c_int + * ::std::mem::size_of::() as libc::c_ulong as libc::c_int)) + as usize] |= ((1 as libc::c_ulong) + << sock + % (8 as libc::c_int + * ::std::mem::size_of::() as libc::c_ulong + as libc::c_int)) as crate::stdlib::__fd_mask; + e = w; + tval.tv_sec = timeout as crate::stdlib::__time_t; + tval.tv_usec = 0 as libc::c_int as crate::stdlib::__suseconds_t; + // only return 0 if w set and sock error is zero, otherwise return error code + if crate::stdlib::select( + sock + 1 as libc::c_int, + 0 as *mut crate::stdlib::fd_set, + &mut w, + &mut e, + (if timeout != 0 { + &mut tval + } else { + 0 as *mut crate::stdlib::timeval + }), + ) == 1 as libc::c_int + && w.__fds_bits[(sock + / (8 as libc::c_int + * ::std::mem::size_of::() as libc::c_ulong + as libc::c_int)) as usize] + & ((1 as libc::c_ulong) + << sock + % (8 as libc::c_int + * ::std::mem::size_of::() as libc::c_ulong + as libc::c_int)) as crate::stdlib::__fd_mask + != 0 as libc::c_int as libc::c_long + { + let mut error = 0 as libc::c_int; + let mut len = + ::std::mem::size_of::() as libc::c_ulong as crate::stdlib::socklen_t; + crate::stdlib::getsockopt( + sock, + 1 as libc::c_int, + 4 as libc::c_int, + &mut error as *mut libc::c_int as *mut libc::c_void, + &mut len, + ); + return error; + } + return -(1 as libc::c_int); +} +#[no_mangle] + +pub unsafe extern "C" fn server_addr( + mut server: *mut libc::c_char, + mut ip_ptr: *mut crate::stdlib::in_addr_t, + mut port_ptr: *mut libc::c_uint, +) { + let mut res = 0 as *mut crate::stdlib::addrinfo; + let mut hints = crate::stdlib::addrinfo { + ai_flags: 0, + ai_family: 0, + ai_socktype: 0, + ai_protocol: 0, + ai_addrlen: 0, + ai_addr: 0 as *mut crate::stdlib::sockaddr, + ai_canonname: 0 as *mut libc::c_char, + ai_next: 0 as *mut crate::stdlib::addrinfo, + }; + let mut port = 0 as *const libc::c_char; + if !crate::stdlib::strtok(server, b":\x00" as *const u8 as *const libc::c_char).is_null() { + port = crate::stdlib::strtok( + 0 as *mut libc::c_char, + b":\x00" as *const u8 as *const libc::c_char, + ); + if !port.is_null() { + *port_ptr = crate::stdlib::atoi(port) as libc::c_uint + } + } + crate::stdlib::memset( + &mut hints as *mut crate::stdlib::addrinfo as *mut libc::c_void, + 0 as libc::c_int, + ::std::mem::size_of::() as libc::c_ulong, + ); + hints.ai_family = 2 as libc::c_int; + crate::stdlib::getaddrinfo(server, 0 as *const libc::c_char, &mut hints, &mut res); + if !res.is_null() && !(*res).ai_addr.is_null() { + *ip_ptr = (*((*res).ai_addr as *mut crate::stdlib::sockaddr_in)) + .sin_addr + .s_addr + } + if !res.is_null() { + crate::stdlib::freeaddrinfo(res); + }; +} +#[no_mangle] + +pub unsafe extern "C" fn set_readwake_handles( + mut handles: *mut crate::stdlib::pollfd, + mut s: crate::squeezelite_h::sockfd, + mut e: libc::c_int, +) { + (*handles.offset(0 as libc::c_int as isize)).fd = s; + (*handles.offset(1 as libc::c_int as isize)).fd = e; + (*handles.offset(0 as libc::c_int as isize)).events = 0x1 as libc::c_int as libc::c_short; + (*handles.offset(1 as libc::c_int as isize)).events = 0x1 as libc::c_int as libc::c_short; +} +#[no_mangle] + +pub unsafe extern "C" fn wait_readwake( + mut handles: *mut crate::stdlib::pollfd, + mut timeout: libc::c_int, +) -> crate::squeezelite_h::event_type { + if crate::stdlib::poll(handles, 2 as libc::c_int as crate::stdlib::nfds_t, timeout) + > 0 as libc::c_int + { + if (*handles.offset(0 as libc::c_int as isize)).revents != 0 { + return crate::squeezelite_h::EVENT_READ; + } + if (*handles.offset(1 as libc::c_int as isize)).revents != 0 { + let mut val: crate::stdlib::eventfd_t = 0; + crate::stdlib::eventfd_read((*handles.offset(1 as libc::c_int as isize)).fd, &mut val); + return crate::squeezelite_h::EVENT_WAKE; + } + } + return crate::squeezelite_h::EVENT_TIMEOUT; +} +// pack/unpack to network byte order +#[no_mangle] + +pub unsafe extern "C" fn packN( + mut dest: *mut crate::squeezelite_h::u32_t, + mut val: crate::squeezelite_h::u32_t, +) { + let mut ptr = dest as *mut crate::squeezelite_h::u8_t; + *ptr = (val >> 24 as libc::c_int & 0xff as libc::c_int as libc::c_uint) + as crate::squeezelite_h::u8_t; + *ptr.offset(1 as libc::c_int as isize) = (val >> 16 as libc::c_int + & 0xff as libc::c_int as libc::c_uint) + as crate::squeezelite_h::u8_t; + *ptr.offset(2 as libc::c_int as isize) = (val >> 8 as libc::c_int + & 0xff as libc::c_int as libc::c_uint) + as crate::squeezelite_h::u8_t; + *ptr.offset(3 as libc::c_int as isize) = + (val & 0xff as libc::c_int as libc::c_uint) as crate::squeezelite_h::u8_t; +} +#[no_mangle] + +pub unsafe extern "C" fn packn( + mut dest: *mut crate::squeezelite_h::u16_t, + mut val: crate::squeezelite_h::u16_t, +) { + let mut ptr = dest as *mut crate::squeezelite_h::u8_t; + *ptr = (val as libc::c_int >> 8 as libc::c_int & 0xff as libc::c_int) + as crate::squeezelite_h::u8_t; + *ptr.offset(1 as libc::c_int as isize) = + (val as libc::c_int & 0xff as libc::c_int) as crate::squeezelite_h::u8_t; +} +#[no_mangle] + +pub unsafe extern "C" fn unpackN( + mut src: *mut crate::squeezelite_h::u32_t, +) -> crate::squeezelite_h::u32_t { + let mut ptr = src as *mut crate::squeezelite_h::u8_t; + return ((*ptr as libc::c_int) << 24 as libc::c_int + | (*ptr.offset(1 as libc::c_int as isize) as libc::c_int) << 16 as libc::c_int + | (*ptr.offset(2 as libc::c_int as isize) as libc::c_int) << 8 as libc::c_int + | *ptr.offset(3 as libc::c_int as isize) as libc::c_int) + as crate::squeezelite_h::u32_t; +} +#[no_mangle] + +pub unsafe extern "C" fn unpackn( + mut src: *mut crate::squeezelite_h::u16_t, +) -> crate::squeezelite_h::u16_t { + let mut ptr = src as *mut crate::squeezelite_h::u8_t; + return ((*ptr as libc::c_int) << 8 as libc::c_int + | *ptr.offset(1 as libc::c_int as isize) as libc::c_int) + as crate::squeezelite_h::u16_t; +} +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Additions (c) Paul Hermann, 2015-2017 under the same license terms + * -Control of Raspberry pi GPIO for amplifier power + * -Launch script on power status change from LMS + */ +// make may define: PORTAUDIO, SELFPIPE, RESAMPLE, RESAMPLE_MP, VISEXPORT, GPIO, IR, DSD, LINKALL to influence build +// build detection +// dynamically loaded libraries at run time +// !LINKALL +// config options +// do not reduce as icy-meta max is 4080 +/* SUN */ +/* SUN */ +// printf/scanf formats for u64_t +// logging +// utils.c (non logging) +#[no_mangle] + +pub unsafe extern "C" fn touch_memory( + mut buf: *mut crate::squeezelite_h::u8_t, + mut size: crate::stddef_h::size_t, +) { + let mut ptr = 0 as *mut crate::squeezelite_h::u8_t; + ptr = buf; + while ptr < buf.offset(size as isize) { + *ptr = 0 as libc::c_int as crate::squeezelite_h::u8_t; + ptr = + ptr.offset(crate::stdlib::sysconf(crate::stdlib::_SC_PAGESIZE as libc::c_int) as isize) + } +} diff --git a/src/vorbis.rs b/src/vorbis.rs new file mode 100644 index 0000000..5f4b132 --- /dev/null +++ b/src/vorbis.rs @@ -0,0 +1,763 @@ +use ::libc; + +pub use crate::stddef_h::size_t; + +pub use crate::stdlib::__int16_t; +pub use crate::stdlib::__int32_t; +pub use crate::stdlib::__int64_t; +pub use crate::stdlib::__pthread_internal_list; +pub use crate::stdlib::__pthread_list_t; +pub use crate::stdlib::__pthread_mutex_s; +pub use crate::stdlib::__uint32_t; +pub use crate::stdlib::__uint64_t; +pub use crate::stdlib::__uint8_t; +pub use crate::stdlib::int16_t; +pub use crate::stdlib::int32_t; +pub use crate::stdlib::int64_t; +pub use crate::stdlib::pthread_mutex_t; +pub use crate::stdlib::u_int32_t; +pub use crate::stdlib::u_int64_t; +pub use crate::stdlib::u_int8_t; + +pub use crate::squeezelite_h::buffer; +pub use crate::squeezelite_h::codec; +pub use crate::squeezelite_h::decode_state; +pub use crate::squeezelite_h::decodestate; +pub use crate::squeezelite_h::disconnect_code; +pub use crate::squeezelite_h::fade_dir; +pub use crate::squeezelite_h::fade_mode; +pub use crate::squeezelite_h::fade_state; +pub use crate::squeezelite_h::frames_t; +pub use crate::squeezelite_h::lDEBUG; +pub use crate::squeezelite_h::lERROR; +pub use crate::squeezelite_h::lINFO; +pub use crate::squeezelite_h::lSDEBUG; +pub use crate::squeezelite_h::lWARN; +pub use crate::squeezelite_h::log_level; +pub use crate::squeezelite_h::output_format; +pub use crate::squeezelite_h::output_state; +pub use crate::squeezelite_h::outputstate; +pub use crate::squeezelite_h::s16_t; +pub use crate::squeezelite_h::s32_t; +pub use crate::squeezelite_h::stream_state; +pub use crate::squeezelite_h::streamstate; +pub use crate::squeezelite_h::u32_t; +pub use crate::squeezelite_h::u64_t; +pub use crate::squeezelite_h::u8_t; +pub use crate::squeezelite_h::C2RustUnnamed_1; +pub use crate::squeezelite_h::_buf_used; +pub use crate::squeezelite_h::DECODE_COMPLETE; +pub use crate::squeezelite_h::DECODE_ERROR; +pub use crate::squeezelite_h::DECODE_READY; +pub use crate::squeezelite_h::DECODE_RUNNING; +pub use crate::squeezelite_h::DECODE_STOPPED; +pub use crate::squeezelite_h::DISCONNECT; +pub use crate::squeezelite_h::DISCONNECT_OK; +pub use crate::squeezelite_h::FADE_ACTIVE; +pub use crate::squeezelite_h::FADE_CROSS; +pub use crate::squeezelite_h::FADE_CROSSFADE; +pub use crate::squeezelite_h::FADE_DOWN; +pub use crate::squeezelite_h::FADE_DUE; +pub use crate::squeezelite_h::FADE_IN; +pub use crate::squeezelite_h::FADE_INACTIVE; +pub use crate::squeezelite_h::FADE_INOUT; +pub use crate::squeezelite_h::FADE_NONE; +pub use crate::squeezelite_h::FADE_OUT; +pub use crate::squeezelite_h::FADE_UP; +pub use crate::squeezelite_h::LOCAL_DISCONNECT; +pub use crate::squeezelite_h::OUTPUT_BUFFER; +pub use crate::squeezelite_h::OUTPUT_OFF; +pub use crate::squeezelite_h::OUTPUT_PAUSE_FRAMES; +pub use crate::squeezelite_h::OUTPUT_RUNNING; +pub use crate::squeezelite_h::OUTPUT_SKIP_FRAMES; +pub use crate::squeezelite_h::OUTPUT_START_AT; +pub use crate::squeezelite_h::OUTPUT_STOPPED; +pub use crate::squeezelite_h::RECV_HEADERS; +pub use crate::squeezelite_h::REMOTE_DISCONNECT; +pub use crate::squeezelite_h::S16_LE; +pub use crate::squeezelite_h::S24_3LE; +pub use crate::squeezelite_h::S24_LE; +pub use crate::squeezelite_h::S32_LE; +pub use crate::squeezelite_h::SEND_HEADERS; +pub use crate::squeezelite_h::STOPPED; +pub use crate::squeezelite_h::STREAMING_BUFFERING; +pub use crate::squeezelite_h::STREAMING_FILE; +pub use crate::squeezelite_h::STREAMING_HTTP; +pub use crate::squeezelite_h::STREAMING_WAIT; +pub use crate::squeezelite_h::TIMEOUT; +pub use crate::squeezelite_h::UNREACHABLE; +pub use crate::src::buffer::_buf_cont_read; +pub use crate::src::buffer::_buf_cont_write; +pub use crate::src::buffer::_buf_inc_readp; +pub use crate::src::buffer::_buf_inc_writep; +pub use crate::src::buffer::_buf_space; +pub use crate::src::decode::decode_newstream; +pub use crate::src::output::_checkfade; +pub use crate::src::utils::logprint; +pub use crate::src::utils::logtime; +pub use crate::stdlib::ogg_int64_t; +pub use crate::stdlib::ov_callbacks; +pub use crate::stdlib::OggVorbis_File; + +pub use crate::stdlib::alloc_chain; +use crate::stdlib::dlerror; +use crate::stdlib::dlopen; +use crate::stdlib::dlsym; +use crate::stdlib::free; +use crate::stdlib::malloc; +use crate::stdlib::memcpy; +use crate::stdlib::memset; +pub use crate::stdlib::ogg_stream_state; +pub use crate::stdlib::ogg_sync_state; +pub use crate::stdlib::oggpack_buffer; +use crate::stdlib::pthread_mutex_lock; +use crate::stdlib::pthread_mutex_unlock; +pub use crate::stdlib::vorbis_block; +pub use crate::stdlib::vorbis_comment; +pub use crate::stdlib::vorbis_dsp_state; +pub use crate::stdlib::vorbis_info; +extern "C" { + #[no_mangle] + pub static mut loglevel: crate::squeezelite_h::log_level; + #[no_mangle] + pub static mut streambuf: *mut crate::squeezelite_h::buffer; + #[no_mangle] + pub static mut outputbuf: *mut crate::squeezelite_h::buffer; + #[no_mangle] + pub static mut stream: crate::squeezelite_h::streamstate; + #[no_mangle] + pub static mut output: crate::squeezelite_h::outputstate; + #[no_mangle] + pub static mut decode: crate::squeezelite_h::decodestate; +} +// automatically select between floating point (preferred) and fixed point libraries: +// NOTE: works with Tremor version here: http://svn.xiph.org/trunk/Tremor, not vorbisidec.1.0.2 currently in ubuntu +// we take common definations from even though we can use tremor at run time +// tremor's OggVorbis_File struct is normally smaller so this is ok, but padding added to malloc in case it is bigger + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct vorbis { + pub vf: *mut crate::stdlib::OggVorbis_File, + pub opened: bool, + pub write_buf: *mut crate::squeezelite_h::u8_t, + pub ov_info: Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::OggVorbis_File, + _: libc::c_int, + ) -> *mut crate::stdlib::vorbis_info, + >, + pub ov_clear: + Option libc::c_int>, + pub ov_read: Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::OggVorbis_File, + _: *mut libc::c_char, + _: libc::c_int, + _: libc::c_int, + _: libc::c_int, + _: libc::c_int, + _: *mut libc::c_int, + ) -> libc::c_long, + >, + pub ov_read_tremor: Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::OggVorbis_File, + _: *mut libc::c_char, + _: libc::c_int, + _: *mut libc::c_int, + ) -> libc::c_long, + >, + pub ov_open_callbacks: Option< + unsafe extern "C" fn( + _: *mut libc::c_void, + _: *mut crate::stdlib::OggVorbis_File, + _: *const libc::c_char, + _: libc::c_long, + _: crate::stdlib::ov_callbacks, + ) -> libc::c_int, + >, +} + +static mut v: *mut vorbis = 0 as *const vorbis as *mut vorbis; +// called with mutex locked within vorbis_decode to avoid locking O before S + +unsafe extern "C" fn _read_cb( + mut ptr: *mut libc::c_void, + mut size: crate::stddef_h::size_t, + mut nmemb: crate::stddef_h::size_t, + mut datasource: *mut libc::c_void, +) -> crate::stddef_h::size_t { + let mut bytes: crate::stddef_h::size_t = 0; + crate::stdlib::pthread_mutex_lock(&mut (*streambuf).mutex); + bytes = if crate::squeezelite_h::_buf_used(streambuf) + < crate::src::buffer::_buf_cont_read(streambuf) + { + crate::squeezelite_h::_buf_used(streambuf) + } else { + crate::src::buffer::_buf_cont_read(streambuf) + } as crate::stddef_h::size_t; + bytes = if bytes < size.wrapping_mul(nmemb) { + bytes + } else { + size.wrapping_mul(nmemb) + }; + crate::stdlib::memcpy(ptr, (*streambuf).readp as *const libc::c_void, bytes); + crate::src::buffer::_buf_inc_readp(streambuf, bytes as libc::c_uint); + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + return bytes.wrapping_div(size); +} +// these are needed for older versions of tremor, later versions and libvorbis allow NULL to be used + +unsafe extern "C" fn _seek_cb( + mut datasource: *mut libc::c_void, + mut offset: crate::stdlib::ogg_int64_t, + mut whence: libc::c_int, +) -> libc::c_int { + return -(1 as libc::c_int); // samples returned are 16 bits +} + +unsafe extern "C" fn _close_cb(mut datasource: *mut libc::c_void) -> libc::c_int { + return 0 as libc::c_int; +} + +unsafe extern "C" fn _tell_cb(mut datasource: *mut libc::c_void) -> libc::c_long { + return 0 as libc::c_int as libc::c_long; +} + +unsafe extern "C" fn vorbis_decode() -> crate::squeezelite_h::decode_state { + static mut channels: libc::c_int = 0; + let mut frames: crate::squeezelite_h::frames_t = 0; + let mut bytes: libc::c_int = 0; + let mut s: libc::c_int = 0; + let mut n: libc::c_int = 0; + let mut write_buf = 0 as *mut crate::squeezelite_h::u8_t; + crate::stdlib::pthread_mutex_lock(&mut (*streambuf).mutex); + if stream.state as libc::c_uint + <= crate::squeezelite_h::DISCONNECT as libc::c_int as libc::c_uint + && crate::squeezelite_h::_buf_used(streambuf) == 0 + { + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + return crate::squeezelite_h::DECODE_COMPLETE; + } + crate::stdlib::pthread_mutex_unlock(&mut (*streambuf).mutex); + if decode.new_stream { + let mut cbs = crate::stdlib::ov_callbacks { + read_func: None, + seek_func: None, + close_func: None, + tell_func: None, + }; + let mut err: libc::c_int = 0; + let mut info = 0 as *mut crate::stdlib::vorbis_info; + cbs.read_func = Some( + _read_cb + as unsafe extern "C" fn( + _: *mut libc::c_void, + _: crate::stddef_h::size_t, + _: crate::stddef_h::size_t, + _: *mut libc::c_void, + ) -> crate::stddef_h::size_t, + ); + if (*v).ov_read_tremor.is_some() { + cbs.seek_func = Some( + _seek_cb + as unsafe extern "C" fn( + _: *mut libc::c_void, + _: crate::stdlib::ogg_int64_t, + _: libc::c_int, + ) -> libc::c_int, + ); + cbs.close_func = + Some(_close_cb as unsafe extern "C" fn(_: *mut libc::c_void) -> libc::c_int); + cbs.tell_func = + Some(_tell_cb as unsafe extern "C" fn(_: *mut libc::c_void) -> libc::c_long) + } else { + cbs.seek_func = None; + cbs.close_func = None; + cbs.tell_func = None + } + err = (*v).ov_open_callbacks.expect("non-null function pointer")( + streambuf as *mut libc::c_void, + (*v).vf, + 0 as *const libc::c_char, + 0 as libc::c_int as libc::c_long, + cbs, + ); + if err < 0 as libc::c_int { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d open_callbacks error: %d\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"vorbis_decode\x00", + )) + .as_ptr(), + 162 as libc::c_int, + err, + ); + } + return crate::squeezelite_h::DECODE_COMPLETE; + } + (*v).opened = 1 as libc::c_int != 0; + info = (*v).ov_info.expect("non-null function pointer")((*v).vf, -(1 as libc::c_int)); + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d setting track_start\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>(b"vorbis_decode\x00")) + .as_ptr(), + 169 as libc::c_int, + ); + } + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + output.next_sample_rate = crate::src::decode::decode_newstream( + (*info).rate as libc::c_uint, + output.supported_rates.as_mut_ptr(), + ); + output.track_start = (*outputbuf).writep; + if output.fade_mode as u64 != 0 { + crate::src::output::_checkfade(1 as libc::c_int != 0); + } + decode.new_stream = 0 as libc::c_int != 0; + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + channels = (*info).channels; + if channels > 2 as libc::c_int { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lWARN as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d too many channels: %d\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"vorbis_decode\x00", + )) + .as_ptr(), + 181 as libc::c_int, + channels, + ); + } + return crate::squeezelite_h::DECODE_ERROR; + } + } + frames = (if crate::src::buffer::_buf_space(outputbuf) + < crate::src::buffer::_buf_cont_write(outputbuf) + { + crate::src::buffer::_buf_space(outputbuf) + } else { + crate::src::buffer::_buf_cont_write(outputbuf) + }) + .wrapping_div(8 as libc::c_int as libc::c_uint); + write_buf = (*v).write_buf; + frames = if frames < 2048 as libc::c_int as libc::c_uint { + frames + } else { + 2048 as libc::c_int as libc::c_uint + }; + bytes = frames + .wrapping_mul(2 as libc::c_int as libc::c_uint) + .wrapping_mul(channels as libc::c_uint) as libc::c_int; + // write the decoded frames into outputbuf even though they are 16 bits per sample, then unpack them + if (*v).ov_read_tremor.is_none() { + n = (*v).ov_read.expect("non-null function pointer")( + (*v).vf, + write_buf as *mut libc::c_char, + bytes, + 0 as libc::c_int, + 2 as libc::c_int, + 1 as libc::c_int, + &mut s, + ) as libc::c_int + } else { + n = (*v).ov_read_tremor.expect("non-null function pointer")( + (*v).vf, + write_buf as *mut libc::c_char, + bytes, + &mut s, + ) as libc::c_int + } + crate::stdlib::pthread_mutex_lock(&mut (*outputbuf).mutex); + if n > 0 as libc::c_int { + let mut count: crate::squeezelite_h::frames_t = 0; + let mut iptr = 0 as *mut crate::squeezelite_h::s16_t; + let mut optr = 0 as *mut crate::squeezelite_h::s32_t; + frames = (n / 2 as libc::c_int / channels) as crate::squeezelite_h::frames_t; + count = frames.wrapping_mul(channels as libc::c_uint); + iptr = (write_buf as *mut crate::squeezelite_h::s16_t).offset(count as isize); + optr = ((*outputbuf).writep as *mut crate::squeezelite_h::s32_t) + .offset(frames.wrapping_mul(2 as libc::c_int as libc::c_uint) as isize); + if channels == 2 as libc::c_int { + loop { + let fresh0 = count; + count = count.wrapping_sub(1); + if !(fresh0 != 0) { + break; + } + iptr = iptr.offset(-1); + optr = optr.offset(-1); + *optr = (*iptr as libc::c_int) << 16 as libc::c_int + } + } else if channels == 1 as libc::c_int { + loop { + let fresh1 = count; + count = count.wrapping_sub(1); + if !(fresh1 != 0) { + break; + } + iptr = iptr.offset(-1); + optr = optr.offset(-1); + *optr = (*iptr as libc::c_int) << 16 as libc::c_int; + optr = optr.offset(-1); + *optr = (*iptr as libc::c_int) << 16 as libc::c_int + } + } + crate::src::buffer::_buf_inc_writep( + outputbuf, + frames.wrapping_mul(8 as libc::c_int as libc::c_uint), + ); + if loglevel as libc::c_uint >= crate::squeezelite_h::lSDEBUG as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d wrote %u frames\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>(b"vorbis_decode\x00")) + .as_ptr(), + 265 as libc::c_int, + frames, + ); + } + } else if n == 0 as libc::c_int { + if stream.state as libc::c_uint + <= crate::squeezelite_h::DISCONNECT as libc::c_int as libc::c_uint + { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d partial decode\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"vorbis_decode\x00", + )) + .as_ptr(), + 270 as libc::c_int, + ); + } + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + return crate::squeezelite_h::DECODE_COMPLETE; + } else { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d no frame decoded\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>( + b"vorbis_decode\x00", + )) + .as_ptr(), + 274 as libc::c_int, + ); + } + } + } else if n == -(3 as libc::c_int) { + // recoverable hole in stream, seen when skipping + if loglevel as libc::c_uint >= crate::squeezelite_h::lDEBUG as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d hole in stream\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>(b"vorbis_decode\x00")) + .as_ptr(), + 280 as libc::c_int, + ); // add some padding as struct size may be larger + } + } else { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d ov_read error: %d\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 14], &[libc::c_char; 14]>(b"vorbis_decode\x00")) + .as_ptr(), + 284 as libc::c_int, + n, + ); + } + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + return crate::squeezelite_h::DECODE_COMPLETE; + } + crate::stdlib::pthread_mutex_unlock(&mut (*outputbuf).mutex); + return crate::squeezelite_h::DECODE_RUNNING; +} + +unsafe extern "C" fn vorbis_open( + mut size: crate::squeezelite_h::u8_t, + mut rate: crate::squeezelite_h::u8_t, + mut chan: crate::squeezelite_h::u8_t, + mut endianness: crate::squeezelite_h::u8_t, +) { + if (*v).vf.is_null() { + (*v).vf = crate::stdlib::malloc( + (::std::mem::size_of::() as libc::c_ulong) + .wrapping_add(128 as libc::c_int as libc::c_ulong), + ) as *mut crate::stdlib::OggVorbis_File; + crate::stdlib::memset( + (*v).vf as *mut libc::c_void, + 0 as libc::c_int, + (::std::mem::size_of::() as libc::c_ulong) + .wrapping_add(128 as libc::c_int as libc::c_ulong), + ); + (*v).write_buf = + crate::stdlib::malloc((2048 as libc::c_int * 8 as libc::c_int) as libc::c_ulong) + as *mut crate::squeezelite_h::u8_t + } else if (*v).opened { + (*v).ov_clear.expect("non-null function pointer")((*v).vf); + (*v).opened = 0 as libc::c_int != 0 + }; +} + +unsafe extern "C" fn vorbis_close() { + if (*v).opened { + (*v).ov_clear.expect("non-null function pointer")((*v).vf); + (*v).opened = 0 as libc::c_int != 0 + } + crate::stdlib::free((*v).vf as *mut libc::c_void); + crate::stdlib::free((*v).write_buf as *mut libc::c_void); + (*v).write_buf = 0 as *mut crate::squeezelite_h::u8_t; + (*v).vf = 0 as *mut crate::stdlib::OggVorbis_File; +} + +unsafe extern "C" fn load_vorbis() -> bool { + let mut handle = crate::stdlib::dlopen( + b"libvorbisfile.so.3\x00" as *const u8 as *const libc::c_char, + 0x2 as libc::c_int, + ); + let mut err = 0 as *mut libc::c_char; + let mut tremor = 0 as libc::c_int != 0; + if handle.is_null() { + handle = crate::stdlib::dlopen( + b"libvorbisidec.so.1\x00" as *const u8 as *const libc::c_char, + 0x2 as libc::c_int, + ); + if !handle.is_null() { + tremor = 1 as libc::c_int != 0 + } else { + if loglevel as libc::c_uint + >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint + { + crate::src::utils::logprint( + b"%s %s:%d dlerror: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"load_vorbis\x00")) + .as_ptr(), + 332 as libc::c_int, + crate::stdlib::dlerror(), + ); + } + return 0 as libc::c_int != 0; + } + } + (*v).ov_read = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::OggVorbis_File, + _: *mut libc::c_char, + _: libc::c_int, + _: libc::c_int, + _: libc::c_int, + _: libc::c_int, + _: *mut libc::c_int, + ) -> libc::c_long, + >, + >(if tremor as libc::c_int != 0 { + 0 as *mut libc::c_void + } else { + crate::stdlib::dlsym(handle, b"ov_read\x00" as *const u8 as *const libc::c_char) + }); + (*v).ov_read_tremor = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::OggVorbis_File, + _: *mut libc::c_char, + _: libc::c_int, + _: *mut libc::c_int, + ) -> libc::c_long, + >, + >(if tremor as libc::c_int != 0 { + crate::stdlib::dlsym(handle, b"ov_read\x00" as *const u8 as *const libc::c_char) + } else { + 0 as *mut libc::c_void + }); + (*v).ov_info = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: *mut crate::stdlib::OggVorbis_File, + _: libc::c_int, + ) -> *mut crate::stdlib::vorbis_info, + >, + >(crate::stdlib::dlsym( + handle, + b"ov_info\x00" as *const u8 as *const libc::c_char, + )); + (*v).ov_clear = ::std::mem::transmute::< + *mut libc::c_void, + Option libc::c_int>, + >(crate::stdlib::dlsym( + handle, + b"ov_clear\x00" as *const u8 as *const libc::c_char, + )); + (*v).ov_open_callbacks = ::std::mem::transmute::< + *mut libc::c_void, + Option< + unsafe extern "C" fn( + _: *mut libc::c_void, + _: *mut crate::stdlib::OggVorbis_File, + _: *const libc::c_char, + _: libc::c_long, + _: crate::stdlib::ov_callbacks, + ) -> libc::c_int, + >, + >(crate::stdlib::dlsym( + handle, + b"ov_open_callbacks\x00" as *const u8 as *const libc::c_char, + )); + err = crate::stdlib::dlerror(); + if !err.is_null() { + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d dlerror: %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"load_vorbis\x00")) + .as_ptr(), + 344 as libc::c_int, + err, + ); + } + return 0 as libc::c_int != 0; + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d loaded %s\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 12], &[libc::c_char; 12]>(b"load_vorbis\x00")).as_ptr(), + 348 as libc::c_int, + if tremor as libc::c_int != 0 { + b"libvorbisidec.so.1\x00" as *const u8 as *const libc::c_char + } else { + b"libvorbisfile.so.3\x00" as *const u8 as *const libc::c_char + }, + ); + } + return 1 as libc::c_int != 0; +} +/* + * Squeezelite - lightweight headless squeezebox emulator + * + * (c) Adrian Smith 2012-2015, triode1@btinternet.com + * Ralph Irving 2015-2017, ralph_irving@hotmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Additions (c) Paul Hermann, 2015-2017 under the same license terms + * -Control of Raspberry pi GPIO for amplifier power + * -Launch script on power status change from LMS + */ +// make may define: PORTAUDIO, SELFPIPE, RESAMPLE, RESAMPLE_MP, VISEXPORT, GPIO, IR, DSD, LINKALL to influence build +// build detection +// dynamically loaded libraries at run time +// !LINKALL +// config options +// do not reduce as icy-meta max is 4080 +/* SUN */ +/* SUN */ +// printf/scanf formats for u64_t +// logging +// utils.c (non logging) +// buffer.c +// _* called with mutex locked +// slimproto.c +// stream.c +// decode.c +// output.c output_alsa.c output_pa.c output_pack.c +// frames played at the point delay is measured +// ordered largest first so [0] is max_rate +// set in decode thread +// set in decode thread +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// set by slimproto +// _* called with mutex locked +// output_alsa.c +// output_pa.c +// output_pulse.c +// output_stdout.c +// output_pack.c +// output_vis.c +// dop.c +// codecs +#[no_mangle] + +pub unsafe extern "C" fn register_vorbis() -> *mut crate::squeezelite_h::codec { + static mut ret: crate::squeezelite_h::codec = unsafe { + { + let mut init = crate::squeezelite_h::codec { + id: 'o' as i32 as libc::c_char, + types: b"ogg\x00" as *const u8 as *const libc::c_char as *mut libc::c_char, + min_read_bytes: 4096 as libc::c_int as libc::c_uint, + min_space: 20480 as libc::c_int as libc::c_uint, + open: Some( + vorbis_open + as unsafe extern "C" fn( + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + _: crate::squeezelite_h::u8_t, + ) -> (), + ), + close: Some(vorbis_close as unsafe extern "C" fn() -> ()), + decode: Some( + vorbis_decode as unsafe extern "C" fn() -> crate::squeezelite_h::decode_state, + ), + }; + init + } + }; + v = crate::stdlib::malloc(::std::mem::size_of::() as libc::c_ulong) as *mut vorbis; + if v.is_null() { + return 0 as *mut crate::squeezelite_h::codec; + } + (*v).vf = 0 as *mut crate::stdlib::OggVorbis_File; + (*v).opened = 0 as libc::c_int != 0; + if !load_vorbis() { + return 0 as *mut crate::squeezelite_h::codec; + } + if loglevel as libc::c_uint >= crate::squeezelite_h::lINFO as libc::c_int as libc::c_uint { + crate::src::utils::logprint( + b"%s %s:%d using vorbis to decode ogg\n\x00" as *const u8 as *const libc::c_char, + crate::src::utils::logtime(), + (*::std::mem::transmute::<&[u8; 16], &[libc::c_char; 16]>(b"register_vorbis\x00")) + .as_ptr(), + 377 as libc::c_int, + ); + } + return &mut ret; +}