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: 2025-12-18 10:07:43 Functions: 8 15 53.3 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2025 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             : #include "logger.h"
      24             : 
      25             : #include <string>
      26             : #include <sstream>
      27             : 
      28             : namespace jami {
      29             : 
      30             : /*
      31             :  * SystemCodecInfo
      32             :  */
      33        3497 : SystemCodecInfo::SystemCodecInfo(unsigned codecId,
      34             :                                  unsigned avcodecId,
      35             :                                  const std::string& longName,
      36             :                                  const std::string& name,
      37             :                                  const std::string& libName,
      38             :                                  MediaType mediaType,
      39             :                                  CodecType codecType,
      40             :                                  unsigned bitrate,
      41             :                                  unsigned payloadType,
      42             :                                  unsigned minQuality,
      43        3497 :                                  unsigned maxQuality)
      44        3497 :     : id(codecId)
      45        3497 :     , avcodecId(avcodecId)
      46        3497 :     , longName(longName)
      47        3497 :     , name(name)
      48        3497 :     , libName(libName)
      49        3497 :     , codecType(codecType)
      50        3497 :     , mediaType(mediaType)
      51        3497 :     , payloadType(payloadType)
      52        3497 :     , bitrate(bitrate)
      53        3497 :     , minQuality(minQuality)
      54        3497 :     , maxQuality(maxQuality)
      55        3497 : {}
      56             : 
      57       13109 : SystemCodecInfo::~SystemCodecInfo() {}
      58             : 
      59             : std::map<std::string, std::string>
      60           0 : SystemCodecInfo::getCodecSpecifications() const
      61             : {
      62           0 :     return {{libjami::Account::ConfProperties::CodecInfo::NAME, longName},
      63           0 :             {libjami::Account::ConfProperties::CodecInfo::TYPE, (mediaType & MEDIA_AUDIO ? "AUDIO" : "VIDEO")},
      64           0 :             {libjami::Account::ConfProperties::CodecInfo::BITRATE, std::to_string(bitrate)}};
      65             : }
      66             : 
      67             : /*
      68             :  * SystemAudioCodecInfo
      69             :  */
      70        2152 : SystemAudioCodecInfo::SystemAudioCodecInfo(unsigned codecId,
      71             :                                            unsigned m_avcodecId,
      72             :                                            const std::string& longName,
      73             :                                            const std::string& m_name,
      74             :                                            const std::string& m_libName,
      75             :                                            CodecType m_type,
      76             :                                            unsigned m_bitrate,
      77             :                                            unsigned m_sampleRate,
      78             :                                            unsigned m_nbChannels,
      79             :                                            unsigned m_payloadType,
      80        2152 :                                            AVSampleFormat sampleFormat)
      81             :     : SystemCodecInfo(codecId, m_avcodecId, longName, m_name, m_libName, MEDIA_AUDIO, m_type, m_bitrate, m_payloadType)
      82        2152 :     , audioformat {m_sampleRate, m_nbChannels, sampleFormat}
      83        2152 : {}
      84             : 
      85        8560 : SystemAudioCodecInfo::~SystemAudioCodecInfo() {}
      86             : 
      87             : std::map<std::string, std::string>
      88          95 : SystemAudioCodecInfo::getCodecSpecifications() const
      89             : {
      90          95 :     return {{libjami::Account::ConfProperties::CodecInfo::NAME, longName},
      91          95 :             {libjami::Account::ConfProperties::CodecInfo::TYPE, (mediaType & MEDIA_AUDIO ? "AUDIO" : "VIDEO")},
      92         190 :             {libjami::Account::ConfProperties::CodecInfo::BITRATE, std::to_string(bitrate)},
      93         190 :             {libjami::Account::ConfProperties::CodecInfo::SAMPLE_RATE, std::to_string(audioformat.sample_rate)},
      94         855 :             {libjami::Account::ConfProperties::CodecInfo::CHANNEL_NUMBER, std::to_string(audioformat.nb_channels)}};
      95             : }
      96             : 
      97             : bool
      98         831 : SystemAudioCodecInfo::isPCMG722() const
      99             : {
     100         831 :     return avcodecId == AV_CODEC_ID_ADPCM_G722;
     101             : }
     102             : 
     103             : void
     104           0 : SystemAudioCodecInfo::setCodecSpecifications(const std::map<std::string, std::string>& details)
     105             : {
     106           0 :     decltype(bitrate) tmp_bitrate = std::stoi(details.at(libjami::Account::ConfProperties::CodecInfo::BITRATE));
     107           0 :     decltype(audioformat) tmp_audioformat = audioformat;
     108           0 :     tmp_audioformat.sample_rate = std::stoi(details.at(libjami::Account::ConfProperties::CodecInfo::SAMPLE_RATE));
     109             : 
     110             :     // copy back if no exception was raised
     111           0 :     bitrate = tmp_bitrate;
     112           0 :     audioformat = tmp_audioformat;
     113           0 : }
     114             : 
     115             : /*
     116             :  * SystemVideoCodecInfo
     117             :  */
     118        1345 : SystemVideoCodecInfo::SystemVideoCodecInfo(unsigned codecId,
     119             :                                            unsigned m_avcodecId,
     120             :                                            const std::string& longName,
     121             :                                            const std::string& m_name,
     122             :                                            const std::string& m_libName,
     123             :                                            CodecType m_type,
     124             :                                            unsigned m_bitrate,
     125             :                                            unsigned m_minQuality,
     126             :                                            unsigned m_maxQuality,
     127             :                                            unsigned m_payloadType,
     128             :                                            unsigned m_frameRate,
     129        1345 :                                            unsigned m_profileId)
     130             :     : SystemCodecInfo(codecId,
     131             :                       m_avcodecId,
     132             :                       longName,
     133             :                       m_name,
     134             :                       m_libName,
     135             :                       MEDIA_VIDEO,
     136             :                       m_type,
     137             :                       m_bitrate,
     138             :                       m_payloadType,
     139             :                       m_minQuality,
     140             :                       m_maxQuality)
     141        1345 :     , frameRate(m_frameRate)
     142        1345 :     , profileId(m_profileId)
     143        1345 : {}
     144             : 
     145        4549 : SystemVideoCodecInfo::~SystemVideoCodecInfo() {}
     146             : 
     147             : std::map<std::string, std::string>
     148           0 : SystemVideoCodecInfo::getCodecSpecifications() const
     149             : {
     150             :     return {
     151           0 :         {libjami::Account::ConfProperties::CodecInfo::NAME, longName},
     152           0 :         {libjami::Account::ConfProperties::CodecInfo::TYPE, (mediaType & MEDIA_AUDIO ? "AUDIO" : "VIDEO")},
     153           0 :         {libjami::Account::ConfProperties::CodecInfo::BITRATE, std::to_string(bitrate)},
     154           0 :         {libjami::Account::ConfProperties::CodecInfo::FRAME_RATE, std::to_string(frameRate)},
     155           0 :         {libjami::Account::ConfProperties::CodecInfo::MIN_BITRATE, std::to_string(minBitrate)},
     156           0 :         {libjami::Account::ConfProperties::CodecInfo::MAX_BITRATE, std::to_string(maxBitrate)},
     157           0 :     };
     158             : }
     159             : 
     160             : void
     161           0 : SystemVideoCodecInfo::setCodecSpecifications(const std::map<std::string, std::string>& details)
     162             : {
     163           0 :     auto copy = *this;
     164             : 
     165           0 :     auto it = details.find(libjami::Account::ConfProperties::CodecInfo::BITRATE);
     166           0 :     if (it != details.end())
     167           0 :         copy.bitrate = std::stoi(it->second);
     168             : 
     169           0 :     it = details.find(libjami::Account::ConfProperties::CodecInfo::FRAME_RATE);
     170           0 :     if (it != details.end())
     171           0 :         copy.frameRate = std::stoi(it->second);
     172             : 
     173           0 :     it = details.find(libjami::Account::ConfProperties::CodecInfo::QUALITY);
     174           0 :     if (it != details.end())
     175           0 :         copy.quality = std::stoi(it->second);
     176             : 
     177           0 :     it = details.find(libjami::Account::ConfProperties::CodecInfo::AUTO_QUALITY_ENABLED);
     178           0 :     if (it != details.end())
     179           0 :         copy.isAutoQualityEnabled = (it->second == TRUE_STR) ? true : false;
     180             : 
     181             :     // copy back if no exception was raised
     182           0 :     *this = std::move(copy);
     183           0 : }
     184             : } // namespace jami

Generated by: LCOV version 1.14