From patchwork Thu Nov 3 23:08:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mengdong.lin@linux.intel.com X-Patchwork-Id: 9412091 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E1AA56022E for ; Fri, 4 Nov 2016 08:40:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9D522B0E3 for ; Fri, 4 Nov 2016 08:40:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE7602B0E5; Fri, 4 Nov 2016 08:40:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC0852B0E3 for ; Fri, 4 Nov 2016 08:40:33 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 41051267444; Fri, 4 Nov 2016 09:40:32 +0100 (CET) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id CFB75267198; Fri, 4 Nov 2016 09:38:06 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id BB40B267373; Fri, 4 Nov 2016 00:07:05 +0100 (CET) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by alsa0.perex.cz (Postfix) with ESMTP id C2D3E267356 for ; Fri, 4 Nov 2016 00:06:59 +0100 (CET) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP; 03 Nov 2016 16:06:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,440,1473145200"; d="scan'208";a="782155241" Received: from amanda-haswell-pc.sh.intel.com ([10.239.159.21]) by FMSMGA003.fm.intel.com with ESMTP; 03 Nov 2016 16:06:43 -0700 From: mengdong.lin@linux.intel.com To: alsa-devel@alsa-project.org Date: Fri, 4 Nov 2016 07:08:12 +0800 Message-Id: X-Mailer: git-send-email 2.5.0 In-Reply-To: References: Cc: Mengdong Lin , tiwai@suse.de, hardik.t.shah@intel.com, guneshwor.o.singh@intel.com, liam.r.girdwood@linux.intel.com, vinod.koul@intel.com, broonie@kernel.org, mengdong.lin@intel.com Subject: [alsa-devel] [PATCH 5/6] topology: Parse and build private data for PCM X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Mengdong Lin Users can define private for PCM (FE DAI & DAI links) elements by both text conf file and C API: - Text conf file may define multiple data blocks for a PCM and they will be merged in building phase; - Add private data to C API template of PCM object. Signed-off-by: Mengdong Lin diff --git a/include/topology.h b/include/topology.h index b6a6f19..481b408 100644 --- a/include/topology.h +++ b/include/topology.h @@ -611,6 +611,8 @@ extern "C" { * symmetric_rates "true" * symmetric_channels "true" * symmetric_sample_bits "false" + * + * data "name" # optional private data * } * * @@ -870,6 +872,7 @@ struct snd_tplg_pcm_template { struct snd_tplg_stream_caps_template *caps[2]; /*!< playback & capture for DAI */ unsigned int flag_mask; /*!< bitmask of flags to configure */ unsigned int flags; /*!< flag value SND_SOC_TPLG_LNK_FLGBIT_* */ + struct snd_soc_tplg_private *priv; /*!< private data */ int num_streams; /*!< number of supported configs */ struct snd_tplg_stream_template stream[0]; /*!< supported configs */ }; diff --git a/src/topology/pcm.c b/src/topology/pcm.c index 77b7605..3f54e94 100644 --- a/src/topology/pcm.c +++ b/src/topology/pcm.c @@ -73,12 +73,32 @@ static int tplg_build_stream_caps(snd_tplg_t *tplg, /* build a PCM (FE DAI & DAI link) element */ static int build_pcm(snd_tplg_t *tplg, struct tplg_elem *elem) { + struct tplg_ref *ref; + struct list_head *base, *pos; int err; err = tplg_build_stream_caps(tplg, elem->id, elem->pcm->caps); if (err < 0) return err; + /* merge private data from the referenced data elements */ + base = &elem->ref_list; + list_for_each(pos, base) { + + ref = list_entry(pos, struct tplg_ref, list); + if (ref->type == SND_TPLG_TYPE_DATA) { + err = tplg_copy_data(tplg, elem, ref); + if (err < 0) + return err; + } + if (!ref->elem) { + SNDERR("error: cannot find '%s' referenced by" + " PCM '%s'\n", ref->id, elem->id); + return -EINVAL; + } else if (err < 0) + return err; + } + return 0; } @@ -394,7 +414,7 @@ static int parse_flag(snd_config_t *n, unsigned int mask_in, return 0; } -/* Parse pcm (for front end DAI & DAI link) */ +/* Parse PCM (for front end DAI & DAI link) in text conf file */ int tplg_parse_pcm(snd_tplg_t *tplg, snd_config_t *cfg, void *private ATTRIBUTE_UNUSED) { @@ -501,6 +521,7 @@ int tplg_parse_be(snd_tplg_t *tplg, snd_config_iterator_t i, next; snd_config_t *n; const char *id, *val = NULL; + int err; elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_BE); if (!elem) @@ -540,6 +561,13 @@ int tplg_parse_be(snd_tplg_t *tplg, tplg_dbg("\t%s: %d\n", id, link->id); continue; } + + if (strcmp(id, "data") == 0) { + err = tplg_parse_data_refs(n, elem); + if (err < 0) + return err; + continue; + } } return 0; @@ -633,10 +661,11 @@ static void tplg_add_stream_caps(struct snd_soc_tplg_stream_caps *caps, caps->sig_bits = caps_tpl->sig_bits; } +/* Add a PCM element (FE DAI & DAI link) from C API */ int tplg_add_pcm_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) { struct snd_tplg_pcm_template *pcm_tpl = t->pcm; - struct snd_soc_tplg_pcm *pcm; + struct snd_soc_tplg_pcm *pcm, *_pcm; struct tplg_elem *elem; int i; @@ -675,6 +704,25 @@ int tplg_add_pcm_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) for (i = 0; i < pcm_tpl->num_streams; i++) tplg_add_stream_object(&pcm->stream[i], &pcm_tpl->stream[i]); + /* private data */ + if (pcm_tpl->priv != NULL && pcm_tpl->priv->size) { + tplg_dbg("\t priv data size %d\n", pcm_tpl->priv->size); + _pcm = realloc(pcm, + elem->size + pcm_tpl->priv->size); + if (!_pcm) { + tplg_elem_free(elem); + return -ENOMEM; + } + + pcm = _pcm; + elem->pcm = pcm; + elem->size += pcm_tpl->priv->size; + + memcpy(pcm->priv.data, pcm_tpl->priv->data, + pcm_tpl->priv->size); + pcm->priv.size = pcm_tpl->priv->size; + } + return 0; }