2019-11-20 16:18:46 +01:00
|
|
|
/* PipeWire
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <spa/utils/names.h>
|
|
|
|
|
#include <spa/node/keys.h>
|
|
|
|
|
|
|
|
|
|
#include "pipewire/pipewire.h"
|
|
|
|
|
|
|
|
|
|
#include "media-session.h"
|
|
|
|
|
|
|
|
|
|
struct impl {
|
|
|
|
|
struct sm_media_session *session;
|
2019-12-18 12:15:03 +01:00
|
|
|
struct spa_hook listener;
|
2019-11-20 16:18:46 +01:00
|
|
|
|
|
|
|
|
struct pw_properties *props;
|
|
|
|
|
struct pw_proxy *proxy;
|
|
|
|
|
};
|
|
|
|
|
|
2019-12-18 12:15:03 +01:00
|
|
|
static void session_destroy(void *data)
|
|
|
|
|
{
|
|
|
|
|
struct impl *impl = data;
|
|
|
|
|
spa_hook_remove(&impl->listener);
|
|
|
|
|
pw_proxy_destroy(impl->proxy);
|
|
|
|
|
pw_properties_free(impl->props);
|
|
|
|
|
free(impl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct sm_media_session_events session_events = {
|
|
|
|
|
SM_VERSION_MEDIA_SESSION_EVENTS,
|
|
|
|
|
.destroy = session_destroy,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int sm_alsa_midi_start(struct sm_media_session *session)
|
2019-11-20 16:18:46 +01:00
|
|
|
{
|
|
|
|
|
struct impl *impl;
|
2019-12-18 12:15:03 +01:00
|
|
|
int res;
|
2019-11-20 16:18:46 +01:00
|
|
|
|
|
|
|
|
impl = calloc(1, sizeof(struct impl));
|
|
|
|
|
if (impl == NULL)
|
2019-12-18 12:15:03 +01:00
|
|
|
return -errno;
|
2019-11-20 16:18:46 +01:00
|
|
|
|
|
|
|
|
impl->session = session;
|
|
|
|
|
impl->props = pw_properties_new(
|
|
|
|
|
SPA_KEY_FACTORY_NAME, SPA_NAME_API_ALSA_SEQ_BRIDGE,
|
|
|
|
|
SPA_KEY_NODE_NAME, "Midi-Bridge",
|
|
|
|
|
NULL);
|
2019-12-18 12:15:03 +01:00
|
|
|
if (impl->props == NULL) {
|
|
|
|
|
res = -errno;
|
2019-11-20 16:18:46 +01:00
|
|
|
goto cleanup;
|
2019-12-18 12:15:03 +01:00
|
|
|
}
|
2019-11-20 16:18:46 +01:00
|
|
|
|
|
|
|
|
impl->proxy = sm_media_session_create_object(session,
|
|
|
|
|
"spa-node-factory",
|
|
|
|
|
PW_TYPE_INTERFACE_Node,
|
2019-12-11 15:26:11 +01:00
|
|
|
PW_VERSION_NODE,
|
2019-11-20 16:18:46 +01:00
|
|
|
&impl->props->dict,
|
|
|
|
|
0);
|
|
|
|
|
|
2019-12-18 12:15:03 +01:00
|
|
|
if (impl->proxy == NULL) {
|
|
|
|
|
res = -errno;
|
2019-11-20 16:18:46 +01:00
|
|
|
goto cleanup_props;
|
2019-12-18 12:15:03 +01:00
|
|
|
}
|
|
|
|
|
sm_media_session_add_listener(session, &impl->listener, &session_events, impl);
|
2019-11-20 16:18:46 +01:00
|
|
|
|
2019-12-18 12:15:03 +01:00
|
|
|
return 0;
|
2019-11-20 16:18:46 +01:00
|
|
|
|
|
|
|
|
cleanup_props:
|
|
|
|
|
pw_properties_free(impl->props);
|
|
|
|
|
cleanup:
|
|
|
|
|
free(impl);
|
2019-12-18 12:15:03 +01:00
|
|
|
return res;
|
2019-11-20 16:18:46 +01:00
|
|
|
}
|