Note to self: speakersafetyd ALSA mixer interlock design:
- Volume unlock is built on the mixer control exclusive lock feature (need to add an ALSA core callback to the kctl to implement this).
- DVC volumes are initially capped at a safe volume known to be safe for the speakers for all possible audio signals (set kernel-side).
- There is a special global watchdog/unlock control (takes an integer timestamp)
- speakersafetyd must first lock the watchdog control and write the current timestamp (CLOCK_MONOTONIC) to it.
- It can then lock the volume controls. This fails if the watchdog control is not locked or not up to date.
- When a volume control is locked by the same PID as the timestamp control and the timestamp is up to date, it removes its volume cap.
- The timestamp must be refreshed at least once per second while the playback PCM stream is active (== the feedback PCM stream is receiving samples). It is allowed to remain unupdated while the PCM is inactive (volumes remain set, but time since last update is cumulative while PCM runs, PCM becoming active does not reset the timeout).
- If at any point the watchdog expires or the unlock control lock is dropped (indicating the daemon died), all volumes are again reset and capped to a safe level.
- If an individual volume control lock is dropped, that individual control goes back to safe mode (only).