Adding unlink command#11
Conversation
| for (unsigned i=0; i<info_.remote_endpoints.size(); ++i){ | ||
| if (info_.remote_endpoints[i].slot == slot) { | ||
| info_.remote_endpoints.erase(info_.remote_endpoints.begin() + i); | ||
| return true; | ||
| } | ||
| } | ||
| return false; |
There was a problem hiding this comment.
A few minor suggestions:
-
Inline
remove_slot_endpoint_()intounlink(). Manipulations with endpoint vectors are done directly inbind()andconnect(), so it would be easier to follow ifunlink()behaves similarly. -
Cover both
remote_endpoints(updated by connect) andlocal_endpoints(updated by bind) -
Use std::remove_if:
| for (unsigned i=0; i<info_.remote_endpoints.size(); ++i){ | |
| if (info_.remote_endpoints[i].slot == slot) { | |
| info_.remote_endpoints.erase(info_.remote_endpoints.begin() + i); | |
| return true; | |
| } | |
| } | |
| return false; | |
| if (auto new_end = std::remove_if(info_.remote_endpoints.begin(), | |
| info_.remote_endpoints.end(), | |
| [slot](const auto& endpoint) { return endpoint.slot == slot; }); | |
| new_end != info_.remote_endpoints.end()) { | |
| info_.remote_endpoints.erase(new_end, info_.remote_endpoints.end()); | |
| } | |
| // same for local_endpoints |
| rvpb::RvNone* response) | ||
| { | ||
| return execute_command_("unlink", [=]() { | ||
| int slot = request->has_slot() ? request->slot() : 0; |
There was a problem hiding this comment.
nit: Let's add roc_slot DEFAULT_SLOT = 0 to constants.hpp and use it here instead of 0.
| void Receiver::unlink(roc_slot slot) | ||
| { | ||
| throw std::invalid_argument("receiver device does not support unlink() currently"); |
There was a problem hiding this comment.
What is the reason? I'd expect it should work for receiver too.
| if (device_encoding.channel_layout == ROC_CHANNEL_LAYOUT_MULTITRACK && device_encoding.channel_count > 4) { | ||
| net_context_config.max_packet_size = device_encoding.channel_count * 512; | ||
| net_context_config.max_frame_size = device_encoding.channel_count * 1024; | ||
| } |
There was a problem hiding this comment.
Two suggestions:
-
Extract this into
max_packet_size()andmax_frame_size()methods ofDeviceLocalEncodingand reuse them in sender and receiver. -
Rework formulas roughly like this:
max_frame_size = channel_count * 1024 * 4 max_packet_size = channel_count * 1024 * 4 + 128Here, 1024 is max samples per packet, 4 is max bytes per sample, and 128 is max packet header size.
(Let me now if this approach works on your setup)
| if (use_uid_) { | ||
| fmt::println("unlinked device with uid \"{}\"", index_or_uid_); | ||
| } else { | ||
| fmt::println("unlinked device with index {}", index_); | ||
| } |
There was a problem hiding this comment.
| if (use_uid_) { | |
| fmt::println("unlinked device with uid \"{}\"", index_or_uid_); | |
| } else { | |
| fmt::println("unlinked device with index {}", index_); | |
| } | |
| if (use_uid_) { | |
| fmt::println("unlinked slot {} of device with uid \"{}\"", | |
| slot_.value_or(0), | |
| index_or_uid_); | |
| } else { | |
| fmt::println( | |
| "unlinked slot {} of device with index {}", slot_.value_or(0), index_); | |
| } |
Looks legit.
Thank you. In another project, I did something like this: Would be great if you could add GrpcSink to |
|
Regarding cmake 4:
|
|
BTW, may I ask, are you using roc-vad in some project or personally? Just curious! |
Adds support for the unlink command in the roc-toolkit. This is useful to allow removal of endpoints without deleting the whole VAD, this in turn allows any applications using the VAD to continue doing so while streaming connections are made/unmade.
It seems to work ok in my testing but maybe I'm missing out some underlying additional clean up that ought be be done when unlinking a slot?
I have also added in a check on the number of tracks which modifies
max_packet_sizeandmax_frame_sizeto accommodate them with larger buffer sizes.I had a little trouble getting grpc to compile with cmake 4 and so moved grpc on to v1.72.0. This has the unwanted side effect of removing the functions used in
tool/main.cppgrpc_init. It looks like grpc have changed the way they manage log levels - I wasn't sure what the best solution to this is as it touches the rest of roc-vad's logging. If you have a suggestion I can look at fixing this.P