Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15358693
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类: LINUX

2009-11-19 14:18:10

浅析放音模式--向/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;
}
阅读(2042) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~