mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	some modernizations
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/glitch-free@2343 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
		
							parent
							
								
									7d6269e57a
								
							
						
					
					
						commit
						775bc6c108
					
				
					 2 changed files with 23 additions and 16 deletions
				
			
		| 
						 | 
					@ -49,7 +49,6 @@ struct pa_ioline {
 | 
				
			||||||
    pa_iochannel *io;
 | 
					    pa_iochannel *io;
 | 
				
			||||||
    pa_defer_event *defer_event;
 | 
					    pa_defer_event *defer_event;
 | 
				
			||||||
    pa_mainloop_api *mainloop;
 | 
					    pa_mainloop_api *mainloop;
 | 
				
			||||||
    int dead;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    char *wbuf;
 | 
					    char *wbuf;
 | 
				
			||||||
    size_t wbuf_length, wbuf_index, wbuf_valid_length;
 | 
					    size_t wbuf_length, wbuf_index, wbuf_valid_length;
 | 
				
			||||||
| 
						 | 
					@ -57,10 +56,11 @@ struct pa_ioline {
 | 
				
			||||||
    char *rbuf;
 | 
					    char *rbuf;
 | 
				
			||||||
    size_t rbuf_length, rbuf_index, rbuf_valid_length;
 | 
					    size_t rbuf_length, rbuf_index, rbuf_valid_length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void (*callback)(pa_ioline*io, const char *s, void *userdata);
 | 
					    pa_ioline_cb_t callback;
 | 
				
			||||||
    void *userdata;
 | 
					    void *userdata;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int defer_close;
 | 
					    pa_bool_t dead:1;
 | 
				
			||||||
 | 
					    pa_bool_t defer_close:1;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void io_callback(pa_iochannel*io, void *userdata);
 | 
					static void io_callback(pa_iochannel*io, void *userdata);
 | 
				
			||||||
| 
						 | 
					@ -73,7 +73,6 @@ pa_ioline* pa_ioline_new(pa_iochannel *io) {
 | 
				
			||||||
    l = pa_xnew(pa_ioline, 1);
 | 
					    l = pa_xnew(pa_ioline, 1);
 | 
				
			||||||
    PA_REFCNT_INIT(l);
 | 
					    PA_REFCNT_INIT(l);
 | 
				
			||||||
    l->io = io;
 | 
					    l->io = io;
 | 
				
			||||||
    l->dead = 0;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    l->wbuf = NULL;
 | 
					    l->wbuf = NULL;
 | 
				
			||||||
    l->wbuf_length = l->wbuf_index = l->wbuf_valid_length = 0;
 | 
					    l->wbuf_length = l->wbuf_index = l->wbuf_valid_length = 0;
 | 
				
			||||||
| 
						 | 
					@ -89,7 +88,8 @@ pa_ioline* pa_ioline_new(pa_iochannel *io) {
 | 
				
			||||||
    l->defer_event = l->mainloop->defer_new(l->mainloop, defer_callback, l);
 | 
					    l->defer_event = l->mainloop->defer_new(l->mainloop, defer_callback, l);
 | 
				
			||||||
    l->mainloop->defer_enable(l->defer_event, 0);
 | 
					    l->mainloop->defer_enable(l->defer_event, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    l->defer_close = 0;
 | 
					    l->dead = FALSE;
 | 
				
			||||||
 | 
					    l->defer_close = FALSE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_iochannel_set_callback(io, io_callback, l);
 | 
					    pa_iochannel_set_callback(io, io_callback, l);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -130,7 +130,7 @@ void pa_ioline_close(pa_ioline *l) {
 | 
				
			||||||
    pa_assert(l);
 | 
					    pa_assert(l);
 | 
				
			||||||
    pa_assert(PA_REFCNT_VALUE(l) >= 1);
 | 
					    pa_assert(PA_REFCNT_VALUE(l) >= 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    l->dead = 1;
 | 
					    l->dead = TRUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (l->io) {
 | 
					    if (l->io) {
 | 
				
			||||||
        pa_iochannel_free(l->io);
 | 
					        pa_iochannel_free(l->io);
 | 
				
			||||||
| 
						 | 
					@ -166,11 +166,13 @@ void pa_ioline_puts(pa_ioline *l, const char *c) {
 | 
				
			||||||
        /* In case the allocated buffer is too small, enlarge it. */
 | 
					        /* In case the allocated buffer is too small, enlarge it. */
 | 
				
			||||||
        if (l->wbuf_valid_length + len > l->wbuf_length) {
 | 
					        if (l->wbuf_valid_length + len > l->wbuf_length) {
 | 
				
			||||||
            size_t n = l->wbuf_valid_length+len;
 | 
					            size_t n = l->wbuf_valid_length+len;
 | 
				
			||||||
            char *new = pa_xmalloc(n);
 | 
					            char *new = pa_xnew(char, n);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (l->wbuf) {
 | 
					            if (l->wbuf) {
 | 
				
			||||||
                memcpy(new, l->wbuf+l->wbuf_index, l->wbuf_valid_length);
 | 
					                memcpy(new, l->wbuf+l->wbuf_index, l->wbuf_valid_length);
 | 
				
			||||||
                pa_xfree(l->wbuf);
 | 
					                pa_xfree(l->wbuf);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            l->wbuf = new;
 | 
					            l->wbuf = new;
 | 
				
			||||||
            l->wbuf_length = n;
 | 
					            l->wbuf_length = n;
 | 
				
			||||||
            l->wbuf_index = 0;
 | 
					            l->wbuf_index = 0;
 | 
				
			||||||
| 
						 | 
					@ -191,15 +193,18 @@ void pa_ioline_puts(pa_ioline *l, const char *c) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void pa_ioline_set_callback(pa_ioline*l, void (*callback)(pa_ioline*io, const char *s, void *userdata), void *userdata) {
 | 
					void pa_ioline_set_callback(pa_ioline*l, pa_ioline_cb_t callback, void *userdata) {
 | 
				
			||||||
    pa_assert(l);
 | 
					    pa_assert(l);
 | 
				
			||||||
    pa_assert(PA_REFCNT_VALUE(l) >= 1);
 | 
					    pa_assert(PA_REFCNT_VALUE(l) >= 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (l->dead)
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    l->callback = callback;
 | 
					    l->callback = callback;
 | 
				
			||||||
    l->userdata = userdata;
 | 
					    l->userdata = userdata;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void failure(pa_ioline *l, int process_leftover) {
 | 
					static void failure(pa_ioline *l, pa_bool_t process_leftover) {
 | 
				
			||||||
    pa_assert(l);
 | 
					    pa_assert(l);
 | 
				
			||||||
    pa_assert(PA_REFCNT_VALUE(l) >= 1);
 | 
					    pa_assert(PA_REFCNT_VALUE(l) >= 1);
 | 
				
			||||||
    pa_assert(!l->dead);
 | 
					    pa_assert(!l->dead);
 | 
				
			||||||
| 
						 | 
					@ -282,7 +287,7 @@ static int do_read(pa_ioline *l) {
 | 
				
			||||||
                    memmove(l->rbuf, l->rbuf+l->rbuf_index, l->rbuf_valid_length);
 | 
					                    memmove(l->rbuf, l->rbuf+l->rbuf_index, l->rbuf_valid_length);
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                /* Enlarge the buffer */
 | 
					                /* Enlarge the buffer */
 | 
				
			||||||
                char *new = pa_xmalloc(n);
 | 
					                char *new = pa_xnew(char, n);
 | 
				
			||||||
                if (l->rbuf_valid_length)
 | 
					                if (l->rbuf_valid_length)
 | 
				
			||||||
                    memcpy(new, l->rbuf+l->rbuf_index, l->rbuf_valid_length);
 | 
					                    memcpy(new, l->rbuf+l->rbuf_index, l->rbuf_valid_length);
 | 
				
			||||||
                pa_xfree(l->rbuf);
 | 
					                pa_xfree(l->rbuf);
 | 
				
			||||||
| 
						 | 
					@ -305,9 +310,9 @@ static int do_read(pa_ioline *l) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (r < 0 && errno != ECONNRESET) {
 | 
					            if (r < 0 && errno != ECONNRESET) {
 | 
				
			||||||
                pa_log("read(): %s", pa_cstrerror(errno));
 | 
					                pa_log("read(): %s", pa_cstrerror(errno));
 | 
				
			||||||
                failure(l, 0);
 | 
					                failure(l, FALSE);
 | 
				
			||||||
            } else
 | 
					            } else
 | 
				
			||||||
                failure(l, 1);
 | 
					                failure(l, TRUE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return -1;
 | 
					            return -1;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -338,7 +343,7 @@ static int do_write(pa_ioline *l) {
 | 
				
			||||||
            if (r < 0 && errno != EPIPE)
 | 
					            if (r < 0 && errno != EPIPE)
 | 
				
			||||||
                pa_log("write(): %s", pa_cstrerror(errno));
 | 
					                pa_log("write(): %s", pa_cstrerror(errno));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            failure(l, 0);
 | 
					            failure(l, FALSE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return -1;
 | 
					            return -1;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -370,7 +375,7 @@ static void do_work(pa_ioline *l) {
 | 
				
			||||||
        do_write(l);
 | 
					        do_write(l);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (l->defer_close && !l->wbuf_valid_length)
 | 
					    if (l->defer_close && !l->wbuf_valid_length)
 | 
				
			||||||
        failure(l, 1);
 | 
					        failure(l, TRUE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_ioline_unref(l);
 | 
					    pa_ioline_unref(l);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -400,7 +405,7 @@ void pa_ioline_defer_close(pa_ioline *l) {
 | 
				
			||||||
    pa_assert(l);
 | 
					    pa_assert(l);
 | 
				
			||||||
    pa_assert(PA_REFCNT_VALUE(l) >= 1);
 | 
					    pa_assert(PA_REFCNT_VALUE(l) >= 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    l->defer_close = 1;
 | 
					    l->defer_close = TRUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!l->wbuf_valid_length)
 | 
					    if (!l->wbuf_valid_length)
 | 
				
			||||||
        l->mainloop->defer_enable(l->defer_event, 1);
 | 
					        l->mainloop->defer_enable(l->defer_event, 1);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,6 +33,8 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct pa_ioline pa_ioline;
 | 
					typedef struct pa_ioline pa_ioline;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef void (*pa_ioline_cb_t)(pa_ioline*io, const char *s, void *userdata);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pa_ioline* pa_ioline_new(pa_iochannel *io);
 | 
					pa_ioline* pa_ioline_new(pa_iochannel *io);
 | 
				
			||||||
void pa_ioline_unref(pa_ioline *l);
 | 
					void pa_ioline_unref(pa_ioline *l);
 | 
				
			||||||
pa_ioline* pa_ioline_ref(pa_ioline *l);
 | 
					pa_ioline* pa_ioline_ref(pa_ioline *l);
 | 
				
			||||||
| 
						 | 
					@ -45,7 +47,7 @@ void pa_ioline_puts(pa_ioline *s, const char *c);
 | 
				
			||||||
void pa_ioline_printf(pa_ioline *s, const char *format, ...) PA_GCC_PRINTF_ATTR(2,3);
 | 
					void pa_ioline_printf(pa_ioline *s, const char *format, ...) PA_GCC_PRINTF_ATTR(2,3);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Set the callback function that is called for every recieved line */
 | 
					/* Set the callback function that is called for every recieved line */
 | 
				
			||||||
void pa_ioline_set_callback(pa_ioline*io, void (*callback)(pa_ioline*io, const char *s, void *userdata), void *userdata);
 | 
					void pa_ioline_set_callback(pa_ioline*io, pa_ioline_cb_t callback, void *userdata);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Make sure to close the ioline object as soon as the send buffer is emptied */
 | 
					/* Make sure to close the ioline object as soon as the send buffer is emptied */
 | 
				
			||||||
void pa_ioline_defer_close(pa_ioline *io);
 | 
					void pa_ioline_defer_close(pa_ioline *io);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue