LCOV - code coverage report
Current view: top level - src/media - media_codec.cpp (source / functions) Coverage Total Hit
Test: jami-coverage-filtered.info Lines: 47.2 % 72 34
Test Date: 2026-06-13 09:18:46 Functions: 53.3 % 15 8

            Line data    Source code
       1              : /*
       2              :  *  Copyright (C) 2004-2026 Savoir-faire Linux Inc.
       3              :  *
       4              :  *  This program is free software: you can redistribute it and/or modify
       5              :  *  it under the terms of the GNU General Public License as published by
       6              :  *  the Free Software Foundation, either version 3 of the License, or
       7              :  *  (at your option) any later version.
       8              :  *
       9              :  *  This program is distributed in the hope that it will be useful,
      10              :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      11              :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      12              :  *  GNU General Public License for more details.
      13              :  *
      14              :  *  You should have received a copy of the GNU General Public License
      15              :  *  along with this program. If not, see <https://www.gnu.org/licenses/>.
      16              :  */
      17              : 
      18              : #include "libav_deps.h" // MUST BE INCLUDED FIRST
      19              : #include "media_codec.h"
      20              : #include "account_const.h"
      21              : 
      22              : #include "string_utils.h"
      23              : 
      24              : #include <string>
      25              : 
      26              : namespace jami {
      27              : 
      28              : /*
      29              :  * SystemCodecInfo
      30              :  */
      31          468 : SystemCodecInfo::SystemCodecInfo(unsigned codecId,
      32              :                                  unsigned avcodecId,
      33              :                                  const std::string& longName,
      34              :                                  const std::string& name,
      35              :                                  const std::string& libName,
      36              :                                  MediaType mediaType,
      37              :                                  CodecType codecType,
      38              :                                  unsigned bitrate,
      39              :                                  unsigned payloadType,
      40              :                                  unsigned minQuality,
      41          468 :                                  unsigned maxQuality)
      42          468 :     : id(codecId)
      43          468 :     , avcodecId(avcodecId)
      44          468 :     , longName(longName)
      45          468 :     , name(name)
      46          468 :     , libName(libName)
      47          468 :     , codecType(codecType)
      48          468 :     , mediaType(mediaType)
      49          468 :     , payloadType(payloadType)
      50          468 :     , bitrate(bitrate)
      51          468 :     , minQuality(minQuality)
      52          468 :     , maxQuality(maxQuality)
      53          468 : {}
      54              : 
      55        10235 : SystemCodecInfo::~SystemCodecInfo() {}
      56              : 
      57              : std::map<std::string, std::string>
      58            0 : SystemCodecInfo::getCodecSpecifications() const
      59              : {
      60            0 :     return {{libjami::Account::ConfProperties::CodecInfo::NAME, longName},
      61            0 :             {libjami::Account::ConfProperties::CodecInfo::TYPE, (mediaType & MEDIA_AUDIO ? "AUDIO" : "VIDEO")},
      62            0 :             {libjami::Account::ConfProperties::CodecInfo::BITRATE, std::to_string(bitrate)}};
      63            0 : }
      64              : 
      65              : /*
      66              :  * SystemAudioCodecInfo
      67              :  */
      68          288 : SystemAudioCodecInfo::SystemAudioCodecInfo(unsigned codecId,
      69              :                                            unsigned m_avcodecId,
      70              :                                            const std::string& longName,
      71              :                                            const std::string& m_name,
      72              :                                            const std::string& m_libName,
      73              :                                            CodecType m_type,
      74              :                                            unsigned m_bitrate,
      75              :                                            unsigned m_sampleRate,
      76              :                                            unsigned m_nbChannels,
      77              :                                            unsigned m_payloadType,
      78          288 :                                            AVSampleFormat sampleFormat)
      79              :     : SystemCodecInfo(codecId, m_avcodecId, longName, m_name, m_libName, MEDIA_AUDIO, m_type, m_bitrate, m_payloadType)
      80          288 :     , audioformat {m_sampleRate, m_nbChannels, sampleFormat}
      81          288 : {}
      82              : 
      83         6704 : SystemAudioCodecInfo::~SystemAudioCodecInfo() {}
      84              : 
      85              : std::map<std::string, std::string>
      86           92 : SystemAudioCodecInfo::getCodecSpecifications() const
      87              : {
      88           92 :     return {{libjami::Account::ConfProperties::CodecInfo::NAME, longName},
      89           92 :             {libjami::Account::ConfProperties::CodecInfo::TYPE, (mediaType & MEDIA_AUDIO ? "AUDIO" : "VIDEO")},
      90            0 :             {libjami::Account::ConfProperties::CodecInfo::BITRATE, std::to_string(bitrate)},
      91           92 :             {libjami::Account::ConfProperties::CodecInfo::SAMPLE_RATE, std::to_string(audioformat.sample_rate)},
      92          736 :             {libjami::Account::ConfProperties::CodecInfo::CHANNEL_NUMBER, std::to_string(audioformat.nb_channels)}};
      93           92 : }
      94              : 
      95              : bool
      96          822 : SystemAudioCodecInfo::isPCMG722() const
      97              : {
      98          822 :     return avcodecId == AV_CODEC_ID_ADPCM_G722;
      99              : }
     100              : 
     101              : void
     102            0 : SystemAudioCodecInfo::setCodecSpecifications(const std::map<std::string, std::string>& details)
     103              : {
     104            0 :     decltype(bitrate) tmp_bitrate = std::stoi(details.at(libjami::Account::ConfProperties::CodecInfo::BITRATE));
     105            0 :     decltype(audioformat) tmp_audioformat = audioformat;
     106            0 :     tmp_audioformat.sample_rate = std::stoi(details.at(libjami::Account::ConfProperties::CodecInfo::SAMPLE_RATE));
     107              : 
     108              :     // copy back if no exception was raised
     109            0 :     bitrate = tmp_bitrate;
     110            0 :     audioformat = tmp_audioformat;
     111            0 : }
     112              : 
     113              : /*
     114              :  * SystemVideoCodecInfo
     115              :  */
     116          180 : SystemVideoCodecInfo::SystemVideoCodecInfo(unsigned codecId,
     117              :                                            unsigned m_avcodecId,
     118              :                                            const std::string& longName,
     119              :                                            const std::string& m_name,
     120              :                                            const std::string& m_libName,
     121              :                                            CodecType m_type,
     122              :                                            unsigned m_bitrate,
     123              :                                            unsigned m_minQuality,
     124              :                                            unsigned m_maxQuality,
     125              :                                            unsigned m_payloadType,
     126              :                                            unsigned m_frameRate,
     127          180 :                                            unsigned m_profileId)
     128              :     : SystemCodecInfo(codecId,
     129              :                       m_avcodecId,
     130              :                       longName,
     131              :                       m_name,
     132              :                       m_libName,
     133              :                       MEDIA_VIDEO,
     134              :                       m_type,
     135              :                       m_bitrate,
     136              :                       m_payloadType,
     137              :                       m_minQuality,
     138              :                       m_maxQuality)
     139          180 :     , frameRate(m_frameRate)
     140          180 :     , profileId(m_profileId)
     141          180 : {}
     142              : 
     143         3388 : SystemVideoCodecInfo::~SystemVideoCodecInfo() {}
     144              : 
     145              : std::map<std::string, std::string>
     146            0 : SystemVideoCodecInfo::getCodecSpecifications() const
     147              : {
     148              :     return {
     149            0 :         {libjami::Account::ConfProperties::CodecInfo::NAME, longName},
     150            0 :         {libjami::Account::ConfProperties::CodecInfo::TYPE, (mediaType & MEDIA_AUDIO ? "AUDIO" : "VIDEO")},
     151            0 :         {libjami::Account::ConfProperties::CodecInfo::BITRATE, std::to_string(bitrate)},
     152            0 :         {libjami::Account::ConfProperties::CodecInfo::FRAME_RATE, std::to_string(frameRate)},
     153            0 :         {libjami::Account::ConfProperties::CodecInfo::MIN_BITRATE, std::to_string(minBitrate)},
     154            0 :         {libjami::Account::ConfProperties::CodecInfo::MAX_BITRATE, std::to_string(maxBitrate)},
     155            0 :     };
     156            0 : }
     157              : 
     158              : void
     159            0 : SystemVideoCodecInfo::setCodecSpecifications(const std::map<std::string, std::string>& details)
     160              : {
     161            0 :     auto copy = *this;
     162              : 
     163            0 :     auto it = details.find(libjami::Account::ConfProperties::CodecInfo::BITRATE);
     164            0 :     if (it != details.end())
     165            0 :         copy.bitrate = std::stoi(it->second);
     166              : 
     167            0 :     it = details.find(libjami::Account::ConfProperties::CodecInfo::FRAME_RATE);
     168            0 :     if (it != details.end())
     169            0 :         copy.frameRate = std::stoi(it->second);
     170              : 
     171            0 :     it = details.find(libjami::Account::ConfProperties::CodecInfo::QUALITY);
     172            0 :     if (it != details.end())
     173            0 :         copy.quality = std::stoi(it->second);
     174              : 
     175            0 :     it = details.find(libjami::Account::ConfProperties::CodecInfo::AUTO_QUALITY_ENABLED);
     176            0 :     if (it != details.end())
     177            0 :         copy.isAutoQualityEnabled = (it->second == TRUE_STR) ? true : false;
     178              : 
     179              :     // copy back if no exception was raised
     180            0 :     *this = std::move(copy);
     181            0 : }
     182              : } // namespace jami
        

Generated by: LCOV version 2.0-1