usb audio: Fix incorrect bytes returned for recording

In a recording session , the number of bytes read is
not updated when pcm_read() fails. This results in
silence/invalid data being added during a device switch
from USB headset to handset.
Fix is to reset the number of bytes read if pcm_read()
returns an error indicating removal of USB headset.

Bug: 18611518

Change-Id: I10d578c3cf1037c90a891e63be2bd1c2b7e6126b
diff --git a/modules/usbaudio/audio_hw.c b/modules/usbaudio/audio_hw.c
index 0ee44c5..49c99af 100644
--- a/modules/usbaudio/audio_hw.c
+++ b/modules/usbaudio/audio_hw.c
@@ -775,6 +775,7 @@
     size_t num_read_buff_bytes = 0;
     void * read_buff = buffer;
     void * out_buff = buffer;
+    int ret = 0;
 
     struct stream_in * in = (struct stream_in *)stream;
 
@@ -824,7 +825,8 @@
         read_buff = in->conversion_buffer;
     }
 
-    if (proxy_read(&in->proxy, read_buff, num_read_buff_bytes) == 0) {
+    ret = proxy_read(&in->proxy, read_buff, num_read_buff_bytes);
+    if (ret == 0) {
         /*
          * Do any conversions necessary to send the data in the format specified to/by the HAL
          * (but different from the ALSA format), such as 24bit ->16bit, or 4chan -> 2chan.
@@ -865,6 +867,8 @@
         /* no need to acquire in->dev->lock to read mic_muted here as we don't change its state */
         if (num_read_buff_bytes > 0 && in->dev->mic_muted)
             memset(buffer, 0, num_read_buff_bytes);
+    } else if (ret == -ENODEV) {
+            num_read_buff_bytes = 0; //reset the  value after USB headset is unplugged
     }
 
 err: