5G-MAG Reference Tools - MBMS Modem
MultichannelRingbuffer.h
Go to the documentation of this file.
1 // 5G-MAG Reference Tools
2 // MBMS Modem Process
3 //
4 // Copyright (C) 2021 Klaus Kühnhammer (Österreichische Rundfunksender GmbH & Co KG)
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Affero General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Affero General Public License for more details.
15 //
16 // You should have received a copy of the GNU Affero General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 //
19 
20 #pragma once
21 #include <stddef.h>
22 #include <vector>
23 #include <mutex>
24 
26  public:
27  explicit MultichannelRingbuffer(size_t size, size_t channels);
28  virtual ~MultichannelRingbuffer();
29 
30  inline size_t free_size() { std::lock_guard<std::mutex> lock(_mutex); return _size - _used; }
31  inline size_t used_size() { std::lock_guard<std::mutex> lock(_mutex); return _used; }
32  inline size_t capacity() { std::lock_guard<std::mutex> lock(_mutex);return _size; }
33 
34  inline void clear() {std::lock_guard<std::mutex> lock(_mutex); _head = _used = 0; };
35 
36  std::vector<void*> write_head(size_t* writeable);
37  void commit(size_t written);
38 
39  void read(std::vector<char*> dest, size_t bytes);
40 
41  private:
42  std::vector<char*> _buffers;
43  size_t _size;
44  size_t _channels;
45  size_t _head;
46  size_t _used;
47  std::mutex _mutex;
48 };
void read(std::vector< char * > dest, size_t bytes)
std::vector< char * > _buffers
std::vector< void * > write_head(size_t *writeable)
MultichannelRingbuffer(size_t size, size_t channels)