浅析放音模式--向/dev/dsp设备write写入音频数据的代码流
《浅析打开/dev/dsp设备节点代码流程》《浅析uda134x声卡驱动probe的精简步骤》
《浅析alsa声卡放音模式时s3c24xx处理器DMA中断如何建立和处理》
/dev/dsp设备节点在被打开之后,文件方法集fops被重新定向到:snd_pcm_oss_f_reg
static const struct file_operations snd_pcm_oss_f_reg =
{
.owner = THIS_MODULE,
.read = snd_pcm_oss_read,
.write = snd_pcm_oss_write,
.open = snd_pcm_oss_open,
.release = snd_pcm_oss_release,
.poll = snd_pcm_oss_poll,
.unlocked_ioctl = snd_pcm_oss_ioctl,
.compat_ioctl = snd_pcm_oss_ioctl_compat,
.mmap = snd_pcm_oss_mmap,
};
所以对/dev/dsp设备节点的write(fd, buf, counts)写操作将对应执行函数snd_pcm_oss_write,下面我们看看该函数实现.
static ssize_t snd_pcm_oss_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
{
struct snd_pcm_oss_file *pcm_oss_file;
struct snd_pcm_substream *substream;
long result;
pcm_oss_file = file->private_data;
substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK]; // 获取放音stream流结构体
if (substream == NULL)
return -ENXIO;
substream->f_flags = file->f_flags & O_NONBLOCK;
result = snd_pcm_oss_write1(substream, buf, count); // 将音频数据发送到外围音频硬件[luther.gliethttp]
《浅析alsa声卡驱动snd_pcm_oss_write1函数》#ifdef OSS_DEBUG
printk(KERN_DEBUG "pcm_oss: write %li bytes (wrote %li bytes)\n",
(long)count, (long)result);
#endif
return result;
}
阅读(2088) | 评论(0) | 转发(0) |