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