summaryrefslogtreecommitdiffstats
path: root/src/modules/rtp/raop_client.c
diff options
context:
space:
mode:
authorColin Guthrie <pulse@colin.guthr.ie>2008-06-10 23:55:58 +0000
committerColin Guthrie <pulse@colin.guthr.ie>2008-10-08 20:32:09 +0100
commitc49be7891fac98056010cf553042946740061590 (patch)
treee8c683339418f22020269e0ba36887874d4352c5 /src/modules/rtp/raop_client.c
parentd86fc75e0cbc9d102dc000d2781f9dfddc89fbbf (diff)
Add some new public API functions to connect and flush.
This allows us to reconnect upon disconnection but this has thus far proved unreliable. We no longer close the socket. We leave this to the module thread to do the closing. We can also flush the remote buffer now. Refs #69 git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/coling@2503 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src/modules/rtp/raop_client.c')
-rw-r--r--src/modules/rtp/raop_client.c73
1 files changed, 53 insertions, 20 deletions
diff --git a/src/modules/rtp/raop_client.c b/src/modules/rtp/raop_client.c
index 4714d273..48deff0d 100644
--- a/src/modules/rtp/raop_client.c
+++ b/src/modules/rtp/raop_client.c
@@ -336,22 +336,30 @@ static void rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist* he
break;
}
+ case STATE_FLUSH:
+ pa_log_debug("RAOP: FLUSHED");
+ break;
+
case STATE_TEARDOWN:
case STATE_SET_PARAMETER:
- case STATE_FLUSH:
break;
case STATE_DISCONNECTED:
pa_assert(c->closed_callback);
- pa_log_debug("RTSP channel closed");
+ pa_assert(c->rtsp);
+
+ pa_log_debug("RTSP control channel closed");
+ pa_rtsp_client_free(c->rtsp);
c->rtsp = NULL;
if (c->fd > 0) {
- pa_close(c->fd);
+ /* We do not close the fd, we leave it to the closed callback to do that */
c->fd = -1;
}
if (c->sc) {
pa_socket_client_unref(c->sc);
c->sc = NULL;
}
+ pa_xfree(c->sid);
+ c->sid = NULL;
c->closed_callback(c->closed_userdata);
break;
}
@@ -359,12 +367,6 @@ static void rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist* he
pa_raop_client* pa_raop_client_new(pa_core *core, const char* host)
{
- char *sci;
- struct {
- uint32_t a;
- uint32_t b;
- uint32_t c;
- } rand_data;
pa_raop_client* c = pa_xnew0(pa_raop_client, 1);
pa_assert(core);
@@ -373,7 +375,43 @@ pa_raop_client* pa_raop_client_new(pa_core *core, const char* host)
c->core = core;
c->fd = -1;
c->host = pa_xstrdup(host);
- c->rtsp = pa_rtsp_client_new("iTunes/4.6 (Macintosh; U; PPC Mac OS X 10.3)");
+
+ if (pa_raop_connect(c)) {
+ pa_raop_client_free(c);
+ return NULL;
+ }
+ return c;
+}
+
+
+void pa_raop_client_free(pa_raop_client* c)
+{
+ pa_assert(c);
+
+ if (c->rtsp)
+ pa_rtsp_client_free(c->rtsp);
+ pa_xfree(c->host);
+ pa_xfree(c);
+}
+
+
+int pa_raop_connect(pa_raop_client* c)
+{
+ char *sci;
+ struct {
+ uint32_t a;
+ uint32_t b;
+ uint32_t c;
+ } rand_data;
+
+ pa_assert(c);
+
+ if (c->rtsp) {
+ pa_log_debug("Connection already in progress");
+ return 0;
+ }
+
+ c->rtsp = pa_rtsp_client_new(c->core->mainloop, c->host, 5000, "iTunes/4.6 (Macintosh; U; PPC Mac OS X 10.3)");
/* Initialise the AES encryption system */
pa_random(c->aes_iv, sizeof(c->aes_iv));
@@ -386,23 +424,18 @@ pa_raop_client* pa_raop_client_new(pa_core *core, const char* host)
c->sid = pa_sprintf_malloc("%u", rand_data.a);
sci = pa_sprintf_malloc("%08x%08x",rand_data.b, rand_data.c);
pa_rtsp_add_header(c->rtsp, "Client-Instance", sci);
+ pa_xfree(sci);
pa_rtsp_set_callback(c->rtsp, rtsp_cb, c);
- if (pa_rtsp_connect(c->rtsp, c->core->mainloop, host, 5000)) {
- pa_rtsp_client_free(c->rtsp);
- return NULL;
- }
- return c;
+ return pa_rtsp_connect(c->rtsp);
}
-void pa_raop_client_free(pa_raop_client* c)
+int pa_raop_flush(pa_raop_client* c)
{
pa_assert(c);
- if (c->rtsp)
- pa_rtsp_client_free(c->rtsp);
- pa_xfree(c->host);
- pa_xfree(c);
+ pa_rtsp_flush(c->rtsp, c->seq, c->rtptime);
+ return 0;
}