Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fb80ecc9 authored by Mike Lockwood's avatar Mike Lockwood
Browse files

A2DP: Fix audio stuttering in A2DP sink mode

Change-Id: Ied821aeb14f83e3fd1daa6e175ac995abbfbb198
parent 9697163e
Loading
Loading
Loading
Loading
+10 −17
Original line number Diff line number Diff line
@@ -218,6 +218,12 @@ static int skt_connect(char *path, size_t buffer_sz)
    len = buffer_sz;
    ret = setsockopt(skt_fd, SOL_SOCKET, SO_SNDBUF, (char*)&len, (int)sizeof(len));

    /* only issue warning if failed */
    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));
@@ -227,7 +233,7 @@ static int skt_connect(char *path, size_t buffer_sz)
    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 @@ static int skt_read(int fd, void *p, size_t len, int us_timeout)

    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 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
        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 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
            /* 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 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
        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)
    {