Codebase list squeezelite / dd2f41c
New upstream snapshot. Debian Janitor 1 year, 5 months ago
31 changed file(s) with 323 addition(s) and 216 deletion(s). Raw diff Collapse all Expand all
44 EXECUTABLE ?= squeezelite
55
66 # passing one or more of these in $(OPTS) enables optional feature inclusion
7 OPT_DSD = -DDSD
8 OPT_FF = -DFFMPEG
9 OPT_ALAC = -DALAC
10 OPT_LINKALL = -DLINKALL
11 OPT_RESAMPLE= -DRESAMPLE
12 OPT_VIS = -DVISEXPORT
13 OPT_IR = -DIR
14 OPT_GPIO = -DGPIO
15 OPT_RPI = -DRPI
16 OPT_NO_FAAD = -DNO_FAAD
17 OPT_SSL = -DUSE_SSL
18 OPT_NOSSLSYM= -DNO_SSLSYM
19 OPT_OPUS = -DOPUS
20 OPT_PORTAUDIO = -DPORTAUDIO
7 OPT_DSD = -DDSD
8 OPT_FF = -DFFMPEG
9 OPT_ALAC = -DALAC
10 OPT_LINKALL = -DLINKALL
11 OPT_RESAMPLE = -DRESAMPLE
12 OPT_VIS = -DVISEXPORT
13 OPT_IR = -DIR
14 OPT_GPIO = -DGPIO
15 OPT_RPI = -DRPI
16 OPT_NO_FAAD = -DNO_FAAD
17 OPT_NO_MAD = -DNO_MAD
18 OPT_NO_MPG123 = -DNO_MPG123
19 OPT_SSL = -DUSE_SSL
20 OPT_NOSSLSYM = -DNO_SSLSYM
21 OPT_OPUS = -DOPUS
22 OPT_PORTAUDIO = -DPORTAUDIO
2123 OPT_PULSEAUDIO = -DPULSEAUDIO
2224
2325 SOURCES = \
2426 main.c slimproto.c buffer.c stream.c utils.c \
2527 output.c output_alsa.c output_pa.c output_stdout.c output_pack.c output_pulse.c decode.c \
26 flac.c pcm.c mad.c vorbis.c mpg.c
28 flac.c pcm.c vorbis.c
2729
2830 SOURCES_DSD = dsd.c dop.c dsd2pcm/dsd2pcm.c
2931 SOURCES_FF = ffmpeg.c
3638 SOURCES_FAAD = faad.c
3739 SOURCES_SSL = sslsym.c
3840 SOURCES_OPUS = opus.c
41 SOURCES_MAD = mad.c
42 SOURCES_MPG123 = mpg.c
3943
4044 LINK_LINUX = -ldl
4145 LINK_ALSA = -lasound
4448 LINK_SSL = -lssl -lcrypto
4549 LINK_ALAC = -lalac
4650
47 LINKALL = -lmad -lmpg123 -lFLAC -lvorbisfile -lvorbis -logg
51 LINKALL = -lFLAC -lvorbisfile -lvorbis -logg
4852 LINKALL_FF = -lavformat -lavcodec -lavutil
4953 LINKALL_RESAMPLE = -lsoxr
5054 LINKALL_IR = -llirc_client
5155 LINKALL_FAAD = -lfaad
5256 LINKALL_OPUS = -lopusfile -lopus
57 LINKALL_MAD = -lmad
58 LINKALL_MPG123 = -lmpg123
5359
5460 DEPS = squeezelite.h slimproto.h
5561
97103 ifneq (,$(findstring $(OPT_SSL), $(OPTS)))
98104 SOURCES += $(SOURCES_SSL)
99105 endif
106 ifeq (,$(findstring $(OPT_NO_MAD), $(OPTS)))
107 SOURCES += $(SOURCES_MAD)
108 endif
109 ifeq (,$(findstring $(OPT_NO_MPG123), $(OPTS)))
110 SOURCES += $(SOURCES_MPG123)
111 endif
100112
101113 # add optional link options
102114 ifneq (,$(findstring $(OPT_LINKALL), $(OPTS)))
118130 endif
119131 ifneq (,$(findstring $(OPT_SSL), $(OPTS)))
120132 LDADD += $(LINK_SSL)
133 endif
134 ifeq (,$(findstring $(OPT_NO_MAD), $(OPTS)))
135 LDADD += $(LINKALL_MAD)
136 endif
137 ifeq (,$(findstring $(OPT_NO_MPG123), $(OPTS)))
138 LDADD += $(LINKALL_MPG123)
121139 endif
122140 else
123141 # if not LINKALL and linux add LINK_LINUX
0 # OSX 10.5 Intel 32-bit
1 OPTS = -DPORTAUDIO -DALAC -DOPUS -DRESAMPLE -DGPIO -DLINKALL -DVISEXPORT -DDSD -DUSE_SSL -I./include -I./include/opus -I./include/alac -O2 -I./include -isysroot /Developer/SDKs/MacOSX10.5.sdk -arch i386
0 # OSX 10.7 Intel 32-bit
1 OPTS = -DPORTAUDIO -DALAC -DOPUS -DRESAMPLE -DLINKALL -DVISEXPORT -DDSD -DUSE_SSL -I./include -I./include/opus -I./include/alac -I./include -O3 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -arch i386 -mmacosx-version-min=10.7
22
3 LDFLAGS = -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk -arch i386 -mmacosx-version-min=10.5 -L./lib
3 LDFLAGS = -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -arch i386 -mmacosx-version-min=10.7 -L./lib
44
55 LDADD = -lportaudio -lpthread -ldl -lm -framework CoreVideo -framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework Carbon
66
0 # OSX 11.0+ arm64 only
1 OPTS = -DPORTAUDIO -DALAC -DOPUS -DRESAMPLE -DLINKALL -DVISEXPORT -DDSD -DUSE_SSL -I./includem1 -I./includem1/opus -I./includem1/alac -arch arm64 -O3 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -mmacosx-version-min=11.0
2
3 LDFLAGS = -arch arm64 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -mmacosx-version-min=11.0 -L./libm1
4
5 LDADD = -lportaudio -lpthread -ldl -lm -framework CoreVideo -framework VideoDecodeAcceleration -framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework Carbon
6
7 include Makefile
00 # OSX 10.7+ 64-bit only
1 OPTS = -DPORTAUDIO -DALAC -DOPUS -DRESAMPLE -DGPIO -DLINKALL -DVISEXPORT -DDSD -DUSE_SSL -I./include64 -I./include64/opus -I./include64/alac -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -arch x86_64 -mmacosx-version-min=10.7
1 OPTS = -DPORTAUDIO -DALAC -DOPUS -DRESAMPLE -DLINKALL -DVISEXPORT -DDSD -DUSE_SSL -I./include64 -I./include64/opus -I./include64/alac -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -arch x86_64 -mmacosx-version-min=10.7
22
33 LDFLAGS = -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -arch x86_64 -mmacosx-version-min=10.7 -L./lib64
44
119119 // extract audio config from within alac
120120 if (!strcmp(type, "alac") && bytes > len) {
121121 u8_t *ptr = streambuf->readp + 36;
122 l->decoder = alac_create_decoder(len - 36, ptr, &l->sample_size, &l->sample_rate, &l->channels);
123 l->play = l->trak;
122 unsigned int block_size;
123 l->play = l->trak;
124 l->decoder = alac_create_decoder(len - 36, ptr, &l->sample_size, &l->sample_rate, &l->channels, &block_size);
125 l->writebuf = malloc(block_size + 256);
126 LOG_INFO("allocated write buffer of %u bytes", block_size);
127 if (!l->writebuf) {
128 LOG_ERROR("allocation failed");
129 return -1;
130 }
124131 }
125132
126133 // extract the total number of samples from stts
375382
376383 // need to create a buffer with contiguous data
377384 if (bytes < block_size) {
378 u8_t *buffer = malloc(block_size);
379 memcpy(buffer, streambuf->readp, bytes);
380 memcpy(buffer + bytes, streambuf->buf, block_size - bytes);
381 iptr = buffer;
385 iptr = malloc(block_size);
386 memcpy(iptr, streambuf->readp, bytes);
387 memcpy(iptr + bytes, streambuf->buf, block_size - bytes);
382388 } else iptr = streambuf->readp;
383389
384390 if (!alac_to_pcm(l->decoder, iptr, l->writebuf, 2, &frames)) {
473479 }
474480 } else if (l->sample_size == 16) {
475481 u16_t *_iptr = (u16_t*) iptr;
482 iptr += count * 4;
476483 while (count--) {
477484 *optr++ = ALIGN16(*_iptr++);
478485 *optr++ = ALIGN16(*_iptr++);
485492 }
486493 } else if (l->sample_size == 32) {
487494 u32_t *_iptr = (u32_t*) iptr;
495 iptr += count * 8;
488496 while (count--) {
489497 *optr++ = ALIGN32(*_iptr++);
490498 *optr++ = ALIGN32(*_iptr++);
510518 return DECODE_RUNNING;
511519 }
512520
513 static void alac_open(u8_t size, u8_t rate, u8_t chan, u8_t endianness) {
514 if (l->decoder) alac_delete_decoder(l->decoder);
515 else l->writebuf = malloc(BLOCK_SIZE * 2);
516
521 static void alac_close(void) {
522 if (l->decoder) alac_delete_decoder(l->decoder);
523 if (l->writebuf) free(l->writebuf);
517524 if (l->chunkinfo) free(l->chunkinfo);
518525 if (l->block_size) free(l->block_size);
519526 if (l->stsc) free(l->stsc);
520 l->decoder = l->chunkinfo = l->stsc = l->block_size = NULL;
521 l->skip = 0;
522 l->samples = l->sttssamples = 0;
523 l->empty = false;
524 l->pos = l->consume = l->sample = l->nextchunk = 0;
527 memset(l, 0, sizeof(struct alac));
525528 }
526529
527 static void alac_close(void) {
528 if (l->decoder) alac_delete_decoder(l->decoder);
529 if (l->chunkinfo) free(l->chunkinfo);
530 if (l->block_size) free(l->block_size);
531 if (l->stsc) free(l->stsc);
532 l->decoder = l->chunkinfo = l->stsc = l->block_size = NULL;
533 free(l->writebuf);
530 static void alac_open(u8_t size, u8_t rate, u8_t chan, u8_t endianness) {
531 alac_close();
534532 }
535533
536534 struct codec *register_alac(void) {
543541 alac_close, // close
544542 alac_decode, // decode
545543 };
546
547 l = malloc(sizeof(struct alac));
548 if (!l) {
549 return NULL;
550 }
551
552 l->decoder = l->chunkinfo = l->stsc = l->block_size = NULL;
553
544
545 l = calloc(1, sizeof(struct alac));
546 if (!l) return NULL;
547
554548 LOG_INFO("using alac to decode alc");
555549 return &ret;
556550 }
3131 /*----------------------------------------------------------------------------*/
3232 extern "C" struct alac_codec_s *alac_create_decoder(int magic_cookie_size, unsigned char *magic_cookie,
3333 unsigned char *sample_size, unsigned *sample_rate,
34 unsigned char *channels) {
34 unsigned char *channels, unsigned int *block_size) {
3535 struct alac_codec_s *codec = (struct alac_codec_s*) malloc(sizeof(struct alac_codec_s));
3636
3737 codec->Decoder = new ALACDecoder;
4242 *sample_size = codec->Decoder->mConfig.bitDepth;
4343
4444 codec->frames_per_packet = codec->Decoder->mConfig.frameLength;
45 codec->block_size = codec->frames_per_packet * (*channels) * (*sample_size) / 8;
45 *block_size = codec->block_size = codec->frames_per_packet * (*channels) * (*sample_size) / 8;
4646
4747 return codec;
4848 }
2727
2828 struct alac_codec_s *alac_create_decoder(int magic_cookie_size, unsigned char *magic_cookie,
2929 unsigned char *sample_size, unsigned *sample_rate,
30 unsigned char *channels);
30 unsigned char *channels, unsigned int *block_size);
3131 void alac_delete_decoder(struct alac_codec_s *codec);
3232 bool alac_to_pcm(struct alac_codec_s *codec, unsigned char* input,
3333 unsigned char *output, char channels, unsigned *out_frames);
00 # Contributor: Carl Chave <online@chave.us>
11 # Maintainer: Ralph Irving <ralph.irving@gmail.com>
22 pkgname=squeezelite
3 pkgver=1.9.7.1273
4 pkgrel=1
3 pkgver=1.9.9.1401
4 pkgrel=0
55 pkgdesc="Lightweight headless squeezebox player for Logitech Media Server"
66 url="https://github.com/ralph-irving/squeezelite"
77 arch="all"
88 license="GPL-3.0-or-later3"
99 options="!check" # No test suite
10 depends="flac alsa-lib faad2 mpg123 libvorbis libmad soxr openssl opusfile libalac"
11 makedepends="flac-dev alsa-lib-dev faad2-dev mpg123-dev libvorbis-dev libmad-dev soxr-dev openssl-dev opusfile-dev opus-dev libalac-dev"
10 depends="flac alsa-lib faad2-libs mpg123-libs libvorbis libmad soxr openssl opusfile libalac lirc"
11 makedepends="flac-dev alsa-lib-dev faad2-dev mpg123-dev libvorbis-dev libmad-dev soxr-dev openssl-dev opusfile-dev opus-dev libalac-dev lirc-dev"
1212 install="$pkgname.pre-install"
1313 subpackages="$pkgname-doc $pkgname-openrc"
1414 source="$pkgname-$pkgver.zip::https://github.com/ralph-irving/squeezelite/archive/master.zip load-libtremor-first.patch $pkgname.confd $pkgname.initd"
1616
1717 build() {
1818 cd "$builddir"
19 make OPTS="-DRESAMPLE -DDSD -DGPIO -DVISEXPORT -DUSE_SSL -DNO_SSLSYM -DOPUS -DALAC -I/usr/include/opus -I/usr/include/alac"
19 make OPTS="-DRESAMPLE -DDSD -DGPIO -DVISEXPORT -DUSE_SSL -DNO_SSLSYM -DOPUS -DALAC -DIR -I/usr/include/opus -I/usr/include/alac"
2020 gcc -Os -fomit-frame-pointer -fcommon -s -o find_servers tools/find_servers.c
2121 gcc -Os -fomit-frame-pointer -fcommon -s -o alsacap tools/alsacap.c -lasound
2222 }
66 arch="all"
77 subpackages="$pkgname-doc $pkgname-dev"
88 license="Apache 2.0"
9 makedepends="git autoconf automake make tar"
9 makedepends="git autoconf automake libtool make tar"
1010 source="fix-arm-segfault.patch \
1111 alac-version.patch"
1212
4444 install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/COPYING
4545 }
4646
47 sha512sums="e72b13714476170108844b84c0043dc06d2ff2e8c9b651a7ad1571d148fc5567aca48048646d16fb82630d6972a31b9328f04e522972b297d1cf8e804785867f fix-arm-segfault.patch
47 sha512sums="271d4c5184c7f48ac79c8f8f9f3bc39f7f970b4d98acda792e40450b687f211094b4dcaea23e034d4deb7ea78713b95e691db9c09fbf31b1be59b6d525ef11a8 fix-arm-segfault.patch
4848 093379f79b5dc9f5b8aa45826d61738b088d78305a7d514df33851ae34d02ee9034a8ecddf2558fcb1bf4daaf64c620ea4411521908cfc748e31fd0a2d50bbf7 alac-version.patch"
33
44 depend() {
55 need net
6 use alsasound
6 use alsa
77 after bootmisc
88 }
99
2626
2727 // _* called with muxtex locked
2828
29 inline unsigned _buf_used(struct buffer *buf) {
29 #if !WIN
30 inline
31 #endif
32 unsigned _buf_used(struct buffer *buf) {
3033 return buf->writep >= buf->readp ? buf->writep - buf->readp : buf->size - (buf->readp - buf->writep);
3134 }
3235
0 squeezelite (1.9+git20221015.ca44fc6-1) UNRELEASED; urgency=low
1
2 * New upstream snapshot.
3
4 -- Debian Janitor <janitor@jelmer.uk> Tue, 18 Oct 2022 03:41:15 -0000
5
06 squeezelite (1.9+git20210102.78fef68-3) unstable; urgency=medium
17
28 * Upload to unstable.
182182 if (!strstr(exclude_codecs, "pcm") && (!include_codecs || (order_codecs = strstr(include_codecs, "pcm"))))
183183 sort_codecs((include_codecs ? order_codecs - include_codecs : i), register_pcm());
184184
185 #if !defined(NO_MAD) && !defined(NO_MPG123)
185186 // try mad then mpg for mp3 unless command line option passed
186187 if (!(strstr(exclude_codecs, "mp3") || strstr(exclude_codecs, "mad")) &&
187188 (!include_codecs || (order_codecs = strstr(include_codecs, "mp3")) || (order_codecs = strstr(include_codecs, "mad"))))
189190 else if (!(strstr(exclude_codecs, "mp3") || strstr(exclude_codecs, "mpg")) &&
190191 (!include_codecs || (order_codecs = strstr(include_codecs, "mp3")) || (order_codecs = strstr(include_codecs, "mpg"))))
191192 sort_codecs((include_codecs ? order_codecs - include_codecs : i), register_mpg());
193 #elif !defined(NO_MAD)
194 if (!strstr(exclude_codecs, "mp3") && (!include_codecs || (order_codecs = strstr(include_codecs, "mp3"))))
195 sort_codecs((include_codecs ? order_codecs - include_codecs : i), register_mad());
196 #elif !defined(NO_MPG123)
197 if (!strstr(exclude_codecs, "mp3") && (!include_codecs || (order_codecs = strstr(include_codecs, "mp3"))))
198 sort_codecs((include_codecs ? order_codecs - include_codecs : i), register_mpg());
199 #endif
192200
193201 LOG_DEBUG("include codecs: %s exclude codecs: %s", include_codecs ? include_codecs : "", exclude_codecs);
194202
5353 unsigned (* avcodec_version)(void);
5454 AVCodec * (* avcodec_find_decoder)(int);
5555 int attribute_align_arg (* avcodec_open2)(AVCodecContext *, const AVCodec *, AVDictionary **);
56 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
5756 AVFrame * (* av_frame_alloc)(void);
5857 void (* av_frame_free)(AVFrame **);
59 #else
60 AVFrame * (* avcodec_alloc_frame)(void);
61 void (* avcodec_free_frame)(AVFrame **);
62 #endif
63 int attribute_align_arg (* avcodec_decode_audio4)(AVCodecContext *, AVFrame *, int *, const AVPacket *);
58 int attribute_align_arg (* avcodec_send_packet)(AVCodecContext *, const AVPacket *);
59 int attribute_align_arg (* avcodec_receive_frame)(AVCodecContext *, AVFrame *);
6460 AVCodecContext * (* avcodec_alloc_context3)(const AVCodec *);
6561 void (* avcodec_free_context)(AVCodecContext **);
6662 int (* avcodec_parameters_to_context)(AVCodecContext *, const AVCodecParameters *);
7268 int (* avformat_find_stream_info)(AVFormatContext *, AVDictionary **);
7369 AVIOContext * (* avio_alloc_context)(unsigned char *, int, int, void *,
7470 int (*read_packet)(void *, uint8_t *, int), int (*write_packet)(void *, uint8_t *, int), int64_t (*seek)(void *, int64_t, int));
71 AVPacket * (* av_packet_alloc)(void);
72 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58,133,100)
7573 void (* av_init_packet)(AVPacket *);
76 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57,24,102)
74 #endif
7775 void (* av_packet_unref)(AVPacket *);
78 #else
79 void (* av_free_packet)(AVPacket *);
80 #endif
8176 int (* av_read_frame)(AVFormatContext *, AVPacket *);
8277 AVInputFormat * (* av_find_input_format)(const char *);
78 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(58,9,100)
8379 void (* av_register_all)(void);
80 #endif
8481 // ffmpeg symbols to be dynamically loaded from libavutil
8582 unsigned (* avutil_version)(void);
8683 void (* av_log_set_callback)(void (*)(void*, int, const char*, va_list));
262259 }
263260
264261 static decode_state ff_decode(void) {
265 int r, len, got_frame;
266 AVPacket pkt_c;
262 int r;
267263 s32_t *optr = NULL;
268264
269265 if (decode.new_stream) {
350346
351347 AVCODEC(ff, open2, ff->codecC, codec, NULL);
352348
353 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
354349 ff->frame = AV(ff, frame_alloc);
355 #else
356 ff->frame = AVCODEC(ff, alloc_frame);
357 #endif
358
359 ff->avpkt = AV(ff, malloc, sizeof(AVPacket));
350 ff->avpkt = AV(ff, packet_alloc);
360351 if (ff->avpkt == NULL) {
361352 LOG_ERROR("can't allocate avpkt");
362353 return DECODE_ERROR;
363354 }
364355
365 AV(ff, init_packet, ff->avpkt);
366 ff->avpkt->data = NULL;
367 ff->avpkt->size = 0;
356 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58,133,100)
357 AV(ff, init_packet, ff->avpkt); // on older ffmpeg, this still is needed to e.g. set ->pos to -1
358 #endif
368359
369360 LOCK_O;
370361 LOG_INFO("setting track_start");
375366 decode.new_stream = false;
376367 UNLOCK_O;
377368 }
378
379 got_frame = 0;
380369
381370 if ((r = AV(ff, read_frame, ff->formatC, ff->avpkt)) < 0) {
382371 if (r == AVERROR_EOF) {
392381 return DECODE_RUNNING;
393382 }
394383
395 // clone packet as we are adjusting it
396 pkt_c = *ff->avpkt;
397
398384 IF_PROCESS(
399385 optr = (s32_t *)process.inbuf;
400386 process.in_frames = 0;
401387 );
402388
403 while (pkt_c.size > 0 || got_frame) {
404
405 len = AVCODEC(ff, decode_audio4, ff->codecC, ff->frame, &got_frame, &pkt_c);
406 if (len < 0) {
407 LOG_ERROR("avcodec_decode_audio4 error: %i %s", len, av__err2str(len));
408 break; // exit loop, free the packet, and continue decoding
409 }
410
411 pkt_c.data += len;
412 pkt_c.size -= len;
413
414 if (got_frame) {
415
389 if ((r = AVCODEC(ff, send_packet, ff->codecC, ff->avpkt)) < 0) {
390 AV(ff, packet_unref, ff->avpkt);
391
392 if (r == AVERROR_EOF) {
393 LOG_DEBUG("av_send_packet reports eof");
394 return DECODE_COMPLETE;
395 } else {
396 LOG_ERROR("av_send_packet error: %i %s", r, av__err2str(r));
397
398 // EAGAIN is treated as an unrecoverable error here since all pending output frames are processed below
399 if (r == AVERROR(EAGAIN) || r == AVERROR(EINVAL) || r == AVERROR(ENOMEM))
400 return DECODE_ERROR;
401
402 // retain existing behavior (continue decoding) for legitimate decoding errors
403 return DECODE_RUNNING;
404 }
405 } else {
406 // a single input packet can lead to multiple output frames - process all of them
407 while ((r = AVCODEC(ff, receive_frame, ff->codecC, ff->frame)) >= 0) {
416408 s16_t *iptr16 = (s16_t *)ff->frame->data[0];
417409 s32_t *iptr32 = (s32_t *)ff->frame->data[0];
418410 s16_t *iptr16l = (s16_t *)ff->frame->data[0];
535527 }
536528 }
537529
538 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57,24,102)
539530 AV(ff, packet_unref, ff->avpkt);
540 #else
541 AV(ff, free_packet, ff->avpkt);
542 #endif
531
532 if (r == AVERROR(EAGAIN)) {
533 // EAGAIN is expected if there are no more pending frames
534 } else if (r == AVERROR_EOF) {
535 LOG_DEBUG("av_receive_frame reports eof");
536 return DECODE_COMPLETE;
537 } else {
538 LOG_ERROR("av_receive_frame error: %i %s", r, av__err2str(r));
539
540 if (r == AVERROR(EINVAL))
541 return DECODE_ERROR;
542
543 // retain existing behavior (continue decoding) for legitimate decoding errors
544 }
543545
544546 return DECODE_RUNNING;
545547 }
564566 }
565567
566568 if (ff->frame) {
567 // ffmpeg version dependant free function
568 #if !LINKALL
569 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
570 ff->av_frame_free ? AV(ff, frame_free, &ff->frame) : AV(ff, freep, &ff->frame);
571 #else
572 ff->avcodec_free_frame ? AVCODEC(ff, free_frame, &ff->frame) : AV(ff, freep, &ff->frame);
573 #endif
574 #elif LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54,28,0)
575 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
576569 AV(ff, frame_free, &ff->frame);
577 #else
578 AVCODEC(ff, free_frame, &ff->frame);
579 #endif
580 #else
581 AV(ff, freep, &ff->frame);
582 #endif
583570 ff->frame = NULL;
584571 }
585572
586573 if (ff->avpkt) {
587 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57,24,102)
588574 AV(ff, packet_unref, ff->avpkt);
589 #else
590 AV(ff, free_packet, ff->avpkt);
591 #endif
592575 AV(ff, freep, &ff->avpkt);
593576 ff->avpkt = NULL;
594577 }
660643 ff->avcodec_version = dlsym(handle_codec, "avcodec_version");
661644 ff->avcodec_find_decoder = dlsym(handle_codec, "avcodec_find_decoder");
662645 ff->avcodec_open2 = dlsym(handle_codec, "avcodec_open2");
663 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
664646 ff->av_frame_alloc = dlsym(handle_codec, "av_frame_alloc");
665647 ff->av_frame_free = dlsym(handle_codec, "av_frame_free");
666 #else
667 ff->avcodec_alloc_frame = dlsym(handle_codec, "avcodec_alloc_frame");
668 ff->avcodec_free_frame = dlsym(handle_codec, "avcodec_free_frame");
669 #endif
670 ff->avcodec_decode_audio4 = dlsym(handle_codec, "avcodec_decode_audio4");
648 ff->avcodec_send_packet = dlsym(handle_codec, "avcodec_send_packet");
649 ff->avcodec_receive_frame = dlsym(handle_codec, "avcodec_receive_frame");
671650 ff->avcodec_alloc_context3 = dlsym(handle_format, "avcodec_alloc_context3");
672651 ff->avcodec_free_context = dlsym(handle_format, "avcodec_free_context");
673652 ff->avcodec_parameters_to_context = dlsym(handle_format, "avcodec_parameters_to_context");
653 ff->av_packet_alloc = dlsym(handle_codec, "av_packet_alloc");
654 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58,133,100)
674655 ff->av_init_packet = dlsym(handle_codec, "av_init_packet");
675 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57,24,102)
656 #endif
676657 ff->av_packet_unref = dlsym(handle_codec, "av_packet_unref");
677 #else
678 ff->av_free_packet = dlsym(handle_codec, "av_free_packet");
679 #endif
680658
681659 if ((err = dlerror()) != NULL) {
682660 LOG_INFO("dlerror: %s", err);
693671 ff->avio_alloc_context = dlsym(handle_format, "avio_alloc_context");
694672 ff->av_read_frame = dlsym(handle_format, "av_read_frame");
695673 ff->av_find_input_format= dlsym(handle_format, "av_find_input_format");
674 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(58,9,100)
696675 ff->av_register_all = dlsym(handle_format, "av_register_all");
676 #endif
697677
698678 if ((err = dlerror()) != NULL) {
699679 LOG_INFO("dlerror: %s", err);
760740
761741 AV(ff, log_set_callback, av_err_callback);
762742
743 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(58,9,100)
763744 AV(ff, register_all);
764
745 #endif
746
765747 registered = true;
766748 }
767749
769751
770752 static struct codec ret = {
771753 'w', // id
772 "wma,wmap", // types
754 "wma,wmap,wmal", // types
773755 READ_SIZE, // min read
774756 WRITE_SIZE, // min space
775757 ff_open_wma, // open
777759 ff_decode, // decode
778760 };
779761
780 LOG_INFO("using ffmpeg to decode wma,wmap");
762 LOG_INFO("using ffmpeg to decode wma,wmap,wmal");
781763 return &ret;
782764 }
783765
122122
123123 *want = bytes;
124124
125 // if there's nothing in the stream buffer, libFLAC will continuously call this function as quickly as possible. slow it down.
126 if (!bytes && !end)
127 usleep(1000);
128
125129 return end ? FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM : FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
126130 }
127131
132132 { "KEY_DOWN", 0x7689b04f, true },
133133 { "KEY_HOME", 0x768922dd, false },
134134 { "KEY_MEDIA_REPEAT", 0x768938c7, false },
135 { "KEY_AGAIN", 0x768938c7, false },
135136 // { "KEY_TITLE", 0x76897887, false }, // Now Playing
136137 // { "KEY_TITLE", 0x7689a25d, false }, // Now Playing
137138 // { "KEY_TEXT", 0x7689f807, false }, // Size
2727
2828 #define TITLE "Squeezelite " VERSION ", Copyright 2012-2015 Adrian Smith, 2015-2021 Ralph Irving."
2929
30 #define CODECS_BASE "flac,pcm,mp3,ogg"
30 #define CODECS_BASE "flac,pcm,ogg"
3131 #if NO_FAAD
3232 #define CODECS_AAC ""
3333 #else
5050 #else
5151 #define CODECS_DSD ""
5252 #endif
53 #define CODECS_MP3 " (mad,mpg for specific mp3 codec)"
53 #if !defined(NO_MAD) && !defined(NO_MPG123)
54 #define CODECS_MP3 ",mp3 (mad,mpg for specific mp3 codec)"
55 #elif defined(NO_MAD) && defined(NO_MPG123)
56 #define CODECS_MP3 ""
57 #else
58 #define CODECS_MP3 ",mp3"
59 #endif
5460
5561 #define CODECS CODECS_BASE CODECS_AAC CODECS_FF CODECS_OPUS CODECS_DSD CODECS_MP3
5662
138144 #if LINUX || FREEBSD || SUN
139145 " -z \t\t\tDaemonize\n"
140146 #endif
141 #if RESAMPLE
142147 " -Z <rate>\t\tReport rate to server in helo as the maximum sample rate we can support\n"
143 #endif
144148 " -t \t\t\tLicense terms\n"
145149 " -? \t\t\tDisplay this help text\n"
146150 "\n"
221225 #endif
222226 #if NO_SSLSYM
223227 " NO_SSLSYM"
228 #endif
229 #if NO_MPG123
230 " NO_MPG123"
231 #endif
232 #if NO_MAD
233 " NO_MAD"
224234 #endif
225235 #if LINKALL
226236 " LINKALL"
349359
350360 while (optind < argc && strlen(argv[optind]) >= 2 && argv[optind][0] == '-') {
351361 char *opt = argv[optind] + 1;
352 if (strstr("oabcCdefmMnNpPrs"
362 if (strstr("oabcCdefmMnNpPrsZ"
353363 #if ALSA
354364 "UVO"
355 #endif
356 /*
357 * only allow '-Z <rate>' override of maxSampleRate
358 * reported by client if built with the capability to resample!
359 */
360 #if RESAMPLE
361 "Z"
362365 #endif
363366 , opt) && optind < argc - 1) {
364367 optarg = argv[optind + 1];
525528 case 'N':
526529 namefile = optarg;
527530 break;
531 case 'Z':
532 maxSampleRate = atoi(optarg);
533 break;
528534 case 'W':
529535 pcm_check_header = true;
530536 break;
555561 } else {
556562 resample = "";
557563 }
558 break;
559 case 'Z':
560 maxSampleRate = atoi(optarg);
561564 break;
562565 #endif
563566 #if DSD
188188
189189 // work backward to unpack samples (if needed)
190190 iptr = (s16_t *) write_buf + count;
191 optr = (ISAMPLE_T *) write_buf + frames * 2;
191 IF_DIRECT(
192 optr = (ISAMPLE_T *) outputbuf->writep + frames * 2;
193 )
194 IF_PROCESS(
195 optr = (ISAMPLE_T *) write_buf + frames * 2;
196 )
192197
193198 if (channels == 2) {
194199 #if BYTES_PER_FRAME == 4
224229 if (stream.state <= DISCONNECT) {
225230 LOG_INFO("partial decode");
226231 UNLOCK_O_direct;
227 UNLOCK_S;
228232 return DECODE_COMPLETE;
229233 } else {
230234 LOG_INFO("no frame decoded");
4646
4747 frames_t frames, size;
4848 bool silence;
49 u8_t flags = output.channels;
4950
5051 s32_t cross_gain_in = 0, cross_gain_out = 0; s32_t *cross_ptr = NULL;
5152
5859 silence = false;
5960
6061 // start when threshold met
61 if (output.state == OUTPUT_BUFFER && frames > output.threshold * output.next_sample_rate / 10 && frames > output.start_frames) {
62 if (output.state == OUTPUT_BUFFER && (frames * BYTES_PER_FRAME) > output.threshold * output.next_sample_rate / 10 && frames > output.start_frames) {
6263 output.state = OUTPUT_RUNNING;
6364 LOG_INFO("start buffer frames: %u", frames);
6465 wake_controller();
255256 }
256257
257258 out_frames = !silence ? min(size, cont_frames) : size;
258
259 wrote = output.write_cb(out_frames, silence, gainL, gainR, cross_gain_in, cross_gain_out, &cross_ptr);
259
260 IF_DSD(
261 if (output.outfmt != PCM) {
262 flags = 0;
263 }
264 )
265
266 wrote = output.write_cb(out_frames, silence, gainL, gainR, flags, cross_gain_in, cross_gain_out, &cross_ptr);
260267
261268 if (wrote <= 0) {
262269 frames -= size;
383390 output.idle_to = (u32_t) idle;
384391
385392 /* Skip test_open for stdout, set default sample rates */
386 if ( output.device[0] == '-' ) {
393 if ( output.device[0] == '-' || user_rates ) {
387394 for (i = 0; i < MAX_SUPPORTED_SAMPLERATES; ++i) {
388395 output.supported_rates[i] = rates[i];
389396 }
392399 if (!test_open(output.device, output.supported_rates, user_rates)) {
393400 LOG_ERROR("unable to open output device: %s", output.device);
394401 exit(0);
395 }
396 }
397
398 if (user_rates) {
399 for (i = 0; i < MAX_SUPPORTED_SAMPLERATES; ++i) {
400 output.supported_rates[i] = rates[i];
401402 }
402403 }
403404
296296 if (snd_pcm_hw_params_test_rate(pcm, hw_params, ref[i], 0) == 0) {
297297 rates[ind++] = ref[i];
298298 }
299 else {
300 LOG_DEBUG("sample rate %u not supported", ref[i]);
301 }
299302 }
300303 }
301304
546549 return 0;
547550 }
548551
549 static int _write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t gainR,
552 static int _write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t gainR, u8_t flags,
550553 s32_t cross_gain_in, s32_t cross_gain_out, s32_t **cross_ptr) {
551554
552555 const snd_pcm_channel_area_t *areas;
593596
594597 outputptr = alsa.mmap ? (areas[0].addr + (areas[0].first + offset * areas[0].step) / 8) : alsa.write_buf;
595598
596 _scale_and_pack_frames(outputptr, inputptr, out_frames, gainL, gainR, output.format);
599 _scale_and_pack_frames(outputptr, inputptr, out_frames, gainL, gainR, flags, output.format);
597600
598601 } else {
599602
600603 outputptr = (void *)inputptr;
601604
602605 if (!silence) {
603
604 if (gainL != FIXED_ONE || gainR!= FIXED_ONE) {
605 _apply_gain(outputbuf, out_frames, gainL, gainR);
606 }
606 _apply_gain(outputbuf, out_frames, gainL, gainR, flags);
607607 }
608608 }
609609
675675 #if GPIO
676676 // Wake up amp
677677 if (gpio_active) {
678 ampstate = 1;
679678 relay(1);
680679 }
681680 if (power_script != NULL) {
682 ampstate = 1;
683681 relay_script(1);
684682 }
685683 #endif
809807 #if GPIO
810808 // Put Amp to Sleep
811809 if (gpio_active){
812 ampstate = 0;
813810 relay(0);
814811 }
815812 if (power_script != NULL ){
816 ampstate = 0;
817813 relay_script(0);
818814 }
819815 #endif
213213 #endif
214214 switch (err) {
215215 case paInvalidSampleRate:
216 LOG_DEBUG("sample rate %u not supported", ref[i]);
216217 continue;
217218 #if WIN
218219 #ifndef PA18API
447448
448449 static u8_t *optr;
449450
450 static int _write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t gainR,
451 static int _write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t gainR, u8_t flags,
451452 s32_t cross_gain_in, s32_t cross_gain_out, s32_t **cross_ptr) {
452453
453454 if (!silence) {
457458 }
458459
459460 if (gainL != FIXED_ONE || gainR!= FIXED_ONE) {
460 _apply_gain(outputbuf, out_frames, gainL, gainR);
461 _apply_gain(outputbuf, out_frames, gainL, gainR, flags);
461462 }
462463
463464 IF_DSD(
4242 return (s32_t)(f * 65536.0F);
4343 }
4444
45 void _scale_and_pack_frames(void *outputptr, s32_t *inputptr, frames_t cnt, s32_t gainL, s32_t gainR, output_format format) {
45 void _scale_and_pack_frames(void *outputptr, s32_t *inputptr, frames_t cnt, s32_t gainL, s32_t gainR, u8_t flags, output_format format) {
46 // in-place copy input samples if mono/combined is used (never happens with DSD active)
47 if ((flags & MONO_LEFT) && (flags & MONO_RIGHT)) {
48 s32_t *ptr = inputptr;
49 frames_t count = cnt;
50 while (count--) {
51 // use 64 bits integer for purists but should really not care
52 *ptr = *(ptr + 1) = ((s64_t) *ptr + (s64_t) *(ptr + 1)) / 2;
53 ptr += 2;
54 }
55 } else if (flags & MONO_RIGHT) {
56 s32_t *ptr = inputptr + 1;
57 frames_t count = cnt;
58 while (count--) {
59 *(ptr - 1) = *ptr;
60 ptr += 2;
61 }
62 } else if (flags & MONO_LEFT) {
63 s32_t *ptr = inputptr;
64 frames_t count = cnt;
65 while (count--) {
66 *(ptr + 1) = *ptr;
67 ptr += 2;
68 }
69 }
70
4671 switch(format) {
4772 #if DSD
4873 case U32_LE:
352377 #if !WIN
353378 inline
354379 #endif
355 void _apply_gain(struct buffer *outputbuf, frames_t count, s32_t gainL, s32_t gainR) {
356 s32_t *ptrL = (s32_t *)(void *)outputbuf->readp;
357 s32_t *ptrR = (s32_t *)(void *)outputbuf->readp + 1;
358 while (count--) {
359 *ptrL = gain(gainL, *ptrL);
360 *ptrR = gain(gainR, *ptrR);
361 ptrL += 2;
362 ptrR += 2;
380 void _apply_gain(struct buffer *outputbuf, frames_t count, s32_t gainL, s32_t gainR, u8_t flags) {
381 if (gainL == FIXED_ONE && gainR == FIXED_ONE && !(flags & (MONO_LEFT | MONO_RIGHT))) {
382 return;
383 } else if ((flags & MONO_LEFT) && (flags & MONO_RIGHT)) {
384 ISAMPLE_T *ptrL = (ISAMPLE_T *)(void *)outputbuf->readp;
385 ISAMPLE_T *ptrR = (ISAMPLE_T *)(void *)outputbuf->readp + 1;
386 while (count--) {
387 *ptrL = *ptrR = (gain(gainL, *ptrL) + gain(gainR, *ptrR)) / 2;
388 ptrL += 2; ptrR += 2;
389 }
390
391 } else if (flags & MONO_RIGHT) {
392 ISAMPLE_T *ptr = (ISAMPLE_T *)(void *)outputbuf->readp + 1;
393 while (count--) {
394 *(ptr - 1) = *ptr = gain(gainR, *ptr);
395 ptr += 2;
396 }
397 } else if (flags & MONO_LEFT) {
398 ISAMPLE_T *ptr = (ISAMPLE_T *)(void *)outputbuf->readp;
399 while (count--) {
400 *(ptr + 1) = *ptr = gain(gainL, *ptr);
401 ptr += 2;
402 }
403 } else {
404 ISAMPLE_T *ptrL = (ISAMPLE_T *)(void *)outputbuf->readp;
405 ISAMPLE_T *ptrR = (ISAMPLE_T *)(void *)outputbuf->readp + 1;
406 while (count--) {
407 *ptrL = gain(gainL, *ptrL);
408 *ptrR = gain(gainR, *ptrR);
409 ptrL += 2; ptrR += 2;
410 }
363411 }
364412 }
361361 d->default_sink_name = strdup(l->name);
362362
363363 if (!d->userdef_rates) {
364 d->rates[0] = l->sample_spec.rate;
365 }
364 d->rates[0] = PA_RATE_MAX;
365 }
366 output.default_sample_rate = l->sample_spec.rate;
366367
367368 *d->sample_spec = l->sample_spec;
368369 }
385386 return true;
386387 }
387388
388 static int _write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t gainR,
389 static int _write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t gainR, u8_t flags,
389390 s32_t cross_gain_in, s32_t cross_gain_out, s32_t **cross_ptr) {
390391 pa_stream_write(pulse.stream, silence ? silencebuf : outputbuf->readp, out_frames * BYTES_PER_FRAME, (pa_free_cb_t)NULL, 0, PA_SEEK_RELATIVE);
391392 return (int)out_frames;
4444 static unsigned buffill;
4545 static int bytes_per_frame;
4646
47 static int _stdout_write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t gainR,
47 static int _stdout_write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t gainR, u8_t flags,
4848 s32_t cross_gain_in, s32_t cross_gain_out, s32_t **cross_ptr) {
4949
5050 u8_t *obuf;
7474 }
7575 )
7676
77 _scale_and_pack_frames(buf + buffill * bytes_per_frame, (s32_t *)(void *)obuf, out_frames, gainL, gainR, output.format);
77 _scale_and_pack_frames(buf + buffill * bytes_per_frame, (s32_t *)(void *)obuf, out_frames, gainL, gainR, flags, output.format);
7878
7979 buffill += out_frames;
8080
6262 #define MAX_DECODE_FRAMES 4096
6363
6464 static u32_t sample_rates[] = {
65 11025, 22050, 32000, 44100, 48000, 8000, 12000, 16000, 24000, 96000, 88200, 176400, 192000, 352800, 384000, 705600, 768000
65 11025, 22050, 32000, 44100, 48000, 8000, 12000, 16000, 24000, 96000, 88200, 176400, 192000, 352800, 384000, 705600, 768000, 1411200, 1536000
6666 };
6767
6868 static u32_t sample_rate;
119119 }
120120
121121 static void sendHELO(bool reconnect, const char *fixed_cap, const char *var_cap, u8_t mac[6]) {
122 #define BASE_CAP "Model=squeezelite,AccuratePlayPoints=1,HasDigitalOut=1,HasPolarityInversion=1,Firmware=" VERSION
122 #define BASE_CAP "Model=squeezelite,AccuratePlayPoints=1,HasDigitalOut=1,HasPolarityInversion=1,Balance=1,Firmware=" VERSION
123123 #define SSL_CAP "CanHTTPS=1"
124124 const char *base_cap;
125125 struct HELO_packet pkt;
379379 output.fade_mode = strm->transition_type - '0';
380380 output.fade_secs = strm->transition_period;
381381 output.invert = (strm->flags & 0x03) == 0x03;
382 LOG_DEBUG("set fade mode: %u", output.fade_mode);
382 output.channels = (strm->flags & 0x0c) >> 2;
383 LOG_DEBUG("set fade mode: %u, channels: %u, invert: %u", output.fade_mode, output.channels, output.invert);
383384 UNLOCK_O;
384385 }
385386 break;
874875
875876 LOCK_O;
876877 snprintf(fixed_cap, FIXED_CAP_LEN, ",ModelName=%s,MaxSampleRate=%u", modelname ? modelname : MODEL_NAME_STRING,
878 #if RESAMPLE
877879 ((maxSampleRate > 0) ? maxSampleRate : output.supported_rates[0]));
880 #else
881 ((maxSampleRate > 0 && maxSampleRate < output.supported_rates[0]) ? maxSampleRate : output.supported_rates[0]));
882 #endif
878883
879884 for (i = 0; i < MAX_CODECS; i++) {
880885 if (codecs[i] && codecs[i]->id && strlen(fixed_cap) < FIXED_CAP_LEN - 10) {
2424 // make may define: PORTAUDIO, SELFPIPE, RESAMPLE, RESAMPLE_MP, VISEXPORT, GPIO, IR, DSD, LINKALL to influence build
2525
2626 #define MAJOR_VERSION "1.9"
27 #define MINOR_VERSION "8"
28 #define MICRO_VERSION "1317"
27 #define MINOR_VERSION "9"
28 #define MICRO_VERSION "1411"
2929
3030 #if defined(CUSTOM_VERSION)
3131 #define VERSION "v" MAJOR_VERSION "." MINOR_VERSION "-" MICRO_VERSION STR(CUSTOM_VERSION)
614614 typedef enum { FADE_UP = 1, FADE_DOWN, FADE_CROSS } fade_dir;
615615 typedef enum { FADE_NONE = 0, FADE_CROSSFADE, FADE_IN, FADE_OUT, FADE_INOUT } fade_mode;
616616
617 #define MAX_SUPPORTED_SAMPLERATES 18
618 #define TEST_RATES = { 768000, 705600, 384000, 352800, 192000, 176400, 96000, 88200, 48000, 44100, 32000, 24000, 22500, 16000, 12000, 11025, 8000, 0 }
617 #define MONO_RIGHT 0x02
618 #define MONO_LEFT 0x01
619 #define MAX_SUPPORTED_SAMPLERATES 20
620 #define TEST_RATES = { 1536000, 1411200, 768000, 705600, 384000, 352800, 192000, 176400, 96000, 88200, 48000, 44100, 32000, 24000, 22500, 16000, 12000, 11025, 8000, 0 }
619621
620622 struct outputstate {
621623 output_state state;
622624 output_format format;
625 u8_t channels;
623626 const char *device;
624627 #if ALSA
625628 unsigned buffer;
631634 unsigned latency;
632635 int pa_hostapi_option;
633636 #endif
634 int (* write_cb)(frames_t out_frames, bool silence, s32_t gainL, s32_t gainR, s32_t cross_gain_in, s32_t cross_gain_out, s32_t **cross_ptr);
637 int (* write_cb)(frames_t out_frames, bool silence, s32_t gainL, s32_t gainR, u8_t flags, s32_t cross_gain_in, s32_t cross_gain_out, s32_t **cross_ptr);
635638 unsigned start_frames;
636639 unsigned frames_played;
637640 unsigned frames_played_dmp;// frames played at the point delay is measured
715718 void output_close_stdout(void);
716719
717720 // output_pack.c
718 void _scale_and_pack_frames(void *outputptr, s32_t *inputptr, frames_t cnt, s32_t gainL, s32_t gainR, output_format format);
721 void _scale_and_pack_frames(void *outputptr, s32_t *inputptr, frames_t cnt, s32_t gainL, s32_t gainR, u8_t flags, output_format format);
719722 void _apply_cross(struct buffer *outputbuf, frames_t out_frames, s32_t cross_gain_in, s32_t cross_gain_out, s32_t **cross_ptr);
720 void _apply_gain(struct buffer *outputbuf, frames_t count, s32_t gainL, s32_t gainR);
723 void _apply_gain(struct buffer *outputbuf, frames_t count, s32_t gainL, s32_t gainR, u8_t flags);
721724 s32_t gain(s32_t gain, s32_t sample);
722725 s32_t to_gain(float f);
723726
758761 struct codec *register_opus(void);
759762 #endif
760763
761 //gpio.c
764 // gpio.c
762765 #if GPIO
763 void relay( int state);
766 void relay(int state);
764767 void relay_script(int state);
765768 int gpio_pin;
766769 bool gpio_active_low;
767770 bool gpio_active;
768771 char *power_script;
769 // my amp state
770 int ampstate;
772
771773 #if RPI
772774 #define PI_INPUT 0
773775 #define PI_OUTPUT 1
129129 <Tool
130130 Name="VCLinkerTool"
131131 AdditionalOptions="/NODEFAULTLIB:LIBCMT"
132 AdditionalDependencies="ws2_32.lib lib\portaudio.lib lib\libogg.lib lib\libvorbisfile.lib lib\libvorbis.lib lib\libmad.lib lib\libFLAC.lib lib\libfaad.lib lib\libmpg123.lib lib\libsoxr.lib lib\libavformat.a lib\libavcodec.a lib\libavutil.a lib\ssleay32.lib lib\libeay32.lib lib\opus.lib lib\opusfile.lib"
132 AdditionalDependencies="ws2_32.lib crypt32.lib lib\portaudio.lib lib\libogg.lib lib\libvorbisfile.lib lib\libvorbis.lib lib\libmad.lib lib\libFLAC.lib lib\libfaad.lib lib\libmpg123.lib lib\libsoxr.lib lib\libavformat.a lib\libavcodec.a lib\libavutil.a lib\ssleay32.lib lib\libeay32.lib lib\opus.lib lib\opusfile.lib"
133133 OutputFile="$(OutDir)\$(ProjectName)-ffmpeg.exe"
134134 LinkIncremental="1"
135135 ModuleDefinitionFile=""
5050 struct streamstate stream;
5151
5252 #if USE_SSL
53 #if WIN
54 #define _last_error() WSAGetLastError()
55 #define ERROR_WOULDBLOCK WSAEWOULDBLOCK
56 #else
5357 #define _last_error() ERROR_WOULDBLOCK
54
58 #endif
5559 static SSL_CTX *SSLctx;
5660 SSL *ssl;
5761
106110
107111 unsigned try = 0;
108112 ssize_t n;
113 int error;
109114
110115 while (len) {
111116 n = _send(ssl, fd, ptr, len, MSG_NOSIGNAL);
112117 if (n <= 0) {
113 if (n < 0 && _last_error() == ERROR_WOULDBLOCK && try < 10) {
114 LOG_SDEBUG("retrying (%d) writing to socket", ++try);
118 error = _last_error();
119 #if WIN
120 if (n < 0 && (error == ERROR_WOULDBLOCK || error == WSAENOTCONN) && try < 10) {
121 #else
122 if (n < 0 && error == ERROR_WOULDBLOCK && try < 10) {
123 #endif
124 LOG_DEBUG("retrying (%d) writing to socket", ++try);
115125 usleep(1000);
116126 continue;
117127 }
118 LOG_INFO("failed writing to socket: %s", strerror(last_error()));
128 LOG_WARN("failed writing to socket: %s", strerror(last_error()));
119129 stream.disconnect = LOCAL_DISCONNECT;
120130 stream.state = DISCONNECT;
121131 wake_controller();
386396 // stream body into streambuf
387397 } else {
388398 int n;
399 int error;
389400
390401 space = min(_buf_space(streambuf), _buf_cont_write(streambuf));
391402 if (stream.meta_interval) {
394405
395406 n = _recv(ssl, fd, streambuf->writep, space, 0);
396407 if (n == 0) {
397 LOG_INFO("end of stream");
408 LOG_INFO("end of stream (%u bytes)", stream.bytes);
398409 _disconnect(DISCONNECT, DISCONNECT_OK);
399410 }
400 if (n < 0 && _last_error() != ERROR_WOULDBLOCK) {
401 LOG_INFO("error reading: %s", strerror(last_error()));
402 _disconnect(DISCONNECT, REMOTE_DISCONNECT);
411 if (n < 0) {
412 error = _last_error();
413 if (error != ERROR_WOULDBLOCK) {
414 LOG_INFO("error reading: %s (%d)", strerror(error), error);
415 _disconnect(DISCONNECT, REMOTE_DISCONNECT);
416 }
403417 }
404418
405419 if (n > 0) {
556570
557571 *host = '\0';
558572 p = strcasestr(header,"Host:");
559 if (p) sscanf(p, "Host:%255[^:]", host);
573 if (p) {
574 sscanf(p, "Host:%255s", host);
575 if ((p = strchr(host, ':')) != NULL) *p = '\0';
576 }
560577
561578 port = ntohs(port);
562579 sock = connect_socket(use_ssl || port == 443);
488488 }
489489 #endif
490490
491 #if WIN && USE_SSL
491 #if WIN
492492 char *strcasestr(const char *haystack, const char *needle) {
493493 size_t length_needle;
494494 size_t length_haystack;
235235
236236 // work backward to unpack samples (if needed)
237237 iptr = (s16_t *) write_buf + count;
238 optr = (ISAMPLE_T *) write_buf + frames * 2;
238 IF_DIRECT(
239 optr = (ISAMPLE_T *) outputbuf->writep + frames * 2;
240 )
241 IF_PROCESS(
242 optr = (ISAMPLE_T *) write_buf + frames * 2;
243 )
239244
240245 if (channels == 2) {
241246 #if BYTES_PER_FRAME == 4