History

ao_coreaudio: register hotplug_cb in normal init() as well

`hotplug_cb` was registered only in `hotplug_init()`. This commit make it registered in `init()` as well, so that the ao can listen for latency change in playback.

Misaki Kasumi committed 2 years ago

Commit 4ce4bf11 parent 2407e1b1 file · +36 −4Browse files

Unified · Split

audio/out/ao_coreaudio.c+36−4
@@ -46,6 +46,8 @@ struct priv { · 45 unmodified lines
4646 // Block that is executed after `IDLE_TIME` to stop audio output unit.
4747 dispatch_block_t idle_work;
4848 dispatch_queue_t queue;
49+
50+ int hotplug_cb_registration_times;
4951 };
5052
5153 static int64_t ca_get_hardware_latency(struct ao *ao) {
@@ -138,6 +140,8 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg) · 86 unmodified lines
138140 static bool init_audiounit(struct ao *ao, AudioStreamBasicDescription asbd);
139141 static void init_physical_format(struct ao *ao);
140142 static void reinit_latency(struct ao *ao);
143+static bool register_hotplug_cb(struct ao *ao);
144+static void unregister_hotplug_cb(struct ao *ao);
141145
142146 static bool reinit_device(struct ao *ao) {
143147 struct priv *p = ao->priv;
@@ -164,6 +168,9 @@ static int init(struct ao *ao) · 20 unmodified lines
164168 if (!reinit_device(ao))
165169 goto coreaudio_error;
166170
171+ if (!register_hotplug_cb(ao))
172+ goto coreaudio_error;
173+
167174 if (p->change_physical_format)
168175 init_physical_format(ao);
169176
@@ -433,6 +440,8 @@ static void uninit(struct ao *ao) · 263 unmodified lines
433440 &p->original_asbd);
434441 CHECK_CA_WARN("could not restore physical stream format");
435442 }
443+
444+ unregister_hotplug_cb(ao);
436445 }
437446
438447 static OSStatus hotplug_cb(AudioObjectID id, UInt32 naddr,
@@ -457,7 +466,25 @@ static uint32_t hotplug_properties[] = { · 18 unmodified lines
457466 static int hotplug_init(struct ao *ao)
458467 {
459468 if (!reinit_device(ao))
460− goto coreaudio_error;
469+ return -1;
470+
471+ if (!register_hotplug_cb(ao))
472+ return -1;
473+
474+ return 0;
475+}
476+
477+static void hotplug_uninit(struct ao *ao)
478+{
479+ unregister_hotplug_cb(ao);
480+}
481+
482+static bool register_hotplug_cb(struct ao *ao)
483+{
484+ struct priv *p = ao->priv;
485+
486+ if (p->hotplug_cb_registration_times++)
487+ return true;
461488
462489 OSStatus err = noErr;
463490 for (int i = 0; i < MP_ARRAY_SIZE(hotplug_properties); i++) {
@@ -476,14 +503,19 @@ static int hotplug_init(struct ao *ao) · 12 unmodified lines
476503 }
477504 }
478505
479− return 0;
506+ return true;
480507
481508 coreaudio_error:
482− return -1;
509+ return false;
483510 }
484511
485−static void hotplug_uninit(struct ao *ao)
512+static void unregister_hotplug_cb(struct ao *ao)
486513 {
514+ struct priv *p = ao->priv;
515+
516+ if (--p->hotplug_cb_registration_times)
517+ return;
518+
487519 OSStatus err = noErr;
488520 for (int i = 0; i < MP_ARRAY_SIZE(hotplug_properties); i++) {
489521 AudioObjectPropertyAddress addr = {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t