From c21c1cdf0995d15c14060bae890cc1e7821514a0 Mon Sep 17 00:00:00 2001 From: deanlee Date: Mon, 15 Nov 2021 22:27:12 +0800 Subject: [PATCH] cleanup --- selfdrive/ui/replay/framereader.cc | 15 +++++---------- selfdrive/ui/replay/framereader.h | 2 +- selfdrive/ui/replay/replay.cc | 8 ++++---- selfdrive/ui/replay/route.cc | 7 +++---- selfdrive/ui/replay/route.h | 3 +-- selfdrive/ui/replay/tests/test_replay.cc | 2 +- 6 files changed, 15 insertions(+), 22 deletions(-) diff --git a/selfdrive/ui/replay/framereader.cc b/selfdrive/ui/replay/framereader.cc index 5111e590322308..0554c6d5279ec5 100644 --- a/selfdrive/ui/replay/framereader.cc +++ b/selfdrive/ui/replay/framereader.cc @@ -14,9 +14,7 @@ int readFunction(void *opaque, uint8_t *buf, int buf_size) { enum AVPixelFormat get_hw_format(AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts) { enum AVPixelFormat *hw_pix_fmt = reinterpret_cast(ctx->opaque); for (const enum AVPixelFormat *p = pix_fmts; *p != -1; p++) { - if (*p == *hw_pix_fmt) { - return *p; - } + if (*p == *hw_pix_fmt) return *p; } assert(0); return AV_PIX_FMT_NONE; @@ -242,12 +240,9 @@ bool FrameReader::copyBuffers(AVFrame *f, uint8_t *rgb, uint8_t *yuv) { return ret >= 0; } -AVHWDeviceType FrameReader::getSupportedHardwareDevice() { - AVHWDeviceType types[] = {AV_HWDEVICE_TYPE_CUDA, AV_HWDEVICE_TYPE_MEDIACODEC, AV_HWDEVICE_TYPE_VIDEOTOOLBOX}; - for (auto t : types) { - if (test_device_type(t)) { - return t; - } +AVHWDeviceType FrameReader::getHardwareDevice() { + for (auto type : {AV_HWDEVICE_TYPE_CUDA, AV_HWDEVICE_TYPE_MEDIACODEC, AV_HWDEVICE_TYPE_VIDEOTOOLBOX}) { + if (test_device_type(type)) return type; } return AV_HWDEVICE_TYPE_NONE; -} \ No newline at end of file +} diff --git a/selfdrive/ui/replay/framereader.h b/selfdrive/ui/replay/framereader.h index 2f9d3448832df3..6cbb77f6afe80d 100644 --- a/selfdrive/ui/replay/framereader.h +++ b/selfdrive/ui/replay/framereader.h @@ -27,7 +27,7 @@ class FrameReader : protected FileReader { int getYUVSize() const { return width * height * 3 / 2; } size_t getFrameCount() const { return frames_.size(); } bool valid() const { return valid_; } - static AVHWDeviceType getSupportedHardwareDevice(); + static AVHWDeviceType getHardwareDevice(); int width = 0, height = 0; diff --git a/selfdrive/ui/replay/replay.cc b/selfdrive/ui/replay/replay.cc index 78581836dad79b..8c762c481290d7 100644 --- a/selfdrive/ui/replay/replay.cc +++ b/selfdrive/ui/replay/replay.cc @@ -24,11 +24,11 @@ Replay::Replay(QString route, QStringList allow, QStringList block, SubMaster *s } qDebug() << "services " << s; - hw_device_type = FrameReader::getSupportedHardwareDevice(); + hw_device_type = FrameReader::getHardwareDevice(); switch (hw_device_type) { - case AV_HWDEVICE_TYPE_CUDA: qInfo() << "decode with CUDA"; break; - case AV_HWDEVICE_TYPE_MEDIACODEC: qInfo() << "decode with MediaCodec"; break; - case AV_HWDEVICE_TYPE_VIDEOTOOLBOX: qInfo() << "decode with VideoToolBox"; break; + case AV_HWDEVICE_TYPE_CUDA: qInfo() << "decode frames with CUDA"; break; + case AV_HWDEVICE_TYPE_MEDIACODEC: qInfo() << "decode frames with MediaCodec"; break; + case AV_HWDEVICE_TYPE_VIDEOTOOLBOX: qInfo() << "decode frames with VideoToolBox"; break; default: break; } diff --git a/selfdrive/ui/replay/route.cc b/selfdrive/ui/replay/route.cc index 1d6d381f671669..40dcd9dcc393c5 100644 --- a/selfdrive/ui/replay/route.cc +++ b/selfdrive/ui/replay/route.cc @@ -92,7 +92,7 @@ void Route::addFileToSegment(int n, const QString &file) { // class Segment Segment::Segment(int n, const SegmentFile &files, AVHWDeviceType hw_device_type, uint32_t flags) - : seg_num(n), hw_device_type(hw_device_type), flags(flags) { + : seg_num(n), hw_device_type(hw_device_type) { // [RoadCam, DriverCam, WideRoadCam, log]. fallback to qcamera/qlog const QString file_list[] = { (flags & REPLAY_FLAG_QCAMERA) || files.road_cam.isEmpty() ? files.qcamera : files.road_cam, @@ -103,7 +103,7 @@ Segment::Segment(int n, const SegmentFile &files, AVHWDeviceType hw_device_type, for (int i = 0; i < std::size(file_list); i++) { if (!file_list[i].isEmpty()) { loading_++; - synchronizer_.addFuture(QtConcurrent::run([=] { loadFile(i, file_list[i].toStdString()); })); + synchronizer_.addFuture(QtConcurrent::run([=] { loadFile(i, file_list[i].toStdString(), !(flags & REPLAY_FLAG_NO_FILE_CACHE)); })); } } } @@ -115,8 +115,7 @@ Segment::~Segment() { synchronizer_.waitForFinished(); } -void Segment::loadFile(int id, const std::string file) { - const bool local_cache = !(flags & REPLAY_FLAG_NO_FILE_CACHE); +void Segment::loadFile(int id, const std::string file, bool local_cache) { bool success = false; if (id < MAX_CAMERAS) { frames[id] = std::make_unique(local_cache, 20 * 1024 * 1024, 3); diff --git a/selfdrive/ui/replay/route.h b/selfdrive/ui/replay/route.h index 937e3f626714cf..c77b31cc936b4f 100644 --- a/selfdrive/ui/replay/route.h +++ b/selfdrive/ui/replay/route.h @@ -58,11 +58,10 @@ class Segment : public QObject { void loadFinished(bool success); protected: - void loadFile(int id, const std::string file); + void loadFile(int id, const std::string file, bool local_cache); std::atomic abort_ = false; std::atomic loading_ = 0; QFutureSynchronizer synchronizer_; - uint32_t flags; AVHWDeviceType hw_device_type; }; diff --git a/selfdrive/ui/replay/tests/test_replay.cc b/selfdrive/ui/replay/tests/test_replay.cc index 4b776e740314e2..b8de286aa9bb00 100644 --- a/selfdrive/ui/replay/tests/test_replay.cc +++ b/selfdrive/ui/replay/tests/test_replay.cc @@ -63,7 +63,7 @@ TEST_CASE("Segment") { REQUIRE(demo_route.segments().size() == 11); QEventLoop loop; - Segment segment(0, demo_route.at(0), flags); + Segment segment(0, demo_route.at(0), AV_HWDEVICE_TYPE_NONE, flags); QObject::connect(&segment, &Segment::loadFinished, [&]() { REQUIRE(segment.isLoaded() == true); REQUIRE(segment.log != nullptr);