详细代码分析:
external/tinyalsa/tinyplay.c
main()
- 参数解析
- play_sample()
- pcm_open()
| + snprintf(fn, sizeof(fn), “/dev/snd/pcmC%uD%u%c”, card, device,
| | flags & PCM_IN ? ‘c’ : ‘p’);
| + pcm->fd = open(fn, O_RDWR|O_NONBLOCK); // 打开/dev/snd…设备
| |
| + ioctl(pcm->fd, SNDRV_PCM_IOCTL_HW_PARAMS, ¶ms)
| + ioctl(pcm->fd, SNDRV_PCM_IOCTL_SW_PARAMS, &sparams)
| - do { pcm_write() } while()
| + // pcm_write()
| + if (!pcm->running) {
| | pcm_prepare(pcm); // ioctl(pcm->fd, SNDRV_PCM_IOCTL_PREPARE)
| | ioctl(pcm->fd, SNDRV_PCM_IOCTL_WRITEI_FRAMES, &x)
| | return 0;
| | }
| |
| + // 通过ioctl写数据 -
- ioctl(pcm->fd, SNDRV_PCM_IOCTL_WRITEI_FRAMES, &x)
- pcm_open()