2019-11-03 11:25:23 +01:00
|
|
|
/* Metadata API
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2019 Wim Taymans
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-11-20 16:18:46 +01:00
|
|
|
#include "pipewire/pipewire.h"
|
|
|
|
|
#include "pipewire/array.h"
|
|
|
|
|
|
2021-05-18 11:40:50 +10:00
|
|
|
#include <spa/utils/string.h>
|
|
|
|
|
|
2019-11-03 11:25:23 +01:00
|
|
|
#include <extensions/metadata.h>
|
|
|
|
|
|
2019-11-20 16:18:46 +01:00
|
|
|
#include "media-session.h"
|
|
|
|
|
|
|
|
|
|
#define NAME "metadata"
|
|
|
|
|
|
|
|
|
|
struct metadata {
|
2021-06-16 10:53:11 +02:00
|
|
|
struct pw_impl_metadata *impl;
|
|
|
|
|
struct pw_metadata *metadata;
|
2020-11-20 17:58:08 +01:00
|
|
|
|
|
|
|
|
struct sm_media_session *session;
|
|
|
|
|
struct spa_hook session_listener;
|
2019-11-20 16:18:46 +01:00
|
|
|
struct pw_proxy *proxy;
|
2019-11-03 11:25:23 +01:00
|
|
|
};
|
|
|
|
|
|
2019-12-18 12:15:03 +01:00
|
|
|
static void session_destroy(void *data)
|
|
|
|
|
{
|
|
|
|
|
struct metadata *this = data;
|
|
|
|
|
|
|
|
|
|
spa_hook_remove(&this->session_listener);
|
|
|
|
|
pw_proxy_destroy(this->proxy);
|
|
|
|
|
|
2021-06-16 10:53:11 +02:00
|
|
|
pw_impl_metadata_destroy(this->impl);
|
2019-12-18 12:15:03 +01:00
|
|
|
free(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct sm_media_session_events session_events = {
|
|
|
|
|
SM_VERSION_MEDIA_SESSION_EVENTS,
|
|
|
|
|
.destroy = session_destroy,
|
|
|
|
|
};
|
|
|
|
|
|
2020-11-20 17:58:08 +01:00
|
|
|
struct pw_metadata *sm_media_session_export_metadata(struct sm_media_session *sess,
|
|
|
|
|
const char *name)
|
2019-11-03 11:25:23 +01:00
|
|
|
{
|
2020-11-20 17:58:08 +01:00
|
|
|
struct metadata *this;
|
2019-12-18 12:15:03 +01:00
|
|
|
int res;
|
2020-11-20 17:58:08 +01:00
|
|
|
struct spa_dict_item items[1];
|
2019-11-03 11:25:23 +01:00
|
|
|
|
2020-11-20 17:58:08 +01:00
|
|
|
this = calloc(1, sizeof(*this));
|
|
|
|
|
if (this == NULL)
|
|
|
|
|
goto error_errno;
|
2019-12-18 12:15:03 +01:00
|
|
|
|
2021-06-16 10:53:11 +02:00
|
|
|
this->impl = pw_context_create_metadata(sess->context,
|
|
|
|
|
name, NULL, 0);
|
|
|
|
|
if (this->impl == NULL)
|
|
|
|
|
goto error_errno;
|
2019-11-03 11:25:23 +01:00
|
|
|
|
2021-06-16 10:53:11 +02:00
|
|
|
this->metadata = pw_impl_metadata_get_implementation(this->impl);
|
2019-11-03 11:25:23 +01:00
|
|
|
|
2020-11-20 17:58:08 +01:00
|
|
|
items[0] = SPA_DICT_ITEM_INIT(PW_KEY_METADATA_NAME, name);
|
|
|
|
|
|
|
|
|
|
this->session = sess;
|
|
|
|
|
this->proxy = sm_media_session_export(sess,
|
2019-11-20 16:18:46 +01:00
|
|
|
PW_TYPE_INTERFACE_Metadata,
|
2020-11-20 17:58:08 +01:00
|
|
|
&SPA_DICT_INIT_ARRAY(items),
|
2021-06-16 10:53:11 +02:00
|
|
|
this->metadata, 0);
|
2020-11-20 17:58:08 +01:00
|
|
|
if (this->proxy == NULL)
|
|
|
|
|
goto error_errno;
|
2020-07-15 14:21:35 +02:00
|
|
|
|
2020-11-20 17:58:08 +01:00
|
|
|
sm_media_session_add_listener(sess, &this->session_listener,
|
|
|
|
|
&session_events, this);
|
2020-07-15 14:21:35 +02:00
|
|
|
|
2021-06-16 10:53:11 +02:00
|
|
|
return this->metadata;
|
2019-12-18 12:15:03 +01:00
|
|
|
|
2020-11-20 17:58:08 +01:00
|
|
|
error_errno:
|
|
|
|
|
res = -errno;
|
|
|
|
|
goto error_free;
|
2019-12-18 12:15:03 +01:00
|
|
|
error_free:
|
2020-11-20 17:58:08 +01:00
|
|
|
free(this);
|
|
|
|
|
errno = -res;
|
|
|
|
|
return NULL;
|
2019-11-03 11:25:23 +01:00
|
|
|
}
|