diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-05-17 01:07:48 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-05-28 00:33:55 +0200 |
| commit | 06e00ae81b6a5c510949848470bcf6b7e0f3ee81 (patch) | |
| tree | 0d10ec3f3ae10de73400652e7872a3c1ba2ebc2f /src/lib | |
| parent | 82f06d69d6884943d3bb829adc0b3b4907011962 (diff) | |
Cleanup: coding style, rename Msg -> Message.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/grok/context.h | 2 | ||||
| -rw-r--r-- | src/lib/grok/messenger.cc | 4 | ||||
| -rw-r--r-- | src/lib/grok/messenger.h | 53 |
3 files changed, 32 insertions, 27 deletions
diff --git a/src/lib/grok/context.h b/src/lib/grok/context.h index 520cc0a1e..bfb2c7301 100644 --- a/src/lib/grok/context.h +++ b/src/lib/grok/context.h @@ -115,7 +115,7 @@ public: auto proc = [this](const std::string& str) { try { - Msg msg(str); + Message msg(str); auto tag = msg.next(); if (tag == GRK_MSGR_BATCH_SUBMIT_COMPRESSED) { auto clientFrameId = msg.nextUint(); diff --git a/src/lib/grok/messenger.cc b/src/lib/grok/messenger.cc index eee765dee..942912677 100644 --- a/src/lib/grok/messenger.cc +++ b/src/lib/grok/messenger.cc @@ -100,7 +100,7 @@ Messenger::processor_thread() break; } - Msg msg(message); + Message msg(message); auto tag = msg.next(); if (tag == GRK_MSGR_BATCH_COMPRESS_INIT) { auto width = msg.nextUint(); @@ -413,7 +413,7 @@ Messenger::schedule_compress(DCPVideo const& proxy, std::function<void(BufferSrc void Messenger::process_compressed(std::string const& message, std::function<void (DCPVideo, uint8_t*, uint32_t)> processor, bool needsRecompression) { - Msg msg(message); + Message msg(message); msg.next(); auto const clientFrameId = msg.nextUint(); auto const compressedFrameId = msg.nextUint(); diff --git a/src/lib/grok/messenger.h b/src/lib/grok/messenger.h index f36f4aeb7..197aadc75 100644 --- a/src/lib/grok/messenger.h +++ b/src/lib/grok/messenger.h @@ -331,63 +331,68 @@ public: }; -struct Msg +class Message { - explicit Msg(const std::string &msg) : ct_(0) +public: + explicit Message(std::string const& msg) { std::stringstream ss(msg); - while(ss.good()) - { + while (ss.good()) { std::string substr; std::getline(ss, substr, ','); - cs_.push_back(substr); + _cs.push_back(substr); } } + std::string next() { - if(ct_ == cs_.size()) - { - getMessengerLogger()->error("Msg: comma separated list exhausted. returning empty."); + if (_ct == _cs.size()) { + getMessengerLogger()->error("Message: comma separated list exhausted. returning empty."); return ""; } - return cs_[ct_++]; + return _cs[_ct++]; } - uint32_t nextUint(void) + uint32_t nextUint() { return (uint32_t)std::stoi(next()); } - std::vector<std::string> cs_; - size_t ct_; +private: + std::vector<std::string> _cs; + size_t _ct = 0; }; -struct ScheduledFrames +class ScheduledFrames { +public: void store(DCPVideo const& val) { - std::unique_lock<std::mutex> lk(mapMutex_); - auto it = map_.find(val.index()); - if (it == map_.end()) - map_.emplace(std::make_pair(val.index(), val)); + std::unique_lock<std::mutex> lk(_mutex); + auto it = _map.find(val.index()); + if (it == _map.end()) { + _map.emplace(std::make_pair(val.index(), val)); + } } + boost::optional<DCPVideo> retrieve(size_t index) { - std::unique_lock<std::mutex> lk(mapMutex_); - auto it = map_.find(index); - if(it == map_.end()) + std::unique_lock<std::mutex> lk(_mutex); + auto it = _map.find(index); + if (it == _map.end()) { return {}; + } DCPVideo val = it->second; - map_.erase(index); + _map.erase(index); return val; } - private: - std::mutex mapMutex_; - std::map<size_t, DCPVideo> map_; +private: + std::mutex _mutex; + std::map<size_t, DCPVideo> _map; }; |
