Skip to content

Commit

Permalink
REFAC(client): Remove invalid usage of auto, raw pointers, and expl…
Browse files Browse the repository at this point in the history
…icit `new`
  • Loading branch information
IsaMorphic committed Nov 25, 2023
1 parent 5e263af commit 53a3ff5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
10 changes: 5 additions & 5 deletions src/mumble/AudioOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,16 +404,16 @@ void AudioOutput::initializeMixer(const unsigned int *chanmasks, bool forceheadp
}
}

void AudioOutput::prepareOutputBuffers(unsigned int frameCount, QList< AudioOutputBuffer * > *qlMix,
QList< AudioOutputBuffer * > *qlDel) {
void AudioOutput::prepareOutputBuffers(unsigned int frameCount, QList< AudioOutputBuffer * > &qlMix,
QList< AudioOutputBuffer * > &qlDel) {
// Get the users that are currently talking (and are thus serving as an audio source)
QMultiHash< const ClientUser *, AudioOutputBuffer * >::const_iterator it = qmOutputs.constBegin();
for (int i = 0; i < qmOutputs.count(); i++) {
for (unsigned int i = 0; i < qmOutputs.count(); i++) {
AudioOutputBuffer *buffer = it.value();
if (!buffer->prepareSampleBuffer(frameCount)) {
qlDel->append(buffer);
qlDel.append(buffer);
} else {
qlMix->append(buffer);
qlMix.append(buffer);
}
++it;
}
Expand Down
4 changes: 2 additions & 2 deletions src/mumble/AudioOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ private slots:
void initializeMixer(const unsigned int *chanmasks, bool forceheadphone = false);
bool mix(void *output, unsigned int frameCount);

virtual void prepareOutputBuffers(unsigned int frameCount, QList< AudioOutputBuffer * > *qlMix,
QList< AudioOutputBuffer * > *qlDel);
virtual void prepareOutputBuffers(unsigned int frameCount, QList< AudioOutputBuffer * > &qlMix,
QList< AudioOutputBuffer * > &qlDel);

public:
void wipe();
Expand Down
37 changes: 19 additions & 18 deletions src/mumble/JackAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ bool JackAudioOutput::unregisterPorts() {
}
}

for (auto port : userPorts) {
for (std::pair< QString, jack_port_t * > port : userPorts) {
if (!port.second) {
continue;
}
Expand All @@ -991,7 +991,7 @@ bool JackAudioOutput::unregisterPorts() {
}
}

for (auto buffer : userBuffers) {
for (std::pair< QString, jack_ringbuffer_t * > buffer : userBuffers) {
if (!buffer.second) {
continue;
}
Expand Down Expand Up @@ -1056,16 +1056,16 @@ bool JackAudioOutput::process(const jack_nframes_t frames) {
// This is in spite of the fact that on most POSIX systems, QMutex is actually implemented using semaphores.
qsSleep.release(1);

for (auto userBufferPair : userBuffers) {
QString name = userBufferPair.first;
for (std::pair< QString, jack_ringbuffer_t * > userBufferPair : userBuffers) {
QString name = userBufferPair.first;
jack_ringbuffer_t *ringBuffer = userBufferPair.second;

jack_port_t *port = userPorts[name];
if (!port) {
continue;
}

char *portBuffer = reinterpret_cast< char * >(jas->getPortBuffer(port, frames));
char *portBuffer = static_cast< char * >(jas->getPortBuffer(port, frames));
if (!portBuffer) {
continue;
}
Expand All @@ -1089,7 +1089,7 @@ bool JackAudioOutput::process(const jack_nframes_t frames) {
outputBuffers.replace(currentChannel, reinterpret_cast< jack_default_audio_sample_t * >(outputBuffer));
}

const auto avail = jas->ringbufferReadSpace(buffer);
const size_t avail = jas->ringbufferReadSpace(buffer);
if (avail == 0) {
for (decltype(iChannels) currentChannel = 0; currentChannel < iChannels; ++currentChannel) {
memset(outputBuffers[currentChannel], 0, frames * sizeof(jack_default_audio_sample_t));
Expand All @@ -1109,7 +1109,7 @@ bool JackAudioOutput::process(const jack_nframes_t frames) {
return true;
}

auto samples = qMin(jas->ringbufferReadSpace(buffer), needed) / sizeof(jack_default_audio_sample_t);
size_t samples = qMin(jas->ringbufferReadSpace(buffer), needed) / sizeof(jack_default_audio_sample_t);
for (auto currentSample = decltype(samples){ 0 }; currentSample < samples; ++currentSample) {
jas->ringbufferRead(
buffer, sizeof(jack_default_audio_sample_t),
Expand All @@ -1125,8 +1125,8 @@ bool JackAudioOutput::process(const jack_nframes_t frames) {
return true;
}

void JackAudioOutput::prepareOutputBuffers(unsigned int frameCount, QList< AudioOutputBuffer * > *qlMix,
QList< AudioOutputBuffer * > *qlDel) {
void JackAudioOutput::prepareOutputBuffers(unsigned int frameCount, QList< AudioOutputBuffer * > &qlMix,
QList< AudioOutputBuffer * > &qlDel) {
ServerHandlerPtr sh = Global::get().sh;
VoiceRecorderPtr recorder;
if (sh) {
Expand All @@ -1142,9 +1142,9 @@ void JackAudioOutput::prepareOutputBuffers(unsigned int frameCount, QList< Audio

if (!user || !recorder || (recorder && !recorder->isTransportEnabled())) {
if (audio->prepareSampleBuffer(frameCount)) {
qlMix->append(audio);
qlMix.append(audio);
} else {
qlDel->append(audio);
qlDel.append(audio);
}

++it;
Expand All @@ -1154,7 +1154,7 @@ void JackAudioOutput::prepareOutputBuffers(unsigned int frameCount, QList< Audio
QString qsPortName = user->qsName;
qsPortName = qsPortName.prepend("user_");
if (!userPorts[qsPortName]) {
auto port = jas->registerPort(qsPortName.toStdString().c_str(), JackPortIsOutput);
jack_port_t *port = jas->registerPort(qsPortName.toStdString().c_str(), JackPortIsOutput);
if (!port) {
qWarning("JackAudioOutput: unable to register user port \"%s\"", qsPortName.toStdString().c_str());
} else {
Expand All @@ -1163,18 +1163,19 @@ void JackAudioOutput::prepareOutputBuffers(unsigned int frameCount, QList< Audio
}

if (!userBuffers[qsPortName]) {
auto buffer = jas->ringbufferCreate(iFrameSize * iSampleSize * JACK_BUFFER_PERIODS);
jack_ringbuffer_t *buffer = jas->ringbufferCreate(iFrameSize * iSampleSize * JACK_BUFFER_PERIODS);
if (!buffer) {
qWarning("JackAudioOutput: unable to create user buffer for port \"%s\"", qsPortName.toStdString().c_str());
qWarning("JackAudioOutput: unable to create user buffer for port \"%s\"",
qsPortName.toStdString().c_str());
} else {
jas->ringbufferMlock(buffer);
userBuffers[qsPortName] = buffer;
}
}

std::unique_ptr< float[] > tempBuffer(new float[frameCount]);
auto tempBuffer = std::make_unique< float[] >(frameCount);
if (audio->prepareSampleBuffer(frameCount)) {
qlMix->append(audio);
qlMix.append(audio);

if (audio->bStereo) {
for (unsigned int i = 0; i < frameCount; i++) {
Expand All @@ -1186,14 +1187,14 @@ void JackAudioOutput::prepareOutputBuffers(unsigned int frameCount, QList< Audio
}
}
} else {
qlDel->append(audio);
qlDel.append(audio);

for (unsigned int i = 0; i < frameCount; i++) {
tempBuffer[i] = 0.0f;
}
}

if (const auto buffer = userBuffers[qsPortName]) {
if (jack_ringbuffer_t *buffer = userBuffers[qsPortName]) {
jas->ringbufferWrite(buffer, frameCount * sizeof(jack_default_audio_sample_t), tempBuffer.get());
}

Expand Down
4 changes: 2 additions & 2 deletions src/mumble/JackAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ class JackAudioOutput : public AudioOutput {

jack_ringbuffer_t *buffer;

void prepareOutputBuffers(unsigned int frameCount, QList< AudioOutputBuffer * > *qlMix,
QList< AudioOutputBuffer * > *qlDel) override;
void prepareOutputBuffers(unsigned int frameCount, QList< AudioOutputBuffer * > &qlMix,
QList< AudioOutputBuffer * > &qlDel) override;

public:
bool isReady();
Expand Down

0 comments on commit 53a3ff5

Please sign in to comment.