media-session: make the services more modular

This commit is contained in:
Wim Taymans 2019-11-20 16:18:46 +01:00
parent b7aa8f5c85
commit 80ac755670
13 changed files with 567 additions and 354 deletions

View file

@ -22,8 +22,15 @@
* DEALINGS IN THE SOFTWARE.
*/
#include "pipewire/pipewire.h"
#include "pipewire/array.h"
#include <extensions/metadata.h>
#include "media-session.h"
#define NAME "metadata"
#define pw_metadata_emit(hooks,method,version,...) \
spa_hook_list_call_simple(hooks, struct pw_metadata_events, \
method, version, ##__VA_ARGS__)
@ -54,17 +61,18 @@ static void set_item(struct item *item, uint32_t subject, const char *key, const
item->value = strdup(value);
}
struct sm_metadata {
struct metadata {
struct pw_metadata impl;
struct sm_media_session *session;
struct spa_hook_list hooks;
struct pw_properties *properties;
struct pw_array metadata;
struct pw_proxy *proxy;
};
static void emit_properties(struct sm_metadata *this, const struct spa_dict *dict)
static void emit_properties(struct metadata *this, const struct spa_dict *dict)
{
struct item *item;
pw_array_for_each(item, &this->metadata) {
@ -81,7 +89,7 @@ static int impl_add_listener(void *object,
const struct pw_metadata_events *events,
void *data)
{
struct sm_metadata *this = object;
struct metadata *this = object;
struct spa_hook_list save;
spa_return_val_if_fail(this != NULL, -EINVAL);
@ -96,7 +104,7 @@ static int impl_add_listener(void *object,
return 0;
}
static struct item *find_item(struct sm_metadata *this, uint32_t subject, const char *key)
static struct item *find_item(struct metadata *this, uint32_t subject, const char *key)
{
struct item *item;
@ -107,7 +115,7 @@ static struct item *find_item(struct sm_metadata *this, uint32_t subject, const
return NULL;
}
static void clear_items(struct sm_metadata *this)
static void clear_items(struct metadata *this)
{
struct item *item;
@ -123,7 +131,7 @@ static int impl_set_property(void *object,
const char *type,
const char *value)
{
struct sm_metadata *this = object;
struct metadata *this = object;
struct item *item = NULL;
if (key == NULL)
@ -160,7 +168,7 @@ static int impl_set_property(void *object,
static int impl_clear(void *object)
{
struct sm_metadata *this = object;
struct metadata *this = object;
clear_items(this);
return 0;
}
@ -172,18 +180,13 @@ struct pw_metadata_methods impl_metadata = {
.clear = impl_clear,
};
struct sm_metadata *
sm_metadata_new(struct pw_properties *props)
void *sm_metadata_start(struct sm_media_session *sess)
{
struct sm_metadata *md;
if (props == NULL)
props = pw_properties_new(NULL, NULL);
if (props == NULL)
return NULL;
struct metadata *md;
md = calloc(1, sizeof(*md));
md->properties = props;
md->session = sess;
md->properties = pw_properties_new(NULL, NULL);
pw_array_init(&md->metadata, 4096);
md->impl.iface = SPA_INTERFACE_INIT(
@ -192,13 +195,23 @@ sm_metadata_new(struct pw_properties *props)
&impl_metadata, md);
spa_hook_list_init(&md->hooks);
md->proxy = sm_media_session_export(sess,
PW_TYPE_INTERFACE_Metadata,
NULL,
&md->impl,
0);
return md;
}
void sm_metadata_destroy(struct sm_metadata *this)
int sm_metadata_stop(void *data)
{
struct metadata *this = data;
pw_proxy_destroy(this->proxy);
clear_items(this);
pw_array_clear(&this->metadata);
pw_properties_free(this->properties);
free(this);
return 0;
}