framereader: fix crash after fallback to cpu decoding (#23055)

old-commit-hash: a449b856ca
commatwo_master
Dean Lee 3 years ago committed by GitHub
parent 70e2e78f52
commit 4ac4b61272
  1. 9
      selfdrive/ui/replay/framereader.cc
  2. 1
      selfdrive/ui/replay/framereader.h

@ -27,8 +27,9 @@ enum AVPixelFormat get_hw_format(AVCodecContext *ctx, const enum AVPixelFormat *
if (*p == *hw_pix_fmt) return *p;
}
printf("Please run replay with the --no-cuda flag!\n");
assert(0);
return AV_PIX_FMT_NONE;
// fallback to YUV420p
*hw_pix_fmt = AV_PIX_FMT_NONE;
return AV_PIX_FMT_YUV420P;
}
} // namespace
@ -94,7 +95,7 @@ bool FrameReader::load(const std::string &url, bool no_cuda, std::atomic<bool> *
width = (decoder_ctx->width + 3) & ~3;
height = decoder_ctx->height;
if (!no_cuda) {
if (has_cuda_device && !no_cuda) {
if (!initHardwareDecoder(AV_HWDEVICE_TYPE_CUDA)) {
printf("No CUDA capable device was found. fallback to CPU decoding.\n");
} else {
@ -136,6 +137,8 @@ bool FrameReader::initHardwareDecoder(AVHWDeviceType hw_device_type) {
int ret = av_hwdevice_ctx_create(&hw_device_ctx, hw_device_type, nullptr, nullptr, 0);
if (ret < 0) {
hw_pix_fmt = AV_PIX_FMT_NONE;
has_cuda_device = false;
printf("Failed to create specified HW device %d.\n", ret);
return false;
}

@ -50,4 +50,5 @@ private:
AVPixelFormat hw_pix_fmt = AV_PIX_FMT_NONE;
AVBufferRef *hw_device_ctx = nullptr;
std::vector<uint8_t> nv12toyuv_buffer;
inline static std::atomic<bool> has_cuda_device = true;
};

Loading…
Cancel
Save