Transpiled by c2rust: `c2rust transpile --binary main compile_commands.json -r --reduce-type-annotations -o ../squeezers -- -I/usr/lib/clang/9.0.1/include`
764 lines
29 KiB
Rust
764 lines
29 KiB
Rust
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 <vorbis/vorbisfile.h> 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<unsafe extern "C" fn(_: *mut crate::stdlib::OggVorbis_File) -> 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::<crate::stdlib::OggVorbis_File>() 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::<crate::stdlib::OggVorbis_File>() 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<unsafe extern "C" fn(_: *mut crate::stdlib::OggVorbis_File) -> 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 <http://www.gnu.org/licenses/>.
|
|
*
|
|
* 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::<vorbis>() 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;
|
|
}
|