summaryrefslogtreecommitdiff
path: root/pipewire-pulseaudio/src/context.c
diff options
context:
space:
mode:
Diffstat (limited to 'pipewire-pulseaudio/src/context.c')
-rw-r--r--pipewire-pulseaudio/src/context.c62
1 files changed, 37 insertions, 25 deletions
diff --git a/pipewire-pulseaudio/src/context.c b/pipewire-pulseaudio/src/context.c
index d5735d84..38b38d59 100644
--- a/pipewire-pulseaudio/src/context.c
+++ b/pipewire-pulseaudio/src/context.c
@@ -817,12 +817,29 @@ static void core_done(void *data, uint32_t id, int seq)
complete_operations(c, seq);
}
+static void core_error(void *data, uint32_t id, int seq, int res, const char *message)
+{
+ pa_context *c = data;
+
+ pw_log_error("error: id:%u seq:%d res:%d %s\n", id, seq, res, message);
+ if (id == 0) {
+ if (c->core) {
+ spa_hook_remove(&c->core_listener);
+ c->core = NULL;
+ }
+ if (!c->disconnect)
+ context_fail(c, PA_ERR_CONNECTIONTERMINATED);
+ }
+}
+
static const struct pw_core_events core_events = {
PW_VERSION_CORE_EVENTS,
.info = core_info,
- .done = core_done
+ .done = core_done,
+ .error = core_error
};
+#if 0
static void remote_state_changed(void *data, enum pw_remote_state old,
enum pw_remote_state state, const char *error)
{
@@ -863,6 +880,7 @@ static const struct pw_remote_events remote_events = {
PW_VERSION_REMOTE_EVENTS,
.state_changed = remote_state_changed,
};
+#endif
struct success_data {
pa_context_success_cb_t cb;
@@ -913,14 +931,15 @@ pa_operation* pa_context_subscribe(pa_context *c, pa_subscription_mask_t m, pa_c
SPA_EXPORT
pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *name, PA_CONST pa_proplist *p)
{
- struct pw_impl_core *core;
- struct pw_loop *loop;
- struct pw_remote *r;
struct pw_properties *props;
pa_context *c;
pa_assert(mainloop);
+ c = calloc(1, sizeof(struct pa_context));
+ if (c == NULL)
+ return NULL;
+
props = pw_properties_new(NULL, NULL);
if (name)
pw_properties_set(props, PA_PROP_APPLICATION_NAME, name);
@@ -928,20 +947,7 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *
if (p)
pw_properties_update(props, &p->props->dict);
- loop = mainloop->userdata;
- core = pw_impl_core_new(loop, NULL, 0);
-
- r = pw_remote_new(core, props, sizeof(struct pa_context));
- if (r == NULL)
- return NULL;
-
- c = pw_remote_get_user_data(r);
- c->loop = loop;
- c->core_impl = core;
- c->remote = r;
-
- pw_remote_add_listener(r, &c->remote_listener, &remote_events, c);
-
+ c->loop = mainloop->userdata;
c->proplist = p ? pa_proplist_copy(p) : pa_proplist_new();
c->refcount = 1;
c->client_index = PA_INVALID_INDEX;
@@ -964,7 +970,8 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *
static void do_core_destroy(pa_mainloop_api*m, void *userdata)
{
pa_context *c = userdata;
- pw_impl_core_destroy(c->core_impl);
+ pw_core_disconnect(c->core);
+ free(c);
}
static void context_free(pa_context *c)
@@ -1059,8 +1066,6 @@ pa_context_state_t pa_context_get_state(PA_CONST pa_context *c)
SPA_EXPORT
int pa_context_connect(pa_context *c, const char *server, pa_context_flags_t flags, const pa_spawn_api *api)
{
- int res;
-
pa_assert(c);
pa_assert(c->refcount >= 1);
@@ -1072,11 +1077,18 @@ int pa_context_connect(pa_context *c, const char *server, pa_context_flags_t fla
c->no_fail = !!(flags & PA_CONTEXT_NOFAIL);
- res = pw_remote_connect(c->remote);
+ pa_context_set_state(c, PA_CONTEXT_CONNECTING);
+
+ c->core = pw_core_connect(c->loop, c->proplist->props, 0);
+ pw_core_add_listener(c->core, &c->core_listener, &core_events, c);
+
+ pa_context_set_state(c, PA_CONTEXT_AUTHORIZING);
+ pa_context_set_state(c, PA_CONTEXT_SETTING_NAME);
+ pa_context_set_state(c, PA_CONTEXT_READY);
pa_context_unref(c);
- return res;
+ return 0;
}
SPA_EXPORT
@@ -1086,7 +1098,7 @@ void pa_context_disconnect(pa_context *c)
pa_assert(c->refcount >= 1);
c->disconnect = true;
- pw_remote_disconnect(c->remote);
+ pw_core_disconnect(c->core);
if (PA_CONTEXT_IS_GOOD(c->state))
pa_context_set_state(c, PA_CONTEXT_TERMINATED);
@@ -1199,7 +1211,7 @@ pa_operation* pa_context_set_name(pa_context *c, const char *name, pa_context_su
items[0] = SPA_DICT_ITEM_INIT(PA_PROP_APPLICATION_NAME, name);
dict = SPA_DICT_INIT(items, 1);
- pw_remote_update_properties(c->remote, &dict);
+ pw_core_update_client_properties(c->core, &dict);
o = pa_operation_new(c, NULL, on_success, sizeof(struct success_data));
d = o->userdata;