From bff03a181f8c4102a75144f818ea15ea53165170 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 23 May 2013 21:23:32 +0200 Subject: core: add a spsc ringbuffer implementation Currently every single AO was implementing it's own ringbuffer, many times with slightly different semantics. This is an attempt to fix the problem. I stole some good ideas from ao_portaudio's ringbuffer and went from there. The main difference is this one stores wpos and rpos which are absolute positions in an "infinite" buffer. To find the actual position for writing / reading just apply modulo size. The producer only modifies wpos while the consumer only modifies rpos. This makes it pretty easy to reason about and make the operations thread safe by using barriers (thread safety is guaranteed only in the Single-Producer/Single- Consumer case). Also adapted ao_coreaudio to use this ringbuffer. --- audio/out/ao_coreaudio/ca_ringbuffer_internal.h | 37 ------------------------- 1 file changed, 37 deletions(-) delete mode 100644 audio/out/ao_coreaudio/ca_ringbuffer_internal.h (limited to 'audio/out/ao_coreaudio/ca_ringbuffer_internal.h') diff --git a/audio/out/ao_coreaudio/ca_ringbuffer_internal.h b/audio/out/ao_coreaudio/ca_ringbuffer_internal.h deleted file mode 100644 index 50b41871b9..0000000000 --- a/audio/out/ao_coreaudio/ca_ringbuffer_internal.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * This file is part of mpv. - * - * mpv is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * mpv is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with mpv. If not, see . - */ - -#ifndef MPV_AUDIO_OUT_CA_RINGBUFFER_H -#define MPV_AUDIO_OUT_CA_RINGBUFFER_H - -struct ca_ringbuffer; - -struct ca_ringbuffer *ca_ringbuffer_new(void *talloc_ctx, int chunks, int chunk_size); -struct ca_ringbuffer *ca_ringbuffer_new2(void *talloc_ctx, int bps, int chunk_size); -int ca_ringbuffer_read(struct ca_ringbuffer *buffer, unsigned char *data, int len); -int ca_ringbuffer_write(struct ca_ringbuffer *buffer, unsigned char *data, int len); - -void ca_ringbuffer_reset(struct ca_ringbuffer *buffer); - -int ca_ringbuffer_available(struct ca_ringbuffer *buffer); -int ca_ringbuffer_size(struct ca_ringbuffer *buffer); -int ca_ringbuffer_buffered(struct ca_ringbuffer *buffer); -int ca_ringbuffer_chunk_size(struct ca_ringbuffer *buffer); - -char *ca_ringbuffer_repr(struct ca_ringbuffer *buffer, void *talloc_ctx); - -#endif -- cgit v1.2.3