Skip to content

Commit

Permalink
Clang-tidy clean-ups (oss apps & samples)
Browse files Browse the repository at this point in the history
Summary:
clang-tidy makes many suggestions.
- missing initializations
- syntax changes
- using modern C++ constructs
- static methods when possible
- using explict for constructors
- "= default" constructors and destructors

and other minor things.

Differential Revision: D52721884

fbshipit-source-id: 35aca28af41c4dee1a7a5a100cbdde4bc217fac9
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Jan 13, 2024
1 parent 085003c commit 8aa70cc
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 43 deletions.
2 changes: 1 addition & 1 deletion sample_code/SampleImageReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ImagePlayer : public RecordFormatStreamPlayer {
/// Sample basic code to demonstrate how to read a VRS file.
struct SampleImageReader {
/// This function is the entry point for your reader
void imageReader(const string& vrsFilePath) {
static void imageReader(const string& vrsFilePath) {
RecordFileReader reader;
if (reader.openFile(vrsFilePath) == 0) {
vector<unique_ptr<StreamPlayer>> streamPlayers;
Expand Down
4 changes: 2 additions & 2 deletions sample_code/SampleRecordAndPlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class RecordableDemo : public Recordable {
}

// pseudocode helper function
bool iNeedToRecordMoreData() {
static bool iNeedToRecordMoreData() {
static int count = 5000;
return --count > 0; // arbitrary condition for our demo
}
Expand Down Expand Up @@ -250,7 +250,7 @@ class PlaybackSample {
/*
* VRS File playback sample
*/
static void readVRSFile(string filePath) {
static void readVRSFile(const string& filePath) {
RecordFileReader reader;
if (reader.openFile(filePath) == 0) {
vector<unique_ptr<StreamPlayer>> streamPlayers;
Expand Down
2 changes: 1 addition & 1 deletion tools/vrs/VrsCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct CommandConverter : public EnumStringConverter<
static_assert(COUNT_OF(sCommands) == enumCount<Command>(), "Missing GaiaOp name definitions");
};

static const RecordFileInfo::Details kCopyOpsDetails = Details::MainCounters;
const RecordFileInfo::Details kCopyOpsDetails = Details::MainCounters;

struct CommandSpec {
Command cmd;
Expand Down
2 changes: 1 addition & 1 deletion tools/vrs/VrsCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ struct VrsCommand {
/// Perform Copy, Merge operation
int doCopyMerge();

bool isRemoteFileSystem(const std::string& path);
static bool isRemoteFileSystem(const std::string& path);

/// Main operation
Command cmd = Command::None;
Expand Down
8 changes: 4 additions & 4 deletions tools/vrsplayer/AudioPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ class AudioPlayer : public QObject, public RecordFormatStreamPlayer {
AudioJob() = default;
AudioJob(std::vector<uint8_t>&& samples, uint32_t frameCount, uint32_t frameSize)
: samples{std::move(samples)}, frameCount{frameCount}, frameSize{frameSize} {}
AudioJob(AudioJob&& job)
AudioJob(AudioJob&& job) noexcept
: samples{std::move(job.samples)}, frameCount{job.frameCount}, frameSize{job.frameSize} {}

AudioJob& operator=(AudioJob&& job) {
AudioJob& operator=(AudioJob&& job) noexcept {
samples = std::move(job.samples);
frameCount = job.frameCount;
frameSize = job.frameSize;
return *this;
}
std::vector<uint8_t> samples;
uint32_t frameCount;
uint32_t frameSize;
uint32_t frameCount{};
uint32_t frameSize{};
};

public:
Expand Down
6 changes: 3 additions & 3 deletions tools/vrsplayer/FileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ QString kLayoutPresets("layout_presets");

class FlagKeeper {
public:
FlagKeeper(bool& flag) : flag_{flag}, finalValue_{flag_} {
explicit FlagKeeper(bool& flag) : flag_{flag}, finalValue_{flag_} {
flag_ = false;
}
FlagKeeper(bool& flag, bool finalValue) : flag_{flag}, finalValue_{finalValue} {
Expand Down Expand Up @@ -565,7 +565,7 @@ void FileReader::setBlankMode(bool blank) {
}

void FileReader::clearLayout(QLayout* layout, bool deleteWidgets) {
QLayoutItem* child;
QLayoutItem* child{};
while ((child = layout->takeAt(0)) != nullptr) {
if (child->layout() != nullptr) {
clearLayout(child->layout(), deleteWidgets);
Expand Down Expand Up @@ -719,7 +719,7 @@ double FileReader::getNextRecordDelay() {
}

void FileReader::playThreadActivity() {
EventChannel::Event event;
EventChannel::Event event{};
while (runThread_) {
double delay = getNextRecordDelay();
if (delay > 0) {
Expand Down
22 changes: 11 additions & 11 deletions tools/vrsplayer/FileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class FileReader : public QObject {
static constexpr double kMaxPlaybackAge = 0.2;

explicit FileReader(QObject* parent = nullptr);
~FileReader();
~FileReader() override;

void setPlayerUi(PlayerUI* ui) {
playerUi_ = ui;
Expand Down Expand Up @@ -128,7 +128,7 @@ class FileReader : public QObject {
void setPosition(int position);
void sliderPressed();
void sliderReleased();
bool eventFilter(QObject* obj, QEvent* event);
bool eventFilter(QObject* obj, QEvent* event) override;
void stop();
void play();
void pause();
Expand Down Expand Up @@ -181,7 +181,7 @@ class FileReader : public QObject {
void closeFile();

private:
PlayerUI* playerUi_;
PlayerUI* playerUi_{};
std::vector<StreamId> visibleStreams_;
QVBoxLayout* videoFrames_{};
int lastMaxPerRow_{0};
Expand All @@ -190,16 +190,16 @@ class FileReader : public QObject {
std::map<StreamId, size_t> lastReadRecords_;
Record::Type recordType_{Record::Type::UNDEFINED};
QTimer slowTimer_;
FileReaderState state_;
FileReaderState state_{};
std::unique_ptr<RecordFileReader> fileReader_;
bool isLocalFile_;
bool isSliderActive_;
bool isLocalFile_{};
bool isSliderActive_{};
bool layoutUpdatesEnabled_{true};
double startTime_;
double endTime_;
uint32_t firstDataRecordIndex_;
double lastShownTime_;
size_t nextRecord_;
double startTime_{};
double endTime_{};
uint32_t firstDataRecordIndex_{};
double lastShownTime_{};
size_t nextRecord_{};
QString lastSaveLocation_;
VideoTime time_;
bool runThread_{true};
Expand Down
4 changes: 2 additions & 2 deletions tools/vrsplayer/FramePlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ class FramePlayer : public QObject, public VideoRecordFormatStreamPlayer {
bool firstImage_{true};
std::atomic<bool> iframesOnly_{true};
string saveNextFramePath_;
int estimatedFps_;
int estimatedFps_{};
Fps dataFps_;
FileReaderState state_{};

vrs::JobQueueWithThread<std::unique_ptr<ImageJob>> imageJobs_;

void convertFrame(shared_ptr<PixelFrame>& frame);
void makeBlankFrame(shared_ptr<PixelFrame>& frame);
static void makeBlankFrame(shared_ptr<PixelFrame>& frame);
shared_ptr<PixelFrame> getFrame(bool inputNotConvertedFrame);
void recycle(shared_ptr<PixelFrame>& frame, bool inputNotConvertedFrame);
bool saveFrame(const CurrentRecord& record, const ContentBlock& contentBlock);
Expand Down
7 changes: 3 additions & 4 deletions tools/vrsplayer/FrameWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void FrameWidget::paintEvent(QPaintEvent* evt) {
unique_lock<mutex> lock;
PixelFrame* image = image_.get();
if (image != nullptr) {
QImage::Format qformat;
QImage::Format qformat{};
hasImage = convertToQImageFormat(image->getPixelFormat(), qformat);
if (hasImage) {
QSize size = image->qsize();
Expand All @@ -97,7 +97,7 @@ void FrameWidget::paintEvent(QPaintEvent* evt) {
size.height(),
static_cast<int>(image->getStride()),
qformat);
painter.translate(rect.width() / 2, rect.height() / 2);
painter.translate(rect.width() / 2.f, rect.height() / 2.f);
QSize rsize = size;
rsize.scale(rotate(rect.size()), Qt::KeepAspectRatio);
bool sideWays = rotation_ % 180 != 0;
Expand All @@ -122,8 +122,7 @@ void FrameWidget::paintEvent(QPaintEvent* evt) {
painter.setPen(Qt::black);
painter.setBackground(QBrush(Qt::white));
painter.setBackgroundMode(Qt::BGMode::OpaqueMode);
QString description =
QString::fromStdString(vrs::toString(image->getPixelFormat()).c_str()) +
QString description = QString::fromStdString(vrs::toString(image->getPixelFormat())) +
" pixel format not supported...";
painter.drawText(QPointF(rect.left() + 4, rect.bottom() - 4), description);
}
Expand Down
2 changes: 1 addition & 1 deletion tools/vrsplayer/FrameWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Fps {
class FrameWidget : public QWidget {
Q_OBJECT
public:
explicit FrameWidget(QWidget* parent = 0);
explicit FrameWidget(QWidget* parent = nullptr);

void paintEvent(QPaintEvent* evt) override;
QSize sizeHint() const override;
Expand Down
10 changes: 5 additions & 5 deletions tools/vrsplayer/PlayerUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ class JumpSlider : public QSlider {
JumpSlider() : QSlider(Qt::Horizontal) {}

protected:
void mousePressEvent(QMouseEvent* event) {
void mousePressEvent(QMouseEvent* event) override {
QStyleOptionSlider opt;
initStyleOption(&opt);
QRect sr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
if (event->button() == Qt::LeftButton && sr.contains(event->pos()) == false) {
if (event->button() == Qt::LeftButton && !sr.contains(event->pos())) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
int newVal = minimum() + ((maximum() - minimum()) * event->x()) / width();
#else
Expand Down Expand Up @@ -231,7 +231,7 @@ void PlayerUI::openFileChooser() {
void PlayerUI::openPathChooser() {
setStatusText({});
fileReader_.stop();
bool ok;
bool ok{};
QString text = QInputDialog::getText(
nullptr,
"Open VRS File",
Expand Down Expand Up @@ -374,7 +374,7 @@ void PlayerUI::toggleVisibleStreams() {
}

void PlayerUI::savePreset() {
bool ok;
bool ok{};
QString text = QInputDialog::getText(
nullptr,
"Save Preset",
Expand All @@ -399,7 +399,7 @@ void PlayerUI::deletePreset(const QString& preset) {
fileReader_.deletePreset(preset);
}

void PlayerUI::reportError(QString errorTitle, QString errorMessage) {
void PlayerUI::reportError(const QString& errorTitle, const QString& errorMessage) {
emit fileReader_.stop();
QMessageBox messageBox(QMessageBox::Critical, "", errorMessage, QMessageBox::Ok);
messageBox.QDialog::setWindowTitle(errorTitle); // Backdoor for MacOS
Expand Down
6 changes: 3 additions & 3 deletions tools/vrsplayer/PlayerUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ using PathPreparer = std::function<QString(const QString&)>;
class PlayerUI : public QWidget {
Q_OBJECT
public:
PlayerUI(QWidget* parent = nullptr);
explicit PlayerUI(QWidget* parent = nullptr);

void setPathPreparer(const PathPreparer& pathPreparer) {
pathPreparer_ = pathPreparer;
Expand Down Expand Up @@ -78,7 +78,7 @@ class PlayerUI : public QWidget {
void savePreset();
void recallPreset(const QString& preset);
void deletePreset(const QString& preset);
void reportError(QString errorTitle, QString errorMessage);
void reportError(const QString& errorTitle, const QString& errorMessage);
void setOverlayColor(QColor color);
QColor getOverlayColor() const {
return overlayColor_;
Expand All @@ -97,7 +97,7 @@ class PlayerUI : public QWidget {
void recordTypeChanged(int index);
void speedControlChanged(int index);
void setStatusText(const std::string& statusText);
bool eventFilter(QObject* obj, QEvent* event);
bool eventFilter(QObject* obj, QEvent* event) override;

private:
QSettings settings_;
Expand Down
2 changes: 1 addition & 1 deletion tools/vrsplayer/PlayerWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using namespace vrsp;
using namespace std;

inline QKeySequence shortcut(int keyA, int keyB, int keyC = 0) {
return QKeySequence(keyA + keyB + keyC);
return {keyA + keyB + keyC};
}

PlayerWindow::PlayerWindow(QApplication& app) : QMainWindow(nullptr) {
Expand Down
8 changes: 4 additions & 4 deletions tools/vrsplayer/PlayerWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ class PlayerWindow : public QMainWindow {

private:
PlayerUI player_;
QMenu* fileMenu_;
QMenu* layoutMenu_;
QMenu* orientationMenu_;
QMenu* textOverlayMenu_;
QMenu* fileMenu_{};
QMenu* layoutMenu_{};
QMenu* orientationMenu_{};
QMenu* textOverlayMenu_{};
std::vector<std::unique_ptr<QAction>> layoutActions_;
};

Expand Down

0 comments on commit 8aa70cc

Please sign in to comment.