"Fossies" - the Fresh Open Source Software Archive

Member "alsa-lib-1.1.9/src/topology/ops.c" (10 May 2019, 3250 Bytes) of package /linux/misc/alsa-lib-1.1.9.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ops.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2   Copyright(c) 2014-2015 Intel Corporation
    3   All rights reserved.
    4 
    5   This library is free software; you can redistribute it and/or modify
    6   it under the terms of the GNU Lesser General Public License as
    7   published by the Free Software Foundation; either version 2.1 of
    8   the License, or (at your option) any later version.
    9 
   10   This program is distributed in the hope that it will be useful,
   11   but WITHOUT ANY WARRANTY; without even the implied warranty of
   12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13   GNU Lesser General Public License for more details.
   14 
   15   Authors: Mengdong Lin <mengdong.lin@intel.com>
   16            Yao Jin <yao.jin@intel.com>
   17            Liam Girdwood <liam.r.girdwood@linux.intel.com>
   18 */
   19 
   20 #include "list.h"
   21 #include "tplg_local.h"
   22 
   23 /* mapping of kcontrol text names to types */
   24 static const struct map_elem control_map[] = {
   25     {"volsw", SND_SOC_TPLG_CTL_VOLSW},
   26     {"volsw_sx", SND_SOC_TPLG_CTL_VOLSW_SX},
   27     {"volsw_xr_sx", SND_SOC_TPLG_CTL_VOLSW_XR_SX},
   28     {"enum", SND_SOC_TPLG_CTL_ENUM},
   29     {"bytes", SND_SOC_TPLG_CTL_BYTES},
   30     {"enum_value", SND_SOC_TPLG_CTL_ENUM_VALUE},
   31     {"range", SND_SOC_TPLG_CTL_RANGE},
   32     {"strobe", SND_SOC_TPLG_CTL_STROBE},
   33 };
   34 
   35 static int lookup_ops(const char *c)
   36 {
   37     unsigned int i;
   38 
   39     for (i = 0; i < ARRAY_SIZE(control_map); i++) {
   40         if (strcmp(control_map[i].name, c) == 0)
   41             return control_map[i].id;
   42     }
   43 
   44     /* cant find string name in our table so we use its ID number */
   45     return atoi(c);
   46 }
   47 
   48 /* Parse Control operations. Ops can come from standard names above or
   49  * bespoke driver controls with numbers >= 256
   50  */
   51 int tplg_parse_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
   52     snd_config_t *cfg, void *private)
   53 {
   54     snd_config_iterator_t i, next;
   55     snd_config_t *n;
   56     struct snd_soc_tplg_ctl_hdr *hdr = private;
   57     const char *id, *value;
   58 
   59     tplg_dbg("\tOps\n");
   60     hdr->size = sizeof(*hdr);
   61 
   62     snd_config_for_each(i, next, cfg) {
   63 
   64         n = snd_config_iterator_entry(i);
   65 
   66         /* get id */
   67         if (snd_config_get_id(n, &id) < 0)
   68             continue;
   69 
   70         /* get value - try strings then ints */
   71         if (snd_config_get_string(n, &value) < 0)
   72             continue;
   73 
   74         if (strcmp(id, "info") == 0)
   75             hdr->ops.info = lookup_ops(value);
   76         else if (strcmp(id, "put") == 0)
   77             hdr->ops.put = lookup_ops(value);
   78         else if (strcmp(id, "get") == 0)
   79             hdr->ops.get = lookup_ops(value);
   80 
   81         tplg_dbg("\t\t%s = %s\n", id, value);
   82     }
   83 
   84     return 0;
   85 }
   86 
   87 /* Parse External Control operations. Ops can come from standard names above or
   88  * bespoke driver controls with numbers >= 256
   89  */
   90 int tplg_parse_ext_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
   91     snd_config_t *cfg, void *private)
   92 {
   93     snd_config_iterator_t i, next;
   94     snd_config_t *n;
   95     struct snd_soc_tplg_bytes_control *be = private;
   96     const char *id, *value;
   97 
   98     tplg_dbg("\tExt Ops\n");
   99 
  100     snd_config_for_each(i, next, cfg) {
  101 
  102         n = snd_config_iterator_entry(i);
  103 
  104         /* get id */
  105         if (snd_config_get_id(n, &id) < 0)
  106             continue;
  107 
  108         /* get value - try strings then ints */
  109         if (snd_config_get_string(n, &value) < 0)
  110             continue;
  111 
  112         if (strcmp(id, "info") == 0)
  113             be->ext_ops.info = lookup_ops(value);
  114         else if (strcmp(id, "put") == 0)
  115             be->ext_ops.put = lookup_ops(value);
  116         else if (strcmp(id, "get") == 0)
  117             be->ext_ops.get = lookup_ops(value);
  118 
  119         tplg_dbg("\t\t%s = %s\n", id, value);
  120     }
  121 
  122     return 0;
  123 }