mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-18 15:52:09 +08:00
framereader: fix crash after fallback to cpu decoding (#23055)
old-commit-hash: a449b856cac746647ad994eb511600929d529498
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user