Skip to content

Commit

Permalink
Tidy: Use the auto type specifier instead of duplicating types. (libm…
Browse files Browse the repository at this point in the history
…ythtv)

The clang-tidy "use auto" modernization checker pointed out a ton of
places where a type specifier was duplicated, e.g. "Foo *var = new
Foo();", where the code can be simplified by using the new "auto"
keyword.  The previous example will be updated to read "auto *var =
new Foo();".  This example looks trivial, but when "Foo" is a 25
character QMap or something even longer, it makes the code easier to
read.  All replacements made by clang-tidy with some manual
reformatting.

There are a couple of manual replacements of begin()/end() with
cbegin()/cend() to ensure that iterators are still const when using
the "auto" keyword.

There is also one tweak for a place where a pointer was malloced with
"sizeof(*ptr)" as the number of bytes of data.

https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-auto.html
  • Loading branch information
linuxdude42 committed Dec 2, 2019
1 parent acf2aeb commit 5b74a52
Show file tree
Hide file tree
Showing 131 changed files with 620 additions and 692 deletions.
27 changes: 13 additions & 14 deletions mythtv/libs/libmythtv/AirPlay/mythairplayserver.cpp
Expand Up @@ -537,7 +537,7 @@ void MythAirplayServer::newConnection(QTcpSocket *client)
void MythAirplayServer::deleteConnection(void)
{
QMutexLocker locker(m_lock);
QTcpSocket *socket = dynamic_cast<QTcpSocket *>(sender());
auto *socket = dynamic_cast<QTcpSocket *>(sender());
if (!socket)
return;

Expand Down Expand Up @@ -601,7 +601,7 @@ void MythAirplayServer::deleteConnection(QTcpSocket *socket)
void MythAirplayServer::read(void)
{
QMutexLocker locker(m_lock);
QTcpSocket *socket = dynamic_cast<QTcpSocket *>(sender());
auto *socket = dynamic_cast<QTcpSocket *>(sender());
if (!socket)
return;

Expand All @@ -612,7 +612,7 @@ void MythAirplayServer::read(void)

if (!m_incoming.contains(socket))
{
APHTTPRequest *request = new APHTTPRequest(buf);
auto *request = new APHTTPRequest(buf);
m_incoming.insert(socket, request);
}
else
Expand Down Expand Up @@ -807,7 +807,7 @@ void MythAirplayServer::HandleResponse(APHTTPRequest *req,
if (req->GetMethod() == "POST")
{
// this may be received before playback starts...
uint64_t intpos = (uint64_t)pos;
auto intpos = (uint64_t)pos;
m_connections[session].m_position = pos;
LOG(VB_GENERAL, LOG_INFO, LOC +
QString("Scrub: (post) seek to %1").arg(intpos));
Expand Down Expand Up @@ -1210,8 +1210,7 @@ void MythAirplayServer::StartPlayback(const QString &pathname)
LOG(VB_PLAYBACK, LOG_DEBUG, LOC +
QString("Sending ACTION_HANDLEMEDIA for %1")
.arg(pathname));
MythEvent* me = new MythEvent(ACTION_HANDLEMEDIA,
QStringList(pathname));
auto* me = new MythEvent(ACTION_HANDLEMEDIA, QStringList(pathname));
qApp->postEvent(GetMythMainWindow(), me);
// Wait until we receive that the play has started
gCoreContext->WaitUntilSignals(SIGNAL(TVPlaybackStarted()),
Expand All @@ -1229,8 +1228,8 @@ void MythAirplayServer::StopPlayback(void)
QString("Sending ACTION_STOP for %1")
.arg(m_pathname));

QKeyEvent* ke = new QKeyEvent(QEvent::KeyPress, 0,
Qt::NoModifier, ACTION_STOP);
auto* ke = new QKeyEvent(QEvent::KeyPress, 0,
Qt::NoModifier, ACTION_STOP);
qApp->postEvent(GetMythMainWindow(), (QEvent*)ke);
// Wait until we receive that playback has stopped
gCoreContext->WaitUntilSignals(SIGNAL(TVPlaybackStopped()),
Expand All @@ -1255,8 +1254,8 @@ void MythAirplayServer::SeekPosition(uint64_t position)
.arg(position)
.arg(m_pathname));

MythEvent* me = new MythEvent(ACTION_SEEKABSOLUTE,
QStringList(QString::number(position)));
auto* me = new MythEvent(ACTION_SEEKABSOLUTE,
QStringList(QString::number(position)));
qApp->postEvent(GetMythMainWindow(), me);
// Wait until we receive that the seek has completed
gCoreContext->WaitUntilSignals(SIGNAL(TVPlaybackSought(qint64)),
Expand All @@ -1281,8 +1280,8 @@ void MythAirplayServer::PausePlayback(void)
QString("Sending ACTION_PAUSE for %1")
.arg(m_pathname));

QKeyEvent* ke = new QKeyEvent(QEvent::KeyPress, 0,
Qt::NoModifier, ACTION_PAUSE);
auto* ke = new QKeyEvent(QEvent::KeyPress, 0,
Qt::NoModifier, ACTION_PAUSE);
qApp->postEvent(GetMythMainWindow(), (QEvent*)ke);
// Wait until we receive that playback has stopped
gCoreContext->WaitUntilSignals(SIGNAL(TVPlaybackPaused()),
Expand All @@ -1307,8 +1306,8 @@ void MythAirplayServer::UnpausePlayback(void)
QString("Sending ACTION_PLAY for %1")
.arg(m_pathname));

QKeyEvent* ke = new QKeyEvent(QEvent::KeyPress, 0,
Qt::NoModifier, ACTION_PLAY);
auto* ke = new QKeyEvent(QEvent::KeyPress, 0,
Qt::NoModifier, ACTION_PLAY);
qApp->postEvent(GetMythMainWindow(), (QEvent*)ke);
// Wait until we receive that playback has stopped
gCoreContext->WaitUntilSignals(SIGNAL(TVPlaybackPlaying()),
Expand Down
14 changes: 7 additions & 7 deletions mythtv/libs/libmythtv/AirPlay/mythraopconnection.cpp
Expand Up @@ -319,7 +319,7 @@ void MythRAOPConnection::udpDataReady(QByteArray buf, const QHostAddress& /*peer

// Check that the audio packet is valid, do so by decoding it. If an error
// occurs, ask to resend it
QList<AudioData> *decoded = new QList<AudioData>();
auto *decoded = new QList<AudioData>();
int numframes = decodeAudioPacket(type, &buf, decoded);
if (numframes < 0)
{
Expand Down Expand Up @@ -627,7 +627,7 @@ uint32_t MythRAOPConnection::decodeAudioPacket(uint8_t type,
tmp_pkt.size = len;

uint32_t frames_added = 0;
uint8_t *samples = (uint8_t *)av_mallocz(AudioOutput::MAX_SIZE_BUFFER);
auto *samples = (uint8_t *)av_mallocz(AudioOutput::MAX_SIZE_BUFFER);
while (tmp_pkt.size > 0)
{
int data_size;
Expand Down Expand Up @@ -817,7 +817,7 @@ void MythRAOPConnection::audioRetry(void)
*/
void MythRAOPConnection::readClient(void)
{
QTcpSocket *socket = dynamic_cast<QTcpSocket *>(sender());
auto *socket = dynamic_cast<QTcpSocket *>(sender());
if (!socket)
return;

Expand Down Expand Up @@ -959,7 +959,7 @@ void MythRAOPConnection::ProcessRequest(const QStringList &header,
if (!LoadKey())
return;
int tosize = RSA_size(LoadKey());
uint8_t *to = new uint8_t[tosize];
auto *to = new uint8_t[tosize];

QByteArray challenge =
QByteArray::fromBase64(tags["Apple-Challenge"].toLatin1());
Expand Down Expand Up @@ -1618,7 +1618,7 @@ bool MythRAOPConnection::CreateDecoder(void)
m_codeccontext = avcodec_alloc_context3(m_codec);
if (m_codeccontext)
{
unsigned char *extradata = new unsigned char[36];
auto *extradata = new unsigned char[36];
memset(extradata, 0, 36);
if (m_audioFormat.size() < 12)
{
Expand Down Expand Up @@ -1734,7 +1734,7 @@ int64_t MythRAOPConnection::AudioCardLatency(void)
if (!m_audio)
return 0;

int16_t *samples = (int16_t *)av_mallocz(AudioOutput::MAX_SIZE_BUFFER);
auto *samples = (int16_t *)av_mallocz(AudioOutput::MAX_SIZE_BUFFER);
int frames = AUDIOCARD_BUFFER * m_frameRate / 1000;
m_audio->AddData((char *)samples,
frames * (m_sampleSize>>3) * m_channels,
Expand All @@ -1760,7 +1760,7 @@ void MythRAOPConnection::newEventClient(QTcpSocket *client)

void MythRAOPConnection::deleteEventClient(void)
{
QTcpSocket *client = dynamic_cast<QTcpSocket *>(sender());
auto *client = dynamic_cast<QTcpSocket *>(sender());
QString label;

if (client != nullptr)
Expand Down
3 changes: 1 addition & 2 deletions mythtv/libs/libmythtv/AirPlay/mythraopdevice.cpp
Expand Up @@ -215,8 +215,7 @@ void MythRAOPDevice::newConnection(QTcpSocket *client)
n.SetVisibility(n.GetVisibility() & ~MythNotification::kPlayback);
GetNotificationCenter()->Queue(n);

MythRAOPConnection *obj =
new MythRAOPConnection(this, client, m_hardwareId, 6000);
auto *obj = new MythRAOPConnection(this, client, m_hardwareId, 6000);

if (obj->Init())
{
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/Bluray/avformatdecoderbd.cpp
Expand Up @@ -30,7 +30,7 @@ void AvFormatDecoderBD::UpdateFramesPlayed(void)
if (!ringBuffer->IsBD())
return;

long long currentpos = (long long)(ringBuffer->BD()->GetCurrentTime() * m_fps);
auto currentpos = (long long)(ringBuffer->BD()->GetCurrentTime() * m_fps);
m_framesPlayed = m_framesRead = currentpos ;
m_parent->SetFramesPlayed(currentpos + 1);
}
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/Bluray/bdiowrapper.cpp
Expand Up @@ -57,7 +57,7 @@ static BD_DIR_H *dir_open_mythiowrapper(const char* dirname)
return sDefaultDirOpen(dirname);
}

BD_DIR_H *dir = (BD_DIR_H*)calloc(1, sizeof(BD_DIR_H));
auto *dir = (BD_DIR_H*)calloc(1, sizeof(BD_DIR_H));

LOG(VB_FILE, LOG_DEBUG, LOC + QString("Opening mythdir dir %1...").arg(dirname));
dir->close = dir_close_mythiowrapper;
Expand Down Expand Up @@ -119,7 +119,7 @@ static BD_FILE_H *file_open_mythiowrapper(const char* filename, const char *cmod
return sDefaultFileOpen(filename, cmode);
}

BD_FILE_H *file = (BD_FILE_H*)calloc(1, sizeof(BD_FILE_H));
auto *file = (BD_FILE_H*)calloc(1, sizeof(BD_FILE_H));

LOG(VB_FILE, LOG_DEBUG, LOC + QString("Opening mythfile file %1...").arg(filename));
file->close = file_close_mythiowrapper;
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/Bluray/bdoverlayscreen.cpp
Expand Up @@ -51,7 +51,7 @@ void BDOverlayScreen::DisplayBDOverlay(BDOverlay *overlay)
if (image)
{
image->Assign(img);
MythUIImage *uiimage = new MythUIImage(this, "bdoverlay");
auto *uiimage = new MythUIImage(this, "bdoverlay");
if (uiimage)
{
uiimage->SetImage(image);
Expand Down
10 changes: 5 additions & 5 deletions mythtv/libs/libmythtv/Bluray/bdringbuffer.cpp
Expand Up @@ -105,21 +105,21 @@ void BDOverlay::wipe(int x, int y, int width, int height)

static void HandleOverlayCallback(void *data, const bd_overlay_s *const overlay)
{
BDRingBuffer *bdrb = (BDRingBuffer*) data;
auto *bdrb = (BDRingBuffer*) data;
if (bdrb)
bdrb->SubmitOverlay(overlay);
}

static void HandleARGBOverlayCallback(void *data, const bd_argb_overlay_s *const overlay)
{
BDRingBuffer *bdrb = (BDRingBuffer*) data;
auto *bdrb = (BDRingBuffer*) data;
if (bdrb)
bdrb->SubmitARGBOverlay(overlay);
}

static void file_opened_callback(void* bdr)
{
BDRingBuffer *obj = (BDRingBuffer*)bdr;
auto *obj = (BDRingBuffer*)bdr;
if (obj)
obj->ProgressUpdate();
}
Expand Down Expand Up @@ -1728,7 +1728,7 @@ void BDRingBuffer::SubmitOverlay(const bd_overlay_s * const overlay)
case BD_OVERLAY_FLUSH: /* all changes have been done, flush overlay to display at given pts */
if (osd)
{
BDOverlay* newOverlay = new BDOverlay(*osd);
auto* newOverlay = new BDOverlay(*osd);
newOverlay->m_image =
osd->m_image.convertToFormat(QImage::Format_ARGB32);
newOverlay->m_pts = overlay->pts;
Expand Down Expand Up @@ -1811,7 +1811,7 @@ void BDRingBuffer::SubmitARGBOverlay(const bd_argb_overlay_s * const overlay)
if (osd)
{
QMutexLocker lock(&m_overlayLock);
BDOverlay* newOverlay = new BDOverlay(*osd);
auto* newOverlay = new BDOverlay(*osd);
newOverlay->m_pts = overlay->pts;
m_overlayImages.append(newOverlay);
}
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/DVD/avformatdecoderdvd.cpp
Expand Up @@ -56,7 +56,7 @@ void AvFormatDecoderDVD::UpdateFramesPlayed(void)
if (!ringBuffer->IsDVD())
return;

long long currentpos = (long long)(ringBuffer->DVD()->GetCurrentTime() * m_fps);
auto currentpos = (long long)(ringBuffer->DVD()->GetCurrentTime() * m_fps);
m_framesPlayed = m_framesRead = currentpos ;
m_parent->SetFramesPlayed(currentpos + 1);
}
Expand Down
18 changes: 6 additions & 12 deletions mythtv/libs/libmythtv/DVD/dvdringbuffer.cpp
Expand Up @@ -738,8 +738,7 @@ int DVDRingBuffer::safe_read(void *data, uint sz)
case DVDNAV_CELL_CHANGE:
{
// get event details
dvdnav_cell_change_event_t *cell_event =
(dvdnav_cell_change_event_t*) (blockBuf);
auto *cell_event = (dvdnav_cell_change_event_t*) (blockBuf);

// update information for the current cell
m_cellChanged = true;
Expand Down Expand Up @@ -847,8 +846,7 @@ int DVDRingBuffer::safe_read(void *data, uint sz)
case DVDNAV_SPU_STREAM_CHANGE:
{
// get event details
dvdnav_spu_stream_change_event_t* spu =
(dvdnav_spu_stream_change_event_t*)(blockBuf);
auto* spu = (dvdnav_spu_stream_change_event_t*)(blockBuf);

// clear any existing subs/buttons
IncrementButtonVersion;
Expand All @@ -875,8 +873,7 @@ int DVDRingBuffer::safe_read(void *data, uint sz)
case DVDNAV_AUDIO_STREAM_CHANGE:
{
// get event details
dvdnav_audio_stream_change_event_t* audio =
(dvdnav_audio_stream_change_event_t*)(blockBuf);
auto* audio = (dvdnav_audio_stream_change_event_t*)(blockBuf);

// retrieve the new track
int new_track = GetAudioTrackNum(audio->physical);
Expand Down Expand Up @@ -1082,8 +1079,7 @@ int DVDRingBuffer::safe_read(void *data, uint sz)
case DVDNAV_VTS_CHANGE:
{
// retrieve event details
dvdnav_vts_change_event_t* vts =
(dvdnav_vts_change_event_t*)(blockBuf);
auto* vts = (dvdnav_vts_change_event_t*)(blockBuf);

// update player
int aspect = dvdnav_get_video_aspect(m_dvdnav);
Expand Down Expand Up @@ -1125,8 +1121,7 @@ int DVDRingBuffer::safe_read(void *data, uint sz)
case DVDNAV_HIGHLIGHT:
{
// retrieve details
dvdnav_highlight_event_t* hl =
(dvdnav_highlight_event_t*)(blockBuf);
auto* hl = (dvdnav_highlight_event_t*)(blockBuf);

// update the current button
m_menuBtnLock.lock();
Expand All @@ -1153,8 +1148,7 @@ int DVDRingBuffer::safe_read(void *data, uint sz)
case DVDNAV_STILL_FRAME:
{
// retrieve still frame details (length)
dvdnav_still_event_t* still =
(dvdnav_still_event_t*)(blockBuf);
auto* still = (dvdnav_still_event_t*)(blockBuf);

if (!bReprocessing && !m_skipstillorwait)
{
Expand Down
9 changes: 4 additions & 5 deletions mythtv/libs/libmythtv/HLS/httplivestream.cpp
Expand Up @@ -816,8 +816,7 @@ DTC::LiveStreamInfo *HTTPLiveStream::StartStream(void)
if (GetDBStatus() != kHLSStatusQueued)
return GetLiveStreamInfo();

HTTPLiveStreamThread *streamThread =
new HTTPLiveStreamThread(GetStreamID());
auto *streamThread = new HTTPLiveStreamThread(GetStreamID());
MThreadPool::globalInstance()->startReserved(streamThread,
"HTTPLiveStream");
MythTimer statusTimer;
Expand Down Expand Up @@ -852,7 +851,7 @@ bool HTTPLiveStream::RemoveStream(int id)
return false;
}

HTTPLiveStream *hls = new HTTPLiveStream(id);
auto *hls = new HTTPLiveStream(id);

if (hls->GetDBStatus() == kHLSStatusRunning) {
HTTPLiveStream::StopStream(id);
Expand Down Expand Up @@ -927,7 +926,7 @@ DTC::LiveStreamInfo *HTTPLiveStream::StopStream(int id)
return nullptr;
}

HTTPLiveStream *hls = new HTTPLiveStream(id);
auto *hls = new HTTPLiveStream(id);
if (!hls)
return nullptr;

Expand Down Expand Up @@ -996,7 +995,7 @@ DTC::LiveStreamInfo *HTTPLiveStream::GetLiveStreamInfo(

DTC::LiveStreamInfoList *HTTPLiveStream::GetLiveStreamInfoList(const QString &FileName)
{
DTC::LiveStreamInfoList *infoList = new DTC::LiveStreamInfoList();
auto *infoList = new DTC::LiveStreamInfoList();

QString sql = "SELECT id FROM livestream ";

Expand Down
11 changes: 5 additions & 6 deletions mythtv/libs/libmythtv/HLS/httplivestreambuffer.cpp
Expand Up @@ -414,7 +414,7 @@ class HLSStream
for (; it != m_segments.end(); ++it)
{
const HLSSegment *old = *it;
HLSSegment *segment = new HLSSegment(*old);
auto *segment = new HLSSegment(*old);
AppendSegment(segment);
}
}
Expand Down Expand Up @@ -560,8 +560,7 @@ class HLSStream
#ifndef USING_LIBCRYPTO
QString m_keypath;
#endif
HLSSegment *segment = new HLSSegment(duration, id, title, psz_uri,
m_keypath);
auto *segment = new HLSSegment(duration, id, title, psz_uri, m_keypath);
AppendSegment(segment);
m_duration += duration;
}
Expand Down Expand Up @@ -1389,7 +1388,7 @@ class PlaylistWorker : public MThread
*/
int ReloadPlaylist(void)
{
StreamsList *streams = new StreamsList;
auto *streams = new StreamsList;

LOG(VB_PLAYBACK, LOG_INFO, LOC + "reloading HLS live meta playlist");

Expand Down Expand Up @@ -2767,8 +2766,8 @@ int HLSRingBuffer::DurationForBytes(uint size)
{
return 0;
}
uint64_t byterate = (uint64_t)(((double)segment->Size()) /
((double)segment->Duration()));
auto byterate = (uint64_t)(((double)segment->Size()) /
((double)segment->Duration()));

return (int)((size * 1000.0) / byterate);
}
Expand Down

0 comments on commit 5b74a52

Please sign in to comment.