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