From 47a05c75929043a038ed63a435ee402d5f2be151 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Fri, 18 Mar 2022 00:38:32 -0700 Subject: [PATCH] feat(core): Add error parsing for Toxav_Err_Call --- src/core/coreav.cpp | 7 ++++-- util/include/util/toxcoreerrorparser.h | 1 + util/src/toxcoreerrorparser.cpp | 34 ++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/core/coreav.cpp b/src/core/coreav.cpp index a6536406e..2280e08bc 100644 --- a/src/core/coreav.cpp +++ b/src/core/coreav.cpp @@ -292,9 +292,12 @@ bool CoreAV::startCall(uint32_t friendNum, bool video) } uint32_t videoBitrate = video ? VIDEO_DEFAULT_BITRATE : 0; - if (!toxav_call(toxav.get(), friendNum, audioSettings.getAudioBitrate(), videoBitrate, - nullptr)) + Toxav_Err_Call err; + toxav_call(toxav.get(), friendNum, audioSettings.getAudioBitrate(), videoBitrate, + &err); + if (!PARSE_ERR(err)) { return false; + } // Audio backend must be set before making a call assert(audio != nullptr); diff --git a/util/include/util/toxcoreerrorparser.h b/util/include/util/toxcoreerrorparser.h index 418e99cb2..3576a786f 100644 --- a/util/include/util/toxcoreerrorparser.h +++ b/util/include/util/toxcoreerrorparser.h @@ -56,4 +56,5 @@ namespace ToxcoreErrorParser { bool parseErr(Tox_Err_File_Send error, int line); bool parseErr(Tox_Err_File_Send_Chunk error, int line); bool parseErr(Toxav_Err_Call_Control error, int line); + bool parseErr(Toxav_Err_Call error, int line); } // namespace ToxcoreErrorParser diff --git a/util/src/toxcoreerrorparser.cpp b/util/src/toxcoreerrorparser.cpp index c53f69cd6..f43ccf65f 100644 --- a/util/src/toxcoreerrorparser.cpp +++ b/util/src/toxcoreerrorparser.cpp @@ -569,3 +569,37 @@ bool ToxcoreErrorParser::parseErr(Toxav_Err_Call_Control error, int line) qCritical() << line << "Unknown Toxav_Err_Call_Control error code:" << error; return false; } + +bool ToxcoreErrorParser::parseErr(Toxav_Err_Call error, int line) +{ + switch (error) { + case TOXAV_ERR_CALL_OK: + return true; + + case TOXAV_ERR_CALL_MALLOC: + qCritical() << line << ": A resource allocation error occurred."; + return false; + + case TOXAV_ERR_CALL_SYNC: + qCritical() << line << ": Synchronization error occurred."; + return false; + + case TOXAV_ERR_CALL_FRIEND_NOT_FOUND: + qCritical() << line << ": The friend number did not designate a valid friend."; + return false; + + case TOXAV_ERR_CALL_FRIEND_NOT_CONNECTED: + qCritical() << line << ": The friend was valid, but not currently connected."; + return false; + + case TOXAV_ERR_CALL_FRIEND_ALREADY_IN_CALL: + qCritical() << line << ": Attempted to call a friend while already in a call with them."; + return false; + + case TOXAV_ERR_CALL_INVALID_BIT_RATE: + qCritical() << line << ": Audio or video bit rate is invalid."; + return false; + } + qCritical() << line << "Unknown Toxav_Err_Call error code:" << error; + return false; +}