aboutsummaryrefslogtreecommitdiffstats
path: root/src/output
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-08-24 02:10:26 +0200
committerMax Kellermann <max@duempel.org>2011-08-28 16:44:12 +0200
commit8a63c279250f0e2297ad2fad5ac679ae1c95652b (patch)
tree4d557d3ddfc9a759c6693de61cc2c073412bc629 /src/output
parent310895f0606ebe1f88e20755f221c51cc66a63df (diff)
downloadmpd-8a63c279250f0e2297ad2fad5ac679ae1c95652b.tar.gz
mpd-8a63c279250f0e2297ad2fad5ac679ae1c95652b.tar.xz
mpd-8a63c279250f0e2297ad2fad5ac679ae1c95652b.zip
output/raop: move NTP code to separate library
Diffstat (limited to '')
-rw-r--r--src/output/raop_output_plugin.c76
-rw-r--r--src/output/raop_output_plugin.h11
2 files changed, 9 insertions, 78 deletions
diff --git a/src/output/raop_output_plugin.c b/src/output/raop_output_plugin.c
index dba89daef..865978c82 100644
--- a/src/output/raop_output_plugin.c
+++ b/src/output/raop_output_plugin.c
@@ -67,8 +67,7 @@ new_raop_data(GError **error_r)
if (raop_session == NULL) {
raop_session = g_new(struct raop_session_data, 1);
raop_session->raop_list = NULL;
- raop_session->ntp.port = 6002;
- raop_session->ntp.fd = -1;
+ ntp_server_init(&raop_session->ntp);
raop_session->ctrl.port = 6001;
raop_session->ctrl.fd = -1;
raop_session->play_state.playing = false;
@@ -402,46 +401,6 @@ fill_time_buffer_with_time(unsigned char *buffer, struct timeval *tout)
fill_int(buffer + 4, long_fraction);
}
-/*
- * Calculate the current NTP time, store it in the buffer.
- */
-static void
-fill_time_buffer(unsigned char *buffer)
-{
- struct timeval current_time;
-
- gettimeofday(&current_time,NULL);
- fill_time_buffer_with_time(buffer, &current_time);
-}
-
-/*
- * Recv the NTP datagram from the AirTunes, send back an NTP response.
- */
-static bool
-send_timing_response(int fd)
-{
- unsigned char buf[32];
- struct sockaddr addr;
- int iter;
- unsigned int addr_len = sizeof(addr);
- int num_bytes = recvfrom(fd, buf, sizeof(buf), 0, &addr, &addr_len);
- if (num_bytes == 0) {
- return false;
- }
- fill_time_buffer(buf + 16);
- // set to response
- buf[1] = 0xd3;
- // copy request
- for (iter = 0; iter < 8; iter++) {
- buf[8 + iter] = buf[24 + iter];
- }
- fill_time_buffer(buf + 24);
-
- num_bytes = sendto(fd, buf, num_bytes, 0, &addr, addr_len);
-
- return num_bytes == sizeof(buf);
-}
-
static void
get_time_for_rtp(struct play_state *state, struct timeval *tout)
{
@@ -498,29 +457,6 @@ send_control_command(struct control_data *ctrl, struct raop_data *rd,
}
/*
- * check to see if there are any timing requests, and respond if there are any
- */
-static bool
-check_timing(struct timeval *tout)
-{
- fd_set rdfds;
- int fdmax = 0;
-
- FD_ZERO(&rdfds);
-
- FD_SET(raop_session->ntp.fd, &rdfds);
- fdmax = raop_session->ntp.fd;
- select(fdmax + 1, &rdfds,NULL, NULL, tout);
- if (FD_ISSET(raop_session->ntp.fd, &rdfds)) {
- if (!send_timing_response(raop_session->ntp.fd)) {
- g_debug("unable to send timing response\n");
- return false;
- }
- }
- return true;
-}
-
-/*
* send RTSP request, and get response if it's needed
* if this gets a success, *kd is allocated or reallocated (if *kd is not NULL)
*/
@@ -605,7 +541,7 @@ exec_request(struct rtspcl_data *rtspcld, const char *cmd,
break;
}
if (FD_ISSET(raop_session->ntp.fd, &rdfds)) {
- send_timing_response(raop_session->ntp.fd);
+ ntp_server_handle(&raop_session->ntp);
}
}
@@ -1141,7 +1077,7 @@ send_audio_data(int fd, GError **error_r)
while (diff < -10000) {
tout.tv_sec = 0;
tout.tv_usec = -diff;
- check_timing(&tout);
+ ntp_server_check(&raop_session->ntp, &tout);
gettimeofday(&current_time, NULL);
diff = difference(&current_time, &rtp_time);
}
@@ -1280,7 +1216,7 @@ raop_output_pause(void *data)
struct timeval tout = {.tv_sec = 0, .tv_usec = 0};
struct raop_data *rd = (struct raop_data *) data;
- check_timing(&tout);
+ ntp_server_check(&raop_session->ntp, &tout);
rd->paused = true;
return true;
}
@@ -1304,7 +1240,7 @@ raop_output_close(void *data)
// TODO clean up everything else
raop_session->play_state.playing = false;
close(raop_session->data_fd);
- close(raop_session->ntp.fd);
+ ntp_server_close(&raop_session->ntp);
close(raop_session->ctrl.fd);
}
}
@@ -1398,7 +1334,7 @@ raop_output_play(void *data, const void *chunk, size_t size,
g_mutex_lock(raop_session->data_mutex);
- check_timing(&tout);
+ ntp_server_check(&raop_session->ntp, &tout);
if (raop_session->play_state.rtptime <= NUMSAMPLES) {
// looped over, need new reference point to calculate correct times
diff --git a/src/output/raop_output_plugin.h b/src/output/raop_output_plugin.h
index ed655330c..3b1d9bdf7 100644
--- a/src/output/raop_output_plugin.h
+++ b/src/output/raop_output_plugin.h
@@ -20,6 +20,8 @@
#ifndef MPD_OUTPUT_RAOP_PLUGIN_H
#define MPD_OUTPUT_RAOP_PLUGIN_H
+#include "ntp_server.h"
+
#include <glib.h>
#include <stdbool.h>
#include <sys/time.h>
@@ -89,13 +91,6 @@ struct encrypt_data {
/*********************************************************************/
-struct ntp_data {
- unsigned short port;
- int fd;
-};
-
-/*********************************************************************/
-
struct raop_data {
struct rtspcl_data *rtspcl;
const char *addr; // target host address
@@ -132,7 +127,7 @@ struct control_data {
// session
struct raop_session_data {
struct raop_data *raop_list;
- struct ntp_data ntp;
+ struct ntp_server ntp;
struct control_data ctrl;
struct encrypt_data encrypt;
struct play_state play_state;