2023-02-08 18:12:00 +01:00
|
|
|
/* PipeWire */
|
|
|
|
|
/* SPDX-FileCopyrightText: Copyright © 2020 Wim Taymans */
|
|
|
|
|
/* SPDX-License-Identifier: MIT */
|
2021-06-18 23:03:58 +02:00
|
|
|
|
|
|
|
|
#include <spa/utils/list.h>
|
|
|
|
|
#include <spa/utils/hook.h>
|
|
|
|
|
#include <pipewire/work-queue.h>
|
|
|
|
|
|
2021-06-18 23:36:35 +02:00
|
|
|
#include "client.h"
|
2023-05-06 01:23:11 +02:00
|
|
|
#include "collect.h"
|
|
|
|
|
#include "commands.h"
|
2021-06-18 23:03:58 +02:00
|
|
|
#include "internal.h"
|
2021-09-22 09:28:54 +10:00
|
|
|
#include "log.h"
|
2023-05-06 01:23:11 +02:00
|
|
|
#include "message.h"
|
2022-02-20 21:34:53 +01:00
|
|
|
#include "operation.h"
|
2021-06-18 23:03:58 +02:00
|
|
|
#include "pending-sample.h"
|
2023-05-06 01:23:11 +02:00
|
|
|
#include "reply.h"
|
2021-06-18 23:03:58 +02:00
|
|
|
#include "sample-play.h"
|
|
|
|
|
|
2023-05-06 01:23:11 +02:00
|
|
|
static void sample_play_finish(struct pending_sample *ps)
|
|
|
|
|
{
|
|
|
|
|
struct client *client = ps->client;
|
|
|
|
|
pending_sample_free(ps);
|
|
|
|
|
client_unref(client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void sample_play_ready_reply(void *data, struct client *client, uint32_t tag)
|
|
|
|
|
{
|
|
|
|
|
struct pending_sample *ps = data;
|
|
|
|
|
struct message *reply;
|
|
|
|
|
uint32_t index = id_to_index(client->manager, ps->play->id);
|
|
|
|
|
|
|
|
|
|
pw_log_info("[%s] PLAY_SAMPLE tag:%u index:%u",
|
|
|
|
|
client->name, ps->tag, index);
|
|
|
|
|
|
|
|
|
|
reply = reply_new(client, ps->tag);
|
|
|
|
|
if (client->version >= 13)
|
|
|
|
|
message_put(reply,
|
|
|
|
|
TAG_U32, index,
|
|
|
|
|
TAG_INVALID);
|
|
|
|
|
|
|
|
|
|
client_queue_message(client, reply);
|
2023-05-07 16:03:29 +02:00
|
|
|
ps->replied = true;
|
2023-05-06 01:23:11 +02:00
|
|
|
|
|
|
|
|
if (ps->done)
|
|
|
|
|
sample_play_finish(ps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void sample_play_ready(void *data, uint32_t id)
|
|
|
|
|
{
|
|
|
|
|
struct pending_sample *ps = data;
|
|
|
|
|
struct client *client = ps->client;
|
|
|
|
|
operation_new_cb(client, ps->tag, sample_play_ready_reply, ps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void on_sample_done(void *obj, void *data, int res, uint32_t id)
|
|
|
|
|
{
|
|
|
|
|
struct pending_sample *ps = obj;
|
|
|
|
|
ps->done = true;
|
2023-05-07 16:03:29 +02:00
|
|
|
if (ps->replied)
|
2023-05-06 01:23:11 +02:00
|
|
|
sample_play_finish(ps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void sample_play_done(void *data, int res)
|
|
|
|
|
{
|
|
|
|
|
struct pending_sample *ps = data;
|
|
|
|
|
struct client *client = ps->client;
|
|
|
|
|
struct impl *impl = client->impl;
|
|
|
|
|
|
|
|
|
|
if (res < 0)
|
|
|
|
|
reply_error(client, COMMAND_PLAY_SAMPLE, ps->tag, res);
|
|
|
|
|
else
|
|
|
|
|
pw_log_info("[%s] PLAY_SAMPLE done tag:%u", client->name, ps->tag);
|
|
|
|
|
|
|
|
|
|
pw_work_queue_add(impl->work_queue, ps, 0,
|
|
|
|
|
on_sample_done, client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct sample_play_events sample_play_events = {
|
|
|
|
|
VERSION_SAMPLE_PLAY_EVENTS,
|
|
|
|
|
.ready = sample_play_ready,
|
|
|
|
|
.done = sample_play_done,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int pending_sample_new(struct client *client, struct sample *sample, struct pw_properties *props, uint32_t tag)
|
|
|
|
|
{
|
|
|
|
|
struct pending_sample *ps;
|
|
|
|
|
struct sample_play *p = sample_play_new(client->core, sample, props, sizeof(*ps));
|
|
|
|
|
if (!p)
|
|
|
|
|
return -errno;
|
|
|
|
|
|
|
|
|
|
ps = p->user_data;
|
|
|
|
|
ps->client = client;
|
|
|
|
|
ps->play = p;
|
|
|
|
|
ps->tag = tag;
|
|
|
|
|
sample_play_add_listener(p, &ps->listener, &sample_play_events, ps);
|
|
|
|
|
spa_list_append(&client->pending_samples, &ps->link);
|
|
|
|
|
client->ref++;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-18 23:03:58 +02:00
|
|
|
void pending_sample_free(struct pending_sample *ps)
|
|
|
|
|
{
|
|
|
|
|
struct client * const client = ps->client;
|
|
|
|
|
struct impl * const impl = client->impl;
|
2022-02-20 21:34:53 +01:00
|
|
|
struct operation *o;
|
2021-06-18 23:03:58 +02:00
|
|
|
|
|
|
|
|
spa_list_remove(&ps->link);
|
|
|
|
|
spa_hook_remove(&ps->listener);
|
|
|
|
|
pw_work_queue_cancel(impl->work_queue, ps, SPA_ID_INVALID);
|
|
|
|
|
|
2022-02-20 21:34:53 +01:00
|
|
|
if ((o = operation_find(client, ps->tag)) != NULL)
|
|
|
|
|
operation_free(o);
|
|
|
|
|
|
2021-06-18 23:03:58 +02:00
|
|
|
sample_play_destroy(ps->play);
|
|
|
|
|
}
|