CRAS: alsa_plugin: support drain behavior and fix deadlock

Drain is not implemented for ALSA ioplug prior to alsa-lib 1.1.6.
Start from 1.1.6, drain behavior has fulfilled by alsa-lib commit
"ce2095c4 pcm: ioplug: Implement proper drain behavior".
This change supports drain behavior (from alsa_plugin's point of view)
and also fixes a deadlock problem from previous implementation.

BUG=b:110190775
TEST=sox -b 16 -r 48000 -c 2 -n -t alsa default synth 3 sine 1000 sine 1000;
cras_test_client --loopback_f xxx.raw; use audacity to check xxx.raw's
integrity

Signed-off-by: Tzung-Bi Shih <tzungbi@chromium.org>
Change-Id: I81bda34057b38cbbf0caf0c776e7b274a3d8c360
Reviewed-on: https://chromium-review.googlesource.com/1124060
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
diff --git a/cras/src/alsa_plugin/pcm_cras.c b/cras/src/alsa_plugin/pcm_cras.c
index 5591a11..f30c7cd 100644
--- a/cras/src/alsa_plugin/pcm_cras.c
+++ b/cras/src/alsa_plugin/pcm_cras.c
@@ -143,7 +143,8 @@
 	sample_bytes = snd_pcm_format_physical_width(io->format) / 8;
 
 	if (io->stream == SND_PCM_STREAM_PLAYBACK) {
-		if (io->state != SND_PCM_STATE_RUNNING) {
+		if (io->state != SND_PCM_STATE_RUNNING &&
+		    io->state != SND_PCM_STATE_DRAINING) {
 			memset(samples, 0, nframes * frame_bytes);
 			return nframes;
 		}