USB Audio Gadget refactoring
cover USB Audio Gadget refactoring
I came to this patch series when wanted to do two things:
- use UAC1 as virtual ALSA sound card on gadget side, just like UAC2 is used so it's possible to do rate resampling
- have both playback/capture support in UAC1
Since I wanted to have same behavior for both UAC1/UAC2, obviously I've got an utility part (u_audio.c) for virtual ALSA sound card handling like we have for ethernet(u_ether) or serial(u_serial) functions. Function-specific parts (f_uac1/f_uac2) became almost as storage for class-specfic USB descriptors, some boilerplate for configfs, binding and few USB config request handling.
Major change to f_uac1 it that it can't do direct play to existing ALSA sound card anymore, representing audio on gadget side as virtual ALSA sound card where audio streams are simply sinked to and sourced from it, so it may break current usecase for some people (and that's why it's RFC).
Luckily, it's possible to use existing user-space applications for audio routing between Audio Gadget and real sound card. I personally use alsaloop tool from alsautils and have ability to create PCM loopback between two different ALSA cards using rate resampling, which is not possible with previous "direct play to ALSA card" approach in f_uac1.
While here, also dropped redundant platform driver/device creation in f_uac2 driver as well as "never implemented" volume/mute functionality in f_uac1 that made this work even easier to do.
This series is tested with both legacy g_audio.ko and modern configfs approaches under Ubuntu 14.04 (UAC1 and UAC2) and under Windows7 x64 (UAC1 only) having perfect results in all cases.
Some changes may have lack of good description that may be obvious for me but not so clear for others, but I hope to fix it in next versions.
Comments, testing are welcome.
Ruslan Bilovol (5):
usb: gadget: f_uac2: remove platform driver/device creation
usb: gadget: f_uac2: split out audio core
usb: gadget: f_uac1: drop volume/mute functionality
usb: gadget: f_uac1: switch to u_audio core utilities
usb: gadget: f_uac1: add capture support
drivers/usb/gadget/Kconfig | 13 +- drivers/usb/gadget/function/Makefile | 3 +- drivers/usb/gadget/function/f_uac1.c | 842 +++++++++++++--------------------- drivers/usb/gadget/function/f_uac2.c | 778 ++++--------------------------- drivers/usb/gadget/function/u_audio.c | 632 +++++++++++++++++++++++++ drivers/usb/gadget/function/u_audio.h | 93 ++++ drivers/usb/gadget/function/u_uac1.c | 314 ------------- drivers/usb/gadget/function/u_uac1.h | 71 +-- drivers/usb/gadget/legacy/Kconfig | 1 + drivers/usb/gadget/legacy/audio.c | 54 ++- 10 files changed, 1208 insertions(+), 1593 deletions(-) create mode 100644 drivers/usb/gadget/function/u_audio.c create mode 100644 drivers/usb/gadget/function/u_audio.h delete mode 100644 drivers/usb/gadget/function/u_uac1.c
Signature · 1 line
1.9.1
RFC PATCH 1/5 usb: gadget: f_uac2: remove platform driver/device creation
Simplify f_uac2 by removing platform driver/device creation; use composite's usb_gadget device as parent for sound card and for debug prints. This removes extra layer of code without any functional change.
--- drivers/usb/gadget/function/f_uac2.c | 107 +++++++++-------------------------- 1 file changed, 28 insertions(+), 79 deletions(-)
drivers/usb/gadget/function/f_uac2.c +28 -79
@@ -13,7 +13,6 @@#include <linux/usb/audio.h> #include <linux/usb/audio-v2.h> -#include <linux/platform_device.h> #include <linux/module.h> #include <sound/core.h>
@@ -54,8 +53,6 @@#define UNFLW_CTRL 8#define OVFLW_CTRL 10 -static const char *uac2_name ="snd_uac2" ; -struct uac2_req {struct uac2_rtd_params *pp;/* parent param */ struct usb_request *req;
@@ -84,9 +81,6 @@ struct uac2_rtd_params { };struct snd_uac2_chip { -struct platform_device pdev; -struct platform_driver pdrv; -struct uac2_rtd_params p_prm;struct uac2_rtd_params c_prm;
@@ -125,6 +119,7 @@ struct audio_dev {struct usb_ep *in_ep, *out_ep;struct usb_function func; +struct usb_gadget *gadget;/* The ALSA Sound Card it represents on the USB-Client side */ struct snd_uac2_chip uac2;
@@ -143,12 +138,6 @@ struct audio_dev *uac2_to_agdev(struct snd_uac2_chip *u) }static inline -struct snd_uac2_chip *pdev_to_uac2 (struct platform_device *p) -{ - return container_of(p, struct snd_uac2_chip, pdev); -} - -static inline struct f_uac2_opts *agdev_to_uac2_opts (struct audio_dev *agdev) { return container_of(agdev->func.fi, struct f_uac2_opts, func_inst);
@@ -257,7 +246,7 @@ agdev_iso_complete(struct usb_ep *ep, struct usb_request *req) exit:if (usb_ep_queue (ep, req,GFP_ATOMIC )) -dev_err (&uac2->pdev.dev,"%d Error!\n" , __LINE__); +dev_err (uac2->card->dev,"%d Error!\n" , __LINE__);if (update_alsa)snd_pcm_period_elapsed (substream);
@@ -441,23 +430,22 @@ static struct snd_pcm_ops uac2_pcm_ops = { .prepare = uac2_pcm_null, }; -static int snd_uac2_probe (struct platform_device *pdev) +static int snd_uac2_probe (struct audio_dev *audio_dev) { -struct snd_uac2_chip *uac2 =pdev_to_uac2 (pdev); +struct snd_uac2_chip *uac2 = &audio_dev->uac2;struct snd_card *card;struct snd_pcm *pcm; -struct audio_dev *audio_dev;struct f_uac2_opts *opts;int err;int p_chmask, c_chmask; - audio_dev =uac2_to_agdev (uac2); opts = container_of(audio_dev->func.fi, struct f_uac2_opts, func_inst); p_chmask = opts->p_chmask; c_chmask = opts->c_chmask;/* Choose any slot, with no id */ - err =snd_card_new (&pdev->dev,-1 ,NULL ,THIS_MODULE ,0 , &card); + err =snd_card_new (&audio_dev->gadget->dev, +-1 ,NULL ,THIS_MODULE ,0 , &card);if (err <0 )return err;
@@ -482,16 +470,15 @@ static int snd_uac2_probe(struct platform_device *pdev)strcpy (card->driver,"UAC2_Gadget" );strcpy (card->shortname,"UAC2_Gadget" ); -sprintf (card->longname,"UAC2_Gadget %i" , pdev->id); +sprintf (card->longname,"UAC2_Gadget %i" , card->dev->id);snd_pcm_lib_preallocate_pages_for_all (pcm,SNDRV_DMA_TYPE_CONTINUOUS ,snd_dma_continuous_data (GFP_KERNEL ),0 ,BUFF_SIZE_MAX ); err =snd_card_register (card); -if (!err) { -platform_set_drvdata (pdev, card); + +if (!err)return 0 ; - } snd_fail:snd_card_free (card);
@@ -502,9 +489,9 @@ snd_fail:return err; } -static int snd_uac2_remove (struct platform_device *pdev) +static int snd_uac2_remove (struct audio_dev *audio_dev) { -struct snd_card *card =platform_get_drvdata (pdev); +struct snd_card *card = audio_dev->uac2.card;if (card)return snd_card_free (card);
@@ -512,45 +499,6 @@ static int snd_uac2_remove(struct platform_device *pdev)return 0 ; } -static void snd_uac2_release (struct device *dev) -{ -dev_dbg (dev,"releasing '%s'\n" ,dev_name (dev)); -} - -static int alsa_uac2_init (struct audio_dev *agdev) -{ -struct snd_uac2_chip *uac2 = &agdev->uac2; -int err; - - uac2->pdrv.probe = snd_uac2_probe; - uac2->pdrv.remove = snd_uac2_remove; - uac2->pdrv.driver.name = uac2_name; - - uac2->pdev.id =0 ; - uac2->pdev.name = uac2_name; - uac2->pdev.dev.release = snd_uac2_release; - -/* Register snd_uac2 driver */ - err =platform_driver_register (&uac2->pdrv); -if (err) -return err; - -/* Register snd_uac2 device */ - err =platform_device_register (&uac2->pdev); -if (err) -platform_driver_unregister (&uac2->pdrv); - -return err; -} - -static void alsa_uac2_exit (struct audio_dev *agdev) -{ -struct snd_uac2_chip *uac2 = &agdev->uac2; - -platform_driver_unregister (&uac2->pdrv); -platform_device_unregister (&uac2->pdev); -} -/* --------- USB Function Interface ------------- */
@@ -971,7 +919,7 @@ free_ep(struct uac2_rtd_params *prm, struct usb_ep *ep) }if (usb_ep_disable (ep)) -dev_err (&uac2->pdev.dev, +dev_err (uac2->card->dev,"%s:%d Error!\n" , __func__, __LINE__); }
@@ -1005,7 +953,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)struct snd_uac2_chip *uac2 = &agdev->uac2;struct usb_composite_dev *cdev = cfg->cdev;struct usb_gadget *gadget = cdev->gadget; -struct device *dev = &uac2->pdev.dev; +struct device *dev = &gadget->dev;struct uac2_rtd_params *prm;struct f_uac2_opts *uac2_opts;struct usb_string *us;
@@ -1076,6 +1024,8 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) agdev->as_in_intf = ret; agdev->as_in_alt =0 ; + agdev->gadget = gadget; + agdev->out_ep =usb_ep_autoconfig (gadget, &fs_epout_desc);if (!agdev->out_ep) {dev_err (dev,"%s:%d Error!\n" , __func__, __LINE__);
@@ -1121,7 +1071,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) goto err_free_descs; } - ret =alsa_uac2_init (agdev); + ret =snd_uac2_probe (agdev);if (ret) goto err_free_descs;return 0 ;
@@ -1131,6 +1081,7 @@ err_free_descs: err:kfree (agdev->uac2.p_prm.rbuf);kfree (agdev->uac2.c_prm.rbuf); + agdev->gadget =NULL ;return -EINVAL ; }
@@ -1141,7 +1092,7 @@ afunc_set_alt(struct usb_function *fn, unsigned intf, unsigned alt)struct audio_dev *agdev =func_to_agdev (fn);struct snd_uac2_chip *uac2 = &agdev->uac2;struct usb_gadget *gadget = cdev->gadget; -struct device *dev = &uac2->pdev.dev; +struct device *dev = &gadget->dev;struct usb_request *req;struct usb_ep *ep;struct uac2_rtd_params *prm;
@@ -1242,7 +1193,6 @@ static int afunc_get_alt(struct usb_function *fn, unsigned intf) {struct audio_dev *agdev =func_to_agdev (fn); -struct snd_uac2_chip *uac2 = &agdev->uac2;if (intf == agdev->ac_intf)return agdev->ac_alt;
@@ -1251,7 +1201,7 @@ afunc_get_alt(struct usb_function *fn, unsigned intf)else if (intf == agdev->as_in_intf)return agdev->as_in_alt;else -dev_err (&uac2->pdev.dev, +dev_err (&agdev->gadget->dev,"%s:%d Invalid Interface %d!\n" , __func__, __LINE__, intf);
@@ -1276,7 +1226,6 @@ in_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr) {struct usb_request *req = fn->config->cdev->req;struct audio_dev *agdev =func_to_agdev (fn); -struct snd_uac2_chip *uac2 = &agdev->uac2;struct f_uac2_opts *opts;u16 w_length =le16_to_cpu (cr->wLength);u16 w_index =le16_to_cpu (cr->wIndex);
@@ -1304,7 +1253,7 @@ in_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr) *(u8 *)req->buf =1 ; value =min_t (unsigned, w_length,1 ); }else { -dev_err (&uac2->pdev.dev, +dev_err (&agdev->gadget->dev,"%s:%d control_selector=%d TODO!\n" , __func__, __LINE__, control_selector); }
@@ -1317,7 +1266,6 @@ in_rq_range(struct usb_function *fn, const struct usb_ctrlrequest *cr) {struct usb_request *req = fn->config->cdev->req;struct audio_dev *agdev =func_to_agdev (fn); -struct snd_uac2_chip *uac2 = &agdev->uac2;struct f_uac2_opts *opts;u16 w_length =le16_to_cpu (cr->wLength);u16 w_index =le16_to_cpu (cr->wIndex);
@@ -1347,7 +1295,7 @@ in_rq_range(struct usb_function *fn, const struct usb_ctrlrequest *cr) value =min_t (unsigned, w_length,sizeof r);memcpy (req->buf, &r, value); }else { -dev_err (&uac2->pdev.dev, +dev_err (&agdev->gadget->dev,"%s:%d control_selector=%d TODO!\n" , __func__, __LINE__, control_selector); }
@@ -1383,12 +1331,11 @@ static int setup_rq_inf(struct usb_function *fn, const struct usb_ctrlrequest *cr) { struct audio_dev *agdev = func_to_agdev(fn); -struct snd_uac2_chip *uac2 = &agdev->uac2;u16 w_index =le16_to_cpu (cr->wIndex);u8 intf = w_index &0xff ;if (intf != agdev->ac_intf) { -dev_err (&uac2->pdev.dev, +dev_err (&agdev->gadget->dev,"%s:%d Error!\n" , __func__, __LINE__);return -EOPNOTSUPP ; }
@@ -1406,7 +1353,6 @@ afunc_setup(struct usb_function *fn, const struct usb_ctrlrequest *cr) {struct usb_composite_dev *cdev = fn->config->cdev;struct audio_dev *agdev =func_to_agdev (fn); -struct snd_uac2_chip *uac2 = &agdev->uac2;struct usb_request *req = cdev->req;u16 w_length =le16_to_cpu (cr->wLength);int value = -EOPNOTSUPP ;
@@ -1418,14 +1364,15 @@ afunc_setup(struct usb_function *fn, const struct usb_ctrlrequest *cr)if ((cr->bRequestType &USB_RECIP_MASK ) ==USB_RECIP_INTERFACE ) value =setup_rq_inf (fn, cr);else -dev_err (&uac2->pdev.dev,"%s:%d Error!\n" , __func__, __LINE__); +dev_err (&agdev->gadget->dev,"%s:%d Error!\n" , + __func__, __LINE__);if (value >=0 ) { req->length = value; req->zero = value < w_length; value =usb_ep_queue (cdev->gadget->ep0, req,GFP_ATOMIC );if (value <0 ) { -dev_err (&uac2->pdev.dev, +dev_err (&agdev->gadget->dev,"%s:%d Error!\n" , __func__, __LINE__); req->status =0 ; }
@@ -1564,7 +1511,7 @@ static void afunc_unbind(struct usb_configuration *c, struct usb_function *f)struct audio_dev *agdev =func_to_agdev (f);struct uac2_rtd_params *prm; -alsa_uac2_exit (agdev); +snd_uac2_remove (agdev); prm = &agdev->uac2.p_prm;kfree (prm->rbuf);
@@ -1572,6 +1519,8 @@ static void afunc_unbind(struct usb_configuration *c, struct usb_function *f) prm = &agdev->uac2.c_prm;kfree (prm->rbuf);usb_free_all_descriptors (f); + + agdev->gadget =NULL ; }static struct usb_function *afunc_alloc (struct usb_function_instance *fi)
Signature · 1 line
1.9.1
RFC PATCH 2/5 usb: gadget: f_uac2: split out audio core
In reply to Ruslan BilovolAbstract the peripheral side ALSA sound card code from the f_uac2 function into a component that can be called by various functions, so the various flavors can be split apart and selectively reused.
Visible changes:
- add uac_params structure to pass audio paramteres for gaudio_setup
- make ALSA sound card's name configurable
- add [in/out]_ep_maxpsize
- allocate snd_uac_chip structure during gaudio_setup
- add gaudio_[start/stop]_[capture/playback] functions
--- drivers/usb/gadget/Kconfig | 4 + drivers/usb/gadget/function/Makefile | 1 + drivers/usb/gadget/function/f_uac2.c | 699 ++++------------------------------ drivers/usb/gadget/function/u_audio.c | 632 ++++++++++++++++++++++++++++++ drivers/usb/gadget/function/u_audio.h | 93 +++++ drivers/usb/gadget/legacy/Kconfig | 1 + 6 files changed, 813 insertions(+), 617 deletions(-) create mode 100644 drivers/usb/gadget/function/u_audio.c create mode 100644 drivers/usb/gadget/function/u_audio.h
drivers/usb/gadget/Kconfig +4 -0
@@ -157,6 +157,9 @@ config USB_U_SERIAL config USB_U_ETHER tristate +config USB_U_AUDIO + tristate + config USB_F_SERIAL tristate
@@ -399,6 +402,7 @@ config USB_CONFIGFS_F_UAC2 depends on SND select USB_LIBCOMPOSITE select SND_PCM + select USB_U_AUDIO select USB_F_UAC2 help This Audio function is compatible with USB Audio Class
drivers/usb/gadget/function/Makefile +1 -0
@@ -32,6 +32,7 @@ usb_f_mass_storage-y := f_mass_storage.o storage_common.o obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o usb_f_fs-y := f_fs.o obj-$(CONFIG_USB_F_FS) += usb_f_fs.o +obj-$(CONFIG_USB_U_AUDIO) += u_audio.o usb_f_uac1-y := f_uac1.o u_uac1.o obj-$(CONFIG_USB_F_UAC1) += usb_f_uac1.o usb_f_uac2-y := f_uac2.o
drivers/usb/gadget/function/f_uac2.c +82 -617
892 lines not on this page · raw message
drivers/usb/gadget/function/u_audio.c new file +632 -0
632 lines not on this page · raw message
drivers/usb/gadget/function/u_audio.h new file +93 -0
93 lines not on this page · raw message
drivers/usb/gadget/legacy/Kconfig +1 -0
@@ -56,6 +56,7 @@ config USB_AUDIO select SND_PCM select USB_F_UAC1 if GADGET_UAC1 select USB_F_UAC2 if !GADGET_UAC1 + select USB_U_AUDIO if USB_F_UAC2 help This Gadget Audio driver is compatible with USB Audio Class specification 2.0. It implements 1 AudioControl interface,
Signature · 1 line
1.9.1
RFC PATCH 3/5 usb: gadget: f_uac1: drop volume/mute functionality
In reply to Ruslan BilovolThe volume/mute feature unit was dummy implementation since this driver creation (2009) and never had real volume control or mute functionality. Since it was never implemented, drop it and increase maintainability of the driver.
Those who want real volume/mute support may revert this patch and add needed handlers
--- drivers/usb/gadget/function/f_uac1.c | 182 +---------------------------------- 1 file changed, 5 insertions(+), 177 deletions(-)
drivers/usb/gadget/function/f_uac1.c +5 -177
@@ -17,9 +17,6 @@#include "u_uac1.h" -static int generic_set_cmd (struct usb_audio_control *con,u8 cmd,int value); -static int generic_get_cmd (struct usb_audio_control *con,u8 cmd); -/* * DESCRIPTORS ... most are static, but strings and full * configuration descriptors are built on demand.
@@ -49,9 +46,9 @@ static struct usb_interface_descriptor ac_interface_desc = {DECLARE_UAC_AC_HEADER_DESCRIPTOR (1 );#define UAC_DT_AC_HEADER_LENGTH UAC_DT_AC_HEADER_SIZE(F_AUDIO_NUM_INTERFACES) -/* 1 input terminal, 1 output terminal and 1 feature unit */ +/* 1 input terminal and 1 output terminal */ #define UAC_DT_TOTAL_LENGTH (UAC_DT_AC_HEADER_LENGTH + UAC_DT_INPUT_TERMINAL_SIZE \ - + UAC_DT_OUTPUT_TERMINAL_SIZE + UAC_DT_FEATURE_UNIT_SIZE(0)) + + UAC_DT_OUTPUT_TERMINAL_SIZE)/* B.3.2 Class-Specific AC Interface Descriptor */ static struct uac1_ac_header_descriptor_1 ac_header_desc = { .bLength =UAC_DT_AC_HEADER_LENGTH ,
@@ -77,54 +74,15 @@ static struct uac_input_terminal_descriptor input_terminal_desc = { .wChannelConfig = 0x3, }; -DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR (0 ); - -#define FEATURE_UNIT_ID 2 -static struct uac_feature_unit_descriptor_0 feature_unit_desc = { - .bLength =UAC_DT_FEATURE_UNIT_SIZE (0 ), - .bDescriptorType =USB_DT_CS_INTERFACE , - .bDescriptorSubtype =UAC_FEATURE_UNIT , - .bUnitID =FEATURE_UNIT_ID , - .bSourceID =INPUT_TERMINAL_ID , - .bControlSize =2 , - .bmaControls[0 ] = (UAC_FU_MUTE |UAC_FU_VOLUME ), -}; - -static struct usb_audio_control mute_control = { - .list =LIST_HEAD_INIT (mute_control.list), - .name ="Mute Control" , - .type =UAC_FU_MUTE , -/* Todo: add real Mute control code */ - .set = generic_set_cmd, - .get = generic_get_cmd, -}; - -static struct usb_audio_control volume_control = { - .list =LIST_HEAD_INIT (volume_control.list), - .name ="Volume Control" , - .type =UAC_FU_VOLUME , -/* Todo: add real Volume control code */ - .set = generic_set_cmd, - .get = generic_get_cmd, -}; - -static struct usb_audio_control_selector feature_unit = { - .list =LIST_HEAD_INIT (feature_unit.list), - .id =FEATURE_UNIT_ID , - .name ="Mute & Volume Control" , - .type =UAC_FEATURE_UNIT , - .desc = (struct usb_descriptor_header *)&feature_unit_desc, -}; - -#define OUTPUT_TERMINAL_ID 3 +#define OUTPUT_TERMINAL_ID 2static struct uac1_output_terminal_descriptor output_terminal_desc = { .bLength =UAC_DT_OUTPUT_TERMINAL_SIZE , .bDescriptorType =USB_DT_CS_INTERFACE , .bDescriptorSubtype =UAC_OUTPUT_TERMINAL , .bTerminalID =OUTPUT_TERMINAL_ID , .wTerminalType =UAC_OUTPUT_TERMINAL_SPEAKER , - .bAssocTerminal =FEATURE_UNIT_ID , - .bSourceID =FEATURE_UNIT_ID , + .bAssocTerminal =0 , + .bSourceID =INPUT_TERMINAL_ID , };/* B.4.1 Standard AS Interface Descriptor */
@@ -195,7 +153,6 @@ static struct usb_descriptor_header *f_audio_desc[] = { (struct usb_descriptor_header *)&input_terminal_desc, (struct usb_descriptor_header *)&output_terminal_desc, - (struct usb_descriptor_header *)&feature_unit_desc, (struct usb_descriptor_header *)&as_interface_alt_0_desc, (struct usb_descriptor_header *)&as_interface_alt_1_desc,
@@ -212,7 +169,6 @@ enum {STR_AC_IF ,STR_INPUT_TERMINAL ,STR_INPUT_TERMINAL_CH_NAMES , -STR_FEAT_DESC_0 ,STR_OUTPUT_TERMINAL ,STR_AS_IF_ALT0 , STR_AS_IF_ALT1,
@@ -222,7 +178,6 @@ static struct usb_string strings_uac1[] = { [STR_AC_IF].s = "AC Interface", [STR_INPUT_TERMINAL].s = "Input terminal", [STR_INPUT_TERMINAL_CH_NAMES].s = "Channels", - [STR_FEAT_DESC_0].s = "Volume control & mute", [STR_OUTPUT_TERMINAL].s = "Output terminal", [STR_AS_IF_ALT0].s = "AS Interface", [STR_AS_IF_ALT1].s = "AS Interface",
@@ -284,11 +239,6 @@ struct f_audio {struct f_audio_buf *copy_buf;struct work_struct playback_work;struct list_head play_queue; - -/* Control Set command */ -struct list_head cs; -u8 set_cmd; -struct usb_audio_control *set_con; };static inline struct f_audio *func_to_audio (struct usb_function *f)
@@ -359,7 +309,6 @@ static void f_audio_complete(struct usb_ep *ep, struct usb_request *req) {struct f_audio *audio = req->context;int status = req->status; -u32 data =0 ;struct usb_ep *out_ep = audio->out_ep;switch (status) {
@@ -367,92 +316,12 @@ static void f_audio_complete(struct usb_ep *ep, struct usb_request *req)case 0 :/* normal completion? */ if (ep == out_ep)f_audio_out_ep_complete (ep, req); -else if (audio->set_con) { -memcpy (&data, req->buf, req->length); - audio->set_con->set (audio->set_con, audio->set_cmd, -le16_to_cpu (data)); - audio->set_con =NULL ; - }break ;default :break ; } } -static int audio_set_intf_req (struct usb_function *f, -const struct usb_ctrlrequest *ctrl) -{ -struct f_audio *audio =func_to_audio (f); -struct usb_composite_dev *cdev = f->config->cdev; -struct usb_request *req = cdev->req; -u8 id = ((le16_to_cpu (ctrl->wIndex) >>8 ) &0xFF ); -u16 len =le16_to_cpu (ctrl->wLength); -u16 w_value =le16_to_cpu (ctrl->wValue); -u8 con_sel = (w_value >>8 ) &0xFF ; -u8 cmd = (ctrl->bRequest &0x0F ); -struct usb_audio_control_selector *cs; -struct usb_audio_control *con; - -DBG (cdev,"bRequest 0x%x, w_value 0x%04x, len %d, entity %d\n" , - ctrl->bRequest, w_value, len, id); - -list_for_each_entry (cs, &audio->cs, list) { -if (cs->id == id) { -list_for_each_entry (con, &cs->control, list) { -if (con->type == con_sel) { - audio->set_con = con; -break ; - } - } -break ; - } - } - - audio->set_cmd = cmd; - req->context = audio; - req->complete = f_audio_complete; - -return len; -} - -static int audio_get_intf_req (struct usb_function *f, -const struct usb_ctrlrequest *ctrl) -{ -struct f_audio *audio =func_to_audio (f); -struct usb_composite_dev *cdev = f->config->cdev; -struct usb_request *req = cdev->req; -int value = -EOPNOTSUPP ; -u8 id = ((le16_to_cpu (ctrl->wIndex) >>8 ) &0xFF ); -u16 len =le16_to_cpu (ctrl->wLength); -u16 w_value =le16_to_cpu (ctrl->wValue); -u8 con_sel = (w_value >>8 ) &0xFF ; -u8 cmd = (ctrl->bRequest &0x0F ); -struct usb_audio_control_selector *cs; -struct usb_audio_control *con; - -DBG (cdev,"bRequest 0x%x, w_value 0x%04x, len %d, entity %d\n" , - ctrl->bRequest, w_value, len, id); - -list_for_each_entry (cs, &audio->cs, list) { -if (cs->id == id) { -list_for_each_entry (con, &cs->control, list) { -if (con->type == con_sel && con->get) { - value = con->get (con, cmd); -break ; - } - } -break ; - } - } - - req->context = audio; - req->complete = f_audio_complete; - len =min_t (size_t,sizeof (value), len); -memcpy (req->buf, &value, len); - -return len; -} -static int audio_set_endpoint_req (struct usb_function *f,const struct usb_ctrlrequest *ctrl) {
@@ -531,14 +400,6 @@ f_audio_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)* activation uses set_alt(). */ switch (ctrl->bRequestType) { -case USB_DIR_OUT |USB_TYPE_CLASS |USB_RECIP_INTERFACE : - value =audio_set_intf_req (f, ctrl); -break ; - -case USB_DIR_IN |USB_TYPE_CLASS |USB_RECIP_INTERFACE : - value =audio_get_intf_req (f, ctrl); -break ; -case USB_DIR_OUT |USB_TYPE_CLASS |USB_RECIP_ENDPOINT : value =audio_set_endpoint_req (f, ctrl);break ;
@@ -689,7 +550,6 @@ f_audio_bind(struct usb_configuration *c, struct usb_function *f) ac_interface_desc.iInterface = us[STR_AC_IF ].id; input_terminal_desc.iTerminal = us[STR_INPUT_TERMINAL ].id; input_terminal_desc.iChannelNames = us[STR_INPUT_TERMINAL_CH_NAMES ].id; - feature_unit_desc.iFeature = us[STR_FEAT_DESC_0 ].id; output_terminal_desc.iTerminal = us[STR_OUTPUT_TERMINAL ].id; as_interface_alt_0_desc.iInterface = us[STR_AS_IF_ALT0 ].id; as_interface_alt_1_desc.iInterface = us[STR_AS_IF_ALT1 ].id;
@@ -734,36 +594,6 @@ fail:/*-------------------------------------------------------------------------*/ -static int generic_set_cmd (struct usb_audio_control *con,u8 cmd,int value) -{ - con->data[cmd] = value; - -return 0 ; -} - -static int generic_get_cmd (struct usb_audio_control *con,u8 cmd) -{ -return con->data[cmd]; -} - -/* Todo: add more control selecotor dynamically */ -static int control_selector_init (struct f_audio *audio) -{ -INIT_LIST_HEAD (&audio->cs); -list_add (&feature_unit.list, &audio->cs); - -INIT_LIST_HEAD (&feature_unit.control); -list_add (&mute_control.list, &feature_unit.control); -list_add (&volume_control.list, &feature_unit.control); - - volume_control.data[UAC__CUR ] =0xffc0 ; - volume_control.data[UAC__MIN ] =0xe3a0 ; - volume_control.data[UAC__MAX ] =0xfff0 ; - volume_control.data[UAC__RES ] =0x0030 ; - -return 0 ; -} -static inline struct f_uac1_opts *to_f_uac1_opts (struct config_item *item) { return container_of(to_config_group(item), struct f_uac1_opts,
@@ -970,8 +800,6 @@ static struct usb_function *f_audio_alloc(struct usb_function_instance *fi) audio->card.func.disable = f_audio_disable; audio->card.func.free_func = f_audio_free; -control_selector_init (audio); -INIT_WORK (&audio->playback_work, f_audio_playback_work);return &audio->card.func;
Signature · 1 line
1.9.1
RFC PATCH 4/5 usb: gadget: f_uac1: switch to u_audio core utilities
In reply to Ruslan BilovolReuse existing u_audio core utilities making f_uac1 much simpler.
This also drops previous f_uac1 approach (write audio samples directly to existing ALSA sound card) and moves to more generic/flexible one - create an f_uac1 ALSA sound card that represents USB Audio function and allows to be used by userspace tools.
As a side effect, using u_audio it will be much
easier to create gadget -> PC Host audio stream
in the future
--- drivers/usb/gadget/Kconfig | 8 +- drivers/usb/gadget/function/Makefile | 2 +- drivers/usb/gadget/function/f_uac1.c | 431 +++++++++++------------------------ drivers/usb/gadget/function/u_uac1.c | 314 ------------------------- drivers/usb/gadget/function/u_uac1.h | 65 +----- drivers/usb/gadget/legacy/Kconfig | 2 +- drivers/usb/gadget/legacy/audio.c | 42 ++-- 7 files changed, 162 insertions(+), 702 deletions(-) delete mode 100644 drivers/usb/gadget/function/u_uac1.c
drivers/usb/gadget/Kconfig +6 -2
@@ -389,12 +389,16 @@ config USB_CONFIGFS_F_UAC1 depends on SND select USB_LIBCOMPOSITE select SND_PCM + select USB_U_AUDIO select USB_F_UAC1 help This Audio function implements 1 AudioControl interface, 1 AudioStreaming Interface each for USB-OUT and USB-IN. - This driver requires a real Audio codec to be present - on the device. + This driver doesn't expect any real Audio codec to be present + on the device - the audio streams are simply sinked to + a virtual ALSA sound card created. The user-space + application may choose to do whatever it wants with the data + received from the USB Host. config USB_CONFIGFS_F_UAC2 bool "Audio Class 2.0"
drivers/usb/gadget/function/Makefile +1 -1
@@ -33,7 +33,7 @@ obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o usb_f_fs-y := f_fs.o obj-$(CONFIG_USB_F_FS) += usb_f_fs.o obj-$(CONFIG_USB_U_AUDIO) += u_audio.o -usb_f_uac1-y := f_uac1.o u_uac1.o +usb_f_uac1-y := f_uac1.o obj-$(CONFIG_USB_F_UAC1) += usb_f_uac1.o usb_f_uac2-y := f_uac2.o obj-$(CONFIG_USB_F_UAC2) += usb_f_uac2.o
drivers/usb/gadget/function/f_uac1.c +129 -302
572 lines not on this page · raw message
drivers/usb/gadget/function/u_uac1.c deleted +0 -314
314 lines not on this page · raw message
drivers/usb/gadget/function/u_uac1.h +10 -55
84 lines not on this page · raw message
drivers/usb/gadget/legacy/Kconfig +1 -1
@@ -56,7 +56,7 @@ config USB_AUDIO select SND_PCM select USB_F_UAC1 if GADGET_UAC1 select USB_F_UAC2 if !GADGET_UAC1 - select USB_U_AUDIO if USB_F_UAC2 + select USB_U_AUDIO help This Gadget Audio driver is compatible with USB Audio Class specification 2.0. It implements 1 AudioControl interface,
drivers/usb/gadget/legacy/audio.c +15 -27
56 lines not on this page · raw message
Signature · 1 line
1.9.1
RFC PATCH 5/5 usb: gadget: f_uac1: add capture support
In reply to Ruslan BilovolAdd capture support (gadget->host) to the f_uac1 driver. This requires renaming of some descriptors, enums etc that were used exclusively for playback path. To make it meaningful, f_uac2 driver naming convention has been used.
By default, capture interface has 48000kHz/2ch configuration, same as playback channel has.
--- drivers/usb/gadget/Kconfig | 7 +- drivers/usb/gadget/function/f_uac1.c | 265 ++++++++++++++++++++++++++++------- drivers/usb/gadget/function/u_uac1.h | 6 + drivers/usb/gadget/legacy/audio.c | 18 +++ 4 files changed, 239 insertions(+), 57 deletions(-)
drivers/usb/gadget/Kconfig +4 -3
@@ -395,10 +395,11 @@ config USB_CONFIGFS_F_UAC1 This Audio function implements 1 AudioControl interface, 1 AudioStreaming Interface each for USB-OUT and USB-IN. This driver doesn't expect any real Audio codec to be present - on the device - the audio streams are simply sinked to - a virtual ALSA sound card created. The user-space + on the device - the audio streams are simply sinked to and + sourced from a virtual ALSA sound card created. The user-space application may choose to do whatever it wants with the data - received from the USB Host. + received from the USB Host and choose to provide whatever it + wants as audio data to the USB Host. config USB_CONFIGFS_F_UAC2 bool "Audio Class 2.0"
drivers/usb/gadget/function/f_uac1.c +211 -54
428 lines not on this page · raw message
drivers/usb/gadget/function/u_uac1.h +6 -0
@@ -21,6 +21,9 @@#define UAC1_DEF_CCHMASK 0x3#define UAC1_DEF_CSRATE 48000#define UAC1_DEF_CSSIZE 2 +#define UAC1_DEF_PCHMASK 0x3 +#define UAC1_DEF_PSRATE 48000 +#define UAC1_DEF_PSSIZE 2struct f_uac1_opts {
@@ -28,6 +31,9 @@ struct f_uac1_opts {int c_chmask;int c_srate;int c_ssize; +int p_chmask; +int p_srate; +int p_ssize; unsigned bound:1;struct mutex lock;
drivers/usb/gadget/legacy/audio.c +18 -0
@@ -55,6 +55,21 @@ MODULE_PARM_DESC(c_ssize, "Capture Sample Size(bytes)");#else #include "u_uac1.h" +/* Playback(USB-IN) Default Stereo - Fl/Fr */ +static int p_chmask =UAC1_DEF_PCHMASK ; +module_param (p_chmask, uint,S_IRUGO ); +MODULE_PARM_DESC (p_chmask,"Playback Channel Mask" ); + +/* Playback Default 48 KHz */ +static int p_srate =UAC1_DEF_PSRATE ; +module_param (p_srate, uint,S_IRUGO ); +MODULE_PARM_DESC (p_srate,"Playback Sampling Rate" ); + +/* Playback Default 16bits/sample */ +static int p_ssize =UAC1_DEF_PSSIZE ; +module_param (p_ssize, uint,S_IRUGO ); +MODULE_PARM_DESC (p_ssize,"Playback Sample Size(bytes)" ); +/* Capture(USB-OUT) Default Stereo - Fl/Fr */ static int c_chmask =UAC1_DEF_CCHMASK ;module_param (c_chmask, uint,S_IRUGO );
@@ -222,6 +237,9 @@ static int audio_bind(struct usb_composite_dev *cdev) uac2_opts->c_ssize = c_ssize;#else uac1_opts = container_of(fi_uac1, struct f_uac1_opts, func_inst); + uac1_opts->p_chmask = p_chmask; + uac1_opts->p_srate = p_srate; + uac1_opts->p_ssize = p_ssize; uac1_opts->c_chmask = c_chmask; uac1_opts->c_srate = c_srate; uac1_opts->c_ssize = c_ssize;
Signature · 1 line
1.9.1
Hi guys,
Any feedback on this patch series? Has anybody had a chance to test it?
Regards,
Ruslan
Quoted 72 lines · Ruslan Bilovol
I came to this patch series when wanted to do two things:
- use UAC1 as virtual ALSA sound card on gadget side, just like UAC2 is used so it's possible to do rate resampling
- have both playback/capture support in UAC1Since I wanted to have same behavior for both UAC1/UAC2, obviously I've got an utility part (
u_audio.c) for virtual ALSA sound card handling like we have forethernet(u_ether)orserial(u_serial)functions. Function-specific parts (f_uac1/f_uac2) became almost as storage for class-specfic USB descriptors, some boilerplate for configfs, binding and few USB config request handling.Major change to
f_uac1it that it can't do direct play to existing ALSA sound card anymore, representing audio on gadget side as virtual ALSA sound card where audio streams are simply sinked to and sourced from it, so it may break current usecase for some people (and that's why it's RFC).Luckily, it's possible to use existing user-space applications for audio routing between Audio Gadget and real sound card. I personally use alsaloop tool from alsautils and have ability to create PCM loopback between two different ALSA cards using rate resampling, which is not possible with previous "direct play to ALSA card" approach in
f_uac1.While here, also dropped redundant platform driver/device creation in
f_uac2driver as well as "never implemented" volume/mute functionality inf_uac1that made this work even easier to do.This series is tested with both legacy g_audio.ko and modern configfs approaches under Ubuntu 14.04 (UAC1 and UAC2) and under Windows7 x64 (UAC1 only) having perfect results in all cases.
Some changes may have lack of good description that may be obvious for me but not so clear for others, but I hope to fix it in next versions.
Comments, testing are welcome.
Ruslan Bilovol (5):
usb: gadget:f_uac2: remove platform driver/device creation
usb: gadget:f_uac2: split out audio core
usb: gadget:f_uac1: drop volume/mute functionality
usb: gadget:f_uac1: switch tou_audiocore utilities
usb: gadget:f_uac1: add capture supportdrivers/usb/gadget/Kconfig | 13 +- drivers/usb/gadget/function/Makefile | 3 +- drivers/usb/gadget/function/f_uac1.c | 842 +++++++++++++--------------------- drivers/usb/gadget/function/f_uac2.c | 778 ++++--------------------------- drivers/usb/gadget/function/u_audio.c | 632 +++++++++++++++++++++++++ drivers/usb/gadget/function/u_audio.h | 93 ++++ drivers/usb/gadget/function/u_uac1.c | 314 ------------- drivers/usb/gadget/function/u_uac1.h | 71 +-- drivers/usb/gadget/legacy/Kconfig | 1 + drivers/usb/gadget/legacy/audio.c | 54 ++- 10 files changed, 1208 insertions(+), 1593 deletions(-) create mode 100644 drivers/usb/gadget/function/u_audio.c create mode 100644 drivers/usb/gadget/function/u_audio.h delete mode 100644 drivers/usb/gadget/function/u_uac1.c--
1.9.1
Ping?
Quoted 81 lines · Ruslan Bilovol
Hi guys,
Any feedback on this patch series? Has anybody had a chance to test it?
Regards,
RuslanQuoted 72 lines · Ruslan Bilovol
I came to this patch series when wanted to do two things:
- use UAC1 as virtual ALSA sound card on gadget side, just like UAC2 is used so it's possible to do rate resampling
- have both playback/capture support in UAC1Since I wanted to have same behavior for both UAC1/UAC2, obviously I've got an utility part (
u_audio.c) for virtual ALSA sound card handling like we have forethernet(u_ether)orserial(u_serial)functions. Function-specific parts (f_uac1/f_uac2) became almost as storage for class-specfic USB descriptors, some boilerplate for configfs, binding and few USB config request handling.Major change to
f_uac1it that it can't do direct play to existing ALSA sound card anymore, representing audio on gadget side as virtual ALSA sound card where audio streams are simply sinked to and sourced from it, so it may break current usecase for some people (and that's why it's RFC).Luckily, it's possible to use existing user-space applications for audio routing between Audio Gadget and real sound card. I personally use alsaloop tool from alsautils and have ability to create PCM loopback between two different ALSA cards using rate resampling, which is not possible with previous "direct play to ALSA card" approach in
f_uac1.While here, also dropped redundant platform driver/device creation in
f_uac2driver as well as "never implemented" volume/mute functionality inf_uac1that made this work even easier to do.This series is tested with both legacy g_audio.ko and modern configfs approaches under Ubuntu 14.04 (UAC1 and UAC2) and under Windows7 x64 (UAC1 only) having perfect results in all cases.
Some changes may have lack of good description that may be obvious for me but not so clear for others, but I hope to fix it in next versions.
Comments, testing are welcome.
Ruslan Bilovol (5):
usb: gadget:f_uac2: remove platform driver/device creation
usb: gadget:f_uac2: split out audio core
usb: gadget:f_uac1: drop volume/mute functionality
usb: gadget:f_uac1: switch tou_audiocore utilities
usb: gadget:f_uac1: add capture supportdrivers/usb/gadget/Kconfig | 13 +- drivers/usb/gadget/function/Makefile | 3 +- drivers/usb/gadget/function/f_uac1.c | 842 +++++++++++++--------------------- drivers/usb/gadget/function/f_uac2.c | 778 ++++--------------------------- drivers/usb/gadget/function/u_audio.c | 632 +++++++++++++++++++++++++ drivers/usb/gadget/function/u_audio.h | 93 ++++ drivers/usb/gadget/function/u_uac1.c | 314 ------------- drivers/usb/gadget/function/u_uac1.h | 71 +-- drivers/usb/gadget/legacy/Kconfig | 1 + drivers/usb/gadget/legacy/audio.c | 54 ++- 10 files changed, 1208 insertions(+), 1593 deletions(-) create mode 100644 drivers/usb/gadget/function/u_audio.c create mode 100644 drivers/usb/gadget/function/u_audio.h delete mode 100644 drivers/usb/gadget/function/u_uac1.c--
1.9.1
Quoted 3 lines
Quoted 3 lines
Quoted 1 line · Ruslan Bilovol
it may break current usecase for some people
And what are the benefits that justify breaking the kernel API?
Regards,
Clemens
Quoted 5 lines · Clemens Ladisch
Quoted 3 lines
Quoted 3 lines
Quoted 1 line · Ruslan Bilovol
it may break current usecase for some people
And what are the benefits that justify breaking the kernel API?
Main limitation with current f_uac1 design is - it can be used only on systems with real ALSA card present and can have only exact number of channels / sampling rate as sink card has.
Yet it is not flexible - can't do audio processing between f_uac1 and the card. Also if someone wants to bind f_uac1 it to another sound card he has to unload g_audio or reconfigure it through configfs - that means USB reenumeration on host device.
If you have a "virtual sound card", audio processing is done in userspace and is more flexible. You even don't need to have a real sound card and can use some userspace application for playing/capturing audio samples. Moreover, existing f_uac2 (that is USB Audio Class 2.0 function implementation) already uses approach of "virtual sound card"
A real cases when it's required to have UAC1 gadget represented as virtual sound card on gadget side:
- android accessory f_audio_source.c implementation, android plays audio directly to UAC1 "virtual sound card"
- some 3G/LTE voice USB sticks with Linux as firmware have user-space application inside that receives audio from network and need to source/sink it to some sound card (UAC1)
- USB sound card with complex audio processing inside, made on small Linux-powered device ("sound-studio")
What's annoying is we have two quite similar USB Audio Classes implementations(f_uac1 and f_uac2) that have opposite audio
representations: first transfers audio samples directly to real ALSA card, second exposes virtual ALSA card. That means you have to implement similar things (capture/playback, etc) in different way. With new design both implementations provide same "API" (virtual sound card), allowing us to reuse a lot of code and implement new features much easier (look at adding of capture support to f_uac1 in PATCH 5/5 - that was very simple and consists almost from adding new USB descriptors and reusing existing code from newly created u_audio.c)
Also new USB Audio Gadget design follows existing approach for another USB Classes:
- serial gadgets use u_serial and expose virtual TTY port
- networking gadgets use u_ether and expose virtual network interface
- uvc gadget exposes virtual v4l device
- midi gadget exposes virtual sound card
- etc, etc
Of course disadvantage of new approach for UAC1 gadget is you need to use some userspace application for routing audio from virtual to real sound card, like in case of UAC2 gadget. But thanks to existing applications like alsaloop it's not difficult nowadays.
The answer I want to get in this RFC - can we drop current f_uac1 approach, simplify USB Audio Gadget by reusing common code.
Or "we do not break userspace" (or API) and have to live with it forever.
Best regards,
Ruslan
Quoted 5 lines · Ruslan Bilovol
Quoted 4 lines · Clemens Ladisch
Quoted 3 lines
Quoted 3 lines
Quoted 1 line · Ruslan Bilovol
it may break current usecase for some people
Quoted 7 lines
Quoted 1 line
And what are the benefits that justify breaking the kernel API?
Main limitation with current
f_uac1design is - it can be used only on systems with real ALSA card present and can have only exact number of channels / sampling rate as sink card has. [...]
A real cases when it's required to have UAC1 gadget represented as virtual sound card on gadget side: [...]
Thanks.
Quoted 4 lines
Of course disadvantage of new approach for UAC1 gadget is you need to use some userspace application for routing audio from virtual to real sound card, like in case of UAC2 gadget. But thanks to existing applications like alsaloop it's not difficult nowadays.
I don't know what the maintainer will say, but you would increase the chances of this change being accepted when you show a concrete example of how to change the userspace configuration from the old to the new driver. (And add it to the documentation.)
Regards,
Clemens
Quoted 21 lines · Clemens Ladisch
Quoted 5 lines · Ruslan Bilovol
Quoted 4 lines · Clemens Ladisch
Quoted 3 lines
Quoted 3 lines
Quoted 1 line · Ruslan Bilovol
it may break current usecase for some people
Quoted 7 lines
Quoted 1 line
And what are the benefits that justify breaking the kernel API?
Main limitation with current
f_uac1design is - it can be used only on systems with real ALSA card present and can have only exact number of channels / sampling rate as sink card has. [...]
A real cases when it's required to have UAC1 gadget represented as virtual sound card on gadget side: [...]Thanks.
Quoted 4 lines
Of course disadvantage of new approach for UAC1 gadget is you need to use some userspace application for routing audio from virtual to real sound card, like in case of UAC2 gadget. But thanks to existing applications like alsaloop it's not difficult nowadays.
Quoted 4 lines
I don't know what the maintainer will say, but you would increase the chances of this change being accepted when you show a concrete example of how to change the userspace configuration from the old to the new driver. (And add it to the documentation.)
Good point, need to update documentation in next files (make similar to UAC2):
Documentation/usb/gadget-testing.txt Documentation/ABI/testing/configfs-usb-gadget-uac1
Best regards,
Ruslan
Quoted 16 lines · Ruslan Bilovol
Quoted 5 lines · Clemens Ladisch
Quoted 3 lines
Quoted 3 lines
Quoted 1 line · Ruslan Bilovol
it may break current usecase for some people
And what are the benefits that justify breaking the kernel API?
Main limitation with current
f_uac1design is - it can be used only on systems with real ALSA card present and can have only exact number of channels / sampling rate as sink card has.
Yet it is not flexible - can't do audio processing betweenf_uac1and the card. Also if someone wants to bindf_uac1it to another sound card he has to unloadg_audioor reconfigure it through configfs - that means USB reenumeration on host device.
Quoted 6 lines
If you have a "virtual sound card", audio processing is done in userspace and is more flexible. You even don't need to have a real sound card and can use some userspace application for playing/capturing audio samples. Moreover, existing
f_uac2(that is USB Audio Class 2.0 function implementation) already uses approach of "virtual sound card"
While I agree the virtual sound card approach is the right way, I am not sure if we should break the userspace api that the existing UAC1 driver exposes. Maybe we should add another virtual-sound-card exposing UAC1 driver ... and hopefully very similar to (or just port of) the f_audio_source.c from android.
Quoted 24 lines · Jassi Brar
Quoted 16 lines · Ruslan Bilovol
Quoted 5 lines · Clemens Ladisch
Quoted 3 lines
Quoted 3 lines
Quoted 1 line · Ruslan Bilovol
it may break current usecase for some people
And what are the benefits that justify breaking the kernel API?
Main limitation with current
f_uac1design is - it can be used only on systems with real ALSA card present and can have only exact number of channels / sampling rate as sink card has.
Yet it is not flexible - can't do audio processing betweenf_uac1and the card. Also if someone wants to bindf_uac1it to another sound card he has to unloadg_audioor reconfigure it through configfs - that means USB reenumeration on host device.Quoted 6 lines
If you have a "virtual sound card", audio processing is done in userspace and is more flexible. You even don't need to have a real sound card and can use some userspace application for playing/capturing audio samples. Moreover, existing
f_uac2(that is USB Audio Class 2.0 function implementation) already uses approach of "virtual sound card"
Quoted 5 lines
While I agree the virtual sound card approach is the right way, I am not sure if we should break the userspace api that the existing UAC1 driver exposes. Maybe we should add another virtual-sound-card exposing UAC1 driver ... and hopefully very similar to (or just port of) the
f_audio_source.cfrom android.
Definitely agree with this opinion. I don't see any benefits of breaking the API here instead of adding just another USB function. Maybe even some pieces of code could be shared with f_uac1.c but I think that this should be a brand new function.
Best regards,
Signature · 3 lines
Krzysztof Opasiak Samsung R&D Institute Poland Samsung Electronics
Quoted 33 lines · Krzysztof Opasiak
Quoted 24 lines · Jassi Brar
Quoted 16 lines · Ruslan Bilovol
Quoted 5 lines · Clemens Ladisch
Quoted 3 lines
Quoted 3 lines
Quoted 1 line · Ruslan Bilovol
it may break current usecase for some people
And what are the benefits that justify breaking the kernel API?
Main limitation with current
f_uac1design is - it can be used only on systems with real ALSA card present and can have only exact number of channels / sampling rate as sink card has.
Yet it is not flexible - can't do audio processing betweenf_uac1and the card. Also if someone wants to bindf_uac1it to another sound card he has to unloadg_audioor reconfigure it through configfs - that means USB reenumeration on host device.Quoted 6 lines
If you have a "virtual sound card", audio processing is done in userspace and is more flexible. You even don't need to have a real sound card and can use some userspace application for playing/capturing audio samples. Moreover, existing
f_uac2(that is USB Audio Class 2.0 function implementation) already uses approach of "virtual sound card"Quoted 5 lines
While I agree the virtual sound card approach is the right way, I am not sure if we should break the userspace api that the existing UAC1 driver exposes. Maybe we should add another virtual-sound-card exposing UAC1 driver ... and hopefully very similar to (or just port of) the
f_audio_source.cfrom android.
Quoted 5 lines
Definitely agree with this opinion. I don't see any benefits of breaking the API here instead of adding just another USB function. Maybe even some pieces of code could be shared with
f_uac1.cbut I think that this should be a brand new function.
So if we want to keep old API working, easiest (and cleanest) way is to create a new f_uac1.c version and kconfig symbol, for example f_uac1_newapi.c and CONFIG_USB_F_UAC1_NEWAPI
There is no sence to share some pieces of code with f_uac1.c just because it is changed too drastically.
So I'll implement it in v2 if there is no any objections
Best regards,
Ruslan Bilovol
Quoted 24 lines · Jassi Brar
Quoted 16 lines · Ruslan Bilovol
Quoted 5 lines · Clemens Ladisch
Quoted 3 lines
Quoted 3 lines
Quoted 1 line · Ruslan Bilovol
it may break current usecase for some people
And what are the benefits that justify breaking the kernel API?
Main limitation with current
f_uac1design is - it can be used only on systems with real ALSA card present and can have only exact number of channels / sampling rate as sink card has.
Yet it is not flexible - can't do audio processing betweenf_uac1and the card. Also if someone wants to bindf_uac1it to another sound card he has to unloadg_audioor reconfigure it through configfs - that means USB reenumeration on host device.Quoted 6 lines
If you have a "virtual sound card", audio processing is done in userspace and is more flexible. You even don't need to have a real sound card and can use some userspace application for playing/capturing audio samples. Moreover, existing
f_uac2(that is USB Audio Class 2.0 function implementation) already uses approach of "virtual sound card"
Quoted 4 lines
While I agree the virtual sound card approach is the right way, I am not sure if we should break the userspace api that the existing UAC1 driver exposes. Maybe we should add another virtual-sound-card exposing UAC1 driver
This approach is quite easy to implement and I though about it when started to work on this patch series, but due to my lazyness I wanted to get some comments before doing extra work.
Quoted 2 lines
... and hopefully very similar to (or just port
of) thef_audio_source.cfrom android.
Current patch series reuses code from f_uac2 (in u_audio) and makes it in some sense similar to f_audio_source.c.
The f_audio_source.c implementation has additional functionality like more accurate data transferring (w.r.t timings), that can be ported to u_audio separately.
Best regards,
Ruslan