u_audio.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * u_audio.h -- interface to USB gadget "ALSA sound card" utilities
  3. *
  4. * Copyright (C) 2016
  5. * Author: Ruslan Bilovol <ruslan.bilovol@gmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. */
  18. #ifndef __U_AUDIO_H
  19. #define __U_AUDIO_H
  20. #include <linux/usb/composite.h>
  21. struct uac_params {
  22. /* playback */
  23. int p_chmask; /* channel mask */
  24. int p_srate; /* rate in Hz */
  25. int p_ssize; /* sample size */
  26. /* capture */
  27. int c_chmask; /* channel mask */
  28. int c_srate; /* rate in Hz */
  29. int c_ssize; /* sample size */
  30. int req_number; /* number of preallocated requests */
  31. };
  32. struct g_audio {
  33. struct usb_function func;
  34. struct usb_gadget *gadget;
  35. struct usb_ep *in_ep;
  36. struct usb_ep *out_ep;
  37. /* Max packet size for all in_ep possible speeds */
  38. unsigned int in_ep_maxpsize;
  39. /* Max packet size for all out_ep possible speeds */
  40. unsigned int out_ep_maxpsize;
  41. /* The ALSA Sound Card it represents on the USB-Client side */
  42. struct snd_uac_chip *uac;
  43. struct uac_params params;
  44. };
  45. static inline struct g_audio *func_to_g_audio(struct usb_function *f)
  46. {
  47. return container_of(f, struct g_audio, func);
  48. }
  49. static inline uint num_channels(uint chanmask)
  50. {
  51. uint num = 0;
  52. while (chanmask) {
  53. num += (chanmask & 1);
  54. chanmask >>= 1;
  55. }
  56. return num;
  57. }
  58. /*
  59. * g_audio_setup - initialize one virtual ALSA sound card
  60. * @g_audio: struct with filled params, in_ep_maxpsize, out_ep_maxpsize
  61. * @pcm_name: the id string for a PCM instance of this sound card
  62. * @card_name: name of this soundcard
  63. *
  64. * This sets up the single virtual ALSA sound card that may be exported by a
  65. * gadget driver using this framework.
  66. *
  67. * Context: may sleep
  68. *
  69. * Returns zero on success, or a negative error on failure.
  70. */
  71. int g_audio_setup(struct g_audio *g_audio, const char *pcm_name,
  72. const char *card_name);
  73. void g_audio_cleanup(struct g_audio *g_audio);
  74. int u_audio_start_capture(struct g_audio *g_audio);
  75. void u_audio_stop_capture(struct g_audio *g_audio);
  76. int u_audio_start_playback(struct g_audio *g_audio);
  77. void u_audio_stop_playback(struct g_audio *g_audio);
  78. #endif /* __U_AUDIO_H */