Rename the entire code so that protocol-specific identifiers have `tcp_` and `udp_` prefix. --- src/modules/raop/module-raop-sink.c | 116 ++++++------- src/modules/raop/raop_client.c | 318 ++++++++++++++++++------------------ src/modules/raop/raop_client.h | 20 +-- 3 files changed, 227 insertions(+), 227 deletions(-) diff --git a/src/modules/raop/module-raop-sink.c b/src/modules/raop/module-raop-sink.c index d9cbe7b..9a3bd59 100644 --- a/src/modules/raop/module-raop-sink.c +++ b/src/modules/raop/module-raop-sink.c @@ -113,11 +113,11 @@ struct userdata { size_t block_size; /* Members only for the TCP protocol */ - int fd; + int tcp_fd; /* Members only for the UDP protocol */ - int control_fd; - int timing_fd; + int udp_control_fd; + int udp_timing_fd; }; static const char* const valid_modargs[] = { @@ -134,26 +134,26 @@ static const char* const valid_modargs[] = { }; enum { - SINK_MESSAGE_PASS_SOCKET = PA_SINK_MESSAGE_MAX, - SINK_MESSAGE_RIP_SOCKET, - SINK_MESSAGE_SETUP, - SINK_MESSAGE_RECORD, - SINK_MESSAGE_DISCONNECTED, + SINK_MESSAGE_TCP_PASS_SOCKET = PA_SINK_MESSAGE_MAX, + SINK_MESSAGE_TCP_RIP_SOCKET, + SINK_MESSAGE_UDP_SETUP, + SINK_MESSAGE_UDP_RECORD, + SINK_MESSAGE_UDP_DISCONNECTED, }; /* Forward declarations: */ static void sink_set_volume_cb(pa_sink *); -static void on_connection(int fd, void *userdata) { +static void tcp_on_connection(int fd, void *userdata) { int so_sndbuf = 0; socklen_t sl = sizeof(int); struct userdata *u = userdata; pa_assert(u); - pa_assert(u->fd < 0); - u->fd = fd; + pa_assert(u->tcp_fd < 0); + u->tcp_fd = fd; - if (getsockopt(u->fd, SOL_SOCKET, SO_SNDBUF, &so_sndbuf, &sl) < 0) + if (getsockopt(u->tcp_fd, SOL_SOCKET, SO_SNDBUF, &so_sndbuf, &sl) < 0) pa_log_warn("getsockopt(SO_SNDBUF) failed: %s", pa_cstrerror(errno)); else { pa_log_debug("SO_SNDBUF is %zu.", (size_t) so_sndbuf); @@ -165,16 +165,16 @@ static void on_connection(int fd, void *userdata) { pa_log_debug("Connection authenticated, handing fd to IO thread..."); - pa_asyncmsgq_post(u->thread_mq.inq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_PASS_SOCKET, NULL, 0, NULL, NULL); + pa_asyncmsgq_post(u->thread_mq.inq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_TCP_PASS_SOCKET, NULL, 0, NULL, NULL); } -static void on_close(void*userdata) { +static void tcp_on_close(void*userdata) { struct userdata *u = userdata; pa_assert(u); pa_log_debug("Connection closed, informing IO thread..."); - pa_asyncmsgq_post(u->thread_mq.inq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_RIP_SOCKET, NULL, 0, NULL, NULL); + pa_asyncmsgq_post(u->thread_mq.inq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_TCP_RIP_SOCKET, NULL, 0, NULL, NULL); } static pa_usec_t sink_get_latency(const struct userdata *u) { @@ -201,7 +201,7 @@ static int tcp_sink_process_msg(pa_msgobject *o, int code, void *data, int64_t o pa_smoother_pause(u->smoother, pa_rtclock_now()); /* Issue a FLUSH if we are connected. */ - if (u->fd >= 0) { + if (u->tcp_fd >= 0) { pa_raop_client_flush(u->raop); } break; @@ -214,7 +214,7 @@ static int tcp_sink_process_msg(pa_msgobject *o, int code, void *data, int64_t o /* The connection can be closed when idle, so check to * see if we need to reestablish it. */ - if (u->fd < 0) + if (u->tcp_fd < 0) pa_raop_client_connect(u->raop); else pa_raop_client_flush(u->raop); @@ -235,14 +235,14 @@ static int tcp_sink_process_msg(pa_msgobject *o, int code, void *data, int64_t o return 0; } - case SINK_MESSAGE_PASS_SOCKET: { + case SINK_MESSAGE_TCP_PASS_SOCKET: { struct pollfd *pollfd; pa_assert(!u->rtpoll_item); u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1); pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL); - pollfd->fd = u->fd; + pollfd->fd = u->tcp_fd; pollfd->events = POLLOUT; /*pollfd->events = */pollfd->revents = 0; @@ -253,10 +253,10 @@ static int tcp_sink_process_msg(pa_msgobject *o, int code, void *data, int64_t o return 0; } - case SINK_MESSAGE_RIP_SOCKET: { - if (u->fd >= 0) { - pa_close(u->fd); - u->fd = -1; + case SINK_MESSAGE_TCP_RIP_SOCKET: { + if (u->tcp_fd >= 0) { + pa_close(u->tcp_fd); + u->tcp_fd = -1; } else /* FIXME */ pa_log("We should not get to this state. Cannot rip socket if not connected."); @@ -292,7 +292,7 @@ static int udp_sink_process_msg(pa_msgobject *o, int code, void *data, int64_t o pa_log_debug("RAOP: SUSPENDED"); pa_smoother_pause(u->smoother, pa_rtclock_now()); - if (pa_raop_client_can_stream(u->raop)) { + if (pa_raop_client_udp_can_stream(u->raop)) { /* Issue a TEARDOWN if we are still connected. */ pa_raop_client_teardown(u->raop); } @@ -313,7 +313,7 @@ static int udp_sink_process_msg(pa_msgobject *o, int code, void *data, int64_t o if (u->sink->thread_info.state == PA_SINK_SUSPENDED) pa_smoother_resume(u->smoother, pa_rtclock_now(), true); pa_log_debug("RAOP: RUNNING"); - if (!pa_raop_client_can_stream(u->raop)) { + if (!pa_raop_client_udp_can_stream(u->raop)) { /* Connecting will trigger a RECORD */ pa_raop_client_connect(u->raop); } @@ -331,7 +331,7 @@ static int udp_sink_process_msg(pa_msgobject *o, int code, void *data, int64_t o case PA_SINK_MESSAGE_GET_LATENCY: { pa_usec_t r = 0; - if (pa_raop_client_can_stream(u->raop)) + if (pa_raop_client_udp_can_stream(u->raop)) r = sink_get_latency(u); *((pa_usec_t*) data) = r; @@ -339,26 +339,26 @@ static int udp_sink_process_msg(pa_msgobject *o, int code, void *data, int64_t o return 0; } - case SINK_MESSAGE_SETUP: { + case SINK_MESSAGE_UDP_SETUP: { struct pollfd *pollfd; u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 2); pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL); - pollfd->fd = u->control_fd; + pollfd->fd = u->udp_control_fd; pollfd->events = POLLIN | POLLPRI; pollfd->revents = 0; pollfd++; - pollfd->fd = u->timing_fd; + pollfd->fd = u->udp_timing_fd; pollfd->events = POLLIN | POLLPRI; pollfd->revents = 0; - u->control_fd = -1; - u->timing_fd = -1; + u->udp_control_fd = -1; + u->udp_timing_fd = -1; return 0; } - case SINK_MESSAGE_RECORD: { + case SINK_MESSAGE_UDP_RECORD: { pa_rtpoll_set_timer_relative(u->rtpoll, pa_bytes_to_usec(u->block_size, &u->sink->sample_spec)); if (u->sink->thread_info.state == PA_SINK_SUSPENDED) { @@ -369,7 +369,7 @@ static int udp_sink_process_msg(pa_msgobject *o, int code, void *data, int64_t o return 0; } - case SINK_MESSAGE_DISCONNECTED: { + case SINK_MESSAGE_UDP_DISCONNECTED: { if (u->sink->thread_info.state == PA_SINK_SUSPENDED) { pa_rtpoll_set_timer_disabled(u->rtpoll); if (u->rtpoll_item) @@ -381,8 +381,8 @@ static int udp_sink_process_msg(pa_msgobject *o, int code, void *data, int64_t o pa_module_unload_request(u->module, true); } - u->control_fd = -1; - u->timing_fd = -1; + u->udp_control_fd = -1; + u->udp_timing_fd = -1; return 0; } } @@ -435,22 +435,22 @@ static void sink_set_mute_cb(pa_sink *s) { } } -static void raop_setup_cb(int control_fd, int timing_fd, void *userdata) { +static void udp_setup_cb(int control_fd, int timing_fd, void *userdata) { struct userdata *u = userdata; pa_assert(control_fd); pa_assert(timing_fd); pa_assert(u); - u->control_fd = control_fd; - u->timing_fd = timing_fd; + u->udp_control_fd = control_fd; + u->udp_timing_fd = timing_fd; pa_log_debug("Connection authenticated, syncing with server..."); - pa_asyncmsgq_post(u->thread_mq.inq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_SETUP, NULL, 0, NULL, NULL); + pa_asyncmsgq_post(u->thread_mq.inq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_UDP_SETUP, NULL, 0, NULL, NULL); } -static void raop_record_cb(void *userdata) { +static void udp_record_cb(void *userdata) { struct userdata *u = userdata; pa_assert(u); @@ -460,17 +460,17 @@ static void raop_record_cb(void *userdata) { pa_log_debug("Synchronization done, pushing job to IO thread..."); - pa_asyncmsgq_post(u->thread_mq.inq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_RECORD, NULL, 0, NULL, NULL); + pa_asyncmsgq_post(u->thread_mq.inq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_UDP_RECORD, NULL, 0, NULL, NULL); } -static void raop_disconnected_cb(void *userdata) { +static void udp_disconnected_cb(void *userdata) { struct userdata *u = userdata; pa_assert(u); pa_log_debug("Connection closed, informing IO thread..."); - pa_asyncmsgq_post(u->thread_mq.inq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_DISCONNECTED, NULL, 0, NULL, NULL); + pa_asyncmsgq_post(u->thread_mq.inq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_UDP_DISCONNECTED, NULL, 0, NULL, NULL); } static void tcp_thread_func(struct userdata *u) { @@ -561,7 +561,7 @@ static void tcp_thread_func(struct userdata *u) { pa_assert(u->encoded_memchunk.length > 0); p = pa_memblock_acquire(u->encoded_memchunk.memblock); - l = pa_write(u->fd, (uint8_t*) p + u->encoded_memchunk.index, u->encoded_memchunk.length, &write_type); + l = pa_write(u->tcp_fd, (uint8_t*) p + u->encoded_memchunk.index, u->encoded_memchunk.length, &write_type); pa_memblock_release(u->encoded_memchunk.memblock); pa_assert(l != 0); @@ -610,7 +610,7 @@ static void tcp_thread_func(struct userdata *u) { #ifdef SIOCOUTQ { int l; - if (ioctl(u->fd, SIOCOUTQ, &l) >= 0 && l > 0) + if (ioctl(u->tcp_fd, SIOCOUTQ, &l) >= 0 && l > 0) n -= (l / u->encoding_ratio); } #endif @@ -706,7 +706,7 @@ static void udp_thread_func(struct userdata *u) { pollfd->revents = 0; pa_log_debug("Received control packet."); read = pa_read(pollfd->fd, packet, sizeof(packet), NULL); - pa_raop_client_handle_control_packet(u->raop, packet, read); + pa_raop_client_udp_handle_control_packet(u->raop, packet, read); } pollfd++; @@ -716,14 +716,14 @@ static void udp_thread_func(struct userdata *u) { pollfd->revents = 0; pa_log_debug("Received timing packet."); read = pa_read(pollfd->fd, packet, sizeof(packet), NULL); - pa_raop_client_handle_timing_packet(u->raop, packet, read); + pa_raop_client_udp_handle_timing_packet(u->raop, packet, read); } } continue; } - if (!pa_raop_client_can_stream(u->raop)) + if (!pa_raop_client_udp_can_stream(u->raop)) continue; if (u->sink->thread_info.state != PA_SINK_RUNNING) continue; @@ -751,7 +751,7 @@ static void udp_thread_func(struct userdata *u) { pa_assert(u->encoded_memchunk.length > 0); - pa_raop_client_send_audio_packet(u->raop, &u->encoded_memchunk, &written); + pa_raop_client_udp_send_audio_packet(u->raop, &u->encoded_memchunk, &written); pa_rtpoll_set_timer_relative(u->rtpoll, pa_bytes_to_usec(u->block_size, &u->sink->sample_spec)); pa_assert(written != 0); @@ -821,7 +821,7 @@ int pa__init(pa_module *m) { u->core = m->core; u->module = m; m->userdata = u; - u->fd = -1; + u->tcp_fd = -1; u->smoother = pa_smoother_new( PA_USEC_PER_SEC, PA_USEC_PER_SEC*2, @@ -916,18 +916,18 @@ int pa__init(pa_module *m) { goto fail; } - pa_raop_client_set_callback(u->raop, on_connection, u); - pa_raop_client_set_closed_callback(u->raop, on_close, u); + pa_raop_client_tcp_set_callback(u->raop, tcp_on_connection, u); + pa_raop_client_tcp_set_closed_callback(u->raop, tcp_on_close, u); if (u->protocol == RAOP_UDP) { /* The number of frames per blocks is not negotiable... */ - pa_raop_client_get_blocks_size(u->raop, &u->block_size); + pa_raop_client_udp_get_blocks_size(u->raop, &u->block_size); u->block_size *= pa_frame_size(&ss); pa_sink_set_max_request(u->sink, u->block_size); - pa_raop_client_set_setup_callback(u->raop, raop_setup_cb, u); - pa_raop_client_set_record_callback(u->raop, raop_record_cb, u); - pa_raop_client_set_disconnected_callback(u->raop, raop_disconnected_cb, u); + pa_raop_client_udp_set_setup_callback(u->raop, udp_setup_cb, u); + pa_raop_client_udp_set_record_callback(u->raop, udp_record_cb, u); + pa_raop_client_udp_set_disconnected_callback(u->raop, udp_disconnected_cb, u); } if (!(u->thread = pa_thread_new("raop-sink", thread_func, u))) { @@ -1002,8 +1002,8 @@ void pa__done(pa_module *m) { if (u->smoother) pa_smoother_free(u->smoother); - if (u->fd >= 0) - pa_close(u->fd); + if (u->tcp_fd >= 0) + pa_close(u->tcp_fd); pa_xfree(u); } diff --git a/src/modules/raop/raop_client.c b/src/modules/raop/raop_client.c index 1ca8421..0174572 100644 --- a/src/modules/raop/raop_client.c +++ b/src/modules/raop/raop_client.c @@ -59,7 +59,7 @@ #include "rtsp_client.h" #include "base64.h" -#define FRAMES_PER_PACKET 352 +#define UDP_FRAMES_PER_PACKET 352 #define AES_CHUNKSIZE 16 #define JACK_STATUS_DISCONNECTED 0 @@ -72,20 +72,19 @@ #define VOLUME_MIN -144 #define VOLUME_MAX 0 -#define RAOP_PORT 5000 #define DEFAULT_RAOP_PORT 5000 -#define DEFAULT_AUDIO_PORT 6000 -#define DEFAULT_CONTROL_PORT 6001 -#define DEFAULT_TIMING_PORT 6002 +#define UDP_DEFAULT_AUDIO_PORT 6000 +#define UDP_DEFAULT_CONTROL_PORT 6001 +#define UDP_DEFAULT_TIMING_PORT 6002 typedef enum { - PAYLOAD_TIMING_REQUEST = 0x52, - PAYLOAD_TIMING_RESPONSE = 0x53, - PAYLOAD_SYNCHRONIZATION = 0x54, - PAYLOAD_RETRANSMIT_REQUEST = 0x55, - PAYLOAD_RETRANSMIT_REPLY = 0x56, - PAYLOAD_AUDIO_DATA = 0x60 -} pa_raop_payload_type; + UDP_PAYLOAD_TIMING_REQUEST = 0x52, + UDP_PAYLOAD_TIMING_RESPONSE = 0x53, + UDP_PAYLOAD_SYNCHRONIZATION = 0x54, + UDP_PAYLOAD_RETRANSMIT_REQUEST = 0x55, + UDP_PAYLOAD_RETRANSMIT_REPLY = 0x56, + UDP_PAYLOAD_AUDIO_DATA = 0x60 +} pa_raop_udp_payload_type; struct pa_raop_client { pa_core *core; @@ -108,36 +107,36 @@ struct pa_raop_client { uint32_t rtptime; /* Members only for the TCP protocol */ - pa_socket_client *sc; - int fd; + pa_socket_client *tcp_sc; + int tcp_fd; - pa_raop_client_cb_t callback; - void *userdata; - pa_raop_client_closed_cb_t closed_callback; - void *closed_userdata; + pa_raop_client_cb_t tcp_callback; + void *tcp_userdata; + pa_raop_client_closed_cb_t tcp_closed_callback; + void *tcp_closed_userdata; /* Members only for the UDP protocol */ - uint16_t control_port; - uint16_t timing_port; + uint16_t udp_control_port; + uint16_t udp_timing_port; - int stream_fd; - int control_fd; - int timing_fd; + int udp_stream_fd; + int udp_control_fd; + int udp_timing_fd; - uint32_t ssrc; + uint32_t udp_ssrc; - bool first_packet; - uint32_t sync_interval; - uint32_t sync_count; + bool udp_first_packet; + uint32_t udp_sync_interval; + uint32_t udp_sync_count; - pa_raop_client_setup_cb_t setup_callback; - void *setup_userdata; + pa_raop_client_setup_cb_t udp_setup_callback; + void *udp_setup_userdata; - pa_raop_client_record_cb_t record_callback; - void *record_userdata; + pa_raop_client_record_cb_t udp_record_callback; + void *udp_record_userdata; - pa_raop_client_disconnected_cb_t disconnected_callback; - void *disconnected_userdata; + pa_raop_client_disconnected_cb_t udp_disconnected_callback; + void *udp_disconnected_userdata; }; /* Timming packet header (8x8): @@ -145,7 +144,7 @@ struct pa_raop_client { * [1] Payload type: 0x53 | marker bit: 0x80, * [2,3] Sequence number: 0x0007, * [4,7] Timestamp: 0x00000000 (unused). */ -static const uint8_t timming_header[8] = { +static const uint8_t udp_timming_header[8] = { 0x80, 0xd3, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00 }; @@ -155,7 +154,7 @@ static const uint8_t timming_header[8] = { * [1] Payload type: 0x54 | marker bit: 0x80, * [2,3] Sequence number: 0x0007, * [4,7] Timestamp: 0x00000000 (to be set). */ -static const uint8_t sync_header[8] = { +static const uint8_t udp_sync_header[8] = { 0x80, 0xd4, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00 }; @@ -283,32 +282,32 @@ static inline void rtrimchar(char *str, char rc) { } } -static void on_connection(pa_socket_client *sc, pa_iochannel *io, void *userdata) { +static void tcp_on_connection(pa_socket_client *sc, pa_iochannel *io, void *userdata) { pa_raop_client *c = userdata; pa_assert(sc); pa_assert(c); - pa_assert(c->sc == sc); - pa_assert(c->fd < 0); - pa_assert(c->callback); + pa_assert(c->tcp_sc == sc); + pa_assert(c->tcp_fd < 0); + pa_assert(c->tcp_callback); - pa_socket_client_unref(c->sc); - c->sc = NULL; + pa_socket_client_unref(c->tcp_sc); + c->tcp_sc = NULL; if (!io) { pa_log("Connection failed: %s", pa_cstrerror(errno)); return; } - c->fd = pa_iochannel_get_send_fd(io); + c->tcp_fd = pa_iochannel_get_send_fd(io); pa_iochannel_set_noclose(io, true); pa_iochannel_free(io); - pa_make_tcp_socket_low_delay(c->fd); + pa_make_tcp_socket_low_delay(c->tcp_fd); pa_log_debug("Connection established"); - c->callback(c->fd, c->userdata); + c->tcp_callback(c->tcp_fd, c->tcp_userdata); } static inline uint64_t timeval_to_ntp(struct timeval *tv) { @@ -442,14 +441,14 @@ fail: return -1; } -static int send_timing_packet(pa_raop_client *c, const uint32_t data[6], uint64_t received) { +static int udp_send_timing_packet(pa_raop_client *c, const uint32_t data[6], uint64_t received) { uint32_t packet[8]; struct timeval tv; ssize_t written = 0; uint64_t trs = 0; int rv = 1; - memcpy(packet, timming_header, sizeof(timming_header)); + memcpy(packet, udp_timming_header, sizeof(udp_timming_header)); /* Copying originate timestamp from the incoming request packet. */ packet[2] = data[4]; packet[3] = data[5]; @@ -461,14 +460,14 @@ static int send_timing_packet(pa_raop_client *c, const uint32_t data[6], uint64_ packet[6] = htonl(trs >> 32); packet[7] = htonl(trs & 0xffffffff); - written = pa_loop_write(c->timing_fd, packet, sizeof(packet), NULL); + written = pa_loop_write(c->udp_timing_fd, packet, sizeof(packet), NULL); if (written == sizeof(packet)) rv = 0; return rv; } -static int send_sync_packet(pa_raop_client *c, uint32_t stamp) { +static int udp_send_sync_packet(pa_raop_client *c, uint32_t stamp) { const uint32_t delay = 88200; uint32_t packet[5]; struct timeval tv; @@ -476,8 +475,8 @@ static int send_sync_packet(pa_raop_client *c, uint32_t stamp) { uint64_t trs = 0; int rv = 1; - memcpy(packet, sync_header, sizeof(sync_header)); - if (c->first_packet) + memcpy(packet, udp_sync_header, sizeof(udp_sync_header)); + if (c->udp_first_packet) packet[0] |= 0x10; stamp -= delay; packet[1] = htonl(stamp); @@ -488,25 +487,25 @@ static int send_sync_packet(pa_raop_client *c, uint32_t stamp) { stamp += delay; packet[4] = htonl(stamp); - written = pa_loop_write(c->control_fd, packet, sizeof(packet), NULL); + written = pa_loop_write(c->udp_control_fd, packet, sizeof(packet), NULL); if (written == sizeof(packet)) rv = 0; return rv; } -static int send_audio_packet(pa_raop_client *c, uint32_t *buffer, size_t size, ssize_t *written) { +static int udp_send_audio_packet(pa_raop_client *c, uint32_t *buffer, size_t size, ssize_t *written) { ssize_t length = 0; int rv = 1; memcpy(buffer, udp_audio_header, sizeof(udp_audio_header)); - if (c->first_packet) + if (c->udp_first_packet) buffer[0] |= ((uint32_t) 0x80) << 8; buffer[0] |= htonl((uint32_t) c->seq); buffer[1] = htonl(c->rtptime); - buffer[2] = htonl(c->ssrc); + buffer[2] = htonl(c->udp_ssrc); - length = pa_loop_write(c->stream_fd, buffer, size, NULL); + length = pa_loop_write(c->udp_stream_fd, buffer, size, NULL); if (length == ((ssize_t) size)) rv = 0; @@ -557,7 +556,7 @@ static void do_rtsp_announce(pa_raop_client *c) { "a=rsaaeskey:%s\r\n" "a=aesiv:%s\r\n", c->sid, ip, c->host, - c->protocol == RAOP_TCP ? 4096 : FRAMES_PER_PACKET, + c->protocol == RAOP_TCP ? 4096 : UDP_FRAMES_PER_PACKET, key, iv); pa_rtsp_announce(c->rtsp, sdp); pa_xfree(key); @@ -619,11 +618,11 @@ static void tcp_rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist uint32_t port = pa_rtsp_serverport(c->rtsp); pa_log_debug("RAOP: RECORDED"); - if (!(c->sc = pa_socket_client_new_string(c->core->mainloop, true, c->host, port))) { + if (!(c->tcp_sc = pa_socket_client_new_string(c->core->mainloop, true, c->host, port))) { pa_log("failed to connect to server '%s:%d'", c->host, port); return; } - pa_socket_client_set_callback(c->sc, on_connection, c); + pa_socket_client_set_callback(c->tcp_sc, tcp_on_connection, c); break; } @@ -640,23 +639,23 @@ static void tcp_rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist break; case STATE_DISCONNECTED: - pa_assert(c->closed_callback); + pa_assert(c->tcp_closed_callback); pa_assert(c->rtsp); pa_log_debug("RTSP control channel closed"); pa_rtsp_client_free(c->rtsp); c->rtsp = NULL; - if (c->fd > 0) { + if (c->tcp_fd > 0) { /* We do not close the fd, we leave it to the closed callback to do that */ - c->fd = -1; + c->tcp_fd = -1; } - if (c->sc) { - pa_socket_client_unref(c->sc); - c->sc = NULL; + if (c->tcp_sc) { + pa_socket_client_unref(c->tcp_sc); + c->tcp_sc = NULL; } pa_xfree(c->sid); c->sid = NULL; - c->closed_callback(c->closed_userdata); + c->tcp_closed_callback(c->tcp_closed_userdata); break; } } @@ -697,8 +696,8 @@ static void udp_rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist char *trs; trs = pa_sprintf_malloc("RTP/AVP/UDP;unicast;interleaved=0-1;mode=record;control_port=%d;timing_port=%d", - c->control_port, - c->timing_port); + c->udp_control_port, + c->udp_timing_port); pa_rtsp_setup(c->rtsp, trs); @@ -707,7 +706,7 @@ static void udp_rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist } case STATE_SETUP: { - uint32_t stream_port = DEFAULT_AUDIO_PORT; + uint32_t stream_port = UDP_DEFAULT_AUDIO_PORT; char *ajs, *trs, *token, *pc; char delimiters[] = ";"; const char *token_state = NULL; @@ -748,12 +747,12 @@ static void udp_rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist if (pa_streq(token, "control_port")) { port = 0; pa_atou(pc + 1, &port); - c->control_port = port; + c->udp_control_port = port; } if (pa_streq(token, "timing_port")) { port = 0; pa_atou(pc + 1, &port); - c->timing_port = port; + c->udp_timing_port = port; } *pc = '='; } @@ -769,47 +768,47 @@ static void udp_rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist stream_port = pa_rtsp_serverport(c->rtsp); if (stream_port == 0) goto error; - if (c->control_port == 0 || c->timing_port == 0) + if (c->udp_control_port == 0 || c->udp_timing_port == 0) goto error; pa_log_debug("Using server_port=%d, control_port=%d & timing_port=%d", stream_port, - c->control_port, - c->timing_port); + c->udp_control_port, + c->udp_timing_port); - c->stream_fd = open_udp_socket(c, stream_port, 0); - c->control_fd = open_udp_socket(c, c->control_port, 1); - c->timing_fd = open_udp_socket(c, c->timing_port, 1); + c->udp_stream_fd = open_udp_socket(c, stream_port, 0); + c->udp_control_fd = open_udp_socket(c, c->udp_control_port, 1); + c->udp_timing_fd = open_udp_socket(c, c->udp_timing_port, 1); - if (c->stream_fd <= 0) + if (c->udp_stream_fd <= 0) goto error; - if (c->control_fd <= 0 || c->timing_fd <= 0) + if (c->udp_control_fd <= 0 || c->udp_timing_fd <= 0) goto error; - c->setup_callback(c->control_fd, c->timing_fd, c->setup_userdata); + c->udp_setup_callback(c->udp_control_fd, c->udp_timing_fd, c->udp_setup_userdata); pa_rtsp_record(c->rtsp, &c->seq, &c->rtptime); break; error: - if (c->stream_fd > 0) { - pa_close(c->stream_fd); - c->stream_fd = -1; + if (c->udp_stream_fd > 0) { + pa_close(c->udp_stream_fd); + c->udp_stream_fd = -1; } - if (c->control_fd > 0) { - pa_close(c->control_fd); - c->control_fd = -1; + if (c->udp_control_fd > 0) { + pa_close(c->udp_control_fd); + c->udp_control_fd = -1; } - if (c->timing_fd > 0) { - pa_close(c->timing_fd); - c->timing_fd = -1; + if (c->udp_timing_fd > 0) { + pa_close(c->udp_timing_fd); + c->udp_timing_fd = -1; } pa_rtsp_client_free(c->rtsp); c->rtsp = NULL; - c->control_port = DEFAULT_CONTROL_PORT; - c->timing_port = DEFAULT_TIMING_PORT; + c->udp_control_port = UDP_DEFAULT_CONTROL_PORT; + c->udp_timing_port = UDP_DEFAULT_TIMING_PORT; pa_log_error("aborting RTSP setup, failed creating required sockets"); @@ -826,15 +825,15 @@ static void udp_rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist alt = pa_xstrdup(pa_headerlist_gets(headers, "Audio-Latency")); /* Generate a random synchronization source identifier from this session. */ pa_random(&rand, sizeof(rand)); - c->ssrc = rand; + c->udp_ssrc = rand; if (alt) pa_atoi(alt, &latency); - c->first_packet = true; - c->sync_count = 0; + c->udp_first_packet = true; + c->udp_sync_count = 0; - c->record_callback(c->setup_userdata); + c->udp_record_callback(c->udp_setup_userdata); pa_xfree(alt); break; @@ -857,17 +856,17 @@ static void udp_rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist pa_rtsp_disconnect(c->rtsp); - if (c->stream_fd > 0) { - pa_close(c->stream_fd); - c->stream_fd = -1; + if (c->udp_stream_fd > 0) { + pa_close(c->udp_stream_fd); + c->udp_stream_fd = -1; } - if (c->control_fd > 0) { - pa_close(c->control_fd); - c->control_fd = -1; + if (c->udp_control_fd > 0) { + pa_close(c->udp_control_fd); + c->udp_control_fd = -1; } - if (c->timing_fd > 0) { - pa_close(c->timing_fd); - c->timing_fd = -1; + if (c->udp_timing_fd > 0) { + pa_close(c->udp_timing_fd); + c->udp_timing_fd = -1; } pa_log_debug("RTSP control channel closed"); @@ -881,20 +880,20 @@ static void udp_rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist } case STATE_DISCONNECTED: { - pa_assert(c->disconnected_callback); + pa_assert(c->udp_disconnected_callback); pa_assert(c->rtsp); - if (c->stream_fd > 0) { - pa_close(c->stream_fd); - c->stream_fd = -1; + if (c->udp_stream_fd > 0) { + pa_close(c->udp_stream_fd); + c->udp_stream_fd = -1; } - if (c->control_fd > 0) { - pa_close(c->control_fd); - c->control_fd = -1; + if (c->udp_control_fd > 0) { + pa_close(c->udp_control_fd); + c->udp_control_fd = -1; } - if (c->timing_fd > 0) { - pa_close(c->timing_fd); - c->timing_fd = -1; + if (c->udp_timing_fd > 0) { + pa_close(c->udp_timing_fd); + c->udp_timing_fd = -1; } pa_log_debug("RTSP control channel closed"); @@ -904,7 +903,7 @@ static void udp_rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist c->rtsp = NULL; c->sid = NULL; - c->disconnected_callback(c->disconnected_userdata); + c->udp_disconnected_callback(c->udp_disconnected_userdata); break; } @@ -924,14 +923,14 @@ pa_raop_client* pa_raop_client_new(pa_core *core, const char *host, return NULL; c->core = core; - c->fd = -1; + c->tcp_fd = -1; c->protocol = protocol; - c->stream_fd = -1; - c->control_fd = -1; - c->timing_fd = -1; + c->udp_stream_fd = -1; + c->udp_control_fd = -1; + c->udp_timing_fd = -1; - c->control_port = DEFAULT_CONTROL_PORT; - c->timing_port = DEFAULT_TIMING_PORT; + c->udp_control_port = UDP_DEFAULT_CONTROL_PORT; + c->udp_timing_port = UDP_DEFAULT_TIMING_PORT; c->host = pa_xstrdup(a.path_or_host); if (a.port) @@ -939,10 +938,10 @@ pa_raop_client* pa_raop_client_new(pa_core *core, const char *host, else c->port = DEFAULT_RAOP_PORT; - c->first_packet = true; + c->udp_first_packet = true; /* Packet sync interval should be around 1s. */ - c->sync_interval = spec.rate / FRAMES_PER_PACKET; - c->sync_count = 0; + c->udp_sync_interval = spec.rate / UDP_FRAMES_PER_PACKET; + c->udp_sync_count = 0; if (c->protocol == RAOP_TCP) { if (pa_raop_client_connect(c)) { @@ -1011,7 +1010,7 @@ int pa_raop_client_flush(pa_raop_client *c) { if (c->rtsp != NULL) { rv = pa_rtsp_flush(c->rtsp, c->seq, c->rtptime); - c->sync_count = -1; + c->udp_sync_count = -1; } return rv; @@ -1030,18 +1029,18 @@ int pa_raop_client_teardown(pa_raop_client *c) { return rv; } -int pa_raop_client_can_stream(pa_raop_client *c) { +int pa_raop_client_udp_can_stream(pa_raop_client *c) { int rv = 0; pa_assert(c); - if (c->stream_fd > 0) + if (c->udp_stream_fd > 0) rv = 1; return rv; } -int pa_raop_client_handle_timing_packet(pa_raop_client *c, const uint8_t packet[], ssize_t size) { +int pa_raop_client_udp_handle_timing_packet(pa_raop_client *c, const uint8_t packet[], ssize_t size) { const uint32_t * data = NULL; uint8_t payload = 0; struct timeval tv; @@ -1058,15 +1057,15 @@ int pa_raop_client_handle_timing_packet(pa_raop_client *c, const uint8_t packet[ return 1; } - data = (uint32_t *) (packet + sizeof(timming_header)); + data = (uint32_t *) (packet + sizeof(udp_timming_header)); rci = timeval_to_ntp(pa_rtclock_get(&tv)); /* The market bit is always set (see rfc3550 for packet structure) ! */ payload = packet[1] ^ 0x80; switch (payload) { - case PAYLOAD_TIMING_REQUEST: - rv = send_timing_packet(c, data, rci); + case UDP_PAYLOAD_TIMING_REQUEST: + rv = udp_send_timing_packet(c, data, rci); break; - case PAYLOAD_TIMING_RESPONSE: + case UDP_PAYLOAD_TIMING_RESPONSE: default: pa_log_debug("Got an unexpected payload type on timing channel !"); return 1; @@ -1075,7 +1074,7 @@ int pa_raop_client_handle_timing_packet(pa_raop_client *c, const uint8_t packet[ return rv; } -int pa_raop_client_handle_control_packet(pa_raop_client *c, const uint8_t packet[], ssize_t size) { +int pa_raop_client_udp_handle_control_packet(pa_raop_client *c, const uint8_t packet[], ssize_t size) { uint8_t payload = 0; int rv = 0; @@ -1089,13 +1088,14 @@ int pa_raop_client_handle_control_packet(pa_raop_client *c, const uint8_t packet } /* The market bit is always set (see rfc3550 for packet structure) ! */ + payload = packet[1] ^ 0x80; switch (payload) { - case PAYLOAD_RETRANSMIT_REQUEST: + case UDP_PAYLOAD_RETRANSMIT_REQUEST: /* Packet retransmission not implemented yet... */ /* rv = ... */ break; - case PAYLOAD_RETRANSMIT_REPLY: + case UDP_PAYLOAD_RETRANSMIT_REPLY: default: pa_log_debug("Got an unexpected payload type on control channel !"); return 1; @@ -1104,18 +1104,18 @@ int pa_raop_client_handle_control_packet(pa_raop_client *c, const uint8_t packet return rv; } -int pa_raop_client_get_blocks_size(pa_raop_client *c, size_t *size) { +int pa_raop_client_udp_get_blocks_size(pa_raop_client *c, size_t *size) { int rv = 0; pa_assert(c); pa_assert(size); - *size = FRAMES_PER_PACKET; + *size = UDP_FRAMES_PER_PACKET; return rv; } -int pa_raop_client_send_audio_packet(pa_raop_client *c, pa_memchunk *block, ssize_t *written) { +int pa_raop_client_udp_send_audio_packet(pa_raop_client *c, pa_memchunk *block, ssize_t *written) { uint32_t *buf = NULL; ssize_t length = 0; int rv = 0; @@ -1124,24 +1124,24 @@ int pa_raop_client_send_audio_packet(pa_raop_client *c, pa_memchunk *block, ssiz pa_assert(block); /* Sync RTP & NTP timestamp if required. */ - if (c->first_packet || c->sync_count >= c->sync_interval) { - send_sync_packet(c, c->rtptime); - c->sync_count = 0; + if (c->udp_first_packet || c->udp_sync_count >= c->udp_sync_interval) { + udp_send_sync_packet(c, c->rtptime); + c->udp_sync_count = 0; } else { - c->sync_count++; + c->udp_sync_count++; } buf = (uint32_t *) pa_memblock_acquire(block->memblock); if (buf != NULL && block->length > 0) - rv = send_audio_packet(c, buf + block->index, block->length, &length); + rv = udp_send_audio_packet(c, buf + block->index, block->length, &length); pa_memblock_release(block->memblock); block->index += length; block->length -= length; if (written != NULL) *written = length; - if (c->first_packet) - c->first_packet = false; + if (c->udp_first_packet) + c->udp_first_packet = false; return rv; } @@ -1256,38 +1256,38 @@ int pa_raop_client_encode_sample(pa_raop_client *c, pa_memchunk *raw, pa_memchun return 0; } -void pa_raop_client_set_callback(pa_raop_client *c, pa_raop_client_cb_t callback, void *userdata) { +void pa_raop_client_tcp_set_callback(pa_raop_client *c, pa_raop_client_cb_t callback, void *userdata) { pa_assert(c); - c->callback = callback; - c->userdata = userdata; + c->tcp_callback = callback; + c->tcp_userdata = userdata; } -void pa_raop_client_set_closed_callback(pa_raop_client *c, pa_raop_client_closed_cb_t callback, void *userdata) { +void pa_raop_client_tcp_set_closed_callback(pa_raop_client *c, pa_raop_client_closed_cb_t callback, void *userdata) { pa_assert(c); - c->closed_callback = callback; - c->closed_userdata = userdata; + c->tcp_closed_callback = callback; + c->tcp_closed_userdata = userdata; } -void pa_raop_client_set_setup_callback(pa_raop_client *c, pa_raop_client_setup_cb_t callback, void *userdata) { +void pa_raop_client_udp_set_setup_callback(pa_raop_client *c, pa_raop_client_setup_cb_t callback, void *userdata) { pa_assert(c); - c->setup_callback = callback; - c->setup_userdata = userdata; + c->udp_setup_callback = callback; + c->udp_setup_userdata = userdata; } -void pa_raop_client_set_record_callback(pa_raop_client *c, pa_raop_client_record_cb_t callback, void *userdata) { +void pa_raop_client_udp_set_record_callback(pa_raop_client *c, pa_raop_client_record_cb_t callback, void *userdata) { pa_assert(c); - c->record_callback = callback; - c->record_userdata = userdata; + c->udp_record_callback = callback; + c->udp_record_userdata = userdata; } -void pa_raop_client_set_disconnected_callback(pa_raop_client *c, pa_raop_client_disconnected_cb_t callback, void *userdata) { +void pa_raop_client_udp_set_disconnected_callback(pa_raop_client *c, pa_raop_client_disconnected_cb_t callback, void *userdata) { pa_assert(c); - c->disconnected_callback = callback; - c->disconnected_userdata = userdata; + c->udp_disconnected_callback = callback; + c->udp_disconnected_userdata = userdata; } diff --git a/src/modules/raop/raop_client.h b/src/modules/raop/raop_client.h index 97847d9..5cf1ff7 100644 --- a/src/modules/raop/raop_client.h +++ b/src/modules/raop/raop_client.h @@ -41,30 +41,30 @@ int pa_raop_client_connect(pa_raop_client *c); int pa_raop_client_flush(pa_raop_client *c); int pa_raop_client_teardown(pa_raop_client *c); -int pa_raop_client_can_stream(pa_raop_client *c); +int pa_raop_client_udp_can_stream(pa_raop_client *c); int pa_raop_client_set_volume(pa_raop_client *c, pa_volume_t volume); int pa_raop_client_encode_sample(pa_raop_client *c, pa_memchunk *raw, pa_memchunk *encoded); -int pa_raop_client_handle_timing_packet(pa_raop_client *c, const uint8_t packet +int pa_raop_client_udp_handle_timing_packet(pa_raop_client *c, const uint8_t packet [], ssize_t size); -int pa_raop_client_handle_control_packet(pa_raop_client *c, const uint8_t packet[], ssize_t size); -int pa_raop_client_get_blocks_size(pa_raop_client *c, size_t *size); -int pa_raop_client_send_audio_packet(pa_raop_client *c, pa_memchunk *block, ssize_t *written); +int pa_raop_client_udp_handle_control_packet(pa_raop_client *c, const uint8_t packet[], ssize_t size); +int pa_raop_client_udp_get_blocks_size(pa_raop_client *c, size_t *size); +int pa_raop_client_udp_send_audio_packet(pa_raop_client *c, pa_memchunk *block, ssize_t *written); typedef void (*pa_raop_client_cb_t)(int fd, void *userdata); -void pa_raop_client_set_callback(pa_raop_client *c, pa_raop_client_cb_t callback, void *userdata); +void pa_raop_client_tcp_set_callback(pa_raop_client *c, pa_raop_client_cb_t callback, void *userdata); typedef void (*pa_raop_client_closed_cb_t)(void *userdata); -void pa_raop_client_set_closed_callback(pa_raop_client *c, pa_raop_client_closed_cb_t callback, void *userdata); +void pa_raop_client_tcp_set_closed_callback(pa_raop_client *c, pa_raop_client_closed_cb_t callback, void *userdata); typedef void (*pa_raop_client_setup_cb_t)(int control_fd, int timing_fd, void *userdata); -void pa_raop_client_set_setup_callback(pa_raop_client *c, pa_raop_client_setup_cb_t callback, void *userdata); +void pa_raop_client_udp_set_setup_callback(pa_raop_client *c, pa_raop_client_setup_cb_t callback, void *userdata); typedef void (*pa_raop_client_record_cb_t)(void *userdata); -void pa_raop_client_set_record_callback(pa_raop_client *c, pa_raop_client_record_cb_t callback, void *userdata); +void pa_raop_client_udp_set_record_callback(pa_raop_client *c, pa_raop_client_record_cb_t callback, void *userdata); typedef void (*pa_raop_client_disconnected_cb_t)(void *userdata); -void pa_raop_client_set_disconnected_callback(pa_raop_client *c, pa_raop_client_disconnected_cb_t callback, void *userdata); +void pa_raop_client_udp_set_disconnected_callback(pa_raop_client *c, pa_raop_client_disconnected_cb_t callback, void *userdata); #endif -- 1.8.1.2