{"id":809069,"url":"http://patchwork.ozlabs.org/api/patches/809069/?format=json","web_url":"http://patchwork.ozlabs.org/project/openbsc/patch/20170902143403.14185-1-axilirator@gmail.com/","project":{"id":39,"url":"http://patchwork.ozlabs.org/api/projects/39/?format=json","name":"OpenBSC development","link_name":"openbsc","list_id":"openbsc.lists.osmocom.org","list_email":"openbsc@lists.osmocom.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170902143403.14185-1-axilirator@gmail.com>","list_archive_url":null,"date":"2017-09-02T14:34:02","name":"[1/2] pq_alsa.c: handle output buffer underrun","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"50e5b3af490df5b994812b8c3df0266b27b4d2b8","submitter":{"id":67986,"url":"http://patchwork.ozlabs.org/api/people/67986/?format=json","name":"Vadim Yanitskiy","email":"axilirator@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/openbsc/patch/20170902143403.14185-1-axilirator@gmail.com/mbox/","series":[{"id":1156,"url":"http://patchwork.ozlabs.org/api/series/1156/?format=json","web_url":"http://patchwork.ozlabs.org/project/openbsc/list/?series=1156","date":"2017-09-02T14:34:02","name":"[1/2] pq_alsa.c: handle output buffer underrun","version":1,"mbox":"http://patchwork.ozlabs.org/series/1156/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/809069/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/809069/checks/","tags":{},"related":[],"headers":{"Return-Path":"<openbsc-bounces@lists.osmocom.org>","X-Original-To":["incoming@patchwork.ozlabs.org","openbsc@lists.osmocom.org"],"Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","openbsc@lists.osmocom.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=lists.osmocom.org\n\t(client-ip=2a01:4f8:191:444b::2:7; helo=lists.osmocom.org;\n\tenvelope-from=openbsc-bounces@lists.osmocom.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"f58Z6Cco\"; dkim-atps=neutral","lists.osmocom.org; dmarc=pass header.from=gmail.com","lists.osmocom.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com header.b=f58Z6Cco","lists.osmocom.org; dmarc=pass header.from=gmail.com"],"Received":["from lists.osmocom.org (lists.osmocom.org\n\t[IPv6:2a01:4f8:191:444b::2:7])\n\tby ozlabs.org (Postfix) with ESMTP id 3xkzDk16vCz9sP1\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSun,  3 Sep 2017 00:35:50 +1000 (AEST)","from lists.osmocom.org (lists.osmocom.org [144.76.43.76])\n\tby lists.osmocom.org (Postfix) with ESMTP id 82C5A38DC3;\n\tSat,  2 Sep 2017 14:35:43 +0000 (UTC)","from mail-lf0-x243.google.com (mail-lf0-x243.google.com\n\t[IPv6:2a00:1450:4010:c07::243])\n\tby lists.osmocom.org (Postfix) with ESMTP id B5DEA38D8B\n\tfor <openbsc@lists.osmocom.org>; Sat,  2 Sep 2017 14:34:10 +0000 (UTC)","by mail-lf0-x243.google.com with SMTP id h132so1489435lfh.2\n\tfor <openbsc@lists.osmocom.org>; Sat, 02 Sep 2017 07:34:10 -0700 (PDT)","from DELL.lan ([92.127.181.248]) by smtp.gmail.com with ESMTPSA id\n\te11sm413177lji.82.2017.09.02.07.34.09\n\tfor <openbsc@lists.osmocom.org>\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tSat, 02 Sep 2017 07:34:09 -0700 (PDT)"],"Received-SPF":"Pass (sender SPF authorized) identity=mailfrom;\n\tclient-ip=2a00:1450:4010:c07::243; helo=mail-lf0-x243.google.com;\n\tenvelope-from=axilirator@gmail.com;\n\treceiver=openbsc@lists.osmocom.org ","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=from:to:subject:date:message-id;\n\tbh=fgU688RbpKfpj8WdOdqF04skvPkuTf/xr8NCW923CnU=;\n\tb=f58Z6CcoVdshHCNnkdjCT1lRrfRRRl9lDGJ7BY2TWMdOuvKr8OXrM0y283/5cGubOo\n\tuaxGEVxWKBGNPxqPZBeCjVAgyIayHHhkwHsU2HCDf6aRckDAkt2tglmEO+5xiNvcIScx\n\tiP/d/G7cLpjKOWW5lFAaj8qwYb6WfJCrF14L47COyMBd/jP/Rx9ri3GPWat3LKoYcbz9\n\tsff0xUKRft6QhKe2+Vqlz/bvNZrpOJrQnhIqiAteEhdmWgYDo5thQruo2HYlOWzlX6QF\n\tk4vwU9WzkI9/lPTMuEvLekBNJktiEZNjr6U+5C/6d3dbAktLtUZ5h9As2yTI6SW+uEoy\n\ty37A==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:subject:date:message-id;\n\tbh=fgU688RbpKfpj8WdOdqF04skvPkuTf/xr8NCW923CnU=;\n\tb=lin7LwRkaAWvub5YYfjYLwHHkQ7WqHFzcUXcJ88+gW4yNajXt0+hsNJrDCWaQYiiaa\n\tCfIaSXlo4pthzMtqW32AF/LPschrjslrGEo/2xRdF3mV4Hnxj23VQr9CJGNWsfnvPSns\n\txjRIAsn2vh1itwkcKurAFupwP7vrQvoiu1rq8ZeyhNKwyQL0UbICnnA8K6sNqK1a3NUb\n\tJiVTx9xTg8yCo7t6RrMY/KKE4LyOZjog+BS4d9BCvJF8iau9pdFm7lVqrSU8bHYq9FOd\n\t/H7hYhSrW71sgy9qkpuhG+/xqvv2Le8tb4gZw3UqKaelFm6xTwPEevXj4sn6EbLeibQ1\n\tQrIw==","X-Gm-Message-State":"AHPjjUjIOGq175Ux5LV4NELmkKVHa3aTFOgW6A8HtO+Sg0VfzKYpsFfe\n\txCJI03KdSQ2Q/lte8RI=","X-Google-Smtp-Source":"ADKCNb7MXEESuR4MjfqDcLUCO8KCJGrQ7mx5+P+BF+zAW8LGjx+IZXi0JR/Q2896cMtU7z6lK/o0Ew==","X-Received":"by 10.25.83.3 with SMTP id h3mr1752493lfb.89.1504362849899;\n\tSat, 02 Sep 2017 07:34:09 -0700 (PDT)","From":"Vadim Yanitskiy <axilirator@gmail.com>","To":"openbsc@lists.osmocom.org","Subject":"[PATCH 1/2] pq_alsa.c: handle output buffer underrun","Date":"Sat,  2 Sep 2017 21:34:02 +0700","Message-Id":"<20170902143403.14185-1-axilirator@gmail.com>","X-Mailer":"git-send-email 2.14.1","X-BeenThere":"openbsc@lists.osmocom.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"\"Development of OpenBSC, OsmoBSC, OsmoNITB,\n\tOsmoCSCN\" <openbsc.lists.osmocom.org>","List-Unsubscribe":"<https://lists.osmocom.org/mailman/options/openbsc>,\n\t<mailto:openbsc-request@lists.osmocom.org?subject=unsubscribe>","List-Archive":"<http://lists.osmocom.org/pipermail/openbsc/>","List-Post":"<mailto:openbsc@lists.osmocom.org>","List-Help":"<mailto:openbsc-request@lists.osmocom.org?subject=help>","List-Subscribe":"<https://lists.osmocom.org/mailman/listinfo/openbsc>,\n\t<mailto:openbsc-request@lists.osmocom.org?subject=subscribe>","Errors-To":"openbsc-bounces@lists.osmocom.org","Sender":"\"OpenBSC\" <openbsc-bounces@lists.osmocom.org>"},"content":"On some systems the ALSA output buffer is pretty big, and\nif the audio samples are not being passed into the buffer\nquickly enough, it becomes starved for data, resulting\nin an error called underrun.\n\nPreviously, when it happenned, GAPK used to stop processing\nwith the following message (where X is a random number):\n\n[+] PQ: Adding ALSA output (dev='default', blk_len=320)\n[!] pq_execute(): abort, item returned -1\n[+] Processed X frames\n\nAccording to the ALSA documentation, the pcm_handle\nchanges its state when the problem happens, and should\nbe recovered using the snd_pcm_prepare() call. This change\nactually does that.\n---\n src/pq_alsa.c | 8 ++++++++\n 1 file changed, 8 insertions(+)","diff":"diff --git a/src/pq_alsa.c b/src/pq_alsa.c\nindex 9cee426..a3435dd 100644\n--- a/src/pq_alsa.c\n+++ b/src/pq_alsa.c\n@@ -57,7 +57,15 @@ pq_cb_alsa_output(void *_state, uint8_t *out, const uint8_t *in, unsigned int in\n \tstruct pq_state_alsa *state = _state;\n \tunsigned int num_samples = in_len/2;\n \tint rv;\n+\n \trv = snd_pcm_writei(state->pcm_handle, in, num_samples);\n+\tif (rv == -EPIPE) {\n+\t\t/* Recover from buffer underrun */\n+\t\tsnd_pcm_prepare(state->pcm_handle);\n+\t\t/* Send a new sample again */\n+\t\trv = snd_pcm_writei(state->pcm_handle, in, num_samples);\n+\t}\n+\n \treturn rv == num_samples ? 0 : -1;\n }\n \n","prefixes":["1/2"]}