LCOV - code coverage report
Current view: top level - src/media - media_codec.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 34 71 47.9 %
Date: 2024-12-21 08:56:24 Functions: 8 15 53.3 %

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

Generated by: LCOV version 1.14