fix alsa playback underrun and premature shutdown

modify buffer and period params request and how the code keeps the buffer
full enough to not underrun.

Also let playing thread finish their jobs if the global state is not
set to cancel.

I need to check the sound and video is still in sync. If not, the alsa
buffer size can be reduced to minimize latency.

Also, it feels like not the full stream is played before the ALSA device
gets closed. I'll check if we could not call snd_pcm_drain() or something
like that.