logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0003-alsa-Port-to-tinyalsa.patch (31813B)


  1. From 39ec20119841c84500e589fee15c10e9fe6c0c97 Mon Sep 17 00:00:00 2001
  2. From: Michael Forney <mforney@mforney.org>
  3. Date: Tue, 31 Aug 2021 14:30:07 -0700
  4. Subject: [PATCH] alsa: Port to tinyalsa
  5. ---
  6. libsndio/debug.c | 2 +-
  7. libsndio/sio_alsa.c | 747 +++++++++++++++-----------------------------
  8. 2 files changed, 247 insertions(+), 502 deletions(-)
  9. diff --git a/libsndio/debug.c b/libsndio/debug.c
  10. index 304975a..40fdc92 100644
  11. --- a/libsndio/debug.c
  12. +++ b/libsndio/debug.c
  13. @@ -35,7 +35,7 @@ _sndio_debug_init(void)
  14. if (_sndio_debug < 0) {
  15. dbg = issetugid() ? NULL : getenv("SNDIO_DEBUG");
  16. - if (!dbg || sscanf(dbg, "%u", &_sndio_debug) != 1)
  17. + if (!dbg || sscanf(dbg, "%d", &_sndio_debug) != 1)
  18. _sndio_debug = 0;
  19. }
  20. }
  21. diff --git a/libsndio/sio_alsa.c b/libsndio/sio_alsa.c
  22. index 6107617..e460bf6 100644
  23. --- a/libsndio/sio_alsa.c
  24. +++ b/libsndio/sio_alsa.c
  25. @@ -29,31 +29,28 @@
  26. #include <string.h>
  27. #include <unistd.h>
  28. #include <values.h>
  29. -#include <alsa/asoundlib.h>
  30. +#include <tinyalsa/asoundlib.h>
  31. #include "debug.h"
  32. #include "sio_priv.h"
  33. #include "bsd-compat.h"
  34. -#define DEVNAME_PREFIX "hw:"
  35. -
  36. #ifdef DEBUG
  37. -static snd_output_t *output = NULL;
  38. -#define DALSA(str, err) fprintf(stderr, "%s: %s\n", str, snd_strerror(err))
  39. +#define DALSA(str, pcm) fprintf(stderr, "%s: %s\n", str, pcm_get_error(pcm))
  40. #else
  41. -#define DALSA(str, err) do {} while (0)
  42. +#define DALSA(str, pcm) do {} while (0)
  43. #endif
  44. struct sio_alsa_hdl {
  45. struct sio_hdl sio;
  46. struct sio_par par;
  47. - char *devname;
  48. - snd_pcm_t *opcm;
  49. - snd_pcm_t *ipcm;
  50. + struct pcm_params *opar;
  51. + struct pcm_params *ipar;
  52. + struct pcm *opcm;
  53. + struct pcm *ipcm;
  54. unsigned ibpf, obpf; /* bytes per frame */
  55. int iused, oused; /* frames used in hardware fifos */
  56. int idelta, odelta; /* position reported to client */
  57. - int nfds, infds, onfds;
  58. int running;
  59. int events;
  60. int ipartial, opartial;
  61. @@ -102,90 +99,56 @@ static unsigned int cap_rates[] = {
  62. 8000, 11025, 12000, 16000, 22050, 24000,
  63. 32000, 44100, 48000, 64000, 88200, 96000
  64. };
  65. -static snd_pcm_format_t cap_fmts[] = {
  66. +static enum pcm_format cap_fmts[] = {
  67. /* XXX add s24le3 and s24be3 */
  68. - SND_PCM_FORMAT_S32_LE, SND_PCM_FORMAT_S32_BE,
  69. - SND_PCM_FORMAT_S24_LE, SND_PCM_FORMAT_S24_BE,
  70. - SND_PCM_FORMAT_S16_LE, SND_PCM_FORMAT_S16_BE,
  71. - SND_PCM_FORMAT_U8
  72. + PCM_FORMAT_S32_LE, PCM_FORMAT_S32_BE,
  73. + PCM_FORMAT_S24_LE, PCM_FORMAT_S24_BE,
  74. + PCM_FORMAT_S16_LE, PCM_FORMAT_S16_BE,
  75. + PCM_FORMAT_S8
  76. };
  77. /*
  78. * convert ALSA format to sio_par encoding
  79. */
  80. static int
  81. -sio_alsa_fmttopar(struct sio_alsa_hdl *hdl, snd_pcm_format_t fmt,
  82. +sio_alsa_fmttopar(struct sio_alsa_hdl *hdl, enum pcm_format fmt,
  83. unsigned int *bits, unsigned int *sig, unsigned int *le)
  84. {
  85. switch (fmt) {
  86. - case SND_PCM_FORMAT_U8:
  87. - *bits = 8;
  88. - *sig = 0;
  89. - break;
  90. - case SND_PCM_FORMAT_S8:
  91. + case PCM_FORMAT_S8:
  92. *bits = 8;
  93. *sig = 1;
  94. break;
  95. - case SND_PCM_FORMAT_S16_LE:
  96. + case PCM_FORMAT_S16_LE:
  97. *bits = 16;
  98. *sig = 1;
  99. *le = 1;
  100. break;
  101. - case SND_PCM_FORMAT_S16_BE:
  102. + case PCM_FORMAT_S16_BE:
  103. *bits = 16;
  104. *sig = 1;
  105. *le = 0;
  106. break;
  107. - case SND_PCM_FORMAT_U16_LE:
  108. - *bits = 16;
  109. - *sig = 0;
  110. - *le = 1;
  111. - break;
  112. - case SND_PCM_FORMAT_U16_BE:
  113. - *bits = 16;
  114. - *sig = 0;
  115. - *le = 0;
  116. - break;
  117. - case SND_PCM_FORMAT_S24_LE:
  118. + case PCM_FORMAT_S24_LE:
  119. *bits = 24;
  120. *sig = 1;
  121. *le = 1;
  122. break;
  123. - case SND_PCM_FORMAT_S24_BE:
  124. + case PCM_FORMAT_S24_BE:
  125. *bits = 24;
  126. *sig = 1;
  127. *le = 0;
  128. break;
  129. - case SND_PCM_FORMAT_U24_LE:
  130. - *bits = 24;
  131. - *sig = 0;
  132. - *le = 1;
  133. - break;
  134. - case SND_PCM_FORMAT_U24_BE:
  135. - *bits = 24;
  136. - *sig = 0;
  137. - *le = 0;
  138. - break;
  139. - case SND_PCM_FORMAT_S32_LE:
  140. + case PCM_FORMAT_S32_LE:
  141. *bits = 32;
  142. *sig = 1;
  143. *le = 1;
  144. break;
  145. - case SND_PCM_FORMAT_S32_BE:
  146. + case PCM_FORMAT_S32_BE:
  147. *bits = 32;
  148. *sig = 1;
  149. *le = 0;
  150. break;
  151. - case SND_PCM_FORMAT_U32_LE:
  152. - *bits = 32;
  153. - *sig = 0;
  154. - *le = 1;
  155. - break;
  156. - case SND_PCM_FORMAT_U32_BE:
  157. - *bits = 32;
  158. - *sig = 0;
  159. - *le = 0;
  160. - break;
  161. default:
  162. DPRINTF("sio_alsa_fmttopar: 0x%x: unsupported format\n", fmt);
  163. hdl->sio.eof = 1;
  164. @@ -199,78 +162,19 @@ sio_alsa_fmttopar(struct sio_alsa_hdl *hdl, snd_pcm_format_t fmt,
  165. * convert sio_par encoding to ALSA format
  166. */
  167. static void
  168. -sio_alsa_enctofmt(struct sio_alsa_hdl *hdl, snd_pcm_format_t *rfmt,
  169. +sio_alsa_enctofmt(struct sio_alsa_hdl *hdl, enum pcm_format *rfmt,
  170. unsigned int bits, unsigned int sig, unsigned int le)
  171. {
  172. - if (bits == 8) {
  173. - if (sig == ~0U || !sig)
  174. - *rfmt = SND_PCM_FORMAT_U8;
  175. - else
  176. - *rfmt = SND_PCM_FORMAT_S8;
  177. - } else if (bits == 16) {
  178. - if (sig == ~0U || sig) {
  179. - if (le == ~0U) {
  180. - *rfmt = SIO_LE_NATIVE ?
  181. - SND_PCM_FORMAT_S16_LE :
  182. - SND_PCM_FORMAT_S16_BE;
  183. - } else if (le)
  184. - *rfmt = SND_PCM_FORMAT_S16_LE;
  185. - else
  186. - *rfmt = SND_PCM_FORMAT_S16_BE;
  187. - } else {
  188. - if (le == ~0U) {
  189. - *rfmt = SIO_LE_NATIVE ?
  190. - SND_PCM_FORMAT_U16_LE :
  191. - SND_PCM_FORMAT_U16_BE;
  192. - } else if (le)
  193. - *rfmt = SND_PCM_FORMAT_U16_LE;
  194. - else
  195. - *rfmt = SND_PCM_FORMAT_U16_BE;
  196. - }
  197. - } else if (bits == 24) {
  198. - if (sig == ~0U || sig) {
  199. - if (le == ~0U) {
  200. - *rfmt = SIO_LE_NATIVE ?
  201. - SND_PCM_FORMAT_S24_LE :
  202. - SND_PCM_FORMAT_S24_BE;
  203. - } else if (le)
  204. - *rfmt = SND_PCM_FORMAT_S24_LE;
  205. - else
  206. - *rfmt = SND_PCM_FORMAT_S24_BE;
  207. - } else {
  208. - if (le == ~0U) {
  209. - *rfmt = SIO_LE_NATIVE ?
  210. - SND_PCM_FORMAT_U24_LE :
  211. - SND_PCM_FORMAT_U24_BE;
  212. - } else if (le)
  213. - *rfmt = SND_PCM_FORMAT_U24_LE;
  214. - else
  215. - *rfmt = SND_PCM_FORMAT_U24_BE;
  216. - }
  217. - } else if (bits == 32) {
  218. - if (sig == ~0U || sig) {
  219. - if (le == ~0U) {
  220. - *rfmt = SIO_LE_NATIVE ?
  221. - SND_PCM_FORMAT_S32_LE :
  222. - SND_PCM_FORMAT_S32_BE;
  223. - } else if (le)
  224. - *rfmt = SND_PCM_FORMAT_S32_LE;
  225. - else
  226. - *rfmt = SND_PCM_FORMAT_S32_BE;
  227. - } else {
  228. - if (le == ~0U) {
  229. - *rfmt = SIO_LE_NATIVE ?
  230. - SND_PCM_FORMAT_U32_LE :
  231. - SND_PCM_FORMAT_U32_BE;
  232. - } else if (le)
  233. - *rfmt = SND_PCM_FORMAT_U32_LE;
  234. - else
  235. - *rfmt = SND_PCM_FORMAT_U32_BE;
  236. - }
  237. - } else {
  238. - *rfmt = SIO_LE_NATIVE ?
  239. - SND_PCM_FORMAT_S16_LE : SND_PCM_FORMAT_S16_BE;
  240. - }
  241. + if (le == ~0U)
  242. + le = SIO_LE_NATIVE;
  243. + if (bits == 8)
  244. + *rfmt = PCM_FORMAT_S8;
  245. + else if (bits == 24)
  246. + *rfmt = le ? PCM_FORMAT_S24_LE : PCM_FORMAT_S24_BE;
  247. + else if (bits == 32)
  248. + *rfmt = le ? PCM_FORMAT_S32_LE : PCM_FORMAT_S32_BE;
  249. + else
  250. + *rfmt = le ? PCM_FORMAT_S16_LE : PCM_FORMAT_S16_BE;
  251. }
  252. struct sio_hdl *
  253. @@ -279,8 +183,7 @@ _sio_alsa_open(const char *str, unsigned mode, int nbio)
  254. const char *p;
  255. struct sio_alsa_hdl *hdl;
  256. struct sio_par par;
  257. - size_t len;
  258. - int err;
  259. + unsigned card, dev;
  260. p = _sndio_parsetype(str, "rsnd");
  261. if (p == NULL) {
  262. @@ -300,42 +203,45 @@ _sio_alsa_open(const char *str, unsigned mode, int nbio)
  263. return NULL;
  264. _sio_create(&hdl->sio, &sio_alsa_ops, mode, nbio);
  265. -#ifdef DEBUG
  266. - err = snd_output_stdio_attach(&output, stderr, 0);
  267. - if (err < 0)
  268. - DALSA("couldn't attach to stderr", err);
  269. -#endif
  270. - if (strcmp(p, "default") == 0)
  271. - p = "0";
  272. - len = strlen(p);
  273. - hdl->devname = malloc(len + sizeof(DEVNAME_PREFIX));
  274. - if (hdl->devname == NULL)
  275. - goto bad_free_hdl;
  276. - memcpy(hdl->devname, DEVNAME_PREFIX, sizeof(DEVNAME_PREFIX) - 1);
  277. - memcpy(hdl->devname + sizeof(DEVNAME_PREFIX) - 1, p, len + 1);
  278. + if (strcmp(p, "default") == 0) {
  279. + card = 0;
  280. + dev = 0;
  281. + } else {
  282. + switch (sscanf(p, "%u,%u", &card, &dev)) {
  283. + case 1:
  284. + dev = 0;
  285. + break;
  286. + case 2:
  287. + break;
  288. + default:
  289. + DPRINTF("invalid device name\n");
  290. + }
  291. + }
  292. if (mode & SIO_PLAY) {
  293. - err = snd_pcm_open(&hdl->opcm, hdl->devname,
  294. - SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
  295. - if (err < 0) {
  296. - DALSA("couldn't open play stream", err);
  297. - goto bad_free;
  298. + hdl->opar = pcm_params_get(card, dev, PCM_OUT);
  299. + if (hdl->opar == NULL) {
  300. + DPRINTF("couldn't get play params\n");
  301. + goto bad_free_hdl;
  302. + }
  303. + hdl->opcm = pcm_open(card, dev, PCM_OUT | PCM_NONBLOCK, NULL);
  304. + if (!pcm_is_ready(hdl->opcm)) {
  305. + DALSA("couldn't open play stream", hdl->opcm);
  306. + goto bad_free_opar;
  307. }
  308. }
  309. if (mode & SIO_REC) {
  310. - err = snd_pcm_open(&hdl->ipcm, hdl->devname,
  311. - SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK);
  312. - if (err < 0) {
  313. - DALSA("couldn't open rec stream", err);
  314. + hdl->ipar = pcm_params_get(card, dev, PCM_IN);
  315. + if (hdl->ipar == NULL) {
  316. + DPRINTF("couldn't get rec params\n");
  317. goto bad_free_opcm;
  318. }
  319. + hdl->ipcm = pcm_open(card, dev, PCM_IN | PCM_NONBLOCK, NULL);
  320. + if (!pcm_is_ready(hdl->ipcm)) {
  321. + DALSA("couldn't open rec stream", hdl->ipcm);
  322. + goto bad_free_ipar;
  323. + }
  324. }
  325. - /*
  326. - * snd_pcm_poll_descriptors_count returns a small value
  327. - * that grows later, after the stream is started
  328. - */
  329. - hdl->nfds = SIO_MAXNFDS;
  330. -
  331. /*
  332. * Default parameters may not be compatible with libsndio (eg. mulaw
  333. * encodings, different playback and recording parameters, etc...), so
  334. @@ -356,12 +262,16 @@ _sio_alsa_open(const char *str, unsigned mode, int nbio)
  335. return (struct sio_hdl *)hdl;
  336. bad_free_ipcm:
  337. if (mode & SIO_REC)
  338. - snd_pcm_close(hdl->ipcm);
  339. + pcm_close(hdl->ipcm);
  340. +bad_free_ipar:
  341. + if (mode & SIO_REC)
  342. + free(hdl->ipar);
  343. bad_free_opcm:
  344. if (mode & SIO_PLAY)
  345. - snd_pcm_close(hdl->opcm);
  346. -bad_free:
  347. - free(hdl->devname);
  348. + pcm_close(hdl->opcm);
  349. +bad_free_opar:
  350. + if (mode & SIO_PLAY)
  351. + free(hdl->opar);
  352. bad_free_hdl:
  353. free(hdl);
  354. return NULL;
  355. @@ -372,11 +282,14 @@ sio_alsa_close(struct sio_hdl *sh)
  356. {
  357. struct sio_alsa_hdl *hdl = (struct sio_alsa_hdl *)sh;
  358. - if (hdl->sio.mode & SIO_PLAY)
  359. - snd_pcm_close(hdl->opcm);
  360. - if (hdl->sio.mode & SIO_REC)
  361. - snd_pcm_close(hdl->ipcm);
  362. - free(hdl->devname);
  363. + if (hdl->sio.mode & SIO_PLAY) {
  364. + free(hdl->opar);
  365. + pcm_close(hdl->opcm);
  366. + }
  367. + if (hdl->sio.mode & SIO_REC) {
  368. + free(hdl->ipar);
  369. + pcm_close(hdl->ipcm);
  370. + }
  371. free(hdl);
  372. }
  373. @@ -394,14 +307,12 @@ sio_alsa_start(struct sio_hdl *sh)
  374. hdl->oused = 0;
  375. hdl->idelta = 0;
  376. hdl->odelta = 0;
  377. - hdl->infds = 0;
  378. - hdl->onfds = 0;
  379. hdl->running = 0;
  380. if (hdl->sio.mode & SIO_PLAY) {
  381. - err = snd_pcm_prepare(hdl->opcm);
  382. + err = pcm_prepare(hdl->opcm);
  383. if (err < 0) {
  384. - DALSA("couldn't prepare play stream", err);
  385. + DALSA("couldn't prepare play stream", hdl->opcm);
  386. hdl->sio.eof = 1;
  387. return 0;
  388. }
  389. @@ -413,9 +324,9 @@ sio_alsa_start(struct sio_hdl *sh)
  390. hdl->opartial = 0;
  391. }
  392. if (hdl->sio.mode & SIO_REC) {
  393. - err = snd_pcm_prepare(hdl->ipcm);
  394. + err = pcm_prepare(hdl->ipcm);
  395. if (err < 0) {
  396. - DALSA("couldn't prepare rec stream", err);
  397. + DALSA("couldn't prepare rec stream", hdl->ipcm);
  398. hdl->sio.eof = 1;
  399. return 0;
  400. }
  401. @@ -427,17 +338,17 @@ sio_alsa_start(struct sio_hdl *sh)
  402. hdl->ipartial = 0;
  403. }
  404. if ((hdl->sio.mode & SIO_PLAY) && (hdl->sio.mode & SIO_REC)) {
  405. - err = snd_pcm_link(hdl->ipcm, hdl->opcm);
  406. + err = pcm_link(hdl->ipcm, hdl->opcm);
  407. if (err < 0) {
  408. - DALSA("couldn't link streams", err);
  409. + DALSA("couldn't link streams", hdl->ipcm);
  410. hdl->sio.eof = 1;
  411. return 0;
  412. }
  413. }
  414. if (!(hdl->sio.mode & SIO_PLAY)) {
  415. - err = snd_pcm_start(hdl->ipcm);
  416. + err = pcm_start(hdl->ipcm);
  417. if (err < 0) {
  418. - DALSA("couldn't start rec stream", err);
  419. + DALSA("couldn't start rec stream", hdl->ipcm);
  420. hdl->sio.eof = 1;
  421. return 0;
  422. }
  423. @@ -449,30 +360,26 @@ static int
  424. sio_alsa_flush(struct sio_hdl *sh)
  425. {
  426. struct sio_alsa_hdl *hdl = (struct sio_alsa_hdl *)sh;
  427. - int err;
  428. if (hdl->sio.mode & SIO_PLAY) {
  429. - err = snd_pcm_drop(hdl->opcm);
  430. - if (err < 0) {
  431. - DALSA("couldn't stop play stream", err);
  432. + if (pcm_stop(hdl->opcm) != 0) {
  433. + DALSA("couldn't stop play stream", hdl->opcm);
  434. hdl->sio.eof = 1;
  435. return 0;
  436. }
  437. free(hdl->otmpbuf);
  438. }
  439. if (hdl->sio.mode & SIO_REC) {
  440. - err = snd_pcm_drop(hdl->ipcm);
  441. - if (err < 0) {
  442. - DALSA("couldn't stop rec stream", err);
  443. + if (pcm_stop(hdl->ipcm) != 0) {
  444. + DALSA("couldn't stop rec stream", hdl->ipcm);
  445. hdl->sio.eof = 1;
  446. return 0;
  447. }
  448. free(hdl->itmpbuf);
  449. }
  450. if ((hdl->sio.mode & SIO_PLAY) && (hdl->sio.mode & SIO_REC)) {
  451. - err = snd_pcm_unlink(hdl->ipcm);
  452. - if (err < 0) {
  453. - DALSA("couldn't unlink streams", err);
  454. + if (pcm_unlink(hdl->ipcm) != 0) {
  455. + DALSA("couldn't unlink streams", hdl->ipcm);
  456. hdl->sio.eof = 1;
  457. return 0;
  458. }
  459. @@ -537,143 +444,110 @@ sio_alsa_xrun(struct sio_alsa_hdl *hdl)
  460. }
  461. static int
  462. -sio_alsa_setpar_hw(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwp,
  463. - snd_pcm_format_t *reqfmt, unsigned int *rate, unsigned int *chans,
  464. - snd_pcm_uframes_t *round, unsigned int *periods)
  465. +sio_alsa_setpar_hw(struct pcm *pcm, struct pcm_params *par,
  466. + struct pcm_config *cfg)
  467. {
  468. - static snd_pcm_format_t fmts[] = {
  469. - SND_PCM_FORMAT_S32_LE, SND_PCM_FORMAT_S32_BE,
  470. - SND_PCM_FORMAT_U32_LE, SND_PCM_FORMAT_U32_BE,
  471. - SND_PCM_FORMAT_S24_LE, SND_PCM_FORMAT_S24_BE,
  472. - SND_PCM_FORMAT_U24_LE, SND_PCM_FORMAT_U24_BE,
  473. - SND_PCM_FORMAT_S16_LE, SND_PCM_FORMAT_S16_BE,
  474. - SND_PCM_FORMAT_U16_LE, SND_PCM_FORMAT_U16_BE,
  475. - SND_PCM_FORMAT_U8, SND_PCM_FORMAT_S8
  476. + static enum pcm_format fmts[] = {
  477. + PCM_FORMAT_S32_LE, PCM_FORMAT_S32_BE,
  478. + PCM_FORMAT_S24_LE, PCM_FORMAT_S24_BE,
  479. + PCM_FORMAT_S16_LE, PCM_FORMAT_S16_BE,
  480. + PCM_FORMAT_S8
  481. };
  482. - int i, err, dir = 0;
  483. - unsigned req_rate, min_periods = 2;
  484. + int i, err;
  485. + unsigned req_rate;
  486. + unsigned min, max;
  487. - req_rate = *rate;
  488. + /* XXX: HW_FREE */
  489. - err = snd_pcm_hw_free(pcm);
  490. - if (err < 0) {
  491. - DALSA("couldn't reset hw configuration", err);
  492. - return 0;
  493. - }
  494. - err = snd_pcm_hw_params_any(pcm, hwp);
  495. - if (err < 0) {
  496. - DALSA("couldn't init pars", err);
  497. - return 0;
  498. - }
  499. - err = snd_pcm_hw_params_set_access(pcm, hwp,
  500. - SND_PCM_ACCESS_RW_INTERLEAVED);
  501. - if (err < 0) {
  502. - DALSA("couldn't set interleaved access", err);
  503. - return 0;
  504. - }
  505. - err = snd_pcm_hw_params_test_format(pcm, hwp, *reqfmt);
  506. - if (err < 0) {
  507. + if (pcm_params_format_test(par, cfg->format) == 0) {
  508. for (i = 0; ; i++) {
  509. - if (i == sizeof(fmts) / sizeof(snd_pcm_format_t)) {
  510. + if (i == sizeof(fmts) / sizeof(fmts[0])) {
  511. DPRINTF("no known format found\n");
  512. return 0;
  513. }
  514. - err = snd_pcm_hw_params_test_format(pcm, hwp, fmts[i]);
  515. - if (err)
  516. + if (pcm_params_format_test(par, fmts[i]) == 0)
  517. continue;
  518. - *reqfmt = fmts[i];
  519. + cfg->format = fmts[i];
  520. break;
  521. }
  522. }
  523. - err = snd_pcm_hw_params_set_format(pcm, hwp, *reqfmt);
  524. - if (err < 0) {
  525. - DALSA("couldn't set fmt", err);
  526. - return 0;
  527. - }
  528. - err = snd_pcm_hw_params_set_rate_resample(pcm, hwp, 0);
  529. - if (err < 0) {
  530. - DALSA("couldn't turn resampling off", err);
  531. - return 0;
  532. - }
  533. - err = snd_pcm_hw_params_set_rate_near(pcm, hwp, rate, 0);
  534. - if (err < 0) {
  535. - DALSA("couldn't set rate", err);
  536. - return 0;
  537. - }
  538. - err = snd_pcm_hw_params_set_channels_near(pcm, hwp, chans);
  539. - if (err < 0) {
  540. - DALSA("couldn't set channel count", err);
  541. - return 0;
  542. - }
  543. - err = snd_pcm_hw_params_set_periods_integer(pcm, hwp);
  544. - if (err < 0) {
  545. - DALSA("couldn't set periods to integer", err);
  546. - return 0;
  547. - }
  548. - err = snd_pcm_hw_params_set_periods_min(pcm, hwp, &min_periods, NULL);
  549. - if (err < 0) {
  550. - DALSA("couldn't set minimum periods", err);
  551. - return 0;
  552. - }
  553. - err = snd_pcm_hw_params_set_period_size_integer(pcm, hwp);
  554. - if (err < 0) {
  555. - DALSA("couldn't set period to integer", err);
  556. - return 0;
  557. - }
  558. -
  559. - *round = *round * *rate / req_rate;
  560. - *round = (*round + 31) & ~31;
  561. - err = snd_pcm_hw_params_set_period_size_near(pcm, hwp, round, &dir);
  562. - if (err < 0) {
  563. - DALSA("couldn't set period size failed", err);
  564. - return 0;
  565. - }
  566. - err = snd_pcm_hw_params_set_periods_near(pcm, hwp, periods, &dir);
  567. - if (err < 0) {
  568. - DALSA("couldn't set period count", err);
  569. - return 0;
  570. - }
  571. - err = snd_pcm_hw_params(pcm, hwp);
  572. + req_rate = cfg->rate;
  573. + min = pcm_params_get_min(par, PCM_PARAM_RATE);
  574. + if (cfg->rate < min)
  575. + cfg->rate = min;
  576. + max = pcm_params_get_max(par, PCM_PARAM_RATE);
  577. + if (cfg->rate > max)
  578. + cfg->rate = max;
  579. +
  580. + min = pcm_params_get_min(par, PCM_PARAM_CHANNELS);
  581. + if (cfg->channels < min)
  582. + cfg->channels = min;
  583. + max = pcm_params_get_max(par, PCM_PARAM_CHANNELS);
  584. + if (cfg->channels > max)
  585. + cfg->channels = max;
  586. +
  587. + cfg->period_size = cfg->period_size * cfg->rate / req_rate;
  588. + cfg->period_size = (cfg->period_size + 31) & ~31;
  589. +
  590. + min = pcm_params_get_min(par, PCM_PARAM_PERIOD_SIZE);
  591. + if (min < 2)
  592. + min = 2;
  593. + if (cfg->period_size < min)
  594. + cfg->period_size = min;
  595. + max = pcm_params_get_max(par, PCM_PARAM_PERIOD_SIZE);
  596. + if (cfg->period_size > max)
  597. + cfg->period_size = max;
  598. +
  599. + min = pcm_params_get_min(par, PCM_PARAM_PERIODS);
  600. + if (cfg->period_count < min)
  601. + cfg->period_count = min;
  602. + max = pcm_params_get_max(par, PCM_PARAM_PERIODS);
  603. + if (cfg->period_count > max)
  604. + cfg->period_count = max;
  605. +
  606. + cfg->start_threshold = 0;
  607. + cfg->stop_threshold = cfg->period_count * cfg->period_size;
  608. + cfg->avail_min = 1;
  609. + cfg->silence_size = 0;
  610. + cfg->silence_threshold = 0;
  611. +
  612. + /* XXX: period_event=1, silence?, silence_threshold? */
  613. +
  614. + err = pcm_set_config(pcm, cfg);
  615. if (err < 0) {
  616. - DALSA("couldn't commit params", err);
  617. + DALSA("couldn't set config", pcm);
  618. return 0;
  619. }
  620. return 1;
  621. }
  622. static int
  623. -sio_alsa_getcap_hw(snd_pcm_t *pcm, int *rates, int *fmts, int *chans)
  624. +sio_alsa_getcap_hw(struct pcm_params *par, int *rates, int *fmts, int *chans)
  625. {
  626. int i, err;
  627. - snd_pcm_hw_params_t *hwp;
  628. -
  629. - snd_pcm_hw_params_alloca(&hwp);
  630. -
  631. - err = snd_pcm_hw_params_any(pcm, hwp);
  632. - if (err < 0) {
  633. - DALSA("sio_alsa_trypar: couldn't init pars", err);
  634. - return 0;
  635. - }
  636. + unsigned min, max;
  637. *fmts = 0;
  638. for (i = 0; i < CAP_NFMTS; i++) {
  639. - err = snd_pcm_hw_params_test_format(pcm, hwp, cap_fmts[i]);
  640. + err = pcm_params_format_test(par, cap_fmts[i]);
  641. if (err == 0) {
  642. *fmts |= 1 << i;
  643. }
  644. }
  645. *rates = 0;
  646. + min = pcm_params_get_min(par, PCM_PARAM_RATE);
  647. + max = pcm_params_get_max(par, PCM_PARAM_RATE);
  648. for (i = 0; i < CAP_NRATES; i++) {
  649. - err = snd_pcm_hw_params_test_rate(pcm, hwp, cap_rates[i], 0);
  650. - if (err == 0) {
  651. + if (min <= cap_rates[i] && cap_rates[i] <= max) {
  652. *rates |= 1 << i;
  653. }
  654. }
  655. *chans = 0;
  656. + min = pcm_params_get_min(par, PCM_PARAM_CHANNELS);
  657. + max = pcm_params_get_max(par, PCM_PARAM_CHANNELS);
  658. for (i = 0; i < CAP_NCHANS; i++) {
  659. - err = snd_pcm_hw_params_test_channels(pcm, hwp, cap_chans[i]);
  660. - if (err == 0) {
  661. + if (min <= cap_chans[i] && cap_chans[i] <= max) {
  662. *chans |= 1 << i;
  663. }
  664. }
  665. @@ -693,13 +567,13 @@ sio_alsa_getcap(struct sio_hdl *sh, struct sio_cap *cap)
  666. irates = orates = ifmts = ofmts = ichans = ochans = 0;
  667. if (hdl->sio.mode & SIO_PLAY) {
  668. - if (!sio_alsa_getcap_hw(hdl->opcm,
  669. + if (!sio_alsa_getcap_hw(hdl->opar,
  670. &orates, &ofmts, &ochans)) {
  671. return 0;
  672. }
  673. }
  674. if (hdl->sio.mode & SIO_REC) {
  675. - if (!sio_alsa_getcap_hw(hdl->ipcm,
  676. + if (!sio_alsa_getcap_hw(hdl->ipar,
  677. &irates, &ifmts, &ichans)) {
  678. return 0;
  679. }
  680. @@ -711,7 +585,7 @@ sio_alsa_getcap(struct sio_hdl *sh, struct sio_cap *cap)
  681. &cap->enc[i].sig,
  682. &cap->enc[i].le);
  683. cap->enc[i].bps = SIO_BPS(cap->enc[0].bits);
  684. - cap->enc[i].msb = 1;
  685. + cap->enc[i].msb = 0;
  686. }
  687. for (i = 0; i < CAP_NRATES; i++) {
  688. cap->rate[i] = cap_rates[i];
  689. @@ -744,186 +618,72 @@ static int
  690. sio_alsa_setpar(struct sio_hdl *sh, struct sio_par *par)
  691. {
  692. struct sio_alsa_hdl *hdl = (struct sio_alsa_hdl *)sh;
  693. - snd_pcm_hw_params_t *ohwp, *ihwp;
  694. - snd_pcm_sw_params_t *oswp, *iswp;
  695. - snd_pcm_uframes_t iround, oround;
  696. - snd_pcm_format_t ifmt, ofmt;
  697. - unsigned int iperiods, operiods;
  698. - unsigned irate, orate;
  699. - int err;
  700. -
  701. - snd_pcm_hw_params_alloca(&ohwp);
  702. - snd_pcm_sw_params_alloca(&oswp);
  703. - snd_pcm_hw_params_alloca(&ihwp);
  704. - snd_pcm_sw_params_alloca(&iswp);
  705. + struct pcm_config icfg, ocfg;
  706. - sio_alsa_enctofmt(hdl, &ifmt, par->bits, par->sig, par->le);
  707. - irate = (par->rate == ~0U) ? 48000 : par->rate;
  708. + sio_alsa_enctofmt(hdl, &icfg.format, par->bits, par->sig, par->le);
  709. + icfg.rate = (par->rate == ~0U) ? 48000 : par->rate;
  710. if (par->appbufsz != ~0U) {
  711. - iround = (par->round != ~0U) ?
  712. + icfg.period_size = (par->round != ~0U) ?
  713. par->round : (par->appbufsz + 1) / 2;
  714. - iperiods = par->appbufsz / iround;
  715. - if (iperiods < 2)
  716. - iperiods = 2;
  717. + icfg.period_count = par->appbufsz / icfg.period_size;
  718. + if (icfg.period_count < 2)
  719. + icfg.period_count = 2;
  720. } else if (par->round != ~0U) {
  721. - iround = par->round;
  722. - iperiods = 2;
  723. + icfg.period_size = par->round;
  724. + icfg.period_count = 2;
  725. } else {
  726. - iperiods = 2;
  727. - iround = irate / 100;
  728. + icfg.period_count = 2;
  729. + icfg.period_size = icfg.rate / 100;
  730. }
  731. if (hdl->sio.mode & SIO_REC) {
  732. hdl->par.rchan = par->rchan;
  733. - if (!sio_alsa_setpar_hw(hdl->ipcm, ihwp,
  734. - &ifmt, &irate, &hdl->par.rchan,
  735. - &iround, &iperiods)) {
  736. + if (!sio_alsa_setpar_hw(hdl->ipcm, hdl->ipar, &icfg)) {
  737. hdl->sio.eof = 1;
  738. return 0;
  739. }
  740. }
  741. - ofmt = ifmt;
  742. - orate = irate;
  743. - oround = iround;
  744. - operiods = iperiods;
  745. + ocfg = icfg;
  746. if (hdl->sio.mode & SIO_PLAY) {
  747. hdl->par.pchan = par->pchan;
  748. - if (!sio_alsa_setpar_hw(hdl->opcm, ohwp,
  749. - &ofmt, &orate, &hdl->par.pchan,
  750. - &oround, &operiods)) {
  751. + if (!sio_alsa_setpar_hw(hdl->opcm, hdl->opar, &ocfg)) {
  752. hdl->sio.eof = 1;
  753. return 0;
  754. }
  755. - if (!(hdl->sio.mode & SIO_REC)) {
  756. - ifmt = ofmt;
  757. - irate = orate;
  758. - iround = oround;
  759. - iperiods = operiods;
  760. - }
  761. + if (!(hdl->sio.mode & SIO_REC))
  762. + icfg = ocfg;
  763. }
  764. DPRINTFN(2, "ofmt = %u, orate = %u, oround = %u, operiods = %u\n",
  765. - ofmt, orate, (unsigned int)oround, operiods);
  766. + ocfg.format, ocfg.rate, ocfg.period_size, ocfg.period_count);
  767. DPRINTFN(2, "ifmt = %u, irate = %u, iround = %u, iperiods = %u\n",
  768. - ifmt, irate, (unsigned int)iround, iperiods);
  769. + icfg.format, icfg.rate, icfg.period_size, icfg.period_count);
  770. - if (ifmt != ofmt) {
  771. + if (icfg.format != ocfg.format) {
  772. DPRINTF("play and rec formats differ\n");
  773. hdl->sio.eof = 1;
  774. return 0;
  775. }
  776. - if (irate != orate) {
  777. + if (icfg.rate != ocfg.rate) {
  778. DPRINTF("play and rec rates differ\n");
  779. hdl->sio.eof = 1;
  780. return 0;
  781. }
  782. - if (iround != oround) {
  783. + if (icfg.period_size != ocfg.period_size) {
  784. DPRINTF("play and rec block sizes differ\n");
  785. hdl->sio.eof = 1;
  786. return 0;
  787. }
  788. - if (!sio_alsa_fmttopar(hdl, ifmt,
  789. + if (!sio_alsa_fmttopar(hdl, icfg.format,
  790. &hdl->par.bits, &hdl->par.sig, &hdl->par.le))
  791. return 0;
  792. - hdl->par.msb = 1;
  793. + hdl->par.msb = 0;
  794. hdl->par.bps = SIO_BPS(hdl->par.bits);
  795. - hdl->par.rate = orate;
  796. - hdl->par.round = oround;
  797. - hdl->par.bufsz = oround * operiods;
  798. + hdl->par.rate = ocfg.rate;
  799. + hdl->par.round = ocfg.period_size;
  800. + hdl->par.bufsz = ocfg.period_size * ocfg.period_count;
  801. hdl->par.appbufsz = hdl->par.bufsz;
  802. - /* software params */
  803. -
  804. - if (hdl->sio.mode & SIO_REC) {
  805. - err = snd_pcm_sw_params_current(hdl->ipcm, iswp);
  806. - if (err < 0) {
  807. - DALSA("couldn't get current rec params", err);
  808. - hdl->sio.eof = 1;
  809. - return 0;
  810. - }
  811. - err = snd_pcm_sw_params_set_start_threshold(hdl->ipcm,
  812. - iswp, 0);
  813. - if (err < 0) {
  814. - DALSA("couldn't set rec start threshold", err);
  815. - hdl->sio.eof = 1;
  816. - return 0;
  817. - }
  818. - err = snd_pcm_sw_params_set_stop_threshold(hdl->ipcm,
  819. - iswp, hdl->par.bufsz);
  820. - if (err < 0) {
  821. - DALSA("couldn't set rec stop threshold", err);
  822. - hdl->sio.eof = 1;
  823. - return 0;
  824. - }
  825. - err = snd_pcm_sw_params_set_avail_min(hdl->ipcm,
  826. - iswp, 1);
  827. - if (err < 0) {
  828. - DALSA("couldn't set rec avail min", err);
  829. - hdl->sio.eof = 1;
  830. - return 0;
  831. - }
  832. - err = snd_pcm_sw_params_set_period_event(hdl->ipcm, iswp, 1);
  833. - if (err < 0) {
  834. - DALSA("couldn't set rec period event", err);
  835. - hdl->sio.eof = 1;
  836. - return 0;
  837. - }
  838. - err = snd_pcm_sw_params(hdl->ipcm, iswp);
  839. - if (err < 0) {
  840. - DALSA("couldn't commit rec sw params", err);
  841. - hdl->sio.eof = 1;
  842. - return 0;
  843. - }
  844. - }
  845. - if (hdl->sio.mode & SIO_PLAY) {
  846. - err = snd_pcm_sw_params_current(hdl->opcm, oswp);
  847. - if (err < 0) {
  848. - DALSA("couldn't get current play params", err);
  849. - hdl->sio.eof = 1;
  850. - return 0;
  851. - }
  852. - err = snd_pcm_sw_params_set_start_threshold(hdl->opcm,
  853. - oswp, hdl->par.bufsz - hdl->par.round);
  854. - if (err < 0) {
  855. - DALSA("couldn't set play start threshold", err);
  856. - hdl->sio.eof = 1;
  857. - return 0;
  858. - }
  859. - err = snd_pcm_sw_params_set_stop_threshold(hdl->opcm,
  860. - oswp, hdl->par.bufsz);
  861. - if (err < 0) {
  862. - DALSA("couldn't set play stop threshold", err);
  863. - hdl->sio.eof = 1;
  864. - return 0;
  865. - }
  866. - err = snd_pcm_sw_params_set_avail_min(hdl->opcm,
  867. - oswp, 1);
  868. - if (err < 0) {
  869. - DALSA("couldn't set play avail min", err);
  870. - hdl->sio.eof = 1;
  871. - return 0;
  872. - }
  873. - err = snd_pcm_sw_params_set_period_event(hdl->opcm, oswp, 1);
  874. - if (err < 0) {
  875. - DALSA("couldn't set play period event", err);
  876. - hdl->sio.eof = 1;
  877. - return 0;
  878. - }
  879. - err = snd_pcm_sw_params(hdl->opcm, oswp);
  880. - if (err < 0) {
  881. - DALSA("couldn't commit play sw params", err);
  882. - hdl->sio.eof = 1;
  883. - return 0;
  884. - }
  885. - }
  886. -#ifdef DEBUG
  887. - if (_sndio_debug >= 2) {
  888. - if (hdl->sio.mode & SIO_REC)
  889. - snd_pcm_dump(hdl->ipcm, output);
  890. - if (hdl->sio.mode & SIO_PLAY)
  891. - snd_pcm_dump(hdl->opcm, output);
  892. - }
  893. -#endif
  894. return 1;
  895. }
  896. @@ -940,7 +700,7 @@ static size_t
  897. sio_alsa_read(struct sio_hdl *sh, void *buf, size_t len)
  898. {
  899. struct sio_alsa_hdl *hdl = (struct sio_alsa_hdl *)sh;
  900. - snd_pcm_sframes_t n;
  901. + int n;
  902. size_t todo;
  903. if (hdl->ipartial > 0) {
  904. @@ -959,7 +719,7 @@ sio_alsa_read(struct sio_hdl *sh, void *buf, size_t len)
  905. todo = len / hdl->ibpf;
  906. if (todo == 0)
  907. return 0;
  908. - while ((n = snd_pcm_readi(hdl->ipcm, buf, todo)) < 0) {
  909. + while ((n = pcm_readi(hdl->ipcm, buf, todo)) < 0) {
  910. if (n == -EINTR)
  911. continue;
  912. if (n == -EPIPE || n == -ESTRPIPE) {
  913. @@ -967,7 +727,7 @@ sio_alsa_read(struct sio_hdl *sh, void *buf, size_t len)
  914. return 0;
  915. }
  916. if (n != -EAGAIN) {
  917. - DALSA("couldn't read data", n);
  918. + DALSA("couldn't read data", hdl->ipcm);
  919. hdl->sio.eof = 1;
  920. }
  921. return 0;
  922. @@ -989,7 +749,7 @@ static size_t
  923. sio_alsa_write(struct sio_hdl *sh, const void *buf, size_t len)
  924. {
  925. struct sio_alsa_hdl *hdl = (struct sio_alsa_hdl *)sh;
  926. - snd_pcm_sframes_t n;
  927. + int n;
  928. size_t todo;
  929. if (len < hdl->obpf || hdl->opartial > 0) {
  930. @@ -1007,7 +767,7 @@ sio_alsa_write(struct sio_hdl *sh, const void *buf, size_t len)
  931. todo = len / hdl->obpf;
  932. if (todo == 0)
  933. return 0;
  934. - while ((n = snd_pcm_writei(hdl->opcm, buf, todo)) < 0) {
  935. + while ((n = pcm_writei(hdl->opcm, buf, todo)) < 0) {
  936. if (n == -EINTR)
  937. continue;
  938. if (n == -ESTRPIPE || n == -EPIPE) {
  939. @@ -1015,7 +775,7 @@ sio_alsa_write(struct sio_hdl *sh, const void *buf, size_t len)
  940. return 0;
  941. }
  942. if (n != -EAGAIN) {
  943. - DALSA("couldn't write data", n);
  944. + DALSA("couldn't write data", hdl->opcm);
  945. hdl->sio.eof = 1;
  946. }
  947. return 0;
  948. @@ -1062,16 +822,14 @@ sio_alsa_onmove(struct sio_alsa_hdl *hdl)
  949. static int
  950. sio_alsa_nfds(struct sio_hdl *sh)
  951. {
  952. - struct sio_alsa_hdl *hdl = (struct sio_alsa_hdl *)sh;
  953. -
  954. - return hdl->nfds;
  955. + return 2;
  956. }
  957. static int
  958. sio_alsa_pollfd(struct sio_hdl *sh, struct pollfd *pfd, int events)
  959. {
  960. struct sio_alsa_hdl *hdl = (struct sio_alsa_hdl *)sh;
  961. - int i;
  962. + int i, nfds;
  963. if (hdl->sio.eof)
  964. return 0;
  965. @@ -1083,100 +841,86 @@ sio_alsa_pollfd(struct sio_hdl *sh, struct pollfd *pfd, int events)
  966. hdl->events &= ~POLLIN;
  967. if (!hdl->sio.started)
  968. hdl->events = 0;
  969. - memset(pfd, 0, sizeof(struct pollfd) * hdl->nfds);
  970. - hdl->onfds = hdl->infds = 0;
  971. + memset(pfd, 0, sizeof(struct pollfd) * 2);
  972. + nfds = 0;
  973. if (hdl->events & POLLOUT) {
  974. if (!hdl->running &&
  975. - snd_pcm_state(hdl->opcm) == SND_PCM_STATE_RUNNING)
  976. + pcm_state(hdl->opcm) == PCM_STATE_RUNNING)
  977. sio_alsa_onmove(hdl);
  978. - hdl->onfds = snd_pcm_poll_descriptors(hdl->opcm,
  979. - pfd, hdl->nfds);
  980. - if (hdl->onfds < 0) {
  981. - DALSA("couldn't poll play descriptors",
  982. - hdl->onfds);
  983. - hdl->sio.eof = 1;
  984. - return 0;
  985. - }
  986. +
  987. + pfd[0].fd = pcm_get_poll_fd(hdl->opcm);
  988. + pfd[0].events = POLLOUT;
  989. + nfds++;
  990. }
  991. if (hdl->events & POLLIN) {
  992. if (!hdl->running &&
  993. - snd_pcm_state(hdl->ipcm) == SND_PCM_STATE_RUNNING)
  994. + pcm_state(hdl->ipcm) == PCM_STATE_RUNNING)
  995. sio_alsa_onmove(hdl);
  996. - hdl->infds = snd_pcm_poll_descriptors(hdl->ipcm,
  997. - pfd + hdl->onfds, hdl->nfds - hdl->onfds);
  998. - if (hdl->infds < 0) {
  999. - DALSA("couldn't poll rec descriptors",
  1000. - hdl->infds);
  1001. - hdl->sio.eof = 1;
  1002. - return 0;
  1003. - }
  1004. +
  1005. + pfd[nfds].fd = pcm_get_poll_fd(hdl->ipcm);
  1006. + pfd[nfds].events = POLLIN;
  1007. + nfds++;
  1008. }
  1009. - DPRINTFN(4, "sio_alsa_pollfd: events = %x, nfds = %d + %d\n",
  1010. - events, hdl->onfds, hdl->infds);
  1011. + DPRINTFN(4, "sio_alsa_pollfd: events = %x, nfds = %d\n",
  1012. + events, nfds);
  1013. - for (i = 0; i < hdl->onfds + hdl->infds; i++) {
  1014. + for (i = 0; i < nfds; i++) {
  1015. DPRINTFN(4, "sio_alsa_pollfd: pfds[%d].events = %x\n",
  1016. i, pfd[i].events);
  1017. }
  1018. - return hdl->onfds + hdl->infds;
  1019. + return nfds;
  1020. }
  1021. int
  1022. sio_alsa_revents(struct sio_hdl *sh, struct pollfd *pfd)
  1023. {
  1024. struct sio_alsa_hdl *hdl = (struct sio_alsa_hdl *)sh;
  1025. - snd_pcm_sframes_t iused, oavail, oused;
  1026. - snd_pcm_state_t istate, ostate;
  1027. - unsigned short revents, r;
  1028. - int nfds, err, i;
  1029. + struct timespec ts;
  1030. + unsigned iused, oavail, oused;
  1031. + int istate, ostate;
  1032. + unsigned short revents;
  1033. + int nfds, i;
  1034. if (hdl->sio.eof)
  1035. return POLLHUP;
  1036. - for (i = 0; i < hdl->onfds + hdl->infds; i++) {
  1037. + nfds = 0;
  1038. + if (hdl->events & POLLOUT)
  1039. + nfds++;
  1040. + if (hdl->events & POLLIN)
  1041. + nfds++;
  1042. +
  1043. + for (i = 0; i < nfds; i++) {
  1044. DPRINTFN(4, "sio_alsa_revents: pfds[%d].revents = %x\n",
  1045. i, pfd[i].revents);
  1046. }
  1047. revents = nfds = 0;
  1048. if (hdl->events & POLLOUT) {
  1049. - err = snd_pcm_poll_descriptors_revents(hdl->opcm,
  1050. - pfd, hdl->onfds, &r);
  1051. - if (err < 0) {
  1052. - DALSA("couldn't get play events", err);
  1053. - hdl->sio.eof = 1;
  1054. - return POLLHUP;
  1055. - }
  1056. - revents |= r;
  1057. - nfds += hdl->onfds;
  1058. + revents |= pfd[0].revents;
  1059. + ++nfds;
  1060. }
  1061. if (hdl->events & POLLIN) {
  1062. - err = snd_pcm_poll_descriptors_revents(hdl->ipcm,
  1063. - pfd + nfds, hdl->infds, &r);
  1064. - if (err < 0) {
  1065. - DALSA("couldn't get rec events", err);
  1066. - hdl->sio.eof = 1;
  1067. - return POLLHUP;
  1068. - }
  1069. - revents |= r;
  1070. - nfds += hdl->infds;
  1071. + revents |= pfd[nfds].revents;
  1072. + ++nfds;
  1073. }
  1074. if (hdl->sio.mode & SIO_PLAY) {
  1075. - ostate = snd_pcm_state(hdl->opcm);
  1076. - if (ostate == SND_PCM_STATE_XRUN) {
  1077. + ostate = pcm_state(hdl->opcm);
  1078. + if (ostate == PCM_STATE_XRUN) {
  1079. if (!sio_alsa_xrun(hdl))
  1080. return POLLHUP;
  1081. return 0;
  1082. }
  1083. - if (ostate == SND_PCM_STATE_RUNNING ||
  1084. - ostate == SND_PCM_STATE_PREPARED) {
  1085. - oavail = snd_pcm_avail_update(hdl->opcm);
  1086. - if (oavail < 0) {
  1087. + if (ostate == PCM_STATE_RUNNING ||
  1088. + ostate == PCM_STATE_PREPARED) {
  1089. + if (pcm_get_htimestamp(hdl->opcm, &oavail, &ts) != 0) {
  1090. + /*
  1091. if (oavail == -EPIPE || oavail == -ESTRPIPE) {
  1092. if (!sio_alsa_xrun(hdl))
  1093. return POLLHUP;
  1094. return 0;
  1095. }
  1096. - DALSA("couldn't get play buffer ptr", oavail);
  1097. + */
  1098. + DPRINTF("couldn't get play buffer ptr\n");
  1099. hdl->sio.eof = 1;
  1100. return POLLHUP;
  1101. }
  1102. @@ -1186,22 +930,23 @@ sio_alsa_revents(struct sio_hdl *sh, struct pollfd *pfd)
  1103. }
  1104. }
  1105. if (hdl->sio.mode & SIO_REC) {
  1106. - istate = snd_pcm_state(hdl->ipcm);
  1107. - if (istate == SND_PCM_STATE_XRUN) {
  1108. + istate = pcm_state(hdl->ipcm);
  1109. + if (istate == PCM_STATE_XRUN) {
  1110. if (!sio_alsa_xrun(hdl))
  1111. return POLLHUP;
  1112. return 0;
  1113. }
  1114. - if (istate == SND_PCM_STATE_RUNNING ||
  1115. - istate == SND_PCM_STATE_PREPARED) {
  1116. - iused = snd_pcm_avail_update(hdl->ipcm);
  1117. - if (iused < 0) {
  1118. + if (istate == PCM_STATE_RUNNING ||
  1119. + istate == PCM_STATE_PREPARED) {
  1120. + if (pcm_get_htimestamp(hdl->ipcm, &iused, &ts) != 0) {
  1121. + /*
  1122. if (iused == -EPIPE || iused == -ESTRPIPE) {
  1123. if (!sio_alsa_xrun(hdl))
  1124. return POLLHUP;
  1125. return 0;
  1126. }
  1127. - DALSA("couldn't get rec buffer ptr", iused);
  1128. + */
  1129. + DPRINTF("couldn't get rec buffer ptr\n");
  1130. hdl->sio.eof = 1;
  1131. return POLLHUP;
  1132. }
  1133. --
  1134. 2.37.3