`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.
Unified · Split
| @@ -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 | ||
| 51 | static int64_t ca_get_hardware_latency(struct ao *ao) { | 53 | 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 | |||
| 138 | static bool init_audiounit(struct ao *ao, AudioStreamBasicDescription asbd); | 140 | static bool init_audiounit(struct ao *ao, AudioStreamBasicDescription asbd); |
| 139 | static void init_physical_format(struct ao *ao); | 141 | static void init_physical_format(struct ao *ao); |
| 140 | static void reinit_latency(struct ao *ao); | 142 | 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); | ||
| 141 | 145 | ||
| 142 | static bool reinit_device(struct ao *ao) { | 146 | static 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 | ||
| 438 | static OSStatus hotplug_cb(AudioObjectID id, UInt32 naddr, | 447 | static OSStatus hotplug_cb(AudioObjectID id, UInt32 naddr, |
| @@ -457,7 +466,25 @@ static uint32_t hotplug_properties[] = { · 18 unmodified lines | |||
| 457 | static int hotplug_init(struct ao *ao) | 466 | static 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 | |||
| 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; | ||
| 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 | ||
| 481 | coreaudio_error: | 508 | coreaudio_error: |
| 482 | return -1; | 509 | return false; |
| 483 | } | 510 | } |
| 484 | 511 | ||
| 485 | static void hotplug_uninit(struct ao *ao) | 512 | static 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 = { |