mirror of
https://github.com/Ryujinx/libsoundio.git
synced 2025-07-01 12:38:15 +00:00
POSIX ring buffer works on OSX and is simpler
This commit is contained in:
parent
a69ff6025c
commit
2b0744816f
|
@ -99,7 +99,6 @@ make
|
||||||
|
|
||||||
## Roadmap
|
## Roadmap
|
||||||
|
|
||||||
0. sine example working with dummy backend osx
|
|
||||||
0. pipe record to playback example working with dummy linux, osx, windows
|
0. pipe record to playback example working with dummy linux, osx, windows
|
||||||
0. pipe record to playback example working with pulseaudio linux
|
0. pipe record to playback example working with pulseaudio linux
|
||||||
0. implement CoreAudio (OSX) backend, get examples working
|
0. implement CoreAudio (OSX) backend, get examples working
|
||||||
|
|
|
@ -16,6 +16,10 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#ifndef MAP_ANONYMOUS
|
||||||
|
#define MAP_ANONYMOUS MAP_ANON
|
||||||
|
#endif
|
||||||
|
|
||||||
struct SoundIoRingBuffer *soundio_ring_buffer_create(struct SoundIo *soundio, int requested_capacity) {
|
struct SoundIoRingBuffer *soundio_ring_buffer_create(struct SoundIo *soundio, int requested_capacity) {
|
||||||
SoundIoRingBuffer *rb = create<SoundIoRingBuffer>();
|
SoundIoRingBuffer *rb = create<SoundIoRingBuffer>();
|
||||||
|
|
||||||
|
@ -88,34 +92,21 @@ int soundio_ring_buffer_init(struct SoundIoRingBuffer *rb, int requested_capacit
|
||||||
rb->write_offset = 0;
|
rb->write_offset = 0;
|
||||||
rb->read_offset = 0;
|
rb->read_offset = 0;
|
||||||
|
|
||||||
char shm_path[] = "/dev/shm/ring-buffer-XXXXXX";
|
rb->address = (char*)mmap(NULL, rb->capacity * 2, PROT_NONE,
|
||||||
int fd = mkstemp(shm_path);
|
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
|
||||||
if (fd < 0)
|
|
||||||
return SoundIoErrorSystemResources;
|
|
||||||
|
|
||||||
if (unlink(shm_path))
|
|
||||||
return SoundIoErrorSystemResources;
|
|
||||||
|
|
||||||
if (ftruncate(fd, rb->capacity))
|
|
||||||
return SoundIoErrorNoMem;
|
|
||||||
|
|
||||||
rb->address = (char*)mmap(NULL, rb->capacity * 2, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
|
|
||||||
if (rb->address == MAP_FAILED)
|
if (rb->address == MAP_FAILED)
|
||||||
return SoundIoErrorNoMem;
|
return SoundIoErrorNoMem;
|
||||||
|
|
||||||
char *other_address = (char*)mmap(rb->address, rb->capacity,
|
char *other_address = (char*)mmap(rb->address, rb->capacity,
|
||||||
PROT_READ|PROT_WRITE, MAP_FIXED|MAP_SHARED, fd, 0);
|
PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_FIXED|MAP_SHARED, -1, 0);
|
||||||
if (other_address != rb->address)
|
if (other_address != rb->address)
|
||||||
return SoundIoErrorNoMem;
|
return SoundIoErrorNoMem;
|
||||||
|
|
||||||
other_address = (char*)mmap(rb->address + rb->capacity, rb->capacity,
|
other_address = (char*)mmap(rb->address + rb->capacity, rb->capacity,
|
||||||
PROT_READ|PROT_WRITE, MAP_FIXED|MAP_SHARED, fd, 0);
|
PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_FIXED|MAP_SHARED, -1, 0);
|
||||||
if (other_address != rb->address + rb->capacity)
|
if (other_address != rb->address + rb->capacity)
|
||||||
return SoundIoErrorNoMem;
|
return SoundIoErrorNoMem;
|
||||||
|
|
||||||
if (close(fd))
|
|
||||||
return SoundIoErrorSystemResources;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue