From 899492c31581f5591cd9437052dda15ad02ec0ac Mon Sep 17 00:00:00 2001 From: Colin Guthrie Date: Sun, 11 May 2008 14:18:48 +0000 Subject: Add a new callback structure to propigate when the RTSP connection dies git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/coling@2402 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/rtp/raop_client.c | 25 ++++++++++++++++++++++++- src/modules/rtp/raop_client.h | 3 +++ src/modules/rtp/rtsp_client.c | 7 ++++--- src/modules/rtp/rtsp_client.h | 3 ++- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/modules/rtp/raop_client.c b/src/modules/rtp/raop_client.c index b4cbd2ba..75881c6e 100644 --- a/src/modules/rtp/raop_client.c +++ b/src/modules/rtp/raop_client.c @@ -89,8 +89,11 @@ struct pa_raop_client { pa_socket_client *sc; int fd; + pa_raop_client_cb_t callback; void* userdata; + pa_raop_client_closed_cb_t closed_callback; + void* closed_userdata; uint8_t *buffer; uint32_t buffer_length; @@ -339,6 +342,19 @@ static void rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist* he case STATE_SET_PARAMETER: case STATE_FLUSH: break; + case STATE_DISCONNECTED: + pa_assert(c->closed_callback); + pa_log_debug("RTSP channel closed"); + if (c->fd > 0) { + pa_close(c->fd); + c->fd = -1; + } + if (c->sc) { + pa_socket_client_unref(c->sc); + c->sc = NULL; + } + c->closed_callback(c->closed_userdata); + break; } } @@ -437,7 +453,6 @@ pa_memchunk pa_raop_client_encode_sample(pa_raop_client* c, pa_mempool* mempool, c->buffer = pa_xrealloc(c->buffer, bufmax); c->buffer_length = bufmax; - pa_log_debug("Creating new memblock"); c->memchunk.memblock = pa_memblock_new_user(mempool, c->buffer, bufmax, noop, 0); } c->memchunk.index = 0; @@ -499,3 +514,11 @@ void pa_raop_client_set_callback(pa_raop_client* c, pa_raop_client_cb_t callback c->callback = callback; c->userdata = userdata; } + +void pa_raop_client_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; +} diff --git a/src/modules/rtp/raop_client.h b/src/modules/rtp/raop_client.h index 68a1cdb0..1ec56ca9 100644 --- a/src/modules/rtp/raop_client.h +++ b/src/modules/rtp/raop_client.h @@ -38,4 +38,7 @@ pa_memchunk pa_raop_client_encode_sample(pa_raop_client* c, pa_mempool* mempool, 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); +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); + #endif diff --git a/src/modules/rtp/rtsp_client.c b/src/modules/rtp/rtsp_client.c index 5665c9f6..22f0f0c1 100644 --- a/src/modules/rtp/rtsp_client.c +++ b/src/modules/rtp/rtsp_client.c @@ -173,6 +173,7 @@ static void headers_read(pa_rtsp_client *c) { pa_assert(c); pa_assert(c->response_headers); + pa_assert(c->callback); /* Deal with a SETUP response */ if (STATE_SETUP == c->state) { @@ -209,8 +210,7 @@ static void headers_read(pa_rtsp_client *c) { } /* Call our callback */ - if (c->callback) - c->callback(c, c->state, c->response_headers, c->userdata); + c->callback(c, c->state, c->response_headers, c->userdata); pa_headerlist_free(c->response_headers); c->response_headers = NULL; @@ -224,12 +224,13 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) { pa_rtsp_client *c = userdata; pa_assert(line); pa_assert(c); + pa_assert(c->callback); if (!s) { - pa_log_warn("Connection closed"); pa_ioline_unref(c->ioline); c->ioline = NULL; pa_rtsp_disconnect(c); + c->callback(c, STATE_DISCONNECTED, NULL, c->userdata); return; } diff --git a/src/modules/rtp/rtsp_client.h b/src/modules/rtp/rtsp_client.h index 0f1daabd..3c5280c2 100644 --- a/src/modules/rtp/rtsp_client.h +++ b/src/modules/rtp/rtsp_client.h @@ -44,7 +44,8 @@ typedef enum { STATE_RECORD, STATE_TEARDOWN, STATE_SET_PARAMETER, - STATE_FLUSH + STATE_FLUSH, + STATE_DISCONNECTED } pa_rtsp_state; typedef void (*pa_rtsp_cb_t)(pa_rtsp_client *c, pa_rtsp_state state, pa_headerlist* hl, void *userdata); -- cgit