From 08b88714e0327a4a138597ba9d434abc0eb130c4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 24 Aug 2011 02:18:51 +0200 Subject: output/raop: use fill_int() in fill_time_...() Eliminate duplicate code. --- src/output/raop_output_plugin.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/output/raop_output_plugin.c b/src/output/raop_output_plugin.c index 02ca120a0..dd35ce8e9 100644 --- a/src/output/raop_output_plugin.c +++ b/src/output/raop_output_plugin.c @@ -374,6 +374,18 @@ get_tcp_connect_by_host(int sd, const char *host, short destport, get_tcp_connect(sd, addr, error_r); } +/* + * Calculate the current NTP time, store it in the buffer. + */ +static void +fill_int(unsigned char *buffer, unsigned int rtp_time) +{ + int iter; + for (iter = 0; iter < 4; iter++) { + buffer[iter] = (rtp_time >> ((3 - iter) * 8)) & 0xff; + } +} + /* * Store time in the NTP format in the buffer */ @@ -381,7 +393,6 @@ static void fill_time_buffer_with_time(unsigned char *buffer, struct timeval *tout) { unsigned long secs_to_baseline = 964697997; - int iter; double fraction; unsigned long long_fraction; unsigned long secs; @@ -389,12 +400,8 @@ fill_time_buffer_with_time(unsigned char *buffer, struct timeval *tout) fraction = ((double) tout->tv_usec) / 1000000.0; long_fraction = (unsigned long) (fraction * 256.0 * 256.0 * 256.0 * 256.0); secs = secs_to_baseline + tout->tv_sec; - for (iter = 0; iter < 4; iter++) { - buffer[iter] = (secs >> ((3 - iter) * 8)) & 0xff; - } - for (iter = 0; iter < 4; iter++) { - buffer[4 + iter] = (long_fraction >> ((3 - iter) * 8)) & 0xff; - } + fill_int(buffer, secs); + fill_int(buffer + 4, long_fraction); } /* @@ -409,18 +416,6 @@ fill_time_buffer(unsigned char *buffer) fill_time_buffer_with_time(buffer, ¤t_time); } -/* - * Calculate the current NTP time, store it in the buffer. - */ -static void -fill_int(unsigned char *buffer, unsigned int rtp_time) -{ - int iter; - for (iter = 0; iter < 4; iter++) { - buffer[iter] = (rtp_time >> ((3 - iter) * 8)) & 0xff; - } -} - /* * Recv the NTP datagram from the AirTunes, send back an NTP response. */ -- cgit v1.2.3