mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 02:53:02 +01:00
fix CPU usage issue regarding audio drivers, courtesy of mannol
This commit is contained in:
parent
2918ca45a2
commit
e574af7d68
@ -314,8 +314,9 @@ DeviceError close_device(DeviceType type, uint32_t device_idx)
|
|||||||
return de_DeviceNotActive;
|
return de_DeviceNotActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
running[type][device_idx] = NULL;
|
||||||
|
|
||||||
if ( !(device->ref_count--) ) {
|
if ( !(device->ref_count--) ) {
|
||||||
running[type][device_idx] = NULL;
|
|
||||||
unlock;
|
unlock;
|
||||||
|
|
||||||
DeviceError rc = de_None;
|
DeviceError rc = de_None;
|
||||||
@ -471,4 +472,4 @@ void* get_device_callback_data(uint32_t device_idx)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return running[input][device_idx]->cb_data;
|
return running[input][device_idx]->cb_data;
|
||||||
}
|
}
|
||||||
|
50
src/notify.c
50
src/notify.c
@ -166,6 +166,32 @@ bool is_playing(int source)
|
|||||||
return ready == AL_PLAYING;
|
return ready == AL_PLAYING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TODO maybe find better way to do this */
|
||||||
|
/* cooldown is in seconds */
|
||||||
|
#define DEVICE_COOLDOWN 5 /* TODO perhaps load this from config? */
|
||||||
|
static bool device_opened = false;
|
||||||
|
time_t last_opened_update = 0;
|
||||||
|
|
||||||
|
bool m_open_device()
|
||||||
|
{
|
||||||
|
last_opened_update = time(NULL);
|
||||||
|
|
||||||
|
if (device_opened) return true;
|
||||||
|
|
||||||
|
/* Blah error check */
|
||||||
|
open_primary_device(output, &Control.device_idx, 48000, 20, 1);
|
||||||
|
return (device_opened = true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool m_close_device()
|
||||||
|
{
|
||||||
|
if (!device_opened) return true;
|
||||||
|
|
||||||
|
close_device(output, Control.device_idx);
|
||||||
|
|
||||||
|
return !(device_opened = false);
|
||||||
|
}
|
||||||
|
|
||||||
/* Terminate all sounds but wait for them to finish first */
|
/* Terminate all sounds but wait for them to finish first */
|
||||||
void graceful_clear()
|
void graceful_clear()
|
||||||
{
|
{
|
||||||
@ -195,6 +221,7 @@ void graceful_clear()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (i == ACTIVE_NOTIFS_MAX) {
|
if (i == ACTIVE_NOTIFS_MAX) {
|
||||||
|
m_close_device(); /* In case it's opened */
|
||||||
control_unlock();
|
control_unlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -207,9 +234,17 @@ void* do_playing(void* _p)
|
|||||||
{
|
{
|
||||||
(void)_p;
|
(void)_p;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
bool has_looping = false;
|
||||||
|
|
||||||
while(Control.poll_active) {
|
while(Control.poll_active) {
|
||||||
control_lock();
|
control_lock();
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < ACTIVE_NOTIFS_MAX; i ++) {
|
for (i = 0; i < ACTIVE_NOTIFS_MAX; i ++) {
|
||||||
|
|
||||||
|
if (actives[i].looping) has_looping = true;
|
||||||
|
|
||||||
if (actives[i].active && !actives[i].looping
|
if (actives[i].active && !actives[i].looping
|
||||||
#ifdef BOX_NOTIFY
|
#ifdef BOX_NOTIFY
|
||||||
&& !actives[i].box
|
&& !actives[i].box
|
||||||
@ -242,6 +277,14 @@ void* do_playing(void* _p)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* device is opened and no activity in under DEVICE_COOLDOWN time, close device*/
|
||||||
|
if (device_opened && !has_looping &&
|
||||||
|
(time(NULL) - last_opened_update) > DEVICE_COOLDOWN) {
|
||||||
|
m_close_device();
|
||||||
|
}
|
||||||
|
has_looping = false;
|
||||||
|
|
||||||
control_unlock();
|
control_unlock();
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
}
|
}
|
||||||
@ -323,8 +366,6 @@ int init_notify(int login_cooldown, int notification_timeout)
|
|||||||
{
|
{
|
||||||
#ifdef SOUND_NOTIFY
|
#ifdef SOUND_NOTIFY
|
||||||
alutInitWithoutContext(NULL, NULL);
|
alutInitWithoutContext(NULL, NULL);
|
||||||
if (open_primary_device(output, &Control.device_idx, 48000, 20, 1) != de_None)
|
|
||||||
return -1;
|
|
||||||
#endif /* SOUND_NOTIFY */
|
#endif /* SOUND_NOTIFY */
|
||||||
|
|
||||||
#if defined(SOUND_NOTIFY) || defined(BOX_NOTIFY)
|
#if defined(SOUND_NOTIFY) || defined(BOX_NOTIFY)
|
||||||
@ -366,7 +407,6 @@ void terminate_notify()
|
|||||||
#ifdef SOUND_NOTIFY
|
#ifdef SOUND_NOTIFY
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; i < SOUNDS_SIZE; i ++) free(Control.sounds[i]);
|
for (; i < SOUNDS_SIZE; i ++) free(Control.sounds[i]);
|
||||||
close_device(output, Control.device_idx);
|
|
||||||
alutExit();
|
alutExit();
|
||||||
#endif /* SOUND_NOTIFY */
|
#endif /* SOUND_NOTIFY */
|
||||||
|
|
||||||
@ -395,6 +435,8 @@ int play_sound_internal(Notification what, bool loop)
|
|||||||
uint32_t source;
|
uint32_t source;
|
||||||
uint32_t buffer;
|
uint32_t buffer;
|
||||||
|
|
||||||
|
m_open_device();
|
||||||
|
|
||||||
alGenSources(1, &source);
|
alGenSources(1, &source);
|
||||||
alGenBuffers(1, &buffer);
|
alGenBuffers(1, &buffer);
|
||||||
buffer = alutCreateBufferFromFile(Control.sounds[what]);
|
buffer = alutCreateBufferFromFile(Control.sounds[what]);
|
||||||
@ -519,6 +561,8 @@ int sound_notify2(ToxWindow* self, Notification notif, uint64_t flags, int id)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_open_device();
|
||||||
|
|
||||||
alSourceStop(actives[id].source);
|
alSourceStop(actives[id].source);
|
||||||
alDeleteSources(1, &actives[id].source);
|
alDeleteSources(1, &actives[id].source);
|
||||||
alDeleteBuffers(1,&actives[id].buffer);
|
alDeleteBuffers(1,&actives[id].buffer);
|
||||||
|
Loading…
Reference in New Issue
Block a user