1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-13 03:33:03 +01:00

What if, like, photosynthesis is a lie?!

This commit is contained in:
mannol 2014-09-28 00:13:45 +02:00
parent a9e5723ca4
commit 784883f773

View File

@ -61,7 +61,7 @@ typedef struct Device {
int32_t call_idx; /* ToxAv call index */
uint32_t source, buffers[OPENAL_BUFS]; /* Playback source/buffers */
size_t ref_count;
size_t *ref_count;
int32_t selection;
bool enable_VAD;
bool muted;
@ -227,21 +227,29 @@ DeviceError open_device(DeviceType type, int32_t selection, uint32_t* device_idx
device->frame_duration = frame_duration;
device->sound_mode = channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
if (pthread_mutex_init(device->mutex, NULL) != 0) {
free(device);
unlock;
return de_InternalError;
}
for (i = 0; i < *device_idx; i ++) { /* Check if any previous has the same selection */
if ( running[type][i]->selection == selection ) {
device->dhndl = running[type][i]->dhndl;
if (type == output) {
device->ctx = running[type][i]->ctx;
memcpy(device->buffers, running[type][i]->buffers, sizeof(running[type][i]->buffers));
device->source = running[type][i]->source;
}
device->ref_count++;
if (pthread_mutex_init(device->mutex, NULL) != 0) {
unlock;
return de_InternalError;
}
if (running[type][i]->ref_count)
device->ref_count = running[type][i]->ref_count;
else
device->ref_count = running[type][i]->ref_count = calloc(1, sizeof(size_t));
*device->ref_count++;
unlock;
return de_None;
}
@ -293,11 +301,6 @@ DeviceError open_device(DeviceType type, int32_t selection, uint32_t* device_idx
thread_paused = false;
}
if (pthread_mutex_init(device->mutex, NULL) != 0) {
unlock;
return de_InternalError;
}
unlock;
return de_None;
}
@ -308,6 +311,7 @@ DeviceError close_device(DeviceType type, uint32_t device_idx)
lock;
Device* device = running[type][device_idx];
DeviceError rc = de_None;
if (!device) {
unlock;
@ -316,10 +320,10 @@ DeviceError close_device(DeviceType type, uint32_t device_idx)
running[type][device_idx] = NULL;
if ( !(device->ref_count--) ) {
unlock;
/* Once copied device->ref_count will be set to 1; not 2
*/
if ( !(device->ref_count) || *(device->ref_count) ) {
DeviceError rc = de_None;
if (type == input) {
if ( !alcCaptureCloseDevice(device->dhndl) ) rc = de_AlError;
@ -334,14 +338,14 @@ DeviceError close_device(DeviceType type, uint32_t device_idx)
alcMakeContextCurrent(NULL);
if ( device->ctx ) alcDestroyContext(device->ctx);
}
free(device);
return rc;
}
else if (device->ref_count) *(device->ref_count)--;
/* Just pop the reference */
free(device);
unlock;
return de_None;
return rc;
}
DeviceError register_device_callback( int32_t call_idx, uint32_t device_idx, DataHandleCallback callback, void* data, bool enable_VAD)