From patchwork Wed Sep 7 03:20:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Devin Heitmueller X-Patchwork-Id: 334 Return-path: Envelope-to: mchehab@infradead.org Delivery-date: Wed, 07 Sep 2011 03:21:51 +0000 Received: from casper.infradead.org [85.118.1.10] by localhost.localdomain with IMAP (fetchmail-6.3.17) for (single-drop); Wed, 07 Sep 2011 00:22:40 -0300 (BRT) Received: from vger.kernel.org ([209.132.180.67]) by casper.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1R18hf-0001zZ-7L; Wed, 07 Sep 2011 03:21:31 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755077Ab1IGDVA (ORCPT + 1 other); Tue, 6 Sep 2011 23:21:00 -0400 Received: from mail-bw0-f46.google.com ([209.85.214.46]:45530 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754714Ab1IGDVA convert rfc822-to-8bit (ORCPT ); Tue, 6 Sep 2011 23:21:00 -0400 Received: by bke11 with SMTP id 11so6029321bke.19 for ; Tue, 06 Sep 2011 20:20:59 -0700 (PDT) MIME-Version: 1.0 Received: by 10.204.130.3 with SMTP id q3mr3486099bks.17.1315365658616; Tue, 06 Sep 2011 20:20:58 -0700 (PDT) Received: by 10.204.152.18 with HTTP; Tue, 6 Sep 2011 20:20:58 -0700 (PDT) In-Reply-To: References: <1315322996-10576-1-git-send-email-mchehab@redhat.com> Date: Tue, 6 Sep 2011 23:20:58 -0400 Message-ID: Subject: Re: [PATCH 01/10] alsa_stream: port changes made on xawtv3 From: Devin Heitmueller To: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org On Tue, Sep 6, 2011 at 10:58 PM, Devin Heitmueller wrote: > On Tue, Sep 6, 2011 at 11:29 AM, Mauro Carvalho Chehab > wrote: >> There are several issues with the original alsa_stream code that got >> fixed on xawtv3, made by me and by Hans de Goede. Basically, the >> code were re-written, in order to follow the alsa best practises. >> >> Backport the changes from xawtv, in order to make it to work on a >> wider range of V4L and sound adapters. >> >> Signed-off-by: Mauro Carvalho Chehab > > Mauro, > > What tuners did you test this patch with?  I went ahead and did a git > pull of your patch series into my local git tree, and now my DVC-90 > (an em28xx device) is capturing at 32 KHz instead of 48 (this is one > of the snd-usb-audio based devices, not em28xx-alsa). > > Note I tested immediately before pulling your patch series and the > audio capture was working fine. > > I think this patch series is going in the right direction in general, > but this patch in particular seems to cause a regression.  Is this > something you want to investigate?  I think we need to hold off on > pulling this series into the new tvtime master until this problem is > resolved. > > Devin > > -- > Devin J. Heitmueller - Kernel Labs > http://www.kernellabs.com > Spent a few minutes digging into this. Looks like the snd-usb-audio driver advertises 8-48KHz. However, it seems that it only captures successfully at 48 KHz. I made the following hack and it started working: Basically the above starts at the *maximum* capture resolution and works its way down. One might argue that this heuristic makes more sense anyway - why *wouldn't* you want the highest quality audio possible by default (rather than the lowest)? Even with that patch though, I hit severe underrun/overrun conditions at 30ms of latency (to the point where the audio is interrupted dozens of times per second). Turned it up to 50ms and it's much better. That said, of course such a change would impact lipsync, so perhaps we need to be adjusting the periods instead. ALSA has never been my area of expertise, so I look to you and Hans to offer some suggestions. Devin diff --git a/src/alsa_stream.c b/src/alsa_stream.c index b6a41a5..57e3c3d 100644 --- a/src/alsa_stream.c +++ b/src/alsa_stream.c @@ -261,7 +261,7 @@ static int setparams(snd_pcm_t *phandle, snd_pcm_t *chandle, fprintf(error_fp, "alsa: Will search a common rate between %u and %u\n", ratemin, ratemax); - for (i = ratemin; i <= ratemax; i+= 100) { + for (i = ratemax; i >= ratemin; i-= 100) { err = snd_pcm_hw_params_set_rate_near(chandle, c_hwparams, &i, 0); if (err) continue;