Date: Wed, 15 Jul 2009 20:54:22 GMT From: Hans Petter Selasky <hselasky@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 166149 for review Message-ID: <200907152054.n6FKsM8O048871@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200907152054.n6FKsM8O048871>