[pulseaudio-discuss] [PATCH] alsa-ucm: Make combination port names deterministic

Arun Raghavan arun.raghavan at collabora.co.uk
Tue Sep 17 05:28:51 PDT 2013


On Thu, 2013-08-22 at 02:02 +0200, Damir Jelić wrote:
> On Wed, Aug 21, 2013 at 03:00:29PM +0530, Arun Raghavan wrote:
> > At the moment, port names combined from multiple devices are generated
> > based on the order that the devices are specified in config. This makes
> > programmatic use of thsee ports a bit painful, so let's make them be
> > combined in alphabetical order.
> > ---
> >  src/modules/alsa/alsa-ucm.c | 21 ++++++++++++++++++---
> >  1 file changed, 18 insertions(+), 3 deletions(-)
> > 
> > diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c
> > index a6ee9a8..d88c80b 100644
> > --- a/src/modules/alsa/alsa-ucm.c
> > +++ b/src/modules/alsa/alsa-ucm.c
> > @@ -671,6 +671,14 @@ int pa_alsa_ucm_get_verb(snd_use_case_mgr_t *uc_mgr, const char *verb_name, cons
> >      return 0;
> >  }
> >  
> > +static int pa_alsa_ucm_device_cmp(const void *a, const void *b)
> > +{
> 
> Opening bracket not on the same line as the expression.
> 
> > +    const pa_alsa_ucm_device *d1 = *(pa_alsa_ucm_device **)a;
> > +    const pa_alsa_ucm_device *d2 = *(pa_alsa_ucm_device **)b;
> > +
> > +    return strcmp(pa_proplist_gets(d1->proplist, PA_ALSA_PROP_UCM_NAME), pa_proplist_gets(d2->proplist, PA_ALSA_PROP_UCM_NAME));
> > +}
> > +
> >  static void ucm_add_port_combination(
> >          pa_hashmap *hash,
> >          pa_alsa_ucm_mapping_context *context,
> > @@ -687,9 +695,16 @@ static void ucm_add_port_combination(
> >      char *name, *desc;
> >      const char *dev_name;
> >      const char *direction;
> > -    pa_alsa_ucm_device *dev;
> > +    pa_alsa_ucm_device *sorted[num], *dev;
> > +
> > +    for (i = 0; i < num; i++)
> > +        sorted[i] = pdevices[i];
> 
> Couldn't we use memcpy() here which would possibly be faster?

I prefer the readability of doing it explicitly in
non-performance-sensitive code.

> > +
> > +    /* Sort by alphabetical order so as to have a deterministic naming scheme
> > +     * for combination ports */
> > +    qsort(&sorted[0], num, sizeof(pa_alsa_ucm_device *), pa_alsa_ucm_device_cmp);
> >  
> > -    dev = pdevices[0];
> > +    dev = sorted[0];
> >      dev_name = pa_proplist_gets(dev->proplist, PA_ALSA_PROP_UCM_NAME);
> >  
> >      name = pa_sprintf_malloc("%s%s", is_sink ? PA_UCM_PRE_TAG_OUTPUT : PA_UCM_PRE_TAG_INPUT, dev_name);
> > @@ -701,7 +716,7 @@ static void ucm_add_port_combination(
> >      for (i = 1; i < num; i++) {
> >          char *tmp;
> >  
> > -        dev = pdevices[i];
> > +        dev = sorted[i];
> >          dev_name = pa_proplist_gets(dev->proplist, PA_ALSA_PROP_UCM_NAME);
> >  
> >          tmp = pa_sprintf_malloc("%s+%s", name, dev_name);
> 
> Rest looks sensible. I haven't compile or run tested this, just wanted to 
> make sure that the coding style error doesn't get in since I posted patches 
> that should fix all of these "bracket style" issues.

Thanks for looking through - I'll fix that.

-- Arun



More information about the pulseaudio-discuss mailing list