Update OpenAL Soft to 1.18.2

This commit is contained in:
Alex Szpakowski
2017-12-10 22:34:10 -04:00
parent 75e0077566
commit b160006eb1
152 changed files with 33572 additions and 15363 deletions
+206 -91
View File
@@ -182,6 +182,8 @@ static ALCboolean pulse_load(void)
#ifdef HAVE_DYNLOAD
if(!pa_handle)
{
al_string missing_funcs = AL_STRING_INIT_STATIC();
#ifdef _WIN32
#define PALIB "libpulse-0.dll"
#elif defined(__APPLE__) && defined(__MACH__)
@@ -191,12 +193,16 @@ static ALCboolean pulse_load(void)
#endif
pa_handle = LoadLib(PALIB);
if(!pa_handle)
{
WARN("Failed to load %s\n", PALIB);
return ALC_FALSE;
}
#define LOAD_FUNC(x) do { \
p##x = GetSymbol(pa_handle, #x); \
if(!(p##x)) { \
ret = ALC_FALSE; \
alstr_append_cstr(&missing_funcs, "\n" #x); \
} \
} while(0)
LOAD_FUNC(pa_context_unref);
@@ -270,9 +276,11 @@ static ALCboolean pulse_load(void)
if(ret == ALC_FALSE)
{
WARN("Missing expected functions:%s\n", alstr_get_cstr(missing_funcs));
CloseLib(pa_handle);
pa_handle = NULL;
}
alstr_reset(&missing_funcs);
}
#endif /* HAVE_DYNLOAD */
return ret;
@@ -443,7 +451,7 @@ static void clear_devlist(vector_DevMap *list)
#define DEINIT_STRS(i) (AL_STRING_DEINIT((i)->name),AL_STRING_DEINIT((i)->device_name))
VECTOR_FOR_EACH(DevMap, *list, DEINIT_STRS);
#undef DEINIT_STRS
VECTOR_RESIZE(*list, 0);
VECTOR_RESIZE(*list, 0, 0);
}
@@ -489,7 +497,7 @@ static ALCboolean ALCpulsePlayback_start(ALCpulsePlayback *self);
static void ALCpulsePlayback_stop(ALCpulsePlayback *self);
static DECLARE_FORWARD2(ALCpulsePlayback, ALCbackend, ALCenum, captureSamples, ALCvoid*, ALCuint)
static DECLARE_FORWARD(ALCpulsePlayback, ALCbackend, ALCuint, availableSamples)
static ALint64 ALCpulsePlayback_getLatency(ALCpulsePlayback *self);
static ClockLatency ALCpulsePlayback_getClockLatency(ALCpulsePlayback *self);
static void ALCpulsePlayback_lock(ALCpulsePlayback *self);
static void ALCpulsePlayback_unlock(ALCpulsePlayback *self);
DECLARE_DEFAULT_ALLOCATORS(ALCpulsePlayback)
@@ -525,35 +533,35 @@ static void ALCpulsePlayback_deviceCallback(pa_context *UNUSED(context), const p
return;
}
#define MATCH_INFO_NAME(iter) (al_string_cmp_cstr((iter)->device_name, info->name) == 0)
#define MATCH_INFO_NAME(iter) (alstr_cmp_cstr((iter)->device_name, info->name) == 0)
VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_INFO_NAME);
if(iter != VECTOR_ITER_END(PlaybackDevices)) return;
if(iter != VECTOR_END(PlaybackDevices)) return;
#undef MATCH_INFO_NAME
AL_STRING_INIT(entry.name);
AL_STRING_INIT(entry.device_name);
al_string_copy_cstr(&entry.device_name, info->name);
alstr_copy_cstr(&entry.device_name, info->name);
count = 0;
while(1)
{
al_string_copy_cstr(&entry.name, info->description);
alstr_copy_cstr(&entry.name, info->description);
if(count != 0)
{
char str[64];
snprintf(str, sizeof(str), " #%d", count+1);
al_string_append_cstr(&entry.name, str);
alstr_append_cstr(&entry.name, str);
}
#define MATCH_ENTRY(i) (al_string_cmp(entry.name, (i)->name) == 0)
#define MATCH_ENTRY(i) (alstr_cmp(entry.name, (i)->name) == 0)
VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_ENTRY);
if(iter == VECTOR_ITER_END(PlaybackDevices)) break;
if(iter == VECTOR_END(PlaybackDevices)) break;
#undef MATCH_ENTRY
count++;
}
TRACE("Got device \"%s\", \"%s\"\n", al_string_get_cstr(entry.name), al_string_get_cstr(entry.device_name));
TRACE("Got device \"%s\", \"%s\"\n", alstr_get_cstr(entry.name), alstr_get_cstr(entry.device_name));
VECTOR_PUSH_BACK(PlaybackDevices, entry);
}
@@ -618,6 +626,11 @@ static void ALCpulsePlayback_bufferAttrCallback(pa_stream *stream, void *pdata)
self->attr = *pa_stream_get_buffer_attr(stream);
TRACE("minreq=%d, tlength=%d, prebuf=%d\n", self->attr.minreq, self->attr.tlength, self->attr.prebuf);
/* FIXME: Update the device's UpdateSize (and/or NumUpdates) using the new
* buffer attributes? Changing UpdateSize will change the ALC_REFRESH
* property, which probably shouldn't change between device resets. But
* leaving it alone means ALC_REFRESH will be off.
*/
}
static void ALCpulsePlayback_contextStateCallback(pa_context *context, void *pdata)
@@ -729,7 +742,7 @@ static void ALCpulsePlayback_sinkNameCallback(pa_context *UNUSED(context), const
return;
}
al_string_copy_cstr(&device->DeviceName, info->description);
alstr_copy_cstr(&device->DeviceName, info->description);
}
@@ -737,9 +750,9 @@ static void ALCpulsePlayback_streamMovedCallback(pa_stream *stream, void *pdata)
{
ALCpulsePlayback *self = pdata;
al_string_copy_cstr(&self->device_name, pa_stream_get_device_name(stream));
alstr_copy_cstr(&self->device_name, pa_stream_get_device_name(stream));
TRACE("Stream moved to %s\n", al_string_get_cstr(self->device_name));
TRACE("Stream moved to %s\n", alstr_get_cstr(self->device_name));
}
@@ -751,6 +764,13 @@ static pa_stream *ALCpulsePlayback_connectStream(const char *device_name,
pa_stream_state_t state;
pa_stream *stream;
if(!device_name)
{
device_name = getenv("ALSOFT_PULSE_DEFAULT");
if(device_name && !device_name[0])
device_name = NULL;
}
stream = pa_stream_new_with_proplist(context, "Playback Stream", spec, chanmap, prop_filter);
if(!stream)
{
@@ -789,7 +809,6 @@ static int ALCpulsePlayback_mixerProc(void *ptr)
ALCpulsePlayback *self = ptr;
ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
ALuint buffer_size;
ALint update_size;
size_t frame_size;
ssize_t len;
@@ -798,18 +817,31 @@ static int ALCpulsePlayback_mixerProc(void *ptr)
pa_threaded_mainloop_lock(self->loop);
frame_size = pa_frame_size(&self->spec);
update_size = device->UpdateSize * frame_size;
/* Sanitize buffer metrics, in case we actually have less than what we
* asked for. */
buffer_size = minu(update_size*device->NumUpdates, self->attr.tlength);
update_size = minu(update_size, buffer_size/2);
do {
len = pa_stream_writable_size(self->stream) - self->attr.tlength +
buffer_size;
if(len < update_size)
while(!self->killNow && device->Connected)
{
len = pa_stream_writable_size(self->stream);
if(len < 0)
{
if(pa_stream_is_corked(self->stream) == 1)
ERR("Failed to get writable size: %ld", (long)len);
aluHandleDisconnect(device);
break;
}
/* Make sure we're going to write at least 2 'periods' (minreqs), in
* case the server increased it since starting playback. Also round up
* the number of writable periods if it's not an integer count.
*/
buffer_size = maxu((self->attr.tlength + self->attr.minreq/2) / self->attr.minreq, 2) *
self->attr.minreq;
/* NOTE: This assumes pa_stream_writable_size returns between 0 and
* tlength, else there will be more latency than intended.
*/
len = mini(len - (ssize_t)self->attr.tlength, 0) + buffer_size;
if(len < (int32_t)self->attr.minreq)
{
if(pa_stream_is_corked(self->stream))
{
pa_operation *o;
o = pa_stream_cork(self->stream, 0, NULL, NULL);
@@ -818,11 +850,12 @@ static int ALCpulsePlayback_mixerProc(void *ptr)
pa_threaded_mainloop_wait(self->loop);
continue;
}
len -= len%update_size;
len -= len%self->attr.minreq;
while(len > 0)
{
size_t newlen = len;
int ret;
void *buf;
pa_free_cb_t free_func = NULL;
@@ -834,10 +867,15 @@ static int ALCpulsePlayback_mixerProc(void *ptr)
aluMixData(device, buf, newlen/frame_size);
pa_stream_write(self->stream, buf, newlen, free_func, 0, PA_SEEK_RELATIVE);
ret = pa_stream_write(self->stream, buf, newlen, free_func, 0, PA_SEEK_RELATIVE);
if(ret != PA_OK)
{
ERR("Failed to write to stream: %d, %s\n", ret, pa_strerror(ret));
break;
}
len -= newlen;
}
} while(!self->killNow && device->Connected);
}
pa_threaded_mainloop_unlock(self->loop);
return 0;
@@ -858,12 +896,12 @@ static ALCenum ALCpulsePlayback_open(ALCpulsePlayback *self, const ALCchar *name
if(VECTOR_SIZE(PlaybackDevices) == 0)
ALCpulsePlayback_probeDevices();
#define MATCH_NAME(iter) (al_string_cmp_cstr((iter)->name, name) == 0)
#define MATCH_NAME(iter) (alstr_cmp_cstr((iter)->name, name) == 0)
VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_NAME);
#undef MATCH_NAME
if(iter == VECTOR_ITER_END(PlaybackDevices))
if(iter == VECTOR_END(PlaybackDevices))
return ALC_INVALID_VALUE;
pulse_name = al_string_get_cstr(iter->device_name);
pulse_name = alstr_get_cstr(iter->device_name);
dev_name = iter->name;
}
@@ -894,11 +932,11 @@ static ALCenum ALCpulsePlayback_open(ALCpulsePlayback *self, const ALCchar *name
}
pa_stream_set_moved_callback(self->stream, ALCpulsePlayback_streamMovedCallback, self);
al_string_copy_cstr(&self->device_name, pa_stream_get_device_name(self->stream));
if(al_string_empty(dev_name))
alstr_copy_cstr(&self->device_name, pa_stream_get_device_name(self->stream));
if(alstr_empty(dev_name))
{
pa_operation *o = pa_context_get_sink_info_by_name(
self->context, al_string_get_cstr(self->device_name),
self->context, alstr_get_cstr(self->device_name),
ALCpulsePlayback_sinkNameCallback, self
);
wait_for_operation(o, self->loop);
@@ -906,7 +944,7 @@ static ALCenum ALCpulsePlayback_open(ALCpulsePlayback *self, const ALCchar *name
else
{
ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
al_string_copy(&device->DeviceName, dev_name);
alstr_copy(&device->DeviceName, dev_name);
}
pa_threaded_mainloop_unlock(self->loop);
@@ -921,7 +959,7 @@ static void ALCpulsePlayback_close(ALCpulsePlayback *self)
self->context = NULL;
self->stream = NULL;
al_string_clear(&self->device_name);
alstr_clear(&self->device_name);
}
static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
@@ -931,7 +969,6 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
const char *mapname = NULL;
pa_channel_map chanmap;
pa_operation *o;
ALuint len;
pa_threaded_mainloop_lock(self->loop);
@@ -946,11 +983,11 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
self->stream = NULL;
}
o = pa_context_get_sink_info_by_name(self->context, al_string_get_cstr(self->device_name),
o = pa_context_get_sink_info_by_name(self->context, alstr_get_cstr(self->device_name),
ALCpulsePlayback_sinkInfoCallback, self);
wait_for_operation(o, self->loop);
if(GetConfigValueBool(al_string_get_cstr(device->DeviceName), "pulse", "fix-rate", 0) ||
if(GetConfigValueBool(alstr_get_cstr(device->DeviceName), "pulse", "fix-rate", 0) ||
!(device->Flags&DEVICE_FREQUENCY_REQUEST))
flags |= PA_STREAM_FIX_RATE;
flags |= PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE;
@@ -984,7 +1021,7 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
break;
}
self->spec.rate = device->Frequency;
self->spec.channels = ChannelsFromDevFmt(device->FmtChans);
self->spec.channels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
if(pa_sample_spec_valid(&self->spec) == 0)
{
@@ -998,7 +1035,7 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
case DevFmtMono:
mapname = "mono";
break;
case DevFmtBFormat3D:
case DevFmtAmbi3D:
device->FmtChans = DevFmtStereo;
/*fall-through*/
case DevFmtStereo:
@@ -1034,9 +1071,9 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
self->attr.tlength = self->attr.minreq * maxu(device->NumUpdates, 2);
self->attr.maxlength = -1;
self->stream = ALCpulsePlayback_connectStream(al_string_get_cstr(self->device_name),
self->loop, self->context, flags,
&self->attr, &self->spec, &chanmap);
self->stream = ALCpulsePlayback_connectStream(alstr_get_cstr(self->device_name),
self->loop, self->context, flags, &self->attr, &self->spec, &chanmap
);
if(!self->stream)
{
pa_threaded_mainloop_unlock(self->loop);
@@ -1051,10 +1088,12 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
{
/* Server updated our playback rate, so modify the buffer attribs
* accordingly. */
device->NumUpdates = (ALuint)((ALdouble)device->NumUpdates / device->Frequency *
self->spec.rate + 0.5);
device->NumUpdates = (ALuint)clampd(
(ALdouble)device->NumUpdates/device->Frequency*self->spec.rate + 0.5, 2.0, 16.0
);
self->attr.minreq = device->UpdateSize * pa_frame_size(&self->spec);
self->attr.tlength = self->attr.minreq * clampu(device->NumUpdates, 2, 16);
self->attr.tlength = self->attr.minreq * device->NumUpdates;
self->attr.maxlength = -1;
self->attr.prebuf = 0;
@@ -1068,10 +1107,30 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
pa_stream_set_buffer_attr_callback(self->stream, ALCpulsePlayback_bufferAttrCallback, self);
ALCpulsePlayback_bufferAttrCallback(self->stream, self);
len = self->attr.minreq / pa_frame_size(&self->spec);
device->NumUpdates = (ALuint)((ALdouble)device->NumUpdates/len*device->UpdateSize + 0.5);
device->NumUpdates = clampu(device->NumUpdates, 2, 16);
device->UpdateSize = len;
device->NumUpdates = (ALuint)clampu64(
(self->attr.tlength + self->attr.minreq/2) / self->attr.minreq, 2, 16
);
device->UpdateSize = self->attr.minreq / pa_frame_size(&self->spec);
/* HACK: prebuf should be 0 as that's what we set it to. However on some
* systems it comes back as non-0, so we have to make sure the device will
* write enough audio to start playback. The lack of manual start control
* may have unintended consequences, but it's better than not starting at
* all.
*/
if(self->attr.prebuf != 0)
{
ALuint len = self->attr.prebuf / pa_frame_size(&self->spec);
if(len <= device->UpdateSize*device->NumUpdates)
ERR("Non-0 prebuf, %u samples (%u bytes), device has %u samples\n",
len, self->attr.prebuf, device->UpdateSize*device->NumUpdates);
else
{
ERR("Large prebuf, %u samples (%u bytes), increasing device from %u samples",
len, self->attr.prebuf, device->UpdateSize*device->NumUpdates);
device->NumUpdates = (len+device->UpdateSize-1) / device->UpdateSize;
}
}
pa_threaded_mainloop_unlock(self->loop);
return ALC_TRUE;
@@ -1113,11 +1172,14 @@ static void ALCpulsePlayback_stop(ALCpulsePlayback *self)
}
static ALint64 ALCpulsePlayback_getLatency(ALCpulsePlayback *self)
static ClockLatency ALCpulsePlayback_getClockLatency(ALCpulsePlayback *self)
{
pa_usec_t latency = 0;
ClockLatency ret;
int neg, err;
pa_threaded_mainloop_lock(self->loop);
ret.ClockTime = GetDeviceClockTime(STATIC_CAST(ALCbackend,self)->mDevice);
if((err=pa_stream_get_latency(self->stream, &latency, &neg)) != 0)
{
/* FIXME: if err = -PA_ERR_NODATA, it means we were called too soon
@@ -1126,11 +1188,14 @@ static ALint64 ALCpulsePlayback_getLatency(ALCpulsePlayback *self)
* dummy value? Either way, it shouldn't be 0. */
if(err != -PA_ERR_NODATA)
ERR("Failed to get stream latency: 0x%x\n", err);
return 0;
latency = 0;
neg = 0;
}
if(neg) latency = 0;
return (ALint64)minu64(latency, U64(0x7fffffffffffffff)/1000) * 1000;
ret.Latency = minu64(latency, U64(0xffffffffffffffff)/1000) * 1000;
pa_threaded_mainloop_unlock(self->loop);
return ret;
}
@@ -1186,7 +1251,7 @@ static ALCboolean ALCpulseCapture_start(ALCpulseCapture *self);
static void ALCpulseCapture_stop(ALCpulseCapture *self);
static ALCenum ALCpulseCapture_captureSamples(ALCpulseCapture *self, ALCvoid *buffer, ALCuint samples);
static ALCuint ALCpulseCapture_availableSamples(ALCpulseCapture *self);
static ALint64 ALCpulseCapture_getLatency(ALCpulseCapture *self);
static ClockLatency ALCpulseCapture_getClockLatency(ALCpulseCapture *self);
static void ALCpulseCapture_lock(ALCpulseCapture *self);
static void ALCpulseCapture_unlock(ALCpulseCapture *self);
DECLARE_DEFAULT_ALLOCATORS(ALCpulseCapture)
@@ -1222,35 +1287,35 @@ static void ALCpulseCapture_deviceCallback(pa_context *UNUSED(context), const pa
return;
}
#define MATCH_INFO_NAME(iter) (al_string_cmp_cstr((iter)->device_name, info->name) == 0)
#define MATCH_INFO_NAME(iter) (alstr_cmp_cstr((iter)->device_name, info->name) == 0)
VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_INFO_NAME);
if(iter != VECTOR_ITER_END(CaptureDevices)) return;
if(iter != VECTOR_END(CaptureDevices)) return;
#undef MATCH_INFO_NAME
AL_STRING_INIT(entry.name);
AL_STRING_INIT(entry.device_name);
al_string_copy_cstr(&entry.device_name, info->name);
alstr_copy_cstr(&entry.device_name, info->name);
count = 0;
while(1)
{
al_string_copy_cstr(&entry.name, info->description);
alstr_copy_cstr(&entry.name, info->description);
if(count != 0)
{
char str[64];
snprintf(str, sizeof(str), " #%d", count+1);
al_string_append_cstr(&entry.name, str);
alstr_append_cstr(&entry.name, str);
}
#define MATCH_ENTRY(i) (al_string_cmp(entry.name, (i)->name) == 0)
#define MATCH_ENTRY(i) (alstr_cmp(entry.name, (i)->name) == 0)
VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_ENTRY);
if(iter == VECTOR_ITER_END(CaptureDevices)) break;
if(iter == VECTOR_END(CaptureDevices)) break;
#undef MATCH_ENTRY
count++;
}
TRACE("Got device \"%s\", \"%s\"\n", al_string_get_cstr(entry.name), al_string_get_cstr(entry.device_name));
TRACE("Got device \"%s\", \"%s\"\n", alstr_get_cstr(entry.name), alstr_get_cstr(entry.device_name));
VECTOR_PUSH_BACK(CaptureDevices, entry);
}
@@ -1343,7 +1408,7 @@ static void ALCpulseCapture_sourceNameCallback(pa_context *UNUSED(context), cons
return;
}
al_string_copy_cstr(&device->DeviceName, info->description);
alstr_copy_cstr(&device->DeviceName, info->description);
}
@@ -1351,9 +1416,9 @@ static void ALCpulseCapture_streamMovedCallback(pa_stream *stream, void *pdata)
{
ALCpulseCapture *self = pdata;
al_string_copy_cstr(&self->device_name, pa_stream_get_device_name(stream));
alstr_copy_cstr(&self->device_name, pa_stream_get_device_name(stream));
TRACE("Stream moved to %s\n", al_string_get_cstr(self->device_name));
TRACE("Stream moved to %s\n", alstr_get_cstr(self->device_name));
}
@@ -1403,6 +1468,7 @@ static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name)
ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
const char *pulse_name = NULL;
pa_stream_flags_t flags = 0;
const char *mapname = NULL;
pa_channel_map chanmap;
ALuint samples;
@@ -1413,13 +1479,13 @@ static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name)
if(VECTOR_SIZE(CaptureDevices) == 0)
ALCpulseCapture_probeDevices();
#define MATCH_NAME(iter) (al_string_cmp_cstr((iter)->name, name) == 0)
#define MATCH_NAME(iter) (alstr_cmp_cstr((iter)->name, name) == 0)
VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_NAME);
#undef MATCH_NAME
if(iter == VECTOR_ITER_END(CaptureDevices))
if(iter == VECTOR_END(CaptureDevices))
return ALC_INVALID_VALUE;
pulse_name = al_string_get_cstr(iter->device_name);
al_string_copy(&device->DeviceName, iter->name);
pulse_name = alstr_get_cstr(iter->device_name);
alstr_copy(&device->DeviceName, iter->name);
}
if(!pulse_open(&self->loop, &self->context, ALCpulseCapture_contextStateCallback, self))
@@ -1427,9 +1493,6 @@ static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name)
pa_threaded_mainloop_lock(self->loop);
self->spec.rate = device->Frequency;
self->spec.channels = ChannelsFromDevFmt(device->FmtChans);
switch(device->FmtType)
{
case DevFmtUByte:
@@ -1452,6 +1515,44 @@ static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name)
goto fail;
}
switch(device->FmtChans)
{
case DevFmtMono:
mapname = "mono";
break;
case DevFmtStereo:
mapname = "front-left,front-right";
break;
case DevFmtQuad:
mapname = "front-left,front-right,rear-left,rear-right";
break;
case DevFmtX51:
mapname = "front-left,front-right,front-center,lfe,side-left,side-right";
break;
case DevFmtX51Rear:
mapname = "front-left,front-right,front-center,lfe,rear-left,rear-right";
break;
case DevFmtX61:
mapname = "front-left,front-right,front-center,lfe,rear-center,side-left,side-right";
break;
case DevFmtX71:
mapname = "front-left,front-right,front-center,lfe,rear-left,rear-right,side-left,side-right";
break;
case DevFmtAmbi3D:
ERR("%s capture samples not supported\n", DevFmtChannelsString(device->FmtChans));
pa_threaded_mainloop_unlock(self->loop);
goto fail;
}
if(!pa_channel_map_parse(&chanmap, mapname))
{
ERR("Failed to build channel map for %s\n", DevFmtChannelsString(device->FmtChans));
pa_threaded_mainloop_unlock(self->loop);
return ALC_FALSE;
}
self->spec.rate = device->Frequency;
self->spec.channels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
if(pa_sample_spec_valid(&self->spec) == 0)
{
ERR("Invalid sample format\n");
@@ -1481,9 +1582,9 @@ static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name)
flags |= PA_STREAM_DONT_MOVE;
TRACE("Connecting to \"%s\"\n", pulse_name ? pulse_name : "(default)");
self->stream = ALCpulseCapture_connectStream(pulse_name, self->loop, self->context,
flags, &self->attr, &self->spec,
&chanmap);
self->stream = ALCpulseCapture_connectStream(pulse_name,
self->loop, self->context, flags, &self->attr, &self->spec, &chanmap
);
if(!self->stream)
{
pa_threaded_mainloop_unlock(self->loop);
@@ -1492,11 +1593,11 @@ static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name)
pa_stream_set_moved_callback(self->stream, ALCpulseCapture_streamMovedCallback, self);
pa_stream_set_state_callback(self->stream, ALCpulseCapture_streamStateCallback, self);
al_string_copy_cstr(&self->device_name, pa_stream_get_device_name(self->stream));
if(al_string_empty(device->DeviceName))
alstr_copy_cstr(&self->device_name, pa_stream_get_device_name(self->stream));
if(alstr_empty(device->DeviceName))
{
pa_operation *o = pa_context_get_source_info_by_name(
self->context, al_string_get_cstr(self->device_name),
self->context, alstr_get_cstr(self->device_name),
ALCpulseCapture_sourceNameCallback, self
);
wait_for_operation(o, self->loop);
@@ -1521,23 +1622,26 @@ static void ALCpulseCapture_close(ALCpulseCapture *self)
self->context = NULL;
self->stream = NULL;
al_string_clear(&self->device_name);
alstr_clear(&self->device_name);
}
static ALCboolean ALCpulseCapture_start(ALCpulseCapture *self)
{
pa_operation *o;
pa_threaded_mainloop_lock(self->loop);
o = pa_stream_cork(self->stream, 0, stream_success_callback, self->loop);
wait_for_operation(o, self->loop);
pa_threaded_mainloop_unlock(self->loop);
return ALC_TRUE;
}
static void ALCpulseCapture_stop(ALCpulseCapture *self)
{
pa_operation *o;
pa_threaded_mainloop_lock(self->loop);
o = pa_stream_cork(self->stream, 1, stream_success_callback, self->loop);
wait_for_operation(o, self->loop);
pa_threaded_mainloop_unlock(self->loop);
}
static ALCenum ALCpulseCapture_captureSamples(ALCpulseCapture *self, ALCvoid *buffer, ALCuint samples)
@@ -1548,6 +1652,7 @@ static ALCenum ALCpulseCapture_captureSamples(ALCpulseCapture *self, ALCvoid *bu
/* Capture is done in fragment-sized chunks, so we loop until we get all
* that's available */
self->last_readable -= todo;
pa_threaded_mainloop_lock(self->loop);
while(todo > 0)
{
size_t rem = todo;
@@ -1587,6 +1692,7 @@ static ALCenum ALCpulseCapture_captureSamples(ALCpulseCapture *self, ALCvoid *bu
self->cap_len = 0;
}
}
pa_threaded_mainloop_unlock(self->loop);
if(todo > 0)
memset(buffer, ((device->FmtType==DevFmtUByte) ? 0x80 : 0), todo);
@@ -1600,7 +1706,9 @@ static ALCuint ALCpulseCapture_availableSamples(ALCpulseCapture *self)
if(device->Connected)
{
ssize_t got = pa_stream_readable_size(self->stream);
ssize_t got;
pa_threaded_mainloop_lock(self->loop);
got = pa_stream_readable_size(self->stream);
if(got < 0)
{
ERR("pa_stream_readable_size() failed: %s\n", pa_strerror(got));
@@ -1608,6 +1716,7 @@ static ALCuint ALCpulseCapture_availableSamples(ALCpulseCapture *self)
}
else if((size_t)got > self->cap_len)
readable += got - self->cap_len;
pa_threaded_mainloop_unlock(self->loop);
}
if(self->last_readable < readable)
@@ -1616,19 +1725,25 @@ static ALCuint ALCpulseCapture_availableSamples(ALCpulseCapture *self)
}
static ALint64 ALCpulseCapture_getLatency(ALCpulseCapture *self)
static ClockLatency ALCpulseCapture_getClockLatency(ALCpulseCapture *self)
{
pa_usec_t latency = 0;
int neg;
ClockLatency ret;
int neg, err;
if(pa_stream_get_latency(self->stream, &latency, &neg) != 0)
pa_threaded_mainloop_lock(self->loop);
ret.ClockTime = GetDeviceClockTime(STATIC_CAST(ALCbackend,self)->mDevice);
if((err=pa_stream_get_latency(self->stream, &latency, &neg)) != 0)
{
ERR("Failed to get stream latency!\n");
return 0;
ERR("Failed to get stream latency: 0x%x\n", err);
latency = 0;
neg = 0;
}
if(neg) latency = 0;
return (ALint64)minu64(latency, U64(0x7fffffffffffffff)/1000) * 1000;
ret.Latency = minu64(latency, U64(0xffffffffffffffff)/1000) * 1000;
pa_threaded_mainloop_unlock(self->loop);
return ret;
}
@@ -1732,14 +1847,14 @@ static void ALCpulseBackendFactory_probe(ALCpulseBackendFactory* UNUSED(self), e
{
case ALL_DEVICE_PROBE:
ALCpulsePlayback_probeDevices();
#define APPEND_ALL_DEVICES_LIST(e) AppendAllDevicesList(al_string_get_cstr((e)->name))
#define APPEND_ALL_DEVICES_LIST(e) AppendAllDevicesList(alstr_get_cstr((e)->name))
VECTOR_FOR_EACH(const DevMap, PlaybackDevices, APPEND_ALL_DEVICES_LIST);
#undef APPEND_ALL_DEVICES_LIST
break;
case CAPTURE_DEVICE_PROBE:
ALCpulseCapture_probeDevices();
#define APPEND_CAPTURE_DEVICE_LIST(e) AppendCaptureDeviceList(al_string_get_cstr((e)->name))
#define APPEND_CAPTURE_DEVICE_LIST(e) AppendCaptureDeviceList(alstr_get_cstr((e)->name))
VECTOR_FOR_EACH(const DevMap, CaptureDevices, APPEND_CAPTURE_DEVICE_LIST);
#undef APPEND_CAPTURE_DEVICE_LIST
break;