Skip to content

Commit

Permalink
Pass SceneStore as const ref through handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
firthm01 committed May 14, 2024
1 parent d216065 commit ab7adb9
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class BinauralMonitoringBackend {
bool isExporting() { return isExporting_; }

private:
void onSceneReceived(proto::SceneStore store);
void onSceneReceived(const proto::SceneStore& store);
void onConnection(communication::ConnectionId connectionId,
const std::string& streamEndpoint);
void onConnectionLost();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SceneStore;
namespace communication {
class MonitoringMetadataReceiver {
public:
using RequestHandler = std::function<void(proto::SceneStore)>;
using RequestHandler = std::function<void(const proto::SceneStore& store)>;
MonitoringMetadataReceiver(std::shared_ptr<spdlog::logger> logger = nullptr);
~MonitoringMetadataReceiver();
MonitoringMetadataReceiver(const MonitoringMetadataReceiver&) = delete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class MonitoringBackend {
bool isExporting() { return isExporting_; }

private:
void onSceneReceived(proto::SceneStore store);
void onSceneReceived(const proto::SceneStore& store);
void onConnection(communication::ConnectionId connectionId,
const std::string& streamEndpoint);
void onConnectionLost();
void updateActiveGains(proto::SceneStore store);
void updateActiveGains(const proto::SceneStore& store);

std::shared_ptr<spdlog::logger> logger_;
std::mutex gainsMutex_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct ItemGains {
class SceneGainsCalculator {
public:
SceneGainsCalculator(Layout outputLayout, int inputChannelCount);
bool update(proto::SceneStore store);
bool update(const proto::SceneStore &store);
Eigen::MatrixXf directGains();
Eigen::MatrixXf diffuseGains();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ BinauralMonitoringBackend::getLatestObjectsTypeMetadata(ConnId id) {
return std::optional<ObjectsEarMetadataAndRouting>();
}

void BinauralMonitoringBackend::onSceneReceived(proto::SceneStore store) {
void BinauralMonitoringBackend::onSceneReceived(
const proto::SceneStore& store) {
isExporting_ = store.has_is_exporting() && store.is_exporting();

size_t totalDsChannels = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void MonitoringMetadataReceiver::handleReceive(std::error_code ec,
}
// Called by NNG callback on thread with small stack.
// Launch task in another thread to overcome stack limitation.
auto future = std::async(std::launch::async, [this, sceneStore = std::move(sceneStore)]() {
auto future = std::async(std::launch::async, [this, sceneStore]() {
handler_(sceneStore);
});
future.get(); //blocking
Expand Down
8 changes: 4 additions & 4 deletions ear-production-suite-plugins/lib/src/monitoring_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ MonitoringBackend::~MonitoringBackend() {
controlConnection_.onConnectionEstablished(nullptr);
}

void MonitoringBackend::onSceneReceived(proto::SceneStore store) {
void MonitoringBackend::onSceneReceived(const proto::SceneStore& store) {
isExporting_ = store.has_is_exporting() && store.is_exporting();
updateActiveGains(std::move(store));
updateActiveGains(store);
}

GainHolder MonitoringBackend::currentGains() {
std::lock_guard<std::mutex> lock(gainsMutex_);
return gains_;
}

void MonitoringBackend::updateActiveGains(proto::SceneStore store) {
void MonitoringBackend::updateActiveGains(const proto::SceneStore& store) {
{
std::lock_guard<std::mutex> lock(gainsCalculatorMutex_);
gainsCalculator_.update(std::move(store));
gainsCalculator_.update(store);
}
{
std::lock_guard<std::mutex> lock(gainsMutex_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ SceneGainsCalculator::SceneGainsCalculator(ear::Layout outputLayout,
totalOutputChannels{static_cast<int>(outputLayout.channels().size())},
totalInputChannels{inputChannelCount} {}

bool SceneGainsCalculator::update(proto::SceneStore store) {
bool SceneGainsCalculator::update(const proto::SceneStore& store) {
// First figure out what we need to process updates for
std::vector<communication::ConnectionId> cachedIdsChecklist;
cachedIdsChecklist.reserve(routingCache_.size());
Expand Down

0 comments on commit ab7adb9

Please sign in to comment.