LCOV - code coverage report
Current view: top level - foo/src/media - media_codec.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 34 69 49.3 %
Date: 2026-04-01 09:29:43 Functions: 8 15 53.3 %

          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        3484 : 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        3484 :                                  unsigned maxQuality)
      42        3484 :     : id(codecId)
      43        3484 :     , avcodecId(avcodecId)
      44        3484 :     , longName(longName)
      45        3484 :     , name(name)
      46        3484 :     , libName(libName)
      47        3484 :     , codecType(codecType)
      48        3484 :     , mediaType(mediaType)
      49        3484 :     , payloadType(payloadType)
      50        3484 :     , bitrate(bitrate)
      51        3484 :     , minQuality(minQuality)
      52        3484 :     , maxQuality(maxQuality)
      53        3484 : {}
      54             : 
      55       13084 : 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             : }
      64             : 
      65             : /*
      66             :  * SystemAudioCodecInfo
      67             :  */
      68        2144 : 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        2144 :                                            AVSampleFormat sampleFormat)
      79             :     : SystemCodecInfo(codecId, m_avcodecId, longName, m_name, m_libName, MEDIA_AUDIO, m_type, m_bitrate, m_payloadType)
      80        2144 :     , audioformat {m_sampleRate, m_nbChannels, sampleFormat}
      81        2144 : {}
      82             : 
      83        8544 : SystemAudioCodecInfo::~SystemAudioCodecInfo() {}
      84             : 
      85             : std::map<std::string, std::string>
      86          89 : SystemAudioCodecInfo::getCodecSpecifications() const
      87             : {
      88          89 :     return {{libjami::Account::ConfProperties::CodecInfo::NAME, longName},
      89          89 :             {libjami::Account::ConfProperties::CodecInfo::TYPE, (mediaType & MEDIA_AUDIO ? "AUDIO" : "VIDEO")},
      90         178 :             {libjami::Account::ConfProperties::CodecInfo::BITRATE, std::to_string(bitrate)},
      91         178 :             {libjami::Account::ConfProperties::CodecInfo::SAMPLE_RATE, std::to_string(audioformat.sample_rate)},
      92         801 :             {libjami::Account::ConfProperties::CodecInfo::CHANNEL_NUMBER, std::to_string(audioformat.nb_channels)}};
      93             : }
      94             : 
      95             : bool
      96         824 : SystemAudioCodecInfo::isPCMG722() const
      97             : {
      98         824 :     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        1340 : 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        1340 :                                            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        1340 :     , frameRate(m_frameRate)
     140        1340 :     , profileId(m_profileId)
     141        1340 : {}
     142             : 
     143        4540 : 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             : }
     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 1.14