Tidy up with clang-format

This commit is contained in:
Mike Brady
2018-11-08 14:43:52 +00:00
parent cfd10647aa
commit e7f70fba32
3 changed files with 66 additions and 57 deletions
+46 -43
View File
@@ -198,7 +198,6 @@ void do_snd_mixer_selem_set_playback_dB_all(snd_mixer_elem_t *mix_elem, double v
static int init(int argc, char **argv) {
snd_output_stdio_attach(&output, stdout, 0);
// debug(2,"audio_alsa init called.");
int response = 0; // this will be what we return to the caller.
const char *str;
@@ -507,7 +506,6 @@ static int init(int argc, char **argv) {
static void deinit(void) {
// debug(2,"audio_alsa deinit called.");
stop();
}
int open_alsa_device(void) {
@@ -543,7 +541,7 @@ int open_alsa_device(void) {
snd_pcm_hw_params_alloca(&alsa_params);
snd_pcm_sw_params_alloca(&alsa_swparams);
ret = snd_pcm_hw_params_any(alsa_handle, alsa_params);
if (ret < 0) {
warn("audio_alsa: Broken configuration for device \"%s\": no configurations "
@@ -698,7 +696,7 @@ int open_alsa_device(void) {
snd_strerror(ret));
return -9;
}
ret = snd_pcm_sw_params_current(alsa_handle, alsa_swparams);
if (ret < 0) {
warn("audio_alsa: Unable to get current sw parameters for device \"%s\": %s.", alsa_out_dev,
@@ -712,15 +710,15 @@ int open_alsa_device(void) {
snd_strerror(ret));
return -11;
}
/* write the sw parameters */
ret = snd_pcm_sw_params(alsa_handle, alsa_swparams);
if (ret < 0) {
warn("audio_alsa: Unable to set software parameters of device: \"%s\": %s.", alsa_out_dev,
snd_strerror(ret));
snd_strerror(ret));
return -12;
}
if (actual_buffer_length < config.audio_backend_buffer_desired_length + minimal_buffer_headroom) {
/*
// the dac buffer is too small, so let's try to set it
@@ -748,7 +746,7 @@ int open_alsa_device(void) {
"length (%ld) you have chosen.",
actual_buffer_length, config.audio_backend_buffer_desired_length);
}
if (alsa_characteristics_already_listed == 0) {
alsa_characteristics_already_listed = 1;
int log_level = 2; // the level at which debug information should be output
@@ -896,38 +894,40 @@ static void start(int i_sample_rate, int i_sample_format) {
measurement_data_is_valid = 0;
}
int my_snd_pcm_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp) {
int ret;
int my_snd_pcm_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp) {
int ret;
snd_pcm_status_t *alsa_snd_pcm_status;
snd_pcm_status_alloca(&alsa_snd_pcm_status);
struct timespec tn; // time now
snd_htimestamp_t update_timestamp; //actually a struct timespec
struct timespec tn; // time now
snd_htimestamp_t update_timestamp; // actually a struct timespec
ret = snd_pcm_status(pcm, alsa_snd_pcm_status);
if (ret) {
*delayp = 0;
return ret;
return ret;
}
snd_pcm_state_t state = snd_pcm_status_get_state(alsa_snd_pcm_status);
if (state != SND_PCM_STATE_RUNNING) {
*delayp = 0;
return -EIO; // might be a better code than this...
return -EIO; // might be a better code than this...
}
clock_gettime(CLOCK_MONOTONIC, &tn);
snd_pcm_status_get_htstamp(alsa_snd_pcm_status, &update_timestamp);
uint64_t t1 = tn.tv_sec * (uint64_t)1000000000 + tn.tv_nsec;
uint64_t t2 = update_timestamp.tv_sec * (uint64_t)1000000000 + update_timestamp.tv_nsec;
uint64_t t1 = tn.tv_sec * (uint64_t)1000000000 + tn.tv_nsec;
uint64_t t2 = update_timestamp.tv_sec * (uint64_t)1000000000 + update_timestamp.tv_nsec;
uint64_t delta = t1 - t2;
uint64_t frames_played_since_last_interrupt = ((uint64_t)desired_sample_rate * delta)/1000000000;
uint64_t frames_played_since_last_interrupt =
((uint64_t)desired_sample_rate * delta) / 1000000000;
snd_pcm_sframes_t frames_played_since_last_interrupt_sized = frames_played_since_last_interrupt;
*delayp = snd_pcm_status_get_delay(alsa_snd_pcm_status) - frames_played_since_last_interrupt_sized;
return 0;
*delayp =
snd_pcm_status_get_delay(alsa_snd_pcm_status) - frames_played_since_last_interrupt_sized;
return 0;
}
int delay(long *the_delay) {
@@ -947,9 +947,9 @@ int delay(long *the_delay) {
debug(1, "Error %d in delay(): \"%s\". Delay reported is %d frames.", reply,
snd_strerror(reply), *the_delay);
derr = snd_pcm_recover(alsa_handle, reply, 1);
if (derr < 0)
warn("Error %d -- could not clear an error after attempting delay(): \"%s\".", derr,
snd_strerror(derr));
if (derr < 0)
warn("Error %d -- could not clear an error after attempting delay(): \"%s\".", derr,
snd_strerror(derr));
frame_index = 0;
measurement_data_is_valid = 0;
@@ -977,9 +977,10 @@ int delay(long *the_delay) {
if ((derr = snd_pcm_prepare(alsa_handle))) {
debug(1, "Error preparing after delay error: \"%s\".", snd_strerror(derr));
derr = snd_pcm_recover(alsa_handle, derr, 1);
if (derr < 0)
warn("Error %d -- could not clear an error after attempting to recover following a delay(): \"%s\".", derr,
snd_strerror(derr));
if (derr < 0)
warn("Error %d -- could not clear an error after attempting to recover following a "
"delay(): \"%s\".",
derr, snd_strerror(derr));
}
}
}
@@ -1028,10 +1029,10 @@ static int play(void *buf, int samples) {
if (snd_pcm_state(alsa_handle) == SND_PCM_STATE_XRUN) {
if ((err = snd_pcm_prepare(alsa_handle))) {
debug(1, "Error preparing after underrun: \"%s\".", snd_strerror(err));
err = snd_pcm_recover(alsa_handle, err, 1);
if (err < 0)
warn("Error %d -- could not clear an error after detecting underrun in play(): \"%s\".", err,
snd_strerror(err));
err = snd_pcm_recover(alsa_handle, err, 1);
if (err < 0)
warn("Error %d -- could not clear an error after detecting underrun in play(): \"%s\".",
err, snd_strerror(err));
}
frame_index = 0; // we'll be starting over
measurement_data_is_valid = 0;
@@ -1049,9 +1050,10 @@ static int play(void *buf, int samples) {
debug(1, "Error %d writing %d samples in play(): \"%s\".", err, samples,
snd_strerror(err));
err = snd_pcm_recover(alsa_handle, err, 1);
if (err < 0)
warn("Error %d -- could not clear an error after attempting to write %d samples in play(): \"%s\".", err, samples,
snd_strerror(err));
if (err < 0)
warn("Error %d -- could not clear an error after attempting to write %d samples in "
"play(): \"%s\".",
err, samples, snd_strerror(err));
}
if (frame_index == 0) {
frames_sent_for_playing = samples;
@@ -1068,9 +1070,9 @@ static int play(void *buf, int samples) {
debug(1, "Error %d in delay in play(): \"%s\". Delay reported is %d frames.", err2,
snd_strerror(err2), fl);
err2 = snd_pcm_recover(alsa_handle, err2, 1);
if (err2 < 0)
warn("Error %d -- could not clear an error after checking delay in play(): \"%s\".", err2,
snd_strerror(err2));
if (err2 < 0)
warn("Error %d -- could not clear an error after checking delay in play(): \"%s\".",
err2, snd_strerror(err2));
frame_index = 0;
measurement_data_is_valid = 0;
} else {
@@ -1097,9 +1099,10 @@ static int play(void *buf, int samples) {
if ((err = snd_pcm_prepare(alsa_handle))) {
debug(1, "Error preparing after play error: \"%s\".", snd_strerror(err));
err2 = snd_pcm_recover(alsa_handle, err, 1);
if (err2 < 0)
warn("Error %d -- could not clear an error after reporting ALSA device in incorrect state for play: \"%s\".", err2,
snd_strerror(err2));
if (err2 < 0)
warn("Error %d -- could not clear an error after reporting ALSA device in incorrect "
"state for play: \"%s\".",
err2, snd_strerror(err2));
}
frame_index = 0;
measurement_data_is_valid = 0;
+18 -12
View File
@@ -454,7 +454,7 @@ void player_put_packet(seq_t seqno, uint32_t actual_timestamp, uint8_t *data, in
// now, if a flush_rtp_timestamp has been defined and the incoming timestamp is "before" it,
// drop it…
if ((conn->flush_rtp_timestamp != 0) && (actual_timestamp != conn->flush_rtp_timestamp) &&
if ((conn->flush_rtp_timestamp != 0) && (actual_timestamp != conn->flush_rtp_timestamp) &&
(modulo_32_offset(actual_timestamp, conn->flush_rtp_timestamp) <
conn->input_rate * 10)) { // if it's less than 10 seconds
debug(2, "Dropping flushed packet in player_put_packet, seqno %u, timestamp %" PRIu32
@@ -465,9 +465,9 @@ void player_put_packet(seq_t seqno, uint32_t actual_timestamp, uint8_t *data, in
conn->initial_reference_timestamp = 0;
} else {
if ((conn->flush_rtp_timestamp != 0) &&
(modulo_32_offset(conn->flush_rtp_timestamp, actual_timestamp) > conn->input_rate/5) &&
(modulo_32_offset(conn->flush_rtp_timestamp, actual_timestamp) > conn->input_rate / 5) &&
(modulo_32_offset(conn->flush_rtp_timestamp, actual_timestamp) < conn->input_rate)) {
// between 0.2 and 1 second
// between 0.2 and 1 second
debug(2, "Dropping flush request in player_put_packet");
conn->flush_rtp_timestamp = 0;
}
@@ -851,7 +851,8 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) {
}
}
if ((conn->flush_rtp_timestamp != 0) && (curframe->given_timestamp != conn->flush_rtp_timestamp) &&
if ((conn->flush_rtp_timestamp != 0) &&
(curframe->given_timestamp != conn->flush_rtp_timestamp) &&
(modulo_32_offset(curframe->given_timestamp, conn->flush_rtp_timestamp) <
conn->input_rate * 10)) { // if it's less than ten seconds
debug(2, "Dropping flushed packet in buffer_get_frame, seqno %u, timestamp %" PRIu32
@@ -866,8 +867,10 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) {
conn->initial_reference_timestamp = 0;
}
if ((conn->flush_rtp_timestamp != 0) &&
(modulo_32_offset(conn->flush_rtp_timestamp, curframe->given_timestamp) > conn->input_rate / 5) &&
(modulo_32_offset(conn->flush_rtp_timestamp, curframe->given_timestamp) < conn->input_rate * 10 )) {
(modulo_32_offset(conn->flush_rtp_timestamp, curframe->given_timestamp) >
conn->input_rate / 5) &&
(modulo_32_offset(conn->flush_rtp_timestamp, curframe->given_timestamp) <
conn->input_rate * 10)) {
debug(2, "Dropping flush request in buffer_get_frame");
conn->flush_rtp_timestamp = 0;
}
@@ -1912,8 +1915,8 @@ void *player_thread_func(void *arg) {
int64_t rt, nt;
rt = reference_timestamp; // uint32_t to int64_t
nt = inframe->given_timestamp; // uint32_t to int64_t
rt = rt*conn->output_sample_ratio;
nt = nt*conn->output_sample_ratio;
rt = rt * conn->output_sample_ratio;
nt = nt * conn->output_sample_ratio;
uint64_t local_time_now = get_absolute_time_in_fp(); // types okay
// struct timespec tn;
@@ -2062,14 +2065,17 @@ void *player_thread_func(void *arg) {
// sync_error_out_of_bounds, sync_error);
sync_error_out_of_bounds = 0;
int64_t filler_length = (int64_t)(config.resyncthreshold * config.output_rate); // number of samples
int64_t filler_length =
(int64_t)(config.resyncthreshold * config.output_rate); // number of samples
if ((sync_error > 0) && (sync_error > filler_length)) {
debug(2, "Large positive sync error: %" PRId64 ".", sync_error);
frames_to_drop = sync_error / conn->output_sample_ratio;
reset_input_flow_metrics(conn);
} else if ((sync_error < 0) && ((-sync_error) > filler_length)) {
debug(2, "Large negative sync error: %" PRId64 " with should_be_frame_32 of %" PRIu32
", nt of %" PRId64 " and current_delay of %" PRId64 ".", sync_error, should_be_frame_32, nt, current_delay);
debug(2,
"Large negative sync error: %" PRId64 " with should_be_frame_32 of %" PRIu32
", nt of %" PRId64 " and current_delay of %" PRId64 ".",
sync_error, should_be_frame_32, nt, current_delay);
int64_t silence_length = -sync_error;
if (silence_length > (filler_length * 5))
silence_length = filler_length * 5;
@@ -2077,7 +2083,7 @@ void *player_thread_func(void *arg) {
char *long_silence = malloc(conn->output_bytes_per_frame * silence_length_sized);
if (long_silence) {
memset(long_silence, 0, conn->output_bytes_per_frame * silence_length_sized);
debug(2,"Play a silence of %d frames.",silence_length_sized);
debug(2, "Play a silence of %d frames.", silence_length_sized);
config.output->play(long_silence, silence_length_sized);
free(long_silence);
} else {
+2 -2
View File
@@ -25,8 +25,6 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include <sys/socket.h>
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
@@ -37,7 +35,9 @@
#include <popt.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>