Skip to content

Commit

Permalink
cppcheck: Fix "variable scope can be reduced" warnings in libmyth.
Browse files Browse the repository at this point in the history
Push variable declarations into the nested scope where they are
actually used, and often combine this with the initial assignment of
the variable.
  • Loading branch information
linuxdude42 committed Aug 24, 2018
1 parent 4e72496 commit 83f6013
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion mythtv/libs/libmyth/audio/audioconvert.cpp
Expand Up @@ -575,7 +575,6 @@ class AudioConvertInternal
AudioConvertInternal(AVSampleFormat in, AVSampleFormat out) :
m_in(in), m_out(out)
{
char error[AV_ERROR_MAX_STRING_SIZE];
m_swr = swr_alloc_set_opts(NULL,
av_get_default_channel_layout(1),
m_out,
Expand All @@ -593,6 +592,7 @@ class AudioConvertInternal
int ret = swr_init(m_swr);
if (ret < 0)
{
char error[AV_ERROR_MAX_STRING_SIZE];
LOG(VB_AUDIO, LOG_ERR, LOC +
QString("error initializing resampler context (%1)")
.arg(av_make_error_string(error, sizeof(error), ret)));
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmyth/audio/audiooutput.cpp
Expand Up @@ -378,6 +378,7 @@ AudioOutput::AudioDeviceConfig* AudioOutput::GetAudioDeviceConfig(
(aosettings.canLPCM() << 0) |
(aosettings.canAC3() << 1) |
(aosettings.canDTS() << 2);
// cppcheck-suppress variableScope
static const char *type_names[] = { "LPCM", "AC3", "DTS" };

if (mask != 0)
Expand Down
13 changes: 5 additions & 8 deletions mythtv/libs/libmyth/audio/audiooutputalsa.cpp
Expand Up @@ -254,8 +254,6 @@ QByteArray *AudioOutputALSA::GetELD(int card, int device, int subdevice)
snd_ctl_elem_value_t *control; snd_ctl_elem_value_alloca(&control);
snd_ctl_elem_type_t type;

unsigned int count;

int err;

snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_PCM);
Expand Down Expand Up @@ -290,7 +288,7 @@ QByteArray *AudioOutputALSA::GetELD(int card, int device, int subdevice)
snd_hctl_close(hctl);
return NULL;
}
count = snd_ctl_elem_info_get_count(info);
unsigned int count = snd_ctl_elem_info_get_count(info);
type = snd_ctl_elem_info_get_type(info);
if (!snd_ctl_elem_info_is_readable(info))
{
Expand Down Expand Up @@ -550,7 +548,7 @@ void AudioOutputALSA::WriteAudio(uchar *aubuf, int size)
{
uchar *tmpbuf = aubuf;
uint frames = size / output_bytes_per_frame;
int err, lw = 0;
int err;

if (pcm_handle == NULL)
{
Expand All @@ -570,7 +568,7 @@ void AudioOutputALSA::WriteAudio(uchar *aubuf, int size)

while (frames > 0)
{
lw = snd_pcm_writei(pcm_handle, tmpbuf, frames);
int lw = snd_pcm_writei(pcm_handle, tmpbuf, frames);

if (lw >= 0)
{
Expand Down Expand Up @@ -993,16 +991,15 @@ QMap<QString, QString> *AudioOutputALSA::GetDevices(const char *type)
{
QMap<QString, QString> *alsadevs = new QMap<QString, QString>();
void **hints, **n;
char *name, *desc;

if (snd_device_name_hint(-1, type, &hints) < 0)
return alsadevs;
n = hints;

while (*n != NULL)
{
name = snd_device_name_get_hint(*n, "NAME");
desc = snd_device_name_get_hint(*n, "DESC");
char *name = snd_device_name_get_hint(*n, "NAME");
char *desc = snd_device_name_get_hint(*n, "DESC");
if (name && desc && strcmp(name, "null"))
alsadevs->insert(name, desc);
if (name)
Expand Down
5 changes: 2 additions & 3 deletions mythtv/libs/libmyth/audio/audiooutputbase.cpp
Expand Up @@ -1305,17 +1305,16 @@ int AudioOutputBase::CopyWithUpmix(char *buffer, int frames, uint &org_waud)

int i = 0;
len = 0;
int nFrames, bdFrames;
while (i < frames)
{
i += upmixer->putFrames(buffer + i * off, frames - i, source_channels);
nFrames = upmixer->numFrames();
int nFrames = upmixer->numFrames();
if (!nFrames)
continue;

len += CheckFreeSpace(nFrames);

bdFrames = (kAudioRingBufferSize - org_waud) / bpf;
int bdFrames = (kAudioRingBufferSize - org_waud) / bpf;
if (bdFrames < nFrames)
{
if ((org_waud % bpf) != 0)
Expand Down
3 changes: 1 addition & 2 deletions mythtv/libs/libmyth/audio/audiooutputca.cpp
Expand Up @@ -195,7 +195,6 @@ AudioOutputSettings* AudioOutputCA::GetOutputSettings(bool digital)
AudioOutputSettings *settings = new AudioOutputSettings();

// Seek hardware sample rate available
int rate;
int *rates = d->RatesList(d->mDeviceID);

if (rates == NULL)
Expand All @@ -205,7 +204,7 @@ AudioOutputSettings* AudioOutputCA::GetOutputSettings(bool digital)
}
else
{
while ((rate = settings->GetNextRate()))
while ((int rate = settings->GetNextRate()))
{
int *p_rates = rates;
while (*p_rates > 0)
Expand Down

0 comments on commit 83f6013

Please sign in to comment.