mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 02:13:01 +01:00
What if, like, photosynthesis is a lie?!
This commit is contained in:
parent
a9e5723ca4
commit
784883f773
46
src/device.c
46
src/device.c
@ -61,7 +61,7 @@ typedef struct Device {
|
|||||||
int32_t call_idx; /* ToxAv call index */
|
int32_t call_idx; /* ToxAv call index */
|
||||||
|
|
||||||
uint32_t source, buffers[OPENAL_BUFS]; /* Playback source/buffers */
|
uint32_t source, buffers[OPENAL_BUFS]; /* Playback source/buffers */
|
||||||
size_t ref_count;
|
size_t *ref_count;
|
||||||
int32_t selection;
|
int32_t selection;
|
||||||
bool enable_VAD;
|
bool enable_VAD;
|
||||||
bool muted;
|
bool muted;
|
||||||
@ -227,21 +227,29 @@ DeviceError open_device(DeviceType type, int32_t selection, uint32_t* device_idx
|
|||||||
device->frame_duration = frame_duration;
|
device->frame_duration = frame_duration;
|
||||||
device->sound_mode = channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
|
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 */
|
for (i = 0; i < *device_idx; i ++) { /* Check if any previous has the same selection */
|
||||||
if ( running[type][i]->selection == selection ) {
|
if ( running[type][i]->selection == selection ) {
|
||||||
device->dhndl = running[type][i]->dhndl;
|
device->dhndl = running[type][i]->dhndl;
|
||||||
|
|
||||||
if (type == output) {
|
if (type == output) {
|
||||||
device->ctx = running[type][i]->ctx;
|
device->ctx = running[type][i]->ctx;
|
||||||
memcpy(device->buffers, running[type][i]->buffers, sizeof(running[type][i]->buffers));
|
memcpy(device->buffers, running[type][i]->buffers, sizeof(running[type][i]->buffers));
|
||||||
device->source = running[type][i]->source;
|
device->source = running[type][i]->source;
|
||||||
}
|
}
|
||||||
device->ref_count++;
|
|
||||||
|
if (running[type][i]->ref_count)
|
||||||
if (pthread_mutex_init(device->mutex, NULL) != 0) {
|
device->ref_count = running[type][i]->ref_count;
|
||||||
unlock;
|
else
|
||||||
return de_InternalError;
|
device->ref_count = running[type][i]->ref_count = calloc(1, sizeof(size_t));
|
||||||
}
|
|
||||||
|
*device->ref_count++;
|
||||||
|
|
||||||
unlock;
|
unlock;
|
||||||
return de_None;
|
return de_None;
|
||||||
}
|
}
|
||||||
@ -293,11 +301,6 @@ DeviceError open_device(DeviceType type, int32_t selection, uint32_t* device_idx
|
|||||||
thread_paused = false;
|
thread_paused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pthread_mutex_init(device->mutex, NULL) != 0) {
|
|
||||||
unlock;
|
|
||||||
return de_InternalError;
|
|
||||||
}
|
|
||||||
|
|
||||||
unlock;
|
unlock;
|
||||||
return de_None;
|
return de_None;
|
||||||
}
|
}
|
||||||
@ -308,6 +311,7 @@ DeviceError close_device(DeviceType type, uint32_t device_idx)
|
|||||||
|
|
||||||
lock;
|
lock;
|
||||||
Device* device = running[type][device_idx];
|
Device* device = running[type][device_idx];
|
||||||
|
DeviceError rc = de_None;
|
||||||
|
|
||||||
if (!device) {
|
if (!device) {
|
||||||
unlock;
|
unlock;
|
||||||
@ -316,10 +320,10 @@ DeviceError close_device(DeviceType type, uint32_t device_idx)
|
|||||||
|
|
||||||
running[type][device_idx] = NULL;
|
running[type][device_idx] = NULL;
|
||||||
|
|
||||||
if ( !(device->ref_count--) ) {
|
/* Once copied device->ref_count will be set to 1; not 2
|
||||||
unlock;
|
*/
|
||||||
|
if ( !(device->ref_count) || *(device->ref_count) ) {
|
||||||
|
|
||||||
DeviceError rc = de_None;
|
|
||||||
|
|
||||||
if (type == input) {
|
if (type == input) {
|
||||||
if ( !alcCaptureCloseDevice(device->dhndl) ) rc = de_AlError;
|
if ( !alcCaptureCloseDevice(device->dhndl) ) rc = de_AlError;
|
||||||
@ -334,14 +338,14 @@ DeviceError close_device(DeviceType type, uint32_t device_idx)
|
|||||||
alcMakeContextCurrent(NULL);
|
alcMakeContextCurrent(NULL);
|
||||||
if ( device->ctx ) alcDestroyContext(device->ctx);
|
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;
|
unlock;
|
||||||
|
return rc;
|
||||||
return de_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceError register_device_callback( int32_t call_idx, uint32_t device_idx, DataHandleCallback callback, void* data, bool enable_VAD)
|
DeviceError register_device_callback( int32_t call_idx, uint32_t device_idx, DataHandleCallback callback, void* data, bool enable_VAD)
|
||||||
|
Loading…
Reference in New Issue
Block a user