Ring Daemon 16.0.0
Loading...
Searching...
No Matches
media_codec.h
Go to the documentation of this file.
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#pragma once
18
19#ifdef HAVE_CONFIG_H
20#include <config.h>
21#endif
22
23#include "audio/audio_format.h"
24
25#include <dhtnet/ip_utils.h>
26#include <cctype>
27#include <string>
28#include <vector>
29#include <map>
30#include <memory>
31#include <iostream>
32#include <unistd.h>
33
34namespace jami {
35
37
38enum CodecType : unsigned {
39 CODEC_NONE = 0, // indicates that no codec is used or defined
43};
44
45enum MediaType : unsigned {
46 MEDIA_NONE = 0, // indicates that no media is used or defined
50};
51
52enum class RateMode : unsigned { CRF_CONSTRAINED, CQ, CBR };
53
54/*
55 * SystemCodecInfo
56 * represent information of a codec available on the system (using libav)
57 * store default codec values
58 */
60{
61 static constexpr unsigned DEFAULT_CODEC_QUALITY {30};
62#ifdef ENABLE_VIDEO
63 static constexpr unsigned DEFAULT_H264_MIN_QUALITY {40};
64 static constexpr unsigned DEFAULT_H264_MAX_QUALITY {20};
65 static constexpr unsigned DEFAULT_VP8_MIN_QUALITY {50};
66 static constexpr unsigned DEFAULT_VP8_MAX_QUALITY {20};
67#endif
68
69 // indicates that the codec does not use quality factor
70 static constexpr unsigned DEFAULT_NO_QUALITY {0};
71
72 static constexpr unsigned DEFAULT_MIN_BITRATE {200};
73 static constexpr unsigned DEFAULT_MAX_BITRATE {6000};
74 static constexpr unsigned DEFAULT_VIDEO_BITRATE {800}; // in Kbits/second
75
76 SystemCodecInfo(unsigned codecId,
77 unsigned avcodecId,
78 const std::string& longName,
79 const std::string& name,
80 const std::string& libName,
83 unsigned bitrate = 0,
84 unsigned payloadType = 0,
87
88 virtual ~SystemCodecInfo();
89 virtual std::map<std::string, std::string> getCodecSpecifications() const;
90
91 /* generic codec information */
92 unsigned id; /* id of the codec used with dbus */
93 unsigned avcodecId; /* AVCodecID libav codec identifier */
94 std::string longName; /* User-friendly codec name */
95 std::string name; /* RTP codec name as specified by http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml */
96 std::string libName;
99
100 /* default codec values */
101 unsigned payloadType;
102 unsigned bitrate;
107
108 // User-preferences from client
109 unsigned order {0}; /*used to define preferred codec list order in UI*/
110 bool isActive {false};
111 unsigned quality;
112};
113
114/*
115 * SystemAudioCodecInfo
116 * represent information of a audio codec available on the system (using libav)
117 * store default codec values
118 */
120{
122 unsigned avcodecId,
123 const std::string& longName,
124 const std::string& name,
125 const std::string& libName,
126 CodecType type,
127 unsigned bitrate = 0,
128 unsigned sampleRate = 0,
129 unsigned nbChannels = 0,
130 unsigned payloadType = 0,
131 AVSampleFormat sampleFormat = AV_SAMPLE_FMT_S16);
132
134
135 std::map<std::string, std::string> getCodecSpecifications() const override;
136 void setCodecSpecifications(const std::map<std::string, std::string>& details);
137
139 bool isPCMG722() const;
140};
141
142/*
143 * SystemVideoCodecInfo
144 * represent information of a video codec available on the system (using libav)
145 * store default codec values
146 */
148{
150 unsigned avcodecId,
151 const std::string& longName,
152 const std::string& name,
153 const std::string& libName,
154 CodecType type = CODEC_NONE,
155 unsigned bitrate = 0,
156 unsigned m_minQuality = 0,
157 unsigned m_maxQuality = 0,
158 unsigned payloadType = 0,
159 unsigned frameRate = 0,
160 unsigned profileId = 0);
161
163
164 void setCodecSpecifications(const std::map<std::string, std::string>& details);
165 std::map<std::string, std::string> getCodecSpecifications() const override;
166
167 unsigned frameRate;
168 unsigned profileId;
169 std::string parameters;
171};
173
175{
176public:
178 CryptoAttribute(const std::string& tag,
179 const std::string& cryptoSuite,
180 const std::string& srtpKeyMethod,
181 const std::string& srtpKeyInfo,
182 const std::string& lifetime,
183 const std::string& mkiValue,
184 const std::string& mkiLength)
185 : tag_(tag)
186 , cryptoSuite_(cryptoSuite)
187 , srtpKeyMethod_(srtpKeyMethod)
188 , srtpKeyInfo_(srtpKeyInfo)
189 , lifetime_(lifetime)
190 , mkiValue_(mkiValue)
191 , mkiLength_(mkiLength)
192 {}
193
194 std::string getTag() const { return tag_; }
195 std::string getCryptoSuite() const { return cryptoSuite_; }
196 std::string getSrtpKeyMethod() const { return srtpKeyMethod_; }
197 std::string getSrtpKeyInfo() const { return srtpKeyInfo_; }
198 std::string getLifetime() const { return lifetime_; }
199 std::string getMkiValue() const { return mkiValue_; }
200 std::string getMkiLength() const { return mkiLength_; }
201
202 inline explicit operator bool() const { return not tag_.empty(); }
203
204 std::string to_string() const
205 {
206 return tag_ + " " + cryptoSuite_ + " " + srtpKeyMethod_ + ":" + srtpKeyInfo_;
207 }
208
209private:
210 std::string tag_;
211 std::string cryptoSuite_;
212 std::string srtpKeyMethod_;
213 std::string srtpKeyInfo_;
214 std::string lifetime_;
215 std::string mkiValue_;
216 std::string mkiLength_;
217};
218
219// Possible values for media direction attribute. 'UNKNOWN' means that the
220// direction was not set yet. Useful to detect errors when parsing the SDP.
222
223// Possible values for media transport attribute. 'UNKNOWN' means that the
224// was not set, or not found when parsing. Useful to detect errors when
225// parsing the SDP.
227
233{
236 bool enabled {false};
237 bool onHold {false};
239
241 dhtnet::IpAddr addr {};
242
244 dhtnet::IpAddr rtcp_addr {};
245
247 std::shared_ptr<SystemCodecInfo> codec {};
248 unsigned payload_type {};
249 std::string receiving_sdp {};
250 unsigned bitrate {};
251 unsigned rtp_clockrate {8000};
252
254 unsigned frame_size {};
255 bool fecEnabled {false};
256
258 std::string parameters {};
260 bool linkableHW {false};
261
264};
265} // namespace jami
std::string getSrtpKeyInfo() const
std::string getMkiValue() const
std::string getTag() const
std::string getSrtpKeyMethod() const
CryptoAttribute(const std::string &tag, const std::string &cryptoSuite, const std::string &srtpKeyMethod, const std::string &srtpKeyInfo, const std::string &lifetime, const std::string &mkiValue, const std::string &mkiLength)
std::string getLifetime() const
std::string getCryptoSuite() const
std::string getMkiLength() const
std::string to_string() const
void emitSignal(Args... args)
Definition ring_signal.h:64
MediaTransport
MediaDirection
@ CODEC_ENCODER
Definition media_codec.h:40
@ CODEC_ENCODER_DECODER
Definition media_codec.h:42
@ CODEC_DECODER
Definition media_codec.h:41
@ CODEC_NONE
Definition media_codec.h:39
KeyExchangeProtocol
Definition media_codec.h:36
bool operator==(SystemCodecInfo codec1, SystemCodecInfo codec2)
@ MEDIA_AUDIO
Definition media_codec.h:47
@ MEDIA_ALL
Definition media_codec.h:49
@ MEDIA_VIDEO
Definition media_codec.h:48
@ MEDIA_NONE
Definition media_codec.h:46
Structure to hold sample rate and channel number associated with audio data.
static const constexpr AudioFormat NONE()
MediaDescription Negotiated RTP media slot.
dhtnet::IpAddr addr
Endpoint socket address.
dhtnet::IpAddr rtcp_addr
RTCP socket address.
MediaType type
Audio / video.
std::string parameters
Video parameters.
std::shared_ptr< SystemCodecInfo > codec
RTP.
MediaDirection direction_
CryptoAttribute crypto
Crypto parameters.
std::string receiving_sdp
unsigned frame_size
Audio parameters.
void setCodecSpecifications(const std::map< std::string, std::string > &details)
std::map< std::string, std::string > getCodecSpecifications() const override
static constexpr unsigned DEFAULT_CODEC_QUALITY
Definition media_codec.h:61
static constexpr unsigned DEFAULT_MAX_BITRATE
Definition media_codec.h:73
static constexpr unsigned DEFAULT_MIN_BITRATE
Definition media_codec.h:72
virtual std::map< std::string, std::string > getCodecSpecifications() const
static constexpr unsigned DEFAULT_NO_QUALITY
Definition media_codec.h:70
static constexpr unsigned DEFAULT_VIDEO_BITRATE
Definition media_codec.h:74
std::map< std::string, std::string > getCodecSpecifications() const override
void setCodecSpecifications(const std::map< std::string, std::string > &details)