link: improve renegotiation

Only suspend an idle node when we need to configure a different format.
This commit is contained in:
Wim Taymans 2017-06-20 12:30:07 +02:00
parent 910318d71f
commit 3b5a308645
20 changed files with 190 additions and 38 deletions

View file

@ -59,3 +59,20 @@ spa_format_filter(const struct spa_format *format,
return res;
}
int
spa_format_compare(const struct spa_format *format1,
const struct spa_format *format2)
{
if (format1 == NULL || format2 == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (SPA_FORMAT_MEDIA_TYPE(format1) != SPA_FORMAT_MEDIA_TYPE(format2) ||
SPA_FORMAT_MEDIA_SUBTYPE(format1) != SPA_FORMAT_MEDIA_SUBTYPE(format2))
return SPA_RESULT_INVALID_MEDIA_TYPE;
return spa_props_compare(SPA_POD_CONTENTS(struct spa_format, format1),
SPA_POD_CONTENTS_SIZE(struct spa_format, format1),
SPA_POD_CONTENTS(struct spa_format, format2),
SPA_POD_CONTENTS_SIZE(struct spa_format, format2));
}

40
spa/lib/format.h Normal file
View file

@ -0,0 +1,40 @@
/* Simple Plugin API
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __SPA_LIBFORMAT_H__
#define __SPA_LIBFORMAT_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/props.h>
int spa_format_filter(const struct spa_format *format,
const struct spa_format *filter,
struct spa_pod_builder *result);
int spa_format_compare(const struct spa_format *format1,
const struct spa_format *format2);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_LIBFORMAT_H__ */

View file

@ -1,5 +1,6 @@
spalib_headers = [
'debug.h',
'format.h',
'props.h',
]

View file

@ -310,3 +310,40 @@ spa_props_filter(struct spa_pod_builder *b,
}
return SPA_RESULT_OK;
}
int spa_props_compare(const struct spa_pod *props1,
uint32_t props1_size,
const struct spa_pod *props2,
uint32_t props2_size)
{
const struct spa_pod *pr;
SPA_POD_FOREACH(props1, props1_size, pr) {
struct spa_pod_prop *p1, *p2;
void *a1, *a2;
if (pr->type != SPA_POD_TYPE_PROP)
continue;
p1 = (struct spa_pod_prop *) pr;
if ((p2 = find_prop(props2, props2_size, p1->body.key)) == NULL)
return SPA_RESULT_INCOMPATIBLE_PROPS;
/* incompatible property types */
if (p1->body.value.type != p2->body.value.type)
return SPA_RESULT_INCOMPATIBLE_PROPS;
if (p1->body.flags & SPA_POD_PROP_FLAG_UNSET ||
p2->body.flags & SPA_POD_PROP_FLAG_UNSET)
return SPA_RESULT_INCOMPATIBLE_PROPS;
a1 = SPA_MEMBER(p1, sizeof(struct spa_pod_prop), void);
a2 = SPA_MEMBER(p2, sizeof(struct spa_pod_prop), void);
if (compare_value(p1->body.value.type, a1, a2) != 0)
return SPA_RESULT_INCOMPATIBLE_PROPS;
}
return SPA_RESULT_OK;
}

View file

@ -32,6 +32,10 @@ int spa_props_filter(struct spa_pod_builder *b,
const struct spa_pod *filter,
uint32_t filter_size);
int spa_props_compare(const struct spa_pod *props1,
uint32_t props1_size,
const struct spa_pod *props2,
uint32_t props2_size);
#ifdef __cplusplus
} /* extern "C" */
#endif