请教下各位大佬,这是个什么问题?我在解码视频帧的时候想用 try catch 做一个舍帧的操作,但是 log 显示在 throw 之后并没有 catch 到相应的异常而是直接 crash 了。
环境: MacOS 下 ndk-r25c 交叉编译
CMAKE_CXX_FLAGS = -std=c++17 -flto -fexceptions -D__STDC_CONSTANT_MACROS
代码:
// 在子线程中执行 while(true) { ... try { auto nframe = getVideoFrame(); frame = std::move(nframe); } catch(const GetDecodedFrameException& e) { logW("获取视频帧未成功"); continue; } catch(...) { logE("获取视频帧发生错误"); break; } ... } std::unique_ptr<AVFrameWrapper> getVideoFrame() { ... if (ps.isDropFastFrame() || (ps.isDropFastFrame() && ps.getMasterSyncType() != SyncType::AV_SYNC_VIDEO)) { if (frame.getPts() != AV_NOPTS_VALUE) { double diff = dpts - ps.getMasterClock(); if (!isnan(diff) && fabs(diff) < AV_NOSYNC_THRESHOLD && diff - ps.getLastFrameFilterDelay() < 0 && getState().getPktSerial() == ps.getVideoClock().getSerial() && getPacketQueue().getNbPackets() > 0) { ps.frameFastDropCountIncrease(); frame.frameUnRef(); logW(fmt::format("舍帧 diff: {}, dpts: {}", diff, dpts)); throw GetDecodedFrameException(); } } } ... } class GetDecodedFrameException : public std::exception { private: std::string info; public: GetDecodedFrameException(): std::exception() { info = "GetDecodedFrameException"; logE(info); }; const char * what () const noexcept { return info.c_str(); } };
![]() | 1 ysc3839 2023-07-19 16:07:57 +08:00 via Android 调试,看怎么 crash 的 |
2 GreyWang 2023-12-21 17:35:44 +08:00 有可能是这个异常太底层,并没有被捕获到; 建议尝试下这个更基础的 try-except 方法,将异常的处理方法放到 except 中处理即可 __try {} __except(1) {} |