mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 11:26:12 +08:00
audio/composite: merge composite instance allocate to one times
here is not need to allocate two times Signed-off-by: chao an <anchao.archer@bytedance.com>
This commit is contained in:
+22
-25
@@ -51,8 +51,8 @@ struct audio_comp_priv_s
|
|||||||
|
|
||||||
/* This is the contained, low-level audio device array and count. */
|
/* This is the contained, low-level audio device array and count. */
|
||||||
|
|
||||||
FAR struct audio_lowerhalf_s **lower;
|
|
||||||
int count;
|
int count;
|
||||||
|
FAR struct audio_lowerhalf_s *lower[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -942,30 +942,31 @@ FAR struct audio_lowerhalf_s *audio_comp_initialize(FAR const char *name,
|
|||||||
{
|
{
|
||||||
FAR struct audio_comp_priv_s *priv;
|
FAR struct audio_comp_priv_s *priv;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int ret = -ENOMEM;
|
int ret;
|
||||||
int i;
|
int i = 0;
|
||||||
|
|
||||||
priv = kmm_zalloc(sizeof(struct audio_comp_priv_s));
|
va_start(ap, name);
|
||||||
|
while (va_arg(ap, FAR void *))
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
priv = kmm_zalloc(sizeof(struct audio_comp_priv_s) +
|
||||||
|
sizeof(FAR void *) * (i - 1));
|
||||||
if (priv == NULL)
|
if (priv == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
priv->export.ops = &g_audio_comp_ops;
|
priv->export.ops = &g_audio_comp_ops;
|
||||||
|
priv->count = i;
|
||||||
va_start(ap, name);
|
|
||||||
while (va_arg(ap, FAR struct audio_lowerhalf_s *))
|
|
||||||
{
|
|
||||||
priv->count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
va_end(ap);
|
|
||||||
priv->lower = kmm_calloc(priv->count,
|
|
||||||
sizeof(FAR struct audio_lowerhalf_s *));
|
|
||||||
if (priv->lower == NULL)
|
|
||||||
{
|
|
||||||
goto free_priv;
|
|
||||||
}
|
|
||||||
|
|
||||||
va_start(ap, name);
|
va_start(ap, name);
|
||||||
for (i = 0; i < priv->count; i++)
|
for (i = 0; i < priv->count; i++)
|
||||||
@@ -980,20 +981,16 @@ FAR struct audio_lowerhalf_s *audio_comp_initialize(FAR const char *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if (name != NULL)
|
if (name != NULL)
|
||||||
{
|
{
|
||||||
ret = audio_register(name, &priv->export);
|
ret = audio_register(name, &priv->export);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
goto free_lower;
|
kmm_free(priv);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &priv->export;
|
return &priv->export;
|
||||||
|
|
||||||
free_lower:
|
|
||||||
kmm_free(priv->lower);
|
|
||||||
free_priv:
|
|
||||||
kmm_free(priv);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user