From 9bea768100f9eb578664686c9cb5b0f95d0400a0 Mon Sep 17 00:00:00 2001 From: antonellocaroli Date: Sat, 11 Feb 2023 18:50:30 +0100 Subject: [PATCH 1/5] libFLAC.so.8 --- flac.c | 31 ++++++++++++++++++------------- squeezelite.h | 20 ++++++++++---------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/flac.c b/flac.c index c82a75e..5b867ff 100644 --- a/flac.c +++ b/flac.c @@ -1,4 +1,4 @@ -/* +/* * Squeezelite - lightweight headless squeezeplay emulator for linux * * (c) Adrian Smith 2012, triode1@btinternet.com @@ -7,7 +7,7 @@ * 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 @@ -110,7 +110,7 @@ static FLAC__StreamDecoderWriteStatus write_cb(const FLAC__StreamDecoder *decode FLAC__int32 *lptr = (FLAC__int32 *)buffer[0]; FLAC__int32 *rptr = (FLAC__int32 *)buffer[channels > 1 ? 1 : 0]; - + if (decode.new_stream) { LOCK_O; LOG_INFO("setting track_start"); @@ -122,7 +122,7 @@ static FLAC__StreamDecoderWriteStatus write_cb(const FLAC__StreamDecoder *decode #define MARKER_OFFSET 2 #else #define MARKER_OFFSET 1 -#endif +#endif if (bits_per_sample == 24 && is_stream_dop(((u8_t *)lptr) + MARKER_OFFSET, ((u8_t *)rptr) + MARKER_OFFSET, 4, frames)) { LOG_INFO("file contains DOP"); if (output.dsdfmt == DOP_S24_LE || output.dsdfmt == DOP_S24_3LE) @@ -151,9 +151,9 @@ static FLAC__StreamDecoderWriteStatus write_cb(const FLAC__StreamDecoder *decode frames_t count; s32_t *optr; - IF_DIRECT( - optr = (s32_t *)outputbuf->writep; - f = min(_buf_space(outputbuf), _buf_cont_write(outputbuf)) / BYTES_PER_FRAME; + IF_DIRECT( + optr = (s32_t *)outputbuf->writep; + f = min(_buf_space(outputbuf), _buf_cont_write(outputbuf)) / BYTES_PER_FRAME; ); IF_PROCESS( optr = (s32_t *)process.inbuf; @@ -225,11 +225,11 @@ static void flac_close(void) { static decode_state flac_decode(void) { bool ok = FLAC(f, stream_decoder_process_single, f->decoder); FLAC__StreamDecoderState state = FLAC(f, stream_decoder_get_state, f->decoder); - + if (!ok && state != FLAC__STREAM_DECODER_END_OF_STREAM) { LOG_INFO("flac error: %s", FLAC_A(f, StreamDecoderStateString)[state]); }; - + if (state == FLAC__STREAM_DECODER_END_OF_STREAM) { return DECODE_COMPLETE; } else if (state > FLAC__STREAM_DECODER_END_OF_STREAM) { @@ -241,9 +241,14 @@ static decode_state flac_decode(void) { static bool load_flac() { #if !LINKALL - void *handle = dlopen(LIBFLAC, RTLD_NOW); + void *handle = NULL; + char name[30]; char *err; + sprintf(name, LIBFLAC, FLAC_API_VERSION_CURRENT < 12 ? 8 : 12); + + handle = dlopen(name, RTLD_NOW); + if (!handle) { LOG_INFO("dlerror: %s", dlerror()); return false; @@ -259,18 +264,18 @@ static bool load_flac() { f->FLAC__stream_decoder_get_state = dlsym(handle, "FLAC__stream_decoder_get_state"); if ((err = dlerror()) != NULL) { - LOG_INFO("dlerror: %s", err); + LOG_INFO("dlerror: %s", err); return false; } - LOG_INFO("loaded "LIBFLAC); + LOG_INFO("loaded %s", name); #endif return true; } struct codec *register_flac(void) { - static struct codec ret = { + static struct codec ret = { 'f', // id "flc", // types 8192, // min read diff --git a/squeezelite.h b/squeezelite.h index edba6e1..2905c80 100644 --- a/squeezelite.h +++ b/squeezelite.h @@ -1,13 +1,13 @@ -/* +/* * Squeezelite - lightweight headless squeezebox emulator * * (c) Adrian Smith 2012-2015, 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 @@ -138,7 +138,7 @@ // dynamically loaded libraries at run time #if LINUX -#define LIBFLAC "libFLAC.so.8" +#define LIBFLAC "libFLAC.so.%d" #define LIBMAD "libmad.so.0" #define LIBMPG "libmpg123.so.0" #define LIBVORBIS "libvorbisfile.so.3" @@ -152,7 +152,7 @@ #endif #if OSX -#define LIBFLAC "libFLAC.8.dylib" +#define LIBFLAC "libFLAC.%d.dylib" #define LIBMAD "libmad.0.dylib" #define LIBMPG "libmpg123.0.dylib" #define LIBVORBIS "libvorbisfile.3.dylib" @@ -178,7 +178,7 @@ #endif #if FREEBSD -#define LIBFLAC "libFLAC.so.11" +#define LIBFLAC "libFLAC.so.%d" #define LIBMAD "libmad.so.2" #define LIBMPG "libmpg123.so.0" #define LIBVORBIS "libvorbisfile.so.6" @@ -325,7 +325,7 @@ typedef int sockfd; #define wake_signal(e) write(e.fds[1], ".", 1) #define wake_clear(e) char c[10]; read(e, &c, 10) #define wake_close(e) close(e.fds[0]); close(e.fds[1]) -struct wake { +struct wake { int fds[2]; }; #endif @@ -514,7 +514,7 @@ bool resample_init(char *opt); #endif // output.c output_alsa.c output_pa.c output_pack.c -typedef enum { OUTPUT_OFF = -1, OUTPUT_STOPPED = 0, OUTPUT_BUFFER, OUTPUT_RUNNING, +typedef enum { OUTPUT_OFF = -1, OUTPUT_STOPPED = 0, OUTPUT_BUFFER, OUTPUT_RUNNING, OUTPUT_PAUSE_FRAMES, OUTPUT_SKIP_FRAMES, OUTPUT_START_AT } output_state; #if DSD @@ -539,7 +539,7 @@ struct outputstate { unsigned buffer; unsigned period; #endif - bool track_started; + bool track_started; #if PORTAUDIO bool pa_reopen; unsigned latency; @@ -600,7 +600,7 @@ void list_devices(void); void list_mixers(const char *output_device); void set_volume(unsigned left, unsigned right); bool test_open(const char *device, unsigned rates[]); -void output_init_alsa(log_level level, const char *device, unsigned output_buf_size, char *params, unsigned rates[], +void output_init_alsa(log_level level, const char *device, unsigned output_buf_size, char *params, unsigned rates[], unsigned rate_delay, unsigned rt_priority, unsigned idle, char *volume_mixer, bool mixer_unmute); void output_close_alsa(void); #endif From f1ea0f4ff159ed354264623501bb0b39e287fdef Mon Sep 17 00:00:00 2001 From: antonellocaroli Date: Fri, 6 Jun 2025 08:04:09 +0200 Subject: [PATCH 2/5] Update stream.c --- stream.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/stream.c b/stream.c index 3fdb28b..eb55e98 100644 --- a/stream.c +++ b/stream.c @@ -1,13 +1,13 @@ -/* +/* * Squeezelite - lightweight headless squeezebox emulator * * (c) Adrian Smith 2012-2015, 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 @@ -42,7 +42,7 @@ static void send_header(void) { unsigned try = 0; ssize_t n; - + while (len) { n = send(fd, ptr, len, MSG_NOSIGNAL); if (n <= 0) { @@ -74,7 +74,8 @@ static void _disconnect(stream_state state, disconnect_code disconnect) { wake_controller(); } -static void *stream_thread() { +// static void *stream_thread() { +static void *stream_thread(void *arg) { while (running) { @@ -139,7 +140,7 @@ static void *stream_thread() { UNLOCK; continue; } - + if (pollinfo.revents & (POLLIN | POLLHUP)) { // get response headers @@ -180,11 +181,11 @@ static void *stream_thread() { } else { endtok = 0; } - + UNLOCK; continue; } - + // receive icy meta data if (stream.meta_interval && stream.meta_next == 0) { @@ -222,7 +223,7 @@ static void *stream_thread() { stream.meta_left -= n; stream.header_len += n; } - + if (stream.meta_left == 0) { if (stream.header_len) { *(stream.header + stream.header_len) = '\0'; @@ -243,7 +244,7 @@ static void *stream_thread() { if (stream.meta_interval) { space = min(space, stream.meta_next); } - + n = recv(fd, streambuf->writep, space, 0); if (n == 0) { LOG_INFO("end of stream"); @@ -253,7 +254,7 @@ static void *stream_thread() { LOG_INFO("error reading: %s", strerror(last_error())); _disconnect(DISCONNECT, REMOTE_DISCONNECT); } - + if (n > 0) { _buf_inc_writep(streambuf, n); stream.bytes += n; @@ -266,15 +267,15 @@ static void *stream_thread() { stream.state = STREAMING_HTTP; wake_controller(); } - + LOG_SDEBUG("streambuf read %d bytes", n); } } UNLOCK; - + } else { - + LOG_SDEBUG("poll timeout"); } } @@ -295,7 +296,7 @@ void stream_init(log_level level, unsigned stream_buf_size) { LOG_ERROR("unable to malloc buffer"); exit(0); } - + stream.state = STOPPED; stream.header = malloc(MAX_HEADER); *stream.header = '\0'; @@ -353,7 +354,7 @@ void stream_file(const char *header, size_t header_len, unsigned threshold) { stream.state = DISCONNECT; } wake_controller(); - + stream.cont_wait = false; stream.meta_interval = 0; stream.meta_next = 0; From 3048c333dc71a14afb11542df2bbb52c85f762d2 Mon Sep 17 00:00:00 2001 From: antonellocaroli Date: Fri, 6 Jun 2025 08:10:23 +0200 Subject: [PATCH 3/5] Update output_stdout.c --- output_stdout.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/output_stdout.c b/output_stdout.c index ad09fcd..53b3442 100644 --- a/output_stdout.c +++ b/output_stdout.c @@ -1,4 +1,4 @@ -/* +/* * Squeezelite - lightweight headless squeezebox emulator * * (c) Adrian Smith 2012-2015, triode1@btinternet.com @@ -7,7 +7,7 @@ * 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 @@ -50,7 +50,7 @@ static int _stdout_write_frames(frames_t out_frames, bool silence, s32_t gainL, u8_t *obuf; if (!silence) { - + if (output.fade == FADE_ACTIVE && output.fade_dir == FADE_CROSS && *cross_ptr) { _apply_cross(outputbuf, out_frames, cross_gain_in, cross_gain_out, cross_ptr); } @@ -81,7 +81,8 @@ static int _stdout_write_frames(frames_t out_frames, bool silence, s32_t gainL, return (int)out_frames; } -static void *output_thread() { +// static void *output_thread() { +static void *output_thread(void *arg) { LOCK; @@ -100,7 +101,7 @@ static void *output_thread() { UNLOCK; while (running) { - + LOCK; output.device_frames = 0; From c76439ff5bdebe82fb8e1aa4c1d91b1cbf6d03f2 Mon Sep 17 00:00:00 2001 From: antonellocaroli Date: Fri, 6 Jun 2025 08:12:10 +0200 Subject: [PATCH 4/5] Update decode.c --- decode.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/decode.c b/decode.c index add5fcb..12dca0f 100644 --- a/decode.c +++ b/decode.c @@ -1,4 +1,4 @@ -/* +/* * Squeezelite - lightweight headless squeezebox emulator * * (c) Adrian Smith 2012-2015, triode1@btinternet.com @@ -7,7 +7,7 @@ * 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 @@ -52,7 +52,8 @@ static bool running = true; #define MAY_PROCESS(x) #endif -static void *decode_thread() { +// static void *decode_thread() { +static void *decode_thread(void *arg) { while (running) { size_t bytes, space, min_space; @@ -70,7 +71,7 @@ static void *decode_thread() { LOCK_D; if (decode.state == DECODE_RUNNING && codec) { - + LOG_SDEBUG("streambuf bytes: %u outputbuf space: %u", bytes, space); IF_DIRECT( @@ -79,9 +80,9 @@ static void *decode_thread() { IF_PROCESS( min_space = process.max_out_frames * BYTES_PER_FRAME; ); - + if (space > min_space && (bytes > codec->min_read_bytes || toend)) { - + decode.state = codec->decode(); IF_PROCESS( @@ -108,7 +109,7 @@ static void *decode_thread() { ran = true; } } - + UNLOCK_D; if (!ran) { @@ -235,9 +236,9 @@ void codec_open(u8_t format, u8_t sample_size, u8_t sample_rate, u8_t channels, LOG_INFO("closing codec: '%c'", codec->id); codec->close(); } - + codec = codecs[i]; - + codec->open(sample_size, sample_rate, channels, endianness); decode.state = DECODE_READY; @@ -251,4 +252,3 @@ void codec_open(u8_t format, u8_t sample_size, u8_t sample_rate, u8_t channels, LOG_ERROR("codec not found"); } - From 52fd5e693694cc864aee36314ed3abfd95537274 Mon Sep 17 00:00:00 2001 From: antonellocaroli Date: Fri, 6 Jun 2025 08:19:45 +0200 Subject: [PATCH 5/5] Update flac.c --- flac.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flac.c b/flac.c index 5b867ff..a94cebf 100644 --- a/flac.c +++ b/flac.c @@ -245,7 +245,8 @@ static bool load_flac() { char name[30]; char *err; - sprintf(name, LIBFLAC, FLAC_API_VERSION_CURRENT < 12 ? 8 : 12); +// sprintf(name, LIBFLAC, FLAC_API_VERSION_CURRENT < 12 ? 8 : 12); +sprintf(name, "libFLAC.so"); handle = dlopen(name, RTLD_NOW);