资源描述:
《alsa声卡dev_snd_pcmc0d0p的open打开流程》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、alsa声卡/dev/snd/pcmC0D0p的open打开流程 原文地址:http://blog.chinaunix.net/space.php?uid=20564848&do=blog&cuid=2116725aplay.c==>main==>snd_pcm_open(&handle,pcm_name,stream,open_mode);//打开一路pcm,刷新config配置如果是"default",同时type等于SND_CONFIG_TYPE_COMPOUND那么这里对应"empty"staticconstch
2、ar*constbuild_in_pcms[]={ "adpcm","alaw","copy","dmix","file","hooks","hw","ladspa","lfloat", "linear","meter","mulaw","multi","null","empty","plug","rate","route","share", "shm","dsnoop","dshare","asym","iec958","softvol","mmap_emul", NULL};_snd_pcm_empty
3、_open和snd_pcm_open_named_slave==>snd_pcm_open_conf(pcmp,name,root,conf,stream,mode);==>open_func=snd_dlobj_cache_lookup(open_name);将获得lib库中_snd_pcm_empty_open函数 所以open_func将等于_snd_pcm_empty_open _snd_pcm_empty_open _snd_pcm_asym_open _snd_pcm_plug_open
4、 _snd_pcm_softvol_open _snd_pcm_dmix_open _snd_pcm_hw_open ==>snd_pcm_hw_open(pcmp,name,card,device,subdevice,stream, mode
5、(nonblock?SND_PCM_NONBLOCK:0), 0,sync_ptr_ioctl);==>snd_ctl_hw_openfilename等于"/dev/snd/controlC0"==>snd_ope
6、n_device(filename,fmode); ctl->ops=&snd_ctl_hw_ops; ctl->private_data=hw; ctl->poll_fd=fd; *handle=ctl;filename等于"/dev/snd/pcmC0D0p"==>fd=snd_open_device(filename,fmode);==>returnsnd_pcm_hw_open_fd(pcmp,name,fd,0,sync_ptr_ioctl);==>snd_pcm_new(&pcm,SND_PCM
7、_TYPE_HW,name,info.stream,mode); pcm->ops=&snd_pcm_hw_ops; pcm->fast_ops=&snd_pcm_hw_fast_ops;staticintsnd_pcm_hw_mmap_control(snd_pcm_t*pcm){ snd_pcm_hw_t*hw=pcm->private_data; void*ptr; interr; if(hw->sync_ptr==NULL){//如果还没有mmap,那么执行mmap映射内核空间驱动使用的声音
8、缓冲区 ptr=mmap(NULL,page_align(sizeof(structsndrv_pcm_mmap_control)), PROT_READ
9、PROT_WRITE,MAP_FILE
10、MAP_SHARED, hw->fd,SNDRV_PCM_MMAP_OFFSET_CONTROL); if(ptr==MAP_FAILED
11、
12、ptr==NULL){ err=-errno; SYSMSG("controlmmapfaile
13、d"); returnerr; } hw->mmap_control=ptr;//声卡驱动头部填充了一个结构体sndrv_pcm_mmap_control,类似qvfb显示原理.//structsndrv_pcm_mmap_control{// sndrv_pcm_