reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
KurentoBridgeMixer.cxx
Go to the documentation of this file.
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4
6#include "ReconSubsystem.hxx"
7#include "Participant.hxx"
9#include "Conversation.hxx"
10
11#include <rutil/Log.hxx>
12#include <rutil/Logger.hxx>
13
14#ifndef max
15#define max(x,y) (((x)>(y))?(x):(y))
16#endif
17
18using namespace recon;
19using namespace resip;
20using namespace std;
21
22#define RESIPROCATE_SUBSYSTEM ReconSubsystem::RECON
23
25{
26 // Set default to 0 gain for entire matrix
27 memset(mMixMatrix, 0, sizeof(mMixMatrix));
28}
29
33
34void
36{
37 int bridgePort = participant->getConnectionPortOnBridge();
38 KurentoBridgeGain inputBridgeWeights[DEFAULT_BRIDGE_MAX_IN_OUTPUTS];
39
40 InfoLog( << "calculatingMixWeigthsForParticipant, handle=" << participant->getParticipantHandle() << ", bridgePort=" << bridgePort << ", hasInput=" << participant->hasInput() << ", hasOutput=" << participant->hasOutput());
41
42 if(bridgePort != -1)
43 {
44 // Default All Inputs/Outputs to 0, then calculate non-zero inputs/outputs
45 for(int i = 0; i < DEFAULT_BRIDGE_MAX_IN_OUTPUTS; i++)
46 {
47 // If we have input capabilities, then clear out other participants outputs to us
48 if (participant->hasInput())
49 {
50 mMixMatrix[bridgePort][i] = 0;
51 }
52 // If we have output capabilites, then clear out other participants inputs from us
53 if (participant->hasOutput())
54 {
55 mMixMatrix[i][bridgePort] = 0;
56 }
57 inputBridgeWeights[i] = 0;
58 }
59
60 // Walk through all Conversations this Participant is in
61 const Participant::ConversationMap& partConvs = participant->getConversations();
62
63 Participant::ConversationMap::const_iterator it1;
64 for(it1 = partConvs.begin(); it1 != partConvs.end(); it1++)
65 {
66 //InfoLog( << "calculateMixWeightsForParticipant: part=" << participant->getParticipantHandle() << ", conv=" << it1->second->getHandle());
67 // Walk through each participant in this Conversation
68 Conversation::ParticipantMap& convParts = it1->second->getParticipants();
69 Conversation::ParticipantMap::iterator it2;
70 it2 = convParts.find(participant->getParticipantHandle()); // Get the participants gain settings in this conversation
71 unsigned int participantOutputGain = 0;
72 unsigned int participantInputGain = 0;
73 if(it2 != convParts.end()) // if we are in the middle of removing a participant from a conversation then they may not exist in the conversation list any more
74 {
75 participantOutputGain = it2->second.getOutputGain();
76 participantInputGain = it2->second.getInputGain();
77 }
78 for(it2 = convParts.begin(); it2 != convParts.end(); it2++)
79 {
80 //InfoLog( << "calculateMixWeightsForParticipant: part=" << participant->getParticipantHandle() << ", conv=" << it1->second->getHandle() << ", otherpart=" << it2->second.getParticipant()->getParticipantHandle() << ", hasInput=" << it2->second.getParticipant()->hasInput() << ", hasOutput=" << it2->second.getParticipant()->hasOutput());
81 // If we found a participant that is not ourself
82 if(it2->second.getParticipant()->getParticipantHandle() != participant->getParticipantHandle())
83 {
84 int otherBridgePort = it2->second.getParticipant()->getConnectionPortOnBridge();
85 //if (otherBridgePort != -1 && otherBridgePort != bridgePort) // Note otherBridgePort can equal bridge port if multiple media participants of the same type exist
86 if (otherBridgePort != -1)
87 {
88 if (participant->hasInput() && // Only look at outputs from other participants if we have an input, and
89 it2->second.getParticipant()->hasOutput()) // Only look at other participant if it has an output
90 {
91 // Calculate the mixed output gain from the other participant to us
92 unsigned int outputGain = ((it2->second.getOutputGain() * participantInputGain) / 100) * 10; // 10 factor is to bring inline with MrpBridgeWeight int type
93 mMixMatrix[bridgePort][otherBridgePort] = max((int)outputGain, mMixMatrix[bridgePort][otherBridgePort]);
94 }
95
96 if (participant->hasOutput() && // Only look at inputs to other participants if we have an output, and
97 it2->second.getParticipant()->hasInput()) // Only look at other participants that have an input and can accept our output
98 {
99 // Calculate the mixed input gain for the other participant
100 unsigned int inputGain = ((it2->second.getInputGain() * participantOutputGain) / 100) * 10; // 10 factor is to bring inline with MrpBridgeWeight int type
101 inputBridgeWeights[otherBridgePort] = mMixMatrix[otherBridgePort][bridgePort] = max((int)inputGain, mMixMatrix[otherBridgePort][bridgePort]);
102 }
103 //InfoLog(<< "Setting mix level for bridge ports: " << bridgePort << " and " << otherBridgePort << ": outputGain=" << mMixMatrix[bridgePort][otherBridgePort]/10 << ", inputGain=" << inputBridgeWeights[otherBridgePort]/10);
104 }
105 }
106 }
107 }
108
109 //outputBridgeMixWeights();
110
111 // Apply new bridge weights
112 if (participant->hasInput())
113 {
114 // Apply mix outputs for other participants if we have an input
115 // FIXME Kurento MprBridge::setMixWeightsForOutput(DEFAULT_BRIDGE_RESOURCE_NAME, *mMediaInterface.getMsgQ(), bridgePort, DEFAULT_BRIDGE_MAX_IN_OUTPUTS, mMixMatrix[bridgePort]);
116 }
117 if (participant->hasOutput())
118 {
119 // Apply mix inputs to other participants if we have an output
120 // FIXME Kurento MprBridge::setMixWeightsForInput(DEFAULT_BRIDGE_RESOURCE_NAME, *mMediaInterface.getMsgQ(), bridgePort, DEFAULT_BRIDGE_MAX_IN_OUTPUTS, inputBridgeWeights);
121 }
122 }
123}
124
125void
127{
128 int i;
129 Data data;
130 data = " ";
131 for(i = 0; i < DEFAULT_BRIDGE_MAX_IN_OUTPUTS; i++)
132 {
133 if(i < 10)
134 {
135 data += " " + Data(i);
136 }
137 else
138 {
139 data += " " + Data(i);
140 }
141 }
142 InfoLog( << data);
143
144 data = "-";
145 for(i = 0; i < DEFAULT_BRIDGE_MAX_IN_OUTPUTS; i++)
146 {
147 data += "----";
148 }
149 InfoLog( << data);
150
151 for(i = 0; i < DEFAULT_BRIDGE_MAX_IN_OUTPUTS; i++)
152 {
153 if(i < 10)
154 {
155 data = Data(i) + " |";
156 }
157 else
158 {
159 data = Data(i) + "|";
160 }
161 for(int j = 0; j < DEFAULT_BRIDGE_MAX_IN_OUTPUTS; j++)
162 {
163 if(mMixMatrix[i][j]/10 < 10)
164 {
165 data += " " + Data(mMixMatrix[i][j]/10) + " ";
166 }
167 else if(mMixMatrix[i][j]/10 < 100)
168 {
169 data += Data(mMixMatrix[i][j]/10) + " ";
170 }
171 else
172 {
173 data += Data(mMixMatrix[i][j]/10) + " ";
174 }
175 }
176 InfoLog( << data);
177 }
178}
179
180
181/* ====================================================================
182
183 Copyright (c) 2021, SIP Spectrum, Inc. www.sipspectrum.com
184 Copyright (c) 2021, Daniel Pocock https://danielpocock.com
185 Copyright (c) 2007-2008, Plantronics, Inc.
186 All rights reserved.
187
188 Redistribution and use in source and binary forms, with or without
189 modification, are permitted provided that the following conditions are
190 met:
191
192 1. Redistributions of source code must retain the above copyright
193 notice, this list of conditions and the following disclaimer.
194
195 2. Redistributions in binary form must reproduce the above copyright
196 notice, this list of conditions and the following disclaimer in the
197 documentation and/or other materials provided with the distribution.
198
199 3. Neither the name of Plantronics nor the names of its contributors
200 may be used to endorse or promote products derived from this
201 software without specific prior written permission.
202
203 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
204 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
205 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
207 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
208 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
209 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
210 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
211 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
212 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
213 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
214
215 ==================================================================== */
#define max(x, y)
#define InfoLog(args_)
Definition Logger.hxx:131
std::map< ParticipantHandle, ConversationParticipantAssignment > ParticipantMap
void calculateMixWeightsForParticipant(Participant *participant)
Calculates all of the current mixer settings required for the passed in participant and applies them.
void outputBridgeMixWeights()
Logs a multiline representation of the current state of the mixing matrix.
This is the base class for a RemoteParticipant, LocalParticipant and a MediaResourceParticipant.
virtual bool hasInput()=0
std::map< ConversationHandle, Conversation * > ConversationMap
virtual bool hasOutput()=0
virtual ParticipantHandle getParticipantHandle()
const ConversationMap & getConversations()
virtual int getConnectionPortOnBridge()=0
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
dcm! – add UnusedChecking(_enum) below;