From owner-p4-projects@FreeBSD.ORG Wed Jul 15 20:54:23 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id DE6751065674; Wed, 15 Jul 2009 20:54:22 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9CF28106566B for ; Wed, 15 Jul 2009 20:54:22 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 80ADF8FC0C for ; Wed, 15 Jul 2009 20:54:22 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n6FKsMto048873 for ; Wed, 15 Jul 2009 20:54:22 GMT (envelope-from hselasky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n6FKsM8O048871 for perforce@freebsd.org; Wed, 15 Jul 2009 20:54:22 GMT (envelope-from hselasky@FreeBSD.org) Date: Wed, 15 Jul 2009 20:54:22 GMT Message-Id: <200907152054.n6FKsM8O048871@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky To: Perforce Change Reviews Cc: Subject: PERFORCE change 166149 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Jul 2009 20:54:23 -0000 http://perforce.freebsd.org/chv.cgi?CH=166149 Change 166149 by hselasky@hselasky_laptop001 on 2009/07/15 20:53:46 USB audio: - code factoring patch from "Eygene Ryabinkin" Affected files ... .. //depot/projects/usb/src/sys/dev/sound/usb/uaudio.c#53 edit Differences ... ==== //depot/projects/usb/src/sys/dev/sound/usb/uaudio.c#53 (text+ko) ==== @@ -108,6 +108,7 @@ #define UAUDIO_MINFRAMES 16 /* must be factor of 8 due HS-USB */ #define UAUDIO_NCHANBUFS 2 /* number of outstanding request */ #define UAUDIO_RECURSE_LIMIT 24 /* rounds */ +#define UAUDIO_MINFRAMES_ALIGN(x) ((x) & ~(UAUDIO_MINFRAMES - 1)) #define MAKE_WORD(h,l) (((h) << 8) | (l)) #define BIT_TEST(bm,bno) (((bm)[(bno) / 8] >> (7 - ((bno) % 8))) & 1) @@ -1113,7 +1114,42 @@ } } +/* + * The following function sets up data size and block count for the + * next audio transfer. + */ static void +uaudio_setup_blockcount(struct uaudio_chan *ch, usb_frcount_t max_frames, + uint32_t *total, uint32_t *blockcount) +{ + uint32_t temp; + uint32_t isiz; + + /* allow dynamic sizing of play buffer */ + isiz = ch->intr_size; + + /* allow dynamic sizing of play buffer */ + temp = isiz / ch->bytes_per_frame; + + /* align units */ + temp = UAUDIO_MINFRAMES_ALIGN(temp); + + /* range check - min */ + if (temp == 0) + temp = UAUDIO_MINFRAMES; + + /* range check - max */ + if (temp > max_frames) + temp = max_frames; + + /* store blockcount */ + *blockcount = temp; + + /* compute the total length */ + *total = temp * ch->bytes_per_frame; +} + +static void uaudio_chan_play_callback(struct usb_xfer *xfer, usb_error_t error) { struct uaudio_chan *ch = usbd_xfer_softc(xfer); @@ -1126,25 +1162,8 @@ usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL); - /* allow dynamic sizing of play buffer */ - total = ch->intr_size; - - /* allow dynamic sizing of play buffer */ - blockcount = total / ch->bytes_per_frame; - - /* align units */ - blockcount -= (blockcount % UAUDIO_MINFRAMES); - - /* range check - min */ - if (blockcount == 0) { - blockcount = UAUDIO_MINFRAMES; - } - /* range check - max */ - if (blockcount > usbd_xfer_max_frames(xfer)) { - blockcount = usbd_xfer_max_frames(xfer); - } - /* compute the total length */ - total = blockcount * ch->bytes_per_frame; + uaudio_setup_blockcount(ch, usbd_xfer_max_frames(xfer), + &total, &blockcount); switch (USB_GET_STATE(xfer)) { case USB_ST_TRANSFERRED: @@ -1221,25 +1240,8 @@ usbd_xfer_status(xfer, &actlen, NULL, NULL, &nframes); - /* allow dynamic sizing of play buffer */ - total = ch->intr_size; - - /* allow dynamic sizing of play buffer */ - blockcount = total / ch->bytes_per_frame; - - /* align units */ - blockcount -= (blockcount % UAUDIO_MINFRAMES); - - /* range check - min */ - if (blockcount == 0) { - blockcount = UAUDIO_MINFRAMES; - } - /* range check - max */ - if (blockcount > usbd_xfer_max_frames(xfer)) { - blockcount = usbd_xfer_max_frames(xfer); - } - /* compute the total length */ - total = blockcount * ch->bytes_per_frame; + uaudio_setup_blockcount(ch, usbd_xfer_max_frames(xfer), + &total, &blockcount); switch (USB_GET_STATE(xfer)) { case USB_ST_TRANSFERRED: