From patchwork Thu Apr 13 06:52:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fuweix.tang@intel.com X-Patchwork-Id: 9678779 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 48233601C3 for ; Thu, 13 Apr 2017 07:01:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A87E28633 for ; Thu, 13 Apr 2017 07:01:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F7D128637; Thu, 13 Apr 2017 07:01:22 +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 7B5062861E for ; Thu, 13 Apr 2017 07:01:21 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id CD723267064; Thu, 13 Apr 2017 08:53:11 +0200 (CEST) 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 1D00D267050; Thu, 13 Apr 2017 08:53:09 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by alsa0.perex.cz (Postfix) with ESMTP id 94CA0266AD7 for ; Thu, 13 Apr 2017 08:53:03 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Apr 2017 23:53:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,193,1488873600"; d="scan'208";a="73475777" Received: from tangfw-thinkpad-x230.sh.intel.com ([10.239.47.88]) by orsmga002.jf.intel.com with ESMTP; 12 Apr 2017 23:53:01 -0700 From: fuweix.tang@intel.com To: alsa-devel@alsa-project.org Date: Thu, 13 Apr 2017 14:52:47 +0800 Message-Id: <1a5aaddf0d9c7937d3ebdecedc23c3eb65ff81ef.1492065639.git.fuweix.tang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Cc: tiwai@suse.de, liam.r.girdwood@linux.intel.com, Fuwei Tang , mengdong.lin@intel.com Subject: [alsa-devel] [PATCH 4/4] topology: Group elements with the same index value into a block 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: Fuwei Tang Topology objects(widgets,controls) with different index value should be grouped into different blocks and the block headers contain the index value. Signed-off-by: Fuwei Tang Reviewed-by: Mengdong Lin --- src/topology/builder.c | 94 +++++++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 43 deletions(-) diff --git a/src/topology/builder.c b/src/topology/builder.c index dcd9e2a..ca5cbe1 100644 --- a/src/topology/builder.c +++ b/src/topology/builder.c @@ -86,58 +86,66 @@ static int write_block_header(snd_tplg_t *tplg, unsigned int type, static int write_elem_block(snd_tplg_t *tplg, struct list_head *base, int size, int tplg_type, const char *obj_name) { - struct list_head *pos; - struct tplg_elem *elem; - int ret, wsize = 0, count = 0, vendor_type; + struct list_head *pos, *sub_pos, *sub_base; + struct tplg_elem *elem, *elem_next; + int ret, wsize = 0, total_size = 0, count = 0, block_size = 0; - /* count number of elements */ - list_for_each(pos, base) - count++; - if (!count) - return 0; - - /* write the header for this block */ - elem = list_entry(base->next, struct tplg_elem, list); - vendor_type = elem->vendor_type; - - ret = write_block_header(tplg, tplg_type, vendor_type, - tplg->version, 0, size, count); - if (ret < 0) { - SNDERR("error: failed to write %s block %d\n", - obj_name, ret); - return ret; - } - - /* write each elem to block */ + sub_base = base; list_for_each(pos, base) { - + /* find elems with the same index to make a block */ elem = list_entry(pos, struct tplg_elem, list); + elem_next = list_entry(pos->next, struct tplg_elem, list); + block_size += elem->size; + count++; - /* compound elems have already been copied to other elems */ - if (elem->compound_elem) - continue; - - if (elem->type != SND_TPLG_TYPE_DAPM_GRAPH) - verbose(tplg, " %s '%s': write %d bytes\n", - obj_name, elem->id, elem->size); - else - verbose(tplg, " %s '%s': write %d bytes\n", - obj_name, elem->route->source, elem->size); - - count = write(tplg->out_fd, elem->obj, elem->size); - if (count < 0) { - SNDERR("error: failed to write %s %d\n", - obj_name, ret); - return ret; + if ((pos->next == base) || (elem_next->index != elem->index)) { + /* write header for the block */ + ret = write_block_header(tplg, tplg_type, elem->vendor_type, + tplg->version, elem->index, block_size, count); + if (ret < 0) { + SNDERR("error: failed to write %s block %d\n", + obj_name, ret); + return ret; + } + + /* write elems for the block */ + list_for_each(sub_pos, sub_base) { + elem = list_entry(sub_pos, struct tplg_elem, list); + /* compound elems have already been copied to other elems */ + if (elem->compound_elem) + continue; + + if (elem->type != SND_TPLG_TYPE_DAPM_GRAPH) + verbose(tplg, " %s '%s': write %d bytes\n", + obj_name, elem->id, elem->size); + else + verbose(tplg, " %s '%s': write %d bytes\n", + obj_name, elem->route->source, elem->size); + + wsize = write(tplg->out_fd, elem->obj, elem->size); + if (wsize < 0) { + SNDERR("error: failed to write %s %d\n", + obj_name, ret); + return ret; + } + + total_size += wsize; + /* get to the end of sub list */ + if (sub_pos == pos) + break; + } + /* the last elem of the current sub list as the head of + next sub list*/ + sub_base = pos; + count = 0; + block_size = 0; } - - wsize += count; } /* make sure we have written the correct size */ - if (wsize != size) { + if (total_size != size) { SNDERR("error: size mismatch. Expected %d wrote %d\n", - size, wsize); + size, total_size); return -EIO; }