Skip to content

Commit 56717c2

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). The role sends an empty source@v1 support object, 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 56717c2

9 files changed

Lines changed: 43 additions & 73 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: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,13 +1130,10 @@ 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").
1133+
// messaging.md "client/hello" requires the object whenever source@v1 is listed, even though
1134+
// roles/source/v1.md "client/hello source@v1 support object" gives it no fields.
11351135
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-
}
1136+
root["payload"]["source@v1_support"].to<JsonObject>();
11401137
}
11411138

11421139
// messaging.md "client/hello": an application-specific role's support object is keyed
@@ -1242,12 +1239,9 @@ void build_client_state_message(const ClientStateMessage* msg, JsonDocument& doc
12421239
}
12431240
}
12441241

1245-
// signal only when set.
1242+
// roles/source/v1.md "client/state source object": signal is required.
12461243
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-
}
1244+
root["payload"]["source"]["signal"] = to_cstr(msg->source.value().signal);
12511245
}
12521246
}
12531247

‎src/protocol_messages.h‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,15 +1019,13 @@ inline std::optional<SourceCommand> source_command_from_string(std::string_view
10191019
}
10201020

10211021
/// @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-
};
1022+
/// source@v1 support object"), which has no fields of its own but must be sent
1023+
struct SourceSupportObject {};
10261024

10271025
/// @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.
1026+
/// object"), whose signal is required
10291027
struct ClientSourceStateObject {
1030-
std::optional<SourceSignal> signal{};
1028+
SourceSignal signal{SourceSignal::ABSENT};
10311029
};
10321030

10331031
// ============================================================================

‎src/source_role.cpp‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,12 @@ void SourceRole::Impl::build_hello_fields(ClientHelloMessage& msg) const {
261261
return;
262262
}
263263
msg.supported_roles.push_back(SendspinRole::SOURCE);
264-
msg.source_v1_support = SourceSupportObject{.line_sense = this->config.line_sense};
264+
msg.source_v1_support = SourceSupportObject{};
265265
}
266266

267267
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
268+
// roles/source/v1.md "client/state source object": present while the role is active, with
269+
// the signal it requires
270270
msg.source = ClientSourceStateObject{.signal = this->signal};
271271
}
272272

@@ -515,10 +515,6 @@ void SourceRole::Impl::append_state_metadata(JsonObject source,
515515
}
516516

517517
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-
}
522518
this->signal = new_signal;
523519
this->client->publish_state();
524520
}

‎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: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,29 +2448,21 @@ TEST(Protocol, Be64HelpersAreBigEndianAndRoundTrip) {
24482448
}
24492449

24502450
// 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").
2451+
// though roles/source/v1.md "client/hello source@v1 support object" gives it no fields; the
2452+
// line_sense feature it once had is gone.
24532453
TEST(Protocol, FormatClientHelloSourceSupport) {
24542454
ClientHelloMessage msg;
24552455
msg.name = "Line In";
24562456
msg.supported_roles.push_back(SendspinRole::SOURCE);
24572457

2458-
msg.source_v1_support = SourceSupportObject{.line_sense = true};
2458+
msg.source_v1_support = SourceSupportObject{};
24592459
JsonDocument doc;
24602460
ASSERT_FALSE(deserializeJson(doc, built_text([&](JsonDocument& message) {
24612461
build_client_hello_message(&msg, message);
24622462
})));
24632463
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);
2464+
ASSERT_TRUE(doc["payload"]["source@v1_support"].is<JsonObject>());
2465+
EXPECT_EQ(doc["payload"]["source@v1_support"].as<JsonObject>().size(), 0U);
24742466

24752467
// Control: a client without the role sends no support object.
24762468
msg.supported_roles.clear();
@@ -2482,8 +2474,8 @@ TEST(Protocol, FormatClientHelloSourceSupport) {
24822474
EXPECT_TRUE(doc_unset["payload"]["source@v1_support"].isUnbound());
24832475
}
24842476

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.
2477+
// roles/source/v1.md "client/state source object": absent when unset, and otherwise always
2478+
// carrying the signal it requires, absent by default.
24872479
TEST(Protocol, FormatClientStateSourceObject) {
24882480
ClientStateMessage msg;
24892481
JsonDocument doc_unset;
@@ -2493,19 +2485,18 @@ TEST(Protocol, FormatClientStateSourceObject) {
24932485
EXPECT_TRUE(doc_unset["payload"]["source"].isUnbound());
24942486

24952487
msg.source = ClientSourceStateObject{};
2496-
JsonDocument doc_empty;
2497-
ASSERT_FALSE(deserializeJson(doc_empty, built_text([&](JsonDocument& message) {
2488+
JsonDocument doc_default;
2489+
ASSERT_FALSE(deserializeJson(doc_default, built_text([&](JsonDocument& message) {
24982490
build_client_state_message(&msg, message);
24992491
})));
2500-
ASSERT_TRUE(doc_empty["payload"]["source"].is<JsonObject>());
2501-
EXPECT_EQ(doc_empty["payload"]["source"].as<JsonObject>().size(), 0U);
2492+
EXPECT_STREQ(doc_default["payload"]["source"]["signal"], "absent");
25022493

2503-
msg.source = ClientSourceStateObject{.signal = SourceSignal::ABSENT};
2494+
msg.source = ClientSourceStateObject{.signal = SourceSignal::PRESENT};
25042495
JsonDocument doc_signal;
25052496
ASSERT_FALSE(deserializeJson(doc_signal, built_text([&](JsonDocument& message) {
25062497
build_client_state_message(&msg, message);
25072498
})));
2508-
EXPECT_STREQ(doc_signal["payload"]["source"]["signal"], "absent");
2499+
EXPECT_STREQ(doc_signal["payload"]["source"]["signal"], "present");
25092500
}
25102501

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

‎tests/test_source_role.cpp‎

Lines changed: 8 additions & 17 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,24 @@ 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);
642+
EXPECT_TRUE(hello.source_v1_support.has_value());
646643

647644
ClientStateMessage state;
648645
source.impl_->build_state_fields(state);
649646
ASSERT_TRUE(state.source.has_value());
650-
EXPECT_FALSE(state.source->signal.has_value()) << "no signal reported yet";
647+
EXPECT_EQ(state.source->signal, SourceSignal::ABSENT) << "absent until one is set";
651648
source.set_signal(SourceSignal::PRESENT);
652649
source.impl_->build_state_fields(state);
653650
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());
651+
source.set_signal(SourceSignal::ABSENT);
652+
source.impl_->build_state_fields(state);
653+
EXPECT_EQ(state.source->signal, SourceSignal::ABSENT);
663654

664655
// An unusable config is never advertised, and does not fail the client's start.
665656
SendspinClient bad_client(SendspinClientConfig{});

0 commit comments

Comments
 (0)