Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Nov 15, 2021
1 parent a1b275e commit c21c1cd
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 22 deletions.
15 changes: 5 additions & 10 deletions selfdrive/ui/replay/framereader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<enum AVPixelFormat *>(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;
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion selfdrive/ui/replay/framereader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions selfdrive/ui/replay/replay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 3 additions & 4 deletions selfdrive/ui/replay/route.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)); }));
}
}
}
Expand All @@ -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<FrameReader>(local_cache, 20 * 1024 * 1024, 3);
Expand Down
3 changes: 1 addition & 2 deletions selfdrive/ui/replay/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> abort_ = false;
std::atomic<int> loading_ = 0;
QFutureSynchronizer<void> synchronizer_;
uint32_t flags;
AVHWDeviceType hw_device_type;
};
2 changes: 1 addition & 1 deletion selfdrive/ui/replay/tests/test_replay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c21c1cd

Please sign in to comment.