Clang Format

This commit is contained in:
Mike Brady
2017-02-11 12:12:07 +00:00
parent cdc7a76e23
commit cf29625d2c
12 changed files with 252 additions and 246 deletions
+8 -10
View File
@@ -148,19 +148,18 @@ static int init(int argc, char **argv) {
if (config.cfg != NULL) {
/* Get the desired buffer size setting. */
if (config_lookup_int(config.cfg,
"alsa.audio_backend_buffer_desired_length", &value)) {
if (config_lookup_int(config.cfg, "alsa.audio_backend_buffer_desired_length", &value)) {
if ((value < 0) || (value > 66150)) {
inform("The setting alsa.audio_backend_buffer_desired_length is deprecated. "
"Use alsa.audio_backend_buffer_desired_length_in_seconds instead.");
"Use alsa.audio_backend_buffer_desired_length_in_seconds instead.");
die("Invalid alsa audio backend buffer desired length \"%d\". It "
"should be between 0 and "
"66150, default is 6615",
value);
} else {
inform("The setting alsa.audio_backend_buffer_desired_length is deprecated. "
"Use alsa.audio_backend_buffer_desired_length_in_seconds instead.");
config.audio_backend_buffer_desired_length = 1.0*value/44100;
"Use alsa.audio_backend_buffer_desired_length_in_seconds instead.");
config.audio_backend_buffer_desired_length = 1.0 * value / 44100;
}
}
@@ -178,18 +177,17 @@ static int init(int argc, char **argv) {
}
/* Get the latency offset. */
if (config_lookup_int(config.cfg, "alsa.audio_backend_latency_offset",
&value)) {
if (config_lookup_int(config.cfg, "alsa.audio_backend_latency_offset", &value)) {
if ((value < -66150) || (value > 66150)) {
inform("The setting alsa.audio_backend_latency_offset is deprecated. "
"Use alsa.audio_backend_latency_offset_in_seconds instead.");
"Use alsa.audio_backend_latency_offset_in_seconds instead.");
die("Invalid alsa audio backend buffer latency offset \"%d\". It "
"should be between -66150 and +66150, default is 0",
value);
} else {
inform("The setting alsa.audio_backend_latency_offset is deprecated. "
"Use alsa.audio_backend_latency_offset_in_seconds instead.");
config.audio_backend_latency_offset = 1.0*value/44100;
"Use alsa.audio_backend_latency_offset_in_seconds instead.");
config.audio_backend_latency_offset = 1.0 * value / 44100;
}
}
+8 -10
View File
@@ -55,19 +55,18 @@ static int init(int argc, char **argv) {
if (config.cfg != NULL) {
/* Get the desired buffer size setting. */
if (config_lookup_int(config.cfg,
"ao.audio_backend_buffer_desired_length", &value)) {
if (config_lookup_int(config.cfg, "ao.audio_backend_buffer_desired_length", &value)) {
if ((value < 0) || (value > 66150)) {
inform("The setting ao.audio_backend_buffer_desired_length is deprecated. "
"Use ao.audio_backend_buffer_desired_length_in_seconds instead.");
"Use ao.audio_backend_buffer_desired_length_in_seconds instead.");
die("Invalid ao audio backend buffer desired length \"%d\". It "
"should be between 0 and "
"66150, default is 6615",
value);
} else {
inform("The setting ao.audio_backend_buffer_desired_length is deprecated. "
"Use ao.audio_backend_buffer_desired_length_in_seconds instead.");
config.audio_backend_buffer_desired_length = 1.0*value/44100;
"Use ao.audio_backend_buffer_desired_length_in_seconds instead.");
config.audio_backend_buffer_desired_length = 1.0 * value / 44100;
}
}
@@ -85,18 +84,17 @@ static int init(int argc, char **argv) {
}
/* Get the latency offset. */
if (config_lookup_int(config.cfg, "ao.audio_backend_latency_offset",
&value)) {
if (config_lookup_int(config.cfg, "ao.audio_backend_latency_offset", &value)) {
if ((value < -66150) || (value > 66150)) {
inform("The setting ao.audio_backend_latency_offset is deprecated. "
"Use ao.audio_backend_latency_offset_in_seconds instead.");
"Use ao.audio_backend_latency_offset_in_seconds instead.");
die("Invalid ao audio backend buffer latency offset \"%d\". It "
"should be between -66150 and +66150, default is 0",
value);
} else {
inform("The setting ao.audio_backend_latency_offset is deprecated. "
"Use ao.audio_backend_latency_offset_in_seconds instead.");
config.audio_backend_latency_offset = 1.0*value/44100;
"Use ao.audio_backend_latency_offset_in_seconds instead.");
config.audio_backend_latency_offset = 1.0 * value / 44100;
}
}
+8 -10
View File
@@ -85,19 +85,18 @@ static int init(int argc, char **argv) {
die("Can't use \"pipe\" backend for STDOUT. Use the \"stdout\" backend instead.");
/* Get the desired buffer size setting. */
if (config_lookup_int(config.cfg,
"pipe.audio_backend_buffer_desired_length", &value)) {
if (config_lookup_int(config.cfg, "pipe.audio_backend_buffer_desired_length", &value)) {
if ((value < 0) || (value > 66150)) {
inform("The setting pipe.audio_backend_buffer_desired_length is deprecated. "
"Use pipe.audio_backend_buffer_desired_length_in_seconds instead.");
"Use pipe.audio_backend_buffer_desired_length_in_seconds instead.");
die("Invalid pipe audio backend buffer desired length \"%d\". It "
"should be between 0 and "
"66150, default is 6615",
value);
} else {
inform("The setting pipe.audio_backend_buffer_desired_length is deprecated. "
"Use pipe.audio_backend_buffer_desired_length_in_seconds instead.");
config.audio_backend_buffer_desired_length = 1.0*value/44100;
"Use pipe.audio_backend_buffer_desired_length_in_seconds instead.");
config.audio_backend_buffer_desired_length = 1.0 * value / 44100;
}
}
@@ -115,18 +114,17 @@ static int init(int argc, char **argv) {
}
/* Get the latency offset. */
if (config_lookup_int(config.cfg, "pipe.audio_backend_latency_offset",
&value)) {
if (config_lookup_int(config.cfg, "pipe.audio_backend_latency_offset", &value)) {
if ((value < -66150) || (value > 66150)) {
inform("The setting pipe.audio_backend_latency_offset is deprecated. "
"Use pipe.audio_backend_latency_offset_in_seconds instead.");
"Use pipe.audio_backend_latency_offset_in_seconds instead.");
die("Invalid pipe audio backend buffer latency offset \"%d\". It "
"should be between -66150 and +66150, default is 0",
value);
} else {
inform("The setting pipe.audio_backend_latency_offset is deprecated. "
"Use pipe.audio_backend_latency_offset_in_seconds instead.");
config.audio_backend_latency_offset = 1.0*value/44100;
"Use pipe.audio_backend_latency_offset_in_seconds instead.");
config.audio_backend_latency_offset = 1.0 * value / 44100;
}
}
+87 -87
View File
@@ -1,9 +1,9 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <memory.h>
#include "common.h"
#include "audio.h"
#include "common.h"
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <soundio/soundio.h>
@@ -15,72 +15,71 @@ struct SoundIo *soundio;
struct SoundIoDevice *device;
struct SoundIoRingBuffer *ring_buffer = NULL;
static int min_int(int a, int b) {
return (a < b) ? a : b;
}
static int min_int(int a, int b) { return (a < b) ? a : b; }
static void write_callback(struct SoundIoOutStream *outstream,
int frame_count_min, int frame_count_max)
{
static void write_callback(struct SoundIoOutStream *outstream, int frame_count_min,
int frame_count_max) {
struct SoundIoChannelArea *areas;
int frame_count;
int err;
int frame_count;
int err;
char *read_ptr = soundio_ring_buffer_read_ptr(ring_buffer);
int fill_bytes = soundio_ring_buffer_fill_count(ring_buffer);
int fill_count = fill_bytes / outstream->bytes_per_frame;
char *read_ptr = soundio_ring_buffer_read_ptr(ring_buffer);
int fill_bytes = soundio_ring_buffer_fill_count(ring_buffer);
int fill_count = fill_bytes / outstream->bytes_per_frame;
debug(3, "[--->>] frame_count_min: %d , frame_count_max: %d , fill_bytes: %d , fill_count: %d , outstream->bytes_per_frame: %d", frame_count_min, frame_count_max, fill_bytes, fill_count, outstream->bytes_per_frame );
debug(3, "[--->>] frame_count_min: %d , frame_count_max: %d , fill_bytes: %d , fill_count: %d , "
"outstream->bytes_per_frame: %d",
frame_count_min, frame_count_max, fill_bytes, fill_count, outstream->bytes_per_frame);
if (frame_count_min > fill_count) {
int frame_count = frame_count_min;
if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))){
debug(0, "[--->>] begin write error: %s", soundio_strerror(err));
}
for (int frame = 0; frame < frame_count; frame += 1) {
for (int ch = 0; ch < outstream->layout.channel_count; ch += 1) {
memset(areas[ch].ptr, 0, outstream->bytes_per_sample);
areas[ch].ptr += areas[ch].step;
}
}
if ((err = soundio_outstream_end_write(outstream)))
debug(0,"[--->>] end write error: %s", soundio_strerror(err));
return;
}
if (frame_count_min > fill_count) {
int frame_count = frame_count_min;
if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))) {
debug(0, "[--->>] begin write error: %s", soundio_strerror(err));
}
for (int frame = 0; frame < frame_count; frame += 1) {
for (int ch = 0; ch < outstream->layout.channel_count; ch += 1) {
memset(areas[ch].ptr, 0, outstream->bytes_per_sample);
areas[ch].ptr += areas[ch].step;
}
}
if ((err = soundio_outstream_end_write(outstream)))
debug(0, "[--->>] end write error: %s", soundio_strerror(err));
return;
}
int read_count = min_int(frame_count_max, fill_count);
int frames_left = read_count;
int read_count = min_int(frame_count_max, fill_count);
int frames_left = read_count;
while (frames_left > 0) {
int frame_count = frames_left;
while (frames_left > 0) {
int frame_count = frames_left;
if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count)))
debug(0, "[--->>] begin write error: %s", soundio_strerror(err));
if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count)))
debug(0, "[--->>] begin write error: %s", soundio_strerror(err));
if (frame_count <= 0)
break;
if (frame_count <= 0)
break;
for (int frame = 0; frame < frame_count; frame += 1) {
for (int ch = 0; ch < outstream->layout.channel_count; ch += 1) {
memcpy(areas[ch].ptr, read_ptr, outstream->bytes_per_sample);
areas[ch].ptr += areas[ch].step;
read_ptr += outstream->bytes_per_sample;
}
}
for (int frame = 0; frame < frame_count; frame += 1) {
for (int ch = 0; ch < outstream->layout.channel_count; ch += 1) {
memcpy(areas[ch].ptr, read_ptr, outstream->bytes_per_sample);
areas[ch].ptr += areas[ch].step;
read_ptr += outstream->bytes_per_sample;
}
}
if ((err = soundio_outstream_end_write(outstream)))
debug(0, "[--->>] end write error: %s", soundio_strerror(err));
if ((err = soundio_outstream_end_write(outstream)))
debug(0, "[--->>] end write error: %s", soundio_strerror(err));
frames_left -= frame_count;
}
frames_left -= frame_count;
}
debug(3,"[--->>] Wrote: %d", read_count * outstream->bytes_per_frame);
soundio_ring_buffer_advance_read_ptr(ring_buffer, read_count * outstream->bytes_per_frame);
debug(3, "[--->>] Wrote: %d", read_count * outstream->bytes_per_frame);
soundio_ring_buffer_advance_read_ptr(ring_buffer, read_count * outstream->bytes_per_frame);
}
static void underflow_callback(struct SoundIoOutStream *outstream) {
static int count = 0;
debug(0, "underflow %d\n", ++count);
static int count = 0;
debug(0, "underflow %d\n", ++count);
}
static int init(int argc, char **argv) {
@@ -89,25 +88,25 @@ static int init(int argc, char **argv) {
soundio = soundio_create();
if (!soundio) {
debug(0, "out of memory\n");
return 1;
debug(0, "out of memory\n");
return 1;
}
if ((err = soundio_connect_backend(soundio, SoundIoBackendCoreAudio))) {
debug(0, "error connecting: %s", soundio_strerror(err));
return 1;
debug(0, "error connecting: %s", soundio_strerror(err));
return 1;
}
soundio_flush_events(soundio);
int default_out_device_index = soundio_default_output_device_index(soundio);
if (default_out_device_index < 0) {
debug(0, "no output device found");
return 1;
debug(0, "no output device found");
return 1;
}
device = soundio_get_output_device(soundio, default_out_device_index);
if (!device) {
debug(0, "out of memory");
return 1;
debug(0, "out of memory");
return 1;
}
debug(0, "Output device: %s\n", device->name);
return 0;
@@ -139,21 +138,21 @@ static void start(int sample_rate, int sample_format) {
// outstream->software_latency = 0;
if ((err = soundio_outstream_open(outstream))) {
debug(0, "unable to open device: %s", soundio_strerror(err));
debug(0, "unable to open device: %s", soundio_strerror(err));
}
if (outstream->layout_error)
debug(0, "unable to set channel layout: %s\n", soundio_strerror(outstream->layout_error));
debug(0, "unable to set channel layout: %s\n", soundio_strerror(outstream->layout_error));
int capacity = outstream->sample_rate * outstream->bytes_per_frame;
ring_buffer = soundio_ring_buffer_create(soundio, capacity);
if (!ring_buffer)
debug(0, "unable to create ring buffer: out of memory");
debug(0, "unable to create ring buffer: out of memory");
char *buf = soundio_ring_buffer_write_ptr(ring_buffer);
memset(buf, 0, capacity);
soundio_ring_buffer_advance_write_ptr(ring_buffer, capacity);
if ((err = soundio_outstream_start(outstream))) {
debug(0, "unable to start outstream: %s", soundio_strerror(err));
debug(0, "unable to start outstream: %s", soundio_strerror(err));
}
debug(1, "libsoundio output started\n");
@@ -167,12 +166,13 @@ static void play(short buf[], int samples) {
int left_bytes = samples * outstream->bytes_per_frame;
char *write_ptr = soundio_ring_buffer_write_ptr(ring_buffer);
debug(3, "[<<---] samples: %d , size: %d", samples, left_bytes );
debug(3, "[<<---] samples: %d , size: %d", samples, left_bytes);
write_bytes = min_int(left_bytes, free_bytes);
debug(3, "[<<---] left_bytes: %d, write_bytes: %d, free_bytes: %d\n", left_bytes, write_bytes, free_bytes);
debug(3, "[<<---] left_bytes: %d, write_bytes: %d, free_bytes: %d\n", left_bytes, write_bytes,
free_bytes);
if (write_bytes){
memcpy(write_ptr, (char*) buf, write_bytes);
if (write_bytes) {
memcpy(write_ptr, (char *)buf, write_bytes);
written_bytes += write_bytes;
soundio_ring_buffer_advance_write_ptr(ring_buffer, write_bytes);
debug(3, "[<<---] Written to buffer : %d\n", written_bytes);
@@ -182,17 +182,17 @@ static void play(short buf[], int samples) {
static void parameters(audio_parameters *info) {
info->minimum_volume_dB = -30.0;
info->maximum_volume_dB = 0.0;
debug(2, "Parameters\n");
debug(2, "Current Volume dB: %f\n", info->current_volume_dB);
debug(2, "Minimum Volume dB: %d\n", info->minimum_volume_dB);
debug(2, "Maximum Volume dB: %d\n", info->maximum_volume_dB);
debug(2, "Parameters\n");
debug(2, "Current Volume dB: %f\n", info->current_volume_dB);
debug(2, "Minimum Volume dB: %d\n", info->minimum_volume_dB);
debug(2, "Maximum Volume dB: %d\n", info->maximum_volume_dB);
}
static void stop(void) {
soundio_outstream_destroy(outstream);
soundio_ring_buffer_clear(ring_buffer);
debug(1, "libsoundio output stopped\n");
}
}
static void flush(void) {
soundio_ring_buffer_clear(ring_buffer);
@@ -202,14 +202,14 @@ static void flush(void) {
static void help(void) { printf(" There are no options for libsoundio.\n"); }
audio_output audio_soundio = {.name = "soundio",
.help = &help,
.init = &init,
.deinit = &deinit,
.start = &start,
.stop = &stop,
.flush = &flush,
.delay = NULL,
.play = &play,
.volume = NULL,
.parameters = &parameters,
.mute = NULL};
.help = &help,
.init = &init,
.deinit = &deinit,
.start = &start,
.stop = &stop,
.flush = &flush,
.delay = NULL,
.play = &play,
.volume = NULL,
.parameters = &parameters,
.mute = NULL};
+10 -13
View File
@@ -56,19 +56,18 @@ static int init(int argc, char **argv) {
if (config.cfg != NULL) {
/* Get the desired buffer size setting. */
if (config_lookup_int(config.cfg,
"stdout.audio_backend_buffer_desired_length", &value)) {
if (config_lookup_int(config.cfg, "stdout.audio_backend_buffer_desired_length", &value)) {
if ((value < 0) || (value > 66150)) {
inform("The setting audio_backend_buffer_desired_length is deprecated. "
"Use audio_backend_buffer_desired_length_in_seconds instead.");
"Use audio_backend_buffer_desired_length_in_seconds instead.");
die("Invalid stdout audio backend buffer desired length \"%d\". It "
"should be between 0 and "
"66150, default is 6615",
value);
} else {
inform("The stdout.setting audio_backend_buffer_desired_length is deprecated. "
"Use stdout.audio_backend_buffer_desired_length_in_seconds instead.");
config.audio_backend_buffer_desired_length = 1.0*value/44100;
"Use stdout.audio_backend_buffer_desired_length_in_seconds instead.");
config.audio_backend_buffer_desired_length = 1.0 * value / 44100;
}
}
@@ -86,23 +85,23 @@ static int init(int argc, char **argv) {
}
/* Get the latency offset. */
if (config_lookup_int(config.cfg, "stdout.audio_backend_latency_offset",
&value)) {
if (config_lookup_int(config.cfg, "stdout.audio_backend_latency_offset", &value)) {
if ((value < -66150) || (value > 66150)) {
inform("The setting stdout.audio_backend_latency_offset is deprecated. "
"Use stdout.audio_backend_latency_offset_in_seconds instead.");
"Use stdout.audio_backend_latency_offset_in_seconds instead.");
die("Invalid stdout audio backend buffer latency offset \"%d\". It "
"should be between -66150 and +66150, default is 0",
value);
} else {
inform("The setting stdout.audio_backend_latency_offset is deprecated. "
"Use stdout.audio_backend_latency_offset_in_seconds instead.");
config.audio_backend_latency_offset = 1.0*value/44100;
"Use stdout.audio_backend_latency_offset_in_seconds instead.");
config.audio_backend_latency_offset = 1.0 * value / 44100;
}
}
/* Get the latency offset. */
if (config_lookup_float(config.cfg, "stdout.audio_backend_latency_offset_in_seconds", &dvalue)) {
if (config_lookup_float(config.cfg, "stdout.audio_backend_latency_offset_in_seconds",
&dvalue)) {
if ((dvalue < -1.0) || (dvalue > 1.5)) {
die("Invalid stdout audio backend buffer latency offset time \"%f\". It "
"should be between -1.0 and +1.5, default is 0 seconds",
@@ -111,8 +110,6 @@ static int init(int argc, char **argv) {
config.audio_backend_latency_offset = dvalue;
}
}
}
return 0;
}
+18 -19
View File
@@ -68,16 +68,15 @@
#endif
#ifdef HAVE_LIBMBEDTLS
#include <mbedtls/version.h>
#include <mbedtls/base64.h>
#include <mbedtls/x509.h>
#include <mbedtls/md.h>
#include "mbedtls/entropy.h"
#include "mbedtls/ctr_drbg.h"
#include "mbedtls/entropy.h"
#include <mbedtls/base64.h>
#include <mbedtls/md.h>
#include <mbedtls/version.h>
#include <mbedtls/x509.h>
#endif
#include <libdaemon/dlog.h>
// true if Shairport Sync is supposed to be sending output to the output device, false otherwise
@@ -357,24 +356,25 @@ uint8_t *rsa_apply(uint8_t *input, int inlen, int *outlen, int mode) {
mbedtls_entropy_init(&entropy);
mbedtls_ctr_drbg_init(&ctr_drbg);
mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
(const unsigned char *)pers, strlen(pers));
mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *)pers,
strlen(pers));
mbedtls_pk_init(&pkctx);
rc = mbedtls_pk_parse_key(&pkctx, (unsigned char *)super_secret_key, sizeof(super_secret_key), NULL, 0);
rc = mbedtls_pk_parse_key(&pkctx, (unsigned char *)super_secret_key, sizeof(super_secret_key),
NULL, 0);
if (rc != 0)
debug(1, "Error %d reading the private key.", rc);
uint8_t *outbuf = NULL;
trsa = mbedtls_pk_rsa(pkctx);
trsa = mbedtls_pk_rsa(pkctx);
switch (mode) {
case RSA_MODE_AUTH:
mbedtls_rsa_set_padding(trsa, MBEDTLS_RSA_PKCS_V15, MBEDTLS_MD_NONE);
outbuf = malloc(trsa->len);
rc = mbedtls_rsa_pkcs1_encrypt(trsa, mbedtls_ctr_drbg_random, &ctr_drbg, MBEDTLS_RSA_PRIVATE,
inlen, input, outbuf);
inlen, input, outbuf);
if (rc != 0)
debug(1, "mbedtls_pk_encrypt error %d.", rc);
*outlen = trsa->len;
@@ -382,8 +382,8 @@ uint8_t *rsa_apply(uint8_t *input, int inlen, int *outlen, int mode) {
case RSA_MODE_KEY:
mbedtls_rsa_set_padding(trsa, MBEDTLS_RSA_PKCS_V21, MBEDTLS_MD_SHA1);
outbuf = malloc(trsa->len);
rc = mbedtls_rsa_pkcs1_decrypt(trsa, mbedtls_ctr_drbg_random, &ctr_drbg, MBEDTLS_RSA_PRIVATE,
&olen, input, outbuf, trsa->len);
rc = mbedtls_rsa_pkcs1_decrypt(trsa, mbedtls_ctr_drbg_random, &ctr_drbg, MBEDTLS_RSA_PRIVATE,
&olen, input, outbuf, trsa->len);
if (rc != 0)
debug(1, "mbedtls_pk_decrypt error %d.", rc);
*outlen = olen;
@@ -745,16 +745,16 @@ uint64_t *ranarray;
int ranarraynext;
void ranarrayinit() {
ranarray = (uint64_t*)malloc(ranarraylength*sizeof(uint64_t));
ranarray = (uint64_t *)malloc(ranarraylength * sizeof(uint64_t));
int i;
for (i=0;i<ranarraylength;i++)
ranarray[i]=r64u();
ranarraynext=0;
for (i = 0; i < ranarraylength; i++)
ranarray[i] = r64u();
ranarraynext = 0;
}
uint64_t ranarrayval() {
uint64_t v = ranarray[ranarraynext];
ranarraynext = (ranarraynext++)%ranarraylength;
ranarraynext = (ranarraynext++) % ranarraylength;
}
void r64arrayinit() { ranarrayinit(); }
@@ -762,4 +762,3 @@ void r64arrayinit() { ranarrayinit(); }
uint64_t ranarray64u() { return (ranarrayval()); }
int64_t ranarray64i() { return (ranarrayval(&rx) >> 1); }
+2 -2
View File
@@ -87,7 +87,7 @@ typedef struct {
int udp_port_base;
int udp_port_range;
int ignore_volume_control;
int volume_max_db_set; // set to 1 if a maximum volume db has been set
int volume_max_db_set; // set to 1 if a maximum volume db has been set
int volume_max_db;
int no_sync; // disable synchronisation, even if it's available
int no_mmap; // disable use of mmap-based output, even if it's available
@@ -125,7 +125,7 @@ typedef struct {
char *configfile;
char *regtype; // The regtype is the service type followed by the protocol, separated by a dot, by
// default “_raop._tcp.”.
char *interface; // a string containg the interface name, or NULL if nothing specified
char *interface; // a string containg the interface name, or NULL if nothing specified
int interface_index; // only valid if the interface string is non-NULL
double audio_backend_buffer_desired_length; // this will be the length in seconds of the
// audio backend buffer -- the DAC buffer for ALSA
+5 -6
View File
@@ -205,7 +205,7 @@ static void register_service(AvahiClient *c) {
int ret;
AvahiIfIndex selected_interface;
if (config.interface!=NULL)
if (config.interface != NULL)
selected_interface = config.interface_index;
else
selected_interface = AVAHI_IF_UNSPEC;
@@ -261,9 +261,8 @@ static void client_callback(AvahiClient *c, AvahiClientState state,
c = NULL;
group = NULL;
if (!(client = avahi_client_new(avahi_threaded_poll_get(tpoll),
AVAHI_CLIENT_NO_FAIL, client_callback,
userdata, &err))) {
if (!(client = avahi_client_new(avahi_threaded_poll_get(tpoll), AVAHI_CLIENT_NO_FAIL,
client_callback, userdata, &err))) {
warn("avahi: failed to create client object: %s", avahi_strerror(err));
avahi_threaded_poll_quit(tpoll);
}
@@ -297,8 +296,8 @@ static int avahi_register(char *srvname, int srvport) {
warn("couldn't create avahi threaded tpoll!");
return -1;
}
if (!(client =
avahi_client_new(avahi_threaded_poll_get(tpoll), AVAHI_CLIENT_NO_FAIL, client_callback, NULL, &err))) {
if (!(client = avahi_client_new(avahi_threaded_poll_get(tpoll), AVAHI_CLIENT_NO_FAIL,
client_callback, NULL, &err))) {
warn("couldn't create avahi client: %s!", avahi_strerror(err));
return -1;
}
+18 -16
View File
@@ -71,9 +71,10 @@ static int mdns_tinysvcmdns_register(char *apname, int port) {
// Look for an ipv4/ipv6 non-loopback interface to use as the main one.
for (ifa = ifalist; ifa != NULL; ifa = ifa->ifa_next) {
// only check for the named interface, if specified
if ((config.interface==NULL) || (strcmp(config.interface,ifa->ifa_name)==0)) {
if (!(ifa->ifa_flags & IFF_LOOPBACK) && ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET) {
if ((config.interface == NULL) || (strcmp(config.interface, ifa->ifa_name) == 0)) {
if (!(ifa->ifa_flags & IFF_LOOPBACK) && ifa->ifa_addr &&
ifa->ifa_addr->sa_family == AF_INET) {
uint32_t main_ip = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
mdnsd_set_hostname(svr, hostname, main_ip); // TTL should be 120 seconds
@@ -96,21 +97,22 @@ static int mdns_tinysvcmdns_register(char *apname, int port) {
// Skip the first one, it was already added by set_hostname
for (ifa = ifa->ifa_next; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_flags & IFF_LOOPBACK) // Skip loop-back interfaces
continue;
continue;
// only check for the named interface, if specified
if ((config.interface==NULL) || (strcmp(config.interface,ifa->ifa_name)==0)) {
if ((config.interface == NULL) || (strcmp(config.interface, ifa->ifa_name) == 0)) {
switch (ifa->ifa_addr->sa_family) {
case AF_INET: { // ipv4
uint32_t ip = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
struct rr_entry *a_e = rr_create_a(create_nlabel(hostname), ip); // TTL should be 120 seconds
mdnsd_add_rr(svr, a_e);
} break;
case AF_INET6: { // ipv6
struct in6_addr *addr = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;
struct rr_entry *aaaa_e =
rr_create_aaaa(create_nlabel(hostname), addr); // TTL should be 120 seconds
mdnsd_add_rr(svr, aaaa_e);
} break;
case AF_INET: { // ipv4
uint32_t ip = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
struct rr_entry *a_e =
rr_create_a(create_nlabel(hostname), ip); // TTL should be 120 seconds
mdnsd_add_rr(svr, a_e);
} break;
case AF_INET6: { // ipv6
struct in6_addr *addr = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;
struct rr_entry *aaaa_e =
rr_create_aaaa(create_nlabel(hostname), addr); // TTL should be 120 seconds
mdnsd_add_rr(svr, aaaa_e);
} break;
}
}
}
+32 -25
View File
@@ -679,8 +679,10 @@ static inline void process_sample(int32_t sample, char **outp, enum sps_format_t
}
dither_mask -= 1;
// int64_t r = r64i();
int64_t r = ranarray64i(); // use an array of precalculated pseudorandom numbers rather than calculating them on the fly. Should be easier on low-powered processors
int64_t r = ranarray64i(); // use an array of precalculated pseudorandom numbers rather than
// calculating them on the fly. Should be easier on low-powered
// processors
int64_t tpdf = (r & dither_mask) - (previous_random_number & dither_mask);
previous_random_number = r;
// add dither, allowing for clipping
@@ -2269,7 +2271,7 @@ void player_volume(double airplay_volume) {
// don't have a hardware mixer
hw_max_db = hw_min_db = hw_range_db = 0;
}
int32_t sw_min_db = -9630;
int32_t sw_max_db = 0;
int32_t sw_range_db = sw_max_db - sw_min_db;
@@ -2278,25 +2280,29 @@ void player_volume(double airplay_volume) {
if (config.volume_range_db)
desired_range_db = (int32_t)trunc(config.volume_range_db * 100);
if (config.volume_max_db_set) {
if (config.volume_max_db_set) {
if (hw_range_db) {
if (((config.volume_max_db*100)<hw_max_db) && ((config.volume_max_db*100)>hw_min_db)) {
hw_max_db = (int)config.volume_max_db*100;
hw_range_db = hw_max_db-hw_min_db;
if (((config.volume_max_db * 100) < hw_max_db) &&
((config.volume_max_db * 100) > hw_min_db)) {
hw_max_db = (int)config.volume_max_db * 100;
hw_range_db = hw_max_db - hw_min_db;
} else {
inform("The volume_max_db setting is out of range of the hardware mixers's limits of %d dB to %d dB. It will be ignored.", (int)(hw_max_db/100), (int)(hw_min_db/100));
inform("The volume_max_db setting is out of range of the hardware mixers's limits of %d dB "
"to %d dB. It will be ignored.",
(int)(hw_max_db / 100), (int)(hw_min_db / 100));
}
} else {
if (((config.volume_max_db*100)<sw_max_db) && ((config.volume_max_db*100)>sw_min_db)) {
sw_max_db = (int)config.volume_max_db*100;
sw_range_db = sw_max_db-sw_min_db;
if (((config.volume_max_db * 100) < sw_max_db) &&
((config.volume_max_db * 100) > sw_min_db)) {
sw_max_db = (int)config.volume_max_db * 100;
sw_range_db = sw_max_db - sw_min_db;
} else {
inform("The volume_max_db setting is out of range of the software attenuation's limits of 0 dB to -96.3 dB. It will be ignored.");
inform("The volume_max_db setting is out of range of the software attenuation's limits of "
"0 dB to -96.3 dB. It will be ignored.");
}
}
}
}
}
if (desired_range_db) {
// debug(1,"An attenuation range of %d is requested.",desired_range_db);
// we have a desired volume range.
@@ -2339,16 +2345,17 @@ void player_volume(double airplay_volume) {
}
}
/*
if (config.volume_max_db_set) {
if ((config.volume_max_db*100<=max_db) && (config.volume_max_db*100>=min_db)) {
debug(1,"Reducing the maximum volume from %d to %d.",max_db/100,config.volume_max_db);
max_db = (int)(config.volume_max_db*100);
} else {
inform("The value of volume_max_db is invalid. It must be in the range %d to %d.",max_db,min_db);
}
}
*/
/*
if (config.volume_max_db_set) {
if ((config.volume_max_db*100<=max_db) && (config.volume_max_db*100>=min_db)) {
debug(1,"Reducing the maximum volume from %d to %d.",max_db/100,config.volume_max_db);
max_db = (int)(config.volume_max_db*100);
} else {
inform("The value of volume_max_db is invalid. It must be in the range %d to
%d.",max_db,min_db);
}
}
*/
double hardware_attenuation, software_attenuation;
double scaled_attenuation = hw_min_db + sw_min_db;
+3 -4
View File
@@ -1625,8 +1625,7 @@ static int rtsp_auth(char **nonce, rtsp_message *req, rtsp_message *resp) {
mbedtls_md5_update(&tctx, (unsigned char *)":", 1);
mbedtls_md5_update(&tctx, (const unsigned char *)realm, strlen(realm));
mbedtls_md5_update(&tctx, (unsigned char *)":", 1);
mbedtls_md5_update(&tctx, (const unsigned char *)config.password,
strlen(config.password));
mbedtls_md5_update(&tctx, (const unsigned char *)config.password, strlen(config.password));
mbedtls_md5_finish(&tctx, digest_urp);
mbedtls_md5_starts(&tctx);
mbedtls_md5_update(&tctx, (const unsigned char *)req->method, strlen(req->method));
@@ -1951,8 +1950,8 @@ void rtsp_listen_loop(void) {
inet_ntop(AF_INET, &(sa->sin_addr), remote_ip4, INET_ADDRSTRLEN);
unsigned short int rport = ntohs(sa->sin_port);
#ifdef CONFIG_METADATA
send_ssnc_metadata('clip', strdup(remote_ip4), strlen(remote_ip4) , 1);
send_ssnc_metadata('svip', strdup(ip4), strlen(ip4) , 1);
send_ssnc_metadata('clip', strdup(remote_ip4), strlen(remote_ip4), 1);
send_ssnc_metadata('svip', strdup(ip4), strlen(ip4), 1);
#endif
debug(1, "New RTSP connection from %s:%u to self at %s:%u.", remote_ip4, rport, ip4,
tport);
+53 -44
View File
@@ -31,6 +31,7 @@
#include <libconfig.h>
#include <libgen.h>
#include <memory.h>
#include <net/if.h>
#include <popt.h>
#include <signal.h>
#include <stdio.h>
@@ -38,7 +39,6 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <net/if.h>
#include <unistd.h>
#include "config.h"
@@ -198,12 +198,13 @@ void usage(char *progname) {
printf(" -v, --verbose -v print debug information; -vv more; -vvv lots.\n");
printf(" -p, --port=PORT set RTSP listening port.\n");
printf(" -a, --name=NAME set advertised name.\n");
// printf(" -A, --AirPlayLatency=FRAMES [Deprecated] Set the latency for audio sent from an "
// "AirPlay device.\n");
// printf(" The default is to set it automatically.\n");
// printf(" -i, --iTunesLatency=FRAMES [Deprecated] Set the latency for audio sent from iTunes "
// "10 or later.\n");
// printf(" The default is to set it automatically.\n");
// printf(" -A, --AirPlayLatency=FRAMES [Deprecated] Set the latency for audio sent from an "
// "AirPlay device.\n");
// printf(" The default is to set it automatically.\n");
// printf(" -i, --iTunesLatency=FRAMES [Deprecated] Set the latency for audio sent from iTunes
// "
// "10 or later.\n");
// printf(" The default is to set it automatically.\n");
printf(" -L, --latency=FRAMES [Deprecated] Set the latency for audio sent from an unknown "
"device.\n");
printf(" The default is to set it automatically.\n");
@@ -230,13 +231,15 @@ void usage(char *progname) {
printf(" -m, --mdns=BACKEND force the use of BACKEND to advertize the service.\n");
printf(" if no mdns provider is specified,\n");
printf(" shairport tries them all until one works.\n");
printf(" -r, --resync=THRESHOLD [Deprecated] resync if error exceeds this number of frames. Set to 0 to "
printf(" -r, --resync=THRESHOLD [Deprecated] resync if error exceeds this number of frames. "
"Set to 0 to "
"stop resyncing.\n");
printf(" -t, --timeout=SECONDS go back to idle mode from play mode after a break in "
"communications of this many seconds (default 120). Set to 0 never to exit play mode.\n");
printf(" --statistics print some interesting statistics -- output to the logfile "
"if running as a daemon.\n");
printf(" --tolerance=TOLERANCE [Deprecated] allow a synchronization error of TOLERANCE frames (default "
printf(" --tolerance=TOLERANCE [Deprecated] allow a synchronization error of TOLERANCE "
"frames (default "
"88) before trying to correct it.\n");
printf(" --password=PASSWORD require PASSWORD to connect. Default is not to require a "
"password.\n");
@@ -259,9 +262,9 @@ int parse_options(int argc, char **argv) {
char *stuffing = NULL; /* used for picking up the stuffing option */
signed char c; /* used for argument parsing */
int i = 0; /* used for tracking options */
int fResyncthreshold = (int)(config.resyncthreshold*44100);
int fTolerance = (int)(config.tolerance*44100);
poptContext optCon; /* context for parsing command-line options */
int fResyncthreshold = (int)(config.resyncthreshold * 44100);
int fTolerance = (int)(config.tolerance * 44100);
poptContext optCon; /* context for parsing command-line options */
struct poptOption optionsTable[] = {
{"verbose", 'v', POPT_ARG_NONE, NULL, 'v', NULL},
{"disconnectFromOutput", 'D', POPT_ARG_NONE, NULL, 0, NULL},
@@ -318,28 +321,33 @@ int parse_options(int argc, char **argv) {
inform("Warning: the option -R or --reconnectToOutput is deprecated.");
break;
case 'A':
inform("Warning: the option -A or --AirPlayLatency is deprecated. This setting is now automatically received from the AirPlay device.");
inform("Warning: the option -A or --AirPlayLatency is deprecated. This setting is now "
"automatically received from the AirPlay device.");
break;
case 'i':
inform("Warning: the option -i or --iTunesLatency is deprecated. This setting is now automatically received from iTunes");
inform("Warning: the option -i or --iTunesLatency is deprecated. This setting is now "
"automatically received from iTunes");
break;
case 'f':
inform("Warning: the option --forkedDaapdLatency is deprecated. This setting is now automatically received from forkedDaapd");
inform("Warning: the option --forkedDaapdLatency is deprecated. This setting is now "
"automatically received from forkedDaapd");
break;
case 'r':
inform("Warning: the option -r or --resync is deprecated. Please use the \"resync_threshold_in_seconds\" setting in the config file instead.");
inform("Warning: the option -r or --resync is deprecated. Please use the "
"\"resync_threshold_in_seconds\" setting in the config file instead.");
break;
case 'z':
inform("Warning: the option --tolerance is deprecated. Please use the \"drift_tolerance_in_seconds\" setting in the config file instead.");
inform("Warning: the option --tolerance is deprecated. Please use the "
"\"drift_tolerance_in_seconds\" setting in the config file instead.");
break;
}
}
}
if (c < -1) {
die("%s: %s", poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(c));
}
config.resyncthreshold = 1.0*fResyncthreshold/44100;
config.tolerance = 1.0*fTolerance/44100;
config.resyncthreshold = 1.0 * fResyncthreshold / 44100;
config.tolerance = 1.0 * fTolerance / 44100;
config_setting_t *setting;
const char *str = 0;
@@ -437,14 +445,14 @@ int parse_options(int argc, char **argv) {
if (config_lookup_int(config.cfg, "general.drift", &value)) {
inform("The drift setting is deprecated. Use "
"drift_tolerance_in_seconds instead");
config.tolerance = 1.0*value/44100;
config.tolerance = 1.0 * value / 44100;
}
/* The old resync setting. */
if (config_lookup_int(config.cfg, "general.resync_threshold", &value)) {
inform("The resync_threshold setting is deprecated. Use "
"resync_threshold_in_seconds instead");
config.resyncthreshold = 1.0*value/44100;
config.resyncthreshold = 1.0 * value / 44100;
}
/* Get the drift tolerance setting. */
@@ -474,10 +482,10 @@ int parse_options(int argc, char **argv) {
else
die("Invalid ignore_volume_control option choice \"%s\". It should be \"yes\" or \"no\"");
}
/* Get the optional volume_max_db setting. */
/* Get the optional volume_max_db setting. */
if (config_lookup_float(config.cfg, "general.volume_max_db", &dvalue)) {
debug(1,"Max volume setting of %f dB",dvalue);
debug(1, "Max volume setting of %f dB", dvalue);
config.volume_max_db = dvalue;
config.volume_max_db_set = 1;
}
@@ -501,39 +509,40 @@ int parse_options(int argc, char **argv) {
/* Get the interface to listen on, if specified Default is all interfaces */
/* we keep the interface name and the index */
if (config_lookup_string(config.cfg, "general.interface", &str))
if (config_lookup_string(config.cfg, "general.interface", &str))
config.interface = strdup(str);
if (config_lookup_string(config.cfg, "general.interface", &str)) {
if (config_lookup_string(config.cfg, "general.interface", &str)) {
int specified_interface_found = 0;
struct if_nameindex *if_ni, *i;
if_ni = if_nameindex();
if (if_ni == NULL) {
debug(1,"Can't get a list of interface names.");
debug(1, "Can't get a list of interface names.");
} else {
for (i = if_ni; ! (i->if_index == 0 && i->if_name == NULL); i++) {
// printf("%u: %s\n", i->if_index, i->if_name);
if (strcmp(i->if_name,str)==0) {
for (i = if_ni; !(i->if_index == 0 && i->if_name == NULL); i++) {
// printf("%u: %s\n", i->if_index, i->if_name);
if (strcmp(i->if_name, str) == 0) {
config.interface_index = i->if_index;
specified_interface_found = 1;
}
}
}
if_freenameindex(if_ni);
if (specified_interface_found==0) {
inform("The mdns service interface \"%s\" was not found, so the setting has been ignored.",config.interface);
if (specified_interface_found == 0) {
inform(
"The mdns service interface \"%s\" was not found, so the setting has been ignored.",
config.interface);
free(config.interface);
config.interface = NULL;
config.interface_index = 0;
}
config.interface_index = 0;
}
}
/* Get the regtype -- the service type and protocol, separated by a dot. Default is
* "_raop._tcp" */
if (config_lookup_string(config.cfg, "general.regtype", &str))
@@ -901,9 +910,9 @@ int main(int argc, char **argv) {
// initialise random number generator
r64init(0);
// initialise the randomw number array
r64arrayinit();
/* Check if we are called with -V or --version parameter */
@@ -1194,7 +1203,7 @@ int main(int argc, char **argv) {
debug(1, "decoders_supported field is %d.", config.decoders_supported);
debug(1, "use_apple_decoder is %d.", config.use_apple_decoder);
if (config.interface)
debug(1, "mdns service interface \"%s\" requested.",config.interface);
debug(1, "mdns service interface \"%s\" requested.", config.interface);
else
debug(1, "no special mdns service interface was requested.");
char *realConfigPath = realpath(config.configfile, NULL);