- 论坛徽章:
- 0
|
ALSA
card 和组件管理
card 管理声卡的所有设备,如PCM ,mixers, MIDI,synthesizer
struct snd_card *snd_card_new(int idx, const char * xid, struct module *module,
int extra_size);
idx 索引号 ,xid 标志字符串,extra_size 将作为card->private_data指向的内存大小
int snd_device_new(struct snd_card *card,snd_device_type_t type, void *device_data,
struct snd_device_ops *ops);
芯片特定数据
struct xxxchip 包含芯片相关的IO端口地址,资源指针,中断号等。
方法1:
struct xxx_chip
{
....
};
card = snd_card_new(index,id,THIS_MODULE,sizepf(struct xxxchip));
struct xxxchip *chip = card->private_data;
方法2:
struct snd_card *card;
struct xxxchip *chip;
card = snd_card_new(index[dev],id[dev], THIS_MODULE,0);
....
struct xxxchip
{
struct snd_card *card;
...
};
chip->card = card;
static struct snd_device_ops ops =
{
dev_free= snd_xxx_chip_dev_free,//组件析构
};
.......
snd_device_new(card,SNDRV_DEV_LOWLEVEL,chip, &ops);
static int snd_xxx_chip_dev_free(struct snd_device *device)
{
return snd_xxx_chip_free(device->device_data);
}
int snd_card_register(struct snd_card *card);
int snd_card_free(struct snd_card *card);
//////////////////////////
一个PCM 随应一个设备文件,由播放和录音流组成,每个流又由子流组成
int snd_pcm_new(struct snd_card *card, char *id, int device,
int playback_count, int capture_count, struct snd_pcm **rpcm);
void snd_pcm_set_ops(strucct snd_pcm,int direction,struct snd_pcm_ops *ops)
direction :SNDRV_PCM_STREAM_PLAYBACK SNDRV_PCM_STREAM_CAPTURE;
struct snd_pcm_ops
{
int (*open)(struct snd_pcm_substream *substream);
int (*close)(struct snd_pcm_substream *substream);
int (*ioctl)(struct snd_pcm_substream *substream,unsigned int cmd,void *arg);
int (*hw_params)(struct snd_pcm_substream *substream,struct
snd_pcm_hw_params *params);//硬件参数
int (*hw_free)(struct snd_pcm_substream *substream);//资源释放
int (*prepare)(struct snd_pcm_substream *substream);//准备
int (*trigger)(struct snd_pcm_substream *substream,int cmd);//开始 停止 暂停时
snd_pcm_uframe_t(*pointer)(struct snd_pcm_substream *substream);
//当前缓冲区硬件位置
int (*copy)(struct snd_pcm_substream *substream,int channel,snd_pcm_uframe_t
pos, void __user *buf, snd_pcm_uframe_t count);
int (*silence)(struct snd_pcm_substream *substream,int channel,snd_pcm_uframe_t
pos, snd_pcm_uframe_t count);
struct page *(*page)(struct snd_pcm_substream, unsigned long offse);
int (*mmap)(struct snd_pcm_substream,struct vm_area_struct *vma);
int (*ack)(struct snd_pcm_substream);
}
所有操作通过snd_pcm_substream_chip()获得xxxchip指针
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/69624/showart_1080489.html |
|