From c32eb98e6c363793bbff2dfec8ae7fe93d3d9168 Mon Sep 17 00:00:00 2001 From: "Tux3 / Mlkj / !Lev.uXFMLA" Date: Thu, 29 Jan 2015 21:23:33 +0100 Subject: [PATCH] CppCheck, some video perf improvements --- src/core.cpp | 3 +-- src/coreav.cpp | 10 ++++---- src/corestructs.cpp | 7 ++++++ src/corestructs.h | 3 +++ src/friend.cpp | 5 ++-- src/friend.h | 2 ++ src/historykeeper.h | 6 ++--- src/misc/cdata.cpp | 2 +- src/misc/cdata.h | 4 +++- src/misc/cstring.cpp | 2 +- src/misc/cstring.h | 2 +- src/video/camera.cpp | 2 +- src/video/camera.h | 2 +- src/video/cameraworker.cpp | 6 +++++ src/video/cameraworker.h | 3 ++- src/video/netvideosource.h | 2 +- src/video/videosource.h | 2 +- src/widget/form/tabcompleter.cpp | 3 ++- src/widget/form/tabcompleter.h | 2 +- src/widget/groupwidget.cpp | 9 +------ src/widget/tool/chatactions/chataction.h | 3 ++- src/widget/videosurface.cpp | 30 +++++++++++++----------- src/widget/videosurface.h | 2 +- 23 files changed, 64 insertions(+), 48 deletions(-) diff --git a/src/core.cpp b/src/core.cpp index 0b5ff1f74..812e36fc5 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -1251,8 +1251,6 @@ bool Core::loadConfiguration(QString path) // tox core is already decrypted if (Settings::getInstance().getEnableLogging() && Settings::getInstance().getEncryptLogs()) { - bool error = true; - // get salt QFile file(HistoryKeeper::getHistoryPath()); file.open(QIODevice::ReadOnly); @@ -1266,6 +1264,7 @@ bool Core::loadConfiguration(QString path) } else { + bool error = true; do { while (!pwsaltedkeys[ptHistory]) diff --git a/src/coreav.cpp b/src/coreav.cpp index b615661cd..19769a778 100644 --- a/src/coreav.cpp +++ b/src/coreav.cpp @@ -26,7 +26,7 @@ ToxCall Core::calls[TOXAV_MAX_CALLS]; #ifdef QTOX_FILTER_AUDIO -AudioFilterer * Core::filterer[TOXAV_MAX_CALLS] { nullptr}; +AudioFilterer * Core::filterer[TOXAV_MAX_CALLS] {nullptr}; #endif const int Core::videobufsize{TOXAV_MAX_VIDEO_WIDTH * TOXAV_MAX_VIDEO_HEIGHT * 4}; uint8_t* Core::videobuf; @@ -252,10 +252,11 @@ void Core::sendCallAudio(int callId, ToxAv* toxav) const int framesize = (calls[callId].codecSettings.audio_frame_duration * calls[callId].codecSettings.audio_sample_rate) / 1000 * av_DefaultSettings.audio_channels; const int bufsize = framesize * 2 * av_DefaultSettings.audio_channels; - uint8_t buf[bufsize], dest[bufsize]; + uint8_t buf[bufsize]; if (Audio::tryCaptureSamples(buf, framesize)) { + uint8_t dest[bufsize]; int r; if ((r = toxav_prepare_audio_frame(toxav, callId, dest, framesize*2, (int16_t*)buf, framesize)) < 0) { @@ -625,9 +626,8 @@ void Core::sendGroupCallAudio(int groupId, ToxAv* toxav) if (Audio::tryCaptureSamples(buf, framesize)) { - int r; - if ((r = toxav_group_send_audio(toxav_get_tox(toxav), groupId, (int16_t*)buf, - framesize, av_DefaultSettings.audio_channels, av_DefaultSettings.audio_sample_rate)) < 0) + if (toxav_group_send_audio(toxav_get_tox(toxav), groupId, (int16_t*)buf, + framesize, av_DefaultSettings.audio_channels, av_DefaultSettings.audio_sample_rate) < 0) { qDebug() << "Core: toxav_group_send_audio error"; groupCalls[groupId].sendAudioTimer->start(); diff --git a/src/corestructs.cpp b/src/corestructs.cpp index c9712d1fe..bb1d5f415 100644 --- a/src/corestructs.cpp +++ b/src/corestructs.cpp @@ -23,6 +23,13 @@ bool ToxFile::open(bool write) return write ? file->open(QIODevice::ReadWrite) : file->open(QIODevice::ReadOnly); } +ToxID::ToxID(const ToxID& other) +{ + publicKey = other.publicKey; + noSpam = other.noSpam; + checkSum = other.checkSum; +} + QString ToxID::toString() const { return publicKey + noSpam + checkSum; diff --git a/src/corestructs.h b/src/corestructs.h index 82848695e..2b31a71bc 100644 --- a/src/corestructs.h +++ b/src/corestructs.h @@ -16,6 +16,9 @@ enum class Status : int {Online = 0, Away, Busy, Offline}; struct ToxID { + ToxID()=default; + ToxID(const ToxID& other); + QString publicKey; QString noSpam; QString checkSum; diff --git a/src/friend.cpp b/src/friend.cpp index e30b9845f..856e2a58c 100644 --- a/src/friend.cpp +++ b/src/friend.cpp @@ -23,12 +23,11 @@ #include "src/misc/settings.h" Friend::Friend(int FriendId, const ToxID &UserId) - : friendId(FriendId) + : userName{Core::getInstance()->getPeerName(UserId)}, + userID{UserId}, friendId{FriendId} { hasNewEvents = 0; friendStatus = Status::Offline; - userID = UserId; - userName = Core::getInstance()->getPeerName(UserId); if (userName.size() == 0) userName = UserId.publicKey; diff --git a/src/friend.h b/src/friend.h index 7117acc1c..b259b6975 100644 --- a/src/friend.h +++ b/src/friend.h @@ -27,7 +27,9 @@ struct Friend { public: Friend(int FriendId, const ToxID &UserId); + Friend(const Friend& other)=delete; ~Friend(); + Friend& operator=(const Friend& other)=delete; void setName(QString name); void setAlias(QString name); diff --git a/src/historykeeper.h b/src/historykeeper.h index 300232e33..4adbdc79f 100644 --- a/src/historykeeper.h +++ b/src/historykeeper.h @@ -63,10 +63,10 @@ private: void updateAliases(); QPair getChatID(const QString &id_str, ChatType ct); int getAliasID(const QString &id_str); - QString wrapMessage(const QString &str); - QString unWrapMessage(const QString &str); - ChatType convertToChatType(int); + static QString wrapMessage(const QString &str); + static QString unWrapMessage(const QString &str); + static ChatType convertToChatType(int); GenericDdInterface *db; QMap aliases; diff --git a/src/misc/cdata.cpp b/src/misc/cdata.cpp index 18f13ca93..7909ba73c 100644 --- a/src/misc/cdata.cpp +++ b/src/misc/cdata.cpp @@ -36,7 +36,7 @@ uint8_t* CData::data() return cData; } -uint16_t CData::size() +uint16_t CData::size() const { return cDataSize; } diff --git a/src/misc/cdata.h b/src/misc/cdata.h index 6433e9bac..3b37b0627 100644 --- a/src/misc/cdata.h +++ b/src/misc/cdata.h @@ -24,11 +24,13 @@ class CData { public: uint8_t* data(); - uint16_t size(); + uint16_t size() const; protected: explicit CData(const QString& data, uint16_t byteSize); + CData(const CData& other)=delete; virtual ~CData(); + CData& operator=(const CData& other)=delete; static QString toString(const uint8_t* cData, const uint16_t cDataSize); diff --git a/src/misc/cstring.cpp b/src/misc/cstring.cpp index b9217fbc8..8624ae8eb 100644 --- a/src/misc/cstring.cpp +++ b/src/misc/cstring.cpp @@ -46,7 +46,7 @@ uint8_t* CString::data() return cString; } -uint16_t CString::size() +uint16_t CString::size() const { return cStringSize; } diff --git a/src/misc/cstring.h b/src/misc/cstring.h index 869fa29f2..ee21a99a9 100644 --- a/src/misc/cstring.h +++ b/src/misc/cstring.h @@ -31,7 +31,7 @@ public: ~CString(); uint8_t* data(); - uint16_t size(); + uint16_t size() const; static QString toString(const uint8_t* cMessage, const uint16_t cMessageSize); static uint16_t fromString(const QString& message, uint8_t* cMessage); diff --git a/src/video/camera.cpp b/src/video/camera.cpp index 9d30944ae..74f5677e8 100644 --- a/src/video/camera.cpp +++ b/src/video/camera.cpp @@ -99,7 +99,7 @@ double Camera::getProp(Camera::Prop prop) return worker->getProp(int(prop)); } -void Camera::onNewFrameAvailable(const VideoFrame frame) +void Camera::onNewFrameAvailable(const VideoFrame &frame) { emit frameAvailable(frame); diff --git a/src/video/camera.h b/src/video/camera.h index c15e1f005..364ae577c 100644 --- a/src/video/camera.h +++ b/src/video/camera.h @@ -79,7 +79,7 @@ private: CameraWorker* worker; private slots: - void onNewFrameAvailable(const VideoFrame frame); + void onNewFrameAvailable(const VideoFrame& frame); }; diff --git a/src/video/cameraworker.cpp b/src/video/cameraworker.cpp index f7304520c..d4c40731d 100644 --- a/src/video/cameraworker.cpp +++ b/src/video/cameraworker.cpp @@ -29,6 +29,12 @@ CameraWorker::CameraWorker(int index) qRegisterMetaType>(); } +CameraWorker::~CameraWorker() +{ + if (clock) + delete clock; +} + void CameraWorker::onStart() { clock = new QTimer(this); diff --git a/src/video/cameraworker.h b/src/video/cameraworker.h index 5afa9545f..5bda28240 100644 --- a/src/video/cameraworker.h +++ b/src/video/cameraworker.h @@ -34,6 +34,7 @@ class CameraWorker : public QObject Q_OBJECT public: CameraWorker(int index); + ~CameraWorker(); void doWork(); void suspend(); @@ -48,7 +49,7 @@ public slots: signals: void started(); - void newFrameAvailable(const VideoFrame frame); + void newFrameAvailable(const VideoFrame& frame); void resProbingFinished(QList res); void propProbingFinished(int prop, double val); diff --git a/src/video/netvideosource.h b/src/video/netvideosource.h index 4ad6dfd51..c3171727e 100644 --- a/src/video/netvideosource.h +++ b/src/video/netvideosource.h @@ -19,7 +19,7 @@ #include "videosource.h" -class vpx_image; +struct vpx_image; class NetVideoSource : public VideoSource { diff --git a/src/video/videosource.h b/src/video/videosource.h index 4dd14151a..1c9646812 100644 --- a/src/video/videosource.h +++ b/src/video/videosource.h @@ -32,7 +32,7 @@ public: virtual void unsubscribe() = 0; signals: - void frameAvailable(const VideoFrame frame); + void frameAvailable(const VideoFrame& frame); }; diff --git a/src/widget/form/tabcompleter.cpp b/src/widget/form/tabcompleter.cpp index 86ec7e55a..382fb6c8f 100644 --- a/src/widget/form/tabcompleter.cpp +++ b/src/widget/form/tabcompleter.cpp @@ -28,7 +28,8 @@ const QString TabCompleter::nickSuffix = QString(": "); TabCompleter::TabCompleter(ChatTextEdit* msgEdit, Group* group) - : QObject(msgEdit), msgEdit(msgEdit), group(group), enabled(false) + : QObject{msgEdit}, msgEdit{msgEdit}, group{group}, + enabled{false}, lastCompletionLength{0} { } diff --git a/src/widget/form/tabcompleter.h b/src/widget/form/tabcompleter.h index f48b1a797..23a3fe000 100644 --- a/src/widget/form/tabcompleter.h +++ b/src/widget/form/tabcompleter.h @@ -40,7 +40,7 @@ public slots: private: struct SortableString { - inline SortableString(const QString &n) { contents = n; } + inline SortableString(const QString &n) : contents{n} {} bool operator<(const SortableString &other) const; QString contents; }; diff --git a/src/widget/groupwidget.cpp b/src/widget/groupwidget.cpp index 7d8892cda..60c5d2297 100644 --- a/src/widget/groupwidget.cpp +++ b/src/widget/groupwidget.cpp @@ -99,16 +99,9 @@ void GroupWidget::updateStatusLight() Group *g = GroupList::findGroup(groupId); if (!g->getEventFlag()) - { statusPic.setPixmap(QPixmap(":img/status/dot_online.png")); - } else - { - if (!g->getMentionedFlag()) - statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png")); - else - statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png")); - } + statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png")); } void GroupWidget::setChatForm(Ui::MainWindow &ui) diff --git a/src/widget/tool/chatactions/chataction.h b/src/widget/tool/chatactions/chataction.h index b007ecb60..95062c29d 100644 --- a/src/widget/tool/chatactions/chataction.h +++ b/src/widget/tool/chatactions/chataction.h @@ -29,7 +29,8 @@ class ChatAction : public QObject { Q_OBJECT public: - ChatAction(const bool &me, const QString &author, const QString &date) : isMe(me), name(author), date(date) {;} + ChatAction(const bool &me, const QString &author, const QString &date) + : isMe{me}, name{author}, date{date}, textTable{nullptr}, textEdit{nullptr} {;} virtual ~ChatAction(){;} void assignPlace(QTextTable *position, QTextEdit* te); diff --git a/src/widget/videosurface.cpp b/src/widget/videosurface.cpp index 9a7fd69b7..379b11afd 100644 --- a/src/widget/videosurface.cpp +++ b/src/widget/videosurface.cpp @@ -23,12 +23,14 @@ VideoSurface::VideoSurface(QWidget* parent) : QGLWidget(QGLFormat(QGL::SingleBuffer), parent) - , source(nullptr) + , source{nullptr} , pbo{nullptr, nullptr} - , textureId(0) - , pboAllocSize(0) - , hasSubscribed(false) - , pboIndex(0) + , bgrProgramm{nullptr} + , yuvProgramm{nullptr} + , textureId{0} + , pboAllocSize{0} + , hasSubscribed{false} + , pboIndex{0} { } @@ -180,14 +182,6 @@ void VideoSurface::paintGL() pbo[nextPboIndex]->release(); } - // render pbo - static float values[] = { - -1, -1, - 1, -1, - -1, 1, - 1, 1 - }; - // background glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); @@ -220,6 +214,14 @@ void VideoSurface::paintGL() if (programm) { + // render pbo + static float values[] = { + -1, -1, + 1, -1, + -1, 1, + 1, 1 + }; + programm->bind(); programm->setAttributeArray(0, GL_FLOAT, values, 2); programm->enableAttributeArray(0); @@ -259,7 +261,7 @@ void VideoSurface::unsubscribe() } } -void VideoSurface::onNewFrameAvailable(const VideoFrame newFrame) +void VideoSurface::onNewFrameAvailable(const VideoFrame& newFrame) { mutex.lock(); frame = newFrame; diff --git a/src/widget/videosurface.h b/src/widget/videosurface.h index 18bfd11c4..c0e313e68 100644 --- a/src/widget/videosurface.h +++ b/src/widget/videosurface.h @@ -44,7 +44,7 @@ protected: void unsubscribe(); private slots: - void onNewFrameAvailable(const VideoFrame newFrame); + void onNewFrameAvailable(const VideoFrame &newFrame); private: VideoSource* source;