Skip to content

Commit 69a4911

Browse files
meiser79claude
andcommitted
Always report the source signal, and drop line_sense
roles/source/v1.md now requires `signal` in every client/state source object and no longer has a line_sense feature (Sendspin/spec#335), and client/hello no longer defines a source@v1 support object. The role sends none, set_signal() is always taken, and the signal is ABSENT until one is set, so a source that detects nothing never hints a start. SourceRoleConfig::line_sense is gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent df59ccd commit 69a4911

9 files changed

Lines changed: 37 additions & 91 deletions

File tree

‎docs/integration-guide.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ source.write_audio(pcm_bytes, len, capture_time_us);
191191

192192
It never waits or allocates. It refuses audio while the stream is closed, a write that is not a whole number of frames, a write longer than the capture buffer takes at once (see `capture_buffer_ms` in [SourceRoleConfig](#sourceroleconfig)), and a write that finds the capture buffer full; after a stall the stream resumes from live capture rather than sending the stale backlog. Start capturing in `on_streaming_started()` and stop in `on_streaming_stopped()` (see [SourceRoleListener](#sourcerolelistener)); the client holds high-performance networking (`on_request_high_performance()`) between the two, as it does during playback. Stop calling `write_audio()` before destroying the client.
193193

194-
A role configured with `line_sense` reports the capture input's signal state from the main loop thread, which goes to the server in `client/state`:
194+
The role reports the capture input's signal state in every `client/state`, as roles/source/v1.md requires. It is `ABSENT` until set, so a source that detects nothing never hints a start; set it from the main loop thread:
195195

196196
```cpp
197197
source.set_signal(SourceSignal::PRESENT); // or ABSENT
@@ -1605,7 +1605,6 @@ Configuration passed to `client.add_source()`. A value that breaks any rule belo
16051605
| `capture_buffer_ms` | `uint32_t` | `500` | More than 0 ms; about the longest network stall the stream rides out without a gap; a longer one resumes from live capture. A single write must fit in just under 5/8 of it. |
16061606
| `opus_bitrate` | `uint32_t` | `128000` | Opus bitrate in bit/s, 500 to 512000; ignored for `PCM` and `FLAC` |
16071607
| `opus_complexity` | `uint8_t` | `2` | Opus encoder complexity, at most 10; ignored for `PCM` and `FLAC` |
1608-
| `line_sense` | `bool` | `false` | Advertise signal sensing; see `SourceRole::set_signal()` |
16091608
| `metadata` | `bool` | `false` | Allow `SourceRole::set_metadata()`; reserves its text block when the role is added |
16101609
| `buffer_location` | `MemoryLocation` | `PREFER_EXTERNAL` | Placement of the capture buffer, the chunk buffer and a `FLAC` or `OPUS` encoder's chunk scratch (ESP-IDF only) |
16111610
| `priority` | `unsigned` | `3` | FreeRTOS priority for the source task, below the protocol and httpd tasks (ESP-IDF only) |
@@ -1760,7 +1759,7 @@ These represent commands the server can send to the player. The player advertise
17601759
| `PRESENT` | Audio signal detected on the capture input |
17611760
| `ABSENT` | No audio signal on the capture input |
17621761

1763-
Reported with `SourceRole::set_signal()`; meaningful only with `SourceRoleConfig::line_sense` set.
1762+
Reported with `SourceRole::set_signal()`, and `ABSENT` until it is first called.
17641763

17651764
### LogLevel
17661765

‎include/sendspin/config.h‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -818,10 +818,9 @@ struct SourceRoleConfig {
818818
/// @brief Opus encoder complexity, at most MAX_OPUS_COMPLEXITY. Ignored (and not validated)
819819
/// for PCM and FLAC.
820820
uint8_t opus_complexity{DEFAULT_OPUS_COMPLEXITY};
821-
uint8_t channels{2}; ///< Capture channel count; must be > 0 (at most 8 for FLAC, 1 or 2
822-
///< for OPUS)
823-
uint8_t bit_depth{16}; ///< Bits per sample: 16, 24 (3 packed bytes), or 32 (16 for OPUS)
824-
bool line_sense{false}; ///< Advertise signal sensing (see SourceRole::set_signal())
821+
uint8_t channels{2}; ///< Capture channel count; must be > 0 (at most 8 for FLAC, 1 or 2
822+
///< for OPUS)
823+
uint8_t bit_depth{16}; ///< Bits per sample: 16, 24 (3 packed bytes), or 32 (16 for OPUS)
825824
/// @brief Allow SourceRole::set_metadata(): reserves its text block (about 3 KB, placed by
826825
/// buffer_location) when the role is added
827826
bool metadata{false};

‎include/sendspin/source_role.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ class SourceRole {
141141

142142
/// @brief Reports the capture input's signal state, published to the server in client/state
143143
///
144-
/// Main loop only. Meaningful only with SourceRoleConfig::line_sense set; ignored (with a
145-
/// warning) otherwise.
144+
/// Main loop only. Every client/state carries one (roles/source/v1.md "client/state source
145+
/// object"); it is ABSENT until this is first called, so a source that never detects
146+
/// anything never hints a start.
146147
void set_signal(SourceSignal signal);
147148

148149
/// @brief Reports what the input audio is, published to the server in client/state

‎src/protocol.cpp‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,15 +1130,6 @@ void build_client_hello_message(const ClientHelloMessage* msg, JsonDocument& doc
11301130
msg->visualizer_support.value().buffer_capacity;
11311131
}
11321132

1133-
// messaging.md "client/hello" requires the object whenever source@v1 is listed; line_sense is
1134-
// emitted only when set (roles/source/v1.md "client/hello source@v1 support object").
1135-
if (msg->source_v1_support.has_value()) {
1136-
JsonObject source_json = root["payload"]["source@v1_support"].to<JsonObject>();
1137-
if (msg->source_v1_support.value().line_sense) {
1138-
source_json["features"]["line_sense"] = true;
1139-
}
1140-
}
1141-
11421133
// messaging.md "client/hello": an application-specific role's support object is keyed
11431134
// "<role>_support". start() replaced the text with ArduinoJson's own serialization of one
11441135
// JSON object, so it is embedded without a second parse, and held the name to
@@ -1242,12 +1233,9 @@ void build_client_state_message(const ClientStateMessage* msg, JsonDocument& doc
12421233
}
12431234
}
12441235

1245-
// signal only when set.
1236+
// roles/source/v1.md "client/state source object": signal is required.
12461237
if (msg->source.has_value()) {
1247-
JsonObject source_json = root["payload"]["source"].to<JsonObject>();
1248-
if (msg->source.value().signal.has_value()) {
1249-
source_json["signal"] = to_cstr(msg->source.value().signal.value());
1250-
}
1238+
root["payload"]["source"]["signal"] = to_cstr(msg->source.value().signal);
12511239
}
12521240
}
12531241

‎src/protocol_messages.h‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,16 +1018,10 @@ inline std::optional<SourceCommand> source_command_from_string(std::string_view
10181018
return std::nullopt;
10191019
}
10201020

1021-
/// @brief Source capabilities advertised in client/hello (roles/source/v1.md "client/hello
1022-
/// source@v1 support object")
1023-
struct SourceSupportObject {
1024-
bool line_sense{false};
1025-
};
1026-
10271021
/// @brief Source state reported in client/state (roles/source/v1.md "client/state source
1028-
/// object"). The object may be present and empty; signal only when line_sense was advertised.
1022+
/// object"), whose signal is required
10291023
struct ClientSourceStateObject {
1030-
std::optional<SourceSignal> signal{};
1024+
SourceSignal signal{SourceSignal::ABSENT};
10311025
};
10321026

10331027
// ============================================================================
@@ -1079,7 +1073,6 @@ struct ClientHelloMessage {
10791073
InlineVector<SendspinRole, static_cast<size_t>(SendspinRole::COUNT)> supported_roles{};
10801074
std::optional<PlayerSupportObject> player_v1_support{};
10811075
std::optional<VisualizerSupportObject> visualizer_support{};
1082-
std::optional<SourceSupportObject> source_v1_support{};
10831076
/// @brief The configured application-specific roles, listed after supported_roles; each
10841077
/// support_json is start()'s re-serialized object, sent as is.
10851078
std::span<const SendspinApplicationRole> application_roles{};

‎src/source_role.cpp‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,14 @@ void SourceRole::Impl::build_hello_fields(ClientHelloMessage& msg) const {
260260
if (!this->config_valid) {
261261
return;
262262
}
263+
// messaging.md "client/hello" defines no source@v1_support object for a client, so listing the
264+
// role is all it advertises.
263265
msg.supported_roles.push_back(SendspinRole::SOURCE);
264-
msg.source_v1_support = SourceSupportObject{.line_sense = this->config.line_sense};
265266
}
266267

267268
void SourceRole::Impl::build_state_fields(ClientStateMessage& msg) const {
268-
// roles/source/v1.md "client/state source object": present while the role is active, even
269-
// empty; signal only once one has been reported
269+
// roles/source/v1.md "client/state source object": present while the role is active, with
270+
// the signal it requires
270271
msg.source = ClientSourceStateObject{.signal = this->signal};
271272
}
272273

@@ -515,10 +516,6 @@ void SourceRole::Impl::append_state_metadata(JsonObject source,
515516
}
516517

517518
void SourceRole::Impl::set_signal(SourceSignal new_signal) {
518-
if (!this->config.line_sense) {
519-
SS_LOGW(TAG, "set_signal() ignored: line_sense not configured");
520-
return;
521-
}
522519
this->signal = new_signal;
523520
this->client->publish_state();
524521
}

‎src/source_role_impl.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,9 @@ struct SourceRole::Impl : RoleTeardown {
185185

186186
// Struct fields
187187
SourceRoleConfig config;
188-
/// Last set_signal() value, reported in client/state once set. Main loop only.
189-
std::optional<SourceSignal> signal;
188+
/// Last set_signal() value, reported in every client/state; ABSENT until one is set.
189+
/// Main loop only.
190+
SourceSignal signal{SourceSignal::ABSENT};
190191

191192
// Pointer fields
192193
SendspinClient* client;

‎tests/test_protocol.cpp‎

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,43 +2447,23 @@ TEST(Protocol, Be64HelpersAreBigEndianAndRoundTrip) {
24472447
}
24482448
}
24492449

2450-
// messaging.md "client/hello" requires the object whenever source@v1 is listed, so it is emitted
2451-
// even with no features; line_sense is emitted only when set (roles/source/v1.md "client/hello
2452-
// source@v1 support object").
2453-
TEST(Protocol, FormatClientHelloSourceSupport) {
2450+
// messaging.md "client/hello" defines no source@v1_support object for a client (the line_sense
2451+
// feature it once had is gone), and forbids sending fields it does not define.
2452+
TEST(Protocol, FormatClientHelloSourceSendsNoSupportObject) {
24542453
ClientHelloMessage msg;
24552454
msg.name = "Line In";
24562455
msg.supported_roles.push_back(SendspinRole::SOURCE);
24572456

2458-
msg.source_v1_support = SourceSupportObject{.line_sense = true};
24592457
JsonDocument doc;
24602458
ASSERT_FALSE(deserializeJson(doc, built_text([&](JsonDocument& message) {
24612459
build_client_hello_message(&msg, message);
24622460
})));
24632461
EXPECT_STREQ(doc["payload"]["supported_roles"][0], "source@v1");
2464-
ASSERT_TRUE(doc["payload"]["source@v1_support"]["features"]["line_sense"].is<bool>());
2465-
EXPECT_TRUE(doc["payload"]["source@v1_support"]["features"]["line_sense"].as<bool>());
2466-
2467-
msg.source_v1_support = SourceSupportObject{};
2468-
JsonDocument doc_no_features;
2469-
ASSERT_FALSE(deserializeJson(doc_no_features, built_text([&](JsonDocument& message) {
2470-
build_client_hello_message(&msg, message);
2471-
})));
2472-
ASSERT_TRUE(doc_no_features["payload"]["source@v1_support"].is<JsonObject>());
2473-
EXPECT_EQ(doc_no_features["payload"]["source@v1_support"].as<JsonObject>().size(), 0U);
2474-
2475-
// Control: a client without the role sends no support object.
2476-
msg.supported_roles.clear();
2477-
msg.source_v1_support.reset();
2478-
JsonDocument doc_unset;
2479-
ASSERT_FALSE(deserializeJson(doc_unset, built_text([&](JsonDocument& message) {
2480-
build_client_hello_message(&msg, message);
2481-
})));
2482-
EXPECT_TRUE(doc_unset["payload"]["source@v1_support"].isUnbound());
2462+
EXPECT_TRUE(doc["payload"]["source@v1_support"].isUnbound());
24832463
}
24842464

2485-
// roles/source/v1.md "client/state source object": absent when unset, present and empty without a
2486-
// signal, and carrying the signal when one is reported.
2465+
// roles/source/v1.md "client/state source object": absent when unset, and otherwise always
2466+
// carrying the signal it requires, absent by default.
24872467
TEST(Protocol, FormatClientStateSourceObject) {
24882468
ClientStateMessage msg;
24892469
JsonDocument doc_unset;
@@ -2493,19 +2473,18 @@ TEST(Protocol, FormatClientStateSourceObject) {
24932473
EXPECT_TRUE(doc_unset["payload"]["source"].isUnbound());
24942474

24952475
msg.source = ClientSourceStateObject{};
2496-
JsonDocument doc_empty;
2497-
ASSERT_FALSE(deserializeJson(doc_empty, built_text([&](JsonDocument& message) {
2476+
JsonDocument doc_default;
2477+
ASSERT_FALSE(deserializeJson(doc_default, built_text([&](JsonDocument& message) {
24982478
build_client_state_message(&msg, message);
24992479
})));
2500-
ASSERT_TRUE(doc_empty["payload"]["source"].is<JsonObject>());
2501-
EXPECT_EQ(doc_empty["payload"]["source"].as<JsonObject>().size(), 0U);
2480+
EXPECT_STREQ(doc_default["payload"]["source"]["signal"], "absent");
25022481

2503-
msg.source = ClientSourceStateObject{.signal = SourceSignal::ABSENT};
2482+
msg.source = ClientSourceStateObject{.signal = SourceSignal::PRESENT};
25042483
JsonDocument doc_signal;
25052484
ASSERT_FALSE(deserializeJson(doc_signal, built_text([&](JsonDocument& message) {
25062485
build_client_state_message(&msg, message);
25072486
})));
2508-
EXPECT_STREQ(doc_signal["payload"]["source"]["signal"], "absent");
2487+
EXPECT_STREQ(doc_signal["payload"]["source"]["signal"], "present");
25092488
}
25102489

25112490
// roles/source/v1.md "client-stream/start": the hyphenated type string, every format field, and

‎tests/test_source_role.cpp‎

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,8 @@ TEST(SourceConfigValidation, RejectsUnusableFormats) {
502502
}
503503

504504
// roles/source/v1.md "client/hello source@v1 support object" and "client/state source object":
505-
// a usable role advertises itself with its line_sense hint, an unusable one not at all, and the
506-
// state object carries a signal only for a role that senses one. The hello and state objects are
505+
// a usable role advertises itself with an empty support object, an unusable one not at all, and
506+
// the state object always carries a signal, absent until one is set. The hello and state objects are
507507
// built without a server, through SourceRole's impl_.
508508
/// The client/state source object's metadata, as the protocol task writes it for a connection
509509
/// whose filter has no measurement yet (an identity transform).
@@ -633,33 +633,23 @@ TEST(SourceRoleMetadata, WithoutTheConfigFlagAReportIsRefused) {
633633

634634
TEST(SourceRoleObjects, HelloAndStateFields) {
635635
SendspinClient client(SendspinClientConfig{});
636-
SourceRoleConfig config;
637-
config.line_sense = true;
638-
SourceRole& source = client.add_source(config);
636+
SourceRole& source = client.add_source(SourceRoleConfig{});
639637

640638
ClientHelloMessage hello;
641639
source.impl_->build_hello_fields(hello);
642640
ASSERT_EQ(hello.supported_roles.size(), 1U);
643641
EXPECT_EQ(hello.supported_roles[0], SendspinRole::SOURCE);
644-
ASSERT_TRUE(hello.source_v1_support.has_value());
645-
EXPECT_TRUE(hello.source_v1_support->line_sense);
646642

647643
ClientStateMessage state;
648644
source.impl_->build_state_fields(state);
649645
ASSERT_TRUE(state.source.has_value());
650-
EXPECT_FALSE(state.source->signal.has_value()) << "no signal reported yet";
646+
EXPECT_EQ(state.source->signal, SourceSignal::ABSENT) << "absent until one is set";
651647
source.set_signal(SourceSignal::PRESENT);
652648
source.impl_->build_state_fields(state);
653649
EXPECT_EQ(state.source->signal, SourceSignal::PRESENT);
654-
655-
// Without line_sense the object is present but never carries a signal.
656-
SendspinClient plain_client(SendspinClientConfig{});
657-
SourceRole& plain = plain_client.add_source(SourceRoleConfig{});
658-
plain.set_signal(SourceSignal::PRESENT);
659-
ClientStateMessage plain_state;
660-
plain.impl_->build_state_fields(plain_state);
661-
ASSERT_TRUE(plain_state.source.has_value());
662-
EXPECT_FALSE(plain_state.source->signal.has_value());
650+
source.set_signal(SourceSignal::ABSENT);
651+
source.impl_->build_state_fields(state);
652+
EXPECT_EQ(state.source->signal, SourceSignal::ABSENT);
663653

664654
// An unusable config is never advertised, and does not fail the client's start.
665655
SendspinClient bad_client(SendspinClientConfig{});
@@ -669,7 +659,6 @@ TEST(SourceRoleObjects, HelloAndStateFields) {
669659
ClientHelloMessage bad_hello;
670660
bad.impl_->build_hello_fields(bad_hello);
671661
EXPECT_TRUE(bad_hello.supported_roles.empty());
672-
EXPECT_FALSE(bad_hello.source_v1_support.has_value());
673662
EXPECT_TRUE(bad.impl_->start(nullptr));
674663
EXPECT_EQ(bad.impl_->task->outbound_ring(), nullptr) << "an unusable source started its task";
675664
}

0 commit comments

Comments
 (0)