From patchwork Sat Sep 2 14:30:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadim Yanitskiy X-Patchwork-Id: 809068 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=144.76.43.76; helo=lists.osmocom.org; envelope-from=openbsc-bounces@lists.osmocom.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="PzCzx9VW"; dkim-atps=neutral Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by ozlabs.org (Postfix) with ESMTP id 3xkz7P4Ksgz9sNr for ; Sun, 3 Sep 2017 00:31:10 +1000 (AEST) Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id 6090A38D65; Sat, 2 Sep 2017 14:30:47 +0000 (UTC) Authentication-Results: lists.osmocom.org; dmarc=none header.from=gmail.com Authentication-Results: lists.osmocom.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=PzCzx9VW 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 2E1BF38D54 for ; Sat, 2 Sep 2017 14:30:39 +0000 (UTC) Received: by mail-lf0-x243.google.com with SMTP id o124so1491723lfo.1 for ; Sat, 02 Sep 2017 07:30:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=G5rmXRj2X1Zl9PMONzVDY/eoNfBM1SKeaS/Oo5ACAhE=; b=PzCzx9VWHxiz0ySPvo/BgAzU/RHwjzRntiFbo55QVp5qwkHuib99CfI8JN4d1EMyh4 xGImc5o59qK5gsxbhcljLF9qEHywrMVgaTM4/nEEpsae/yP97S8KtbLfY6xWgyWN7jeo o9DEnwLljhSGHsiaR9tMqX6JzLR6N6HT/FzoZXdzmbeacat+ani0RX/hUpBsp3VCzMv/ sX7CZalobMlN8KL4QtULpQXqTlJZF/T9jVQyEmGS0LoOfHap68zD8hmolodRbs0tFOio YM1k/nCrytjvqdVAJncY8n3krIYRgJVTkVWH8X3O36toq+mo9bVKr2lJurMUgDCcL9PL j7+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=G5rmXRj2X1Zl9PMONzVDY/eoNfBM1SKeaS/Oo5ACAhE=; b=Lsn6caj4HtwENQYRE9Uax7DuDDpRUCFIRdE2PM6vAARBjVD9N9Z0Q/j/+deDjCpgpj x/WLo0Ewh3O4PY/15RqATIb5DXg+dUA0aVGrwhzQBdtFoCvQOKa+H/MuwwF/SKfcy2f/ l9Kv1ziEx315q29vILx9uCzd3Cyd4Qkts1wWxFIeGARhrOcssV1E5/dgl1K4xLpdxUVe PtYia8N+YBSE5SMKXso5zE3GDbnmhFkY6VZSRn6FDzVJBvTMCV2/AidD5Es2KR0//VHn Hm/ytRekwNHw4V96kFQOztfTPYTssDNmFH1MblS0twUVPfbAIZkmNpR7SEP0hbEV8B4q /OZQ== X-Gm-Message-State: AHPjjUg4o4lLgYobWzEid58zqAcIcqanoPoiFCtS9bLXljbzuWv7dvw4 jMF7wsiPeBgG+gomhx4= X-Google-Smtp-Source: ADKCNb4evSSzxX6uGfiksx1VOaUWzvynytL3ya3PREb9tXRhOr/WbZZo9BctfVlDJizIEnB3G5PYjw== X-Received: by 10.46.82.25 with SMTP id g25mr1135500ljb.25.1504362636455; Sat, 02 Sep 2017 07:30:36 -0700 (PDT) Received: from DELL.lan ([92.127.181.248]) by smtp.gmail.com with ESMTPSA id n76sm208435lje.62.2017.09.02.07.30.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 02 Sep 2017 07:30:35 -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:30:09 +0700 Message-Id: <20170902143009.14011-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: , Cc: axilirator@gmail.com 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; } -- 2.14.1 From 8f1b0a9bf966cd561b10d2d33c6a47dd02e17dcf Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Sat, 2 Sep 2017 18:02:45 +0700 Subject: [PATCH 2/2] pq_alsa.c: print error message if device init fails To: openbsc@lists.osmocom.org Cc: 246tnt@gmail.com, laforge@gnumonks.org, axilirator@gmail.com --- src/pq_alsa.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/pq_alsa.c b/src/pq_alsa.c index a3435dd..cad76ca 100644 --- a/src/pq_alsa.c +++ b/src/pq_alsa.c @@ -85,13 +85,16 @@ pq_queue_alsa_op(struct pq *pq, const char *alsa_dev, unsigned int blk_len, int int rc = -1; state = calloc(1, sizeof(struct pq_state_alsa)); - if (!state) - return -ENOMEM; + if (!state) { + rc = -ENOMEM; + goto out_print; + } rc = snd_pcm_open(&state->pcm_handle, alsa_dev, in_out_n ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK, 0); if (rc < 0) - return rc; + goto out_print; + state->blk_len = blk_len; rc = snd_pcm_hw_params_malloc(&hw_params); @@ -143,6 +146,9 @@ out_free_par: out_close: snd_pcm_close(state->pcm_handle); free(state); +out_print: + fprintf(stderr, "[!] Couldn't init ALSA device '%s': %s\n", + alsa_dev, snd_strerror(rc)); return rc; }