4.hda设备中的pcm文件 (第七部分)

本文详细介绍了Linux内核中hda设备pcm文件的构建过程,包括snd_hda_codec_build_pcms、snd_hda_codec_parse_pcms和snd_hda_attach_pcm_stream函数的作用。内容涉及模拟设备的判断、pcm设备名称设置、hda_pcm结构的生成以及pcm文件的注册,最终使音频播放和录制功能得以实现。
摘要由CSDN通过智能技术生成

4.6 构建pcm

接着上节的内容,现在来看看构建pcm的过程。

4.6.1 snd_hda_codec_build_pcms

int snd_hda_codec_build_pcms(struct hda_codec *codec)
{
	struct hda_bus *bus = codec->bus;
	struct hda_pcm *cpcm;
	int dev, err;

	err = snd_hda_codec_parse_pcms(codec);
	if (err < 0)
		return err;

	/* attach a new PCM streams */
	list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
		if (cpcm->pcm)
			continue; /* already attached */
		if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams)
			continue; /* no substreams assigned */

		dev = get_empty_pcm_device(bus, cpcm->pcm_type);
		if (dev < 0) {
			cpcm->device = SNDRV_PCM_INVALID_DEVICE;
			continue; /* no fatal error */
		}
		cpcm->device = dev;
		err =  snd_hda_attach_pcm_stream(bus, codec, cpcm);
		if (err < 0) {
			codec_err(codec,
				  "cannot attach PCM stream %d for codec #%d\n",
				  dev, codec->core.addr);
			continue; /* no fatal error */
		}
	}

	return 0;
}

snd_hda_codec_parse_pcms的作用是根据codec的信息生成对应的hda_pcm对象。

snd_hda_attach_pcm_stream将调用snd_pcm_new 生成snd_pcm文件,也是我们这一章探寻的一个终点了。

下面将分别介绍这两个函数。

get_empty_pcm_device,这个函数我不太理解。给hda_bus中的pcm_dev_bits赋了值,但遍寻代码,也没发现pcm_dev_bits有什么用处。

4.6.2 snd_hda_codec_parse_pcms

int snd_hda_codec_parse_pcms(struct hda_codec *codec)
{
	struct hda_pcm *cpcm;
	int err;
    // 如果codec->pcm_list_head为空,说明已经解析过了,返回
	if (!list_empty(&codec->pcm_list_head))
		return 0; /* already parsed */
// 要通过patch_ops.build_pcms来完成,之前看过具体的设置了
	if (!codec->patch_ops.build_pcms)
		return 0;

	err = codec->patch_ops.build_pcms(codec);
	if (err < 0) {
		codec_err(codec, "cannot build PCMs for #%d (error %d)\n",
			  codec->core.addr, err);
		return err;
	}
    // 遍历设置所有的stream信息
	list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
		int stream;

		for (stream = 0; stream < 2; stream++) {
			struct hda_pcm_stream *info = &cpcm->stream[stream];

			if (!info->substreams)
				continue;
			err = set_pcm_default_values(codec, info);
			if (err < 0) {
				codec_warn(codec,
					   "fail to setup d
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值