MT#59962 core/MultiPartyMixer: use smart pointers

Automatically manage allocated storage and objects.

Change-Id: I1b2f3d3dfc08e3b461fdc35badd520045783e0f5
mr13.3.1
Richard Fuchs 10 months ago
parent d349c5f900
commit 3b86b6dd60

@ -56,14 +56,6 @@ AmMultiPartyMixer::AmMultiPartyMixer()
{
}
AmMultiPartyMixer::~AmMultiPartyMixer()
{
for (std::deque<MixerBufferState>::iterator it = buffer_state.begin();
it != buffer_state.end(); it++) {
it->free_channels();
}
}
unsigned int AmMultiPartyMixer::addChannel(unsigned int external_sample_rate)
{
unsigned int cur_channel_id = 0;
@ -254,7 +246,7 @@ std::deque<MixerBufferState>::iterator AmMultiPartyMixer::findOrCreateBufferStat
}
//DBG("XXDebugMixerXX: Creating buffer state (from PutChannelPacket)");
buffer_state.push_back(MixerBufferState(sample_rate, channelids));
buffer_state.emplace_back(sample_rate, channelids);
std::deque<MixerBufferState>::reverse_iterator rit = buffer_state.rbegin();
//DEBUG_MIXER_BUFFER_STATE(*((rit + 1).base()), "returned to PutChannelPacket");
return (rit + 1).base();
@ -277,7 +269,7 @@ AmMultiPartyMixer::findBufferStateForReading(unsigned int sample_rate,
if (buffer_state.size() < MAX_BUFFER_STATES) {
// DBG("XXDebugMixerXX: Creating buffer state (from GetChannelPacket)\n");
buffer_state.push_back(MixerBufferState(sample_rate, channelids));
buffer_state.emplace_back(sample_rate, channelids);
} // else just reuse the last buffer - conference without a speaker
std::deque<MixerBufferState>::reverse_iterator rit = buffer_state.rbegin();
//DEBUG_MIXER_BUFFER_STATE(*((rit + 1).base()), "returned to PutChannelPacket");
@ -291,7 +283,6 @@ void AmMultiPartyMixer::cleanupBufferStates(unsigned int last_ts)
&& (unsigned int)GetCurrentSampleRate() != buffer_state.front().sample_rate) {
//DEBUG_MIXER_BUFFER_STATE(buffer_state.front(), "freed in cleanupBufferStates");
buffer_state.front().free_channels();
buffer_state.pop_front();
}
}
@ -307,24 +298,13 @@ void AmMultiPartyMixer::unlock()
}
MixerBufferState::MixerBufferState(unsigned int sample_rate, std::set<int>& channelids)
: sample_rate(sample_rate), last_ts(0), channels(), mixed_channel(NULL)
: sample_rate(sample_rate), last_ts(0), channels()
{
for (std::set<int>::iterator it = channelids.begin(); it != channelids.end(); it++) {
channels.insert(std::make_pair(*it,new SampleArrayShort()));
}
mixed_channel = new SampleArrayInt();
}
MixerBufferState::MixerBufferState(const MixerBufferState& other)
: sample_rate(other.sample_rate), last_ts(other.last_ts),
channels(other.channels), mixed_channel(other.mixed_channel)
{
}
MixerBufferState::~MixerBufferState()
{
free_channels();
mixed_channel.reset(new SampleArrayInt());
}
void MixerBufferState::add_channel(unsigned int channel_id)
@ -337,7 +317,6 @@ void MixerBufferState::remove_channel(unsigned int channel_id)
{
ChannelMap::iterator channel_it = channels.find(channel_id);
if (channel_it != channels.end()) {
delete channel_it->second;
channels.erase(channel_it);
}
}
@ -350,7 +329,7 @@ SampleArrayShort* MixerBufferState::get_channel(unsigned int channel_id)
return NULL;
}
return channel_it->second;
return channel_it->second.get();
}
void MixerBufferState::fix_channels(std::set<int>& curchannelids)
@ -362,16 +341,3 @@ void MixerBufferState::fix_channels(std::set<int>& curchannelids)
}
}
}
void MixerBufferState::free_channels()
{
for (ChannelMap::iterator it = channels.begin(); it != channels.end(); it++) {
if (it->second != NULL)
delete it->second;
}
if (mixed_channel) {
delete mixed_channel;
mixed_channel = NULL;
}
}

@ -41,22 +41,20 @@
struct MixerBufferState
{
typedef std::map<int,SampleArrayShort*> ChannelMap;
typedef std::map<int,std::unique_ptr<SampleArrayShort>> ChannelMap;
unsigned int sample_rate;
unsigned int last_ts;
ChannelMap channels;
SampleArrayInt *mixed_channel;
std::unique_ptr<SampleArrayInt> mixed_channel;
MixerBufferState(unsigned int sample_rate, std::set<int>& channelids);
MixerBufferState(const MixerBufferState& other);
~MixerBufferState();
~MixerBufferState() {}
void add_channel(unsigned int channel_id);
void remove_channel(unsigned int channel_id);
SampleArrayShort* get_channel(unsigned int channel_id);
void fix_channels(std::set<int>& curchannelids);
void free_channels();
};
/**
@ -91,7 +89,7 @@ class AmMultiPartyMixer
public:
AmMultiPartyMixer();
~AmMultiPartyMixer();
~AmMultiPartyMixer() {}
unsigned int addChannel(unsigned int external_sample_rate);
void removeChannel(unsigned int channel_id);

Loading…
Cancel
Save