2018-08-02 11:25:27 +02:00
|
|
|
/* PipeWire
|
|
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* Copyright © 2018 Wim Taymans
|
2018-08-02 11:25:27 +02:00
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* 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:
|
2018-08-02 11:25:27 +02:00
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* 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.
|
2018-08-02 11:25:27 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <spa/node/node.h>
|
|
|
|
|
#include <spa/utils/hook.h>
|
|
|
|
|
#include <spa/param/audio/format-utils.h>
|
2018-10-18 15:16:59 +02:00
|
|
|
#include <spa/param/props.h>
|
2018-11-16 16:41:13 +01:00
|
|
|
#include <spa/debug/pod.h>
|
2019-09-30 21:23:29 +02:00
|
|
|
#include <spa/support/dbus.h>
|
2018-08-02 11:25:27 +02:00
|
|
|
|
2019-01-14 12:58:23 +01:00
|
|
|
#include "pipewire/pipewire.h"
|
2018-08-02 11:25:27 +02:00
|
|
|
#include "pipewire/private.h"
|
2019-11-04 17:27:41 +01:00
|
|
|
#include "extensions/session-manager.h"
|
2018-08-02 11:25:27 +02:00
|
|
|
|
2019-09-30 21:23:29 +02:00
|
|
|
#include <dbus/dbus.h>
|
|
|
|
|
|
2018-09-11 15:25:35 +02:00
|
|
|
#define NAME "media-session"
|
|
|
|
|
|
2019-11-07 16:03:00 +01:00
|
|
|
int sm_monitor_start(struct pw_remote *remote);
|
|
|
|
|
int sm_policy_start(struct pw_remote *remote);
|
2019-11-13 09:38:40 +01:00
|
|
|
int sm_policy_ep_start(struct pw_remote *remote);
|
2019-07-10 20:24:11 +02:00
|
|
|
|
2018-08-02 11:25:27 +02:00
|
|
|
struct impl {
|
|
|
|
|
struct pw_main_loop *loop;
|
|
|
|
|
struct pw_core *core;
|
|
|
|
|
|
2019-11-07 16:03:00 +01:00
|
|
|
struct pw_remote *monitor_remote;
|
|
|
|
|
struct spa_hook monitor_listener;
|
2018-09-11 15:25:35 +02:00
|
|
|
|
2019-11-07 16:03:00 +01:00
|
|
|
struct pw_remote *policy_remote;
|
|
|
|
|
struct spa_hook policy_listener;
|
2018-08-02 11:25:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void on_state_changed(void *_data, enum pw_remote_state old, enum pw_remote_state state, const char *error)
|
|
|
|
|
{
|
|
|
|
|
struct impl *impl = _data;
|
|
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
|
case PW_REMOTE_STATE_ERROR:
|
2018-09-11 15:25:35 +02:00
|
|
|
pw_log_error(NAME" %p: remote error: %s", impl, error);
|
2018-08-02 11:25:27 +02:00
|
|
|
pw_main_loop_quit(impl->loop);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PW_REMOTE_STATE_CONNECTED:
|
2018-09-26 13:22:21 +02:00
|
|
|
pw_log_info(NAME" %p: connected", impl);
|
2018-08-02 11:25:27 +02:00
|
|
|
break;
|
2018-09-26 13:22:21 +02:00
|
|
|
|
|
|
|
|
case PW_REMOTE_STATE_UNCONNECTED:
|
|
|
|
|
pw_log_info(NAME" %p: disconnected", impl);
|
|
|
|
|
pw_main_loop_quit(impl->loop);
|
|
|
|
|
break;
|
2018-08-02 11:25:27 +02:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
printf("remote state: \"%s\"\n", pw_remote_state_as_string(state));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct pw_remote_events remote_events = {
|
|
|
|
|
PW_VERSION_REMOTE_EVENTS,
|
|
|
|
|
.state_changed = on_state_changed,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
struct impl impl = { 0, };
|
2019-11-07 16:03:00 +01:00
|
|
|
int res;
|
2018-08-02 11:25:27 +02:00
|
|
|
|
|
|
|
|
pw_init(&argc, &argv);
|
|
|
|
|
|
|
|
|
|
impl.loop = pw_main_loop_new(NULL);
|
2019-01-08 17:30:12 +01:00
|
|
|
impl.core = pw_core_new(pw_main_loop_get_loop(impl.loop), NULL, 0);
|
2018-08-02 11:25:27 +02:00
|
|
|
|
2019-07-10 20:24:11 +02:00
|
|
|
pw_core_add_spa_lib(impl.core, "api.bluez5.*", "bluez5/libspa-bluez5");
|
|
|
|
|
pw_core_add_spa_lib(impl.core, "api.alsa.*", "alsa/libspa-alsa");
|
|
|
|
|
pw_core_add_spa_lib(impl.core, "api.v4l2.*", "v4l2/libspa-v4l2");
|
|
|
|
|
|
2019-11-07 16:03:00 +01:00
|
|
|
impl.monitor_remote = pw_remote_new(impl.core, NULL, 0);
|
|
|
|
|
pw_remote_add_listener(impl.monitor_remote, &impl.monitor_listener, &remote_events, &impl);
|
|
|
|
|
|
|
|
|
|
impl.policy_remote = pw_remote_new(impl.core, NULL, 0);
|
|
|
|
|
pw_remote_add_listener(impl.policy_remote, &impl.policy_listener, &remote_events, &impl);
|
|
|
|
|
|
2019-08-16 22:11:42 +02:00
|
|
|
pw_module_load(impl.core, "libpipewire-module-client-device", NULL, NULL);
|
|
|
|
|
pw_module_load(impl.core, "libpipewire-module-adapter", NULL, NULL);
|
2019-11-03 10:31:14 +01:00
|
|
|
pw_module_load(impl.core, "libpipewire-module-metadata", NULL, NULL);
|
2019-11-04 17:27:41 +01:00
|
|
|
pw_module_load(impl.core, "libpipewire-module-session-manager", NULL, NULL);
|
2019-07-10 20:24:11 +02:00
|
|
|
|
2019-11-07 16:03:00 +01:00
|
|
|
sm_monitor_start(impl.monitor_remote);
|
2019-11-13 09:38:40 +01:00
|
|
|
// sm_policy_start(impl.policy_remote);
|
|
|
|
|
sm_policy_ep_start(impl.policy_remote);
|
2018-08-02 11:25:27 +02:00
|
|
|
|
2019-11-07 16:03:00 +01:00
|
|
|
if ((res = pw_remote_connect(impl.monitor_remote)) < 0)
|
|
|
|
|
return res;
|
|
|
|
|
if ((res = pw_remote_connect(impl.policy_remote)) < 0)
|
|
|
|
|
return res;
|
2019-11-03 10:31:14 +01:00
|
|
|
|
2018-08-02 11:25:27 +02:00
|
|
|
pw_main_loop_run(impl.loop);
|
|
|
|
|
|
|
|
|
|
pw_core_destroy(impl.core);
|
|
|
|
|
pw_main_loop_destroy(impl.loop);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|