hal : Send drain to the driver if next track returns error

-Partial drain is send to the driver after next track ioctl.
-If next track times out or returns any error then call drain.
-Partial drain will not  be executed if next track fails.

CRs-Fixed: 594977
Change-Id: I0665f21a5ea01f7776408b5155344f542021c299
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 19fdda2..434b431 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -831,6 +831,7 @@
 {
     struct stream_out *out = (struct stream_out *) context;
     struct listnode *item;
+    int ret = 0;
 
     setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_AUDIO);
     set_sched_policy(0, SP_FOREGROUND);
@@ -880,8 +881,14 @@
             event = STREAM_CBK_EVENT_WRITE_READY;
             break;
         case OFFLOAD_CMD_PARTIAL_DRAIN:
-            compress_next_track(out->compr);
-            compress_partial_drain(out->compr);
+            ret = compress_next_track(out->compr);
+            if(ret == 0)
+                compress_partial_drain(out->compr);
+            else if(ret == -ETIMEDOUT)
+                compress_drain(out->compr);
+            else
+                ALOGE("%s: Next track returned error %d",__func__, ret);
+
             send_callback = true;
             event = STREAM_CBK_EVENT_DRAIN_READY;
             break;