mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
module-snapcast: don't hardcode the JSON message id
Use a counter to make it increment for each message.
This commit is contained in:
parent
9b33cea0f7
commit
8cff77706a
1 changed files with 13 additions and 11 deletions
|
|
@ -149,6 +149,7 @@ struct impl {
|
||||||
AvahiServiceBrowser *sink_browser;
|
AvahiServiceBrowser *sink_browser;
|
||||||
|
|
||||||
struct spa_list tunnel_list;
|
struct spa_list tunnel_list;
|
||||||
|
uint32_t id;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tunnel_info {
|
struct tunnel_info {
|
||||||
|
|
@ -287,6 +288,7 @@ static int handle_connect(struct tunnel *t, int fd)
|
||||||
int res;
|
int res;
|
||||||
socklen_t len;
|
socklen_t len;
|
||||||
char *str;
|
char *str;
|
||||||
|
struct impl *impl = t->impl;
|
||||||
|
|
||||||
len = sizeof(res);
|
len = sizeof(res);
|
||||||
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &res, &len) < 0) {
|
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &res, &len) < 0) {
|
||||||
|
|
@ -299,22 +301,23 @@ static int handle_connect(struct tunnel *t, int fd)
|
||||||
t->connecting = false;
|
t->connecting = false;
|
||||||
pw_log_info("connected");
|
pw_log_info("connected");
|
||||||
|
|
||||||
str = "{\"id\":8,\"jsonrpc\": \"2.0\",\"method\":\"Server.GetRPCVersion\"}\r\n";
|
str = spa_aprintf("{\"id\":%u,\"jsonrpc\": \"2.0\",\"method\":\"Server.GetRPCVersion\"}\r\n",
|
||||||
res = write(t->source->fd, str, strlen(str));
|
impl->id++);
|
||||||
pw_log_info("wrote %s: %d", str, res);
|
|
||||||
|
|
||||||
str = spa_aprintf("{\"id\":4,\"jsonrpc\":\"2.0\",\"method\":\"Stream.RemoveStream\","
|
|
||||||
"\"params\":{\"id\":\"%s\"}}\r\n", t->stream_name);
|
|
||||||
res = write(t->source->fd, str, strlen(str));
|
res = write(t->source->fd, str, strlen(str));
|
||||||
pw_log_info("wrote %s: %d", str, res);
|
pw_log_info("wrote %s: %d", str, res);
|
||||||
free(str);
|
free(str);
|
||||||
|
|
||||||
str = spa_aprintf("{\"id\":4,\"jsonrpc\":\"2.0\",\"method\":\"Stream.AddStream\""
|
str = spa_aprintf("{\"id\":%u,\"jsonrpc\":\"2.0\",\"method\":\"Stream.RemoveStream\","
|
||||||
|
"\"params\":{\"id\":\"%s\"}}\r\n", impl->id++, t->stream_name);
|
||||||
|
res = write(t->source->fd, str, strlen(str));
|
||||||
|
pw_log_info("wrote %s: %d", str, res);
|
||||||
|
free(str);
|
||||||
|
|
||||||
|
str = spa_aprintf("{\"id\":%u,\"jsonrpc\":\"2.0\",\"method\":\"Stream.AddStream\""
|
||||||
",\"params\":{\"streamUri\":\"tcp://%s?name=%s&mode=client&"
|
",\"params\":{\"streamUri\":\"tcp://%s?name=%s&mode=client&"
|
||||||
"sampleformat=%d:%d:%d&codec=pcm&chunk_ms=20\"}}\r\n",
|
"sampleformat=%d:%d:%d&codec=pcm&chunk_ms=20\"}}\r\n", impl->id++,
|
||||||
t->server_address, t->stream_name, t->audio_info.rate,
|
t->server_address, t->stream_name, t->audio_info.rate,
|
||||||
get_bps(t->audio_info.format), t->audio_info.channels);
|
get_bps(t->audio_info.format), t->audio_info.channels);
|
||||||
|
|
||||||
res = write(t->source->fd, str, strlen(str));
|
res = write(t->source->fd, str, strlen(str));
|
||||||
pw_log_info("wrote %s: %d", str, res);
|
pw_log_info("wrote %s: %d", str, res);
|
||||||
free(str);
|
free(str);
|
||||||
|
|
@ -329,7 +332,6 @@ static int process_input(struct tunnel *t)
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
res = read(t->source->fd, buffer, sizeof(buffer));
|
res = read(t->source->fd, buffer, sizeof(buffer));
|
||||||
pw_log_info("%d", res);
|
|
||||||
if (res == 0)
|
if (res == 0)
|
||||||
return -EPIPE;
|
return -EPIPE;
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
|
|
@ -342,7 +344,7 @@ static int process_input(struct tunnel *t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pw_log_info("%s", buffer);
|
pw_log_info("received: %s", buffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue