From: Takashi Iwai Subject: Re: [PATCH v1 3/4] alsabat: add XRUN injections function Date: Thu, 31 Aug 2017 20:22:06 +0200 Message-ID: References: <20170831133709.25537-1-keqiao.zhang@intel.com> <20170831133709.25537-4-keqiao.zhang@intel.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 508FA266B70 for ; Thu, 31 Aug 2017 20:22:07 +0200 (CEST) In-Reply-To: <20170831133709.25537-4-keqiao.zhang@intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: Zhang Keqiao Cc: alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org On Thu, 31 Aug 2017 15:37:08 +0200, Zhang Keqiao wrote: > > This patch add XRUN injections function, alsabat can trigger the XRUNs > by writing the 'XRUN INJECTION' files. > > Signed-off-by: Zhang Keqiao > --- > bat/bat.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- > bat/common.h | 6 ++++ > 2 files changed, 101 insertions(+), 2 deletions(-) > > diff --git a/bat/bat.c b/bat/bat.c > index b12e5d3..20fa926 100644 > --- a/bat/bat.c > +++ b/bat/bat.c > @@ -127,8 +127,81 @@ static void get_sine_frequencies(struct bat *bat, char *freq) > } > } > > -/* parse the card and pcm ID of playback device and capture device */ > -/* Then we can get the path for specify device to do the XRUN injection */ > +static int xrun_injection(struct bat *bat) > +{ > + char playback_file[MAX_PATH + MAX_FILE]; > + char capture_file[MAX_PATH + MAX_FILE]; > + char filename[MAX_FILE] = XRUN_INJECTION_FILE; > + char playback_filepath[MAX_PATH] = PLAYBACK_XRUN_INJECTION_PATH; > + char capture_filepath[MAX_PATH] = CAPTURE_XRUN_INJECTION_PATH; > + FILE *fp, *fc; > + > + if (bat->xrun_playback) { > + /* replace the card ID and PCM ID in macro for xrun injection path */ > + sprintf(playback_filepath, playback_filepath, bat->playback.card_id, > + bat->playback.pcm_id); This doesn't look sane. The format path shouldn't be same as the target. There is no guarantee that the format path is evaluated before storing the resultant string. Moreover: > +#define PLAYBACK_XRUN_INJECTION_PATH "/proc/asound/card%s/pcm%sp/sub0" > +#define CAPTURE_XRUN_INJECTION_PATH "/proc/asound/card%s/pcm%sc/sub0" This assumes the PCM#0, which isn't always true. thanks, Takashi