Skip to content

Commit

Permalink
Tidy up using clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebrady committed Mar 7, 2018
1 parent 07e4656 commit c36a782
Show file tree
Hide file tree
Showing 20 changed files with 259 additions and 232 deletions.
18 changes: 9 additions & 9 deletions audio_alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ static int init(int argc, char **argv) {
}
}
if (((config.alsa_use_playback_switch_for_mute == 1) &&
(snd_mixer_selem_has_playback_switch(alsa_mix_elem))) ||
(snd_mixer_selem_has_playback_switch(alsa_mix_elem))) ||
mixer_volume_setting_gives_mute) {
audio_alsa.mute = &mute; // insert the mute function now we know it can do muting stuff
// debug(1, "Has mixer and mute ability we will use.");
Expand Down Expand Up @@ -462,11 +462,11 @@ int open_alsa_device(void) {
const snd_pcm_uframes_t minimal_buffer_headroom =
352 * 2; // we accept this much headroom in the hardware buffer, but we'll
// accept less
/*
const snd_pcm_uframes_t requested_buffer_headroom =
minimal_buffer_headroom + 2048; // we ask for this much headroom in the
// hardware buffer, but we'll accept less
*/
/*
const snd_pcm_uframes_t requested_buffer_headroom =
minimal_buffer_headroom + 2048; // we ask for this much headroom in the
// hardware buffer, but we'll accept less
*/

int ret, dir = 0;
unsigned int my_sample_rate = desired_sample_rate;
Expand Down Expand Up @@ -654,11 +654,11 @@ int open_alsa_device(void) {
if (alsa_characteristics_already_listed == 0) {
alsa_characteristics_already_listed = 1;
int log_level = 2; // the level at which debug information should be output
// int rc;
// int rc;
snd_pcm_access_t access_type;
snd_pcm_format_t format_type;
snd_pcm_subformat_t subformat_type;
// unsigned int val, val2;
// unsigned int val, val2;
unsigned int uval, uval2;
int sval;
int dir;
Expand Down Expand Up @@ -852,7 +852,7 @@ static void play(short buf[], int samples) {
}
if (ret == 0) {
pthread_mutex_lock(&alsa_mutex);
// snd_pcm_sframes_t current_delay = 0;
// snd_pcm_sframes_t current_delay = 0;
int err;
if (snd_pcm_state(alsa_handle) == SND_PCM_STATE_XRUN) {
if ((err = snd_pcm_prepare(alsa_handle))) {
Expand Down
6 changes: 3 additions & 3 deletions audio_pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ static void stop(void) {

static int init(int argc, char **argv) {
debug(1, "pipe init");
// const char *str;
// int value;
// double dvalue;
// const char *str;
// int value;
// double dvalue;

// set up default values first

Expand Down
19 changes: 10 additions & 9 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ void die(const char *format, ...) {

if ((debuglev) && (config.debugger_show_elapsed_time) && (config.debugger_show_relative_time))
daemon_log(LOG_EMERG, "|% 20.9f|% 20.9f|*fatal error: %s", tss, tsl, s);
else if ((debuglev) && (config.debugger_show_relative_time))
else if ((debuglev) && (config.debugger_show_relative_time))
daemon_log(LOG_EMERG, "% 20.9f|*fatal error: %s", tsl, s);
else if ((debuglev) && (config.debugger_show_elapsed_time))
else if ((debuglev) && (config.debugger_show_elapsed_time))
daemon_log(LOG_EMERG, "% 20.9f|*fatal error: %s", tss, s);
else
daemon_log(LOG_EMERG, "fatal error: %s", s);
Expand All @@ -138,12 +138,12 @@ void warn(const char *format, ...) {
va_start(args, format);
vsnprintf(s, sizeof(s), format, args);
va_end(args);

if ((debuglev) && (config.debugger_show_elapsed_time) && (config.debugger_show_relative_time))
daemon_log(LOG_WARNING, "|% 20.9f|% 20.9f|*warning: %s", tss, tsl, s);
else if ((debuglev) && (config.debugger_show_relative_time))
else if ((debuglev) && (config.debugger_show_relative_time))
daemon_log(LOG_WARNING, "% 20.9f|*warning: %s", tsl, s);
else if ((debuglev) && (config.debugger_show_elapsed_time))
else if ((debuglev) && (config.debugger_show_elapsed_time))
daemon_log(LOG_WARNING, "% 20.9f|*warning: %s", tss, s);
else
daemon_log(LOG_WARNING, "%s", s);
Expand Down Expand Up @@ -709,11 +709,12 @@ uint32_t uatoi(const char *nptr) {
}

double flat_vol2attn(double vol, long max_db, long min_db) {
double vol_setting = min_db; // if all else fails, set this, for safety
double vol_setting = min_db; // if all else fails, set this, for safety

if ((vol <= 0.0) && (vol >= -30.0)) {
vol_setting = ((max_db - min_db) * (30.0 + vol) / 30) + min_db;
// debug(2, "Linear profile Volume Setting: %f in range %ld to %ld.", vol_setting, min_db, max_db);
// debug(2, "Linear profile Volume Setting: %f in range %ld to %ld.", vol_setting, min_db,
// max_db);
} else if (vol != -144.0) {
debug(1,
"Linear volume request value %f is out of range: should be from 0.0 to -30.0 or -144.0.",
Expand Down Expand Up @@ -969,9 +970,9 @@ uint64_t ranarray64u() { return (ranarrayval()); }

int64_t ranarray64i() { return (ranarrayval() >> 1); }

uint32_t nctohl(const uint8_t * p) { // read 4 characters from the p and do ntohl on them
uint32_t nctohl(const uint8_t *p) { // read 4 characters from the p and do ntohl on them
// this is to avoid possible aliasing violations
uint32_t holder;
memcpy(&holder,p,sizeof(holder));
memcpy(&holder, p, sizeof(holder));
return ntohl(holder);
}
3 changes: 1 addition & 2 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ typedef struct {

} shairport_cfg;


uint32_t nctohl(const uint8_t * p); // read 4 characters from the p and do ntohl on them
uint32_t nctohl(const uint8_t *p); // read 4 characters from the p and do ntohl on them

// true if Shairport Sync is supposed to be sending output to the output device, false otherwise

Expand Down
74 changes: 40 additions & 34 deletions dacp.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include <arpa/inet.h>
#include <errno.h>
#include <inttypes.h>
#include <math.h>
#include <memory.h>
#include <netdb.h>
Expand All @@ -40,7 +41,6 @@
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <inttypes.h>

#include "metadata_hub.h"
#include "tinyhttp/http.h"
Expand Down Expand Up @@ -271,9 +271,9 @@ void set_dacp_server_information(rtsp_conn_info *conn) { // tell the DACP conver
strncpy(dacp_server.ip_string, conn->client_ip_string, INET6_ADDRSTRLEN);
dacp_server.active_remote_id = conn->dacp_active_remote;
if (dacp_server.port)
dacp_server.scan_enable=1;
dacp_server.scan_enable = 1;
else
dacp_server.scan_enable=0;
dacp_server.scan_enable = 0;
pthread_cond_signal(&dacp_server_information_cv);
pthread_mutex_unlock(&dacp_server_information_lock);
}
Expand All @@ -293,31 +293,32 @@ void *dacp_monitor_thread_code(void *na) {
}
scan_index++;
result = dacp_get_volume(NULL); // just want the http code
if ((result==496) || (result==403)|| (result==501)) {
if ((result == 496) || (result == 403) || (result == 501)) {
// debug(1,"Stopping scan because the response to \"dacp_get_volume(NULL)\" is %d.",result);
dacp_server.scan_enable = 0;
}
pthread_mutex_unlock(&dacp_server_information_lock);
// debug(1, "DACP Server ID \"%u\" at \"%s:%u\", scan %d.", dacp_server.active_remote_id,
// dacp_server.ip_string, dacp_server.port, scan_index);
if (result==200) {
if (result == 200) {
ssize_t le;
char *response = NULL;
int32_t item_size;
char command[1024] = "";
snprintf(command, sizeof(command) - 1, "playstatusupdate?revision-number=%d", revision_number);
snprintf(command, sizeof(command) - 1, "playstatusupdate?revision-number=%d",
revision_number);
// debug(1,"Command: \"%s\"",command);
result = dacp_send_command(command, &response, &le);
// debug(1,"Response to \"%s\" is %d.",command,result);
// if (result == 200) {
// if (result == 200) {
if (0) {
char *sp = response;
if (le >= 8) {
// here start looking for the contents of the status update
if (dacp_tlv_crawl(&sp, &item_size) == 'cmst') { // status
// here, we know that we are receiving playerstatusupdates, so set a flag
metadata_hub_modify_prolog();
debug(1,"playstatusupdate release track metadata");
debug(1, "playstatusupdate release track metadata");
metadata_hub_reset_track_metadata();
metadata_store.playerstatusupdates_are_received = 1;
sp -= item_size; // drop down into the array -- don't skip over it
Expand Down Expand Up @@ -558,7 +559,7 @@ void *dacp_monitor_thread_code(void *na) {
// finished possibly writing to the metadata hub
metadata_hub_modify_epilog(1);
} else {
debug(1,"Status Update not found.\n");
debug(1, "Status Update not found.\n");
}
} else {
debug(1, "Can't find any content in playerstatusupdate request");
Expand Down Expand Up @@ -649,36 +650,39 @@ int dacp_get_client_volume(int32_t *result) {
debug(1, "Unexpected response %d to dacp volume control request", response);
} */
if (result) {
*result=overall_volume;
*result = overall_volume;
// debug(1,"dacp_get_client_volume returns: %" PRId32 ".",overall_volume);
}
return response;
}

int dacp_set_include_speaker_volume(int64_t machine_number, int32_t vo) {
debug(1,"dacp_set_include_speaker_volume to %" PRId32 ".",vo);
debug(1, "dacp_set_include_speaker_volume to %" PRId32 ".", vo);
char message[1000];
memset(message, 0, sizeof(message));
sprintf(message, "setproperty?include-speaker-id=%" PRId64 "&dmcp.volume=%" PRId32 "", machine_number, vo);
debug(1,"sending \"%s\"",message);
sprintf(message, "setproperty?include-speaker-id=%" PRId64 "&dmcp.volume=%" PRId32 "",
machine_number, vo);
debug(1, "sending \"%s\"", message);
return send_simple_dacp_command(message);
// should return 204
}

int dacp_set_speaker_volume(int64_t machine_number, int32_t vo) {
char message[1000];
memset(message, 0, sizeof(message));
sprintf(message, "setproperty?speaker-id=%" PRId64 "&dmcp.volume=%" PRId32 "", machine_number, vo);
debug(1,"sending \"%s\"",message);
sprintf(message, "setproperty?speaker-id=%" PRId64 "&dmcp.volume=%" PRId32 "", machine_number,
vo);
debug(1, "sending \"%s\"", message);
return send_simple_dacp_command(message);
// should return 204
}

int dacp_get_speaker_list(dacp_spkr_stuff *speaker_info, int max_size_of_array, int *actual_speaker_count) {
int dacp_get_speaker_list(dacp_spkr_stuff *speaker_info, int max_size_of_array,
int *actual_speaker_count) {
// char typestring[5];
char *server_reply = NULL;
int speaker_index = -1; // will be incremented before use
int speaker_count = -1; // will be fixed if there is no problem
int speaker_count = -1; // will be fixed if there is no problem
ssize_t le;

int response = dacp_send_command("getspeakers", &server_reply, &le);
Expand All @@ -698,7 +702,7 @@ int dacp_get_speaker_list(dacp_spkr_stuff *speaker_info, int max_size_of_array,
le -= 8;
speaker_index++;
if (speaker_index == max_size_of_array)
return 413;// Payload Too Large -- too many speakers
return 413; // Payload Too Large -- too many speakers
speaker_info[speaker_index].active = 0;
speaker_info[speaker_index].speaker_number = 0;
speaker_info[speaker_index].volume = 0;
Expand All @@ -719,7 +723,8 @@ int dacp_get_speaker_list(dacp_spkr_stuff *speaker_info, int max_size_of_array,
t = sp - item_size;
r = ntohl(*(uint32_t *)(t));
speaker_info[speaker_index].volume = r;
// debug(1,"The individual volume of speaker \"%s\" is \"%d\".",speaker_info[speaker_index].name,r);
// debug(1,"The individual volume of speaker \"%s\" is
// \"%d\".",speaker_info[speaker_index].name,r);
break;
case 'msma':
t = sp - item_size;
Expand All @@ -740,12 +745,12 @@ int dacp_get_speaker_list(dacp_spkr_stuff *speaker_info, int max_size_of_array,
case 'cavd':
case 'caiv':
case 'cads':
*(uint32_t *)typestring = htonl(type);
typestring[4] = 0;
t = sp-item_size;
u = *t;
debug(1,"Type: '%s' Value: \"%d\".",typestring,u);
Expand Down Expand Up @@ -795,11 +800,11 @@ int dacp_get_volume(int32_t *the_actual_volume) {
int32_t overall_volume = 0;
int32_t actual_volume = 0;
int http_response = dacp_get_client_volume(&overall_volume);
if (http_response==200) {
if (http_response == 200) {
// debug(1,"Overall volume is: %u.",overall_volume);
int speaker_count = 0;
http_response = dacp_get_speaker_list((dacp_spkr_stuff *)&speaker_info, 50,&speaker_count);
if (http_response==200) {
http_response = dacp_get_speaker_list((dacp_spkr_stuff *)&speaker_info, 50, &speaker_count);
if (http_response == 200) {
// get our machine number
uint16_t *hn = (uint16_t *)config.hw_addr;
uint32_t *ln = (uint32_t *)(config.hw_addr + 2);
Expand All @@ -815,7 +820,7 @@ int dacp_get_volume(int32_t *the_actual_volume) {
relative_volume = speaker_info[i].volume;
/*
debug(1,"Our speaker was found with a relative volume of: %u.",relative_volume);
if (speaker_info[i].active)
debug(1,"Our speaker is active.");
else
Expand All @@ -824,17 +829,18 @@ int dacp_get_volume(int32_t *the_actual_volume) {
}
}
actual_volume = (overall_volume * relative_volume + 50) / 100;
// debug(1,"Overall volume: %d, relative volume: %d%, actual volume: %d.",overall_volume,relative_volume,actual_volume);
// debug(1,"Overall volume: %d, relative volume: %d%, actual volume:
// %d.",overall_volume,relative_volume,actual_volume);
// debug(1,"Our actual speaker volume is %d.",actual_volume);
//metadata_hub_modify_prolog();
//metadata_store.speaker_volume = actual_volume;
//metadata_hub_modify_epilog(1);
// metadata_hub_modify_prolog();
// metadata_store.speaker_volume = actual_volume;
// metadata_hub_modify_epilog(1);
} else {
debug(1,"Unexpected return code %d from dacp_get_speaker_list.",http_response);
debug(1, "Unexpected return code %d from dacp_get_speaker_list.", http_response);
}
} else {
debug(1,"Unexpected return code %d from dacp_get_client_volume.",http_response);
}
} else {
debug(1, "Unexpected return code %d from dacp_get_client_volume.", http_response);
}
if (the_actual_volume) {
// debug(1,"dacp_get_volume returns %d.",actual_volume);
*the_actual_volume = actual_volume;
Expand Down
6 changes: 4 additions & 2 deletions dacp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ uint32_t dacp_tlv_crawl(

int dacp_set_speaker_volume(int64_t machine_number, int32_t vo);

int dacp_get_speaker_list(dacp_spkr_stuff *speaker_array, int max_size_of_array, int *actual_speaker_count);
int dacp_get_speaker_list(dacp_spkr_stuff *speaker_array, int max_size_of_array,
int *actual_speaker_count);
void set_dacp_server_information(rtsp_conn_info *conn); // tell the DACP conversation thread that
// the dacp server information has been set
// or changed
int send_simple_dacp_command(const char *command);

int dacp_set_include_speaker_volume(int64_t machine_number, int32_t vo);
int dacp_get_client_volume(int32_t *result);
int dacp_get_volume(int32_t *the_actual_volume); // get the speaker volume information from the DACP source
int dacp_get_volume(
int32_t *the_actual_volume); // get the speaker volume information from the DACP source
Loading

0 comments on commit c36a782

Please sign in to comment.