you re right the code here does not cover all cases yet  there are scenarios thread rm active adev will get called the active device is set as inactive the active device is un plugged operation on the adev failed  eg  append stream or playback fail  for we should keep pinned streams and keep the adev active only for pinned streams for we should remove pinned streams  and notify client  for i think we should do as how about add a  keep pinned streams  param to thread rm active adev as an instruction 