mirror of
https://github.com/love2d/megasource.git
synced 2026-08-17 19:24:09 +02:00
Added missing changes to the OpenAL-Soft update.
This commit is contained in:
@@ -14,8 +14,8 @@
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
* Or go to http://www.gnu.org/copyleft/lgpl.html
|
||||
*/
|
||||
|
||||
@@ -34,13 +34,6 @@
|
||||
|
||||
#if PA_API_VERSION == 12
|
||||
|
||||
#ifndef PA_CHECK_VERSION
|
||||
#define PA_CHECK_VERSION(major,minor,micro) \
|
||||
((PA_MAJOR > (major)) || \
|
||||
(PA_MAJOR == (major) && PA_MINOR > (minor)) || \
|
||||
(PA_MAJOR == (major) && PA_MINOR == (minor) && PA_MICRO >= (micro)))
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DYNLOAD
|
||||
static void *pa_handle;
|
||||
#define MAKE_FUNC(x) static __typeof(x) * p##x
|
||||
@@ -108,13 +101,9 @@ MAKE_FUNC(pa_operation_unref);
|
||||
MAKE_FUNC(pa_proplist_new);
|
||||
MAKE_FUNC(pa_proplist_free);
|
||||
MAKE_FUNC(pa_proplist_set);
|
||||
#if PA_CHECK_VERSION(0,9,15)
|
||||
MAKE_FUNC(pa_channel_map_superset);
|
||||
MAKE_FUNC(pa_stream_set_buffer_attr_callback);
|
||||
#endif
|
||||
#if PA_CHECK_VERSION(0,9,16)
|
||||
MAKE_FUNC(pa_stream_begin_write);
|
||||
#endif
|
||||
#undef MAKE_FUNC
|
||||
|
||||
#define pa_context_unref ppa_context_unref
|
||||
@@ -181,13 +170,9 @@ MAKE_FUNC(pa_stream_begin_write);
|
||||
#define pa_proplist_new ppa_proplist_new
|
||||
#define pa_proplist_free ppa_proplist_free
|
||||
#define pa_proplist_set ppa_proplist_set
|
||||
#if PA_CHECK_VERSION(0,9,15)
|
||||
#define pa_channel_map_superset ppa_channel_map_superset
|
||||
#define pa_stream_set_buffer_attr_callback ppa_stream_set_buffer_attr_callback
|
||||
#endif
|
||||
#if PA_CHECK_VERSION(0,9,16)
|
||||
#define pa_stream_begin_write ppa_stream_begin_write
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -278,18 +263,10 @@ static ALCboolean pulse_load(void)
|
||||
LOAD_FUNC(pa_proplist_new);
|
||||
LOAD_FUNC(pa_proplist_free);
|
||||
LOAD_FUNC(pa_proplist_set);
|
||||
LOAD_FUNC(pa_channel_map_superset);
|
||||
LOAD_FUNC(pa_stream_set_buffer_attr_callback);
|
||||
LOAD_FUNC(pa_stream_begin_write);
|
||||
#undef LOAD_FUNC
|
||||
#define LOAD_OPTIONAL_FUNC(x) do { \
|
||||
p##x = GetSymbol(pa_handle, #x); \
|
||||
} while(0)
|
||||
#if PA_CHECK_VERSION(0,9,15)
|
||||
LOAD_OPTIONAL_FUNC(pa_channel_map_superset);
|
||||
LOAD_OPTIONAL_FUNC(pa_stream_set_buffer_attr_callback);
|
||||
#endif
|
||||
#if PA_CHECK_VERSION(0,9,16)
|
||||
LOAD_OPTIONAL_FUNC(pa_stream_begin_write);
|
||||
#endif
|
||||
#undef LOAD_OPTIONAL_FUNC
|
||||
|
||||
if(ret == ALC_FALSE)
|
||||
{
|
||||
@@ -428,8 +405,7 @@ error:
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
static void pulse_close(pa_threaded_mainloop *loop, pa_context *context,
|
||||
pa_stream *stream)
|
||||
static void pulse_close(pa_threaded_mainloop *loop, pa_context *context, pa_stream *stream)
|
||||
{
|
||||
pa_threaded_mainloop_lock(loop);
|
||||
|
||||
@@ -438,10 +414,7 @@ static void pulse_close(pa_threaded_mainloop *loop, pa_context *context,
|
||||
pa_stream_set_state_callback(stream, NULL, NULL);
|
||||
pa_stream_set_moved_callback(stream, NULL, NULL);
|
||||
pa_stream_set_write_callback(stream, NULL, NULL);
|
||||
#if PA_CHECK_VERSION(0,9,15)
|
||||
if(pa_stream_set_buffer_attr_callback)
|
||||
pa_stream_set_buffer_attr_callback(stream, NULL, NULL);
|
||||
#endif
|
||||
pa_stream_set_buffer_attr_callback(stream, NULL, NULL);
|
||||
pa_stream_disconnect(stream);
|
||||
pa_stream_unref(stream);
|
||||
}
|
||||
@@ -544,6 +517,7 @@ static void ALCpulsePlayback_deviceCallback(pa_context *UNUSED(context), const p
|
||||
pa_threaded_mainloop *loop = pdata;
|
||||
const DevMap *iter;
|
||||
DevMap entry;
|
||||
int count;
|
||||
|
||||
if(eol)
|
||||
{
|
||||
@@ -553,18 +527,34 @@ static void ALCpulsePlayback_deviceCallback(pa_context *UNUSED(context), const p
|
||||
|
||||
#define MATCH_INFO_NAME(iter) (al_string_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;
|
||||
#undef MATCH_INFO_NAME
|
||||
if(iter != VECTOR_ITER_END(PlaybackDevices))
|
||||
return;
|
||||
|
||||
TRACE("Got device \"%s\", \"%s\"\n", info->description, info->name);
|
||||
|
||||
AL_STRING_INIT(entry.name);
|
||||
AL_STRING_INIT(entry.device_name);
|
||||
|
||||
al_string_copy_cstr(&entry.name, info->description);
|
||||
al_string_copy_cstr(&entry.device_name, info->name);
|
||||
|
||||
count = 0;
|
||||
while(1)
|
||||
{
|
||||
al_string_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);
|
||||
}
|
||||
|
||||
#define MATCH_ENTRY(i) (al_string_cmp(entry.name, (i)->name) == 0)
|
||||
VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_ENTRY);
|
||||
if(iter == VECTOR_ITER_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));
|
||||
|
||||
VECTOR_PUSH_BACK(PlaybackDevices, entry);
|
||||
}
|
||||
|
||||
@@ -660,27 +650,44 @@ static void ALCpulsePlayback_streamWriteCallback(pa_stream* UNUSED(p), size_t UN
|
||||
|
||||
static void ALCpulsePlayback_sinkInfoCallback(pa_context *UNUSED(context), const pa_sink_info *info, int eol, void *pdata)
|
||||
{
|
||||
static const struct {
|
||||
enum DevFmtChannels chans;
|
||||
pa_channel_map map;
|
||||
} chanmaps[] = {
|
||||
{ DevFmtX71, { 8, {
|
||||
PA_CHANNEL_POSITION_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_RIGHT,
|
||||
PA_CHANNEL_POSITION_FRONT_CENTER, PA_CHANNEL_POSITION_LFE,
|
||||
PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT,
|
||||
PA_CHANNEL_POSITION_SIDE_LEFT, PA_CHANNEL_POSITION_SIDE_RIGHT
|
||||
} } },
|
||||
{ DevFmtX61, { 7, {
|
||||
PA_CHANNEL_POSITION_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_RIGHT,
|
||||
PA_CHANNEL_POSITION_FRONT_CENTER, PA_CHANNEL_POSITION_LFE,
|
||||
PA_CHANNEL_POSITION_REAR_CENTER,
|
||||
PA_CHANNEL_POSITION_SIDE_LEFT, PA_CHANNEL_POSITION_SIDE_RIGHT
|
||||
} } },
|
||||
{ DevFmtX51, { 6, {
|
||||
PA_CHANNEL_POSITION_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_RIGHT,
|
||||
PA_CHANNEL_POSITION_FRONT_CENTER, PA_CHANNEL_POSITION_LFE,
|
||||
PA_CHANNEL_POSITION_SIDE_LEFT, PA_CHANNEL_POSITION_SIDE_RIGHT
|
||||
} } },
|
||||
{ DevFmtX51Rear, { 6, {
|
||||
PA_CHANNEL_POSITION_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_RIGHT,
|
||||
PA_CHANNEL_POSITION_FRONT_CENTER, PA_CHANNEL_POSITION_LFE,
|
||||
PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT
|
||||
} } },
|
||||
{ DevFmtQuad, { 4, {
|
||||
PA_CHANNEL_POSITION_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_RIGHT,
|
||||
PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT
|
||||
} } },
|
||||
{ DevFmtStereo, { 2, {
|
||||
PA_CHANNEL_POSITION_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_RIGHT
|
||||
} } },
|
||||
{ DevFmtMono, { 1, {PA_CHANNEL_POSITION_MONO} } }
|
||||
};
|
||||
ALCpulsePlayback *self = pdata;
|
||||
ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
|
||||
char chanmap_str[256] = "";
|
||||
const struct {
|
||||
const char *str;
|
||||
enum DevFmtChannels chans;
|
||||
} chanmaps[] = {
|
||||
{ "front-left,front-right,front-center,lfe,rear-left,rear-right,side-left,side-right",
|
||||
DevFmtX71 },
|
||||
{ "front-left,front-right,front-center,lfe,rear-center,side-left,side-right",
|
||||
DevFmtX61 },
|
||||
{ "front-left,front-right,front-center,lfe,rear-left,rear-right",
|
||||
DevFmtX51 },
|
||||
{ "front-left,front-right,front-center,lfe,side-left,side-right",
|
||||
DevFmtX51Side },
|
||||
{ "front-left,front-right,rear-left,rear-right", DevFmtQuad },
|
||||
{ "front-left,front-right", DevFmtStereo },
|
||||
{ "mono", DevFmtMono },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
if(eol)
|
||||
{
|
||||
@@ -688,26 +695,27 @@ static void ALCpulsePlayback_sinkInfoCallback(pa_context *UNUSED(context), const
|
||||
return;
|
||||
}
|
||||
|
||||
for(i = 0;chanmaps[i].str;i++)
|
||||
for(i = 0;i < COUNTOF(chanmaps);i++)
|
||||
{
|
||||
pa_channel_map map;
|
||||
if(!pa_channel_map_parse(&map, chanmaps[i].str))
|
||||
continue;
|
||||
|
||||
if(pa_channel_map_equal(&info->channel_map, &map)
|
||||
#if PA_CHECK_VERSION(0,9,15)
|
||||
|| (pa_channel_map_superset &&
|
||||
pa_channel_map_superset(&info->channel_map, &map))
|
||||
#endif
|
||||
)
|
||||
if(pa_channel_map_superset(&info->channel_map, &chanmaps[i].map))
|
||||
{
|
||||
device->FmtChans = chanmaps[i].chans;
|
||||
return;
|
||||
if(!(device->Flags&DEVICE_CHANNELS_REQUEST))
|
||||
device->FmtChans = chanmaps[i].chans;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(i == COUNTOF(chanmaps))
|
||||
{
|
||||
char chanmap_str[PA_CHANNEL_MAP_SNPRINT_MAX] = "";
|
||||
pa_channel_map_snprint(chanmap_str, sizeof(chanmap_str), &info->channel_map);
|
||||
WARN("Failed to find format for channel map:\n %s\n", chanmap_str);
|
||||
}
|
||||
|
||||
pa_channel_map_snprint(chanmap_str, sizeof(chanmap_str), &info->channel_map);
|
||||
ERR("Failed to find format for channel map:\n %s\n", chanmap_str);
|
||||
if(info->active_port)
|
||||
TRACE("Active port: %s (%s)\n", info->active_port->name, info->active_port->description);
|
||||
device->IsHeadphones = (info->active_port &&
|
||||
strcmp(info->active_port->name, "analog-output-headphones") == 0 &&
|
||||
device->FmtChans == DevFmtStereo);
|
||||
}
|
||||
|
||||
static void ALCpulsePlayback_sinkNameCallback(pa_context *UNUSED(context), const pa_sink_info *info, int eol, void *pdata)
|
||||
@@ -818,10 +826,7 @@ static int ALCpulsePlayback_mixerProc(void *ptr)
|
||||
void *buf;
|
||||
pa_free_cb_t free_func = NULL;
|
||||
|
||||
#if PA_CHECK_VERSION(0,9,16)
|
||||
if(!pa_stream_begin_write ||
|
||||
pa_stream_begin_write(self->stream, &buf, &newlen) < 0)
|
||||
#endif
|
||||
if(pa_stream_begin_write(self->stream, &buf, &newlen) < 0)
|
||||
{
|
||||
buf = pa_xmalloc(newlen);
|
||||
free_func = pa_xfree;
|
||||
@@ -841,10 +846,10 @@ static int ALCpulsePlayback_mixerProc(void *ptr)
|
||||
|
||||
static ALCenum ALCpulsePlayback_open(ALCpulsePlayback *self, const ALCchar *name)
|
||||
{
|
||||
const_al_string dev_name = AL_STRING_INIT_STATIC();
|
||||
const char *pulse_name = NULL;
|
||||
pa_stream_flags_t flags;
|
||||
pa_sample_spec spec;
|
||||
pa_operation *o;
|
||||
|
||||
if(name)
|
||||
{
|
||||
@@ -859,6 +864,7 @@ static ALCenum ALCpulsePlayback_open(ALCpulsePlayback *self, const ALCchar *name
|
||||
if(iter == VECTOR_ITER_END(PlaybackDevices))
|
||||
return ALC_INVALID_VALUE;
|
||||
pulse_name = al_string_get_cstr(iter->device_name);
|
||||
dev_name = iter->name;
|
||||
}
|
||||
|
||||
if(!pulse_open(&self->loop, &self->context, ALCpulsePlayback_contextStateCallback, self))
|
||||
@@ -868,7 +874,7 @@ static ALCenum ALCpulsePlayback_open(ALCpulsePlayback *self, const ALCchar *name
|
||||
|
||||
flags = PA_STREAM_FIX_FORMAT | PA_STREAM_FIX_RATE |
|
||||
PA_STREAM_FIX_CHANNELS;
|
||||
if(!GetConfigValueBool("pulse", "allow-moves", 0))
|
||||
if(!GetConfigValueBool(NULL, "pulse", "allow-moves", 0))
|
||||
flags |= PA_STREAM_DONT_MOVE;
|
||||
|
||||
spec.format = PA_SAMPLE_S16NE;
|
||||
@@ -889,10 +895,19 @@ 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));
|
||||
o = pa_context_get_sink_info_by_name(self->context,
|
||||
al_string_get_cstr(self->device_name),
|
||||
ALCpulsePlayback_sinkNameCallback, self);
|
||||
wait_for_operation(o, self->loop);
|
||||
if(al_string_empty(dev_name))
|
||||
{
|
||||
pa_operation *o = pa_context_get_sink_info_by_name(
|
||||
self->context, al_string_get_cstr(self->device_name),
|
||||
ALCpulsePlayback_sinkNameCallback, self
|
||||
);
|
||||
wait_for_operation(o, self->loop);
|
||||
}
|
||||
else
|
||||
{
|
||||
ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
|
||||
al_string_copy(&device->DeviceName, dev_name);
|
||||
}
|
||||
|
||||
pa_threaded_mainloop_unlock(self->loop);
|
||||
|
||||
@@ -915,37 +930,33 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
|
||||
pa_stream_flags_t flags = 0;
|
||||
const char *mapname = NULL;
|
||||
pa_channel_map chanmap;
|
||||
pa_operation *o;
|
||||
ALuint len;
|
||||
|
||||
pa_threaded_mainloop_lock(self->loop);
|
||||
|
||||
if(self->stream)
|
||||
{
|
||||
pa_stream_set_state_callback(self->stream, NULL, NULL);
|
||||
pa_stream_set_moved_callback(self->stream, NULL, NULL);
|
||||
#if PA_CHECK_VERSION(0,9,15)
|
||||
if(pa_stream_set_buffer_attr_callback)
|
||||
pa_stream_set_buffer_attr_callback(self->stream, NULL, NULL);
|
||||
#endif
|
||||
pa_stream_set_write_callback(self->stream, NULL, NULL);
|
||||
pa_stream_set_buffer_attr_callback(self->stream, NULL, NULL);
|
||||
pa_stream_disconnect(self->stream);
|
||||
pa_stream_unref(self->stream);
|
||||
self->stream = NULL;
|
||||
}
|
||||
|
||||
if(!(device->Flags&DEVICE_CHANNELS_REQUEST))
|
||||
{
|
||||
pa_operation *o;
|
||||
o = pa_context_get_sink_info_by_name(self->context,
|
||||
al_string_get_cstr(self->device_name),
|
||||
ALCpulsePlayback_sinkInfoCallback, self);
|
||||
wait_for_operation(o, self->loop);
|
||||
}
|
||||
if(!(device->Flags&DEVICE_FREQUENCY_REQUEST))
|
||||
flags |= PA_STREAM_FIX_RATE;
|
||||
o = pa_context_get_sink_info_by_name(self->context, al_string_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) ||
|
||||
!(device->Flags&DEVICE_FREQUENCY_REQUEST))
|
||||
flags |= PA_STREAM_FIX_RATE;
|
||||
flags |= PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE;
|
||||
flags |= PA_STREAM_ADJUST_LATENCY;
|
||||
flags |= PA_STREAM_START_CORKED;
|
||||
if(!GetConfigValueBool("pulse", "allow-moves", 0))
|
||||
if(!GetConfigValueBool(NULL, "pulse", "allow-moves", 0))
|
||||
flags |= PA_STREAM_DONT_MOVE;
|
||||
|
||||
switch(device->FmtType)
|
||||
@@ -987,6 +998,9 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
|
||||
case DevFmtMono:
|
||||
mapname = "mono";
|
||||
break;
|
||||
case DevFmtBFormat3D:
|
||||
device->FmtChans = DevFmtStereo;
|
||||
/*fall-through*/
|
||||
case DevFmtStereo:
|
||||
mapname = "front-left,front-right";
|
||||
break;
|
||||
@@ -994,11 +1008,11 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
|
||||
mapname = "front-left,front-right,rear-left,rear-right";
|
||||
break;
|
||||
case DevFmtX51:
|
||||
mapname = "front-left,front-right,front-center,lfe,rear-left,rear-right";
|
||||
break;
|
||||
case DevFmtX51Side:
|
||||
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;
|
||||
@@ -1035,8 +1049,6 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
|
||||
self->spec = *(pa_stream_get_sample_spec(self->stream));
|
||||
if(device->Frequency != self->spec.rate)
|
||||
{
|
||||
pa_operation *o;
|
||||
|
||||
/* Server updated our playback rate, so modify the buffer attribs
|
||||
* accordingly. */
|
||||
device->NumUpdates = (ALuint)((ALdouble)device->NumUpdates / device->Frequency *
|
||||
@@ -1053,15 +1065,10 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
|
||||
device->Frequency = self->spec.rate;
|
||||
}
|
||||
|
||||
#if PA_CHECK_VERSION(0,9,15)
|
||||
if(pa_stream_set_buffer_attr_callback)
|
||||
pa_stream_set_buffer_attr_callback(self->stream, ALCpulsePlayback_bufferAttrCallback, self);
|
||||
#endif
|
||||
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);
|
||||
if((CPUCapFlags&CPU_CAP_SSE))
|
||||
len = (len+3)&~3;
|
||||
device->NumUpdates = (ALuint)((ALdouble)device->NumUpdates/len*device->UpdateSize + 0.5);
|
||||
device->NumUpdates = clampu(device->NumUpdates, 2, 16);
|
||||
device->UpdateSize = len;
|
||||
@@ -1083,10 +1090,18 @@ static void ALCpulsePlayback_stop(ALCpulsePlayback *self)
|
||||
pa_operation *o;
|
||||
int res;
|
||||
|
||||
if(!self->stream)
|
||||
if(!self->stream || self->killNow)
|
||||
return;
|
||||
|
||||
self->killNow = AL_TRUE;
|
||||
/* Signal the main loop in case PulseAudio isn't sending us audio requests
|
||||
* (e.g. if the device is suspended). We need to lock the mainloop in case
|
||||
* the mixer is between checking the killNow flag but before waiting for
|
||||
* the signal.
|
||||
*/
|
||||
pa_threaded_mainloop_lock(self->loop);
|
||||
pa_threaded_mainloop_unlock(self->loop);
|
||||
pa_threaded_mainloop_signal(self->loop, 0);
|
||||
althrd_join(self->thread, &res);
|
||||
|
||||
pa_threaded_mainloop_lock(self->loop);
|
||||
@@ -1199,6 +1214,7 @@ static void ALCpulseCapture_deviceCallback(pa_context *UNUSED(context), const pa
|
||||
pa_threaded_mainloop *loop = pdata;
|
||||
const DevMap *iter;
|
||||
DevMap entry;
|
||||
int count;
|
||||
|
||||
if(eol)
|
||||
{
|
||||
@@ -1208,18 +1224,34 @@ static void ALCpulseCapture_deviceCallback(pa_context *UNUSED(context), const pa
|
||||
|
||||
#define MATCH_INFO_NAME(iter) (al_string_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;
|
||||
#undef MATCH_INFO_NAME
|
||||
if(iter != VECTOR_ITER_END(CaptureDevices))
|
||||
return;
|
||||
|
||||
TRACE("Got device \"%s\", \"%s\"\n", info->description, info->name);
|
||||
|
||||
AL_STRING_INIT(entry.name);
|
||||
AL_STRING_INIT(entry.device_name);
|
||||
|
||||
al_string_copy_cstr(&entry.name, info->description);
|
||||
al_string_copy_cstr(&entry.device_name, info->name);
|
||||
|
||||
count = 0;
|
||||
while(1)
|
||||
{
|
||||
al_string_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);
|
||||
}
|
||||
|
||||
#define MATCH_ENTRY(i) (al_string_cmp(entry.name, (i)->name) == 0)
|
||||
VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_ENTRY);
|
||||
if(iter == VECTOR_ITER_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));
|
||||
|
||||
VECTOR_PUSH_BACK(CaptureDevices, entry);
|
||||
}
|
||||
|
||||
@@ -1372,7 +1404,6 @@ static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name)
|
||||
const char *pulse_name = NULL;
|
||||
pa_stream_flags_t flags = 0;
|
||||
pa_channel_map chanmap;
|
||||
pa_operation *o;
|
||||
ALuint samples;
|
||||
|
||||
if(name)
|
||||
@@ -1388,6 +1419,7 @@ static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name)
|
||||
if(iter == VECTOR_ITER_END(CaptureDevices))
|
||||
return ALC_INVALID_VALUE;
|
||||
pulse_name = al_string_get_cstr(iter->device_name);
|
||||
al_string_copy(&device->DeviceName, iter->name);
|
||||
}
|
||||
|
||||
if(!pulse_open(&self->loop, &self->context, ALCpulseCapture_contextStateCallback, self))
|
||||
@@ -1445,7 +1477,7 @@ static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name)
|
||||
pa_frame_size(&self->spec);
|
||||
|
||||
flags |= PA_STREAM_START_CORKED|PA_STREAM_ADJUST_LATENCY;
|
||||
if(!GetConfigValueBool("pulse", "allow-moves", 0))
|
||||
if(!GetConfigValueBool(NULL, "pulse", "allow-moves", 0))
|
||||
flags |= PA_STREAM_DONT_MOVE;
|
||||
|
||||
TRACE("Connecting to \"%s\"\n", pulse_name ? pulse_name : "(default)");
|
||||
@@ -1461,10 +1493,14 @@ static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name)
|
||||
pa_stream_set_state_callback(self->stream, ALCpulseCapture_streamStateCallback, self);
|
||||
|
||||
al_string_copy_cstr(&self->device_name, pa_stream_get_device_name(self->stream));
|
||||
o = pa_context_get_source_info_by_name(self->context,
|
||||
al_string_get_cstr(self->device_name),
|
||||
ALCpulseCapture_sourceNameCallback, self);
|
||||
wait_for_operation(o, self->loop);
|
||||
if(al_string_empty(device->DeviceName))
|
||||
{
|
||||
pa_operation *o = pa_context_get_source_info_by_name(
|
||||
self->context, al_string_get_cstr(self->device_name),
|
||||
ALCpulseCapture_sourceNameCallback, self
|
||||
);
|
||||
wait_for_operation(o, self->loop);
|
||||
}
|
||||
|
||||
pa_threaded_mainloop_unlock(self->loop);
|
||||
return ALC_NO_ERROR;
|
||||
@@ -1607,11 +1643,6 @@ static void ALCpulseCapture_unlock(ALCpulseCapture *self)
|
||||
}
|
||||
|
||||
|
||||
static inline void AppendAllDevicesList2(const DevMap *entry)
|
||||
{ AppendAllDevicesList(al_string_get_cstr(entry->name)); }
|
||||
static inline void AppendCaptureDeviceList2(const DevMap *entry)
|
||||
{ AppendCaptureDeviceList(al_string_get_cstr(entry->name)); }
|
||||
|
||||
typedef struct ALCpulseBackendFactory {
|
||||
DERIVE_FROM_TYPE(ALCbackendFactory);
|
||||
} ALCpulseBackendFactory;
|
||||
@@ -1638,7 +1669,7 @@ static ALCboolean ALCpulseBackendFactory_init(ALCpulseBackendFactory* UNUSED(sel
|
||||
pa_threaded_mainloop *loop;
|
||||
|
||||
pulse_ctx_flags = 0;
|
||||
if(!GetConfigValueBool("pulse", "spawn-server", 1))
|
||||
if(!GetConfigValueBool(NULL, "pulse", "spawn-server", 1))
|
||||
pulse_ctx_flags |= PA_CONTEXT_NOAUTOSPAWN;
|
||||
|
||||
if((loop=pa_threaded_mainloop_new()) &&
|
||||
@@ -1701,12 +1732,16 @@ static void ALCpulseBackendFactory_probe(ALCpulseBackendFactory* UNUSED(self), e
|
||||
{
|
||||
case ALL_DEVICE_PROBE:
|
||||
ALCpulsePlayback_probeDevices();
|
||||
VECTOR_FOR_EACH(const DevMap, PlaybackDevices, AppendAllDevicesList2);
|
||||
#define APPEND_ALL_DEVICES_LIST(e) AppendAllDevicesList(al_string_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();
|
||||
VECTOR_FOR_EACH(const DevMap, CaptureDevices, AppendCaptureDeviceList2);
|
||||
#define APPEND_CAPTURE_DEVICE_LIST(e) AppendCaptureDeviceList(al_string_get_cstr((e)->name))
|
||||
VECTOR_FOR_EACH(const DevMap, CaptureDevices, APPEND_CAPTURE_DEVICE_LIST);
|
||||
#undef APPEND_CAPTURE_DEVICE_LIST
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1716,25 +1751,15 @@ static ALCbackend* ALCpulseBackendFactory_createBackend(ALCpulseBackendFactory*
|
||||
if(type == ALCbackend_Playback)
|
||||
{
|
||||
ALCpulsePlayback *backend;
|
||||
|
||||
backend = ALCpulsePlayback_New(sizeof(*backend));
|
||||
NEW_OBJ(backend, ALCpulsePlayback)(device);
|
||||
if(!backend) return NULL;
|
||||
memset(backend, 0, sizeof(*backend));
|
||||
|
||||
ALCpulsePlayback_Construct(backend, device);
|
||||
|
||||
return STATIC_CAST(ALCbackend, backend);
|
||||
}
|
||||
if(type == ALCbackend_Capture)
|
||||
{
|
||||
ALCpulseCapture *backend;
|
||||
|
||||
backend = ALCpulseCapture_New(sizeof(*backend));
|
||||
NEW_OBJ(backend, ALCpulseCapture)(device);
|
||||
if(!backend) return NULL;
|
||||
memset(backend, 0, sizeof(*backend));
|
||||
|
||||
ALCpulseCapture_Construct(backend, device);
|
||||
|
||||
return STATIC_CAST(ALCbackend, backend);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user