From 4f3df90a3eb7e732283a4e312c7a3a003d791bd3 Mon Sep 17 00:00:00 2001 From: sauwming Date: Tue, 23 Apr 2024 17:01:38 +0800 Subject: [PATCH] Fixed PJSUA2 API to get/set Opus config (#3935) --- pjsip/include/pjsua2/endpoint.hpp | 2 -- pjsip/src/pjsua2/endpoint.cpp | 39 ++++++++++++++++++------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/pjsip/include/pjsua2/endpoint.hpp b/pjsip/include/pjsua2/endpoint.hpp index 0d2bfdc882..a40c38df57 100644 --- a/pjsip/include/pjsua2/endpoint.hpp +++ b/pjsip/include/pjsua2/endpoint.hpp @@ -1779,7 +1779,6 @@ class Endpoint */ void resetVideoCodecParam(const string &codec_id) PJSUA2_THROW(Error); -#if defined(PJMEDIA_HAS_OPUS_CODEC) && (PJMEDIA_HAS_OPUS_CODEC!=0) /** * Get codec Opus config. * @@ -1794,7 +1793,6 @@ class Endpoint */ void setCodecOpusConfig(const CodecOpusConfig &opus_cfg) PJSUA2_THROW(Error); -#endif /** * Enumerate all SRTP crypto-suite names. diff --git a/pjsip/src/pjsua2/endpoint.cpp b/pjsip/src/pjsua2/endpoint.cpp index f206f27e3f..417a123cfd 100644 --- a/pjsip/src/pjsua2/endpoint.cpp +++ b/pjsip/src/pjsua2/endpoint.cpp @@ -2490,34 +2490,41 @@ void Endpoint::codecSetParam(const string &codec_id, PJSUA2_CHECK_EXPR( pjsua_codec_set_param(&codec_str, &pj_param) ); } -#if defined(PJMEDIA_HAS_OPUS_CODEC) && (PJMEDIA_HAS_OPUS_CODEC!=0) CodecOpusConfig Endpoint::getCodecOpusConfig() const PJSUA2_THROW(Error) { - pjmedia_codec_opus_config opus_cfg; - CodecOpusConfig config; + CodecOpusConfig config; +#if defined(PJMEDIA_HAS_OPUS_CODEC) && (PJMEDIA_HAS_OPUS_CODEC!=0) + pjmedia_codec_opus_config opus_cfg; - PJSUA2_CHECK_EXPR(pjmedia_codec_opus_get_config(&opus_cfg)); - config.fromPj(opus_cfg); + PJSUA2_CHECK_EXPR(pjmedia_codec_opus_get_config(&opus_cfg)); + config.fromPj(opus_cfg); +#else + PJSUA2_RAISE_ERROR(PJ_ENOTSUP); +#endif - return config; + return config; } void Endpoint::setCodecOpusConfig(const CodecOpusConfig &opus_cfg) PJSUA2_THROW(Error) { - const pj_str_t codec_id = {(char *)"opus", 4}; - pjmedia_codec_param param; - pjmedia_codec_opus_config new_opus_cfg; - - PJSUA2_CHECK_EXPR(pjsua_codec_get_param(&codec_id, ¶m)); - new_opus_cfg = opus_cfg.toPj(); - - PJSUA2_CHECK_EXPR(pjmedia_codec_opus_set_default_param(&new_opus_cfg, - ¶m)); -} +#if defined(PJMEDIA_HAS_OPUS_CODEC) && (PJMEDIA_HAS_OPUS_CODEC!=0) + const pj_str_t codec_id = {(char *)"opus", 4}; + pjmedia_codec_param param; + pjmedia_codec_opus_config new_opus_cfg; + + PJSUA2_CHECK_EXPR(pjsua_codec_get_param(&codec_id, ¶m)); + new_opus_cfg = opus_cfg.toPj(); + + PJSUA2_CHECK_EXPR(pjmedia_codec_opus_set_default_param(&new_opus_cfg, + ¶m)); +#else + PJ_UNUSED_ARG(opus_cfg); + PJSUA2_RAISE_ERROR(PJ_ENOTSUP); #endif +} void Endpoint::clearCodecInfoList(CodecInfoVector &codec_list) {