forked from Glimesh/janus-ftl-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RelayThreadPool.h
52 lines (45 loc) · 1.17 KB
/
RelayThreadPool.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* @file RelayThreadPool.h
* @author Hayden McAfee (hayden@outlook.com)
* @version 0.1
* @date 2020-08-28
*
* @copyright Copyright (c) 2020 Hayden McAfee
*
*/
#pragma once
#include "RtpRelayPacket.h"
#include <atomic>
#include <memory>
#include <mutex>
#include <vector>
#include <queue>
#include <thread>
#include <condition_variable>
class FtlStreamStore;
class FtlStream;
class RelayThreadPool
{
public:
/* Constructor/Destructor */
RelayThreadPool(
std::shared_ptr<FtlStreamStore> ftlStreamStore,
unsigned int threadCount = std::thread::hardware_concurrency());
/* Public methods */
void Start();
void Stop();
void RelayPacket(RtpRelayPacket packet);
private:
/* Private members */
const std::shared_ptr<FtlStreamStore> ftlStreamStore;
unsigned int threadCount;
std::atomic<bool> stopping { false };
// Packet relay threads
std::mutex threadVectorMutex;
std::mutex relayMutex;
std::vector<std::thread> relayThreads;
std::condition_variable relayThreadCondition;
std::queue<RtpRelayPacket> packetRelayQueue;
/* Private methods */
void relayThreadMethod(unsigned int threadNumber);
};