forked from ProgrammerAndHacker/media-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathActiveSpeakerMultiplexer.h
90 lines (76 loc) · 2.53 KB
/
ActiveSpeakerMultiplexer.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef ACTIVESPEAKERMULTIPLEXER_H
#define ACTIVESPEAKERMULTIPLEXER_H
#include "config.h"
#include "rtp/RTPIncomingMediaStream.h"
#include "rtp/RTPStreamTransponder.h"
#include "TimeService.h"
class ActiveSpeakerMultiplexer :
public RTPIncomingMediaStream::Listener
{
private:
struct Source
{
uint32_t id;
RTPIncomingMediaStream* incoming = nullptr;
uint64_t score = 0;
uint64_t ts = 0;
std::vector<RTPPacket::shared> packets;
Source(uint32_t id, RTPIncomingMediaStream* incoming) :
id(id),
incoming(incoming)
{
}
bool operator<(const Source& b)
{
return score < b.score;
}
};
struct Destination
{
uint32_t id;
RTPStreamTransponder* transponder = nullptr;
uint64_t ts = 0;
uint64_t sourceId = 0;
Destination(uint32_t id, RTPStreamTransponder* transponder) :
id(id),
transponder(transponder)
{
}
};
public:
class Listener
{
public:
virtual ~Listener() = default;
virtual void onActiveSpeakerChanged(uint32_t speakerId, uint32_t multiplexdId) = 0;
virtual void onActiveSpeakerRemoved(uint32_t multiplexdId) = 0;
};
public:
ActiveSpeakerMultiplexer(TimeService& timeService, Listener* listener);
virtual ~ActiveSpeakerMultiplexer();
void AddIncomingSourceGroup(RTPIncomingMediaStream* incoming, uint32_t id);
void RemoveIncomingSourceGroup(RTPIncomingMediaStream* incoming);
void AddRTPStreamTransponder(RTPStreamTransponder* transpoder, uint32_t id);
void RemoveRTPStreamTransponder(RTPStreamTransponder* transpoder);
virtual void onRTP(RTPIncomingMediaStream* stream, const RTPPacket::shared& packet) override;
virtual void onRTP(RTPIncomingMediaStream* stream, const std::vector<RTPPacket::shared>& packets) override;
virtual void onBye(RTPIncomingMediaStream* stream) override;
virtual void onEnded(RTPIncomingMediaStream* stream) override;
void SetMaxAccumulatedScore(uint64_t maxAcummulatedScore) { this->maxAcummulatedScore = maxAcummulatedScore; }
void SetNoiseGatingThreshold(uint8_t noiseGatingThreshold) { this->noiseGatingThreshold = noiseGatingThreshold; }
void SetMinActivationScore(uint32_t minActivationScore) { this->minActivationScore = minActivationScore; }
void Stop();
private:
void Process(uint64_t now);
private:
TimeService& timeService;
Timer::shared timer;
Listener* listener;
uint64_t last = 0;
uint64_t maxAcummulatedScore = 2500;
uint8_t noiseGatingThreshold = 127;
uint64_t minActivationScore = 0;
std::map<RTPIncomingMediaStream*, Source> sources;
std::map<RTPStreamTransponder*, Destination> destinations;
};
#endif /* ACTIVESPEAKERMULTIPLEXER_H */