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
46 // Block that is executed after `IDLE_TIME` to stop audio output unit.46 // Block that is executed after `IDLE_TIME` to stop audio output unit.
47 dispatch_block_t idle_work;47 dispatch_block_t idle_work;
48 dispatch_queue_t queue;48 dispatch_queue_t queue;
49
50 int hotplug_cb_registration_times;
49};51};
50 52
51static int64_t ca_get_hardware_latency(struct ao *ao) {53static 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
138static bool init_audiounit(struct ao *ao, AudioStreamBasicDescription asbd);140static bool init_audiounit(struct ao *ao, AudioStreamBasicDescription asbd);
139static void init_physical_format(struct ao *ao);141static void init_physical_format(struct ao *ao);
140static void reinit_latency(struct ao *ao);142static void reinit_latency(struct ao *ao);
143static bool register_hotplug_cb(struct ao *ao);
144static void unregister_hotplug_cb(struct ao *ao);
141 145
142static bool reinit_device(struct ao *ao) {146static bool reinit_device(struct ao *ao) {
143 struct priv *p = ao->priv;147 struct priv *p = ao->priv;
@@ -164,6 +168,9 @@ static int init(struct ao *ao) · 20 unmodified lines
164 if (!reinit_device(ao))168 if (!reinit_device(ao))
165 goto coreaudio_error;169 goto coreaudio_error;
166 170
171 if (!register_hotplug_cb(ao))
172 goto coreaudio_error;
173
167 if (p->change_physical_format)174 if (p->change_physical_format)
168 init_physical_format(ao);175 init_physical_format(ao);
169 176
@@ -433,6 +440,8 @@ static void uninit(struct ao *ao) · 263 unmodified lines
433 &p->original_asbd);440 &p->original_asbd);
434 CHECK_CA_WARN("could not restore physical stream format");441 CHECK_CA_WARN("could not restore physical stream format");
435 }442 }
443
444 unregister_hotplug_cb(ao);
436}445}
437 446
438static OSStatus hotplug_cb(AudioObjectID id, UInt32 naddr,447static OSStatus hotplug_cb(AudioObjectID id, UInt32 naddr,
@@ -457,7 +466,25 @@ static uint32_t hotplug_properties[] = { · 18 unmodified lines
457static int hotplug_init(struct ao *ao)466static int hotplug_init(struct ao *ao)
458{467{
459 if (!reinit_device(ao))468 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
477static void hotplug_uninit(struct ao *ao)
478{
479 unregister_hotplug_cb(ao);
480}
481
482static 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;
461 488
462 OSStatus err = noErr;489 OSStatus err = noErr;
463 for (int i = 0; i < MP_ARRAY_SIZE(hotplug_properties); i++) {490 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
476 }503 }
477 }504 }
478 505
479 return 0;506 return true;
480 507
481coreaudio_error:508coreaudio_error:
482 return -1;509 return false;
483}510}
484 511
485static void hotplug_uninit(struct ao *ao)512static void unregister_hotplug_cb(struct ao *ao)
486{513{
514 struct priv *p = ao->priv;
515
516 if (--p->hotplug_cb_registration_times)
517 return;
518
487 OSStatus err = noErr;519 OSStatus err = noErr;
488 for (int i = 0; i < MP_ARRAY_SIZE(hotplug_properties); i++) {520 for (int i = 0; i < MP_ARRAY_SIZE(hotplug_properties); i++) {
489 AudioObjectPropertyAddress addr = {521 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