A2DP: Fix audio stuttering in A2DP sink mode

Change-Id: Ied821aeb14f83e3fd1daa6e175ac995abbfbb198
diff --git a/audio_a2dp_hw/audio_a2dp_hw.c b/audio_a2dp_hw/audio_a2dp_hw.c
index 14a9235..beedb3b 100644
--- a/audio_a2dp_hw/audio_a2dp_hw.c
+++ b/audio_a2dp_hw/audio_a2dp_hw.c
@@ -222,12 +222,18 @@
     if (ret < 0)
         ERROR("setsockopt failed (%s)", strerror(errno));
 
+    ret = setsockopt(skt_fd, SOL_SOCKET, SO_RCVBUF, (char*)&len, (int)sizeof(len));
+
+    /* only issue warning if failed */
+    if (ret < 0)
+        ERROR("setsockopt failed (%s)", strerror(errno));
+
     INFO("connected to stack fd = %d", skt_fd);
 
     return skt_fd;
 }
 
-static int skt_read(int fd, void *p, size_t len, int us_timeout)
+static int skt_read(int fd, void *p, size_t len)
 {
     int read;
     struct pollfd pfd;
@@ -235,19 +241,6 @@
 
     FNLOG();
 
-    pfd.fd = fd;
-    pfd.events = POLLIN;
-
-    ts.tv_sec = us_timeout / 1000000;
-    ts.tv_nsec = (us_timeout % 1000000) * 1000;
-
-    ts_log("skt_read ppoll", len, NULL);
-
-    /* read time out */
-    if (ppoll(&pfd, 1, &ts, NULL) == 0) {
-        return 0;
-    }
-
     ts_log("skt_read recv", len, NULL);
 
     if ((read = recv(fd, p, len, MSG_NOSIGNAL)) == -1)
@@ -933,8 +926,6 @@
         return -1;
     }
 
-    int us_delay = calc_audiotime(in->common.cfg, bytes);
-
     /* only allow autostarting if we are in stopped or standby */
     if ((in->common.state == AUDIO_A2DP_STATE_STOPPED) ||
         (in->common.state == AUDIO_A2DP_STATE_STANDBY))
@@ -946,6 +937,8 @@
             /* emulate time this write represents to avoid very fast write
                failures during transition periods or remote suspend */
 
+            int us_delay = calc_audiotime(in->common.cfg, bytes);
+
             DEBUG("emulate a2dp read delay (%d us)", us_delay);
 
             usleep(us_delay);
@@ -961,7 +954,7 @@
         return -1;
     }
 
-    read = skt_read(in->common.audio_fd, buffer, bytes, us_delay);
+    read = skt_read(in->common.audio_fd, buffer, bytes);
 
     if (read == -1)
     {