From patchwork Sat Sep 2 14:34:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadim Yanitskiy X-Patchwork-Id: 809069 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.osmocom.org (client-ip=2a01:4f8:191:444b::2:7; helo=lists.osmocom.org; envelope-from=openbsc-bounces@lists.osmocom.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="f58Z6Cco"; dkim-atps=neutral Received: from lists.osmocom.org (lists.osmocom.org [IPv6:2a01:4f8:191:444b::2:7]) by ozlabs.org (Postfix) with ESMTP id 3xkzDk16vCz9sP1 for ; Sun, 3 Sep 2017 00:35:50 +1000 (AEST) Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id 82C5A38DC3; Sat, 2 Sep 2017 14:35:43 +0000 (UTC) Authentication-Results: lists.osmocom.org; dmarc=pass header.from=gmail.com Authentication-Results: lists.osmocom.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=f58Z6Cco X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4010:c07::243; helo=mail-lf0-x243.google.com; envelope-from=axilirator@gmail.com; receiver=openbsc@lists.osmocom.org Authentication-Results: lists.osmocom.org; dmarc=pass header.from=gmail.com Received: from mail-lf0-x243.google.com (mail-lf0-x243.google.com [IPv6:2a00:1450:4010:c07::243]) by lists.osmocom.org (Postfix) with ESMTP id B5DEA38D8B for ; Sat, 2 Sep 2017 14:34:10 +0000 (UTC) Received: by mail-lf0-x243.google.com with SMTP id h132so1489435lfh.2 for ; Sat, 02 Sep 2017 07:34:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=fgU688RbpKfpj8WdOdqF04skvPkuTf/xr8NCW923CnU=; b=f58Z6CcoVdshHCNnkdjCT1lRrfRRRl9lDGJ7BY2TWMdOuvKr8OXrM0y283/5cGubOo uaxGEVxWKBGNPxqPZBeCjVAgyIayHHhkwHsU2HCDf6aRckDAkt2tglmEO+5xiNvcIScx iP/d/G7cLpjKOWW5lFAaj8qwYb6WfJCrF14L47COyMBd/jP/Rx9ri3GPWat3LKoYcbz9 sff0xUKRft6QhKe2+Vqlz/bvNZrpOJrQnhIqiAteEhdmWgYDo5thQruo2HYlOWzlX6QF k4vwU9WzkI9/lPTMuEvLekBNJktiEZNjr6U+5C/6d3dbAktLtUZ5h9As2yTI6SW+uEoy y37A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=fgU688RbpKfpj8WdOdqF04skvPkuTf/xr8NCW923CnU=; b=lin7LwRkaAWvub5YYfjYLwHHkQ7WqHFzcUXcJ88+gW4yNajXt0+hsNJrDCWaQYiiaa CfIaSXlo4pthzMtqW32AF/LPschrjslrGEo/2xRdF3mV4Hnxj23VQr9CJGNWsfnvPSns xjRIAsn2vh1itwkcKurAFupwP7vrQvoiu1rq8ZeyhNKwyQL0UbICnnA8K6sNqK1a3NUb JiVTx9xTg8yCo7t6RrMY/KKE4LyOZjog+BS4d9BCvJF8iau9pdFm7lVqrSU8bHYq9FOd /H7hYhSrW71sgy9qkpuhG+/xqvv2Le8tb4gZw3UqKaelFm6xTwPEevXj4sn6EbLeibQ1 QrIw== X-Gm-Message-State: AHPjjUjIOGq175Ux5LV4NELmkKVHa3aTFOgW6A8HtO+Sg0VfzKYpsFfe xCJI03KdSQ2Q/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; Sat, 02 Sep 2017 07:34:09 -0700 (PDT) Received: from DELL.lan ([92.127.181.248]) by smtp.gmail.com with ESMTPSA id e11sm413177lji.82.2017.09.02.07.34.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 02 Sep 2017 07:34:09 -0700 (PDT) From: Vadim Yanitskiy 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, OsmoCSCN" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" On some systems the ALSA output buffer is pretty big, and if the audio samples are not being passed into the buffer quickly enough, it becomes starved for data, resulting in an error called underrun. Previously, when it happenned, GAPK used to stop processing with the following message (where X is a random number): [+] PQ: Adding ALSA output (dev='default', blk_len=320) [!] pq_execute(): abort, item returned -1 [+] Processed X frames According to the ALSA documentation, the pcm_handle changes its state when the problem happens, and should be recovered using the snd_pcm_prepare() call. This change actually does that. --- src/pq_alsa.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pq_alsa.c b/src/pq_alsa.c index 9cee426..a3435dd 100644 --- a/src/pq_alsa.c +++ b/src/pq_alsa.c @@ -57,7 +57,15 @@ pq_cb_alsa_output(void *_state, uint8_t *out, const uint8_t *in, unsigned int in struct pq_state_alsa *state = _state; unsigned int num_samples = in_len/2; int rv; + rv = snd_pcm_writei(state->pcm_handle, in, num_samples); + if (rv == -EPIPE) { + /* Recover from buffer underrun */ + snd_pcm_prepare(state->pcm_handle); + /* Send a new sample again */ + rv = snd_pcm_writei(state->pcm_handle, in, num_samples); + } + return rv == num_samples ? 0 : -1; }