id
int64 0
755k
| file_name
stringlengths 3
109
| file_path
stringlengths 13
185
| content
stringlengths 31
9.38M
| size
int64 31
9.38M
| language
stringclasses 1
value | extension
stringclasses 11
values | total_lines
int64 1
340k
| avg_line_length
float64 2.18
149k
| max_line_length
int64 7
2.22M
| alphanum_fraction
float64 0
1
| repo_name
stringlengths 6
65
| repo_stars
int64 100
47.3k
| repo_forks
int64 0
12k
| repo_open_issues
int64 0
3.4k
| repo_license
stringclasses 9
values | repo_extraction_date
stringclasses 92
values | exact_duplicates_redpajama
bool 2
classes | near_duplicates_redpajama
bool 2
classes | exact_duplicates_githubcode
bool 2
classes | exact_duplicates_stackv2
bool 1
class | exact_duplicates_stackv1
bool 2
classes | near_duplicates_githubcode
bool 2
classes | near_duplicates_stackv1
bool 2
classes | near_duplicates_stackv2
bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
751,866
|
common.h
|
savoirfairelinux_jami-daemon/test/unitTest/common.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <chrono>
#include <cstdint>
#include <map>
#include <string>
#include <filesystem>
constexpr size_t WAIT_FOR_ANNOUNCEMENT_TIMEOUT = 30;
constexpr size_t WAIT_FOR_REMOVAL_TIMEOUT = 30;
extern void
wait_for_announcement_of(const std::vector<std::string> accountIDs,
std::chrono::seconds timeout = std::chrono::seconds(WAIT_FOR_ANNOUNCEMENT_TIMEOUT));
extern void
wait_for_announcement_of(const std::string& accountId,
std::chrono::seconds timeout = std::chrono::seconds(WAIT_FOR_ANNOUNCEMENT_TIMEOUT));
extern void
wait_for_removal_of(const std::vector<std::string> accounts,
std::chrono::seconds timeout = std::chrono::seconds(WAIT_FOR_REMOVAL_TIMEOUT));
extern void
wait_for_removal_of(const std::string& account,
std::chrono::seconds timeout = std::chrono::seconds(WAIT_FOR_REMOVAL_TIMEOUT));
extern std::map<std::string, std::string>
load_actors(const std::filesystem::path& from_yaml);
extern std::map<std::string, std::string>
load_actors_and_wait_for_announcement(const std::string& from_yaml);
| 1,837
|
C++
|
.h
| 40
| 42.1
| 109
| 0.730017
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,867
|
conversationcommon.h
|
savoirfairelinux_jami-daemon/test/unitTest/conversation/conversationcommon.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "jamidht/jamiaccount.h"
#include <string>
namespace jami {
void addVote(std::shared_ptr<JamiAccount> account,
const std::string& convId,
const std::string& votedUri,
const std::string& content);
void simulateRemoval(std::shared_ptr<JamiAccount> account,
const std::string& convId,
const std::string& votedUri);
void addFile(std::shared_ptr<JamiAccount> account,
const std::string& convId,
const std::string& relativePath,
const std::string& content = "");
void addAll(std::shared_ptr<JamiAccount> account, const std::string& convId);
void commit(std::shared_ptr<JamiAccount> account, const std::string& convId, Json::Value& message);
std::string commitInRepo(const std::string& repoPath,
std::shared_ptr<JamiAccount> account,
const std::string& message);
} // namespace jami
| 1,691
|
C++
|
.h
| 37
| 39.513514
| 99
| 0.68731
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,868
|
nodes.h
|
savoirfairelinux_jami-daemon/test/unitTest/swarm/nodes.h
|
#pragma once
#include "opendht/infohash.h"
#include <dhtnet/multiplexed_socket.h>
#include "manager.h"
using NodeId = dht::PkId;
std::vector<NodeId> nodeTestIds1({
NodeId("053927d831827a9f7e606d4c9c9fe833922c0d35b3960dd2250085f46c0e4f41"),
NodeId("41a05179e4b3e42c3409b10280bb448d5bbd5ef64784b997d2d1663457bb6ba8"),
NodeId("105ba3496ecaa41ad360b45afcefab63ce1c458527ac128d41c791d40e8c62b8"),
NodeId("1b8cc1705ede1abfdf3de98cf94b62d1482ef87ff8206aff483379ad2ff8a3a5"),
NodeId("1bd92a8aab91e63267fd91c6ff4d88896bca4b69e422b11894881cd849fa1467"),
NodeId("28f4c7e34eb4310b2e1ea3b139ee6993e6b021770ee98895a54cdd1e372bd78e"),
NodeId("2dd1dd976c7dc234ca737c85e4ea48ad09423067a77405254424c4cdd845720d"),
NodeId("30e177a56bd1a7969e1973ad8b210a556f6a2b15debc972661a8f555d52edbe2"),
NodeId("312226d8fa653704758a681c8c21ec81cec914d0b8aa19e1142d3cf900e3f3b4"),
NodeId("33f280d8208f42ac34321e6e6871aecd100c2bfd4f1848482e7a7ed8ae895414")
});
std::vector<NodeId> nodeTestIds2({
NodeId("053927d831827a9f7e606d4c9c9fe833922c0d35b3960dd2250085f46c0e4f41"), // 0
NodeId("41a05179e4b3e42c3409b10280bb448d5bbd5ef64784b997d2d1663457bb6ba8"), // 1
NodeId("77a9fba2c5a65812d9290c567897131b20a723e0ca2f65ef5c6b421585e4da2b"), // 2
NodeId("6110cda4bc6f5465acab2e779fad607bf4edcf6114c7333968a2d197aa7a0a63"), // 3
NodeId("6aed0ef602f5c676e7afd337e3984a211c385f38230fa894cfa91e1cbd592b5c"), // 4
NodeId("e633ca67cc8801ec141b2f7eb55b78886e9266ed60c7e4bc12c232ab60d7317e"), // 5
NodeId("84b59e42e8156d18794d263baae06344871b9f97d5006e1f99e8545337c37c37"), // 6
NodeId("a3b1b35be59ed62926569479d72718ccca553710f2a22490d1155d834d972525"), // 7
NodeId("4f76e769061f343b2caf9eea35632d28cde8d7a67e5e0f59857733cabc538997"), // 8
NodeId("fda3516c620bf55511ed0184fc3e32fc346ea0f3a2c6bc19257bd98e19734307") // 9
});
std::vector<NodeId> nodeTestIds3({
NodeId("41a05179e4b3e42c3409b10280bb448d5bbd5ef64784b997d2d1663457bb6ba8"),
NodeId("053927d831827a9f7e606d4c9c9fe833922c0d35b3960dd2250085f46c0e4f41"),
NodeId("271c3365b92f249597be69e4fde318cb13abd1059fb3ad88da52d7690083ffb0"),
NodeId("6aed0ef602f5f676e7afd337e3984a211c385f38230fa894cfa91e1cbd592b5c"),
NodeId("821bc564703ba2fc147f12f1ec30a2bd39bd8ad9fe241da3b47d391cfcc87519"),
NodeId("84b59e42e815dd18794d263baae06344871b9f97d5006e1f99e8545337c37c37"),
NodeId("897b3ff45a8e1c1fa7168b2fac0f32b6cfa3bf430685b36b6f2d646a9125164e"),
NodeId("a3b1b35be59ed62926569479d72718ccca553710f2a22490d1155d834d972525"),
NodeId("f04d8116705f692677cb7cb519c078341fe8aaae3f792904a7be3a8ae0bfa1ea"),
NodeId("f3a0b932602befe4c00b8bf7d2101f60a712bb55b0f62a023766250044b883a8")
});
std::vector<std::shared_ptr<dhtnet::ChannelSocketTest>> nodeTestChannels1(
{std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds1.at(0), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds1.at(1), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds1.at(2), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds1.at(3), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds1.at(4), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds1.at(5), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds1.at(6), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds1.at(7), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds1.at(8), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds1.at(9), "test1", 0)
});
std::vector<std::shared_ptr<dhtnet::ChannelSocketTest>> nodeTestChannels2(
{std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds2.at(0), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds2.at(1), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds2.at(2), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds2.at(3), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds2.at(4), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds2.at(5), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds2.at(6), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds2.at(7), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds2.at(8), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds2.at(9), "test1", 0)
});
std::vector<std::shared_ptr<dhtnet::ChannelSocketTest>> nodeTestChannels3(
{std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds3.at(0), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds3.at(1), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds3.at(2), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds3.at(3), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds3.at(4), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds3.at(5), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds3.at(6), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds3.at(7), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds3.at(8), "test1", 0),
std::make_shared<dhtnet::ChannelSocketTest>(jami::Manager::instance().ioContext(), nodeTestIds3.at(9), "test1", 0)
});
| 6,587
|
C++
|
.h
| 77
| 80.701299
| 120
| 0.773294
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,869
|
utils.h
|
savoirfairelinux_jami-daemon/test/agent/src/utils.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cstdint>
#include <filesystem>
#include "logger.h"
static inline SCM
to_guile(bool b)
{
return scm_from_bool(b);
}
static inline SCM
to_guile(const std::string& str)
{
return scm_from_utf8_string(str.c_str());
}
static inline SCM
to_guile(uint8_t x)
{
return scm_from_uint8(x);
}
static inline SCM
to_guile(uint16_t x)
{
return scm_from_uint16(x);
}
static inline SCM
to_guile(uint32_t x)
{
return scm_from_uint32(x);
}
static inline SCM
to_guile(uint64_t x)
{
return scm_from_uint64(x);
}
static inline SCM
to_guile(int8_t x)
{
return scm_from_int8(x);
}
static inline SCM
to_guile(int16_t x)
{
return scm_from_int16(x);
}
static inline SCM
to_guile(int32_t x)
{
return scm_from_int32(x);
}
static inline SCM
to_guile(int64_t x)
{
return scm_from_int64(x);
}
static inline SCM
to_guile(double x)
{
return scm_from_double(x);
}
/* Forward declarations since we call to_guile() recursively for containers */
template<typename T> static inline SCM to_guile(const std::vector<T>& values);
template<typename K, typename V> static inline SCM to_guile(const std::map<K, V>& map);
template<typename T>
static inline SCM
to_guile(const std::vector<T>& values)
{
SCM vec = scm_c_make_vector(values.size(), SCM_UNDEFINED);
for (size_t i = 0; i < values.size(); ++i) {
SCM_SIMPLE_VECTOR_SET(vec, i, to_guile(values[i]));
}
return vec;
}
template<typename K, typename V>
static inline SCM
to_guile(const std::map<K, V>& map)
{
SCM assoc = SCM_EOL;
for (auto const& [key, value] : map) {
SCM pair = scm_cons(to_guile(key), to_guile(value));
assoc = scm_cons(pair, assoc);
}
return assoc;
}
template<typename... Args>
static inline SCM
pack_to_guile(Args... args)
{
SCM lst = SCM_EOL;
std::vector<SCM> values = {to_guile(args)...};
while (values.size()) {
lst = scm_cons(values.back(), lst);
values.pop_back();
}
return lst;
}
template<typename... Args>
static inline SCM
apply_to_guile(SCM body_proc, Args... args)
{
if (scm_is_false(scm_procedure_p(body_proc))) {
scm_wrong_type_arg_msg("apply_to_guile", 0, body_proc, "procedure");
}
SCM arglst = pack_to_guile(args...);
return scm_apply_0(body_proc, arglst);
}
struct from_guile
{
SCM value;
from_guile(SCM val)
: value(val)
{ }
operator bool()
{
return scm_to_bool(value);
}
operator uint8_t()
{
return scm_to_uint8(value);
}
operator uint16_t()
{
return scm_to_uint16(value);
}
operator uint32_t()
{
return scm_to_uint32(value);
}
operator uint64_t()
{
return scm_to_uint64(value);
}
operator int8_t()
{
return scm_to_int8(value);
}
operator int16_t()
{
return scm_to_int16(value);
}
operator int32_t()
{
return scm_to_int32(value);
}
operator int64_t()
{
return scm_to_int64(value);
}
operator std::string()
{
char* str_raw = scm_to_locale_string(value);
std::string ret(str_raw);
free(str_raw);
return ret;
}
operator std::filesystem::path()
{
char* str_raw = scm_to_locale_string(value);
std::string ret(str_raw);
free(str_raw);
return std::filesystem::path(ret);
}
template<typename T>
operator std::vector<T>()
{
std::vector<T> ret;
ret.reserve(SCM_SIMPLE_VECTOR_LENGTH(value));
for (size_t i = 0; i < SCM_SIMPLE_VECTOR_LENGTH(value); ++i) {
SCM val = SCM_SIMPLE_VECTOR_REF(value, i);
ret.emplace_back(from_guile(val));
}
return ret;
}
template<typename K, typename V>
operator std::map<K, V>()
{
std::map<K, V> ret;
while (not scm_is_null(value)) {
SCM pair = scm_car(value);
K key = from_guile(scm_car(pair));
V val = from_guile(scm_cdr(pair));
ret[key] = val;
value = scm_cdr(value);
}
return ret;
}
};
| 4,882
|
C++
|
.h
| 202
| 19.683168
| 87
| 0.632591
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,870
|
bindings.h
|
savoirfairelinux_jami-daemon/test/agent/src/bindings/bindings.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
/* Guile */
#include <libguile.h>
/* Agent */
#include "utils.h"
#define DEFINE_AND_EXPORT(NAME, VALUE, TYPE) \
do { \
scm_c_define(NAME, TYPE(VALUE)); \
scm_c_export(NAME, NULL); \
} while (0)
#define DEFINE_INT(NAME) DEFINE_AND_EXPORT(#NAME, NAME, scm_from_int)
#define DEFINE_UINT(NAME) DEFINE_AND_EXPORT(#NAME, NAME, scm_from_uint)
#define DEFINE_UINT32(NAME) DEFINE_AND_EXPORT(#NAME, NAME, scm_from_uint32)
#define LOG_BINDING() JAMI_INFO("[GUILE] In binding %s()", __func__)
extern void define_primitive(const char* name, int req, int opt, int rst, void* func);
extern void install_scheme_primitives();
| 1,445
|
C++
|
.h
| 32
| 42
| 86
| 0.682303
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,871
|
account.h
|
savoirfairelinux_jami-daemon/test/agent/src/bindings/account.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
/* Jami */
#include "jami/callmanager_interface.h"
#include "jami/configurationmanager_interface.h"
#include "jami/presencemanager_interface.h"
/* Agent */
#include "utils.h"
static SCM set_details_binding(SCM accountID_str, SCM details_alist)
{
LOG_BINDING();
libjami::setAccountDetails(from_guile(accountID_str),
from_guile(details_alist));
return SCM_UNDEFINED;
}
static SCM get_details_binding(SCM accountID_str)
{
LOG_BINDING();
return to_guile(libjami::getAccountDetails(from_guile(accountID_str)));
}
static SCM send_register_binding(SCM accountID_str, SCM enable_boolean)
{
LOG_BINDING();
libjami::sendRegister(from_guile(accountID_str),
from_guile(enable_boolean));
return SCM_UNDEFINED;
}
static SCM export_to_file_binding(SCM accountID_str, SCM path_str, SCM passwd_str_optional)
{
LOG_BINDING();
if (SCM_UNBNDP(passwd_str_optional)) {
return to_guile(libjami::exportToFile(from_guile(accountID_str),
from_guile(path_str)));
}
return to_guile(libjami::exportToFile(from_guile(accountID_str),
from_guile(path_str),
from_guile(passwd_str_optional)));
}
static SCM
add_account_binding(SCM details_alist, SCM accountID_str_optional)
{
LOG_BINDING();
if (SCM_UNBNDP(accountID_str_optional)) {
return to_guile(libjami::addAccount(from_guile(details_alist)));
}
return to_guile(libjami::addAccount(from_guile(details_alist),
from_guile(accountID_str_optional)));
}
static SCM
accept_trust_request_binding(SCM accountID_str, SCM from_uri_str)
{
LOG_BINDING();
return to_guile(libjami::acceptTrustRequest(from_guile(accountID_str),
from_guile(from_uri_str)));
}
static SCM
send_trust_request_binding(SCM accountID_str, SCM to_uri_str, SCM payload_vector_uint8_optional)
{
LOG_BINDING();
if (SCM_UNBNDP(payload_vector_uint8_optional)) {
payload_vector_uint8_optional = scm_c_make_vector(0, SCM_UNDEFINED);
}
libjami::sendTrustRequest(from_guile(accountID_str),
from_guile(to_uri_str),
from_guile(payload_vector_uint8_optional));
return SCM_UNDEFINED;
}
static SCM
get_contacts_binding(SCM accountID_str)
{
LOG_BINDING();
return to_guile(libjami::getContacts(from_guile(accountID_str)));
}
static SCM
subscribe_buddy_binding(SCM accountID_str, SCM peer_uri_str, SCM flag_bool)
{
LOG_BINDING();
libjami::subscribeBuddy(from_guile(accountID_str),
from_guile(peer_uri_str),
from_guile(flag_bool));
return SCM_UNDEFINED;
}
static SCM
add_contact_binding(SCM accountID_str, SCM uri_str)
{
LOG_BINDING();
libjami::addContact(from_guile(accountID_str),
from_guile(uri_str));
return SCM_UNDEFINED;
}
static SCM
remove_contact_binding(SCM accountID_str, SCM uri_str, SCM ban_optional_bool)
{
LOG_BINDING();
libjami::removeContact(from_guile(accountID_str),
from_guile(uri_str),
from_guile(ban_optional_bool));
return SCM_UNDEFINED;
}
static void
install_account_primitives(void *)
{
define_primitive("set-details", 2, 0, 0, (void*) set_details_binding);
define_primitive("get-details", 1, 0, 0, (void*) get_details_binding);
define_primitive("send-register", 2, 0, 0, (void*) send_register_binding);
define_primitive("account->archive", 2, 1, 0, (void*) export_to_file_binding);
define_primitive("add", 1, 1, 0, (void*) add_account_binding);
define_primitive("add-contact", 2, 0, 0, (void*) add_contact_binding);
define_primitive("remove-contact", 2, 1, 0, (void*) remove_contact_binding);
define_primitive("accept-trust-request", 2, 0, 0, (void*) accept_trust_request_binding);
define_primitive("send-trust-request", 2, 1, 0, (void*) send_trust_request_binding);
define_primitive("get-contacts", 1, 0, 0, (void*) get_contacts_binding);
define_primitive("subscribe-buddy", 3, 0, 0, (void*) subscribe_buddy_binding);
}
| 5,017
|
C++
|
.h
| 129
| 32.51938
| 96
| 0.669001
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,872
|
logger.h
|
savoirfairelinux_jami-daemon/test/agent/src/bindings/logger.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
/* Jami */
#include "logger.h"
/* Agent */
#include "utils.h"
static SCM log_binding(SCM log_lvl_int, SCM file_str, SCM line_int, SCM text_str)
{
const std::string file = from_guile(file_str);
const std::string text = from_guile(text_str);
jami::Logger::log(from_guile(log_lvl_int),
file.c_str(),
from_guile(line_int),
false, "[GUILE] %s\n", text.c_str());
return SCM_UNDEFINED;
}
static void
install_logger_primitives(void *)
{
define_primitive("log", 4, 0, 0, (void*) log_binding);
DEFINE_INT(LOG_DEBUG);
DEFINE_INT(LOG_INFO);
DEFINE_INT(LOG_WARNING);
DEFINE_INT(LOG_ERR);
}
| 1,444
|
C++
|
.h
| 40
| 31.3
| 81
| 0.666428
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,873
|
signal.h
|
savoirfairelinux_jami-daemon/test/agent/src/bindings/signal.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
extern void install_signal_primitives(void *);
| 778
|
C++
|
.h
| 18
| 41.333333
| 73
| 0.752306
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,874
|
conversation.h
|
savoirfairelinux_jami-daemon/test/agent/src/bindings/conversation.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
/* Jami */
#include "jami/conversation_interface.h"
/* Agent */
#include "utils.h"
static SCM
get_conversations_binding(SCM accountID_str)
{
LOG_BINDING();
return to_guile(libjami::getConversations(from_guile(accountID_str)));
}
static SCM
get_conversation_members_binding(SCM accountID_str, SCM conversationID_str)
{
LOG_BINDING();
return to_guile(libjami::getConversationMembers(from_guile(accountID_str),
from_guile(conversationID_str)));
}
static SCM
accept_conversation_binding(SCM accountID_str, SCM conversationID_str)
{
LOG_BINDING();
libjami::acceptConversationRequest(from_guile(accountID_str),
from_guile(conversationID_str));
return SCM_UNDEFINED;
}
static SCM
send_message_binding(SCM accountID_str, SCM conversationID_str, SCM message_str,
SCM parent_str_optional)
{
LOG_BINDING();
if (SCM_UNBNDP(parent_str_optional)) {
libjami::sendMessage(from_guile(accountID_str),
from_guile(conversationID_str),
from_guile(message_str),
"");
} else {
libjami::sendMessage(from_guile(accountID_str),
from_guile(conversationID_str),
from_guile(message_str),
from_guile(parent_str_optional));
}
return SCM_UNDEFINED;
}
static void
install_conversation_primitives(void *)
{
define_primitive("get-conversations", 1, 0, 0,
(void*) get_conversations_binding);
define_primitive("get-conversation-members", 2, 0, 0,
(void*) get_conversation_members_binding);
define_primitive("accept-conversation", 2, 0, 0,
(void*) accept_conversation_binding);
define_primitive("send-message", 3, 1, 0,
(void*) send_message_binding);
}
| 2,699
|
C++
|
.h
| 72
| 29.986111
| 84
| 0.648908
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,875
|
call.h
|
savoirfairelinux_jami-daemon/test/agent/src/bindings/call.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
/* Jami */
#include "jami/callmanager_interface.h"
#include "jami/configurationmanager_interface.h"
/* Agent */
#include "utils.h"
static SCM
place_call_with_media_binding(SCM accountID_str,
SCM contact_str,
SCM call_media_vector_alist_optional)
{
LOG_BINDING();
if (SCM_UNBNDP(call_media_vector_alist_optional)) {
call_media_vector_alist_optional = scm_c_make_vector(0, SCM_UNDEFINED);
}
return to_guile(libjami::placeCallWithMedia(from_guile(accountID_str),
from_guile(contact_str),
from_guile(call_media_vector_alist_optional)));
}
static SCM
hang_up_binding(SCM accountID_str, SCM callID_str)
{
LOG_BINDING();
return to_guile(libjami::hangUp(from_guile(accountID_str), from_guile(callID_str)));
}
static SCM
accept_binding(SCM accountID_str, SCM callID_str, SCM call_media_vector_alist_optional)
{
LOG_BINDING();
if (SCM_UNBNDP(call_media_vector_alist_optional)) {
return to_guile(libjami::accept(from_guile(accountID_str), from_guile(callID_str)));
}
return to_guile(libjami::acceptWithMedia(from_guile(accountID_str),
from_guile(callID_str),
from_guile(call_media_vector_alist_optional)));
}
static SCM
refuse_binding(SCM accountID_str, SCM callID_str)
{
LOG_BINDING();
return to_guile(libjami::refuse(from_guile(accountID_str), from_guile(callID_str)));
}
static SCM
hold_binding(SCM accountID_str, SCM callID_str)
{
LOG_BINDING();
return to_guile(libjami::hold(from_guile(accountID_str), from_guile(callID_str)));
}
static SCM
unhold_binding(SCM accountID_str, SCM callID_str)
{
LOG_BINDING();
return to_guile(libjami::unhold(from_guile(accountID_str), from_guile(callID_str)));
}
static void
install_call_primitives(void*)
{
define_primitive("place-call/media", 2, 1, 0, (void*) place_call_with_media_binding);
define_primitive("hang-up", 2, 0, 0, (void*) hang_up_binding);
define_primitive("accept", 2, 1, 0, (void*) accept_binding);
define_primitive("refuse", 2, 0, 0, (void*) refuse_binding);
define_primitive("hold", 2, 0, 0, (void*) hold_binding);
define_primitive("unhold", 2, 0, 0, (void*) unhold_binding);
}
| 3,114
|
C++
|
.h
| 80
| 33.25
| 93
| 0.674511
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,876
|
jami.h
|
savoirfairelinux_jami-daemon/test/agent/src/bindings/jami.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "jami/jami.h"
#include "utils.h"
static SCM init_binding(SCM flags)
{
LOG_BINDING();
unsigned int flags_cast = from_guile(flags);
return to_guile(libjami::init(static_cast<libjami::InitFlag>(flags_cast)));
}
static SCM fini_binding()
{
LOG_BINDING();
libjami::fini();
return SCM_UNDEFINED;
}
static SCM initialized_binding()
{
LOG_BINDING();
return to_guile(libjami::initialized());
}
static SCM logging_binding(SCM whom, SCM action)
{
LOG_BINDING();
libjami::logging(from_guile(whom), from_guile(action));
return SCM_UNDEFINED;
}
static SCM platform_binding()
{
LOG_BINDING();
return to_guile(libjami::platform());
}
static SCM start_binding(SCM config_file)
{
LOG_BINDING();
return to_guile(libjami::start(from_guile(config_file)));
}
static SCM version_binding()
{
LOG_BINDING();
return to_guile(libjami::version());
}
static void
install_jami_primitives(void *)
{
define_primitive("init", 1, 0, 0, (void*) init_binding);
define_primitive("initialized", 0, 0, 0, (void*) initialized_binding);
define_primitive("fini", 0, 0, 0, (void*) fini_binding);
define_primitive("logging", 2, 0, 0, (void*) logging_binding);
define_primitive("platform", 0, 0, 0, (void*) platform_binding);
define_primitive("start", 1, 0, 0, (void*) start_binding);
define_primitive("version", 0, 0, 0, (void*) version_binding);
}
| 2,228
|
C++
|
.h
| 68
| 28.838235
| 83
| 0.686449
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,877
|
sys_time.h
|
savoirfairelinux_jami-daemon/compat/msvc/sys_time.h
|
#ifndef SYS_TIME_H_
#define SYS_TIME_H_
#include <time.h>
#include <winsock2.h>
struct timezone
{
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
};
static __inline int gettimeofday(struct timeval *tp, struct timezone * tzp)
{
FILETIME file_time;
SYSTEMTIME system_time;
ULARGE_INTEGER ularge;
static int tzflag;
GetSystemTime(&system_time);
SystemTimeToFileTime(&system_time, &file_time);
ularge.LowPart = file_time.dwLowDateTime;
ularge.HighPart = file_time.dwHighDateTime;
tp->tv_sec = (long)((ularge.QuadPart - 116444736000000000Ui64) / 10000000L);
tp->tv_usec = (long)(system_time.wMilliseconds * 1000);
if (NULL != tzp)
{
if (!tzflag)
{
_tzset();
tzflag++;
}
tzp->tz_minuteswest = _timezone / 60;
tzp->tz_dsttime = _daylight;
}
return 0;
}
#endif
| 943
|
C++
|
.h
| 34
| 22.794118
| 80
| 0.638981
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,878
|
unistd.h
|
savoirfairelinux_jami-daemon/compat/msvc/unistd.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifndef __STRICT_ANSI__
#include <stdlib.h>
#include <process.h>
#include <direct.h>
#include <fcntl.h>
#include <io.h>
#define R_OK 4
#define W_OK 2
#define F_OK 0
#ifndef STDIN_FILENO
#define STDIN_FILENO 0
#endif
#ifndef STDOUT_FILENO
#define STDOUT_FILENO 1
#endif
#ifndef STDERR_FILENO
#define STDERR_FILENO 2
#endif
#define srandom srand
#define random rand
#define inline __inline
typedef int mode_t;
#include <BaseTsd.h>
#endif
| 1,184
|
C++
|
.h
| 41
| 27.292683
| 73
| 0.755732
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| true
| false
| false
| false
| false
| false
| false
|
751,879
|
config.h
|
savoirfairelinux_jami-daemon/compat/msvc/config.h
|
/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
systems. This function is required for `alloca.c' support on those systems.
*/
/* #undef CRAY_STACKSEG_END */
/* Define to 1 if using `alloca.c'. */
/* #undef C_ALLOCA */
/* Define to 1 if you want hardware acceleration support. */
#define RING_ACCEL 1
/* Define to 1 if you have `alloca', as a function or macro. */
#define HAVE_ALLOCA 1
/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
*/
#define HAVE_ALLOCA_H 1
/* Define if you have alsa */
#define HAVE_ALSA 0
/* Define to 1 if you have the <arpa/inet.h> header file. */
#define HAVE_ARPA_INET_H 0
/* Define if you have CoreAudio */
#define HAVE_COREAUDIO 0
/* define if the compiler supports basic C++11 syntax */
#define HAVE_CXX11 1
/* Define to enable dht */
#define HAVE_DHT 1
/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1
/* Define to 1 if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
/* Define if you have libiax */
#define HAVE_IAX 0
/* Define if you have instant messaging support */
#define HAVE_INSTANT_MESSAGING 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define if you have jack */
#define HAVE_JACK 0
/* Define to 1 if you have the <libintl.h> header file. */
#define HAVE_LIBINTL_H 0
/* Define if you have libupnp */
#define HAVE_LIBUPNP 1
/* Define if you have natpmp */
#define HAVE_LIBNATPMP 1
/* Define to 1 if you have the <limits.h> header file. */
#define HAVE_LIMITS_H 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the <netdb.h> header file. */
#define HAVE_NETDB_H 1
/* Define to 1 if you have the <netinet/in.h> header file. */
#define HAVE_NETINET_IN_H 1
/* Define if you have OpenSL */
/* #undef HAVE_OPENSL */
/* Define if you have portaudio */
#define HAVE_PORTAUDIO 1
/* Define if you have POSIX threads libraries and header files. */
#define HAVE_PTHREAD 1
/* Have PTHREAD_PRIO_INHERIT. */
#define HAVE_PTHREAD_PRIO_INHERIT 1
/* Define to 1 if the system has the type `ptrdiff_t'. */
/* #undef HAVE_PTRDIFF_T */
/* Define if you have pulseaudio */
#define HAVE_PULSE 0
/* Define if you have shared memory support */
#undef ENABLE_SHM
/* Define if you have libspeex */
#define HAVE_SPEEX 0
/* Define if you have libspeexdsp */
#define HAVE_SPEEXDSP 1
/* Define if you have webrtc-audio-processing */
#define HAVE_WEBRTC_AP 1
/* Define to 1 if stdbool.h conforms to C99. */
#define HAVE_STDBOOL_H 1
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 0
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the <sys/ioctl.h> header file. */
#define HAVE_SYS_IOCTL_H 1
/* Define to 1 if you have the <sys/socket.h> header file. */
#define HAVE_SYS_SOCKET_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define if you have tls support */
#define HAVE_TLS 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define to 1 if the system has the type `_Bool'. */
#define HAVE__BOOL 1
/* Define to the sub-directory where libtool stores uninstalled libraries. */
#define LT_OBJDIR ".libs/"
/* Name of package */
#define PACKAGE "jami"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "jami@lists.savoirfairelinux.net"
/* Define to the full name of this package. */
#define PACKAGE_NAME "Jami Daemon"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "Jami Daemon 10.0.2"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "jami"
/* Define to the home page for this package. */
#define PACKAGE_URL ""
/* Define to the version of this package. */
#define PACKAGE_VERSION "10.0.2"
/* Define to necessary symbol if this constant uses a non-standard name on
your system. */
/* #undef PTHREAD_CREATE_JOINABLE */
/* Video support enabled */
#define ENABLE_VIDEO /**/
/* Jami Plugin support enabled */
#define ENABLE_PLUGIN /**/
/* Name directory service support enabled */
#define HAVE_RINGNS 1
/* If using the C implementation of alloca, define if you know the
direction of stack growth for your system; otherwise it will be
automatically deduced at runtime.
STACK_DIRECTION > 0 => grows toward higher addresses
STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown */
/* #undef STACK_DIRECTION */
/* Define to 1 if the `S_IS*' macros in <sys/stat.h> do not work properly. */
/* #undef STAT_MACROS_BROKEN */
/* Define to 1 if you have the ANSI C header files. */
/* #undef STDC_HEADERS */
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#define TIME_WITH_SYS_TIME 1
/* Define to 1 for Unicode (Wide Chars) APIs. */
#define UNICODE 1
#undef _MBCS
/* Version number of package */
#define VERSION "10.0.2"
// UWP compatibility
#define JAMI_DATADIR ""
/* Define to limit the scope of <windows.h>. */
/* #undef WIN32_LEAN_AND_MEAN */
/* ISO C, POSIX, and 4.3BSD things. */
/* #undef _BSD_SOURCE */
/* Extensions to ISO C99 from ISO C11. */
/* #undef _ISOC11_SOURCE */
/* Extensions to ISO C89 from ISO C99. */
/* #undef _ISOC99_SOURCE */
/* IEEE Std 1003.1. */
/* #undef _POSIX_C_SOURCE */
/* IEEE Std 1003.1. */
/* #undef _POSIX_SOURCE */
/* ISO C, POSIX, and SVID things. */
/* #undef _SVID_SOURCE */
/* Define to 1 for Unicode (Wide Chars) APIs. */
/* #undef _UNICODE */
/* POSIX and XPG 7th edition */
/* #undef _XOPEN_SOURCE */
/* XPG things and X/Open Unix extensions. */
/* #undef _XOPEN_SOURCE_EXTENDED */
/* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
/* #undef inline */
#endif
/* Define to `int' if <sys/types.h> does not define. */
/* #undef pid_t */
/* Define to `unsigned int' if <sys/types.h> does not define. */
/* #undef size_t */
/* Define to empty if the keyword `volatile' does not work. Warning: valid
code using `volatile' can become incorrect without. Disable with care. */
/* #undef volatile */
| 6,725
|
C++
|
.h
| 174
| 37.189655
| 78
| 0.711063
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,880
|
compiler_intrinsics.h
|
savoirfairelinux_jami-daemon/src/compiler_intrinsics.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef INTRIN_H_
#define INTRIN_H_
#ifdef _MSC_VER
#define UNUSED
#else
#define UNUSED __attribute__((__unused__))
#endif
#endif // INTRIN_H_
| 863
|
C++
|
.h
| 24
| 34.208333
| 73
| 0.742823
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,881
|
account_factory.h
|
savoirfairelinux_jami-daemon/src/account_factory.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
#include <map>
#include <vector>
#include <memory>
#include <mutex>
#include <utility>
#include <functional>
#include <ciso646>
namespace jami {
class Account;
class AccountGeneratorBase;
template<class T>
using AccountMap = std::map<std::string, std::shared_ptr<T>, std::less<>>;
class AccountFactory
{
public:
static const std::string_view DEFAULT_ACCOUNT_TYPE;// = SIPAccount::ACCOUNT_TYPE;
AccountFactory();
bool isSupportedType(std::string_view accountType) const;
std::shared_ptr<Account> createAccount(std::string_view accountType, const std::string& id);
void removeAccount(Account& account);
void removeAccount(std::string_view id);
template<class T = Account>
bool hasAccount(std::string_view id) const
{
std::lock_guard lk(mutex_);
const auto map = getMap_<T>();
return map and map->find(id) != map->cend();
}
template<class T = Account>
void clear()
{
std::lock_guard lk(mutex_);
auto map = getMap_<T>();
if (!map)
return;
map->clear();
}
template<class T = Account>
bool empty() const
{
std::lock_guard lock(mutex_);
const auto map = getMap_<T>();
return map and map->empty();
}
template<class T = Account>
std::size_t accountCount() const
{
std::lock_guard lock(mutex_);
const auto map = getMap_<T>();
if (!map)
return 0;
return map->size();
}
template<class T = Account>
std::shared_ptr<T> getAccount(std::string_view id) const
{
std::lock_guard lock(mutex_);
const auto map = getMap_<T>();
if (!map)
return nullptr;
const auto& it = map->find(id);
if (it == map->cend())
return nullptr;
return std::static_pointer_cast<T>(it->second);
}
template<class T = Account>
std::vector<std::shared_ptr<T>> getAllAccounts() const
{
std::lock_guard lock(mutex_);
std::vector<std::shared_ptr<T>> v;
if (const auto map = getMap_<T>()) {
v.reserve(map->size());
for (const auto& it : *map)
v.emplace_back(std::static_pointer_cast<T>(it.second));
}
return v;
}
private:
mutable std::recursive_mutex mutex_ {};
std::map<std::string, std::function<std::shared_ptr<Account>(const std::string&)>, std::less<>> generators_ {};
std::map<std::string, AccountMap<Account>, std::less<>> accountMaps_ {};
template<class T>
const AccountMap<Account>* getMap_() const
{
const auto& itermap = accountMaps_.find(T::ACCOUNT_TYPE);
if (itermap != accountMaps_.cend())
return &itermap->second;
return nullptr;
}
};
template<>
bool AccountFactory::hasAccount(std::string_view id) const;
template<>
void AccountFactory::clear();
template<>
std::vector<std::shared_ptr<Account>> AccountFactory::getAllAccounts() const;
template<>
std::shared_ptr<Account> AccountFactory::getAccount(std::string_view accountId) const;
template<>
bool AccountFactory::empty() const;
template<>
std::size_t AccountFactory::accountCount() const;
} // namespace jami
| 3,981
|
C++
|
.h
| 121
| 27.586777
| 115
| 0.652026
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,882
|
scheduled_executor.h
|
savoirfairelinux_jami-daemon/src/scheduled_executor.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <thread>
#include <functional>
#include <map>
#include <vector>
#include <chrono>
#include <memory>
#include <atomic>
#include <mutex>
#include <condition_variable>
#include <ciso646>
#include <string>
#include "noncopyable.h"
#include "tracepoint.h"
#include "trace-tools.h"
namespace jami {
extern std::atomic<uint64_t> task_cookie;
/**
* A runnable function
*/
struct Job {
Job(std::function<void()>&& f, const char* file, uint32_t l)
: fn(std::move(f))
, filename(file)
, linum(l) { }
std::function<void()> fn;
const char* filename;
uint32_t linum;
inline operator bool() const {
return static_cast<bool>(fn);
}
void reset() {
fn = {};
}
};
struct RepeatedJob {
RepeatedJob(std::function<bool()>&& f, const char* file, uint32_t l)
: fn(std::move(f))
, filename(file)
, linum(l) { }
std::function<bool()> fn;
const char* filename;
uint32_t linum;
inline operator bool() {
return static_cast<bool>(fn);
}
void reset() {
fn = {};
}
};
/**
* A Job that can be disposed
*/
class Task
{
public:
Task(std::function<void()>&& fn, const char* filename, uint32_t linum)
: job_(std::move(fn), filename, linum)
, cookie_(task_cookie++) { }
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
void run(const char* executor_name)
{
if (job_.fn) {
jami_tracepoint(scheduled_executor_task_begin,
executor_name,
job_.filename, job_.linum,
cookie_);
job_.fn();
jami_tracepoint(scheduled_executor_task_end,
cookie_);
}
}
#pragma GCC pop
void cancel() { job_.reset(); }
bool isCancelled() const { return !job_; }
Job& job() { return job_; }
private:
Job job_;
uint64_t cookie_;
};
/**
* A RepeatedJob that can be disposed
*/
class RepeatedTask
{
public:
RepeatedTask(std::function<bool()>&& fn, const char* filename,
uint32_t linum)
: job_(std::move(fn), filename, linum)
, cookie_(task_cookie++) { }
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
bool run(const char* executor_name)
{
bool cont;
std::lock_guard l(lock_);
if (not cancel_.load() and job_.fn) {
jami_tracepoint(scheduled_executor_task_begin,
executor_name,
job_.filename, job_.linum,
cookie_);
cont = job_.fn();
jami_tracepoint(scheduled_executor_task_end,
cookie_);
} else {
cont = false;
}
if (not cont) {
cancel_.store(true);
job_.reset();
}
return static_cast<bool>(job_);
}
#pragma GCC pop
void cancel() { cancel_.store(true); }
void destroy()
{
cancel();
std::lock_guard l(lock_);
job_.reset();
}
bool isCancelled() const { return cancel_.load(); }
RepeatedJob& job() { return job_; }
private:
NON_COPYABLE(RepeatedTask);
RepeatedJob job_;
mutable std::mutex lock_;
std::atomic_bool cancel_ {false};
uint64_t cookie_;
};
class ScheduledExecutor
{
public:
using clock = std::chrono::steady_clock;
using time_point = clock::time_point;
using duration = clock::duration;
ScheduledExecutor(const std::string& name_);
~ScheduledExecutor();
/**
* Schedule job to be run ASAP
*/
void run(std::function<void()>&& job,
const char* filename=CURRENT_FILENAME(),
uint32_t linum=CURRENT_LINE());
/**
* Schedule job to be run at time t
*/
std::shared_ptr<Task> schedule(std::function<void()>&& job, time_point t,
const char* filename=CURRENT_FILENAME(),
uint32_t linum=CURRENT_LINE());
/**
* Schedule job to be run after delay dt
*/
std::shared_ptr<Task> scheduleIn(std::function<void()>&& job, duration dt,
const char* filename=CURRENT_FILENAME(),
uint32_t linum=CURRENT_LINE());
/**
* Schedule job to be run every dt, starting now.
*/
std::shared_ptr<RepeatedTask> scheduleAtFixedRate(std::function<bool()>&& job,
duration dt,
const char* filename=CURRENT_FILENAME(),
uint32_t linum=CURRENT_LINE());
/**
* Stop the scheduler, it is unable to be reversed
*/
void stop();
private:
NON_COPYABLE(ScheduledExecutor);
void loop();
void schedule(std::shared_ptr<Task>, time_point t);
void reschedule(std::shared_ptr<RepeatedTask>, time_point t, duration dt);
std::string name_;
std::shared_ptr<std::atomic<bool>> running_;
std::map<time_point, std::vector<Job>> jobs_ {};
std::mutex jobLock_ {};
std::condition_variable cv_ {};
std::thread thread_;
};
} // namespace jami
| 6,062
|
C++
|
.h
| 197
| 23.335025
| 94
| 0.580429
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,883
|
rational.h
|
savoirfairelinux_jami-daemon/src/rational.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <utility> // std::swap
#include <cstdlib> // std::abs
#include <iostream>
#include <cmath> // std::fmod
#include <functional> // std::modulus
#include <ciso646> // and, or ...
extern "C" {
#include <libavutil/rational.h> // specify conversions for AVRational
}
namespace jami {
/**
* Naive implementation of the boost::rational interface, described here:
* http://www.boost.org/doc/libs/1_57_0/libs/rational/rational.html
*/
template<typename I>
class rational
{
public:
// Constructors
constexpr rational() {} // Zero
constexpr rational(I n)
: num_(n) {} // Equal to n/1
constexpr rational(I n, I d)
: num_(n)
, den_(d)
{
reduce();
} // General case (n/d)
// Define conversions to and from AVRational (equivalent)
constexpr rational(AVRational r)
: num_(r.num)
, den_(r.den) {};
constexpr operator AVRational() const { return AVRational {(int) num_, (int) den_}; }
// Normal copy constructors and assignment operators
// Assignment from I
rational& operator=(I n)
{
num_ = n;
den_ = 1;
return *this;
}
// Assign in place
rational& assign(I n, I d)
{
num_ = n;
den_ = d;
reduce();
return *this;
}
// Representation
constexpr I numerator() const { return num_; };
constexpr I denominator() const { return den_; };
template<typename R = double>
constexpr R real() const
{
return num_ / (R) den_;
}
// In addition to the following operators, all of the "obvious" derived
// operators are available - see operators.hpp
// Arithmetic operators
constexpr rational operator+(const rational& r) const
{
return {num_ * r.den_ + r.num_ * den_, den_ * r.den_};
}
constexpr rational operator-(const rational& r) const
{
return {num_ * r.den_ - r.num_ * den_, den_ * r.den_};
}
constexpr rational operator*(const rational& r) const { return {num_ * r.num_, den_ * r.den_}; }
constexpr rational operator/(const rational& r) const { return {num_ * r.den_, den_ * r.num_}; }
rational& operator+=(const rational& r)
{
std::swap(*this, *this + r);
return *this;
}
rational& operator-=(const rational& r)
{
std::swap(*this, *this - r);
return *this;
}
rational& operator*=(const rational& r)
{
num_ *= r.num_;
den_ *= r.den_;
reduce();
return *this;
}
rational& operator/=(const rational& r)
{
num_ *= r.den_;
den_ *= r.num_;
reduce();
return *this;
}
// Arithmetic with integers
rational& operator+=(I i)
{
num_ += i * den_;
return *this;
}
rational& operator-=(I i)
{
num_ -= i * den_;
return *this;
}
rational& operator*=(I i)
{
num_ *= i;
reduce();
return *this;
}
rational& operator/=(I i)
{
den_ *= i;
reduce();
return *this;
}
// Increment and decrement
const rational& operator++()
{
num_ += den_;
return *this;
}
const rational& operator--()
{
num_ -= den_;
return *this;
}
// Operator not
constexpr bool operator!() const { return !num_; };
// Boolean conversion
explicit constexpr operator bool() const { return num_; }
// Comparison operators
constexpr bool operator<(const rational& r) const
{
bool inv = (den_ > 0) != (r.den_ > 0);
return inv != (num_ * r.den_ < den_ * r.num_);
}
constexpr bool operator>(const rational& r) const
{
bool inv = (den_ > 0) != (r.den_ > 0);
return inv != (num_ * r.den_ > den_ * r.num_);
}
constexpr bool operator==(const rational& r) const { return num_ * r.den_ == den_ * r.num_; }
constexpr bool operator!=(const rational& r) const { return num_ * r.den_ != den_ * r.num_; }
// Comparison with integers
constexpr bool operator<(I i) const { return den_ < 0 ? (num_ > i * den_) : (num_ < i * den_); }
constexpr bool operator>(I i) const { return den_ < 0 ? (num_ < i * den_) : (num_ > i * den_); }
constexpr bool operator==(I i) const { return num_ == i * den_; }
constexpr bool operator!=(I i) const { return num_ != i * den_; }
private:
I num_ {0};
I den_ {1};
static constexpr I gcd(I a, I b) { return b == (I) 0 ? a : gcd(b, std::modulus<I>()(a, b)); }
void reduce()
{
if (std::is_integral<I>::value) {
if (num_ and den_) {
auto g = gcd(num_ >= 0 ? num_ : -num_, den_ >= 0 ? den_ : -den_);
if (g > (I) 1) {
num_ /= g;
den_ /= g;
}
}
}
}
};
// Unary operators
template<typename I>
rational<I>
operator+(const rational<I>& r)
{
return r;
}
template<typename I>
rational<I>
operator-(const rational<I>& r)
{
return {-r.numerator(), r.denominator()};
};
// Reversed order operators for - and / between (types convertible to) I and rational
template<typename I, typename II>
inline rational<I> operator-(II i, const rational<I>& r);
template<typename I, typename II>
inline rational<I>
operator/(II i, const rational<I>& r)
{
return {i * r.denominator(), r.numerator()};
}
// Absolute value
template<typename I>
rational<I>
abs(const rational<I>& r)
{
return {std::abs(r.numerator()), std::abs(r.denominator())};
}
// Input and output
template<typename I>
std::istream&
operator>>(std::istream& is, rational<I>& r)
{
char sep;
is >> r.num_ >> sep >> r.den_;
return is;
}
template<typename I>
std::ostream&
operator<<(std::ostream& os, const rational<I>& r)
{
os << r.numerator() << '/' << r.denominator();
return os;
}
// Type conversion
template<typename T, typename I>
T rational_cast(const rational<I>& r);
} // namespace jami
namespace std {
template<>
struct modulus<double>
{
double operator()(const double& lhs, const double& rhs) const { return std::fmod(lhs, rhs); }
};
} // namespace std
| 6,908
|
C++
|
.h
| 240
| 23.820833
| 100
| 0.591203
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,884
|
call_set.h
|
savoirfairelinux_jami-daemon/src/call_set.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "call.h"
#include "conference.h"
#include <map>
#include <memory>
#include <string>
#include <mutex>
namespace jami {
class CallSet
{
public:
std::shared_ptr<Call> getCall(const std::string& callId) const
{
std::lock_guard l(mutex_);
auto i = calls_.find(callId);
return i == calls_.end() ? std::shared_ptr<Call> {} : i->second.lock();
}
std::shared_ptr<Conference> getConference(const std::string& conferenceId) const
{
std::lock_guard l(mutex_);
auto i = conferences_.find(conferenceId);
return i == conferences_.end() ? std::shared_ptr<Conference> {} : i->second;
}
void add(const std::shared_ptr<Call>& call)
{
std::lock_guard l(mutex_);
calls_.emplace(call->getCallId(), call);
}
void add(const std::shared_ptr<Conference>& conference)
{
std::lock_guard l(mutex_);
conferences_.emplace(conference->getConfId(), conference);
}
bool remove(const std::shared_ptr<Call>& call)
{
std::lock_guard l(mutex_);
return calls_.erase(call->getCallId()) > 0;
}
bool removeConference(const std::string& confId)
{
std::lock_guard l(mutex_);
return conferences_.erase(confId) > 0;
}
std::vector<std::string> getCallIds() const
{
std::lock_guard l(mutex_);
std::vector<std::string> ids;
ids.reserve(calls_.size());
for (const auto& callIt : calls_)
ids.emplace_back(callIt.first);
return ids;
}
std::vector<std::shared_ptr<Call>> getCalls() const
{
std::lock_guard l(mutex_);
std::vector<std::shared_ptr<Call>> calls;
calls.reserve(calls_.size());
for (const auto& callIt : calls_)
if (auto call = callIt.second.lock())
calls.emplace_back(std::move(call));
return calls;
}
std::vector<std::string> getConferenceIds() const
{
std::lock_guard l(mutex_);
std::vector<std::string> ids;
ids.reserve(conferences_.size());
for (const auto& confIt : conferences_)
ids.emplace_back(confIt.first);
return ids;
}
std::vector<std::shared_ptr<Conference>> getConferences() const
{
std::lock_guard l(mutex_);
std::vector<std::shared_ptr<Conference>> confs;
confs.reserve(conferences_.size());
for (const auto& confIt : conferences_)
if (const auto& conf = confIt.second)
confs.emplace_back(conf);
return confs;
}
private:
mutable std::mutex mutex_;
std::map<std::string, std::weak_ptr<Call>> calls_;
std::map<std::string, std::shared_ptr<Conference>> conferences_;
};
} // namespace jami
| 3,494
|
C++
|
.h
| 103
| 27.990291
| 84
| 0.633649
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,885
|
threadloop.h
|
savoirfairelinux_jami-daemon/src/threadloop.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <atomic>
#include <thread>
#include <functional>
#include <stdexcept>
#include <condition_variable>
#include <mutex>
namespace jami {
struct ThreadLoopException : public std::runtime_error
{
ThreadLoopException()
: std::runtime_error("ThreadLoopException")
{}
};
class ThreadLoop
{
public:
enum class ThreadState { READY, RUNNING, STOPPING };
ThreadLoop(const std::function<bool()>& setup,
const std::function<void()>& process,
const std::function<void()>& cleanup);
virtual ~ThreadLoop();
void start();
void exit();
virtual void stop();
void join();
void waitForCompletion(); // thread will stop itself
bool isRunning() const noexcept;
bool isStopping() const noexcept { return state_ == ThreadState::STOPPING; }
std::thread::id get_id() const noexcept { return threadId_; }
private:
ThreadLoop(const ThreadLoop&) = delete;
ThreadLoop(ThreadLoop&&) noexcept = delete;
ThreadLoop& operator=(const ThreadLoop&) = delete;
ThreadLoop& operator=(ThreadLoop&&) noexcept = delete;
// These must be provided by users of ThreadLoop
std::function<bool()> setup_;
std::function<void()> process_;
std::function<void()> cleanup_;
void mainloop(std::thread::id& tid,
const std::function<bool()> setup,
const std::function<void()> process,
const std::function<void()> cleanup);
std::atomic<ThreadState> state_ {ThreadState::READY};
std::thread::id threadId_;
std::thread thread_;
};
class InterruptedThreadLoop : public ThreadLoop
{
public:
InterruptedThreadLoop(const std::function<bool()>& setup,
const std::function<void()>& process,
const std::function<void()>& cleanup)
: ThreadLoop::ThreadLoop(setup, process, cleanup)
{}
void stop() override;
void interrupt() noexcept { cv_.notify_one(); }
template<typename Rep, typename Period>
void wait_for(const std::chrono::duration<Rep, Period>& rel_time)
{
if (std::this_thread::get_id() != get_id())
throw std::runtime_error("Unable to call wait_for outside thread context");
std::unique_lock lk(mutex_);
cv_.wait_for(lk, rel_time, [this]() { return isStopping(); });
}
template<typename Rep, typename Period, typename Pred>
bool wait_for(const std::chrono::duration<Rep, Period>& rel_time, Pred&& pred)
{
if (std::this_thread::get_id() != get_id())
throw std::runtime_error("Unable to call wait_for outside thread context");
std::unique_lock lk(mutex_);
return cv_.wait_for(lk, rel_time, [this, pred] { return isStopping() || pred(); });
}
template<typename Pred>
void wait(Pred&& pred)
{
if (std::this_thread::get_id() != get_id())
throw std::runtime_error("Unable to call wait outside thread context");
std::unique_lock lk(mutex_);
cv_.wait(lk, [this, p = std::forward<Pred>(pred)] { return isStopping() || p(); });
}
private:
std::mutex mutex_;
std::condition_variable cv_;
};
} // namespace jami
| 3,930
|
C++
|
.h
| 102
| 32.931373
| 91
| 0.658697
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,886
|
fileutils.h
|
savoirfairelinux_jami-daemon/src/fileutils.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "jami/def.h"
#include <dhtnet/fileutils.h>
#include <string>
#include <vector>
#include <chrono>
#include <mutex>
#include <cstdio>
#include <ios>
#include <filesystem>
#include <string_view>
#ifndef _WIN32
#include <sys/stat.h> // mode_t
#define DIR_SEPARATOR_STR "/" // Directory separator string
#define DIR_SEPARATOR_CH '/' // Directory separator char
#define DIR_SEPARATOR_STR_ESC "\\/" // Escaped directory separator string
#else
#define mode_t unsigned
#define DIR_SEPARATOR_STR "\\" // Directory separator string
#define DIR_SEPARATOR_CH '\\' // Directory separator char
#define DIR_SEPARATOR_STR_ESC "//*" // Escaped directory separator string
#endif
namespace jami {
namespace fileutils {
using namespace std::literals;
std::filesystem::path get_config_dir(const char* pkg);
std::filesystem::path get_data_dir(const char* pkg);
std::filesystem::path get_cache_dir(const char* pkg);
const std::filesystem::path& get_home_dir();
const std::filesystem::path& get_config_dir();
const std::filesystem::path& get_data_dir();
const std::filesystem::path& get_cache_dir();
/**
* Set the program's resource directory path. This is used for clients that may be installed in different
* locations and are deployed with ringtones and other resources in an application relative directory.
* @param resource_dir_path The path to the ringtone directory.
*/
LIBJAMI_PUBLIC void set_resource_dir_path(const std::filesystem::path& resourceDirPath);
/**
* Get the resource directory path that was set with set_resource_dir_path.
* @return The resource directory path.
*/
const std::filesystem::path& get_resource_dir_path();
/**
* Expand the given path.
* @param path The path to be expanded.
* @return The expanded path as a string.
*/
std::string expand_path(const std::string& path);
bool isPathRelative(const std::filesystem::path& path);
/**
* If path is contained in base, return the suffix, otherwise return the full path.
* @param base must not finish with DIR_SEPARATOR_STR, can be empty
* @param path the path
*/
std::string getCleanPath(const std::string& base, const std::string& path);
/**
* If path is relative, it is appended to base.
*/
std::filesystem::path getFullPath(const std::filesystem::path& base,
const std::filesystem::path& path);
bool createFileLink(const std::filesystem::path& src, const std::filesystem::path& dest, bool hard = false);
std::string_view getFileExtension(std::string_view filename);
bool isDirectoryWritable(const std::string& directory);
/**
* Read the full content of a file at path.
* If path is relative, it is appended to default_dir.
*/
std::vector<uint8_t> loadFile(const std::filesystem::path& path,
const std::filesystem::path& default_dir = {});
std::string loadTextFile(const std::filesystem::path& path,
const std::filesystem::path& default_dir = {});
void saveFile(const std::filesystem::path& path, const uint8_t* data, size_t data_size, mode_t mode = 0644);
inline void
saveFile(const std::filesystem::path& path, const std::vector<uint8_t>& data, mode_t mode = 0644)
{
saveFile(path, data.data(), data.size(), mode);
}
std::vector<uint8_t> loadCacheFile(const std::filesystem::path& path,
std::chrono::system_clock::duration maxAge);
std::string loadCacheTextFile(const std::filesystem::path& path, std::chrono::system_clock::duration maxAge);
static constexpr auto ARCHIVE_AUTH_SCHEME_NONE = ""sv;
static constexpr auto ARCHIVE_AUTH_SCHEME_PASSWORD = "password"sv;
static constexpr auto ARCHIVE_AUTH_SCHEME_KEY = "key"sv;
struct ArchiveStorageData {
std::vector<uint8_t> data;
std::vector<uint8_t> salt;
};
ArchiveStorageData readArchive(const std::filesystem::path& path, std::string_view scheme, const std::string& pwd);
void writeArchive(const std::string& data,
const std::filesystem::path& path,
std::string_view scheme,
const std::string& password = {}, const std::vector<uint8_t>& password_salt = {});
int64_t size(const std::filesystem::path& path);
std::string sha3File(const std::filesystem::path& path);
std::string sha3sum(const std::vector<uint8_t>& buffer);
/**
* Windows compatibility wrapper for checking read-only attribute
*/
int accessFile(const std::string& file, int mode);
/**
* Return the last write time (epoch time) of a given file path (in seconds).
*/
uint64_t lastWriteTimeInSeconds(const std::filesystem::path& filePath);
} // namespace fileutils
} // namespace jami
| 5,382
|
C++
|
.h
| 122
| 41.02459
| 115
| 0.720099
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,887
|
map_utils.h
|
savoirfairelinux_jami-daemon/src/map_utils.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <vector>
#include <iterator>
#include <algorithm>
#include <tuple>
namespace jami {
namespace map_utils {
///< Return the N-th type of a tuple type used as the Container compliant value type
template<typename C, std::size_t N>
using type_element =
typename std::remove_cv<typename std::tuple_element<N, typename C::value_type>::type>::type;
///< Extract in a std::vector object each N-th values of tuples contained in a Container compliant
///< object \a container.
template<std::size_t N, typename C>
inline std::vector<type_element<C, N>>
extractElements(const C& container)
{
std::vector<type_element<C, N>> result;
if (container.size() > 0) {
result.resize(container.size());
auto iter = std::begin(container);
std::generate(std::begin(result), std::end(result), [&] { return std::get<N>(*iter++); });
}
return result;
}
template<typename M>
inline auto
extractKeys(const M& map) -> decltype(extractElements<0>(map))
{
return extractElements<0>(map);
}
template<typename M>
inline auto
extractValues(const M& map) -> decltype(extractElements<1>(map))
{
return extractElements<1>(map);
}
} // namespace map_utils
} // namespace jami
| 1,934
|
C++
|
.h
| 55
| 32.818182
| 98
| 0.72703
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,888
|
vcard.h
|
savoirfairelinux_jami-daemon/src/vcard.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
#include <string_view>
#include <map>
namespace vCard {
struct Delimiter
{
constexpr static std::string_view SEPARATOR_TOKEN = ";";
constexpr static std::string_view END_LINE_TOKEN = "\n";
constexpr static std::string_view BEGIN_TOKEN = "BEGIN:VCARD";
constexpr static std::string_view END_TOKEN = "END:VCARD";
constexpr static std::string_view BEGIN_TOKEN_KEY = "BEGIN";
constexpr static std::string_view END_TOKEN_KEY = "END";
};;
struct Property
{
constexpr static std::string_view UID = "UID";
constexpr static std::string_view VCARD_VERSION = "VERSION";
constexpr static std::string_view ADDRESS = "ADR";
constexpr static std::string_view AGENT = "AGENT";
constexpr static std::string_view BIRTHDAY = "BDAY";
constexpr static std::string_view CATEGORIES = "CATEGORIES";
constexpr static std::string_view CLASS = "CLASS";
constexpr static std::string_view DELIVERY_LABEL = "LABEL";
constexpr static std::string_view EMAIL = "EMAIL";
constexpr static std::string_view FORMATTED_NAME = "FN";
constexpr static std::string_view GEOGRAPHIC_POSITION = "GEO";
constexpr static std::string_view KEY = "KEY";
constexpr static std::string_view LOGO = "LOGO";
constexpr static std::string_view MAILER = "MAILER";
constexpr static std::string_view NAME = "N";
constexpr static std::string_view NICKNAME = "NICKNAME";
constexpr static std::string_view DESCRIPTION = "DESCRIPTION";
constexpr static std::string_view NOTE = "NOTE";
constexpr static std::string_view ORGANIZATION = "ORG";
constexpr static std::string_view PHOTO = "PHOTO";
constexpr static std::string_view PRODUCT_IDENTIFIER = "PRODID";
constexpr static std::string_view REVISION = "REV";
constexpr static std::string_view ROLE = "ROLE";
constexpr static std::string_view SORT_STRING = "SORT-STRING";
constexpr static std::string_view SOUND = "SOUND";
constexpr static std::string_view TELEPHONE = "TEL";
constexpr static std::string_view TIME_ZONE = "TZ";
constexpr static std::string_view TITLE = "TITLE";
constexpr static std::string_view RDV_ACCOUNT = "RDV_ACCOUNT";
constexpr static std::string_view RDV_DEVICE = "RDV_DEVICE";
constexpr static std::string_view URL = "URL";
constexpr static std::string_view BASE64 = "ENCODING=BASE64";
constexpr static std::string_view TYPE_PNG = "TYPE=PNG";
constexpr static std::string_view TYPE_JPEG = "TYPE=JPEG";
constexpr static std::string_view PHOTO_PNG = "PHOTO;ENCODING=BASE64;TYPE=PNG";
constexpr static std::string_view PHOTO_JPEG = "PHOTO;ENCODING=BASE64;TYPE=JPEG";
};
struct Value
{
constexpr static std::string_view TITLE = "title";
constexpr static std::string_view DESCRIPTION = "description";
constexpr static std::string_view AVATAR = "avatar";
constexpr static std::string_view RDV_ACCOUNT = "rdvAccount";
constexpr static std::string_view RDV_DEVICE = "rdvDevice";
};
namespace utils {
/**
* Payload to vCard
* @param content payload
* @return the vCard representation
*/
std::map<std::string, std::string> toMap(std::string_view content);
std::map<std::string, std::string> initVcard();
std::string toString(const std::map<std::string, std::string>& vCard);
} // namespace utils
} // namespace vCard
| 4,066
|
C++
|
.h
| 88
| 42.761364
| 85
| 0.724937
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,889
|
base64.h
|
savoirfairelinux_jami-daemon/src/base64.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
#include <string_view>
#include <vector>
#include <exception>
#include <cstdint>
namespace jami {
namespace base64 {
class base64_exception : public std::exception
{};
std::string encode(std::string_view);
inline std::string encode(const std::vector<uint8_t>& data) {
return encode(std::string_view((const char*)data.data(), data.size()));
}
std::vector<uint8_t> decode(std::string_view);
} // namespace base64
} // namespace jami
| 1,191
|
C++
|
.h
| 33
| 34.272727
| 75
| 0.746087
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,890
|
account.h
|
savoirfairelinux_jami-daemon/src/account.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "client/ring_signal.h"
#include "configurationmanager_interface.h"
#include "noncopyable.h"
#include "config/serializable.h"
#include "registration_states.h"
#include "im/message_engine.h"
#include "media/media_codec.h"
#include "media/media_attribute.h"
#include "logger.h"
#include "compiler_intrinsics.h" // include the "UNUSED" macro
#include "call_set.h"
#include "account_config.h"
#include <dhtnet/ip_utils.h>
#include <dhtnet/upnp/upnp_control.h>
#include <functional>
#include <string>
#include <vector>
#include <memory>
#include <map>
#include <set>
#include <random>
#include <stdexcept>
#include <atomic>
#include <mutex>
#include <chrono>
namespace Json {
class Value;
}
namespace jami {
static constexpr uint64_t JAMI_ID_MAX_VAL = 9007199254740992;
constexpr static const char RINGDIR[] = "ringtones";
class Call;
class SystemCodecContainer;
class VoipLinkException : public std::runtime_error
{
public:
VoipLinkException(const std::string& str = "")
: std::runtime_error("VoipLinkException occurred: " + str)
{}
};
/**
* @file account.h
* @brief Interface to protocol account (ex: SIPAccount)
* It can be enable on loading or activate after.
* It contains account, configuration, VoIP Link and Calls (inside the VoIPLink)
*/
class Account : public std::enable_shared_from_this<Account>
{
public:
Account(const std::string& accountID);
/**
* Virtual destructor
*/
virtual ~Account();
/**
* Free all ressources related to this account.
* ***Current calls using this account are HANG-UP***
*/
void hangupCalls();
virtual std::unique_ptr<AccountConfig> buildConfig() const = 0;
void setConfig(std::unique_ptr<AccountConfig>&& config)
{
std::lock_guard lock(configurationMutex_);
config_ = std::move(config);
loadConfig();
}
/**
* Load the settings in this account.
*/
virtual void loadConfig();
const AccountConfig& config() const
{
if (config_)
return *config_;
else
throw std::runtime_error("Account doesn't have a configuration");
}
inline void editConfig(std::function<void(AccountConfig& config)>&& edit)
{
std::lock_guard lock(configurationMutex_);
edit(*config_);
saveConfig();
}
virtual void saveConfig() const;
void setAccountDetails(const std::map<std::string, std::string>& details)
{
std::lock_guard lock(configurationMutex_);
if (not config_)
config_ = buildConfig();
config_->fromMap(details);
loadConfig();
saveConfig();
}
std::map<std::string, std::string> getAccountDetails() const
{
std::lock_guard lock(configurationMutex_);
return config().toMap();
}
virtual std::map<std::string, std::string> getVolatileAccountDetails() const;
virtual std::string getFromUri() const = 0;
/**
* Get the account ID
* @return constant account id
*/
const std::string& getAccountID() const { return accountID_; }
virtual std::string_view getAccountType() const = 0;
/**
* Returns true if this is the IP2IP account
*/
virtual bool isIP2IP() const { return false; }
/**
* Register the account.
* This should update the getRegistrationState() return value.
*/
virtual void doRegister() = 0;
/**
* Unregister the account.
* This should update the getRegistrationState() return value.
*/
virtual void doUnregister(std::function<void(bool)> cb = std::function<void(bool)>()) = 0;
RegistrationState getRegistrationState() const { return registrationState_; }
/**
* Create a new outgoing call.
*
* @param toUrl The address to call
* @param mediaList A list of media
* @return The created call
*/
virtual std::shared_ptr<Call> newOutgoingCall(std::string_view toUrl,
const std::vector<libjami::MediaMap>& mediaList)
= 0;
/**
* If supported, send a text message from this account.
* @return a token to query the message status
*/
virtual uint64_t sendTextMessage(const std::string& /*to*/,
const std::string& /*deviceId*/,
const std::map<std::string, std::string>& /*payloads*/,
uint64_t /*refreshToken*/ = 0,
bool /*onlyConnected*/ = false)
{
return 0;
}
virtual void setIsComposing(const std::string& /*conversationUri*/, bool /*isWriting*/) {};
virtual bool setMessageDisplayed(const std::string& /*conversationUri*/,
const std::string& /*messageId*/,
int /*status*/)
{
return false;
};
virtual std::vector<libjami::Message> getLastMessages(const uint64_t& /*base_timestamp*/)
{
return {};
}
virtual std::map<std::string, std::string> getNearbyPeers() const { return {}; }
virtual void updateProfile(const std::string& /*displayName*/, const std::string& /*avatar*/,const uint64_t& /*flag*/) {}
/**
* Return the status corresponding to the token.
*/
virtual im::MessageStatus getMessageStatus(uint64_t /*id*/) const
{
return im::MessageStatus::UNKNOWN;
}
virtual bool cancelMessage(uint64_t /*id*/) { return false; }
virtual bool setPushNotificationToken(const std::string& pushDeviceToken = "")
{
std::lock_guard lock(configurationMutex_);
if (config_ && config_->deviceKey != pushDeviceToken) {
config_->deviceKey = pushDeviceToken;
saveConfig();
return true;
}
return false;
}
virtual bool setPushNotificationTopic(const std::string& topic = "")
{
std::lock_guard lock(configurationMutex_);
if (config_ && config_->notificationTopic != topic) {
config_->notificationTopic = topic;
saveConfig();
return true;
}
return false;
}
virtual bool setPushNotificationConfig(const std::map<std::string, std::string>& data);
/**
* Tell if the account is enable or not.
* @return true if enabled, false otherwise
*/
bool isEnabled() const { return config().enabled; }
void setEnabled(bool enable)
{
config_->enabled = enable;
// Update the UPnP controller to make sure it's in the correct state since this
// depends on whether the account is enabled or not (in particular, we don't want
// disabled accounts to generate UPnP activity).
updateUpnpController();
}
/**
* Tell if the account is activated
* (can currently be used).
*/
bool isActive() const noexcept { return active_; }
void setActive(bool active) noexcept { active_ = active; }
bool isUsable() const { return config().enabled and active_; }
void enableVideo(bool enable)
{
editConfig([&](AccountConfig& config) { config.videoEnabled = enable; });
}
bool isVideoEnabled() const { return config().videoEnabled; }
/**
* Set the registration state of the specified link
* @param state The registration state of underlying VoIPLink
*/
virtual void setRegistrationState(RegistrationState state,
int detail_code = 0,
const std::string& detail_str = {});
const std::string& getUsername() const { return config().username; }
const std::string& getHostname() const { return config().hostname; }
const std::string& getAlias() const { return config().alias; }
static std::vector<unsigned> getDefaultCodecsId();
static std::map<std::string, std::string> getDefaultCodecDetails(const unsigned& codecId);
/* Accessor to data structures
* @return The list that reflects the user's choice
*/
std::vector<unsigned> getActiveCodecs(MediaType mediaType = MEDIA_ALL) const;
bool hasActiveCodec(MediaType mediaType) const;
/**
* Update both the codec order structure and the codec string used for
* SDP offer and configuration respectively
*/
virtual void setActiveCodecs(const std::vector<unsigned>& list);
std::shared_ptr<SystemCodecInfo> searchCodecById(unsigned codecId, MediaType mediaType);
std::vector<std::shared_ptr<SystemCodecInfo>> getActiveAccountCodecInfoList(
MediaType mediaType) const;
std::shared_ptr<SystemCodecInfo> searchCodecByPayload(unsigned payload, MediaType mediaType);
std::filesystem::path getRingtonePath() const { return ringtonePath_; }
bool getRingtoneEnabled() const { return config().ringtoneEnabled; }
std::string getDisplayName() const { return config().displayName; }
std::string getMailBox() const { return config().mailbox; }
bool isRendezVous() const { return config().isRendezVous; }
bool isAutoAnswerEnabled() const { return config().autoAnswerEnabled; }
bool isReadReceiptEnabled() const { return config().sendReadReceipt; }
bool isComposingEnabled() const { return config().sendComposing; }
/**
* returns whether or not UPnP is enabled and active
* ie: if it is able to make port mappings
*/
bool getUPnPActive() const;
/**
* Get the UPnP IP (external router) address.
* If use UPnP is set to false, the address will be empty.
*/
dhtnet::IpAddr getUPnPIpAddress() const;
/**
* Random generator engine
* Logical account state shall never rely on the state of the random generator.
*/
mutable std::mt19937_64 rand;
/**
* Inform the account that the network status has changed.
*/
virtual void connectivityChanged() {};
virtual bool handleMessage(const std::string& /*from*/,
const std::pair<std::string, std::string>& /*message*/)
{
return false;
};
/**
* Helper function used to load the default codec order from the codec factory
*/
void loadDefaultCodecs();
void setCodecActive(unsigned codecId);
void setCodecInactive(unsigned codecId);
/**
* Get the user-agent
*/
const std::string& getUserAgentName();
std::set<std::string> getDefaultModerators() const { return config().defaultModerators; }
void addDefaultModerator(const std::string& peerURI);
void removeDefaultModerator(const std::string& peerURI);
bool isLocalModeratorsEnabled() const { return config().localModeratorsEnabled; }
bool isAllModerators() const { return config().allModeratorsEnabled; }
// Enable/disable ICE for media
bool isIceForMediaEnabled() const { return iceForMediaEnabled_; }
void enableIceForMedia(bool enable) { iceForMediaEnabled_ = enable; }
// Enable/disable generation of empty offers
bool isEmptyOffersEnabled() const { return false; }
// Check if a Daemon version (typically peer's version) satisfies the
// minimum required version. This check is typically used to disable a
// feature if it's not backward compatible with the peer's version.
static bool meetMinimumRequiredVersion(const std::vector<unsigned>& jamiVersion,
const std::vector<unsigned>& minRequiredVersion);
// Enable/disable compliancy with RFC-5245 for component IDs format.
// The ICE component IDs are enumerated relative to the SDP session,
// i.e., starts from 1 and incremented for each component.
// However, RFC-5245 requires that the ICE component IDs are enumerated
// relative to the media stream, e.g., component IDs 1 and 2 for audio,
// and component IDs 1 and 2 for video. This non-conformity can cause
// inter-operability issues.
// When the compliancy feature is enabled, the component ID in the
// generated SDP will be compliant to RFC-5245. This feature should be
// enabled only when the peer is compliant to RFC-5245 as well.
// The current version is able to correctly parse both formats.
// This feature is needed for backward compatiblity, and should be removed
// once the backward compatibility is no more required.
bool isIceCompIdRfc5245Compliant() const { return iceCompIdRfc5245Compliant_; }
void enableIceCompIdRfc5245Compliance(bool enable) { iceCompIdRfc5245Compliant_ = enable; }
void enableAutoLoadConversations(bool enable) { autoLoadConversations_ = enable; }
std::shared_ptr<Call> getCall(const std::string& callId) const
{
return callSet_.getCall(callId);
}
std::vector<std::string> getCallList() const { return callSet_.getCallIds(); }
std::shared_ptr<Conference> getConference(const std::string& confId) const
{
return callSet_.getConference(confId);
}
std::vector<std::string> getConferenceList() const { return callSet_.getConferenceIds(); }
void attach(const std::shared_ptr<Call>& call) { callSet_.add(call); }
bool detach(const std::shared_ptr<Call>& call) { return callSet_.remove(call); }
void attach(const std::shared_ptr<Conference>& conf) { callSet_.add(conf); }
bool removeConference(const std::string& confId)
{
auto result = callSet_.removeConference(confId);
if (result)
emitSignal<libjami::CallSignal::ConferenceRemoved>(getAccountID(), confId);
return result;
}
public:
// virtual methods that has to be implemented by concrete classes
/**
* This method is called to request removal of possible account traces on the system,
* like internal account setup files.
*/
virtual void flush() {/* nothing to do here - overload */};
private:
NON_COPYABLE(Account);
/**
* Set of calls attached to the account.
*/
CallSet callSet_;
protected:
virtual void updateUpnpController();
std::unique_ptr<AccountConfig> config_ {};
friend class ConfigurationTest;
static const std::string DEFAULT_USER_AGENT;
static std::string mapStateNumberToString(RegistrationState state);
/**
* Build the user-agent string
*/
static std::string getDefaultUserAgent();
/**
* Account ID are assign in constructor and shall not changed
*/
const std::string accountID_;
mutable std::recursive_mutex configurationMutex_ {};
/**
* Tells if the account is active now.
* This allows doRegister to be called.
* When an account is unactivated, doUnregister must be called.
*/
bool active_ {true};
/*
* The general, protocol neutral registration
* state of the account
*/
RegistrationState registrationState_ {RegistrationState::UNLOADED};
/**
* Vector containing all system codecs (with default parameters)
*/
std::shared_ptr<SystemCodecContainer> systemCodecContainer_;
/**
* Vector containing all account codecs (set of system codecs with custom parameters)
*/
std::vector<std::shared_ptr<SystemCodecInfo>> accountCodecInfoList_;
/**
* Ringtone .au file used for this account
*/
std::filesystem::path ringtonePath_;
/**
* UPnP IGD controller and the mutex to access it
*/
mutable std::mutex upnp_mtx {};
std::shared_ptr<dhtnet::upnp::Controller> upnpCtrl_;
bool iceForMediaEnabled_ {true};
bool iceCompIdRfc5245Compliant_ {false};
/**
* Auto load conversations when creatinf convModule()
*/
bool autoLoadConversations_ {true};
/**
* private account codec searching functions
*/
std::shared_ptr<SystemCodecInfo> searchCodecByName(const std::string& name, MediaType mediaType);
std::vector<unsigned> getAccountCodecInfoIdList(MediaType mediaType) const;
void setAllCodecsActive(MediaType mediaType, bool active);
void sortCodec();
};
static inline std::ostream&
operator<<(std::ostream& os, const Account& acc)
{
os << "[Account " << acc.getAccountID() << "] ";
return os;
}
} // namespace jami
| 16,956
|
C++
|
.h
| 426
| 33.577465
| 126
| 0.672932
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,891
|
gittransport.h
|
savoirfairelinux_jami-daemon/src/gittransport.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <memory>
#include <string>
#include <string_view>
#include <algorithm>
#include <git2/remote.h>
#include <git2/sys/transport.h>
#include <git2/errors.h>
#include <git2.h>
namespace jami {
class Manager;
} // namespace jami
namespace dhtnet {
class ChannelSocket;
} // namespace dhtnet
// NOTE: THIS MUST BE IN THE ROOT NAMESPACE FOR LIBGIT2
struct P2PStream
{
git_smart_subtransport_stream base;
std::weak_ptr<dhtnet::ChannelSocket> socket;
std::string cmd {};
std::string url {};
unsigned sent_command : 1;
};
struct P2PSubTransport
{
git_smart_subtransport base;
std::unique_ptr<P2PStream> stream;
git_remote* remote;
};
using namespace std::string_view_literals;
constexpr auto UPLOAD_PACK_CMD = "git-upload-pack"sv;
constexpr auto HOST_TAG = "host="sv;
/*
* Create a git protocol request.
*
* For example: 0029git-upload-pack conversation\0host=device\0
* @param buf The buffer to fill
* @param cmd The wanted command
* @param url The repository's URL
* @return 0 on success, - 1 on error
*/
int generateRequest(git_buf* request, const std::string& cmd, const std::string_view& url);
/**
* Send a git command on the linked socket
* @param s Related stream
* @return 0 on success
*/
int sendCmd(P2PStream* s);
/**
* Read on a channel socket
* @param stream Related stream
* @param buffer Buffer to fill
* @param buflen Maximum buffer size
* @param read Number of bytes read
* @return 0 on success
*/
int P2PStreamRead(git_smart_subtransport_stream* stream, char* buffer, size_t buflen, size_t* read);
int P2PStreamWrite(git_smart_subtransport_stream* stream, const char* buffer, size_t len);
/**
* Free resources used by the stream
*/
void P2PStreamFree(git_smart_subtransport_stream* stream);
/**
* Handles git actions
* @param out Subtransport's stream created or used by the action
* @param transport Subtransport created or used by the action
* @param url 'deviceId/conversationId'
* @param action Action to perform
* @return 0 on success
*/
int P2PSubTransportAction(git_smart_subtransport_stream** out,
git_smart_subtransport* transport,
const char* url,
git_smart_service_t action);
/**
* Close a subtransport
* Because we use a channel socket, we need to do nothing here.
* Will be shutdown by the rest of the code
*/
int P2PSubTransportClose(git_smart_subtransport*);
/**
* Free resources used by a transport
* @param transport Transport to free
*/
void P2PSubTransportFree(git_smart_subtransport* transport);
/**
* Create a new subtransport
* @param out The new subtransport
* @param owner The transport owning this subtransport
* @param payload The remote
* @return 0 on success
*/
int P2PSubTransportNew(P2PSubTransport** out, git_transport* owner, void* payload);
/**
* Setup the subtransport callback
* @param out Subtransport created
* @param owner Transport owning the sub transport
* @param param The remote
* @param 0 on success
*/
int p2p_subtransport_cb(git_smart_subtransport** out, git_transport* owner, void* payload);
/**
* Setup the transport callback
* @param out Transport created
* @param owner Remote wanted
* @param 0 on success
*/
int p2p_transport_cb(git_transport** out, git_remote* owner, void* param);
| 4,166
|
C++
|
.h
| 125
| 30.768
| 100
| 0.718618
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,892
|
archiver.h
|
savoirfairelinux_jami-daemon/src/archiver.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "noncopyable.h"
#include <cstdint>
#include <string>
#include <vector>
#include <map>
#include <functional>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H
typedef struct gzFile_s* gzFile;
namespace jami {
/**
* Archiver is used to generate/read encrypted archives
*/
namespace archiver {
using FileMatchPair = std::function<std::pair<bool, std::string_view>(std::string_view)>;
/**
* Compress a STL string using zlib with given compression level and return
* the binary data.
*/
std::vector<uint8_t> compress(const std::string& str);
/**
* Decompress an STL string using zlib and return the original data.
*/
std::vector<uint8_t> decompress(const std::vector<uint8_t>& dat);
/**
* Compress string to a Gzip file
*/
void compressGzip(const std::string& str, const std::string& path);
void compressGzip(const std::vector<uint8_t>& dat, const std::string& path);
/**
* Decompress Gzip file to bytes
*/
std::vector<uint8_t> decompressGzip(const std::string& path);
/**
* Open Gzip file (uses wide string version of gzopen on windows)
*/
gzFile openGzip(const std::string& path, const char* mode);
/**
* @brief uncompressArchive Uncompresses an archive and puts the different files
* in dir folder according to a FileMatchPair f
* @param path
* @param dir
* @param f takes a filename relative path inside the archive like mysubfolder/myfile
* and returns a pair (bool, new filename relative path)
* Where the bool indicates if we should uncompress this file
* and the new filename relative path puts the file in the directory dir under a different
* relative path name like mynewsubfolder/myfile
* @return void
*/
void uncompressArchive(const std::string& path, const std::string& dir, const FileMatchPair& f);
/**
* @brief readFileFromArchive read a file from an archive without uncompressing
* the whole archive
* @param path archive path
* @param fileRelativePathName file path relative path name in the archive
* E.g: data/myfile.txt inside the archive
* @return fileContent std::vector<uint8_t> that contains the file content
*/
std::vector<uint8_t> readFileFromArchive(const std::string& path,
const std::string& fileRelativePathName);
/**
* @brief listFilesFromArchive list all files from an archive
* @param path archive path
* @return std::vector<std::string> that contains all files relative path names
*/
std::vector<std::string> listFilesFromArchive(const std::string& path);
} // namespace archiver
} // namespace jami
| 3,276
|
C++
|
.h
| 86
| 35.848837
| 96
| 0.750158
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,893
|
preferences.h
|
savoirfairelinux_jami-daemon/src/preferences.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __PREFERENCE_H__
#define __PREFERENCE_H__
#include "config/serializable.h"
#include "client/ring_signal.h"
#include <string>
#include <map>
#include <set>
#include <vector>
namespace YAML {
class Emitter;
class Node;
} // namespace YAML
extern "C" {
struct pjsip_msg;
}
namespace jami {
class AudioLayer;
class Preferences : public Serializable
{
public:
static const char* const DFT_ZONE;
static const char* const REGISTRATION_EXPIRE_KEY;
Preferences();
void serialize(YAML::Emitter& out) const override;
void unserialize(const YAML::Node& in) override;
const std::string& getAccountOrder() const { return accountOrder_; }
// flush invalid accountIDs from account order
void verifyAccountOrder(const std::vector<std::string>& accounts);
void addAccount(const std::string& acc);
void removeAccount(const std::string& acc);
void setAccountOrder(const std::string& ord) { accountOrder_ = ord; }
int getHistoryLimit() const { return historyLimit_; }
void setHistoryLimit(int lim) { historyLimit_ = lim; }
int getRingingTimeout() const { return ringingTimeout_; }
void setRingingTimeout(int timeout) { ringingTimeout_ = timeout; }
int getHistoryMaxCalls() const { return historyMaxCalls_; }
void setHistoryMaxCalls(int max) { historyMaxCalls_ = max; }
std::string getZoneToneChoice() const { return zoneToneChoice_; }
void setZoneToneChoice(const std::string& str) { zoneToneChoice_ = str; }
int getPortNum() const { return portNum_; }
void setPortNum(int port) { portNum_ = port; }
bool getSearchBarDisplay() const { return searchBarDisplay_; }
void setSearchBarDisplay(bool search) { searchBarDisplay_ = search; }
bool getMd5Hash() const { return md5Hash_; }
void setMd5Hash(bool md5) { md5Hash_ = md5; }
private:
std::string accountOrder_;
int historyLimit_;
int historyMaxCalls_;
int ringingTimeout_;
std::string zoneToneChoice_;
int portNum_;
bool searchBarDisplay_;
bool md5Hash_;
constexpr static const char* const CONFIG_LABEL = "preferences";
};
class VoipPreference : public Serializable
{
public:
VoipPreference();
void serialize(YAML::Emitter& out) const override;
void unserialize(const YAML::Node& in) override;
bool getPlayDtmf() const { return playDtmf_; }
void setPlayDtmf(bool dtmf) { playDtmf_ = dtmf; }
bool getPlayTones() const { return playTones_; }
void setPlayTones(bool tone) { playTones_ = tone; }
int getPulseLength() const { return pulseLength_; }
void setPulseLength(int length) { pulseLength_ = length; }
private:
bool playDtmf_;
bool playTones_;
int pulseLength_;
constexpr static const char* const CONFIG_LABEL = "voipPreferences";
};
class AudioPreference : public Serializable
{
public:
AudioPreference();
AudioLayer* createAudioLayer();
static std::vector<std::string> getSupportedAudioManagers();
const std::string& getAudioApi() const { return audioApi_; }
void setAudioApi(const std::string& api) { audioApi_ = api; }
void serialize(YAML::Emitter& out) const override;
void unserialize(const YAML::Node& in) override;
// alsa preference
int getAlsaCardin() const { return alsaCardin_; }
void setAlsaCardin(int c) { alsaCardin_ = c; }
int getAlsaCardout() const { return alsaCardout_; }
void setAlsaCardout(int c) { alsaCardout_ = c; }
int getAlsaCardRingtone() const { return alsaCardRingtone_; }
void setAlsaCardRingtone(int c) { alsaCardRingtone_ = c; }
const std::string& getAlsaPlugin() const { return alsaPlugin_; }
void setAlsaPlugin(const std::string& p) { alsaPlugin_ = p; }
int getAlsaSmplrate() const { return alsaSmplrate_; }
void setAlsaSmplrate(int r) { alsaSmplrate_ = r; }
// pulseaudio preference
const std::string& getPulseDevicePlayback() const { return pulseDevicePlayback_; }
void setPulseDevicePlayback(const std::string& p) { pulseDevicePlayback_ = p; }
const std::string& getPulseDeviceRecord() const { return pulseDeviceRecord_; }
void setPulseDeviceRecord(const std::string& r) { pulseDeviceRecord_ = r; }
const std::string& getPulseDeviceRingtone() const { return pulseDeviceRingtone_; }
void setPulseDeviceRingtone(const std::string& r) { pulseDeviceRingtone_ = r; }
// portaudio preference
const std::string& getPortAudioDevicePlayback() const { return portaudioDevicePlayback_; }
void setPortAudioDevicePlayback(const std::string& p) { portaudioDevicePlayback_ = p; }
const std::string& getPortAudioDeviceRecord() const { return portaudioDeviceRecord_; }
void setPortAudioDeviceRecord(const std::string& r) { portaudioDeviceRecord_ = r; }
const std::string& getPortAudioDeviceRingtone() const { return portaudioDeviceRingtone_; }
void setPortAudioDeviceRingtone(const std::string& r) { portaudioDeviceRingtone_ = r; }
// general preference
const std::string& getRecordPath() const { return recordpath_; }
// Returns true if directory is writeable
bool setRecordPath(const std::string& r);
bool getIsAlwaysRecording() const { return alwaysRecording_; }
void setIsAlwaysRecording(bool rec) { alwaysRecording_ = rec; }
double getVolumemic() const { return volumemic_; }
void setVolumemic(double m) { volumemic_ = m; }
double getVolumespkr() const { return volumespkr_; }
void setVolumespkr(double s) { volumespkr_ = s; }
bool isAGCEnabled() const { return agcEnabled_; }
void setAGCState(bool enabled) { agcEnabled_ = enabled; }
const std::string& getNoiseReduce() const { return denoise_; }
void setNoiseReduce(const std::string& enabled) { denoise_ = enabled; }
bool getCaptureMuted() const { return captureMuted_; }
void setCaptureMuted(bool muted) { captureMuted_ = muted; }
bool getPlaybackMuted() const { return playbackMuted_; }
void setPlaybackMuted(bool muted) { playbackMuted_ = muted; }
const std::string& getAudioProcessor() const { return audioProcessor_; }
void setAudioProcessor(const std::string& ap) { audioProcessor_ = ap; }
bool getVadEnabled() const { return vadEnabled_; }
void setVad(bool enable) { vadEnabled_ = enable; }
const std::string& getEchoCanceller() const { return echoCanceller_; }
void setEchoCancel(std::string& canceller) { echoCanceller_ = canceller; }
private:
std::string audioApi_;
// alsa preference
int alsaCardin_;
int alsaCardout_;
int alsaCardRingtone_;
std::string alsaPlugin_;
int alsaSmplrate_;
// pulseaudio preference
std::string pulseDevicePlayback_;
std::string pulseDeviceRecord_;
std::string pulseDeviceRingtone_;
// portaudio preference
std::string portaudioDevicePlayback_;
std::string portaudioDeviceRecord_;
std::string portaudioDeviceRingtone_;
// general preference
std::string recordpath_;
bool alwaysRecording_;
double volumemic_;
double volumespkr_;
// audio processor preferences
std::string audioProcessor_;
std::string denoise_;
bool agcEnabled_;
bool vadEnabled_;
std::string echoCanceller_;
bool captureMuted_;
bool playbackMuted_;
constexpr static const char* const CONFIG_LABEL = "audio";
};
#ifdef ENABLE_VIDEO
class VideoPreferences : public Serializable
{
public:
VideoPreferences();
void serialize(YAML::Emitter& out) const override;
void unserialize(const YAML::Node& in) override;
bool getDecodingAccelerated() const { return decodingAccelerated_; }
bool setDecodingAccelerated(bool decodingAccelerated)
{
if (decodingAccelerated_ != decodingAccelerated) {
decodingAccelerated_ = decodingAccelerated;
emitSignal<libjami::ConfigurationSignal::HardwareDecodingChanged>(decodingAccelerated_);
return true;
}
return false;
}
bool getEncodingAccelerated() const { return encodingAccelerated_; }
bool setEncodingAccelerated(bool encodingAccelerated)
{
if (encodingAccelerated_ != encodingAccelerated) {
encodingAccelerated_ = encodingAccelerated;
emitSignal<libjami::ConfigurationSignal::HardwareEncodingChanged>(encodingAccelerated_);
return true;
}
return false;
}
bool getRecordPreview() const { return recordPreview_; }
void setRecordPreview(bool rec) { recordPreview_ = rec; }
int getRecordQuality() const { return recordQuality_; }
void setRecordQuality(int rec) { recordQuality_ = rec; }
const std::string& getConferenceResolution() const { return conferenceResolution_; }
void setConferenceResolution(const std::string& res) { conferenceResolution_ = res; }
private:
bool decodingAccelerated_;
bool encodingAccelerated_;
bool recordPreview_;
int recordQuality_;
std::string conferenceResolution_;
constexpr static const char* const CONFIG_LABEL = "video";
};
#endif // ENABLE_VIDEO
#ifdef ENABLE_PLUGIN
class PluginPreferences : public Serializable
{
public:
PluginPreferences();
void serialize(YAML::Emitter& out) const override;
void unserialize(const YAML::Node& in) override;
bool getPluginsEnabled() const { return pluginsEnabled_; }
void setPluginsEnabled(bool pluginsEnabled) { pluginsEnabled_ = pluginsEnabled; }
std::vector<std::string> getLoadedPlugins() const
{
std::vector<std::string> v(loadedPlugins_.begin(), loadedPlugins_.end());
return v;
}
std::vector<std::string> getInstalledPlugins() const
{
return std::vector<std::string>(installedPlugins_.begin(), installedPlugins_.end());
}
void saveStateLoadedPlugins(std::string plugin, bool loaded)
{
if (loaded) {
if (loadedPlugins_.find(plugin) != loadedPlugins_.end())
return;
loadedPlugins_.emplace(plugin);
} else {
auto it = loadedPlugins_.find(plugin);
if (it != loadedPlugins_.end())
loadedPlugins_.erase(it);
}
}
private:
bool pluginsEnabled_;
std::set<std::string> installedPlugins_;
std::set<std::string> loadedPlugins_;
constexpr static const char* const CONFIG_LABEL = "plugins";
};
#endif // ENABLE_PLUGIN
} // namespace jami
#endif
| 11,127
|
C++
|
.h
| 261
| 37.54023
| 100
| 0.716358
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,894
|
noncopyable.h
|
savoirfairelinux_jami-daemon/src/noncopyable.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
/**
* @file noncopyable.h
* @brief Simple macro to hide class' copy constructor and assignment operator.
* Useful to avoid shallow copying (i.e. classes with pointer members)
* Usage: For a class named MyClass, the macro call
* NON_COPYABLE(MyClass) should go in the private section of MyClass
* WARNING: Since C++11 using this macro make the class also non-movable by default!
* You shall re-implement yourself (or at least using declare with =default)
* move-constructor and move-assignable function members if they are needed.
*/
#define NON_COPYABLE(ClassName) \
ClassName(const ClassName&) = delete; \
ClassName& operator=(const ClassName&) = delete
| 1,446
|
C++
|
.h
| 30
| 46.066667
| 91
| 0.732673
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| true
| false
|
751,895
|
winsyslog.h
|
savoirfairelinux_jami-daemon/src/winsyslog.h
|
/*
* This header borrowed from Cygnus GNUwin32 project
*
* Cygwin is free software. Red Hat, Inc. licenses Cygwin to you under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; you can redistribute it and/or modify it under the terms of
* the GNU General Public License either version 3 of the license, or (at your
* option) any later version (GPLv3+), along with the additional permissions
* given below.
*
* Modified for use with functions to map syslog
* calls to EventLog calls on the windows platform
*
* much of this is not used, but here for the sake of
* error free compilation. EventLogs will most likely
* not behave as syslog does, but may be useful anyway.
* much of what syslog does can be emulated here, but
* that will have to be done later.
*/
#ifndef WINSYSLOG_H
#define WINSYSLOG_H
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
#include <windows.h>
#define WINLOG_PRIMASK 0x07
#define WINLOG_PRI(p) ((p) &WINLOG_PRIMASK)
#define WINLOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))
#define WINLOG_KERN (0 << 3)
#define WINLOG_USER (1 << 3)
#define WINLOG_MAIL (2 << 3)
#define WINLOG_DAEMON (3 << 3)
#define WINLOG_AUTH (4 << 3)
#define WINLOG_SYSLOG (5 << 3)
#define WINLOG_LPR (6 << 3)
#define WINLOG_NEWS (7 << 3)
#define WINLOG_UUCP (8 << 3)
#define WINLOG_CRON (9 << 3)
#define WINLOG_AUTHPRIV (10 << 3)
#define WINLOG_NFACILITIES 10
#define WINLOG_FACMASK 0x03f8
#define WINLOG_FAC(p) (((p) &WINLOG_FACMASK) >> 3)
#define WINLOG_MASK(pri) (1 << (pri))
#define WINLOG_UPTO(pri) ((1 << ((pri) + 1)) - 1)
/*
* Option flags for openlog.
*
* WINLOG_ODELAY no longer does anything.
* WINLOG_NDELAY is the inverse of what it used to be.
*/
#define WINLOG_PID 0x01 /* log the pid with each message */
#define WINLOG_CONS 0x02 /* log on the console if errors in sending */
#define WINLOG_ODELAY 0x04 /* delay open until first syslog() (default) */
#define WINLOG_NDELAY 0x08 /* don't delay open */
#define WINLOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */
#define WINLOG_PERROR 0x20 /* log to stderr as well */
#define strerror_r(errno, buf, len) strerror_s(buf, len, errno)
#ifdef __cplusplus
extern "C" {
#endif
extern void closelog(void);
extern void openlog(const char*, int, int);
extern void syslog(int, const char*, ...);
#ifdef __cplusplus
}
#endif
#endif
| 2,451
|
C++
|
.h
| 67
| 35.074627
| 78
| 0.707122
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,896
|
string_utils.h
|
savoirfairelinux_jami-daemon/src/string_utils.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cstdint>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <regex>
#include <iterator>
#include <charconv>
#include <string_view>
#ifdef _WIN32
#include <WTypes.h>
#endif
#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif
namespace jami {
constexpr static const char TRUE_STR[] = "true";
constexpr static const char FALSE_STR[] = "false";
constexpr static const char*
bool_to_str(bool b) noexcept
{
return b ? TRUE_STR : FALSE_STR;
}
std::string_view userAgent();
constexpr inline std::string_view
platform() {
using namespace std::literals;
#ifdef __linux__
#if defined(__ANDROID__)
return "Android"sv;
#else
return "Linux"sv;
#endif
#elif defined(_WIN32)
return "Windows"sv;
#elif defined(__APPLE__)
#if TARGET_OS_IOS
return "iOS"sv;
#else
return "macOS"sv;
#endif
#else
return "unknown"sv;
#endif
}
constexpr inline std::string_view
arch() {
using namespace std::literals;
#if defined(__x86_64__) || defined(_M_X64)
return "x86_64"sv;
#elif defined(__i386__) || defined(_M_IX86)
return "x86"sv;
#elif defined(__aarch64__) || defined(_M_ARM64)
return "arm64"sv;
#elif defined(__arm__) || defined(_M_ARM)
return "arm"sv;
#else
return "unknown"sv;
#endif
}
std::string to_string(double value);
#ifdef _WIN32
std::wstring to_wstring(const std::string& str, int codePage = CP_UTF8);
std::string to_string(const std::wstring& wstr, int codePage = CP_UTF8);
#endif
std::string to_hex_string(uint64_t id);
uint64_t from_hex_string(const std::string& str);
template<typename T>
inline T
to_int(std::string_view str, T defaultValue)
{
T result;
auto [p, ec] = std::from_chars(str.data(), str.data()+str.size(), result);
if (ec == std::errc())
return result;
else
return defaultValue;
}
template<typename T>
T
to_int(std::string_view str)
{
T result;
auto [p, ec] = std::from_chars(str.data(), str.data()+str.size(), result);
if (ec == std::errc())
return result;
if (ec == std::errc::invalid_argument)
throw std::invalid_argument("Unable to parse integer: invalid_argument");
else if (ec == std::errc::result_out_of_range)
throw std::out_of_range("Unable to parse integer: out of range");
throw std::system_error(std::make_error_code(ec));
}
static inline int
stoi(const std::string& str)
{
return std::stoi(str);
}
static inline double
stod(const std::string& str)
{
return std::stod(str);
}
template<typename... Args>
std::string concat(Args &&... args){
static_assert((std::is_constructible_v<std::string_view, Args&&> && ...));
std::string s;
s.reserve((std::string_view{ args }.size() + ...));
(s.append(std::forward<Args>(args)), ...);
return s;
}
std::string_view trim(std::string_view s);
/**
* Split a string_view with an API similar to std::getline.
* @param str The input string stream to iterate on, trimed of line during iteration.
* @param line The output substring.
* @param delim The delimiter.
* @return True if line was set, false if the end of the input was reached.
*/
inline bool
getline_full(std::string_view& str, std::string_view& line, char delim = '\n')
{
if (str.empty())
return false;
auto pos = str.find(delim);
line = str.substr(0, pos);
str.remove_prefix(pos < str.size() ? pos + 1 : str.size());
return true;
}
/**
* Similar to @getline_full but skips empty results.
*/
inline bool
getline(std::string_view& str, std::string_view& line, char delim = '\n')
{
do {
if (!getline_full(str, line, delim))
return false;
} while (line.empty());
return true;
}
inline std::vector<std::string_view>
split_string(std::string_view str, char delim)
{
std::vector<std::string_view> output;
for (auto first = str.data(), second = str.data(), last = first + str.size();
second != last && first != last;
first = second + 1) {
second = std::find(first, last, delim);
if (first != second)
output.emplace_back(first, second - first);
}
return output;
}
inline std::vector<std::string_view>
split_string(std::string_view str, std::string_view delims = " ")
{
std::vector<std::string_view> output;
for (auto first = str.data(), second = str.data(), last = first + str.size();
second != last && first != last;
first = second + 1) {
second = std::find_first_of(first, last, std::cbegin(delims), std::cend(delims));
if (first != second)
output.emplace_back(first, second - first);
}
return output;
}
std::vector<unsigned> split_string_to_unsigned(std::string_view s, char sep);
void string_replace(std::string& str, const std::string& from, const std::string& to);
std::string_view string_remove_suffix(std::string_view str, char separator);
std::string string_join(const std::set<std::string>& set, std::string_view separator = "/");
std::set<std::string> string_split_set(std::string& str, std::string_view separator = "/");
} // namespace jami
// Add string operators crucially missing from standard
// see https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/1RcShRhrmRc
namespace std {
inline string
operator+(const string& s, const string_view& sv)
{
return jami::concat(s, sv);
}
inline string
operator+(const string_view& sv, const string& s)
{
return jami::concat(sv, s);
}
using svmatch = match_results<string_view::const_iterator>;
using svsub_match = sub_match<string_view::const_iterator>;
constexpr string_view svsub_match_view(const svsub_match& submatch) noexcept {
return string_view(&*submatch.first, submatch.second - submatch.first);
}
inline bool
regex_match(string_view sv,
svmatch& m,
const regex& e,
regex_constants::match_flag_type flags = regex_constants::match_default)
{
return regex_match(sv.begin(), sv.end(), m, e, flags);
}
inline bool
regex_match(string_view sv,
const regex& e,
regex_constants::match_flag_type flags = regex_constants::match_default)
{
return regex_match(sv.begin(), sv.end(), e, flags);
}
inline bool
regex_search(string_view sv,
svmatch& m,
const regex& e,
regex_constants::match_flag_type flags = regex_constants::match_default)
{
return regex_search(sv.begin(), sv.end(), m, e, flags);
}
} // namespace std
| 7,206
|
C++
|
.h
| 231
| 27.761905
| 92
| 0.676407
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,897
|
logger.h
|
savoirfairelinux_jami-daemon/src/logger.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "jami/def.h"
//#define __STDC_FORMAT_MACROS 1
#include <fmt/core.h>
#include <fmt/format.h>
#include <fmt/chrono.h>
#include <fmt/printf.h>
#if __has_include(<fmt/std.h>)
#include <fmt/std.h>
#else
#include <fmt/ostream.h>
#endif
#include <opendht/logger.h>
#include <cinttypes> // for PRIx64
#include <cstdarg>
#include <atomic>
#include <sstream>
#include <string>
#include "string_utils.h" // to_string
#ifdef __ANDROID__
#include <android/log.h>
#define LOG_ERR ANDROID_LOG_ERROR
#define LOG_WARNING ANDROID_LOG_WARN
#define LOG_INFO ANDROID_LOG_INFO
#define LOG_DEBUG ANDROID_LOG_DEBUG
#elif defined(_WIN32)
#include "winsyslog.h"
#define LOG_ERR EVENTLOG_ERROR_TYPE
#define LOG_WARNING EVENTLOG_WARNING_TYPE
#define LOG_INFO EVENTLOG_INFORMATION_TYPE
#define LOG_DEBUG EVENTLOG_SUCCESS
#else
#include <syslog.h> // Defines LOG_XXXX
#endif /* __ANDROID__ / _WIN32 */
#if defined(_WIN32) && !defined(_MSC_VER)
#define PRINTF_ATTRIBUTE(a, b) __attribute__((format(gnu_printf, a, b)))
#elif defined(__GNUC__)
#define PRINTF_ATTRIBUTE(a, b) __attribute__((format(printf, a, b)))
#else
#define PRINTF_ATTRIBUTE(a, b)
#endif
namespace jami {
/**
* Thread-safe function to print the stringified contents of errno
*/
void strErr();
///
/// Level-driven logging class that support printf and C++ stream logging fashions.
///
class Logger
{
public:
class Handler;
struct Msg;
Logger(int level, const char* file, int line, bool linefeed)
: level_ {level}
, file_ {file}
, line_ {line}
, linefeed_ {linefeed}
{}
Logger() = delete;
Logger(const Logger&) = delete;
Logger(Logger&&) = default;
~Logger() { log(level_, file_, line_, linefeed_, "%s", os_.str().c_str()); }
template<typename T>
inline Logger& operator<<(const T& value)
{
os_ << value;
return *this;
}
constexpr static int dhtLevel(dht::log::LogLevel level) {
switch (level) {
case dht::log::LogLevel::debug:
return LOG_DEBUG;
case dht::log::LogLevel::warning:
return LOG_WARNING;
case dht::log::LogLevel::error:
default:
return LOG_ERR;
}
}
LIBJAMI_PUBLIC
static void write(int level, const char* file, int line, std::string&& message);
static inline void writeDht(dht::log::LogLevel level, std::string&& message) {
write(dhtLevel(level), nullptr, 0, std::move(message));
}
static inline std::shared_ptr<dht::log::Logger> dhtLogger() {
return std::make_shared<dht::Logger>(&Logger::writeDht);
}
///
/// Printf fashion logging.
///
/// Example: JAMI_DBG("%s", "Hello, World!")
///
LIBJAMI_PUBLIC
static void log(int level, const char* file, int line, bool linefeed, const char* const fmt, ...)
PRINTF_ATTRIBUTE(5, 6);
///
/// Printf fashion logging (using va_list parameters)
///
LIBJAMI_PUBLIC
static void vlog(int level, const char* file, int line, bool linefeed, const char* fmt, va_list);
static void setConsoleLog(bool enable);
static void setSysLog(bool enable);
static void setMonitorLog(bool enable);
static void setFileLog(const std::string& path);
static void setDebugMode(bool enable);
static bool debugEnabled();
static void fini();
///
/// Stream fashion logging.
///
/// Example: JAMI_DBG() << "Hello, World!"
///
static Logger log(int level, const char* file, int line, bool linefeed)
{
return {level, file, line, linefeed};
}
private:
int level_; ///< LOG_XXXX values
const char* const file_; ///< contextual filename (printed as header)
const int line_; ///< contextual line number (printed as header)
bool linefeed_ {
true}; ///< true if a '\n' (or any platform equivalent) has to be put at line end in consoleMode
std::ostringstream os_; ///< string stream used with C++ stream style (stream operator<<)
};
namespace log {
template<typename S, typename... Args>
void info(const char* file, int line, S&& format, Args&&... args) {
Logger::write(LOG_INFO, file, line, fmt::format(std::forward<S>(format), std::forward<Args>(args)...));
}
template<typename S, typename... Args>
void dbg(const char* file, int line, S&& format, Args&&... args) {
Logger::write(LOG_DEBUG, file, line, fmt::format(std::forward<S>(format), std::forward<Args>(args)...));
}
template<typename S, typename... Args>
void warn(const char* file, int line, S&& format, Args&&... args) {
Logger::write(LOG_WARNING, file, line, fmt::format(std::forward<S>(format), std::forward<Args>(args)...));
}
template<typename S, typename... Args>
void error(const char* file, int line, S&& format, Args&&... args) {
Logger::write(LOG_ERR, file, line, fmt::format(std::forward<S>(format), std::forward<Args>(args)...));
}
}
// We need to use macros for contextual information
#define JAMI_INFO(...) ::jami::Logger::log(LOG_INFO, __FILE__, __LINE__, true, ##__VA_ARGS__)
#define JAMI_DBG(...) ::jami::Logger::log(LOG_DEBUG, __FILE__, __LINE__, true, ##__VA_ARGS__)
#define JAMI_WARN(...) ::jami::Logger::log(LOG_WARNING, __FILE__, __LINE__, true, ##__VA_ARGS__)
#define JAMI_ERR(...) ::jami::Logger::log(LOG_ERR, __FILE__, __LINE__, true, ##__VA_ARGS__)
#define JAMI_XINFO(...) ::jami::Logger::log(LOG_INFO, __FILE__, __LINE__, false, ##__VA_ARGS__)
#define JAMI_XDBG(...) ::jami::Logger::log(LOG_DEBUG, __FILE__, __LINE__, false, ##__VA_ARGS__)
#define JAMI_XWARN(...) ::jami::Logger::log(LOG_WARNING, __FILE__, __LINE__, false, ##__VA_ARGS__)
#define JAMI_XERR(...) ::jami::Logger::log(LOG_ERR, __FILE__, __LINE__, false, ##__VA_ARGS__)
#define JAMI_LOG(formatstr, ...) ::jami::log::info(__FILE__, __LINE__, FMT_STRING(formatstr), ##__VA_ARGS__)
#define JAMI_DEBUG(formatstr, ...) if(::jami::Logger::debugEnabled()) { ::jami::log::dbg(__FILE__, __LINE__, FMT_STRING(formatstr), ##__VA_ARGS__); }
#define JAMI_WARNING(formatstr, ...) ::jami::log::warn(__FILE__, __LINE__, FMT_STRING(formatstr), ##__VA_ARGS__)
#define JAMI_ERROR(formatstr, ...) ::jami::log::error(__FILE__, __LINE__, FMT_STRING(formatstr), ##__VA_ARGS__)
} // namespace jami
| 6,995
|
C++
|
.h
| 174
| 36.574713
| 149
| 0.653443
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,898
|
manager.h
|
savoirfairelinux_jami-daemon/src/manager.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "account_factory.h"
#include "call_factory.h"
#include "preferences.h"
#include "media/audio/audiolayer.h"
#include "scheduled_executor.h"
#include "gittransport.h"
#include <dhtnet/certstore.h>
#include <algorithm>
#include <atomic>
#include <functional>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "trace-tools.h"
namespace asio {
class io_context;
}
namespace dhtnet {
class ChannelSocket;
class IceTransportFactory;
} // namespace dhtnet
namespace jami {
namespace video {
class SinkClient;
class VideoGenerator;
} // namespace video
class RingBufferPool;
struct VideoManager;
class Conference;
class AudioLoop;
class JamiAccount;
class SIPVoIPLink;
class JamiPluginManager;
/** Manager (controller) of daemon */
// TODO LIBJAMI_PUBLIC only if tests
class LIBJAMI_TESTABLE Manager
{
private:
std::mt19937_64 rand_;
public:
// TODO LIBJAMI_PUBLIC only if tests
static LIBJAMI_TESTABLE Manager& instance();
void setAutoAnswer(bool enable);
/**
* General preferences configuration
*/
Preferences preferences;
/**
* Voip related preferences
*/
VoipPreference voipPreferences;
/**
* Audio preferences
*/
AudioPreference audioPreference;
#ifdef ENABLE_PLUGIN
/**
* Plugin preferences
*/
PluginPreferences pluginPreferences;
#endif
#ifdef ENABLE_VIDEO
/**
* Video preferences
*/
VideoPreferences videoPreferences;
#endif
// Manager should not be accessed until initialized.
// FIXME this is an evil hack!
static std::atomic_bool initialized;
#if TARGET_OS_IOS
static bool isIOSExtension;
#endif
static bool syncOnRegister;
static bool autoLoad;
/**
* Initialisation of thread (sound) and map.
* Init a new VoIPLink, audio codec and audio driver.
*/
void init(const std::filesystem::path& config_file, libjami::InitFlag flags);
/*
* Terminate all threads and exit DBus loop
*/
void finish() noexcept;
void monitor(bool continuous);
std::vector<std::map<std::string, std::string>> getConnectionList(
const std::string& accountId, const std::string& conversationId);
std::vector<std::map<std::string, std::string>> getChannelList(const std::string& accountId,
const std::string& connectionId);
/**
* Accessor to audiodriver.
* it's multi-thread and use mutex internally
* @return AudioLayer* The audio layer object
*/
std::shared_ptr<AudioLayer> getAudioDriver();
inline std::unique_ptr<AudioDeviceGuard> startAudioStream(AudioDeviceType stream)
{
return std::make_unique<AudioDeviceGuard>(*this, stream);
}
/**
* Place a new call
* @param accountId the user's account ID
* @param callee the callee's ID/URI. Depends on the account type.
* Refer to placeCall/placeCallWithMedia documentations.
* @param mediaList a list of media to include
* @return the call ID on success, empty string otherwise
*/
std::string outgoingCall(const std::string& accountId,
const std::string& callee,
const std::vector<libjami::MediaMap>& mediaList = {});
/**
* Functions which occur with a user's action
* Answer the call
* @param callId
*/
bool answerCall(const std::string& accountId,
const std::string& callId,
const std::vector<libjami::MediaMap>& mediaList = {});
bool answerCall(Call& call, const std::vector<libjami::MediaMap>& mediaList = {});
/**
* Handle incoming call and notify user
* @param accountId an account id
* @param call A call pointer
*/
void incomingCall(const std::string& accountId, Call& call);
/**
* Functions which occur with a user's action
* Hangup the call
* @param accountId
* @param callId The call identifier
*/
bool hangupCall(const std::string& accountId, const std::string& callId);
/**
* Functions which occur with a user's action
* Hangup the conference (hangup every participants)
* @param id The call identifier
*/
bool hangupConference(const std::string& accountId, const std::string& confId);
/**
* Functions which occur with a user's action
* Put the call on hold
* @param accountId
* @param callId The call identifier
*/
bool onHoldCall(const std::string& accountId, const std::string& callId);
/**
* Functions which occur with a user's action
* Put the call off hold
* @param accountId
* @param id The call identifier
*/
bool offHoldCall(const std::string& accountId, const std::string& callId);
/**
* Functions which occur with a user's action
* Transfer the call
* @param id The call identifier
* @param to The recipient of the transfer
*/
bool transferCall(const std::string& accountId, const std::string& id, const std::string& to);
/**
* Notify the client the transfer is successful
*/
void transferSucceeded();
/**
* Notify the client that the transfer failed
*/
void transferFailed();
/**
* Functions which occur with a user's action
* Refuse the call
* @param id The call identifier
*/
bool refuseCall(const std::string& accountId, const std::string& id);
/**
* Hold every participant to a conference
* @param the conference id
*/
bool holdConference(const std::string& accountId, const std::string& confId);
/**
* Unhold all conference participants
* @param the conference id
*/
bool unHoldConference(const std::string& accountId, const std::string& confId);
/**
* Add a subcall to a conference
* @param the call id
* @param the conference id
*/
bool addSubCall(const std::string& accountId,
const std::string& callId,
const std::string& account2Id,
const std::string& confId);
bool addSubCall(Call& call, Conference& conference);
void bindCallToConference(Call& call, Conference& conf);
/**
* Bind the main participant to a conference (mainly called on a double click action)
* @param the conference id
*/
bool addMainParticipant(const std::string& accountId, const std::string& confId);
/**
* Join two participants to create a conference
* @param the fist call id
* @param the second call id
*/
bool joinParticipant(const std::string& accountId,
const std::string& callId1,
const std::string& account2Id,
const std::string& callId2,
bool attached = true);
/**
* Create a conference from a list of participant
* @param A vector containing the list of participant
*/
void createConfFromParticipantList(const std::string& accountId,
const std::vector<std::string>&);
/**
* Detach a participant from a conference, put the call on hold, do not hangup it
* @param call id
* @param the current call id
*/
bool detachParticipant(const std::string& callId);
/**
* Detach the local participant from curent conference.
* Remote participants are placed in hold.
*/
bool detachHost(const std::shared_ptr<Conference>& conf = {});
/**
* Remove the conference participant from a conference
* @param call id
*/
void removeParticipant(Call& call);
/**
* Join two conference together into one unique conference
*/
bool joinConference(const std::string& accountId,
const std::string& confId1,
const std::string& account2Id,
const std::string& confId2);
void addAudio(Call& call);
void removeAudio(Call& call);
/**
* Save config to file
*/
void saveConfig();
void saveConfig(const std::shared_ptr<Account>& acc);
/**
* Play a ringtone
*/
void playTone();
/**
* Play a special ringtone ( BUSY ) if there's at least one message on the voice mail
*/
void playToneWithMessage();
/**
* Acts on the audio streams and audio files
*/
void stopTone();
/**
* Notify the user that the recipient of the call has answered and the put the
* call in Current state
* @param id The call identifier
*/
void peerAnsweredCall(Call& call);
/**
* Rings back because the outgoing call is ringing and the put the
* call in Ringing state
* @param id The call identifier
*/
void peerRingingCall(Call& call);
/**
* Put the call in Hungup state, remove the call from the list
* @param id The call identifier
*/
void peerHungupCall(Call& call);
/**
* Notify the client with an incoming message
* @param accountId The account identifier
* @param callId The call to send the message
* @param messages A map if mime type as key and mime payload as value
*/
void incomingMessage(const std::string& accountId,
const std::string& callId,
const std::string& from,
const std::map<std::string, std::string>& messages);
/**
* Send a new text message to the call, if participate to a conference, send to all participant.
* @param accountId
* @param callId The call to send the message
* @param message A list of pair of mime types and payloads
* @param from The sender of this message (could be another participant of a conference)
*/
void sendCallTextMessage(const std::string& accountId,
const std::string& callID,
const std::map<std::string, std::string>& messages,
const std::string& from,
bool isMixed);
/**
* ConfigurationManager - Send registration request
* @param accountId The account to register/unregister
* @param enable The flag for the type of registration
* false for unregistration request
* true for registration request
*/
void sendRegister(const std::string& accountId, bool enable);
uint64_t sendTextMessage(const std::string& accountID,
const std::string& to,
const std::map<std::string, std::string>& payloads,
bool fromPlugin = false,
bool onlyConnected = false);
int getMessageStatus(uint64_t id) const;
int getMessageStatus(const std::string& accountID, uint64_t id) const;
/**
* Get account list
* @return std::vector<std::string> A list of accoundIDs
*/
std::vector<std::string> getAccountList() const;
/**
* Set the account order in the config file
*/
void setAccountsOrder(const std::string& order);
/**
* Retrieve details about a given account
* @param accountID The account identifier
* @return std::map< std::string, std::string > The account details
*/
std::map<std::string, std::string> getAccountDetails(const std::string& accountID) const;
/**
* Retrieve volatile details such as recent registration errors
* @param accountID The account identifier
* @return std::map< std::string, std::string > The account volatile details
*/
std::map<std::string, std::string> getVolatileAccountDetails(const std::string& accountID) const;
/**
* Get list of calls (internal subcalls are filter-out)
* @return std::vector<std::string> A list of call IDs (without subcalls)
*/
std::vector<std::string> getCallList() const;
/**
* Save the details of an existing account, given the account ID
* This will load the configuration map with the given data.
* It will also register/unregister links where the 'Enabled' switched.
* @param accountID The account identifier
* @param details The account parameters
*/
void setAccountDetails(const std::string& accountID,
const std::map<std::string, std::string>& details);
void setAccountActive(const std::string& accountID,
bool active,
bool shutdownConnections);
void loadAccountAndConversation(const std::string& accountId,
bool loadAll,
const std::string& convId);
std::mt19937_64 getSeededRandomEngine();
/**
* Return a new random accountid that is not present in the list
* @return A brand new accountid
*/
std::string getNewAccountId();
/**
* Add a new account, and give it a new account ID automatically
* @param details The new account parameters
* @param accountId optionnal predetermined accountid to use
* @return The account Id given to the new account
*/
std::string addAccount(const std::map<std::string, std::string>& details,
const std::string& accountId = {});
/**
* Delete an existing account, unregister VoIPLink associated, and
* purge from configuration.
* If 'flush' argument is true, filesystem entries are also removed.
* @param accountID The account unique ID
*/
void removeAccount(const std::string& accountID, bool flush = false);
void removeAccounts();
/**
* Set input audio plugin
* @param audioPlugin The audio plugin
*/
void setAudioPlugin(const std::string& audioPlugin);
/**
* Set audio device
* @param index The index of the soundcard
* @param the type of stream, either PLAYBACK, CAPTURE, RINGTONE
*/
void setAudioDevice(int index, AudioDeviceType streamType);
void startAudio();
/**
* Get list of supported audio output device
* @return std::vector<std::string> A list of the audio devices supporting playback
*/
std::vector<std::string> getAudioOutputDeviceList();
/**
* Get list of supported audio input device
* @return std::vector<std::string> A list of the audio devices supporting capture
*/
std::vector<std::string> getAudioInputDeviceList();
/**
* Get string array representing integer indexes of output, input, and ringtone device
* @return std::vector<std::string> A list of the current audio devices
*/
std::vector<std::string> getCurrentAudioDevicesIndex();
/**
* Get index of an audio device
* @param name The string description of an audio device
* @return int His index
*/
int getAudioInputDeviceIndex(const std::string& name);
int getAudioOutputDeviceIndex(const std::string& name);
/**
* Get current alsa plugin
* @return std::string The Alsa plugin
*/
std::string getCurrentAudioOutputPlugin() const;
/**
* Get the noise reduction engine state from
* the current audio layer.
*/
std::string getNoiseSuppressState() const;
/**
* Set the noise reduction engine state in the current
* audio layer.
*/
void setNoiseSuppressState(const std::string& state);
bool isAGCEnabled() const;
void setAGCState(bool enabled);
/**
* Get is always recording functionality
*/
bool getIsAlwaysRecording() const;
/**
* Set is always recording functionality, every calls will then be set in RECORDING mode
* once answered
*/
void setIsAlwaysRecording(bool isAlwaysRec);
/**
* Set recording on / off
* Start recording
* @param id The call identifier
* Returns true if the call was set to record
*/
bool toggleRecordingCall(const std::string& accountId, const std::string& id);
/**
* Start playback fo a recorded file if and only if audio layer is not already started.
* @param File path of the file to play
*/
bool startRecordedFilePlayback(const std::string&);
void recordingPlaybackSeek(const double value);
/**
* Stop playback of recorded file
*/
void stopRecordedFilePlayback();
/**
* Set the maximum number of days to keep in the history
* @param calls The number of days
*/
void setHistoryLimit(int days);
/**
* Get the maximum number of days to keep in the history
* @return double The number of days
*/
int getHistoryLimit() const;
/**
* Set ringing timeout (number of seconds after which a call will
* enter BUSY state if not answered).
* @param timeout in seconds
*/
void setRingingTimeout(int timeout);
/**
* Get ringing timeout (number of seconds after which a call will
* enter BUSY state if not answered).
* @return timeout in seconds
*/
int getRingingTimeout() const;
/**
* Get the audio manager
* @return int The audio manager
* "alsa"
* "pulseaudio"
*/
std::string getAudioManager() const;
/**
* Set the audio manager
* @return true if api is now in use, false otherwise
*/
bool setAudioManager(const std::string& api);
/**
* Callback called when the audio layer initialised with its
* preferred format.
*/
AudioFormat hardwareAudioFormatChanged(AudioFormat format);
/**
* Should be called by any component dealing with an external
* audio source, indicating the format used so the mixer format
* can be eventually adapted.
* @returns the new format used by the main buffer.
*/
AudioFormat audioFormatUsed(AudioFormat format);
/**
* Handle audio sounds heard by a caller while they wait for their
* connection to a called party to be completed.
*/
void ringback();
/**
* Handle played music when an incoming call occurs
*/
void playRingtone(const std::string& accountID);
/**
* Handle played music when a congestion occurs
*/
void congestion();
/**
* Play the dtmf-associated sound
* @param code The pressed key
*/
void playDtmf(char code);
/**
* Handle played sound when a call is unable to be completed because of a busy recipient
*/
void callBusy(Call& call);
/**
* Handle played sound when a failure occurs
*/
void callFailure(Call& call);
/**
* Retrieve the current telephone tone
* @return AudioLoop* The audio tone or 0 if no tone (init before calling this function)
*/
std::shared_ptr<AudioLoop> getTelephoneTone();
/**
* Retrieve the current telephone file
* @return AudioLoop* The audio file or 0 if the wav is stopped
*/
std::shared_ptr<AudioLoop> getTelephoneFile();
/**
* @return true is there is one or many incoming call waiting
* new call, not answered or refused
*/
bool incomingCallsWaiting();
/**
* Get the current call
* @return std::shared_ptr<Call> A call shared pointer (could be empty)
*/
std::shared_ptr<Call> getCurrentCall() const;
/**
* Get the current call id
* @return std::string The call id or ""
*/
const std::string& getCurrentCallId() const;
/**
* Check if a call is the current one
* @param call the new call
* @return bool True if the call is the current
*/
bool isCurrentCall(const Call& call) const;
/**
* Load the accounts order set by the user from the jamirc config file
* @return std::vector<std::string> A vector containing the account ID's
*/
std::vector<std::string_view> loadAccountOrder() const;
/**
* Load the account map from configuration
*/
int loadAccountMap(const YAML::Node& node);
/**
* Get the Call referred by callID. If the Call does not exist, return
* empty std::shared_ptr<Call> instance
*/
std::shared_ptr<Call> getCallFromCallID(const std::string& callID) const;
/**
* Return a pointer to the instance of the RingBufferPool
*/
RingBufferPool& getRingBufferPool();
/**
* Tell if there is a current call processed
* @return bool True if there is a current call
*/
bool hasCurrentCall() const;
/**
* Get an account pointer, looks for account of type T
* @param accountID account ID to get
* @return std::shared_ptr<Account> Shared pointer on an Account instance or nullptr if not found
*/
template<class T = Account>
inline std::shared_ptr<T> getAccount(std::string_view accountId) const
{
return accountFactory.getAccount<T>(accountId);
}
/**
* Get a list of account pointers of type T (baseclass Account)
* @return a sorted vector of all accounts of type T
*/
template<class T = Account>
std::vector<std::shared_ptr<T>> getAllAccounts() const
{
const auto& account_order = loadAccountOrder();
const auto& all_accounts = accountFactory.getAllAccounts<T>();
std::vector<std::shared_ptr<T>> accountList;
accountList.reserve(all_accounts.size());
for (const auto& id : account_order) {
if (auto acc = accountFactory.getAccount<T>(id))
accountList.emplace_back(std::move(acc));
}
for (auto& account : all_accounts) {
if (std::find(accountList.begin(), accountList.end(), account) == accountList.end())
accountList.emplace_back(std::move(account));
}
return accountList;
}
template<class T = Account>
std::size_t accountCount() const
{
return accountFactory.accountCount<T>();
}
template<class T>
inline std::shared_ptr<T> findAccount(const std::function<bool(const std::shared_ptr<T>&)>& pred)
{
for (const auto& account : getAllAccounts<T>()) {
if (pred(account))
return account;
}
return {};
}
// only used by test framework
bool hasAccount(const std::string& accountID);
/**
* Send registration for all enabled accounts
*/
void registerAccounts();
/**
* Send registration for one account
*/
void registerAccount(const std::string& accountID, const std::string& convId = {});
/**
* Send unregister for all enabled accounts
*/
void unregisterAccounts();
/**
* Create a new outgoing call
* @param toUrl Destination address
* @param accountId local account
* @param mediaList the list of medias
* @return A (shared) pointer of Call class type.
* @note This function raises VoipLinkException() on error.
*/
std::shared_ptr<Call> newOutgoingCall(std::string_view toUrl,
const std::string& accountId,
const std::vector<libjami::MediaMap>& mediaList);
CallFactory callFactory;
const std::shared_ptr<dhtnet::IceTransportFactory>& getIceTransportFactory();
std::shared_ptr<asio::io_context> ioContext() const;
std::shared_ptr<dhtnet::upnp::UPnPContext> upnpContext() const;
ScheduledExecutor& scheduler();
std::shared_ptr<Task> scheduleTask(std::function<void()>&& task,
std::chrono::steady_clock::time_point when,
const char* filename = CURRENT_FILENAME(),
uint32_t linum = CURRENT_LINE());
std::shared_ptr<Task> scheduleTaskIn(std::function<void()>&& task,
std::chrono::steady_clock::duration timeout,
const char* filename = CURRENT_FILENAME(),
uint32_t linum = CURRENT_LINE());
std::map<std::string, std::string> getNearbyPeers(const std::string& accountID);
void updateProfile(const std::string& accountID,const std::string& displayName,const std::string& avatar,const uint64_t& flag);
#ifdef ENABLE_VIDEO
/**
* Create a new SinkClient instance, store it in an internal cache as a weak_ptr
* and return it as a shared_ptr. If a SinkClient is already stored for the given id,
* this method returns this instance.
* @param id SinkClient identifier as a string. Default is empty.
* @param mixer true if the SinkCient is the sink of a VideoMixer node. Default is false.
* @return share_ptr<SinkClient> A shared pointer on the created instance.
*/
std::shared_ptr<video::SinkClient> createSinkClient(const std::string& id = "",
bool mixer = false);
/**
* Create a SinkClient instance for each participant in a conference, store it in an internal
* cache as a weak_ptr and populates sinksMap with sink ids and shared_ptrs.
* @param callId
* @param infos ConferenceInfos that will create the sinks
* @param videoStream the the VideoFrameActiveWriter to which the sinks should be attached
* @param sinksMap A map between sink ids and the respective shared pointer.
*/
void createSinkClients(
const std::string& callId,
const ConfInfo& infos,
const std::vector<std::shared_ptr<video::VideoFrameActiveWriter>>& videoStreams,
std::map<std::string, std::shared_ptr<video::SinkClient>>& sinksMap,
const std::string& accountId = "");
/**
* Return an existing SinkClient instance as a shared_ptr associated to the given identifier.
* Return an empty shared_ptr (nullptr) if nothing found.
* @param id SinkClient identifier as a string.
* @return share_ptr<SinkClient> A shared pointer on the found instance. Empty if not found.
*/
std::shared_ptr<video::SinkClient> getSinkClient(const std::string& id);
#endif // ENABLE_VIDEO
VideoManager& getVideoManager() const;
std::atomic<unsigned> dhtLogLevel {0}; // default = disable
AccountFactory accountFactory;
std::vector<libjami::Message> getLastMessages(const std::string& accountID,
const uint64_t& base_timestamp);
SIPVoIPLink& sipVoIPLink() const;
#ifdef ENABLE_PLUGIN
JamiPluginManager& getJamiPluginManager() const;
#endif
/**
* Return current git socket used for a conversation
* @param accountId Related account
* @param deviceId Related device
* @param conversationId Related conversation
* @return std::optional<std::weak_ptr<ChannelSocket>> the related socket
*/
std::shared_ptr<dhtnet::ChannelSocket> gitSocket(const std::string_view accountId,
const std::string_view deviceId,
const std::string_view conversationId);
void setDefaultModerator(const std::string& accountID, const std::string& peerURI, bool state);
std::vector<std::string> getDefaultModerators(const std::string& accountID);
void enableLocalModerators(const std::string& accountID, bool state);
bool isLocalModeratorsEnabled(const std::string& accountID);
void setAllModerators(const std::string& accountID, bool allModerators);
bool isAllModerators(const std::string& accountID);
void insertGitTransport(git_smart_subtransport* tr, std::unique_ptr<P2PSubTransport>&& sub);
void eraseGitTransport(git_smart_subtransport* tr);
dhtnet::tls::CertificateStore& certStore(const std::string& accountId) const;
private:
Manager();
~Manager();
friend class AudioDeviceGuard;
// Data members
struct ManagerPimpl;
std::unique_ptr<ManagerPimpl> pimpl_;
};
class AudioDeviceGuard
{
public:
AudioDeviceGuard(Manager& manager, AudioDeviceType type);
~AudioDeviceGuard();
private:
Manager& manager_;
const AudioDeviceType type_;
};
// Helper to install a callback to be called once by the main event loop
template<typename Callback>
static void
runOnMainThread(Callback&& cb,
const char* filename = CURRENT_FILENAME(),
uint32_t linum = CURRENT_LINE())
{
Manager::instance().scheduler().run([cb = std::forward<Callback>(cb)]() mutable { cb(); },
filename,
linum);
}
} // namespace jami
| 29,526
|
C++
|
.h
| 774
| 30.971576
| 131
| 0.648116
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,899
|
debug_utils.h
|
savoirfairelinux_jami-daemon/src/debug_utils.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "libav_deps.h"
#include "media_io_handle.h"
#include "system_codec_container.h"
#include <opendht/utils.h>
#include <chrono>
#include <cstdio>
#include <fstream>
#include <ios>
#include <ratio>
#include <string_view>
#include "logger.h"
#warning Debug utilities included in build
using Clock = std::chrono::steady_clock;
using namespace std::literals;
namespace jami {
namespace debug {
/**
* Ex:
* Timer t;
* std::this_thread::sleep_for(std::chrono::milliseconds(10));
* JAMI_DBG() << "Task took " << t.getDuration<std::chrono::nanoseconds>() << " ns";
*/
class Timer
{
public:
Timer(std::string_view name) : name_(name), start_(Clock::now()) {}
~Timer() {
print("end"sv);
}
template<class Period = std::ratio<1>>
uint64_t getDuration() const
{
auto diff = std::chrono::duration_cast<Period>(Clock::now() - start_);
return diff.count();
}
void print(std::string_view action) const {
JAMI_DBG() << name_ << ": " << action << " after " << dht::print_duration(Clock::now() - start_);
}
private:
std::string_view name_;
std::chrono::time_point<Clock> start_;
};
/**
* Audio logger. Writes a wav file from raw PCM or AVFrame. Helps debug what goes wrong with audio.
*/
class WavWriter {
public:
WavWriter(const char* filename, AVFrame* frame)
{
JAMI_WARNING("WavWriter(): {} ({}, {})", filename, av_get_sample_fmt_name((AVSampleFormat)frame->format), frame->sample_rate);
avformat_alloc_output_context2(&format_ctx_, nullptr, "wav", filename);
if (!format_ctx_)
throw std::runtime_error("Failed to allocate output format context");
AVCodecID codec_id = AV_CODEC_ID_NONE;
switch (frame->format) {
case AV_SAMPLE_FMT_U8:
codec_id = AV_CODEC_ID_PCM_U8;
break;
case AV_SAMPLE_FMT_S16:
case AV_SAMPLE_FMT_S16P:
codec_id = AV_CODEC_ID_PCM_S16LE;
break;
case AV_SAMPLE_FMT_S32:
case AV_SAMPLE_FMT_S32P:
codec_id = AV_CODEC_ID_PCM_S32LE;
break;
case AV_SAMPLE_FMT_S64:
case AV_SAMPLE_FMT_S64P:
codec_id = AV_CODEC_ID_PCM_S64LE;
break;
case AV_SAMPLE_FMT_FLT:
case AV_SAMPLE_FMT_FLTP:
codec_id = AV_CODEC_ID_PCM_F32LE;
break;
case AV_SAMPLE_FMT_DBL:
codec_id = AV_CODEC_ID_PCM_F64LE;
break;
default:
throw std::runtime_error("Unsupported audio format");
}
auto codec = avcodec_find_encoder(codec_id);
if (!codec)
throw std::runtime_error("Failed to find audio codec");
codec_ctx_ = avcodec_alloc_context3(codec);
if (!codec_ctx_)
throw std::runtime_error("Failed to allocate audio codec context");
codec_ctx_->sample_fmt = (AVSampleFormat)frame->format;
codec_ctx_->ch_layout = frame->ch_layout;
codec_ctx_->sample_rate = frame->sample_rate;
if (format_ctx_->oformat->flags & AVFMT_GLOBALHEADER)
codec_ctx_->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
if (avcodec_open2(codec_ctx_, codec, nullptr) < 0)
throw std::runtime_error("Failed to open audio codec");
stream_ = avformat_new_stream(format_ctx_, codec);
if (!stream_)
throw std::runtime_error("Failed to create audio stream");
if (avcodec_parameters_from_context(stream_->codecpar, codec_ctx_) < 0)
throw std::runtime_error("Failed to copy codec parameters to stream");
if (!(format_ctx_->oformat->flags & AVFMT_NOFILE)) {
if (avio_open(&format_ctx_->pb, filename, AVIO_FLAG_WRITE) < 0) {
throw std::runtime_error("Failed to open output file for writing");
}
}
if (avformat_write_header(format_ctx_, nullptr) < 0)
throw std::runtime_error("Failed to write header to output file");
}
void write(AVFrame* frame) {
int ret = avcodec_send_frame(codec_ctx_, frame);
if (ret < 0)
JAMI_ERROR("Error sending a frame to the encoder");
while (ret >= 0) {
AVPacket *pkt = av_packet_alloc();
ret = avcodec_receive_packet(codec_ctx_, pkt);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
break;
else if (ret < 0) {
JAMI_ERROR("Error encoding a frame");
break;
}
pkt->stream_index = stream_->index;
pkt->pts = lastPts;
pkt->dts = lastPts;
lastPts += frame->nb_samples * (int64_t)stream_->time_base.den / (stream_->time_base.num * (int64_t)frame->sample_rate);
ret = av_write_frame(format_ctx_, pkt);
if (ret < 0) {
JAMI_ERROR("Error while writing output packet");
break;
}
av_packet_free(&pkt);
}
}
~WavWriter() {
if (codec_ctx_) {
avcodec_close(codec_ctx_);
avcodec_free_context(&codec_ctx_);
}
if (format_ctx_) {
av_write_trailer(format_ctx_);
if (!(format_ctx_->oformat->flags & AVFMT_NOFILE))
avio_closep(&format_ctx_->pb);
avformat_free_context(format_ctx_);
}
}
private:
AVFormatContext* format_ctx_ {nullptr};
AVCodecContext* codec_ctx_ {nullptr};
AVStream* stream_ {nullptr};
int64_t lastPts {0};
};
/**
* Minimally invasive video writer. Writes raw frames. Helps debug what goes wrong with video.
*/
class VideoWriter
{
public:
VideoWriter(const std::string& filename, AVPixelFormat format, int width, int height)
: filename_(filename)
, format_(format)
, width_(width)
, height_(height)
{
f_ = fopen(filename.c_str(), "wb");
}
// so an int (VideoFrame.format()) can be passed without casting
VideoWriter(const std::string& filename, int format, int width, int height)
: VideoWriter(filename, static_cast<AVPixelFormat>(format), width, height)
{}
~VideoWriter()
{
fclose(f_);
JAMI_DBG("Play video file with: ffplay -f rawvideo -pixel_format %s -video_size %dx%d %s",
av_get_pix_fmt_name(format_),
width_,
height_,
filename_.c_str());
}
void write(VideoFrame& frame)
{
int ret = 0;
uint8_t* buffer = nullptr;
auto f = frame.pointer();
if (format_ != f->format || width_ != f->width || height_ != f->height)
return;
int size = av_image_get_buffer_size(format_, width_, height_, 1);
buffer = reinterpret_cast<uint8_t*>(av_malloc(size));
if (!buffer) {
return;
}
if ((ret = av_image_copy_to_buffer(buffer,
size,
reinterpret_cast<const uint8_t* const*>(f->data),
reinterpret_cast<const int*>(f->linesize),
format_,
width_,
height_,
1))
< 0) {
av_freep(&buffer);
return;
}
fwrite(buffer, 1, size, f_);
av_freep(&buffer);
}
private:
FILE* f_;
std::string filename_;
AVPixelFormat format_;
int width_, height_;
};
} // namespace debug
} // namespace jami
| 8,466
|
C++
|
.h
| 228
| 27.969298
| 134
| 0.566659
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,900
|
uri.h
|
savoirfairelinux_jami-daemon/src/uri.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
#include <string_view>
namespace jami {
using namespace std::string_view_literals;
static constexpr std::string_view DATA_TRANSFER_SCHEME = "data-transfer://"sv;
class Uri
{
public:
enum class Scheme {
JAMI, // Start with "jami:" and 45 ASCII chars OR 40 ASCII chars
SIP, // Start with "sip:"
SWARM, // Start with "swarm:" and 40 ASCII chars
RENDEZVOUS, // Start with "rdv" and used for call in swarms
GIT, // Start with "git:"
DATA_TRANSFER, // Start with "data-transfer://"
SYNC, // Start with "sync:"
MESSAGE, // Start with "msg:"
UNRECOGNIZED // Anything that doesn't fit in other categories
};
Uri(std::string_view uri);
const std::string& authority() const;
Scheme scheme() const;
std::string toString() const;
// TODO hostname, transport, handle sip:
private:
constexpr std::string_view schemeToString() const;
Scheme scheme_;
std::string authority_;
};
} // namespace jami
| 1,806
|
C++
|
.h
| 47
| 34.553191
| 81
| 0.674472
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,901
|
observer.h
|
savoirfairelinux_jami-daemon/src/observer.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "noncopyable.h"
#include <cstdlib>
#include <cstdint>
#include <memory>
#include <set>
#include <list>
#include <mutex>
#include <functional>
#include <ciso646> // fix windows compiler bug
#ifndef __DEBUG__ // this is only defined on plugins build for debugging
#include "logger.h"
#endif
namespace jami {
template<typename T>
class Observer;
template<typename T>
class Observable;
/*=== Observable =============================================================*/
template<typename T>
class Observable
{
public:
Observable()
: mutex_()
, observers_()
{}
/**
* @brief ~Observable
* Detach all observers to avoid making them call this observable when
* destroyed
*/
virtual ~Observable()
{
std::lock_guard lk(mutex_);
for (auto& pobs : priority_observers_) {
if (auto so = pobs.lock()) {
so->detached(this);
}
}
for (auto& o : observers_)
o->detached(this);
}
bool attach(Observer<T>* o)
{
std::lock_guard lk(mutex_);
if (o and observers_.insert(o).second) {
o->attached(this);
return true;
}
return false;
}
void attachPriorityObserver(std::shared_ptr<Observer<T>> o)
{
std::lock_guard lk(mutex_);
priority_observers_.push_back(o);
o->attached(this);
}
void detachPriorityObserver(Observer<T>* o)
{
std::lock_guard lk(mutex_);
for (auto it = priority_observers_.begin(); it != priority_observers_.end(); it++) {
if (auto so = it->lock()) {
if (so.get() == o) {
so->detached(this);
priority_observers_.erase(it);
return;
}
}
}
}
bool detach(Observer<T>* o)
{
std::lock_guard lk(mutex_);
if (o and observers_.erase(o)) {
o->detached(this);
return true;
}
return false;
}
size_t getObserversCount()
{
std::lock_guard lk(mutex_);
return observers_.size() + priority_observers_.size();
}
protected:
void notify(T data)
{
std::lock_guard lk(mutex_);
for (auto it = priority_observers_.begin(); it != priority_observers_.end();) {
if (auto so = it->lock()) {
it++;
try {
so->update(this, data);
} catch (std::exception& e) {
#ifndef __DEBUG__
JAMI_ERR() << e.what();
#endif
}
} else {
it = priority_observers_.erase(it);
}
}
for (auto observer : observers_) {
observer->update(this, data);
}
}
private:
NON_COPYABLE(Observable);
protected:
std::mutex mutex_; // lock observers_
std::list<std::weak_ptr<Observer<T>>> priority_observers_;
std::set<Observer<T>*> observers_;
};
template<typename T>
class PublishObservable : public Observable<T>
{
public:
void publish(T data) { this->notify(data); }
};
/*=== Observer =============================================================*/
template<typename T>
class Observer
{
public:
virtual ~Observer() {}
virtual void update(Observable<T>*, const T&) = 0;
virtual void attached(Observable<T>*) {}
virtual void detached(Observable<T>*) {}
};
template<typename T>
class FuncObserver : public Observer<T>
{
public:
using F = std::function<void(const T&)>;
FuncObserver(F f)
: f_(f)
{}
virtual ~FuncObserver() {}
void update(Observable<T>*, const T& t) override { f_(t); }
private:
F f_;
};
/*=== PublishMapSubject ====================================================*/
template<typename T1, typename T2>
class PublishMapSubject : public Observer<T1>, public Observable<T2>
{
public:
using F = std::function<T2(const T1&)>;
PublishMapSubject(F f)
: map_ {f}
{}
void update(Observable<T1>*, const T1& t) override { this->notify(map_(t)); }
/**
* @brief attached
* Here we just make sure that the PublishMapSubject is only attached to one
* Observable at a time.
* @param srcObs
*/
virtual void attached(Observable<T1>* srcObs) override
{
if (obs_ != nullptr && obs_ != srcObs) {
obs_->detach(this);
obs_ = srcObs;
}
}
/**
* @brief detached
* Since a MapSubject is only attached to one Observable, when detached
* We should detach all of it observers
*/
virtual void detached(Observable<T1>*) override
{
std::lock_guard lk(this->mutex_);
for (auto& pobs : this->priority_observers_) {
if (auto so = pobs.lock()) {
so->detached(this);
}
}
for (auto& o : this->observers_)
o->detached(this);
}
/**
* @brief ~PublishMapSubject()
* Detach all observers to avoid making them call this observable when
* destroyed
**/
~PublishMapSubject() { detached(nullptr); }
private:
F map_;
Observable<T1>* obs_ = nullptr;
};
}; // namespace jami
| 5,974
|
C++
|
.h
| 209
| 22.358852
| 92
| 0.571603
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,902
|
account_schema.h
|
savoirfairelinux_jami-daemon/src/account_schema.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef ACCOUNT_SCHEMA_H_
#define ACCOUNT_SCHEMA_H_
/**
* @file account_schema.h
* @brief Account specific keys/constants that must be shared in daemon and clients.
*/
namespace jami {
namespace Conf {
// Common account parameters
static const char* const CONFIG_ACCOUNT_TYPE = "Account.type";
static const char* const CONFIG_ACCOUNT_ALIAS = "Account.alias";
static const char* const CONFIG_ACCOUNT_DISPLAYNAME = "Account.displayName";
static const char* const CONFIG_ACCOUNT_MAILBOX = "Account.mailbox";
static const char* const CONFIG_ACCOUNT_ENABLE = "Account.enable";
static const char* const CONFIG_ACCOUNT_AUTOANSWER = "Account.autoAnswer";
static const char* const CONFIG_ACCOUNT_SENDREADRECEIPT = "Account.sendReadReceipt";
static const char* const CONFIG_ACCOUNT_SENDCOMPOSING = "Account.sendComposing";
static const char* const CONFIG_ACCOUNT_ISRENDEZVOUS = "Account.rendezVous";
static const char* const CONFIG_ACCOUNT_REGISTRATION_EXPIRE = "Account.registrationExpire";
static const char* const CONFIG_ACCOUNT_DTMF_TYPE = "Account.dtmfType";
static const char* const CONFIG_RINGTONE_PATH = "Account.ringtonePath";
static const char* const CONFIG_RINGTONE_ENABLED = "Account.ringtoneEnabled";
static const char* const CONFIG_VIDEO_ENABLED = "Account.videoEnabled";
static const char* const CONFIG_KEEP_ALIVE_ENABLED = "Account.keepAliveEnabled";
static const char* const CONFIG_PRESENCE_ENABLED = "Account.presenceEnabled";
static const char* const CONFIG_PRESENCE_PUBLISH_SUPPORTED = "Account.presencePublishSupported";
static const char* const CONFIG_PRESENCE_SUBSCRIBE_SUPPORTED = "Account.presenceSubscribeSupported";
static const char* const CONFIG_PRESENCE_STATUS = "Account.presenceStatus";
static const char* const CONFIG_PRESENCE_NOTE = "Account.presenceNote";
static const char* const CONFIG_ACCOUNT_HOSTNAME = "Account.hostname";
static const char* const CONFIG_ACCOUNT_USERNAME = "Account.username";
static const char* const CONFIG_ACCOUNT_ROUTESET = "Account.routeset";
static const char* const CONFIG_ACCOUNT_IP_AUTO_REWRITE = "Account.allowIPAutoRewrite";
static const char* const CONFIG_ACCOUNT_PASSWORD = "Account.password";
static const char* const CONFIG_ACCOUNT_REALM = "Account.realm";
static const char* const CONFIG_ACCOUNT_USERAGENT = "Account.useragent";
static const char* const CONFIG_ACCOUNT_HAS_CUSTOM_USERAGENT = "Account.hasCustomUserAgent";
static const char* const CONFIG_ACCOUNT_AUDIO_PORT_MIN = "Account.audioPortMin";
static const char* const CONFIG_ACCOUNT_AUDIO_PORT_MAX = "Account.audioPortMax";
static const char* const CONFIG_ACCOUNT_VIDEO_PORT_MIN = "Account.videoPortMin";
static const char* const CONFIG_ACCOUNT_VIDEO_PORT_MAX = "Account.videoPortMax";
static const char* const CONFIG_BIND_ADDRESS = "Account.bindAddress";
static const char* const CONFIG_DHT_PORT = "Account.dhtPort";
static const char* const CONFIG_LOCAL_INTERFACE = "Account.localInterface";
static const char* const CONFIG_PUBLISHED_SAMEAS_LOCAL = "Account.publishedSameAsLocal";
static const char* const CONFIG_LOCAL_PORT = "Account.localPort";
static const char* const CONFIG_PUBLISHED_PORT = "Account.publishedPort";
static const char* const CONFIG_PUBLISHED_ADDRESS = "Account.publishedAddress";
static const char* const CONFIG_UPNP_ENABLED = "Account.upnpEnabled";
static const char* const CONFIG_DEFAULT_MODERATORS = "Account.defaultModerators";
static const char* const CONFIG_LOCAL_MODERATORS_ENABLED = "Account.localModeratorsEnabled";
static const char* const CONFIG_ALL_MODERATORS_ENABLED = "Account.allModeratorEnabled";
static const char* const CONFIG_ACCOUNT_UICUSTOMIZATION = "Account.uiCustomization";
// SIP specific parameters
static const char* const CONFIG_STUN_SERVER = "STUN.server";
static const char* const CONFIG_STUN_ENABLE = "STUN.enable";
static const char* const CONFIG_TURN_SERVER = "TURN.server";
static const char* const CONFIG_TURN_ENABLE = "TURN.enable";
static const char* const CONFIG_TURN_SERVER_UNAME = "TURN.username";
static const char* const CONFIG_TURN_SERVER_PWD = "TURN.password";
static const char* const CONFIG_TURN_SERVER_REALM = "TURN.realm";
// SRTP specific parameters
static const char* const CONFIG_SRTP_ENABLE = "SRTP.enable";
static const char* const CONFIG_SRTP_KEY_EXCHANGE = "SRTP.keyExchange";
static const char* const CONFIG_SRTP_RTP_FALLBACK = "SRTP.rtpFallback";
static const char* const CONFIG_TLS_LISTENER_PORT = "TLS.listenerPort";
static const char* const CONFIG_TLS_ENABLE = "TLS.enable";
static const char* const CONFIG_TLS_CA_LIST_FILE = "TLS.certificateListFile";
static const char* const CONFIG_TLS_CERTIFICATE_FILE = "TLS.certificateFile";
static const char* const CONFIG_TLS_PRIVATE_KEY_FILE = "TLS.privateKeyFile";
static const char* const CONFIG_TLS_PASSWORD = "TLS.password";
static const char* const CONFIG_TLS_METHOD = "TLS.method";
static const char* const CONFIG_TLS_CIPHERS = "TLS.ciphers";
static const char* const CONFIG_TLS_SERVER_NAME = "TLS.serverName";
static const char* const CONFIG_TLS_VERIFY_SERVER = "TLS.verifyServer";
static const char* const CONFIG_TLS_VERIFY_CLIENT = "TLS.verifyClient";
static const char* const CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE = "TLS.requireClientCertificate";
static const char* const CONFIG_TLS_DISABLE_SECURE_DLG_CHECK = "TLS.disableSecureDlgCheck";
static const char* const CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC = "TLS.negotiationTimeoutSec";
// DHT specific parameters
static const char* const CONFIG_DHT_PUBLIC_IN_CALLS = "DHT.PublicInCalls";
// Volatile parameters
static const char* const CONFIG_ACCOUNT_REGISTRATION_STATUS = "Account.registrationStatus";
static const char* const CONFIG_ACCOUNT_REGISTRATION_STATE_CODE = "Account.registrationCode";
static const char* const CONFIG_ACCOUNT_REGISTRATION_STATE_DESC = "Account.registrationDescription";
static const char* const CONFIG_TRANSPORT_STATE_CODE = "Transport.statusCode";
static const char* const CONFIG_TRANSPORT_STATE_DESC = "Transport.statusDescription";
} // namespace Conf
} // namespace jami
#endif // ACCOUNT_SCHEMA_H_
| 6,770
|
C++
|
.h
| 106
| 62.537736
| 100
| 0.79645
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,903
|
conference.h
|
savoirfairelinux_jami-daemon/src/conference.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <chrono>
#include <set>
#include <string>
#include <memory>
#include <vector>
#include <string_view>
#include <map>
#include <functional>
#include "conference_protocol.h"
#include "media/audio/audio_input.h"
#include "media/media_attribute.h"
#include "media/recordable.h"
#ifdef ENABLE_PLUGIN
#include "plugin/streamdata.h"
#endif
#ifdef ENABLE_VIDEO
#include "media/video/sinkclient.h"
#endif
#include <json/json.h>
namespace jami {
class Call;
class Account;
#ifdef ENABLE_VIDEO
namespace video {
class VideoMixer;
}
#endif
// info for a stream
struct ParticipantInfo
{
std::string uri;
std::string device;
std::string sinkId; // stream ID
bool active {false};
int x {0};
int y {0};
int w {0};
int h {0};
bool videoMuted {false};
bool audioLocalMuted {false};
bool audioModeratorMuted {false};
bool isModerator {false};
bool handRaised {false};
bool voiceActivity {false};
bool recording {false};
void fromJson(const Json::Value& v)
{
uri = v["uri"].asString();
device = v["device"].asString();
sinkId = v["sinkId"].asString();
active = v["active"].asBool();
x = v["x"].asInt();
y = v["y"].asInt();
w = v["w"].asInt();
h = v["h"].asInt();
videoMuted = v["videoMuted"].asBool();
audioLocalMuted = v["audioLocalMuted"].asBool();
audioModeratorMuted = v["audioModeratorMuted"].asBool();
isModerator = v["isModerator"].asBool();
handRaised = v["handRaised"].asBool();
voiceActivity = v["voiceActivity"].asBool();
recording = v["recording"].asBool();
}
Json::Value toJson() const
{
Json::Value val;
val["uri"] = uri;
val["device"] = device;
val["sinkId"] = sinkId;
val["active"] = active;
val["x"] = x;
val["y"] = y;
val["w"] = w;
val["h"] = h;
val["videoMuted"] = videoMuted;
val["audioLocalMuted"] = audioLocalMuted;
val["audioModeratorMuted"] = audioModeratorMuted;
val["isModerator"] = isModerator;
val["handRaised"] = handRaised;
val["voiceActivity"] = voiceActivity;
val["recording"] = recording;
return val;
}
std::map<std::string, std::string> toMap() const
{
return {{"uri", uri},
{"device", device},
{"sinkId", sinkId},
{"active", active ? "true" : "false"},
{"x", std::to_string(x)},
{"y", std::to_string(y)},
{"w", std::to_string(w)},
{"h", std::to_string(h)},
{"videoMuted", videoMuted ? "true" : "false"},
{"audioLocalMuted", audioLocalMuted ? "true" : "false"},
{"audioModeratorMuted", audioModeratorMuted ? "true" : "false"},
{"isModerator", isModerator ? "true" : "false"},
{"handRaised", handRaised ? "true" : "false"},
{"voiceActivity", voiceActivity ? "true" : "false"},
{"recording", recording ? "true" : "false"}};
}
friend bool operator==(const ParticipantInfo& p1, const ParticipantInfo& p2)
{
return p1.uri == p2.uri and p1.device == p2.device and p1.sinkId == p2.sinkId
and p1.active == p2.active and p1.x == p2.x and p1.y == p2.y and p1.w == p2.w
and p1.h == p2.h and p1.videoMuted == p2.videoMuted
and p1.audioLocalMuted == p2.audioLocalMuted
and p1.audioModeratorMuted == p2.audioModeratorMuted
and p1.isModerator == p2.isModerator and p1.handRaised == p2.handRaised
and p1.voiceActivity == p2.voiceActivity and p1.recording == p2.recording;
}
friend bool operator!=(const ParticipantInfo& p1, const ParticipantInfo& p2)
{
return !(p1 == p2);
}
};
struct ConfInfo : public std::vector<ParticipantInfo>
{
int h {0};
int w {0};
int v {1}; // Supported conference protocol version
int layout {0};
friend bool operator==(const ConfInfo& c1, const ConfInfo& c2)
{
if (c1.h != c2.h or c1.w != c2.w)
return false;
if (c1.size() != c2.size())
return false;
for (auto& p1 : c1) {
auto it = std::find_if(c2.begin(), c2.end(), [&p1](const ParticipantInfo& p2) {
return p1 == p2;
});
if (it != c2.end())
continue;
else
return false;
}
return true;
}
friend bool operator!=(const ConfInfo& c1, const ConfInfo& c2) { return !(c1 == c2); }
std::vector<std::map<std::string, std::string>> toVectorMapStringString() const;
std::string toString() const;
};
using CallIdSet = std::set<std::string>;
using clock = std::chrono::steady_clock;
class Conference : public Recordable, public std::enable_shared_from_this<Conference>
{
public:
enum class State { ACTIVE_ATTACHED, ACTIVE_DETACHED, HOLD };
/**
* Constructor for this class, increment static counter
*/
explicit Conference(const std::shared_ptr<Account>&,
const std::string& confId = "");
/**
* Destructor for this class, decrement static counter
*/
~Conference();
/**
* Return the conference id
*/
const std::string& getConfId() const { return id_; }
std::shared_ptr<Account> getAccount() const { return account_.lock(); }
std::string getAccountId() const;
/**
* Return the current conference state
*/
State getState() const;
/**
* Set conference state
*/
void setState(State state);
/**
* Set a callback that will be called when the conference will be destroyed
*/
void onShutdown(std::function<void(int)> cb) { shutdownCb_ = std::move(cb); }
/**
* Return a string description of the conference state
*/
static constexpr const char* getStateStr(State state)
{
switch (state) {
case State::ACTIVE_ATTACHED:
return "ACTIVE_ATTACHED";
case State::ACTIVE_DETACHED:
return "ACTIVE_DETACHED";
case State::HOLD:
return "HOLD";
default:
return "";
}
}
const char* getStateStr() const { return getStateStr(confState_); }
/**
* Set the mute state of the local host
*/
void setLocalHostMuteState(MediaType type, bool muted);
/**
* Get the mute state of the local host
*/
bool isMediaSourceMuted(MediaType type) const;
/**
* Process a media change request.
* Used to change the media attributes of the host.
*
* @param remoteMediaList new media list from the remote
* @return true on success
*/
bool requestMediaChange(const std::vector<libjami::MediaMap>& mediaList);
/**
* Process incoming media change request.
*
* @param callId the call ID
* @param remoteMediaList new media list from the remote
*/
void handleMediaChangeRequest(const std::shared_ptr<Call>& call,
const std::vector<libjami::MediaMap>& remoteMediaList);
/**
* Add a new subcall to the conference
*/
void addSubCall(const std::string& callId);
/**
* Remove a subcall from the conference
*/
void removeSubCall(const std::string& callId);
/**
* Attach host
*/
void attachHost(const std::vector<libjami::MediaMap>& mediaList = {});
/**
* Detach local audio/video from the conference
*/
void detachHost();
/**
* Get the participant list for this conference
*/
CallIdSet getSubCalls() const;
/**
* Start/stop recording toggle
*/
bool toggleRecording() override;
void switchInput(const std::string& input);
void setActiveParticipant(const std::string& participant_id);
void setActiveStream(const std::string& streamId, bool state);
void setLayout(int layout);
void onConfOrder(const std::string& callId, const std::string& order);
bool isVideoEnabled() const;
#ifdef ENABLE_VIDEO
void createSinks(const ConfInfo& infos);
std::shared_ptr<video::VideoMixer> getVideoMixer();
std::string getVideoInput() const;
#endif
std::vector<std::map<std::string, std::string>> getConferenceInfos() const
{
std::lock_guard lk(confInfoMutex_);
return confInfo_.toVectorMapStringString();
}
void updateConferenceInfo(ConfInfo confInfo);
void setModerator(const std::string& uri, const bool& state);
void hangupParticipant(const std::string& accountUri, const std::string& deviceId = "");
void setHandRaised(const std::string& uri, const bool& state);
void setVoiceActivity(const std::string& streamId, const bool& newState);
void muteParticipant(const std::string& uri, const bool& state);
void muteLocalHost(bool is_muted, const std::string& mediaType);
bool isRemoteParticipant(const std::string& uri);
void mergeConfInfo(ConfInfo& newInfo, const std::string& peerURI);
/**
* The client shows one tile per stream (video/audio related to a media)
* @note for now, in conferences we can only mute the audio of a call
* @todo add a track (audio OR video) parameter to know what we want to mute
* @param accountUri Account of the stream
* @param deviceId Device of the stream
* @param streamId Stream to mute
* @param state True to mute, false to unmute
*/
void muteStream(const std::string& accountUri,
const std::string& deviceId,
const std::string& streamId,
const bool& state);
void updateMuted();
void updateRecording();
void updateVoiceActivity();
std::shared_ptr<Call> getCallFromPeerID(std::string_view peerId);
/**
* Announce to the client that medias are successfully negotiated
*/
void reportMediaNegotiationStatus();
/**
* Retrieve current medias list
* @return current medias
*/
std::vector<libjami::MediaMap> currentMediaList() const;
// Update layout if recording changes
void stopRecording() override;
bool startRecording(const std::string& path) override;
/**
* @return Conference duration in milliseconds
*/
std::chrono::milliseconds getDuration() const
{
return duration_start_ == clock::time_point::min()
? std::chrono::milliseconds::zero()
: std::chrono::duration_cast<std::chrono::milliseconds>(clock::now()
- duration_start_);
}
private:
std::weak_ptr<Conference> weak()
{
return std::static_pointer_cast<Conference>(shared_from_this());
}
static std::shared_ptr<Call> getCall(const std::string& callId);
bool isModerator(std::string_view uri) const;
bool isHandRaised(std::string_view uri) const;
bool isVoiceActive(std::string_view uri) const;
void updateModerators();
void updateHandsRaised();
void muteHost(bool state);
void muteCall(const std::string& callId, bool state);
void foreachCall(const std::function<void(const std::shared_ptr<Call>& call)>& cb);
std::string id_;
std::weak_ptr<Account> account_;
State confState_ {State::ACTIVE_DETACHED};
mutable std::mutex subcallsMtx_ {};
CallIdSet subCalls_;
std::string mediaPlayerId_ {};
mutable std::mutex confInfoMutex_ {};
ConfInfo confInfo_ {};
void sendConferenceInfos();
std::shared_ptr<RingBuffer> ghostRingBuffer_;
#ifdef ENABLE_VIDEO
bool videoEnabled_;
std::shared_ptr<video::VideoMixer> videoMixer_;
std::map<std::string, std::shared_ptr<video::SinkClient>> confSinksMap_ {};
#endif
std::shared_ptr<jami::AudioInput> audioMixer_;
std::set<std::string, std::less<>> moderators_ {};
std::set<std::string, std::less<>> participantsMuted_ {};
std::set<std::string, std::less<>> handsRaised_;
// stream IDs
std::set<std::string, std::less<>> streamsVoiceActive {};
void initRecorder(std::shared_ptr<MediaRecorder>& rec);
void deinitRecorder(std::shared_ptr<MediaRecorder>& rec);
bool isMuted(std::string_view uri) const;
ConfInfo getConfInfoHostUri(std::string_view localHostURI, std::string_view destURI);
bool isHost(std::string_view uri) const;
bool isHostDevice(std::string_view deviceId) const;
/**
* If the local host is participating in the conference (attached
* mode ), this variable will hold the media source states
* of the local host.
*/
std::vector<MediaAttribute> hostSources_;
// Because host doesn't have a call, we need to store the audio inputs
std::map<std::string, std::shared_ptr<jami::AudioInput>> hostAudioInputs_;
bool localModAdded_ {false};
std::map<std::string, ConfInfo> remoteHosts_;
#ifdef ENABLE_VIDEO
void resizeRemoteParticipants(ConfInfo& confInfo, std::string_view peerURI);
#endif
std::string_view findHostforRemoteParticipant(std::string_view uri,
std::string_view deviceId = "");
std::shared_ptr<Call> getCallWith(const std::string& accountUri, const std::string& deviceId);
std::mutex sinksMtx_ {};
#ifdef ENABLE_PLUGIN
/**
* Call Streams and some typedefs
*/
using AVMediaStream = Observable<std::shared_ptr<MediaFrame>>;
using MediaStreamSubject = PublishMapSubject<std::shared_ptr<MediaFrame>, AVFrame*>;
#ifdef ENABLE_VIDEO
/**
* Map: maps the VideoFrame to an AVFrame
**/
std::function<AVFrame*(const std::shared_ptr<jami::MediaFrame>&)> pluginVideoMap_ =
[](const std::shared_ptr<jami::MediaFrame>& m) -> AVFrame* {
return std::static_pointer_cast<VideoFrame>(m)->pointer();
};
#endif // ENABLE_VIDEO
/**
* @brief createConfAVStream
* Creates a conf AV stream like video input, video receive, audio input or audio receive
* @param StreamData
* @param streamSource
* @param mediaStreamSubject
*/
void createConfAVStream(const StreamData& StreamData,
AVMediaStream& streamSource,
const std::shared_ptr<MediaStreamSubject>& mediaStreamSubject,
bool force = false);
/**
* @brief createConfAVStreams
* Creates all Conf AV Streams (2 if audio, 4 if audio video)
*/
void createConfAVStreams();
std::mutex avStreamsMtx_ {};
std::map<std::string, std::shared_ptr<MediaStreamSubject>> confAVStreams;
#endif // ENABLE_PLUGIN
ConfProtocolParser parser_;
std::string getRemoteId(const std::shared_ptr<jami::Call>& call) const;
std::function<void(int)> shutdownCb_;
clock::time_point duration_start_;
/**
* Initialize sources for host (takes default camera/audio)
*/
void initSourcesForHost();
/**
* Take over media control from the call.
* When a call joins a conference, the media control (mainly mute/un-mute
* state of the local media source) will be handled by the conference and
* the mixer.
*/
void takeOverMediaSourceControl(const std::string& callId);
/**
* Bind host's audio
*/
void bindHostAudio();
/**
* Unbind host's audio
*/
void unbindHostAudio();
/**
* Bind call's audio to the conference
*/
void bindSubCallAudio(const std::string& callId);
/**
* Unbind call's audio from the conference
*/
void unbindSubCallAudio(const std::string& callId);
};
} // namespace jami
| 16,583
|
C++
|
.h
| 450
| 30.126667
| 98
| 0.635882
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,904
|
call.h
|
savoirfairelinux_jami-daemon/src/call.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "logger.h"
#include "conference.h"
#include "media/recordable.h"
#include "media/peerrecorder.h"
#include "media/media_codec.h"
#include "media/media_attribute.h"
#include <dhtnet/ip_utils.h>
#include <atomic>
#include <mutex>
#include <map>
#include <sstream>
#include <memory>
#include <vector>
#include <condition_variable>
#include <set>
#include <list>
#include <functional>
template<typename T>
bool
is_uninitialized(std::weak_ptr<T> const& weak)
{
using wt = std::weak_ptr<T>;
return !weak.owner_before(wt {}) && !wt {}.owner_before(weak);
}
namespace jami {
class VoIPLink;
class Account;
class AudioDeviceGuard;
class Call;
class Conference;
using CallMap = std::map<std::string, std::shared_ptr<Call>>;
namespace video {
class VideoGenerator;
}
/*
* @file call.h
* @brief A call is the base class for protocol-based calls
*/
class Call : public Recordable, public PeerRecorder, public std::enable_shared_from_this<Call>
{
public:
/**
* Tell where we're at with the call. The call gets Connected when we know
* from the other end what happened with out call. A call can be 'Connected'
* even if the call state is Busy, or Error.
*
* Audio should be transmitted when ConnectionState = Connected AND
* CallState = Active.
*
* \note modify validStateTransition/getStateStr if this enum changes
*/
enum class ConnectionState : unsigned {
DISCONNECTED,
TRYING,
PROGRESSING,
RINGING,
CONNECTED,
COUNT__
};
/**
* The Call State.
*
* \note modify validStateTransition/getStateStr if this enum changes
*/
enum class CallState : unsigned {
INACTIVE,
ACTIVE,
HOLD,
BUSY,
PEER_BUSY,
MERROR,
OVER,
COUNT__
};
enum class LinkType { GENERIC, SIP };
using SubcallSet = std::set<std::shared_ptr<Call>, std::owner_less<std::shared_ptr<Call>>>;
using OnReadyCb = std::function<void(bool)>;
using StateListenerCb = std::function<bool(CallState, ConnectionState, int)>;
/**
* This determines if the call originated from the local user (OUTGOING)
* or from some remote peer (INCOMING, MISSED).
*/
enum class CallType : unsigned { INCOMING, OUTGOING, MISSED };
virtual ~Call();
std::weak_ptr<Call> weak() { return std::static_pointer_cast<Call>(shared_from_this()); }
virtual LinkType getLinkType() const { return LinkType::GENERIC; }
/**
* Return a reference on the call id
* @return call id
*/
const std::string& getCallId() const { return id_; }
/**
* Return a reference on the conference id
* @return call id
*/
std::shared_ptr<Conference> getConference() const { return conf_.lock(); }
bool isConferenceParticipant() const { return not is_uninitialized(conf_); }
std::weak_ptr<Account> getAccount() const { return account_; }
std::string getAccountId() const;
CallType getCallType() const { return type_; }
/**
* Set the peer number (destination on outgoing)
* not protected by mutex (when created)
* @param number peer number
*/
void setPeerNumber(const std::string& number) { peerNumber_ = number; }
/**
* Get the peer number (destination on outgoing)
* not protected by mutex (when created)
* @return std::string The peer number
*/
const std::string& getPeerNumber() const { return peerNumber_; }
/**
* Set the display name (caller in ingoing)
* not protected by mutex (when created)
* @return std::string The peer display name
*/
void setPeerDisplayName(const std::string& name) { peerDisplayName_ = name; }
/**
* Get "To" from the invite
* @note Used to make the difference between incoming calls for accounts and for conversations
* @return the "To" that was present in the invite
*/
const std::string& toUsername() const { return toUsername_; }
/**
* Updated by sipvoiplink, corresponds to the "To" in the invite
* @param username "To"
*/
void toUsername(const std::string& username) { toUsername_ = username; }
/**
* Get the peer display name (caller in ingoing)
* not protected by mutex (when created)
* @return std::string The peer name
*/
const std::string& getPeerDisplayName() const { return peerDisplayName_; }
/**
* Tell if the call is incoming
* @return true if yes false otherwise
*/
bool isIncoming() const { return type_ == CallType::INCOMING; }
/**
* Set the state of the call (protected by mutex)
* @param call_state The call state
* @param cnx_state The call connection state
* @param code Optional error-dependent code (used to report more information)
* @return true if the requested state change was valid, false otherwise
*/
bool setState(CallState call_state, signed code = 0);
bool setState(CallState call_state, ConnectionState cnx_state, signed code = 0);
bool setState(ConnectionState cnx_state, signed code = 0);
/**
* Get the call state of the call (protected by mutex)
* @return CallState The call state
*/
CallState getState() const;
/**
* Get the connection state of the call (protected by mutex)
* @return ConnectionState The connection state
*/
ConnectionState getConnectionState() const;
std::string getStateStr() const;
void setIPToIP(bool IPToIP) { isIPToIP_ = IPToIP; }
virtual std::map<std::string, std::string> getDetails() const;
/**
* Answer the call
*/
virtual void answer() = 0;
/**
* Answer a call with a list of media attributes.
* @param mediaList The list of the media attributes.
* The media attributes set by the caller of this method will
* determine the response sent to the peer and the configuration
* of the local media.
* If the media list is empty, the current media set when the call
* was created will be used.
*/
virtual void answer(const std::vector<libjami::MediaMap>& mediaList) = 0;
/**
* Check the media of an incoming media change request.
* This method checks the new media against the current media. It
* determines if the differences are significant enough to require
* more processing.
* For instance, this can be used to check if the a change request
* must be reported to the client for confirmation or can be handled
* by the daemon.
* The conditions that cause this method to return true are implementation
* specific.
*
* @param the new media list from the remote
* @return true if the new media differs from the current media
**/
virtual bool checkMediaChangeRequest(const std::vector<libjami::MediaMap>& remoteMediaList) = 0;
/**
* Process incoming media change request.
*
* @param the new media list from the remote
*/
virtual void handleMediaChangeRequest(const std::vector<libjami::MediaMap>& remoteMediaList) = 0;
/**
* Answer to a media update request.
* The media attributes set by the caller of this method will
* determine the response to send to the peer and the configuration
* of the local media.
* @param mediaList The list of media attributes. An empty media
* list means the media update request was not accepted, meaning the
* call continue with the current media. It's up to the implementation
* to determine wether an answer will be sent to the peer.
* @param isRemote True if the media list is from the remote peer
*/
virtual void answerMediaChangeRequest(const std::vector<libjami::MediaMap>& mediaList,
bool isRemote = false)
= 0;
/**
* Hang up the call
* @param reason
*/
virtual void hangup(int reason) = 0;
/**
* Refuse incoming call
*/
virtual void refuse() = 0;
/**
* Transfer a call to specified URI
* @param to The recipient of the call
*/
virtual void transfer(const std::string& to) = 0;
/**
* Attended transfer
* @param The target call id
* @return True on success
*/
virtual bool attendedTransfer(const std::string& to) = 0;
/**
* Put a call on hold
* @param cb On hold can be queued if waiting for ICE. This callback will be called when ready
* @return bool True on success, False if failed or pending
*/
virtual bool onhold(OnReadyCb&& cb) = 0;
/**
* Resume a call from hold state
* @param cb On hold can be queued if waiting for ICE. This callback will be called when ready
* @return bool True on success, False if failed or pending
*/
virtual bool offhold(OnReadyCb&& cb) = 0;
virtual void sendKeyframe(int streamIdx = -1) = 0;
/**
* Check wether ICE is enabled for media
*/
virtual bool isIceEnabled() const = 0;
/**
* Peer has hung up a call
*/
virtual void peerHungup();
virtual void removeCall();
/**
* Update recording state. Typically used to send notifications
* to peers about the local recording session state
*/
virtual void updateRecState(bool state) = 0;
void addStateListener(StateListenerCb&& listener)
{
std::lock_guard lk {callMutex_};
stateChangedListeners_.emplace_back(std::move(listener));
}
/**
* Attach subcall to this instance.
* If this subcall is answered, this subcall and this instance will be merged using merge().
*/
void addSubCall(Call& call);
///
/// Return true if this call instance is a subcall (internal call for multi-device handling)
///
bool isSubcall() const
{
std::lock_guard lk {callMutex_};
return parent_ != nullptr;
}
/**
* @return Call duration in milliseconds
*/
std::chrono::milliseconds getCallDuration() const
{
return duration_start_ == time_point::min()
? std::chrono::milliseconds::zero()
: std::chrono::duration_cast<std::chrono::milliseconds>(clock::now()
- duration_start_);
}
// media management
virtual bool toggleRecording();
virtual std::vector<MediaAttribute> getMediaAttributeList() const = 0;
virtual std::map<std::string, bool> getAudioStreams() const = 0;
#ifdef ENABLE_VIDEO
virtual void createSinks(ConfInfo& infos) = 0;
#endif
virtual void switchInput(const std::string& = {}) {};
/**
* mute/unmute a media of a call
* @param mediaType type of media
* @param isMuted true for muting, false for unmuting
*/
virtual void muteMedia(const std::string& mediaType, bool isMuted) = 0;
/**
* Send DTMF
* @param code The char code
*/
virtual void carryingDTMFdigits(char code) = 0;
/**
* Make a change request of the current media with the provided media
* @param mediaList the new media list
* @return true on success
*/
virtual bool requestMediaChange(const std::vector<libjami::MediaMap>& mediaList) = 0;
/**
* Retrieve current medias list
* @return current medias
*/
virtual std::vector<libjami::MediaMap> currentMediaList() const = 0;
/**
* Send a message to a call identified by its callid
*
* @param A list of mimetype/payload pairs
* @param The sender of this message (could be another participant of a conference)
*/
virtual void sendTextMessage(const std::map<std::string, std::string>& messages,
const std::string& from)
= 0;
void onTextMessage(std::map<std::string, std::string>&& messages);
virtual std::shared_ptr<SystemCodecInfo> getAudioCodec() const
{
return {};
}
virtual std::shared_ptr<SystemCodecInfo> getVideoCodec() const
{
return {};
}
virtual void restartMediaSender() = 0;
// Media status methods
virtual bool hasVideo() const = 0;
virtual bool isCaptureDeviceMuted(const MediaType& mediaType) const = 0;
/**
* A Call can be in a conference. If this is the case, the other side
* will send conference information describing the rendered image
* @msg A JSON object describing the conference
*/
void setConferenceInfo(const std::string& msg);
virtual void enterConference(std::shared_ptr<Conference> conference) = 0;
virtual void exitConference() = 0;
std::vector<std::map<std::string, std::string>> getConferenceInfos() const
{
return confInfo_.toVectorMapStringString();
}
std::unique_ptr<AudioDeviceGuard> audioGuard;
void sendConfOrder(const Json::Value& root);
void sendConfInfo(const std::string& json);
void resetConfInfo();
virtual void monitor() const = 0;
int conferenceProtocolVersion() const
{
return peerConfProtocol_;
}
protected:
using clock = std::chrono::steady_clock;
using time_point = clock::time_point;
virtual void merge(Call& scall);
/**
* Constructor of a call
* @param id Unique identifier of the call
* @param type set definitely this call as incoming/outgoing
* @param details volatile details to customize the call creation
*/
Call(const std::shared_ptr<Account>& account,
const std::string& id,
Call::CallType type,
const std::map<std::string, std::string>& details = {});
// TODO all these members are not protected against multi-thread access
const std::string id_ {};
///< MultiDevice: parent call, nullptr otherwise. Access protected by callMutex_.
mutable std::shared_ptr<Call> parent_;
///< MultiDevice: list of attached subcall
SubcallSet subcalls_;
using MsgList = std::list<std::pair<std::map<std::string, std::string>, std::string>>;
///< MultiDevice: message waiting to be sent (need a valid subcall)
MsgList pendingOutMessages_;
/** Protect every attribute that can be changed by two threads */
mutable std::recursive_mutex callMutex_ {};
mutable std::mutex confInfoMutex_ {};
mutable ConfInfo confInfo_ {};
time_point duration_start_ {time_point::min()};
private:
bool validStateTransition(CallState newState);
void checkPendingIM();
void checkAudio();
void subcallStateChanged(Call&, Call::CallState, Call::ConnectionState);
SubcallSet safePopSubcalls();
std::vector<StateListenerCb> stateChangedListeners_ {};
protected:
/** Unique conference ID, used exclusively in case of a conference */
std::weak_ptr<Conference> conf_ {};
/** Type of the call */
CallType type_;
/** Associate account ID */
std::weak_ptr<Account> account_;
/** Disconnected/Progressing/Trying/Ringing/Connected */
ConnectionState connectionState_ {ConnectionState::DISCONNECTED};
/** Inactive/Active/Hold/Busy/Error */
CallState callState_ {CallState::INACTIVE};
std::string reason_ {};
/** Direct IP-to-IP or classic call */
bool isIPToIP_ {false};
/** Number of the peer */
std::string peerNumber_ {};
/** Peer Display Name */
std::string peerDisplayName_ {};
time_t timestamp_start_ {0};
///< MultiDevice: message received by subcall to merged yet
MsgList pendingInMessages_;
/// Supported conference protocol version
int peerConfProtocol_ {0};
std::string toUsername_ {};
};
// Helpers
/**
* Obtain a shared smart pointer of instance
*/
inline std::shared_ptr<Call>
getPtr(Call& call)
{
return call.shared_from_this();
}
} // namespace jami
| 16,612
|
C++
|
.h
| 450
| 31.32
| 101
| 0.669324
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,905
|
enumclass_utils.h
|
savoirfairelinux_jami-daemon/src/enumclass_utils.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "logger.h"
#include <map>
#include <type_traits>
#include <vector>
#include <cassert>
namespace jami {
/**
* This function adds a safe way to get an enum class size
*/
template<typename A>
constexpr inline size_t
enum_class_size()
{
return size_t(A::COUNT__);
}
/**
* This generic class represents a multidimensional enum class array.
* It safely converts them to integers. Each enum class needs a "COUNT__" item
* at the end."
*
* This struct enforces:
* * That the rows are indexed using enum_classes
* * That the size of the matrix matches the enum_class size
* * That the operators are within the matrix boundary
*/
template<class Row, typename Value, typename A = Value>
struct Matrix1D
{
constexpr Matrix1D(std::initializer_list<std::initializer_list<Value>> s);
// Row is a built-in type ("int" by default)
Value operator[](Row v);
const Value operator[](Row v) const;
/**
* An Iterator for enum classes
*/
class EnumClassIter
{
public:
EnumClassIter(const Matrix1D<Row, Value, A>* p_vec, size_t pos)
: pos_(pos)
, p_vec_(p_vec)
{}
bool operator!=(const EnumClassIter& other) const;
Row operator*() const;
const EnumClassIter& operator++();
private:
size_t pos_;
const Matrix1D<Row, Value, A>* p_vec_;
};
// Iterators
EnumClassIter begin();
EnumClassIter end();
// Only use for single reverse mappable arrays, will ASSERT otherwise
Row fromValue(const Value& value) const;
static void setReverseMapping(Matrix1D<Row, const char*> names);
private:
const std::vector<Value> data_;
static std::map<A, Row> reverseMapping_;
};
/**
* A matrix with no value
*
* This is useful to use enum class in C++11 foreach loops
*
* @usage
* for (const MyEnum& value : Matrix0D<MyEnum>()) {
* std::cout << "Name: " << MyEnumNames[value] << std::endl;
* }
*/
template<class EnumClass>
struct Matrix0D
{
/**
* An Iterator for enum classes
*/
class EnumClassIter
{
public:
EnumClassIter(const Matrix0D<EnumClass>* p_vec, size_t pos)
: pos_(pos)
, p_vec_(p_vec)
{}
bool operator!=(const EnumClassIter& other) const;
EnumClass operator*() const;
const EnumClassIter& operator++();
private:
size_t pos_;
const Matrix0D<EnumClass>* p_vec_;
};
Matrix0D();
// Iterators
EnumClassIter begin();
EnumClassIter end();
};
/**
* A helper to type to match serializable string to enum elements
*/
template<class Row>
using EnumClassNames = Matrix1D<Row, std::string_view>;
/**
* Create a matrix type with 2 enum class dimensions M[I,J] = V
* ^ ^ ^
* | | |
* Rows <--- | |
* Columns <----- |
* Value <----------
*/
template<class Row, class Column, typename Value>
using Matrix2D = Matrix1D<Row, Matrix1D<Column, Value>>;
/**
* Create an array of callbacks.
*
* This type hides all the C++ syntax requirements
*/
template<class Row, class Class, typename Result = void, typename... Args>
using CallbackMatrix1D = Matrix1D<Row, Result (Class::*)(Args... args)>;
/**
* Create a method callback matrix.
*
* This type hides all the C++ syntax requirements
*/
template<class Row, class Column, class Class, typename Result = void, typename... Args>
using CallbackMatrix2D = Matrix2D<Row, Column, void (Class::*)(Args... args)>;
/*
* IMPLEMENTATION
*
*/
template<class Row, typename Value, typename Accessor>
constexpr Matrix1D<Row, Value, Accessor>::Matrix1D(std::initializer_list<std::initializer_list<Value>> s)
: data_(*std::begin(s))
{
static_assert(std::is_enum<Row>(), "Row has to be an enum class");
static_assert((int) Row::COUNT__ > 0, "Row need a COUNT__ element");
// FIXME C++14, use static_assert and make the ctor constexpr
assert(s.begin()->size()
== enum_class_size<Row>()); //,"Matrix row have to match the enum class size");
}
template<class Row, typename Value, typename Accessor>
Value Matrix1D<Row, Value, Accessor>::operator[](Row v)
{
// ASSERT(size_t(v) >= size_t(Row::COUNT__),"State Machine Out of Bounds\n");
if (size_t(v) >= enum_class_size<Row>() || static_cast<int>(v) < 0) {
JAMI_ERR("State Machine Out of Bounds %d\n", size_t(v));
assert(false);
throw v;
}
return data_[size_t(v)];
}
template<class Row, typename Value, typename Accessor>
const Value Matrix1D<Row, Value, Accessor>::operator[](Row v) const
{
assert(size_t(v) <= enum_class_size<Row>() + 1 && size_t(v) >= 0); // COUNT__ is also valid
if (size_t(v) >= enum_class_size<Row>()) {
JAMI_ERR("State Machine Out of Bounds %zu\n", size_t(v));
assert(false);
throw v;
}
return data_[size_t(v)];
}
template<class E, class T, class A>
std::map<A, E> Matrix1D<E, T, A>::reverseMapping_;
template<class Row, typename Value, typename Accessor>
void
Matrix1D<Row, Value, Accessor>::setReverseMapping(Matrix1D<Row, const char*> names)
{
for (const Row row : Matrix0D<Row>())
reverseMapping_[names[row]] = row;
}
template<class Row, typename Value, typename Accessor>
Row
Matrix1D<Row, Value, Accessor>::fromValue(const Value& value) const
{
if (!reverseMapping_.empty()) {
for (int i = 0; i < enum_class_size<Row>(); i++) {
const_cast<Matrix1D*>(this)->reverseMapping_[(*const_cast<Matrix1D*>(this))[(Row) i]]
= static_cast<Row>(i);
}
assert(reverseMapping_.empty() == enum_class_size<Row>());
}
if (reverseMapping_.count(value) == 0) {
throw value;
}
return reverseMapping_[value];
}
template<class EnumClass>
Matrix0D<EnumClass>::Matrix0D()
{
static_assert(std::is_enum<EnumClass>(),
"The first template parameter has to be an enum class\n");
}
template<class EnumClass>
EnumClass Matrix0D<EnumClass>::EnumClassIter::operator*() const
{
assert(pos_ < enum_class_size<EnumClass>());
return static_cast<EnumClass>(pos_);
}
template<class EnumClass>
const typename Matrix0D<EnumClass>::EnumClassIter&
Matrix0D<EnumClass>::EnumClassIter::operator++()
{
++pos_;
return *this;
}
template<class EnumClass>
bool
Matrix0D<EnumClass>::EnumClassIter::operator!=(const EnumClassIter& other) const
{
return pos_ != other.pos_;
}
template<class EnumClass>
typename Matrix0D<EnumClass>::EnumClassIter
Matrix0D<EnumClass>::begin()
{
return Matrix0D<EnumClass>::EnumClassIter(this, 0);
}
template<class EnumClass>
typename Matrix0D<EnumClass>::EnumClassIter
Matrix0D<EnumClass>::end()
{
return Matrix0D<EnumClass>::EnumClassIter(this, enum_class_size<EnumClass>());
}
template<class Row, typename Value, typename Accessor>
const typename Matrix1D<Row, Value, Accessor>::EnumClassIter&
Matrix1D<Row, Value, Accessor>::EnumClassIter::operator++()
{
++pos_;
return *this;
}
template<class Row, typename Value, typename Accessor>
bool
Matrix1D<Row, Value, Accessor>::EnumClassIter::operator!=(const EnumClassIter& other) const
{
return pos_ != other.pos_;
}
template<class Row, typename Value, typename Accessor>
typename Matrix1D<Row, Value, Accessor>::EnumClassIter
Matrix1D<Row, Value, Accessor>::begin()
{
return Matrix1D<Row, Value, Accessor>::EnumClassIter(this, 0);
}
template<class Row, typename Value, typename Accessor>
typename Matrix1D<Row, Value, Accessor>::EnumClassIter
Matrix1D<Row, Value, Accessor>::end()
{
return Matrix1D<Row, Value, Accessor>::EnumClassIter(this, enum_class_size<Row>());
}
} // namespace jami
| 8,606
|
C++
|
.h
| 264
| 29.075758
| 105
| 0.664578
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
751,906
|
call_factory.h
|
savoirfairelinux_jami-daemon/src/call_factory.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <map>
#include <memory>
#include <mutex>
#include <vector>
#include <string>
#include <utility>
#include "call.h"
#include "account.h"
namespace jami {
class SIPAccountBase;
class SIPCall;
class CallFactory
{
public:
CallFactory(std::mt19937_64& rand)
: rand_(rand)
{}
std::string getNewCallID() const;
/**
* Create a new call instance.
* @param account Account used to create this call
* @param type Set definitely this call as incoming/outgoing
* @param mediaList The list of media to include
* @return A shared pointer to the created call
*/
std::shared_ptr<SIPCall> newSipCall(const std::shared_ptr<SIPAccountBase>& account,
Call::CallType type,
const std::vector<libjami::MediaMap>& mediaList);
/**
* Forbid creation of new calls.
*/
void forbid();
/**
* Remove given call instance from call list.
*/
void removeCall(Call& call);
/**
* Accessor on removeCall with callID than instance.
*/
void removeCall(const std::string& id);
/**
* Return call pointer associated to given ID.Type can optionally be specified.
*/
std::shared_ptr<Call> getCall(const std::string& id) const;
std::shared_ptr<Call> getCall(const std::string& id, Call::LinkType link) const;
template<class C>
std::shared_ptr<C> getCall(const std::string& id)
{
return std::dynamic_pointer_cast<C>(getCall(id, C::LINK_TYPE));
}
/**
* Return if given call exists. Type can optionally be specified.
*/
bool hasCall(const std::string& id) const;
bool hasCall(const std::string& id, Call::LinkType link) const;
/**
* Return if calls exist. Type can optionally be specified.
*/
bool empty() const;
bool empty(Call::LinkType link) const;
/**
* Erase all calls.
*/
void clear();
/**
* Return all calls. Type can optionally be specified.
*/
std::vector<std::shared_ptr<Call>> getAllCalls() const;
std::vector<std::shared_ptr<Call>> getAllCalls(Call::LinkType link) const;
/**
* Return all call's IDs. Type can optionally be specified.
*/
std::vector<std::string> getCallIDs() const;
std::vector<std::string> getCallIDs(Call::LinkType link) const;
/**
* Return number of calls. Type can optionally be specified.
*/
std::size_t callCount() const;
std::size_t callCount(Call::LinkType link) const;
private:
/**
* @brief Get the calls map
* @param link The call type
* @return A pointer to the calls map instance
* @warning Concurrency protection must done by the caller.
*/
const CallMap* getMap_(Call::LinkType link) const
{
auto const& itermap = callMaps_.find(link);
if (itermap != callMaps_.cend())
return &itermap->second;
return nullptr;
}
std::mt19937_64& rand_;
mutable std::recursive_mutex callMapsMutex_ {};
std::atomic_bool allowNewCall_ {true};
std::map<Call::LinkType, CallMap> callMaps_ {};
};
} // namespace jami
| 3,908
|
C++
|
.h
| 116
| 28.396552
| 89
| 0.660828
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,907
|
registration_states.h
|
savoirfairelinux_jami-daemon/src/registration_states.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef REGISTERED
#undef REGISTERED
#endif
namespace jami {
/** Contains all the Registration states for an account can be in */
enum class RegistrationState {
UNLOADED,
UNREGISTERED,
TRYING,
REGISTERED,
ERROR_GENERIC,
ERROR_AUTH,
ERROR_NETWORK,
ERROR_HOST,
ERROR_SERVICE_UNAVAILABLE,
ERROR_NEED_MIGRATION,
INITIALIZING
};
} // namespace jami
| 1,121
|
C++
|
.h
| 36
| 28.388889
| 73
| 0.742831
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,908
|
ring_types.h
|
savoirfairelinux_jami-daemon/src/ring_types.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef RING_TYPES_H_
#define RING_TYPES_H_
#include <type_traits>
#include <memory>
#include <mutex>
#include <cstddef> // for size_t
#include <ciso646> // fix windows compiler bug
namespace jami {
static constexpr size_t SIZEBUF = 16000; /** About 62.5ms of buffering at 48kHz */
/**
* This meta-function is used to enable a template overload
* only if given class T is a base of class U
*/
template<class T, class U>
using enable_if_base_of = typename std::enable_if<std::is_base_of<T, U>::value, T>::type;
/**
* Return a shared pointer on an auto-generated global instance of class T.
* This instance is created only at usage and destroyed when not,
* as we keep only a weak reference on it.
* But when created it's always the same object until all holders release
* their sharing.
* An optional MaxRespawn positive integer can be given to limit the number
* of time the object can be created (i.e. different instance).
* Any negative values (default) block this effect (unlimited respawn).
* This function is thread-safe.
*/
template<class T, signed MaxRespawn = -1>
std::shared_ptr<T>
getGlobalInstance()
{
static std::recursive_mutex mutex; // recursive as instance calls recursively
static std::weak_ptr<T> wlink;
std::unique_lock<std::recursive_mutex> lock(mutex);
if (wlink.expired()) {
static signed counter {MaxRespawn};
if (not counter)
return nullptr;
auto link = std::make_shared<T>();
wlink = link;
if (counter > 0)
--counter;
return link;
}
return wlink.lock();
}
} // namespace jami
#endif // RING_TYPES_H_
| 2,364
|
C++
|
.h
| 63
| 34.349206
| 89
| 0.715909
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,909
|
conference_protocol.h
|
savoirfairelinux_jami-daemon/src/conference_protocol.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string_view>
#include <functional>
#include <json/json.h>
#include "logger.h"
namespace jami {
/**
* Used to parse confOrder objects
* @note the user of this class must initialize the different lambdas.
*/
class ConfProtocolParser
{
public:
ConfProtocolParser() {};
void onVersion(std::function<void(uint32_t)>&& cb) { version_ = std::move(cb); }
/**
* Ask the caller to check if a peer is authorized (moderator of the conference)
*/
void onCheckAuthorization(std::function<bool(std::string_view)>&& cb)
{
checkAuthorization_ = std::move(cb);
}
void onHangupParticipant(std::function<void(const std::string&, const std::string&)>&& cb)
{
hangupParticipant_ = std::move(cb);
}
void onRaiseHand(std::function<void(const std::string&, bool)>&& cb)
{
raiseHand_ = std::move(cb);
}
void onSetActiveStream(std::function<void(const std::string&, bool)>&& cb)
{
setActiveStream_ = std::move(cb);
}
void onMuteStreamAudio(
std::function<void(const std::string&, const std::string&, const std::string&, bool)>&& cb)
{
muteStreamAudio_ = std::move(cb);
}
void onMuteStreamVideo(
std::function<void(const std::string&, const std::string&, const std::string&, bool)>&& cb)
{
muteStreamVideo_ = std::move(cb);
}
void onSetLayout(std::function<void(int)>&& cb) { setLayout_ = std::move(cb); }
// Version 0, deprecated
void onKickParticipant(std::function<void(const std::string&)>&& cb)
{
kickParticipant_ = std::move(cb);
}
void onSetActiveParticipant(std::function<void(const std::string&)>&& cb)
{
setActiveParticipant_ = std::move(cb);
}
void onMuteParticipant(std::function<void(const std::string&, bool)>&& cb)
{
muteParticipant_ = std::move(cb);
}
void onRaiseHandUri(std::function<void(const std::string&, bool)>&& cb)
{
raiseHandUri_ = std::move(cb);
}
void onVoiceActivity(std::function<void(const std::string&, bool)>&& cb)
{
voiceActivity_ = std::move(cb);
}
/**
* Inject in the parser the data to parse
*/
void initData(Json::Value&& d, std::string_view peerId)
{
data_ = std::move(d);
peerId_ = peerId;
}
/**
* Parse the datas, this will call the methods injected if necessary
*/
void parse();
private:
void parseV0();
void parseV1();
std::string_view peerId_;
Json::Value data_;
std::function<void(uint32_t)> version_;
std::function<bool(std::string_view)> checkAuthorization_;
std::function<void(const std::string&, const std::string&)> hangupParticipant_;
std::function<void(const std::string&, bool)> raiseHand_;
std::function<void(const std::string&, bool)> setActiveStream_;
std::function<void(const std::string&, const std::string&, const std::string&, bool)>
muteStreamAudio_;
std::function<void(const std::string&, const std::string&, const std::string&, bool)>
muteStreamVideo_;
std::function<void(int)> setLayout_;
std::function<void(const std::string&, bool)> raiseHandUri_;
std::function<void(const std::string&)> kickParticipant_;
std::function<void(const std::string&)> setActiveParticipant_;
std::function<void(const std::string&, bool)> muteParticipant_;
std::function<void(const std::string&, bool)> voiceActivity_;
};
} // namespace jami
| 4,273
|
C++
|
.h
| 119
| 31.176471
| 99
| 0.667231
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,910
|
data_transfer.h
|
savoirfairelinux_jami-daemon/src/data_transfer.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "jami/datatransfer_interface.h"
#include "noncopyable.h"
#include <dhtnet/multiplexed_socket.h>
#include <fstream>
#include <functional>
#include <memory>
#include <optional>
#include <string>
namespace jami {
libjami::DataTransferId generateUID(std::mt19937_64& engine);
class Stream;
struct IncomingFileInfo
{
libjami::DataTransferId id;
std::shared_ptr<Stream> stream;
};
struct WaitingRequest
{
std::string fileId;
std::string interactionId;
std::string sha3sum;
std::string path;
std::size_t totalSize;
MSGPACK_DEFINE(fileId, interactionId, sha3sum, path, totalSize)
};
typedef std::function<void(const std::string&)> InternalCompletionCb;
typedef std::function<void()> OnFinishedCb;
class FileInfo
{
public:
FileInfo(const std::shared_ptr<dhtnet::ChannelSocket>& channel,
const std::string& fileId,
const std::string& interactionId,
const libjami::DataTransferInfo& info);
virtual ~FileInfo() {}
virtual void process() = 0;
std::shared_ptr<dhtnet::ChannelSocket> channel() const { return channel_; }
libjami::DataTransferInfo info() const { return info_; }
virtual void cancel() = 0;
void onFinished(std::function<void(uint32_t)>&& cb) { finishedCb_ = std::move(cb); }
void emit(libjami::DataTransferEventCode code);
protected:
std::atomic_bool isUserCancelled_ {false};
std::string fileId_ {};
std::string interactionId_ {};
libjami::DataTransferInfo info_ {};
std::shared_ptr<dhtnet::ChannelSocket> channel_ {};
std::function<void(uint32_t)> finishedCb_ {};
};
class IncomingFile : public FileInfo, public std::enable_shared_from_this<IncomingFile>
{
public:
IncomingFile(const std::shared_ptr<dhtnet::ChannelSocket>& channel,
const libjami::DataTransferInfo& info,
const std::string& fileId,
const std::string& interactionId,
const std::string& sha3Sum);
~IncomingFile();
void process() override;
void cancel() override;
private:
std::mutex streamMtx_;
std::ofstream stream_;
std::string sha3Sum_ {};
std::filesystem::path path_;
};
class OutgoingFile : public FileInfo
{
public:
OutgoingFile(const std::shared_ptr<dhtnet::ChannelSocket>& channel,
const std::string& fileId,
const std::string& interactionId,
const libjami::DataTransferInfo& info,
size_t start = 0,
size_t end = 0);
~OutgoingFile();
void process() override;
void cancel() override;
private:
std::ifstream stream_;
size_t start_ {0};
size_t end_ {0};
};
class TransferManager : public std::enable_shared_from_this<TransferManager>
{
public:
TransferManager(const std::string& accountId, const std::string& accountUri, const std::string& to, const std::mt19937_64& rand);
~TransferManager();
/**
* Send a file to a channel
* @param channel channel to use
* @param fileId fileId of the transfer
* @param interactionId interactionId of the transfer
* @param path path of the file
* @param start start offset
* @param end end
*/
void transferFile(const std::shared_ptr<dhtnet::ChannelSocket>& channel,
const std::string& fileId,
const std::string& interactionId,
const std::string& path,
size_t start = 0,
size_t end = 0,
OnFinishedCb onFinished = {});
/**
* Refuse a transfer
* @param id of the transfer
*/
bool cancel(const std::string& fileId);
/**
* Get current transfer info
* @param id of the transfer
* @param total size
* @param path path of the file
* @param progress current progress
* @return if found
*/
bool info(const std::string& fileId,
std::string& path,
int64_t& total,
int64_t& progress) const noexcept;
/**
* Inform the transfer manager that a transfer is waited (and will be automatically accepted)
* @param id of the transfer
* @param interactionId linked interaction
* @param sha3sum attended sha3sum
* @param path where the file will be downloaded
* @param total total size of the file
*/
void waitForTransfer(const std::string& fileId,
const std::string& interactionId,
const std::string& sha3sum,
const std::string& path,
std::size_t total);
/**
* Handle incoming transfer
* @param id Related id
* @param channel Related channel
*/
void onIncomingFileTransfer(const std::string& fileId,
const std::shared_ptr<dhtnet::ChannelSocket>& channel);
/**
* Retrieve path of a file
* @param id
*/
std::filesystem::path path(const std::string& fileId) const;
/**
* Retrieve waiting files
* @return waiting list
*/
std::vector<WaitingRequest> waitingRequests() const;
bool isWaiting(const std::string& fileId) const;
void onIncomingProfile(const std::shared_ptr<dhtnet::ChannelSocket>& channel, const std::string& sha3Sum = "");
/**
* @param contactId contact's id
* @return where profile.vcf is stored
*/
std::filesystem::path profilePath(const std::string& contactId) const;
private:
std::weak_ptr<TransferManager> weak()
{
return std::static_pointer_cast<TransferManager>(shared_from_this());
}
NON_COPYABLE(TransferManager);
class Impl;
std::unique_ptr<Impl> pimpl_;
};
} // namespace jami
| 6,614
|
C++
|
.h
| 185
| 29.405405
| 133
| 0.642511
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,911
|
account_config.h
|
savoirfairelinux_jami-daemon/src/account_config.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "connectivity/sip_utils.h"
#include "config/serializable.h"
#include "string_utils.h"
#include <string>
#include <string_view>
#include <utility>
#include <map>
#include <filesystem>
using namespace std::literals;
namespace jami {
constexpr const char* const DEFAULT_RINGTONE_PATH = "default.opus";
struct AccountConfig : public Serializable
{
AccountConfig(const std::string& type_, const std::string& id_, const std::filesystem::path& path_ = {})
: type(type_)
, id(id_)
, path(path_)
{}
void serializeDiff(YAML::Emitter& out, const AccountConfig& def) const;
virtual void serialize(YAML::Emitter& out) const = 0;
virtual void unserialize(const YAML::Node& node);
virtual std::map<std::string, std::string> toMap() const;
virtual void fromMap(const std::map<std::string, std::string>&);
/** Account type */
const std::string type;
/** Account id */
const std::string id;
/** Path where the configuration file is stored.
* Part of the context but not stored in the configuration
* Used to compute relative paths for configuraton fields */
const std::filesystem::path path;
/** A user-defined name for this account */
std::string alias {};
std::string username {};
/** SIP hostname (SIP account) or DHT bootstrap nodes (Jami account) */
std::string hostname {};
/** True if the account is enabled. */
bool enabled {true};
/** If true, automatically answer calls to this account */
bool autoAnswerEnabled {false};
/** If true, send displayed status (and emit to the client) */
bool sendReadReceipt {true};
/** If true, send composing status (and emit to the client) */
bool sendComposing {true};
/** If true mix calls into a conference */
bool isRendezVous {false};
/**
* The number of concurrent calls for the account
* -1: Unlimited
* 0: Do not disturb
* 1: Single call
* +: Multi line
*/
int activeCallLimit {-1};
std::vector<unsigned> activeCodecs {};
/**
* Play ringtone when receiving a call
*/
bool ringtoneEnabled {true};
/**
* Ringtone file used for this account
*/
std::string ringtonePath {DEFAULT_RINGTONE_PATH};
/**
* Allows user to temporarily disable video calling
*/
bool videoEnabled {true};
/**
* Display name when calling
*/
std::string displayName {};
/**
* User-agent used for registration
*/
std::string customUserAgent {};
/**
* Account mail box
*/
std::string mailbox {};
/**
* UPnP IGD controller and the mutex to access it
*/
bool upnpEnabled {true};
std::set<std::string> defaultModerators {};
bool localModeratorsEnabled {true};
bool allModeratorsEnabled {true};
/**
* Device push notification token.
*/
std::string deviceKey {};
/**
* Device push notification platform.
*/
std::string platform {};
/**
* Push notification topic.
*/
std::string notificationTopic {};
/**
* information about the customization of ui
*/
std::string uiCustomization {};
};
inline void
parseString(const std::map<std::string, std::string>& details, const char* key, std::string& s)
{
auto it = details.find(key);
if (it != details.end())
s = it->second;
}
inline void
parseBool(const std::map<std::string, std::string>& details, const char* key, bool& s)
{
auto it = details.find(key);
if (it != details.end())
s = it->second == TRUE_STR;
}
template<class T>
inline void
parseInt(const std::map<std::string, std::string>& details, const char* key, T& s)
{
auto it = details.find(key);
if (it != details.end())
s = to_int<T>(it->second);
}
void parsePath(const std::map<std::string, std::string>& details,
const char* key,
std::string& s,
const std::filesystem::path& base);
} // namespace jami
| 4,769
|
C++
|
.h
| 147
| 27.755102
| 108
| 0.658744
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,912
|
utf8_utils.h
|
savoirfairelinux_jami-daemon/src/connectivity/utf8_utils.h
|
/*
* Copyright (C) 1999 Tom Tromey
* Copyright (C) 2000 Red Hat, Inc.
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* Author: Pascal Potvin <pascal.potvin@extenway.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cstdlib>
#include <string>
namespace jami {
/**
* utf8_validate:
*
* Validates UTF-8 encoded text. @str is the text to validate;
*
* Returns true if all of @str was valid. Dbus requires valid UTF-8 as input;
* sip packets should also be encoded in utf8; so data read from a file or the
* network should be checked with utf8_validate() before doing anything else
* with it.
*
* Returns: true if the text was valid UTF-8
*/
bool utf8_validate(std::string_view str);
/**
* utf8_make_valid:
* @name: a pointer to a nul delimited string.
*
* Transforms a unknown c_string into a pretty utf8 encoded std::string.
* Every unreadable or invalid byte will be transformed into U+FFFD
* (REPLACEMENT CHARACTER).
*
* Returns: a valid utf8 string.
*/
std::string utf8_make_valid(std::string_view str);
} // namespace jami
| 1,704
|
C++
|
.h
| 49
| 32.857143
| 78
| 0.737417
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,913
|
ip_utils.h
|
savoirfairelinux_jami-daemon/src/connectivity/ip_utils.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
namespace jami {
namespace ip_utils {
std::string getDeviceName();
} // namespace ip_utils
} // namespace jami
| 863
|
C++
|
.h
| 23
| 35.695652
| 73
| 0.75
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,914
|
sip_utils.h
|
savoirfairelinux_jami-daemon/src/connectivity/sip_utils.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "connectivity/ip_utils.h"
#include "media/media_codec.h"
#include "noncopyable.h"
#include <utility>
#include <string>
#include <vector>
#include <cstring> // strcmp
#include <dhtnet/ip_utils.h>
#include <pjsip/sip_msg.h>
#include <pjlib.h>
#include <pj/pool.h>
#include <pjsip/sip_endpoint.h>
#include <pjsip/sip_dialog.h>
namespace jami {
namespace sip_utils {
using namespace std::literals;
// SIP methods. Only list methods that need to be explicitly
// handled
namespace SIP_METHODS {
constexpr std::string_view MESSAGE = "MESSAGE"sv;
constexpr std::string_view INFO = "INFO"sv;
constexpr std::string_view OPTIONS = "OPTIONS"sv;
constexpr std::string_view PUBLISH = "PUBLISH"sv;
constexpr std::string_view REFER = "REFER"sv;
constexpr std::string_view NOTIFY = "NOTIFY"sv;
} // namespace SIP_METHODS
static constexpr int DEFAULT_SIP_PORT {5060};
static constexpr int DEFAULT_SIP_TLS_PORT {5061};
static constexpr int DEFAULT_AUTO_SELECT_PORT {0};
/// PjsipErrorCategory - a PJSIP error category for std::error_code
class PjsipErrorCategory final : public std::error_category
{
public:
const char* name() const noexcept override { return "pjsip"; }
std::string message(int condition) const override;
};
/// PJSIP related exception
/// Based on std::system_error with code() returning std::error_code with PjsipErrorCategory category
class PjsipFailure : public std::system_error
{
private:
static constexpr const char* what_ = "PJSIP call failed";
public:
PjsipFailure()
: std::system_error(std::error_code(PJ_EUNKNOWN, PjsipErrorCategory()), what_)
{}
explicit PjsipFailure(pj_status_t status)
: std::system_error(std::error_code(status, PjsipErrorCategory()), what_)
{}
};
std::string sip_strerror(pj_status_t code);
// Helper function that return a constant pj_str_t from an array of any types
// that may be statically casted into char pointer.
// Per convention, the input array is supposed to be null terminated.
template<typename T, std::size_t N>
constexpr const pj_str_t
CONST_PJ_STR(T (&a)[N]) noexcept
{
return {const_cast<char*>(a), N - 1};
}
inline const pj_str_t
CONST_PJ_STR(const std::string& str) noexcept
{
return {const_cast<char*>(str.c_str()), (pj_ssize_t) str.size()};
}
inline constexpr pj_str_t
CONST_PJ_STR(const std::string_view& str) noexcept
{
return {const_cast<char*>(str.data()), (pj_ssize_t) str.size()};
}
inline constexpr std::string_view
as_view(const pj_str_t& str) noexcept
{
return {str.ptr, (size_t) str.slen};
}
static constexpr const char*
getKeyExchangeName(KeyExchangeProtocol kx)
{
return kx == KeyExchangeProtocol::SDES ? "sdes" : "";
}
static inline KeyExchangeProtocol
getKeyExchangeProtocol(std::string_view name)
{
return name == "sdes"sv ? KeyExchangeProtocol::SDES : KeyExchangeProtocol::NONE;
}
/**
* Helper function to parser header from incoming sip messages
* @return Header from SIP message
*/
std::string fetchHeaderValue(pjsip_msg* msg, const std::string& field);
pjsip_route_hdr* createRouteSet(const std::string& route, pj_pool_t* hdr_pool);
std::string_view stripSipUriPrefix(std::string_view sipUri);
std::string parseDisplayName(const pjsip_name_addr* sip_name_addr);
std::string parseDisplayName(const pjsip_from_hdr* header);
std::string parseDisplayName(const pjsip_contact_hdr* header);
std::string_view getHostFromUri(std::string_view sipUri);
void addContactHeader(const std::string& contact, pjsip_tx_data* tdata);
void addUserAgentHeader(const std::string& userAgent, pjsip_tx_data* tdata);
std::string_view getPeerUserAgent(const pjsip_rx_data* rdata);
std::vector<std::string> getPeerAllowMethods(const pjsip_rx_data* rdata);
void logMessageHeaders(const pjsip_hdr* hdr_list);
constexpr std::string_view DEFAULT_VIDEO_STREAMID = "video_0";
constexpr std::string_view DEFAULT_AUDIO_STREAMID = "audio_0";
std::string streamId(const std::string& callId, std::string_view label);
// PJSIP dialog locking in RAII way
// Usage: declare local variable like this: sip_utils::PJDialogLock lock {dialog};
// The lock is kept until the local variable is deleted
class PJDialogLock
{
public:
explicit PJDialogLock(pjsip_dialog* dialog)
: dialog_(dialog)
{
pjsip_dlg_inc_lock(dialog_);
}
~PJDialogLock() { pjsip_dlg_dec_lock(dialog_); }
private:
NON_COPYABLE(PJDialogLock);
pjsip_dialog* dialog_ {nullptr};
};
// Helper on PJSIP memory pool allocation from endpoint
// This encapsulate the allocated memory pool inside a unique_ptr
static inline std::unique_ptr<pj_pool_t, decltype(pj_pool_release)&>
smart_alloc_pool(pjsip_endpoint* endpt, const char* const name, pj_size_t initial, pj_size_t inc)
{
auto pool = pjsip_endpt_create_pool(endpt, name, initial, inc);
if (not pool)
throw std::bad_alloc();
return std::unique_ptr<pj_pool_t, decltype(pj_pool_release)&>(pool, pj_pool_release);
}
void sockaddr_to_host_port(pj_pool_t* pool, pjsip_host_port* host_port, const pj_sockaddr* addr);
static constexpr int POOL_TP_INIT {512};
static constexpr int POOL_TP_INC {512};
static constexpr int TRANSPORT_INFO_LENGTH {64};
} // namespace sip_utils
} // namespace jami
| 5,933
|
C++
|
.h
| 153
| 36.594771
| 101
| 0.750914
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,915
|
memory.h
|
savoirfairelinux_jami-daemon/src/connectivity/security/memory.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef __cplusplus
#include <cstddef>
#else
#include <stddef.h>
#endif
// C-callable versions of C++ APIs.
#ifdef __cplusplus
namespace {
extern "C" {
#endif
void ring_secure_memzero(void* ptr, size_t length);
#ifdef __cplusplus
};
}
namespace jami {
namespace secure {
/// Erase with \a size '0' the given memory starting at \a ptr pointer.
void memzero(void* ptr, std::size_t length);
} // namespace secure
} // namespace jami
#endif // __cplusplus
| 1,189
|
C++
|
.h
| 38
| 29.684211
| 73
| 0.742782
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,916
|
tlsvalidator.h
|
savoirfairelinux_jami-daemon/src/connectivity/security/tlsvalidator.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "enumclass_utils.h"
#include <dhtnet/certstore.h>
#include <string>
#include <vector>
#include <memory>
// OpenDHT
namespace dht {
namespace crypto {
struct Certificate;
}
} // namespace dht
namespace jami {
namespace tls {
#if !defined(S_IRWXG)
#define S_IRWXG 00070
#endif /* S_IRWXG */
#if !defined(S_IRGRP)
#define S_IRGRP 00040
#endif /* S_IRGRP */
#if !defined(S_IWGRP)
#define S_IWGRP 00020
#endif /* S_IWGRP */
#if !defined(S_IXGRP)
#define S_IXGRP 00010
#endif /* S_IXGRP */
#if !defined(S_IRWXO)
#define S_IRWXO 00007
#endif /* S_IRWXO */
#if !defined(S_IROTH)
#define S_IROTH 00004
#endif /* S_IROTH */
#if !defined(S_IWOTH)
#define S_IWOTH 00002
#endif /* S_IWOTH */
#if !defined(S_IXOTH)
#define S_IXOTH 00001
#endif /* S_IXOTH */
class TlsValidatorException : public std::runtime_error
{
public:
TlsValidatorException(const std::string& str)
: std::runtime_error(str) {};
};
class TlsValidator
{
public:
/**
* @enum CertificateCheck All validation fields
*
*/
enum class CertificateCheck {
HAS_PRIVATE_KEY, /** This certificate has a build in private key */
EXPIRED, /** This certificate is past its expiration date */
STRONG_SIGNING, /** This certificate has been signed with a brute-force-able method */
NOT_SELF_SIGNED, /** This certificate has been self signed */
KEY_MATCH, /** The public and private keys provided don't match */
PRIVATE_KEY_STORAGE_PERMISSION, /** The file hosting the private key isn't correctly secured */
PUBLIC_KEY_STORAGE_PERMISSION, /** The file hosting the public key isn't correctly secured */
PRIVATE_KEY_DIRECTORY_PERMISSIONS, /** The folder storing the private key isn't correctly
secured */
PUBLIC_KEY_DIRECTORY_PERMISSIONS, /** The folder storing the public key isn't correctly
secured */
PRIVATE_KEY_STORAGE_LOCATION, /** Some operating systems have extra policies for certificate
storage */
PUBLIC_KEY_STORAGE_LOCATION, /** Some operating systems have extra policies for certificate
storage */
PRIVATE_KEY_SELINUX_ATTRIBUTES, /** Some operating systems require keys to have extra
attributes */
PUBLIC_KEY_SELINUX_ATTRIBUTES, /** Some operating systems require keys to have extra
attributes */
EXIST, /** The certificate file doesn't exist or is not accessible */
VALID, /** The file is not a certificate */
VALID_AUTHORITY, /** The claimed authority did not sign the certificate */
KNOWN_AUTHORITY, /** Some operating systems provide a list of trusted authorities, use it */
NOT_REVOKED, /** The certificate has been revoked by the authority */
AUTHORITY_MISMATCH, /** The certificate and authority mismatch */
UNEXPECTED_OWNER, /** The certificate has an expected owner */
NOT_ACTIVATED, /** The certificate has not been activated yet */
COUNT__,
};
/**
* @enum CertificateDetails Informative fields about a certificate
*/
enum class CertificateDetails {
EXPIRATION_DATE, /** The certificate expiration date */
ACTIVATION_DATE, /** The certificate activation date */
REQUIRE_PRIVATE_KEY_PASSWORD, /** Does the private key require a password */
PUBLIC_SIGNATURE,
VERSION_NUMBER,
SERIAL_NUMBER,
ISSUER,
SUBJECT_KEY_ALGORITHM,
SUBJECT_KEY,
CN,
UID,
N,
O,
SIGNATURE_ALGORITHM,
MD5_FINGERPRINT,
SHA1_FINGERPRINT,
PUBLIC_KEY_ID,
ISSUER_DN,
ISSUER_CN,
ISSUER_UID,
ISSUER_N,
ISSUER_O,
NEXT_EXPECTED_UPDATE_DATE,
OUTGOING_SERVER, /** The hostname/outgoing server used for this certificate */
IS_CA,
COUNT__
};
/**
* @enum CheckValuesType Categories of possible values for each CertificateCheck
*/
enum class CheckValuesType {
BOOLEAN,
ISO_DATE,
CUSTOM,
NUMBER,
COUNT__,
};
/**
* @enum CheckValue possible values for check
*
* All boolean check use PASSED when the test result is positive and
* FAILED when it is negative. All new check need to keep this convention
* or ::isValid() result will become unrepresentative of the real state.
*
* CUSTOM should be avoided when possible. This enum can be extended when
* new validated types are required.
*/
enum class CheckValues {
PASSED, /** Equivalent of a boolean "true" */
FAILED, /** Equivalent of a boolean "false" */
UNSUPPORTED, /** The operating system doesn't support or require the check */
ISO_DATE, /** The check value is an ISO 8601 date YYYY-MM-DD[TH24:MM:SS+00:00] */
CUSTOM, /** The check value cannot be represented with a finite set of values */
NUMBER,
COUNT__,
};
/**
* @typedef CheckResult A validated and unvalidated result pair
*
* The CheckValue is the most important value of the pair. The string
* can either be the value of a CheckValues::CUSTOM result or an
* error code (where applicable).
*/
using CheckResult = std::pair<CheckValues, std::string>;
/**
* Create a TlsValidator for a given certificate
* @param certificate The certificate path
* @param privatekey An optional private key file path
* @param privatekeyPasswd An optional private key password
* @param caList An optional CA list to use for certificate validation
*/
TlsValidator(const dhtnet::tls::CertificateStore& certStore,
const std::string& certificate,
const std::string& privatekey = "",
const std::string& privatekeyPasswd = "",
const std::string& caList = "");
TlsValidator(const dhtnet::tls::CertificateStore& certStore, const std::vector<std::vector<uint8_t>>& certificate_chain_raw);
TlsValidator(const dhtnet::tls::CertificateStore& certStore, const std::vector<uint8_t>& certificate_raw);
TlsValidator(const dhtnet::tls::CertificateStore& certStore, const std::shared_ptr<dht::crypto::Certificate>&);
~TlsValidator();
bool hasCa() const;
bool isValid(bool verbose = false);
// Security checks
CheckResult hasPrivateKey();
CheckResult notExpired();
CheckResult strongSigning();
CheckResult notSelfSigned();
CheckResult keyMatch();
CheckResult privateKeyStoragePermissions();
CheckResult publicKeyStoragePermissions();
CheckResult privateKeyDirectoryPermissions();
CheckResult publicKeyDirectoryPermissions();
CheckResult privateKeyStorageLocation();
CheckResult publicKeyStorageLocation();
CheckResult privateKeySelinuxAttributes();
CheckResult publicKeySelinuxAttributes();
CheckResult exist();
CheckResult valid();
CheckResult validAuthority();
CheckResult knownAuthority();
CheckResult notRevoked();
CheckResult authorityMatch();
CheckResult expectedOwner();
CheckResult activated();
// Certificate details
CheckResult getExpirationDate();
CheckResult getActivationDate();
CheckResult requirePrivateKeyPassword();
CheckResult getPublicSignature();
CheckResult getVersionNumber();
CheckResult getSerialNumber();
CheckResult getIssuer();
CheckResult getSubjectKeyAlgorithm();
CheckResult getSubjectKey();
CheckResult getCN();
CheckResult getUID();
CheckResult getN();
CheckResult getO();
CheckResult getSignatureAlgorithm();
CheckResult getMd5Fingerprint();
CheckResult getSha1Fingerprint();
CheckResult getPublicKeyId();
CheckResult getIssuerDN();
CheckResult getIssuerCN();
CheckResult getIssuerUID();
CheckResult getIssuerN();
CheckResult getIssuerO();
CheckResult outgoingServer();
CheckResult isCA();
void setCaTlsValidator(const TlsValidator& validator);
std::map<std::string, std::string> getSerializedChecks();
std::map<std::string, std::string> getSerializedDetails();
std::shared_ptr<dht::crypto::Certificate> getCertificate() const { return x509crt_; }
private:
// Enum class names
static const EnumClassNames<CertificateCheck> CertificateCheckNames;
static const EnumClassNames<CertificateDetails> CertificateDetailsNames;
static const EnumClassNames<const CheckValuesType> CheckValuesTypeNames;
static const EnumClassNames<CheckValues> CheckValuesNames;
/**
* Map check to their check method
*/
static const CallbackMatrix1D<CertificateCheck, TlsValidator, CheckResult> checkCallback;
/**
* Map check to their getter method
*/
static const CallbackMatrix1D<CertificateDetails, TlsValidator, CheckResult> getterCallback;
/**
* Valid values for each categories
*/
static const Matrix2D<CheckValuesType, CheckValues, bool> acceptedCheckValuesResult;
static const Matrix1D<CertificateCheck, CheckValuesType> enforcedCheckType;
const dhtnet::tls::CertificateStore& certStore_;
std::string certificatePath_;
std::string privateKeyPath_;
std::string caListPath_ {};
std::vector<uint8_t> certificateContent_;
std::shared_ptr<dht::crypto::Certificate> x509crt_;
bool certificateFileFound_ {false};
bool certificateFound_ {false};
bool privateKeyFound_ {false};
bool privateKeyPassword_ {false};
bool privateKeyMatch_ {false};
bool caChecked_ {false};
unsigned int caValidationOutput_ {
0}; // 0 means "no flags set", where flags are ones from gnutls_certificate_status_t
mutable char copy_buffer[4096];
/**
* Helper method to convert a CheckResult into a std::string
*/
std::string getStringValue(const CertificateCheck check, const CheckResult result);
// Helper
unsigned int compareToCa();
public:
#if 0 // TODO reimplement this method. do not use it as it
/**
* Verify that the local hostname points to a valid SSL server by
* establishing a connection to it and by validating its certificate.
*
* @param host the DNS domain address that the certificate should feature
* @return 0 if success, -1 otherwise
*/
static int verifyHostnameCertificate(const std::string& host,
const uint16_t port);
#endif
}; // TlsValidator
} // namespace tls
} // namespace jami
| 11,935
|
C++
|
.h
| 289
| 34.910035
| 129
| 0.655434
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,917
|
trace-tools.h
|
savoirfairelinux_jami-daemon/src/jami/trace-tools.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef ENABLE_TRACEPOINTS
/*
* GCC Only. We use these instead of classic __FILE__ and __LINE__ because
* these are evaluated where invoked and not at expansion time. See GCC manual.
*/
# define CURRENT_FILENAME() __builtin_FILE()
# define CURRENT_LINE() __builtin_LINE()
#else
# define CURRENT_FILENAME() ""
# define CURRENT_LINE() 0
#endif
#ifdef HAVE_CXXABI_H
#include <cxxabi.h>
#include <string>
template<typename T>
std::string demangle()
{
int err;
char *raw;
std::string ret;
raw = abi::__cxa_demangle(typeid(T).name(), 0, 0, &err);
if (0 == err) {
ret = raw;
} else {
ret = typeid(T).name();
}
std::free(raw);
return ret;
}
#else
template<typename T>
std::string demangle()
{
return typeid(T).name();
}
#endif
| 1,529
|
C++
|
.h
| 53
| 26.301887
| 80
| 0.695504
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,918
|
datatransfer_interface.h
|
savoirfairelinux_jami-daemon/src/jami/datatransfer_interface.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LIBJAMI_DATATRANSFERI_H
#define LIBJAMI_DATATRANSFERI_H
#include "def.h"
#include "jami.h"
#include <string>
#include <map>
#include <vector>
#include <memory>
#include <bitset>
namespace libjami {
[[deprecated("Replaced by registerSignalHandlers")]] LIBJAMI_PUBLIC void registerDataXferHandlers(
const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>&);
using DataTransferId = uint64_t;
enum class LIBJAMI_PUBLIC DataTransferEventCode : uint32_t {
invalid = 0,
created,
unsupported,
wait_peer_acceptance,
wait_host_acceptance,
ongoing,
finished,
closed_by_host,
closed_by_peer,
invalid_pathname,
unjoinable_peer,
timeout_expired,
};
enum class LIBJAMI_PUBLIC DataTransferError : uint32_t {
success = 0,
unknown,
io,
invalid_argument,
};
/// Bit definition for DataTransferInfo.flags field
enum class LIBJAMI_PUBLIC DataTransferFlags {
direction = 0, ///< 0: outgoing, 1: incoming
};
struct LIBJAMI_PUBLIC DataTransferInfo
{
std::string accountId; ///< Identifier of the emiter/receiver account
DataTransferEventCode lastEvent {
DataTransferEventCode::invalid}; ///< Latest event code sent to the user
uint32_t flags {0}; ///< Transfer global information.
int64_t totalSize {0}; ///< Total number of bytes to sent/receive, 0 if not known
int64_t bytesProgress {0}; ///< Number of bytes sent/received
std::string author;
std::string peer; ///< Identifier of the remote peer (in the semantic of the associated account)
std::string conversationId;
std::string displayName; ///< Human oriented transfer name
std::string path; ///< associated local file path if supported (empty, if not)
std::string mimetype; ///< MimeType of transferred data
///< (https://www.iana.org/assignments/media-types/media-types.xhtml)
};
/// Asynchronously send a file to a peer using given account connection.
///
/// If given account supports a file transfer protocol this function creates
/// an internal data transfer and return its identification.
/// This identity code is used by signals and APIs to follow the transfer progress.
///
/// Following the \a info structure fields usage:
/// - accountId [mandatory] existing account ID with file transfer support
/// - peer [mandatory] peer address suitable for the given account
/// - path [mandatory] pathname of file to transfer
/// - mimetype [optional] file type
/// - displayName [optional] textual representation given to the peer when the file is proposed
///
/// Other fields are not used, but you must keep the default assigned value for compatibility.
///
/// \param info a DataTransferInfo structure filled with information useful for a file transfer.
/// \param[out] id data transfer identifiant if function succeed, usable with other APIs. Undefined
/// value in case of error.
///
/// \return DataTransferError::success if file is accepted for transfer, any other value in case of
/// errors \note If the account is valid but doesn't support file transfer, or if the peer is
/// unjoignable, or at any further events during the transfer, the function returns a valid
/// DataTransferId as the processing is asynchronous. Application will be signaled throught
/// DataTransferEvent signal for such event. There is no reserved or special values on
/// DataTransferId type.
///
LIBJAMI_PUBLIC void sendFile(const std::string& accountId,
const std::string& conversationId,
const std::string& path,
const std::string& displayName,
const std::string& replyTo) noexcept;
/// Asks for retransferring a file. Generally this means that the file is missing
/// from the conversation
///
/// \param accountId
/// \param conversationId
/// \param fileId
/// \param path
///
LIBJAMI_PUBLIC bool downloadFile(const std::string& accountId,
const std::string& conversationId,
const std::string& interactionId,
const std::string& fileId,
const std::string& path) noexcept;
/// Refuse or abort an outgoing or an incoming file transfer.
///
/// Use this function when you receive an incoming or when you want to abort an outgoing
/// data transfer.
/// The cancellation will occurs asynchronously, a cancel event will be generated when its effective.
/// This function can be used only once per data transfer identifiant, when used more it's ignored.
///
/// \param id data transfer identification value as given by a DataTransferEvent signal.
///
/// \return DataTransferError::invalid_argument if id is unknown.
/// \note unknown \a id results to a no-op call.
///
DataTransferError cancelDataTransfer(const std::string& accountId,
const std::string& conversationId,
const std::string& fileId) noexcept LIBJAMI_PUBLIC;
/// Return the amount of sent/received bytes of an existing data transfer.
///
/// \param id data transfer identification value as given by a DataTransferEvent signal.
/// \param[out] total positive number of bytes to sent/received, or -1 if unknown.
/// \param[out] progress positive number of bytes already sent/received.
///
/// \return DataTransferError::success if \a total and \a progress is set with valid values.
/// DataTransferError::invalid_argument if the id is unknown.
///
LIBJAMI_PUBLIC DataTransferError fileTransferInfo(const std::string& accountId,
const std::string& conversationId,
const std::string& fileId,
std::string& path,
int64_t& total,
int64_t& progress) noexcept;
// Signals
struct LIBJAMI_PUBLIC DataTransferSignal
{
struct LIBJAMI_PUBLIC DataTransferEvent
{
constexpr static const char* name = "DataTransferEvent";
using cb_type = void(const std::string& accountId,
const std::string& conversationId,
const std::string& interactionId,
const std::string& fileId,
int eventCode);
};
};
} // namespace libjami
#endif // LIBJAMI_DATATRANSFERI_H
| 7,310
|
C++
|
.h
| 158
| 39.550633
| 101
| 0.67419
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,919
|
presence_const.h
|
savoirfairelinux_jami-daemon/src/jami/presence_const.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LIBJAMI_PRESENCE_CONST_H
#define LIBJAMI_PRESENCE_CONST_H
#include "def.h"
namespace libjami {
namespace Presence {
constexpr static const char* BUDDY_KEY = "Buddy";
constexpr static const char* STATUS_KEY = "Status";
constexpr static const char* LINESTATUS_KEY = "LineStatus";
constexpr static const char* ONLINE_KEY = "Online";
constexpr static const char* OFFLINE_KEY = "Offline";
} // namespace Presence
} // namespace libjami
#endif
| 1,170
|
C++
|
.h
| 29
| 38.586207
| 73
| 0.761023
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,920
|
account_const.h
|
savoirfairelinux_jami-daemon/src/jami/account_const.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LIBJAMI_ACCOUNT_H
#define LIBJAMI_ACCOUNT_H
#include "def.h"
// Defined in windows.h
#ifdef ERROR
#undef ERROR
#endif
namespace libjami {
namespace Account {
namespace ProtocolNames {
constexpr static const char SIP[] = "SIP";
constexpr static const char IP2IP[] = "IP2IP";
constexpr static const char RING[] = "RING";
constexpr static const char JAMI[] = "JAMI";
} // namespace ProtocolNames
namespace States {
constexpr static const char REGISTERED[] = "REGISTERED";
constexpr static const char READY[] = "READY";
constexpr static const char UNREGISTERED[] = "UNREGISTERED";
constexpr static const char TRYING[] = "TRYING";
constexpr static const char ERROR[] = "ERROR";
constexpr static const char ERROR_GENERIC[] = "ERROR_GENERIC";
constexpr static const char ERROR_AUTH[] = "ERROR_AUTH";
constexpr static const char ERROR_NETWORK[] = "ERROR_NETWORK";
constexpr static const char ERROR_HOST[] = "ERROR_HOST";
constexpr static const char ERROR_CONF_STUN[] = "ERROR_CONF_STUN";
constexpr static const char ERROR_EXIST_STUN[] = "ERROR_EXIST_STUN";
constexpr static const char ERROR_SERVICE_UNAVAILABLE[] = "ERROR_SERVICE_UNAVAILABLE";
constexpr static const char ERROR_NOT_ACCEPTABLE[] = "ERROR_NOT_ACCEPTABLE";
constexpr static const char ERROR_MISSING_ID[] = "ERROR_MISSING_ID";
constexpr static const char ERROR_NEED_MIGRATION[] = "ERROR_NEED_MIGRATION";
constexpr static const char REQUEST_TIMEOUT[] = "Request Timeout";
constexpr static const char INITIALIZING[] = "INITIALIZING";
} // namespace States
enum class MessageStates : int {
UNKNOWN = 0,
SENDING,
SENT,
DISPLAYED,
FAILURE,
CANCELLED
}; // libjami::Account::MessageStates
namespace VolatileProperties {
constexpr static const char ACTIVE[] = "Account.active";
constexpr static const char DEVICE_ANNOUNCED[] = "Account.deviceAnnounced";
constexpr static const char DHT_BOUND_PORT[] = "Account.dhtBoundPort";
constexpr static const char REGISTERED_NAME[] = "Account.registeredName";
// Volatile parameters
namespace Registration {
constexpr static const char STATUS[] = "Account.registrationStatus";
constexpr static const char STATE_CODE[] = "Account.registrationCode";
constexpr static const char STATE_DESC[] = "Account.registrationDescription";
} // namespace Registration
namespace Transport {
constexpr static const char STATE_CODE[] = "Transport.statusCode";
constexpr static const char STATE_DESC[] = "Transport.statusDescription";
} // namespace Transport
namespace InstantMessaging {
constexpr static const char OFF_CALL[] = "IM.offCall";
}
} // namespace VolatileProperties
namespace ConfProperties {
constexpr static const char ID[] = "Account.id";
constexpr static const char TYPE[] = "Account.type";
constexpr static const char ALIAS[] = "Account.alias";
constexpr static const char DISPLAYNAME[] = "Account.displayName";
constexpr static const char ENABLED[] = "Account.enable";
constexpr static const char MAILBOX[] = "Account.mailbox";
constexpr static const char DTMF_TYPE[] = "Account.dtmfType";
constexpr static const char AUTOANSWER[] = "Account.autoAnswer";
constexpr static const char SENDREADRECEIPT[] = "Account.sendReadReceipt";
constexpr static const char SENDCOMPOSING[] = "Account.sendComposing";
constexpr static const char ISRENDEZVOUS[] = "Account.rendezVous";
constexpr static const char ACTIVE_CALL_LIMIT[] = "Account.activeCallLimit";
constexpr static const char HOSTNAME[] = "Account.hostname";
constexpr static const char USERNAME[] = "Account.username";
constexpr static const char BIND_ADDRESS[] = "Account.bindAddress";
constexpr static const char ROUTE[] = "Account.routeset";
constexpr static const char PASSWORD[] = "Account.password";
constexpr static const char REALM[] = "Account.realm";
constexpr static const char LOCAL_INTERFACE[] = "Account.localInterface";
constexpr static const char PUBLISHED_SAMEAS_LOCAL[] = "Account.publishedSameAsLocal";
constexpr static const char LOCAL_PORT[] = "Account.localPort";
constexpr static const char PUBLISHED_PORT[] = "Account.publishedPort";
constexpr static const char PUBLISHED_ADDRESS[] = "Account.publishedAddress";
constexpr static const char USER_AGENT[] = "Account.useragent";
constexpr static const char UPNP_ENABLED[] = "Account.upnpEnabled";
constexpr static const char HAS_CUSTOM_USER_AGENT[] = "Account.hasCustomUserAgent";
constexpr static const char ALLOW_CERT_FROM_HISTORY[] = "Account.allowCertFromHistory";
constexpr static const char ALLOW_CERT_FROM_CONTACT[] = "Account.allowCertFromContact";
constexpr static const char ALLOW_CERT_FROM_TRUSTED[] = "Account.allowCertFromTrusted";
constexpr static const char ARCHIVE_PASSWORD_SCHEME[] = "Account.archivePasswordScheme";
constexpr static const char ARCHIVE_PASSWORD[] = "Account.archivePassword";
constexpr static const char ARCHIVE_HAS_PASSWORD[] = "Account.archiveHasPassword";
constexpr static const char ARCHIVE_PATH[] = "Account.archivePath";
constexpr static const char ARCHIVE_PIN[] = "Account.archivePIN";
constexpr static const char DEVICE_ID[] = "Account.deviceID";
constexpr static const char DEVICE_NAME[] = "Account.deviceName";
constexpr static const char PROXY_ENABLED[] = "Account.proxyEnabled";
constexpr static const char PROXY_LIST_ENABLED[] = "Account.proxyListEnabled";
constexpr static const char PROXY_SERVER[] = "Account.proxyServer";
constexpr static const char PROXY_PUSH_TOKEN[] = "Account.proxyPushToken";
constexpr static const char KEEP_ALIVE_ENABLED[] = "Account.keepAliveEnabled";
constexpr static const char DHT_PEER_DISCOVERY[] = "Account.peerDiscovery";
constexpr static const char ACCOUNT_PEER_DISCOVERY[] = "Account.accountDiscovery";
constexpr static const char ACCOUNT_PUBLISH[] = "Account.accountPublish";
constexpr static const char MANAGER_URI[] = "Account.managerUri";
constexpr static const char MANAGER_USERNAME[] = "Account.managerUsername";
constexpr static const char BOOTSTRAP_LIST_URL[] = "Account.bootstrapListUrl";
constexpr static const char DHT_PROXY_LIST_URL[] = "Account.dhtProxyListUrl";
constexpr static const char DHT_PORT[] = "Account.dhtPort";
constexpr static const char DEFAULT_MODERATORS[] = "Account.defaultModerators";
constexpr static const char LOCAL_MODERATORS_ENABLED[] = "Account.localModeratorsEnabled";
constexpr static const char ALL_MODERATORS_ENABLED[] = "Account.allModeratorsEnabled";
constexpr static const char ACCOUNT_IP_AUTO_REWRITE[] = "Account.allowIPAutoRewrite";
constexpr static const char UI_CUSTOMIZATION[] = "Account.uiCustomization";
namespace Audio {
constexpr static const char PORT_MAX[] = "Account.audioPortMax";
constexpr static const char PORT_MIN[] = "Account.audioPortMin";
} // namespace Audio
namespace Video {
constexpr static const char ENABLED[] = "Account.videoEnabled";
constexpr static const char PORT_MAX[] = "Account.videoPortMax";
constexpr static const char PORT_MIN[] = "Account.videoPortMin";
} // namespace Video
namespace STUN {
constexpr static const char SERVER[] = "STUN.server";
constexpr static const char ENABLED[] = "STUN.enable";
} // namespace STUN
namespace TURN {
constexpr static const char SERVER[] = "TURN.server";
constexpr static const char ENABLED[] = "TURN.enable";
constexpr static const char SERVER_UNAME[] = "TURN.username";
constexpr static const char SERVER_PWD[] = "TURN.password";
constexpr static const char SERVER_REALM[] = "TURN.realm";
} // namespace TURN
namespace Presence {
constexpr static const char SUPPORT_PUBLISH[] = "Account.presencePublishSupported";
constexpr static const char SUPPORT_SUBSCRIBE[] = "Account.presenceSubscribeSupported";
constexpr static const char ENABLED[] = "Account.presenceEnabled";
} // namespace Presence
namespace Registration {
constexpr static const char EXPIRE[] = "Account.registrationExpire";
constexpr static const char STATUS[] = "Account.registrationStatus";
} // namespace Registration
namespace Ringtone {
constexpr static const char PATH[] = "Account.ringtonePath";
constexpr static const char ENABLED[] = "Account.ringtoneEnabled";
} // namespace Ringtone
namespace SRTP {
constexpr static const char KEY_EXCHANGE[] = "SRTP.keyExchange";
constexpr static const char ENABLED[] = "SRTP.enable";
constexpr static const char RTP_FALLBACK[] = "SRTP.rtpFallback";
} // namespace SRTP
namespace TLS {
constexpr static const char LISTENER_PORT[] = "TLS.listenerPort";
constexpr static const char ENABLED[] = "TLS.enable";
constexpr static const char PORT[] = "TLS.port";
constexpr static const char CA_LIST_FILE[] = "TLS.certificateListFile";
constexpr static const char CERTIFICATE_FILE[] = "TLS.certificateFile";
constexpr static const char PRIVATE_KEY_FILE[] = "TLS.privateKeyFile";
constexpr static const char PASSWORD[] = "TLS.password";
constexpr static const char METHOD[] = "TLS.method";
constexpr static const char CIPHERS[] = "TLS.ciphers";
constexpr static const char SERVER_NAME[] = "TLS.serverName";
constexpr static const char VERIFY_SERVER[] = "TLS.verifyServer";
constexpr static const char VERIFY_CLIENT[] = "TLS.verifyClient";
constexpr static const char REQUIRE_CLIENT_CERTIFICATE[] = "TLS.requireClientCertificate";
constexpr static const char DISABLE_SECURE_DLG_CHECK[] = "TLS.disableSecureDlgCheck";
constexpr static const char NEGOTIATION_TIMEOUT_SEC[] = "TLS.negotiationTimeoutSec";
} // namespace TLS
namespace DHT {
constexpr static const char PUBLIC_IN_CALLS[] = "DHT.PublicInCalls";
constexpr static const char ALLOW_FROM_TRUSTED[] = "DHT.AllowFromTrusted";
} // namespace DHT
namespace RingNS {
constexpr static const char URI[] = "RingNS.uri";
constexpr static const char ACCOUNT[] = "RingNS.account";
} // namespace RingNS
namespace CodecInfo {
constexpr static const char NAME[] = "CodecInfo.name";
constexpr static const char TYPE[] = "CodecInfo.type";
constexpr static const char SAMPLE_RATE[] = "CodecInfo.sampleRate";
constexpr static const char FRAME_RATE[] = "CodecInfo.frameRate";
constexpr static const char BITRATE[] = "CodecInfo.bitrate";
constexpr static const char MIN_BITRATE[] = "CodecInfo.min_bitrate";
constexpr static const char MAX_BITRATE[] = "CodecInfo.max_bitrate";
constexpr static const char QUALITY[] = "CodecInfo.quality";
constexpr static const char MIN_QUALITY[] = "CodecInfo.min_quality";
constexpr static const char MAX_QUALITY[] = "CodecInfo.max_quality";
constexpr static const char CHANNEL_NUMBER[] = "CodecInfo.channelNumber";
constexpr static const char AUTO_QUALITY_ENABLED[] = "CodecInfo.autoQualityEnabled";
} // namespace CodecInfo
} // namespace ConfProperties
namespace TrustRequest {
constexpr static const char FROM[] = "from";
constexpr static const char RECEIVED[] = "received";
constexpr static const char PAYLOAD[] = "payload";
constexpr static const char CONVERSATIONID[] = "conversationId";
} // namespace TrustRequest
} // namespace Account
} // namespace libjami
#endif
| 11,574
|
C++
|
.h
| 219
| 51.360731
| 90
| 0.785683
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,921
|
conversation_interface.h
|
savoirfairelinux_jami-daemon/src/jami/conversation_interface.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LIBJAMI_CONVERSATIONI_H
#define LIBJAMI_CONVERSATIONI_H
#include "def.h"
#include <vector>
#include <map>
#include <string>
#include <list>
#include "jami.h"
namespace libjami {
struct SwarmMessage
{
std::string id;
std::string type;
std::string linearizedParent;
std::map<std::string, std::string> body;
std::vector<std::map<std::string, std::string>> reactions;
std::vector<std::map<std::string, std::string>> editions;
std::map<std::string, int32_t> status;
void fromMapStringString(const std::map<std::string, std::string>& commit) {
id = commit.at("id");
type = commit.at("type");
body = commit; // TODO erase type/id?
}
};
// Conversation management
LIBJAMI_PUBLIC std::string startConversation(const std::string& accountId);
LIBJAMI_PUBLIC void acceptConversationRequest(const std::string& accountId,
const std::string& conversationId);
LIBJAMI_PUBLIC void declineConversationRequest(const std::string& accountId,
const std::string& conversationId);
LIBJAMI_PUBLIC bool removeConversation(const std::string& accountId,
const std::string& conversationId);
LIBJAMI_PUBLIC std::vector<std::string> getConversations(const std::string& accountId);
LIBJAMI_PUBLIC std::vector<std::map<std::string, std::string>> getConversationRequests(
const std::string& accountId);
// Calls
LIBJAMI_PUBLIC std::vector<std::map<std::string, std::string>> getActiveCalls(
const std::string& accountId, const std::string& conversationId);
// Conversation's infos management
LIBJAMI_PUBLIC void updateConversationInfos(const std::string& accountId,
const std::string& conversationId,
const std::map<std::string, std::string>& infos);
LIBJAMI_PUBLIC std::map<std::string, std::string> conversationInfos(
const std::string& accountId, const std::string& conversationId);
LIBJAMI_PUBLIC void setConversationPreferences(const std::string& accountId,
const std::string& conversationId,
const std::map<std::string, std::string>& prefs);
LIBJAMI_PUBLIC std::map<std::string, std::string> getConversationPreferences(
const std::string& accountId, const std::string& conversationId);
// Member management
LIBJAMI_PUBLIC void addConversationMember(const std::string& accountId,
const std::string& conversationId,
const std::string& contactUri);
LIBJAMI_PUBLIC void removeConversationMember(const std::string& accountId,
const std::string& conversationId,
const std::string& contactUri);
LIBJAMI_PUBLIC std::vector<std::map<std::string, std::string>> getConversationMembers(
const std::string& accountId, const std::string& conversationId);
// Message send/load
LIBJAMI_PUBLIC void sendMessage(const std::string& accountId,
const std::string& conversationId,
const std::string& message,
const std::string& replyTo,
const int32_t& flag = 0);
LIBJAMI_PUBLIC uint32_t loadConversationMessages(const std::string& accountId,
const std::string& conversationId,
const std::string& fromMessage,
size_t n);
LIBJAMI_PUBLIC uint32_t loadConversation(const std::string& accountId,
const std::string& conversationId,
const std::string& fromMessage,
size_t n);
LIBJAMI_PUBLIC uint32_t loadConversationUntil(const std::string& accountId,
const std::string& conversationId,
const std::string& fromMessage,
const std::string& toMessage);
LIBJAMI_PUBLIC uint32_t loadSwarmUntil(const std::string& accountId,
const std::string& conversationId,
const std::string& fromMessage,
const std::string& toMessage);
LIBJAMI_PUBLIC uint32_t countInteractions(const std::string& accountId,
const std::string& conversationId,
const std::string& toId,
const std::string& fromId,
const std::string& authorUri);
LIBJAMI_PUBLIC void clearCache(const std::string& accountId, const std::string& conversationId);
LIBJAMI_PUBLIC uint32_t searchConversation(const std::string& accountId,
const std::string& conversationId,
const std::string& author,
const std::string& lastId,
const std::string& regexSearch,
const std::string& type,
const int64_t& after,
const int64_t& before,
const uint32_t& maxResult,
const int32_t& flag);
LIBJAMI_PUBLIC void reloadConversationsAndRequests(const std::string& accountId);
struct LIBJAMI_PUBLIC ConversationSignal
{
struct LIBJAMI_PUBLIC ConversationLoaded
{
constexpr static const char* name = "ConversationLoaded";
using cb_type = void(uint32_t /* id */,
const std::string& /*accountId*/,
const std::string& /* conversationId */,
std::vector<std::map<std::string, std::string>> /*messages*/);
};
struct LIBJAMI_PUBLIC SwarmLoaded
{
constexpr static const char* name = "SwarmLoaded";
using cb_type = void(uint32_t /* id */,
const std::string& /*accountId*/,
const std::string& /* conversationId */,
std::vector<SwarmMessage> /*messages*/);
};
struct LIBJAMI_PUBLIC MessagesFound
{
constexpr static const char* name = "MessagesFound";
using cb_type = void(uint32_t /* id */,
const std::string& /*accountId*/,
const std::string& /* conversationId */,
std::vector<std::map<std::string, std::string>> /*messages*/);
};
struct LIBJAMI_PUBLIC MessageReceived
{
constexpr static const char* name = "MessageReceived";
using cb_type = void(const std::string& /*accountId*/,
const std::string& /* conversationId */,
std::map<std::string, std::string> /*message*/);
};
struct LIBJAMI_PUBLIC SwarmMessageReceived
{
constexpr static const char* name = "SwarmMessageReceived";
using cb_type = void(const std::string& /*accountId*/,
const std::string& /* conversationId */,
const SwarmMessage& /*message*/);
};
struct LIBJAMI_PUBLIC SwarmMessageUpdated
{
constexpr static const char* name = "SwarmMessageUpdated";
using cb_type = void(const std::string& /*accountId*/,
const std::string& /* conversationId */,
const SwarmMessage& /*message*/);
};
struct LIBJAMI_PUBLIC ReactionAdded
{
constexpr static const char* name = "ReactionAdded";
using cb_type = void(const std::string& /*accountId*/,
const std::string& /* conversationId */,
const std::string& /* messageId */,
std::map<std::string, std::string> /*reaction*/);
};
struct LIBJAMI_PUBLIC ReactionRemoved
{
constexpr static const char* name = "ReactionRemoved";
using cb_type = void(const std::string& /*accountId*/,
const std::string& /* conversationId */,
const std::string& /* messageId */,
const std::string& /* reactionId */);
};
struct LIBJAMI_PUBLIC ConversationProfileUpdated
{
constexpr static const char* name = "ConversationProfileUpdated";
using cb_type = void(const std::string& /*accountId*/,
const std::string& /* conversationId */,
std::map<std::string, std::string> /*profile*/);
};
struct LIBJAMI_PUBLIC ConversationRequestReceived
{
constexpr static const char* name = "ConversationRequestReceived";
using cb_type = void(const std::string& /*accountId*/,
const std::string& /* conversationId */,
std::map<std::string, std::string> /*metadatas*/);
};
struct LIBJAMI_PUBLIC ConversationRequestDeclined
{
constexpr static const char* name = "ConversationRequestDeclined";
using cb_type = void(const std::string& /*accountId*/,
const std::string& /* conversationId */);
};
struct LIBJAMI_PUBLIC ConversationReady
{
constexpr static const char* name = "ConversationReady";
using cb_type = void(const std::string& /*accountId*/,
const std::string& /* conversationId */);
};
struct LIBJAMI_PUBLIC ConversationRemoved
{
constexpr static const char* name = "ConversationRemoved";
using cb_type = void(const std::string& /*accountId*/,
const std::string& /* conversationId */);
};
struct LIBJAMI_PUBLIC ConversationMemberEvent
{
constexpr static const char* name = "ConversationMemberEvent";
using cb_type = void(const std::string& /*accountId*/,
const std::string& /* conversationId */,
const std::string& /* memberUri */,
int /* event 0 = add, 1 = joins, 2 = leave, 3 = banned */);
};
struct LIBJAMI_PUBLIC ConversationSyncFinished
{
constexpr static const char* name = "ConversationSyncFinished";
using cb_type = void(const std::string& /*accountId*/);
};
struct LIBJAMI_PUBLIC ConversationCloned
{
constexpr static const char* name = "ConversationCloned";
using cb_type = void(const std::string& /*accountId*/);
};
struct LIBJAMI_PUBLIC CallConnectionRequest
{
constexpr static const char* name = "CallConnectionRequest";
using cb_type = void(const std::string& /*accountId*/,
const std::string& /*peerId*/,
bool hasVideo);
};
struct LIBJAMI_PUBLIC OnConversationError
{
constexpr static const char* name = "OnConversationError";
using cb_type = void(const std::string& /*accountId*/,
const std::string& /* conversationId */,
int code,
const std::string& what);
};
// Preferences
struct LIBJAMI_PUBLIC ConversationPreferencesUpdated
{
constexpr static const char* name = "ConversationPreferencesUpdated";
using cb_type = void(const std::string& /*accountId*/,
const std::string& /*conversationId*/,
std::map<std::string, std::string> /*preferences*/);
};
};
} // namespace libjami
#endif // LIBJAMI_CONVERSATIONI_H
| 12,922
|
C++
|
.h
| 252
| 36.496032
| 96
| 0.562688
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,922
|
presencemanager_interface.h
|
savoirfairelinux_jami-daemon/src/jami/presencemanager_interface.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LIBJAMI_PRESENCEMANAGERI_H
#define LIBJAMI_PRESENCEMANAGERI_H
#include "def.h"
#include <vector>
#include <map>
#include <string>
#include <memory>
#include "jami.h"
#include "presence_const.h"
namespace libjami {
[[deprecated("Replaced by registerSignalHandlers")]] LIBJAMI_PUBLIC void registerPresHandlers(
const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>&);
/* Presence subscription/Notification. */
LIBJAMI_PUBLIC void publish(const std::string& accountID, bool status, const std::string& note);
LIBJAMI_PUBLIC void answerServerRequest(const std::string& uri, bool flag);
LIBJAMI_PUBLIC void subscribeBuddy(const std::string& accountID, const std::string& uri, bool flag);
LIBJAMI_PUBLIC std::vector<std::map<std::string, std::string>> getSubscriptions(
const std::string& accountID);
LIBJAMI_PUBLIC void setSubscriptions(const std::string& accountID,
const std::vector<std::string>& uris);
// Presence signal type definitions
struct LIBJAMI_PUBLIC PresenceSignal
{
struct LIBJAMI_PUBLIC NewServerSubscriptionRequest
{
constexpr static const char* name = "NewServerSubscriptionRequest";
using cb_type = void(const std::string& /*remote*/);
};
struct LIBJAMI_PUBLIC ServerError
{
constexpr static const char* name = "ServerError";
using cb_type = void(const std::string& /*account_id*/,
const std::string& /*error*/,
const std::string& /*msg*/);
};
struct LIBJAMI_PUBLIC NewBuddyNotification
{
constexpr static const char* name = "NewBuddyNotification";
using cb_type = void(const std::string& /*account_id*/,
const std::string& /*buddy_uri*/,
int /*status*/,
const std::string& /*line_status*/);
};
struct LIBJAMI_PUBLIC NearbyPeerNotification
{
constexpr static const char* name = "NearbyPeerNotification";
using cb_type = void(const std::string& /*account_id*/,
const std::string& /*buddy_uri*/,
int /*state*/,
const std::string& /*displayname*/);
};
struct LIBJAMI_PUBLIC SubscriptionStateChanged
{
constexpr static const char* name = "SubscriptionStateChanged";
using cb_type = void(const std::string& /*account_id*/,
const std::string& /*buddy_uri*/,
int /*state*/);
};
};
} // namespace libjami
#endif // PRESENCEMANAGERI_H
| 3,359
|
C++
|
.h
| 77
| 36.155844
| 100
| 0.655868
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,923
|
plugin_manager_interface.h
|
savoirfairelinux_jami-daemon/src/jami/plugin_manager_interface.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "jami.h"
#include "def.h"
#include <string>
#include <vector>
#include <map>
#include <list>
#ifdef __APPLE__
#import "TargetConditionals.h"
#endif
namespace libjami {
LIBJAMI_PUBLIC bool loadPlugin(const std::string& path);
LIBJAMI_PUBLIC bool unloadPlugin(const std::string& path);
LIBJAMI_PUBLIC std::map<std::string, std::string> getPluginDetails(const std::string& path);
LIBJAMI_PUBLIC std::vector<std::map<std::string, std::string>> getPluginPreferences(
const std::string& path, const std::string& accountId);
LIBJAMI_PUBLIC bool setPluginPreference(const std::string& path,
const std::string& accountId,
const std::string& key,
const std::string& value);
LIBJAMI_PUBLIC std::map<std::string, std::string> getPluginPreferencesValues(
const std::string& path, const std::string& accountId);
LIBJAMI_PUBLIC bool resetPluginPreferencesValues(const std::string& path,
const std::string& accountId);
LIBJAMI_PUBLIC std::vector<std::string> getInstalledPlugins();
LIBJAMI_PUBLIC std::vector<std::string> getLoadedPlugins();
LIBJAMI_PUBLIC std::map<std::string, std::string> getPlatformInfo();
LIBJAMI_PUBLIC int installPlugin(const std::string& jplPath, bool force);
LIBJAMI_PUBLIC int uninstallPlugin(const std::string& pluginRootPath);
LIBJAMI_PUBLIC std::vector<std::string> getCallMediaHandlers();
LIBJAMI_PUBLIC std::vector<std::string> getChatHandlers();
LIBJAMI_PUBLIC void toggleCallMediaHandler(const std::string& mediaHandlerId,
const std::string& callId,
bool toggle);
LIBJAMI_PUBLIC void toggleChatHandler(const std::string& chatHandlerId,
const std::string& accountId,
const std::string& peerId,
bool toggle);
LIBJAMI_PUBLIC std::map<std::string, std::string> getCallMediaHandlerDetails(
const std::string& mediaHandlerId);
LIBJAMI_PUBLIC std::vector<std::string> getCallMediaHandlerStatus(const std::string& callId);
LIBJAMI_PUBLIC std::map<std::string, std::string> getChatHandlerDetails(
const std::string& chatHandlerId);
LIBJAMI_PUBLIC std::vector<std::string> getChatHandlerStatus(const std::string& accountId,
const std::string& peerId);
LIBJAMI_PUBLIC bool getPluginsEnabled();
LIBJAMI_PUBLIC void setPluginsEnabled(bool state);
LIBJAMI_PUBLIC void sendWebViewMessage(const std::string& pluginId,
const std::string& webViewId,
const std::string& messageId,
const std::string& payload);
LIBJAMI_PUBLIC std::string sendWebViewAttach(const std::string& pluginId,
const std::string& accountId,
const std::string& webViewId,
const std::string& action);
LIBJAMI_PUBLIC void sendWebViewDetach(const std::string& pluginId, const std::string& webViewId);
namespace PluginSignal {
struct LIBJAMI_PUBLIC WebViewMessageReceived
{
constexpr static const char* name = "WebViewMessageReceived";
using cb_type = void(const std::string& /*pluginId*/,
const std::string& /*webViewId*/,
const std::string& /*messageId*/,
const std::string& /*payload*/);
};
} // namespace PluginSignal
} // namespace libjami
| 4,410
|
C++
|
.h
| 83
| 42.807229
| 97
| 0.651842
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,924
|
videomanager_interface.h
|
savoirfairelinux_jami-daemon/src/jami/videomanager_interface.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef DENABLE_VIDEOMANAGERI_H
#define DENABLE_VIDEOMANAGERI_H
#include "jami.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H
extern "C" {
struct AVFrame;
struct AVPacket;
void av_frame_free(AVFrame** frame);
void av_packet_free(AVPacket** frame);
}
#include "def.h"
#include <memory>
#include <vector>
#include <map>
#include <string>
#include <functional>
#include <chrono>
#include <cstdint>
#include <cstdlib>
#ifdef __APPLE__
#import "TargetConditionals.h"
#endif
namespace jami {
struct AudioFormat;
}
namespace libjami {
[[deprecated("Replaced by registerSignalHandlers")]] LIBJAMI_PUBLIC void registerVideoHandlers(
const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>&);
struct LIBJAMI_PUBLIC AVFrame_deleter
{
void operator()(AVFrame* frame) const { av_frame_free(&frame); }
};
typedef std::unique_ptr<AVFrame, AVFrame_deleter> FrameBuffer;
struct LIBJAMI_PUBLIC AVPacket_deleter
{
void operator()(AVPacket* pkt) const { av_packet_free(&pkt); }
};
typedef std::unique_ptr<AVPacket, AVPacket_deleter> PacketBuffer;
class LIBJAMI_PUBLIC MediaFrame
{
public:
// Construct an empty MediaFrame
MediaFrame();
MediaFrame(const MediaFrame&) = delete;
MediaFrame& operator=(const MediaFrame& o) = delete;
MediaFrame(MediaFrame&& o) = delete;
MediaFrame& operator=(MediaFrame&& o) = delete;
virtual ~MediaFrame() = default;
// Return a pointer on underlaying buffer
const AVFrame* pointer() const noexcept { return frame_.get(); }
AVFrame* pointer() noexcept { return frame_.get(); }
AVPacket* packet() const noexcept { return packet_.get(); }
// Fill this MediaFrame with data from o
void copyFrom(const MediaFrame& o);
void setPacket(PacketBuffer&& pkt);
// Reset internal buffers (return to an empty MediaFrame)
virtual void reset() noexcept;
FrameBuffer getFrame() { return std::move(frame_); }
protected:
FrameBuffer frame_;
PacketBuffer packet_;
};
class LIBJAMI_PUBLIC AudioFrame : public MediaFrame
{
public:
AudioFrame()
: MediaFrame()
{}
AudioFrame(const jami::AudioFormat& format, size_t nb_samples = 0);
~AudioFrame() {};
void mix(const AudioFrame& o);
float calcRMS() const;
jami::AudioFormat getFormat() const;
size_t getFrameSize() const;
bool has_voice {false};
private:
void setFormat(const jami::AudioFormat& format);
void reserve(size_t nb_samples = 0);
};
class LIBJAMI_PUBLIC VideoFrame : public MediaFrame
{
public:
// Construct an empty VideoFrame
VideoFrame()
: MediaFrame()
{}
~VideoFrame();
// Reset internal buffers (return to an empty VideoFrame)
void reset() noexcept override;
// Fill this VideoFrame with data from o
void copyFrom(const VideoFrame& o);
// Return frame size in bytes
std::size_t size() const noexcept;
// Return pixel format
int format() const noexcept;
// Return frame width in pixels
int width() const noexcept;
// Return frame height in pixels
int height() const noexcept;
// Allocate internal pixel buffers following given specifications
void reserve(int format, int width, int height);
// Return orientation (in degrees) stored in the frame metadata, or 0 by default.
int getOrientation() const;
// Set internal pixel buffers on given memory buffer
// This buffer must follow given specifications.
void setFromMemory(uint8_t* data, int format, int width, int height) noexcept;
void setFromMemory(uint8_t* data,
int format,
int width,
int height,
const std::function<void(uint8_t*)>& cb) noexcept;
void setReleaseCb(const std::function<void(uint8_t*)>& cb) noexcept;
void noise();
private:
std::function<void(uint8_t*)> releaseBufferCb_ {};
uint8_t* ptr_ {nullptr};
bool allocated_ {false};
void setGeometry(int format, int width, int height) noexcept;
};
struct LIBJAMI_PUBLIC SinkTarget
{
std::function<FrameBuffer()> pull;
std::function<void(FrameBuffer)> push;
int /* AVPixelFormat */ preferredFormat {-1 /* AV_PIX_FMT_NONE */};
};
using VideoCapabilities = std::map<std::string, std::map<std::string, std::vector<std::string>>>;
LIBJAMI_PUBLIC std::vector<std::string> getDeviceList();
LIBJAMI_PUBLIC VideoCapabilities getCapabilities(const std::string& deviceId);
LIBJAMI_PUBLIC std::map<std::string, std::string> getSettings(const std::string& deviceId);
LIBJAMI_PUBLIC void applySettings(const std::string& deviceId,
const std::map<std::string, std::string>& settings);
LIBJAMI_PUBLIC void setDefaultDevice(const std::string& deviceId);
LIBJAMI_PUBLIC void setDeviceOrientation(const std::string& deviceId, int angle);
LIBJAMI_PUBLIC std::map<std::string, std::string> getDeviceParams(const std::string& deviceId);
LIBJAMI_PUBLIC std::string getDefaultDevice();
LIBJAMI_PUBLIC void startAudioDevice();
LIBJAMI_PUBLIC void stopAudioDevice();
LIBJAMI_PUBLIC std::string openVideoInput(const std::string& path);
LIBJAMI_PUBLIC bool closeVideoInput(const std::string& id);
LIBJAMI_PUBLIC std::string createMediaPlayer(const std::string& path);
LIBJAMI_PUBLIC bool closeMediaPlayer(const std::string& id);
LIBJAMI_PUBLIC bool pausePlayer(const std::string& id, const bool& pause);
LIBJAMI_PUBLIC bool mutePlayerAudio(const std::string& id, const bool& mute);
LIBJAMI_PUBLIC bool playerSeekToTime(const std::string& id, const int& time);
LIBJAMI_PUBLIC int64_t getPlayerPosition(const std::string& id);
LIBJAMI_PUBLIC int64_t getPlayerDuration(const std::string& id);
LIBJAMI_PUBLIC void setAutoRestart(const std::string& id, const bool& restart);
LIBJAMI_PUBLIC bool registerSinkTarget(const std::string& sinkId, SinkTarget target);
#ifdef ENABLE_SHM
LIBJAMI_PUBLIC void startShmSink(const std::string& sinkId, bool value);
#endif
LIBJAMI_PUBLIC std::map<std::string, std::string> getRenderer(const std::string& callId);
LIBJAMI_PUBLIC std::string startLocalMediaRecorder(const std::string& videoInputId,
const std::string& filepath);
LIBJAMI_PUBLIC void stopLocalRecorder(const std::string& filepath);
#if defined(__ANDROID__) || (defined(TARGET_OS_IOS) && TARGET_OS_IOS)
LIBJAMI_PUBLIC void addVideoDevice(
const std::string& node, const std::vector<std::map<std::string, std::string>>& devInfo = {});
LIBJAMI_PUBLIC void removeVideoDevice(const std::string& node);
LIBJAMI_PUBLIC VideoFrame* getNewFrame(std::string_view id);
LIBJAMI_PUBLIC void publishFrame(std::string_view id);
#endif
LIBJAMI_PUBLIC bool getDecodingAccelerated();
LIBJAMI_PUBLIC void setDecodingAccelerated(bool state);
LIBJAMI_PUBLIC bool getEncodingAccelerated();
LIBJAMI_PUBLIC void setEncodingAccelerated(bool state);
// player signal type definitions
struct LIBJAMI_PUBLIC MediaPlayerSignal
{
struct LIBJAMI_PUBLIC FileOpened
{
constexpr static const char* name = "FileOpened";
using cb_type = void(const std::string& /*playerId*/,
std::map<std::string, std::string> /*playerInfo*/);
};
};
// Video signal type definitions
struct LIBJAMI_PUBLIC VideoSignal
{
struct LIBJAMI_PUBLIC DeviceEvent
{
constexpr static const char* name = "DeviceEvent";
using cb_type = void(void);
};
struct LIBJAMI_PUBLIC DecodingStarted
{
constexpr static const char* name = "DecodingStarted";
using cb_type = void(const std::string& /*id*/,
const std::string& /*shm_path*/,
int /*w*/,
int /*h*/,
bool /*is_mixer*/ id);
};
struct LIBJAMI_PUBLIC DecodingStopped
{
constexpr static const char* name = "DecodingStopped";
using cb_type = void(const std::string& /*id*/,
const std::string& /*shm_path*/,
bool /*is_mixer*/);
};
#ifdef __ANDROID__
struct LIBJAMI_PUBLIC SetParameters
{
constexpr static const char* name = "SetParameters";
using cb_type = void(const std::string& device,
const int format,
const int width,
const int height,
const int rate);
};
struct LIBJAMI_PUBLIC GetCameraInfo
{
constexpr static const char* name = "GetCameraInfo";
using cb_type = void(const std::string& device,
std::vector<int>* formats,
std::vector<unsigned>* sizes,
std::vector<unsigned>* rates);
};
struct LIBJAMI_PUBLIC RequestKeyFrame
{
constexpr static const char* name = "RequestKeyFrame";
using cb_type = void(const std::string& /*device*/);
};
struct LIBJAMI_PUBLIC SetBitrate
{
constexpr static const char* name = "SetBitrate";
using cb_type = void(const std::string& /*device*/, const int bitrate);
};
#endif
struct LIBJAMI_PUBLIC StartCapture
{
constexpr static const char* name = "StartCapture";
using cb_type = void(const std::string& /*device*/);
};
struct LIBJAMI_PUBLIC StopCapture
{
constexpr static const char* name = "StopCapture";
using cb_type = void(const std::string& /*device*/);
};
struct LIBJAMI_PUBLIC DeviceAdded
{
constexpr static const char* name = "DeviceAdded";
using cb_type = void(const std::string& /*device*/);
};
struct LIBJAMI_PUBLIC ParametersChanged
{
constexpr static const char* name = "ParametersChanged";
using cb_type = void(const std::string& /*device*/);
};
};
} // namespace libjami
#endif // DENABLE_VIDEOMANAGERI_H
| 10,658
|
C++
|
.h
| 270
| 33.788889
| 98
| 0.686201
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,925
|
call_const.h
|
savoirfairelinux_jami-daemon/src/jami/call_const.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LIBJAMI_CALL_H
#define LIBJAMI_CALL_H
#include "def.h"
namespace libjami {
namespace Call {
namespace StateEvent {
constexpr static char INCOMING[] = "INCOMING";
constexpr static char CONNECTING[] = "CONNECTING";
constexpr static char RINGING[] = "RINGING";
constexpr static char CURRENT[] = "CURRENT";
constexpr static char HUNGUP[] = "HUNGUP";
constexpr static char BUSY[] = "BUSY";
constexpr static char PEER_BUSY[] = "PEER_BUSY";
constexpr static char FAILURE[] = "FAILURE";
constexpr static char HOLD[] = "HOLD";
constexpr static char UNHOLD[] = "UNHOLD";
constexpr static char INACTIVE[] = "INACTIVE";
constexpr static char OVER[] = "OVER";
} // namespace StateEvent
namespace Details {
constexpr static char CALL_TYPE[] = "CALL_TYPE";
constexpr static char PEER_NUMBER[] = "PEER_NUMBER";
constexpr static char REGISTERED_NAME[] = "REGISTERED_NAME";
constexpr static char DISPLAY_NAME[] = "DISPLAY_NAME";
constexpr static char CALL_STATE[] = "CALL_STATE";
constexpr static char CONF_ID[] = "CONF_ID";
constexpr static char TIMESTAMP_START[] = "TIMESTAMP_START";
constexpr static char TO_USERNAME[] = "TO_USERNAME";
constexpr static char ACCOUNTID[] = "ACCOUNTID";
constexpr static char PEER_HOLDING[] = "PEER_HOLDING";
constexpr static char AUDIO_MUTED[] = "AUDIO_MUTED";
constexpr static char VIDEO_MUTED[] = "VIDEO_MUTED";
constexpr static char VIDEO_SOURCE[] = "VIDEO_SOURCE";
constexpr static char AUDIO_ONLY[] = "AUDIO_ONLY";
constexpr static char AUDIO_CODEC[] = "AUDIO_CODEC";
constexpr static char AUDIO_SAMPLE_RATE[] = "AUDIO_SAMPLE_RATE";
constexpr static char VIDEO_CODEC[] = "VIDEO_CODEC";
constexpr static char SOCKETS[] = "SOCKETS";
constexpr static char VIDEO_MIN_BITRATE[] = "VIDEO_MIN_BITRATE";
constexpr static char VIDEO_BITRATE[] = "VIDEO_BITRATE";
constexpr static char VIDEO_MAX_BITRATE[] = "VIDEO_MAX_BITRATE";
} // namespace Details
} // namespace Call
} // namespace libjami
#endif
| 2,650
|
C++
|
.h
| 61
| 42
| 73
| 0.753201
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,926
|
tracepoint-def.h
|
savoirfairelinux_jami-daemon/src/jami/tracepoint-def.h
|
#ifdef ENABLE_TRACEPOINTS
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#undef LTTNG_UST_TRACEPOINT_PROVIDER
#define LTTNG_UST_TRACEPOINT_PROVIDER jami
#undef LTTNG_UST_TRACEPOINT_INCLUDE
#define LTTNG_UST_TRACEPOINT_INCLUDE "src/jami/tracepoint-def.h"
#if !defined(TRACEPOINT_DEF_H) || defined(LTTNG_UST_TRACEPOINT_HEADER_MULTI_READ)
#define TRACEPOINT_DEF_H
#include <lttng/tracepoint.h>
/*
* Use LTTNG_UST_TRACEPOINT_EVENT(), LTTNG_UST_TRACEPOINT_EVENT_CLASS(),
* LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(), and LTTNG_UST_TRACEPOINT_LOGLEVEL()
* here.
*/
LTTNG_UST_TRACEPOINT_EVENT(
jami,
scheduled_executor_task_begin,
LTTNG_UST_TP_ARGS(
const char *, executor_name,
const char *, filename,
uint32_t, linum,
uint64_t, cookie
),
LTTNG_UST_TP_FIELDS(
lttng_ust_field_string(executor, executor_name)
lttng_ust_field_string(source_filename, filename)
lttng_ust_field_integer(uint32_t, source_line, linum)
lttng_ust_field_integer(uint64_t, cookie, cookie)
)
)
LTTNG_UST_TRACEPOINT_EVENT(
jami,
scheduled_executor_task_end,
LTTNG_UST_TP_ARGS(uint64_t, cookie),
LTTNG_UST_TP_FIELDS(lttng_ust_field_integer(uint64_t, cookie, cookie))
)
LTTNG_UST_TRACEPOINT_EVENT(
jami,
ice_transport_context,
LTTNG_UST_TP_ARGS(
uint64_t, context
),
LTTNG_UST_TP_FIELDS(
lttng_ust_field_integer(uint64_t, ice_context, context)
)
)
LTTNG_UST_TRACEPOINT_EVENT(
jami,
ice_transport_send,
LTTNG_UST_TP_ARGS(
uint64_t, context,
unsigned, component,
size_t, len,
const char*, remote_addr
),
LTTNG_UST_TP_FIELDS(
lttng_ust_field_integer(uint64_t, ice_context, context)
lttng_ust_field_integer(unsigned, component, component)
lttng_ust_field_integer(size_t, packet_length, len)
lttng_ust_field_string(remote_addr, remote_addr)
)
)
LTTNG_UST_TRACEPOINT_EVENT(
jami,
ice_transport_send_status,
LTTNG_UST_TP_ARGS(
int, status
),
LTTNG_UST_TP_FIELDS(
lttng_ust_field_integer(int, pj_status, status)
)
)
LTTNG_UST_TRACEPOINT_EVENT(
jami,
ice_transport_recv,
LTTNG_UST_TP_ARGS(
uint64_t, context,
unsigned, component,
size_t, len,
const char*, remote_addr
),
LTTNG_UST_TP_FIELDS(
lttng_ust_field_integer(uint64_t, ice_context, context)
lttng_ust_field_integer(unsigned, component, component)
lttng_ust_field_integer(size_t, packet_length, len)
lttng_ust_field_string(remote_addr, remote_addr)
)
)
LTTNG_UST_TRACEPOINT_EVENT(
jami,
emit_signal,
LTTNG_UST_TP_ARGS(
const char*, signal_type
),
LTTNG_UST_TP_FIELDS(
lttng_ust_field_string(signal_type, signal_type)
)
)
LTTNG_UST_TRACEPOINT_EVENT(
jami,
emit_signal_end,
LTTNG_UST_TP_ARGS(
),
LTTNG_UST_TP_FIELDS(
)
)
LTTNG_UST_TRACEPOINT_EVENT(
jami,
emit_signal_begin_callback,
LTTNG_UST_TP_ARGS(
const char*, filename,
uint32_t, linum
),
LTTNG_UST_TP_FIELDS(
lttng_ust_field_string(source_filename, filename)
lttng_ust_field_integer(uint32_t, source_line, linum)
)
)
LTTNG_UST_TRACEPOINT_EVENT(
jami,
emit_signal_end_callback,
LTTNG_UST_TP_ARGS(
),
LTTNG_UST_TP_FIELDS(
)
)
LTTNG_UST_TRACEPOINT_EVENT(
jami,
audio_input_read_from_device_end,
LTTNG_UST_TP_ARGS(
const char*, id
),
LTTNG_UST_TP_FIELDS(
lttng_ust_field_integer(uint64_t, id, strtoull(id, NULL, 16))
)
)
LTTNG_UST_TRACEPOINT_EVENT(
jami,
audio_layer_put_recorded_end,
LTTNG_UST_TP_ARGS(
),
LTTNG_UST_TP_FIELDS(
)
)
LTTNG_UST_TRACEPOINT_EVENT(
jami,
audio_layer_get_to_play_end,
LTTNG_UST_TP_ARGS(
),
LTTNG_UST_TP_FIELDS(
)
)
LTTNG_UST_TRACEPOINT_EVENT(
jami,
call_start,
LTTNG_UST_TP_ARGS(
const char*, id
),
LTTNG_UST_TP_FIELDS(
lttng_ust_field_integer(uint64_t, id, strtoull(id, NULL, 16))
)
)
LTTNG_UST_TRACEPOINT_EVENT(
jami,
call_end,
LTTNG_UST_TP_ARGS(
const char*, id
),
LTTNG_UST_TP_FIELDS(
lttng_ust_field_integer(uint64_t, id, strtoull(id, NULL, 16))
)
)
LTTNG_UST_TRACEPOINT_EVENT(
jami,
conference_begin,
LTTNG_UST_TP_ARGS(
const char*, id
),
LTTNG_UST_TP_FIELDS(
lttng_ust_field_integer(uint64_t, id, strtoull(id, NULL, 16))
)
)
LTTNG_UST_TRACEPOINT_EVENT(
jami,
conference_end,
LTTNG_UST_TP_ARGS(
const char*, id
),
LTTNG_UST_TP_FIELDS(
lttng_ust_field_integer(uint64_t, id, strtoull(id, NULL, 16))
)
)
LTTNG_UST_TRACEPOINT_EVENT(
jami,
conference_add_participant,
LTTNG_UST_TP_ARGS(
const char*, conference_id,
const char*, participant_id
),
LTTNG_UST_TP_FIELDS(
lttng_ust_field_integer(uint64_t, id, strtoull(conference_id, NULL, 16))
lttng_ust_field_integer(uint64_t, participant_id, strtoull(participant_id, NULL, 16))
)
)
#endif /* TRACEPOINT_DEF_H */
#include <lttng/tracepoint-event.h>
#endif
| 5,391
|
C++
|
.h
| 209
| 20.028708
| 97
| 0.637951
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,927
|
tracepoint.h
|
savoirfairelinux_jami-daemon/src/jami/tracepoint.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#include "tracepoint-def.h"
#pragma GCC diagnostic pop
#ifdef ENABLE_TRACEPOINTS
# ifndef lttng_ust_tracepoint
# define lttng_ust_tracepoint(...) tracepoint(__VA_ARGS__)
# endif
# ifndef lttng_ust_do_tracepoint
# define lttng_ust_do_tracepoint(...) do_tracepoint(__VA_ARGS__)
# endif
# ifndef lttng_ust_tracepoint_enabled
# define lttng_ust_tracepoint_enabled(...) tracepoint_enabled(__VA_ARGS__)
# endif
# define jami_tracepoint(tp_name, ...) \
lttng_ust_tracepoint(jami, tp_name __VA_OPT__(,) __VA_ARGS__)
# define jami_tracepoint_if_enabled(tp_name, ...) \
do { \
if (lttng_ust_tracepoint_enabled(jami, tp_name)) { \
lttng_ust_do_tracepoint(jami, \
tp_name \
__VA_OPT__(,) \
__VA_ARGS__); \
} \
} \
while (0)
#else
# define jami_tracepoint(...) static_assert(true)
# define jami_tracepoint_if_enabled(...) static_assert(true)
#endif
| 2,214
|
C++
|
.h
| 47
| 40.659574
| 77
| 0.548193
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,928
|
configurationmanager_interface.h
|
savoirfairelinux_jami-daemon/src/jami/configurationmanager_interface.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "def.h"
#include <vector>
#include <map>
#include <memory>
#include <string>
#include <cstdint>
#include "jami.h"
#include "security_const.h"
#ifdef __APPLE__
#include <TargetConditionals.h>
#endif
namespace libjami {
[[deprecated("Replaced by registerSignalHandlers")]] LIBJAMI_PUBLIC void registerConfHandlers(
const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>&);
struct LIBJAMI_PUBLIC Message
{
std::string from;
std::map<std::string, std::string> payloads;
uint64_t received;
};
LIBJAMI_PUBLIC std::map<std::string, std::string> getAccountDetails(const std::string& accountId);
LIBJAMI_PUBLIC std::map<std::string, std::string> getVolatileAccountDetails(
const std::string& accountId);
LIBJAMI_PUBLIC void setAccountDetails(const std::string& accountId,
const std::map<std::string, std::string>& details);
LIBJAMI_PUBLIC void setAccountActive(const std::string& accountId,
bool active,
bool shutdownConnections = false);
LIBJAMI_PUBLIC void loadAccountAndConversation(const std::string& accountId,
bool loadAll,
const std::string& convId);
LIBJAMI_PUBLIC std::map<std::string, std::string> getAccountTemplate(const std::string& accountType);
LIBJAMI_PUBLIC std::string addAccount(const std::map<std::string, std::string>& details,
const std::string& accountId = {});
LIBJAMI_PUBLIC void monitor(bool continuous);
LIBJAMI_PUBLIC std::vector<std::map<std::string, std::string>> getConnectionList(
const std::string& accountId, const std::string& conversationId);
LIBJAMI_PUBLIC std::vector<std::map<std::string, std::string>> getChannelList(
const std::string& accountId, const std::string& connectionId);
LIBJAMI_PUBLIC bool exportOnRing(const std::string& accountId, const std::string& password);
LIBJAMI_PUBLIC bool exportToFile(const std::string& accountId,
const std::string& destinationPath,
const std::string& scheme = {},
const std::string& password = {});
LIBJAMI_PUBLIC bool revokeDevice(const std::string& accountId,
const std::string& deviceId,
const std::string& scheme = {},
const std::string& password = {});
LIBJAMI_PUBLIC std::map<std::string, std::string> getKnownRingDevices(const std::string& accountId);
LIBJAMI_PUBLIC bool changeAccountPassword(const std::string& accountId,
const std::string& password_old,
const std::string& password_new);
LIBJAMI_PUBLIC bool isPasswordValid(const std::string& accountId, const std::string& password);
LIBJAMI_PUBLIC std::vector<uint8_t> getPasswordKey(const std::string& accountId,
const std::string& password);
LIBJAMI_PUBLIC bool lookupName(const std::string& account,
const std::string& nameserver,
const std::string& name);
LIBJAMI_PUBLIC bool lookupAddress(const std::string& account,
const std::string& nameserver,
const std::string& address);
LIBJAMI_PUBLIC bool registerName(const std::string& account,
const std::string& name,
const std::string& scheme = {},
const std::string& password = {});
LIBJAMI_PUBLIC bool searchUser(const std::string& account, const std::string& query);
LIBJAMI_PUBLIC void removeAccount(const std::string& accountId);
LIBJAMI_PUBLIC std::vector<std::string> getAccountList();
LIBJAMI_PUBLIC void sendRegister(const std::string& accountId, bool enable);
LIBJAMI_PUBLIC void registerAllAccounts(void);
LIBJAMI_PUBLIC uint64_t sendAccountTextMessage(const std::string& accountId,
const std::string& to,
const std::map<std::string, std::string>& payloads,
int32_t flags);
LIBJAMI_PUBLIC bool cancelMessage(const std::string& accountId, uint64_t message);
LIBJAMI_PUBLIC std::vector<Message> getLastMessages(const std::string& accountId,
const uint64_t& base_timestamp);
LIBJAMI_PUBLIC std::map<std::string, std::string> getNearbyPeers(const std::string& accountId);
LIBJAMI_PUBLIC void updateProfile(const std::string& accountId,const std::string& displayName, const std::string& avatar, const uint64_t& flag);
LIBJAMI_PUBLIC int getMessageStatus(uint64_t id);
LIBJAMI_PUBLIC int getMessageStatus(const std::string& accountId, uint64_t id);
LIBJAMI_PUBLIC void setIsComposing(const std::string& accountId,
const std::string& conversationUri,
bool isWriting);
LIBJAMI_PUBLIC bool setMessageDisplayed(const std::string& accountId,
const std::string& conversationUri,
const std::string& messageId,
int status);
LIBJAMI_PUBLIC std::vector<unsigned> getCodecList();
LIBJAMI_PUBLIC std::vector<std::string> getSupportedTlsMethod();
LIBJAMI_PUBLIC std::vector<std::string> getSupportedCiphers(const std::string& accountId);
LIBJAMI_PUBLIC std::map<std::string, std::string> getCodecDetails(const std::string& accountId,
const unsigned& codecId);
LIBJAMI_PUBLIC bool setCodecDetails(const std::string& accountId,
const unsigned& codecId,
const std::map<std::string, std::string>& details);
LIBJAMI_PUBLIC std::vector<unsigned> getActiveCodecList(const std::string& accountId);
LIBJAMI_PUBLIC void setActiveCodecList(const std::string& accountId,
const std::vector<unsigned>& list);
LIBJAMI_PUBLIC std::vector<std::string> getAudioPluginList();
LIBJAMI_PUBLIC void setAudioPlugin(const std::string& audioPlugin);
LIBJAMI_PUBLIC std::vector<std::string> getAudioOutputDeviceList();
LIBJAMI_PUBLIC void setAudioOutputDevice(int32_t index);
LIBJAMI_PUBLIC void startAudio();
LIBJAMI_PUBLIC void setAudioInputDevice(int32_t index);
LIBJAMI_PUBLIC void setAudioRingtoneDevice(int32_t index);
LIBJAMI_PUBLIC std::vector<std::string> getAudioInputDeviceList();
LIBJAMI_PUBLIC std::vector<std::string> getCurrentAudioDevicesIndex();
LIBJAMI_PUBLIC int32_t getAudioInputDeviceIndex(const std::string& name);
LIBJAMI_PUBLIC int32_t getAudioOutputDeviceIndex(const std::string& name);
LIBJAMI_PUBLIC std::string getCurrentAudioOutputPlugin();
LIBJAMI_PUBLIC std::string getNoiseSuppressState();
LIBJAMI_PUBLIC void setNoiseSuppressState(const std::string& state);
LIBJAMI_PUBLIC bool isAgcEnabled();
LIBJAMI_PUBLIC void setAgcState(bool enabled);
LIBJAMI_PUBLIC void muteDtmf(bool mute);
LIBJAMI_PUBLIC bool isDtmfMuted();
LIBJAMI_PUBLIC bool isCaptureMuted();
LIBJAMI_PUBLIC void muteCapture(bool mute);
LIBJAMI_PUBLIC bool isPlaybackMuted();
LIBJAMI_PUBLIC void mutePlayback(bool mute);
LIBJAMI_PUBLIC bool isRingtoneMuted();
LIBJAMI_PUBLIC void muteRingtone(bool mute);
LIBJAMI_PUBLIC std::vector<std::string> getSupportedAudioManagers();
LIBJAMI_PUBLIC std::string getAudioManager();
LIBJAMI_PUBLIC bool setAudioManager(const std::string& api);
LIBJAMI_PUBLIC std::string getRecordPath();
LIBJAMI_PUBLIC void setRecordPath(const std::string& recPath);
LIBJAMI_PUBLIC bool getIsAlwaysRecording();
LIBJAMI_PUBLIC void setIsAlwaysRecording(bool rec);
LIBJAMI_PUBLIC bool getRecordPreview();
LIBJAMI_PUBLIC void setRecordPreview(bool rec);
LIBJAMI_PUBLIC int getRecordQuality();
LIBJAMI_PUBLIC void setRecordQuality(int quality);
LIBJAMI_PUBLIC void setHistoryLimit(int32_t days);
LIBJAMI_PUBLIC int32_t getHistoryLimit();
LIBJAMI_PUBLIC void setRingingTimeout(int32_t timeout);
LIBJAMI_PUBLIC int32_t getRingingTimeout();
LIBJAMI_PUBLIC void setAccountsOrder(const std::string& order);
LIBJAMI_PUBLIC std::vector<std::map<std::string, std::string>> getCredentials(
const std::string& accountId);
LIBJAMI_PUBLIC void setCredentials(const std::string& accountId,
const std::vector<std::map<std::string, std::string>>& details);
LIBJAMI_PUBLIC std::string getAddrFromInterfaceName(const std::string& iface);
LIBJAMI_PUBLIC std::vector<std::string> getAllIpInterface();
LIBJAMI_PUBLIC std::vector<std::string> getAllIpInterfaceByName();
LIBJAMI_PUBLIC void setVolume(const std::string& device, double value);
LIBJAMI_PUBLIC double getVolume(const std::string& device);
/*
* Security
*/
LIBJAMI_PUBLIC std::map<std::string, std::string> validateCertificate(
const std::string& accountId, const std::string& certificate);
LIBJAMI_PUBLIC std::map<std::string, std::string> validateCertificatePath(
const std::string& accountId,
const std::string& certificatePath,
const std::string& privateKey,
const std::string& privateKeyPassword,
const std::string& caList);
LIBJAMI_PUBLIC std::map<std::string, std::string> getCertificateDetails(
const std::string& accountId, const std::string& certificate);
LIBJAMI_PUBLIC std::map<std::string, std::string> getCertificateDetailsPath(
const std::string& accountId,
const std::string& certificatePath,
const std::string& privateKey,
const std::string& privateKeyPassword);
LIBJAMI_PUBLIC std::vector<std::string> getPinnedCertificates(const std::string& accountId);
LIBJAMI_PUBLIC std::vector<std::string> pinCertificate(const std::string& accountId,
const std::vector<uint8_t>& certificate,
bool local);
LIBJAMI_PUBLIC bool unpinCertificate(const std::string& accountId, const std::string& certId);
LIBJAMI_PUBLIC void pinCertificatePath(const std::string& accountId, const std::string& path);
LIBJAMI_PUBLIC unsigned unpinCertificatePath(const std::string& accountId, const std::string& path);
LIBJAMI_PUBLIC bool pinRemoteCertificate(const std::string& accountId, const std::string& certId);
LIBJAMI_PUBLIC bool setCertificateStatus(const std::string& account,
const std::string& certId,
const std::string& status);
LIBJAMI_PUBLIC std::vector<std::string> getCertificatesByStatus(const std::string& account,
const std::string& status);
/* contact requests */
LIBJAMI_PUBLIC std::vector<std::map<std::string, std::string>> getTrustRequests(
const std::string& accountId);
LIBJAMI_PUBLIC bool acceptTrustRequest(const std::string& accountId, const std::string& from);
LIBJAMI_PUBLIC bool discardTrustRequest(const std::string& accountId, const std::string& from);
LIBJAMI_PUBLIC void sendTrustRequest(const std::string& accountId,
const std::string& to,
const std::vector<uint8_t>& payload = {});
/* Contacts */
LIBJAMI_PUBLIC void addContact(const std::string& accountId, const std::string& uri);
LIBJAMI_PUBLIC void removeContact(const std::string& accountId, const std::string& uri, bool ban);
LIBJAMI_PUBLIC std::map<std::string, std::string> getContactDetails(const std::string& accountId,
const std::string& uri);
LIBJAMI_PUBLIC std::vector<std::map<std::string, std::string>> getContacts(
const std::string& accountId);
/*
* Network connectivity
*/
LIBJAMI_PUBLIC void connectivityChanged();
/* Dht proxy */
/**
* Set the device push notification token (for all accounts).
* If set, proxy clients will use push notifications.
* Set to empty to disable push notifications.
*/
LIBJAMI_PUBLIC void setPushNotificationToken(const std::string& pushDeviceToken);
/**
* Set the topic for ios
* bundle_id for ios 14.5 and higher
* bundle_id.voip for ios prior 14.5
*/
LIBJAMI_PUBLIC void setPushNotificationTopic(const std::string& topic);
LIBJAMI_PUBLIC void setPushNotificationConfig(const std::map<std::string, std::string>& data);
/**
* To be called by clients with relevant data when a push notification is received.
*/
LIBJAMI_PUBLIC void pushNotificationReceived(const std::string& from,
const std::map<std::string, std::string>& data);
/**
* Returns whether or not the audio meter is enabled for ring buffer @id.
*
* NOTE If @id is empty, returns true if at least 1 audio meter is enabled.
*/
LIBJAMI_PUBLIC bool isAudioMeterActive(const std::string& id);
/**
* Enables/disables an audio meter for the specified @id.
*
* NOTE If @id is empty, applies to all ring buffers.
*/
LIBJAMI_PUBLIC void setAudioMeterState(const std::string& id, bool state);
/**
* Add/remove default moderator for conferences
*/
LIBJAMI_PUBLIC void setDefaultModerator(const std::string& accountId,
const std::string& peerURI,
bool state);
/**
* Get default moderators for an account
*/
LIBJAMI_PUBLIC std::vector<std::string> getDefaultModerators(const std::string& accountId);
/**
* Enable/disable local moderators for conferences
*/
LIBJAMI_PUBLIC void enableLocalModerators(const std::string& accountId, bool isModEnabled);
/**
* Get local moderators state
*/
LIBJAMI_PUBLIC bool isLocalModeratorsEnabled(const std::string& accountId);
/**
* Enable/disable all moderators for conferences
*/
LIBJAMI_PUBLIC void setAllModerators(const std::string& accountId, bool allModerators);
/**
* Get all moderators state
*/
LIBJAMI_PUBLIC bool isAllModerators(const std::string& accountId);
/**
* Set the resource directory path
*/
LIBJAMI_PUBLIC void setResourceDirPath(const std::string& resourceDirPath);
struct LIBJAMI_PUBLIC AudioSignal
{
struct LIBJAMI_PUBLIC DeviceEvent
{
constexpr static const char* name = "audioDeviceEvent";
using cb_type = void(void);
};
// Linear audio level (between 0 and 1). To get level in dB: dB=20*log10(level)
struct LIBJAMI_PUBLIC AudioMeter
{
constexpr static const char* name = "AudioMeter";
using cb_type = void(const std::string& id, float level);
};
};
// Configuration signal type definitions
struct LIBJAMI_PUBLIC ConfigurationSignal
{
struct LIBJAMI_PUBLIC VolumeChanged
{
constexpr static const char* name = "VolumeChanged";
using cb_type = void(const std::string& /*device*/, double /*value*/);
};
struct LIBJAMI_PUBLIC AccountsChanged
{
constexpr static const char* name = "AccountsChanged";
using cb_type = void(void);
};
struct LIBJAMI_PUBLIC Error
{
constexpr static const char* name = "Error";
using cb_type = void(int /*alert*/);
};
// TODO: move those to AccountSignal in next API breakage
struct LIBJAMI_PUBLIC AccountDetailsChanged
{
constexpr static const char* name = "AccountDetailsChanged";
using cb_type = void(const std::string& /*account_id*/,
const std::map<std::string, std::string>& /* details */);
};
struct LIBJAMI_PUBLIC StunStatusFailed
{
constexpr static const char* name = "StunStatusFailed";
using cb_type = void(const std::string& /*account_id*/);
};
struct LIBJAMI_PUBLIC RegistrationStateChanged
{
constexpr static const char* name = "RegistrationStateChanged";
using cb_type = void(const std::string& /*account_id*/,
const std::string& /*state*/,
int /*detailsCode*/,
const std::string& /*detailsStr*/);
};
struct LIBJAMI_PUBLIC VolatileDetailsChanged
{
constexpr static const char* name = "VolatileDetailsChanged";
using cb_type = void(const std::string& /*account_id*/,
const std::map<std::string, std::string>& /* details */);
};
struct LIBJAMI_PUBLIC IncomingAccountMessage
{
constexpr static const char* name = "IncomingAccountMessage";
using cb_type = void(const std::string& /*account_id*/,
const std::string& /*from*/,
const std::string& /*message_id*/,
const std::map<std::string, std::string>& /*payloads*/);
};
struct LIBJAMI_PUBLIC AccountMessageStatusChanged
{
constexpr static const char* name = "AccountMessageStatusChanged";
using cb_type = void(const std::string& /*account_id*/,
const std::string& /*conversation_id*/,
const std::string& /*peer*/,
const std::string& /*message_id*/,
int /*state*/);
};
struct LIBJAMI_PUBLIC NeedsHost
{
constexpr static const char* name = "NeedsHost";
using cb_type = void(const std::string& /*account_id*/,
const std::string& /*conversation_id*/);
};
struct LIBJAMI_PUBLIC ActiveCallsChanged
{
constexpr static const char* name = "ActiveCallsChanged";
using cb_type = void(const std::string& /*account_id*/,
const std::string& /*conversation_id*/,
const std::vector<std::map<std::string, std::string>>& /*activeCalls*/);
};
struct LIBJAMI_PUBLIC ProfileReceived
{
constexpr static const char* name = "ProfileReceived";
using cb_type = void(const std::string& /*account_id*/,
const std::string& /*from*/,
const std::string& /*vcard*/);
};
struct LIBJAMI_PUBLIC ComposingStatusChanged
{
constexpr static const char* name = "ComposingStatusChanged";
using cb_type = void(const std::string& /*account_id*/,
const std::string& /*convId*/,
const std::string& /*from*/,
int /*status*/);
};
struct LIBJAMI_PUBLIC IncomingTrustRequest
{
constexpr static const char* name = "IncomingTrustRequest";
using cb_type = void(const std::string& /*account_id*/,
const std::string& /*from*/,
const std::string& /*conversationId*/,
const std::vector<uint8_t>& payload,
time_t received);
};
struct LIBJAMI_PUBLIC ContactAdded
{
constexpr static const char* name = "ContactAdded";
using cb_type = void(const std::string& /*account_id*/,
const std::string& /*uri*/,
bool confirmed);
};
struct LIBJAMI_PUBLIC ContactRemoved
{
constexpr static const char* name = "ContactRemoved";
using cb_type = void(const std::string& /*account_id*/,
const std::string& /*uri*/,
bool banned);
};
struct LIBJAMI_PUBLIC ExportOnRingEnded
{
constexpr static const char* name = "ExportOnRingEnded";
using cb_type = void(const std::string& /*account_id*/, int state, const std::string& pin);
};
struct LIBJAMI_PUBLIC NameRegistrationEnded
{
constexpr static const char* name = "NameRegistrationEnded";
using cb_type = void(const std::string& /*account_id*/, int state, const std::string& name);
};
struct LIBJAMI_PUBLIC KnownDevicesChanged
{
constexpr static const char* name = "KnownDevicesChanged";
using cb_type = void(const std::string& /*account_id*/,
const std::map<std::string, std::string>& devices);
};
struct LIBJAMI_PUBLIC RegisteredNameFound
{
constexpr static const char* name = "RegisteredNameFound";
using cb_type = void(const std::string& /*account_id*/,
int state,
const std::string& /*address*/,
const std::string& /*name*/);
};
struct LIBJAMI_PUBLIC UserSearchEnded
{
constexpr static const char* name = "UserSearchEnded";
using cb_type = void(const std::string& /*account_id*/,
int state,
const std::string& /*query*/,
const std::vector<std::map<std::string, std::string>>& /*results*/);
};
struct LIBJAMI_PUBLIC CertificatePinned
{
constexpr static const char* name = "CertificatePinned";
using cb_type = void(const std::string& /*certId*/);
};
struct LIBJAMI_PUBLIC CertificatePathPinned
{
constexpr static const char* name = "CertificatePathPinned";
using cb_type = void(const std::string& /*path*/,
const std::vector<std::string>& /*certId*/);
};
struct LIBJAMI_PUBLIC CertificateExpired
{
constexpr static const char* name = "CertificateExpired";
using cb_type = void(const std::string& /*certId*/);
};
struct LIBJAMI_PUBLIC CertificateStateChanged
{
constexpr static const char* name = "CertificateStateChanged";
using cb_type = void(const std::string& /*account_id*/,
const std::string& /*certId*/,
const std::string& /*state*/);
};
struct LIBJAMI_PUBLIC MediaParametersChanged
{
constexpr static const char* name = "MediaParametersChanged";
using cb_type = void(const std::string& /*accountId*/);
};
struct LIBJAMI_PUBLIC MigrationEnded
{
constexpr static const char* name = "MigrationEnded";
using cb_type = void(const std::string& /*accountId*/, const std::string& /*state*/);
};
struct LIBJAMI_PUBLIC DeviceRevocationEnded
{
constexpr static const char* name = "DeviceRevocationEnded";
using cb_type = void(const std::string& /*accountId*/,
const std::string& /*device*/,
int /*status*/);
};
struct LIBJAMI_PUBLIC AccountProfileReceived
{
constexpr static const char* name = "AccountProfileReceived";
using cb_type = void(const std::string& /*accountId*/,
const std::string& displayName,
const std::string& /*userPhoto*/);
};
/**
* These are special getters for Android and UWP, so the daemon can retrieve
* information only accessible through their respective platform APIs
*/
#if defined(__ANDROID__) || (defined(TARGET_OS_IOS) && TARGET_OS_IOS)
struct LIBJAMI_PUBLIC GetHardwareAudioFormat
{
constexpr static const char* name = "GetHardwareAudioFormat";
using cb_type = void(std::vector<int32_t>* /* params_ret */);
};
#endif
#if defined(__ANDROID__) || (defined(TARGET_OS_IOS) && TARGET_OS_IOS)
struct LIBJAMI_PUBLIC GetAppDataPath
{
constexpr static const char* name = "GetAppDataPath";
using cb_type = void(const std::string& name, std::vector<std::string>* /* path_ret */);
};
struct LIBJAMI_PUBLIC GetDeviceName
{
constexpr static const char* name = "GetDeviceName";
using cb_type = void(std::vector<std::string>* /* path_ret */);
};
#endif
struct LIBJAMI_PUBLIC HardwareDecodingChanged
{
constexpr static const char* name = "HardwareDecodingChanged";
using cb_type = void(bool /* state */);
};
struct LIBJAMI_PUBLIC HardwareEncodingChanged
{
constexpr static const char* name = "HardwareEncodingChanged";
using cb_type = void(bool /* state */);
};
struct LIBJAMI_PUBLIC MessageSend
{
constexpr static const char* name = "MessageSend";
using cb_type = void(const std::string&);
};
};
} // namespace libjami
| 25,248
|
C++
|
.h
| 521
| 39.026871
| 144
| 0.645037
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,929
|
media_const.h
|
savoirfairelinux_jami-daemon/src/jami/media_const.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LIBJAMI_MEDIA_H
#define LIBJAMI_MEDIA_H
#include "def.h"
namespace libjami {
namespace Media {
// Supported MRL schemes
namespace VideoProtocolPrefix {
constexpr static const char* NONE = "";
constexpr static const char* DISPLAY = "display";
constexpr static const char* FILE = "file";
constexpr static const char* CAMERA = "camera";
constexpr static const char* SEPARATOR = "://";
} // namespace VideoProtocolPrefix
namespace Details {
constexpr static char MEDIA_TYPE_AUDIO[] = "MEDIA_TYPE_AUDIO";
constexpr static char MEDIA_TYPE_VIDEO[] = "MEDIA_TYPE_VIDEO";
// Renderer and Shm info
constexpr static char CALL_ID[] = "CALL_ID";
constexpr static char SHM_PATH[] = "SHM_PATH";
constexpr static char WIDTH[] = "WIDTH";
constexpr static char HEIGHT[] = "HEIGHT";
} // namespace Details
namespace MediaAttributeKey {
constexpr static char MEDIA_TYPE[] = "MEDIA_TYPE"; // string
constexpr static char ENABLED[] = "ENABLED"; // bool
constexpr static char MUTED[] = "MUTED"; // bool
constexpr static char SOURCE[] = "SOURCE"; // string
constexpr static char LABEL[] = "LABEL"; // string
constexpr static char ON_HOLD[] = "ON_HOLD"; // bool
} // namespace MediaAttributeKey
namespace MediaAttributeValue {
constexpr static auto AUDIO = "MEDIA_TYPE_AUDIO";
constexpr static auto VIDEO = "MEDIA_TYPE_VIDEO";
constexpr static auto SRC_TYPE_NONE = "NONE";
constexpr static auto SRC_TYPE_CAPTURE_DEVICE = "CAPTURE_DEVICE";
constexpr static auto SRC_TYPE_DISPLAY = "DISPLAY";
constexpr static auto SRC_TYPE_FILE = "FILE";
} // namespace MediaAttributeValue
namespace MediaNegotiationStatusEvents {
constexpr static auto NEGOTIATION_SUCCESS = "NEGOTIATION_SUCCESS";
constexpr static auto NEGOTIATION_FAIL = "NEGOTIATION_FAIL";
} // namespace MediaNegotiationStatusEvents
} // namespace Media
} // namespace libjami
#endif
| 2,591
|
C++
|
.h
| 61
| 40.983607
| 73
| 0.751491
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,930
|
def.h
|
savoirfairelinux_jami-daemon/src/jami/def.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
// Generic helper definitions for shared library support
#if defined _WIN32 || defined __CYGWIN__
#define LIBJAMI_IMPORT __declspec(dllimport)
#define LIBJAMI_EXPORT __declspec(dllexport)
#define LIBJAMI_HIDDEN
#else
#define LIBJAMI_IMPORT __attribute__((visibility("default")))
#define LIBJAMI_EXPORT __attribute__((visibility("default")))
#define LIBJAMI_HIDDEN __attribute__((visibility("hidden")))
#endif
// Now we use the generic helper definitions above to define LIBJAMI_PUBLIC and LIBJAMI_LOCAL.
// LIBJAMI_PUBLIC is used for the public API symbols. It is either DLL imports or DLL exports (or does
// nothing for static build) LIBJAMI_LOCAL is used for non-api symbols.
#ifdef jami_EXPORTS // defined if Jami is compiled as a shared library
#ifdef LIBJAMI_BUILD // defined if we are building the Jami shared library (instead of using it)
#define LIBJAMI_PUBLIC LIBJAMI_EXPORT
#else
#define LIBJAMI_PUBLIC LIBJAMI_IMPORT
#endif // LIBJAMI_BUILD
#define LIBJAMI_LOCAL LIBJAMI_HIDDEN
#else // jami_EXPORTS is not defined: this means Jami is a static lib.
#define LIBJAMI_PUBLIC
#define LIBJAMI_LOCAL
#endif // jami_EXPORTS
#ifdef DEBUG
#define LIBJAMI_TESTABLE LIBJAMI_EXPORT
#else
#define LIBJAMI_TESTABLE
#endif
| 1,955
|
C++
|
.h
| 46
| 41.086957
| 102
| 0.775328
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,931
|
security_const.h
|
savoirfairelinux_jami-daemon/src/jami/security_const.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LIBJAMI_SECURITY_H
#define LIBJAMI_SECURITY_H
#include "def.h"
namespace libjami {
namespace Certificate {
namespace Status {
constexpr static char UNDEFINED[] = "UNDEFINED";
constexpr static char ALLOWED[] = "ALLOWED";
constexpr static char BANNED[] = "BANNED";
} // namespace Status
namespace TrustStatus {
constexpr static char UNTRUSTED[] = "UNTRUSTED";
constexpr static char TRUSTED[] = "TRUSTED";
} // namespace TrustStatus
/**
* Those constantes are used by the ConfigurationManager.validateCertificate method
*/
namespace ChecksNames {
constexpr static char HAS_PRIVATE_KEY[] = "HAS_PRIVATE_KEY";
constexpr static char EXPIRED[] = "EXPIRED";
constexpr static char STRONG_SIGNING[] = "STRONG_SIGNING";
constexpr static char NOT_SELF_SIGNED[] = "NOT_SELF_SIGNED";
constexpr static char KEY_MATCH[] = "KEY_MATCH";
constexpr static char PRIVATE_KEY_STORAGE_PERMISSION[] = "PRIVATE_KEY_STORAGE_PERMISSION";
constexpr static char PUBLIC_KEY_STORAGE_PERMISSION[] = "PUBLIC_KEY_STORAGE_PERMISSION";
constexpr static char PRIVATE_KEY_DIRECTORY_PERMISSIONS[] = "PRIVATEKEY_DIRECTORY_PERMISSIONS";
constexpr static char PUBLIC_KEY_DIRECTORY_PERMISSIONS[] = "PUBLICKEY_DIRECTORY_PERMISSIONS";
constexpr static char PRIVATE_KEY_STORAGE_LOCATION[] = "PRIVATE_KEY_STORAGE_LOCATION";
constexpr static char PUBLIC_KEY_STORAGE_LOCATION[] = "PUBLIC_KEY_STORAGE_LOCATION";
constexpr static char PRIVATE_KEY_SELINUX_ATTRIBUTES[] = "PRIVATE_KEY_SELINUX_ATTRIBUTES";
constexpr static char PUBLIC_KEY_SELINUX_ATTRIBUTES[] = "PUBLIC_KEY_SELINUX_ATTRIBUTES";
constexpr static char EXIST[] = "EXIST";
constexpr static char VALID[] = "VALID";
constexpr static char VALID_AUTHORITY[] = "VALID_AUTHORITY";
constexpr static char KNOWN_AUTHORITY[] = "KNOWN_AUTHORITY";
constexpr static char NOT_REVOKED[] = "NOT_REVOKED";
constexpr static char AUTHORITY_MISMATCH[] = "AUTHORITY_MISMATCH";
constexpr static char UNEXPECTED_OWNER[] = "UNEXPECTED_OWNER";
constexpr static char NOT_ACTIVATED[] = "NOT_ACTIVATED";
} // namespace ChecksNames
/**
* Those constants are used by the ConfigurationManager.getCertificateDetails method
*/
namespace DetailsNames {
constexpr static char EXPIRATION_DATE[] = "EXPIRATION_DATE";
constexpr static char ACTIVATION_DATE[] = "ACTIVATION_DATE";
constexpr static char REQUIRE_PRIVATE_KEY_PASSWORD[] = "REQUIRE_PRIVATE_KEY_PASSWORD";
constexpr static char PUBLIC_SIGNATURE[] = "PUBLIC_SIGNATURE";
constexpr static char VERSION_NUMBER[] = "VERSION_NUMBER";
constexpr static char SERIAL_NUMBER[] = "SERIAL_NUMBER";
constexpr static char ISSUER[] = "ISSUER";
constexpr static char SUBJECT_KEY_ALGORITHM[] = "SUBJECT_KEY_ALGORITHM";
constexpr static char SUBJECT_KEY[] = "SUBJECT_KEY";
constexpr static char CN[] = "CN";
constexpr static char UID[] = "UID";
constexpr static char N[] = "N";
constexpr static char O[] = "O";
constexpr static char SIGNATURE_ALGORITHM[] = "SIGNATURE_ALGORITHM";
constexpr static char MD5_FINGERPRINT[] = "MD5_FINGERPRINT";
constexpr static char SHA1_FINGERPRINT[] = "SHA1_FINGERPRINT";
constexpr static char PUBLIC_KEY_ID[] = "PUBLIC_KEY_ID";
constexpr static char ISSUER_DN[] = "ISSUER_DN";
constexpr static char ISSUER_CN[] = "ISSUER_CN";
constexpr static char ISSUER_UID[] = "ISSUER_UID";
constexpr static char ISSUER_N[] = "ISSUER_N";
constexpr static char ISSUER_O[] = "ISSUER_O";
constexpr static char NEXT_EXPECTED_UPDATE_DATE[] = "NEXT_EXPECTED_UPDATE_DATE";
constexpr static char OUTGOING_SERVER[] = "OUTGOING_SERVER";
constexpr static char IS_CA[] = "IS_CA";
} // namespace DetailsNames
/**
* Those constants are used by the ConfigurationManager.getCertificateDetails and
* ConfigurationManager.validateCertificate methods
*/
namespace ChecksValuesTypesNames {
constexpr static char BOOLEAN[] = "BOOLEAN";
constexpr static char ISO_DATE[] = "ISO_DATE";
constexpr static char CUSTOM[] = "CUSTOM";
constexpr static char NUMBER[] = "NUMBER";
} // namespace ChecksValuesTypesNames
/**
* Those constantes are used by the ConfigurationManager.validateCertificate method
*/
namespace CheckValuesNames {
constexpr static char PASSED[] = "PASSED";
constexpr static char FAILED[] = "FAILED";
constexpr static char UNSUPPORTED[] = "UNSUPPORTED";
constexpr static char ISO_DATE[] = "ISO_DATE";
constexpr static char CUSTOM[] = "CUSTOM";
constexpr static char DATE[] = "DATE";
} // namespace CheckValuesNames
} // namespace Certificate
namespace TlsTransport {
constexpr static char TLS_PEER_CERT[] = "TLS_PEER_CERT";
constexpr static char TLS_PEER_CA_NUM[] = "TLS_PEER_CA_NUM";
constexpr static char TLS_PEER_CA_[] = "TLS_PEER_CA_";
constexpr static char TLS_CIPHER[] = "TLS_CIPHER";
} // namespace TlsTransport
} // namespace libjami
#endif
| 5,417
|
C++
|
.h
| 116
| 45.37931
| 95
| 0.772315
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,932
|
callmanager_interface.h
|
savoirfairelinux_jami-daemon/src/jami/callmanager_interface.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LIBJAMI_CALLMANAGERI_H
#define LIBJAMI_CALLMANAGERI_H
#include "def.h"
#include <stdexcept>
#include <map>
#include <memory>
#include <vector>
#include <string>
#include <cstdint>
#include "jami.h"
namespace libjami {
[[deprecated("Replaced by registerSignalHandlers")]] LIBJAMI_PUBLIC void registerCallHandlers(
const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>&);
/* Call related methods */
LIBJAMI_PUBLIC std::string placeCall(const std::string& accountId, const std::string& to);
LIBJAMI_PUBLIC std::string placeCallWithMedia(
const std::string& accountId,
const std::string& to,
const std::vector<std::map<std::string, std::string>>& mediaList);
LIBJAMI_PUBLIC bool refuse(const std::string& accountId, const std::string& callId);
LIBJAMI_PUBLIC bool accept(const std::string& accountId, const std::string& callId);
LIBJAMI_PUBLIC bool hangUp(const std::string& accountId, const std::string& callId);
LIBJAMI_PUBLIC bool hold(const std::string& accountId, const std::string& callId);
LIBJAMI_PUBLIC bool unhold(const std::string& accountId, const std::string& callId);
LIBJAMI_PUBLIC bool muteLocalMedia(const std::string& accountId,
const std::string& callId,
const std::string& mediaType,
bool mute);
LIBJAMI_PUBLIC bool transfer(const std::string& accountId,
const std::string& callId,
const std::string& to);
LIBJAMI_PUBLIC bool attendedTransfer(const std::string& accountId,
const std::string& callId,
const std::string& targetID);
LIBJAMI_PUBLIC std::map<std::string, std::string> getCallDetails(const std::string& accountId,
const std::string& callId);
LIBJAMI_PUBLIC std::vector<std::string> getCallList(const std::string& accountId);
/* APIs that supports an arbitrary number of media */
LIBJAMI_PUBLIC bool acceptWithMedia(const std::string& accountId,
const std::string& callId,
const std::vector<libjami::MediaMap>& mediaList);
LIBJAMI_PUBLIC bool requestMediaChange(const std::string& accountId,
const std::string& callId,
const std::vector<libjami::MediaMap>& mediaList);
/**
* Answer a media change request
* @param accountId
* @param callId
* @param mediaList the list of media attributes. The client can
* control the media through the attributes. The list should have
* the same size as the list reported in the media change request.
* The client can ignore the media update request by not calling this
* method, or calling it with an empty media list.
*/
LIBJAMI_PUBLIC bool answerMediaChangeRequest(const std::string& accountId,
const std::string& callId,
const std::vector<libjami::MediaMap>& mediaList);
/* Conference related methods */
LIBJAMI_PUBLIC bool joinParticipant(const std::string& accountId,
const std::string& sel_callId,
const std::string& account2Id,
const std::string& drag_callId);
LIBJAMI_PUBLIC void createConfFromParticipantList(const std::string& accountId,
const std::vector<std::string>& participants);
LIBJAMI_PUBLIC void setConferenceLayout(const std::string& accountId,
const std::string& confId,
uint32_t layout);
LIBJAMI_PUBLIC bool isConferenceParticipant(const std::string& accountId, const std::string& callId);
LIBJAMI_PUBLIC bool addParticipant(const std::string& accountId,
const std::string& callId,
const std::string& account2Id,
const std::string& confId);
LIBJAMI_PUBLIC bool addMainParticipant(const std::string& accountId, const std::string& confId);
LIBJAMI_PUBLIC bool detachLocalParticipant();
LIBJAMI_PUBLIC bool detachParticipant(const std::string& accountId, const std::string& callId);
LIBJAMI_PUBLIC bool joinConference(const std::string& accountId,
const std::string& sel_confId,
const std::string& account2Id,
const std::string& drag_confId);
LIBJAMI_PUBLIC bool hangUpConference(const std::string& accountId, const std::string& confId);
LIBJAMI_PUBLIC bool holdConference(const std::string& accountId, const std::string& confId);
LIBJAMI_PUBLIC bool unholdConference(const std::string& accountId, const std::string& confId);
LIBJAMI_PUBLIC std::vector<std::string> getConferenceList(const std::string& accountId);
LIBJAMI_PUBLIC std::vector<std::string> getParticipantList(const std::string& accountId,
const std::string& confId);
LIBJAMI_PUBLIC std::string getConferenceId(const std::string& accountId, const std::string& callId);
LIBJAMI_PUBLIC std::map<std::string, std::string> getConferenceDetails(const std::string& accountId,
const std::string& callId);
LIBJAMI_PUBLIC std::vector<libjami::MediaMap> currentMediaList(const std::string& accountId,
const std::string& callId);
LIBJAMI_PUBLIC std::vector<std::map<std::string, std::string>> getConferenceInfos(
const std::string& accountId, const std::string& confId);
LIBJAMI_PUBLIC void setModerator(const std::string& accountId,
const std::string& confId,
const std::string& accountUri,
const bool& state);
/// DEPRECATED USE muteStream
LIBJAMI_PUBLIC void muteParticipant(const std::string& accountId,
const std::string& confId,
const std::string& accountUri,
const bool& state);
// Note: muting Audio not supported yet
LIBJAMI_PUBLIC void muteStream(const std::string& accountId,
const std::string& confId,
const std::string& accountUri,
const std::string& deviceId,
const std::string& streamId,
const bool& state);
/// DEPRECATED, USE setActiveStream
LIBJAMI_PUBLIC void setActiveParticipant(const std::string& accountId,
const std::string& confId,
const std::string& callId);
LIBJAMI_PUBLIC void setActiveStream(const std::string& accountId,
const std::string& confId,
const std::string& accountUri,
const std::string& deviceId,
const std::string& streamId,
const bool& state);
LIBJAMI_PUBLIC void hangupParticipant(const std::string& accountId,
const std::string& confId,
const std::string& accountUri,
const std::string& deviceId);
/// DEPRECATED, use raiseHand
LIBJAMI_PUBLIC void raiseParticipantHand(const std::string& accountId,
const std::string& confId,
const std::string& peerId,
const bool& state);
LIBJAMI_PUBLIC void raiseHand(const std::string& accountId,
const std::string& confId,
const std::string& accountUri,
const std::string& deviceId,
const bool& state);
/* Statistic related methods */
LIBJAMI_PUBLIC void startSmartInfo(uint32_t refreshTimeMs);
LIBJAMI_PUBLIC void stopSmartInfo();
/* File Playback methods */
LIBJAMI_PUBLIC bool startRecordedFilePlayback(const std::string& filepath);
LIBJAMI_PUBLIC void stopRecordedFilePlayback();
/* General audio methods */
LIBJAMI_PUBLIC bool toggleRecording(const std::string& accountId, const std::string& callId);
/* DEPRECATED */
LIBJAMI_PUBLIC void setRecording(const std::string& accountId, const std::string& callId);
LIBJAMI_PUBLIC void recordPlaybackSeek(double value);
LIBJAMI_PUBLIC bool getIsRecording(const std::string& accountId, const std::string& callId);
LIBJAMI_PUBLIC void playDTMF(const std::string& key);
LIBJAMI_PUBLIC void startTone(int32_t start, int32_t type);
LIBJAMI_PUBLIC bool switchInput(const std::string& accountId,
const std::string& callId,
const std::string& resource);
LIBJAMI_PUBLIC bool switchSecondaryInput(const std::string& accountId,
const std::string& confId,
const std::string& resource);
/* Instant messaging */
LIBJAMI_PUBLIC void sendTextMessage(const std::string& accountId,
const std::string& callId,
const std::map<std::string, std::string>& messages,
const std::string& from,
bool isMixed);
// Call signal type definitions
struct LIBJAMI_PUBLIC CallSignal
{
struct LIBJAMI_PUBLIC StateChange
{
constexpr static const char* name = "StateChange";
using cb_type = void(const std::string&, const std::string&, const std::string&, int);
};
struct LIBJAMI_PUBLIC TransferFailed
{
constexpr static const char* name = "TransferFailed";
using cb_type = void(void);
};
struct LIBJAMI_PUBLIC TransferSucceeded
{
constexpr static const char* name = "TransferSucceeded";
using cb_type = void(void);
};
struct LIBJAMI_PUBLIC RecordPlaybackStopped
{
constexpr static const char* name = "RecordPlaybackStopped";
using cb_type = void(const std::string&);
};
struct LIBJAMI_PUBLIC VoiceMailNotify
{
constexpr static const char* name = "VoiceMailNotify";
using cb_type = void(const std::string&, int32_t, int32_t, int32_t);
};
struct LIBJAMI_PUBLIC IncomingMessage
{
constexpr static const char* name = "IncomingMessage";
using cb_type = void(const std::string&,
const std::string&,
const std::string&,
const std::map<std::string, std::string>&);
};
struct LIBJAMI_PUBLIC IncomingCall
{
constexpr static const char* name = "IncomingCall";
using cb_type = void(const std::string&, const std::string&, const std::string&);
};
struct LIBJAMI_PUBLIC IncomingCallWithMedia
{
constexpr static const char* name = "IncomingCallWithMedia";
using cb_type = void(const std::string&,
const std::string&,
const std::string&,
const std::vector<std::map<std::string, std::string>>&);
};
struct LIBJAMI_PUBLIC MediaChangeRequested
{
constexpr static const char* name = "MediaChangeRequested";
using cb_type = void(const std::string&,
const std::string&,
const std::vector<std::map<std::string, std::string>>&);
};
struct LIBJAMI_PUBLIC RecordPlaybackFilepath
{
constexpr static const char* name = "RecordPlaybackFilepath";
using cb_type = void(const std::string&, const std::string&);
};
struct LIBJAMI_PUBLIC ConferenceCreated
{
constexpr static const char* name = "ConferenceCreated";
using cb_type = void(const std::string&, const std::string&, const std::string&);
};
struct LIBJAMI_PUBLIC ConferenceChanged
{
constexpr static const char* name = "ConferenceChanged";
using cb_type = void(const std::string&, const std::string&, const std::string&);
};
struct LIBJAMI_PUBLIC UpdatePlaybackScale
{
constexpr static const char* name = "UpdatePlaybackScale";
using cb_type = void(const std::string&, unsigned, unsigned);
};
struct LIBJAMI_PUBLIC ConferenceRemoved
{
constexpr static const char* name = "ConferenceRemoved";
using cb_type = void(const std::string&, const std::string&);
};
struct LIBJAMI_PUBLIC RecordingStateChanged
{
constexpr static const char* name = "RecordingStateChanged";
using cb_type = void(const std::string&, int);
};
struct LIBJAMI_PUBLIC RtcpReportReceived
{
constexpr static const char* name = "RtcpReportReceived";
using cb_type = void(const std::string&, const std::map<std::string, int>&);
};
struct LIBJAMI_PUBLIC PeerHold
{
constexpr static const char* name = "PeerHold";
using cb_type = void(const std::string&, bool);
};
struct LIBJAMI_PUBLIC VideoMuted
{
constexpr static const char* name = "VideoMuted";
using cb_type = void(const std::string&, bool);
};
struct LIBJAMI_PUBLIC AudioMuted
{
constexpr static const char* name = "AudioMuted";
using cb_type = void(const std::string&, bool);
};
struct LIBJAMI_PUBLIC SmartInfo
{
constexpr static const char* name = "SmartInfo";
using cb_type = void(const std::map<std::string, std::string>&);
};
struct LIBJAMI_PUBLIC ConnectionUpdate
{
constexpr static const char* name = "ConnectionUpdate";
using cb_type = void(const std::string&, int);
};
struct LIBJAMI_PUBLIC OnConferenceInfosUpdated
{
constexpr static const char* name = "OnConferenceInfosUpdated";
using cb_type = void(const std::string&,
const std::vector<std::map<std::string, std::string>>&);
};
struct LIBJAMI_PUBLIC RemoteRecordingChanged
{
constexpr static const char* name = "RemoteRecordingChanged";
using cb_type = void(const std::string&, const std::string&, bool);
};
// Report media negotiation status
struct LIBJAMI_PUBLIC MediaNegotiationStatus
{
constexpr static const char* name = "MediaNegotiationStatus";
using cb_type = void(const std::string&,
const std::string&,
const std::vector<std::map<std::string, std::string>>&);
};
};
} // namespace libjami
#endif // LIBJAMI_CALLMANAGERI_H
| 15,669
|
C++
|
.h
| 312
| 38.384615
| 101
| 0.61557
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,933
|
jami.h
|
savoirfairelinux_jami-daemon/src/jami/jami.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LIBJAMI_H
#define LIBJAMI_H
#include "def.h"
#include <vector>
#include <functional>
#include <string>
#include <map>
#include <memory>
#include <type_traits>
#include <filesystem>
#include "trace-tools.h"
namespace libjami {
/* flags for initialization */
enum InitFlag {
LIBJAMI_FLAG_DEBUG = 1 << 0,
LIBJAMI_FLAG_CONSOLE_LOG = 1 << 1,
LIBJAMI_FLAG_AUTOANSWER = 1 << 2,
LIBJAMI_FLAG_IOS_EXTENSION = 1 << 4,
LIBJAMI_FLAG_NO_LOCAL_AUDIO = 1 << 6,
LIBJAMI_FLAG_NO_LOCAL_VIDEO = 1 << 7,
LIBJAMI_FLAG_NO_LOCAL_MEDIA = LIBJAMI_FLAG_NO_LOCAL_AUDIO | LIBJAMI_FLAG_NO_LOCAL_VIDEO,
LIBJAMI_FLAG_NO_AUTOSYNC = 1 << 8,
LIBJAMI_FLAG_NO_AUTOLOAD = 1 << 9 // disable auto loading of accounts and conversations
};
/**
* Return the library version as string.
*/
LIBJAMI_PUBLIC const char* version() noexcept;
/**
* Return the target platform (OS) as a string.
*/
LIBJAMI_PUBLIC std::string_view platform() noexcept;
/**
* Return the target architecture as a string.
*/
LIBJAMI_PUBLIC std::string_view arch() noexcept;
/**
* Initialize globals, create underlaying daemon.
*
* @param flags Flags to customize this initialization
* @returns true if initialization succeed else false.
*/
LIBJAMI_PUBLIC bool init(enum InitFlag flags) noexcept;
/**
* Start asynchronously daemon created by init().
* @returns true if daemon started successfully
*/
LIBJAMI_PUBLIC bool start(const std::filesystem::path& config_file = {}) noexcept;
/**
* Stop and freeing any resource allocated by daemon
*/
LIBJAMI_PUBLIC void fini() noexcept;
LIBJAMI_PUBLIC bool initialized() noexcept;
/**
* Control log handlers.
*
* @param whom Log handler to control
*/
LIBJAMI_PUBLIC void logging(const std::string& whom, const std::string& action) noexcept;
/* External Callback Dynamic Utilities
*
* The library provides to users a way to be acknowledged
* when daemon's objects have a state change.
* The user is aware of this changement when the deamon calls
* a user-given callback.
* Daemon handles many of these callbacks, one per event type.
* The user registers his callbacks using registerXXXXHandlers() functions.
* As each callback has its own function signature,
* to keep compatibility over releases we don't let user directly provides
* his callbacks as it or through a structure.
* This way brings ABI violation if we need to change the order
* and/or the existence of any callback type.
* Thus the user have to pass them using following template classes
* and functions, that wraps user-callback in a generic and ABI-compatible way.
*/
/* Generic class to transit user callbacks to daemon library.
* Used conjointly with std::shared_ptr to hide the concrete class.
* See CallbackWrapper template for details.
*/
class LIBJAMI_PUBLIC CallbackWrapperBase
{
protected:
// Because post() needs Manager, it should be defined in a .cpp
// so not in a templated class.
// Also we do not want this method to be public in the API.
void post(std::function<void()> cb);
};
/* Concrete class of CallbackWrapperBase.
* This class wraps callbacks of a specific signature.
* Also used to obtain the user callback from a CallbackWrapperBase shared ptr.
*
* This class is CopyConstructible, CopyAssignable, MoveConstructible
* and MoveAssignable.
*/
template<typename TProto>
class CallbackWrapper : public CallbackWrapperBase
{
private:
using TFunc = std::function<TProto>;
TFunc cb_; // The user-callback
public:
const char* file_;
uint32_t linum_;
// Empty wrapper: no callback associated.
// Used to initialize internal callback arrays.
CallbackWrapper() noexcept {}
// Create and initialize a wrapper to given callback.
CallbackWrapper(TFunc&& func, const char* filename, uint32_t linum) noexcept
: cb_(std::forward<TFunc>(func))
, file_(filename)
, linum_(linum)
{}
// Create and initialize a wrapper from a generic CallbackWrapperBase
// shared pointer.
// Note: the given callback is copied into internal storage.
CallbackWrapper(const std::shared_ptr<CallbackWrapperBase>& p) noexcept
{
if (p) {
auto other = (CallbackWrapper<TProto>*) p.get();
cb_ = other->cb_;
file_ = other->file_;
linum_ = other->linum_;
}
}
// Return user-callback reference.
// The returned std::function can be null-initialized if no callback
// has been set.
constexpr const TFunc& operator*() const noexcept { return cb_; }
// Return boolean true value if a non-null callback has been set
constexpr explicit operator bool() const noexcept { return static_cast<bool>(cb_); }
};
/* Concrete class of CallbackWrapperBase.
* This class wraps callbacks of a specific signature.
* Used to retrigger callbacks on a io context to avoid lock if signals cannot
* be emitted while a method is called.
* Also used to obtain the user callback from a CallbackWrapperBase shared ptr.
*
* This class is CopyConstructible, CopyAssignable, MoveConstructible
* and MoveAssignable.
*/
template<typename TProto>
class SerializedCallbackWrapper : public CallbackWrapperBase
{
private:
using TFunc = std::function<TProto>;
TFunc cb_; // The user-callback
// This is quite a ugly method used to transmit templated TFunc with their arguments in the
// ioContext of the manager to avoid locks for signals.
template<typename TCallback>
auto ioContextWrapper(TCallback&& fun)
{
return [this, fun {std::move(fun)}](
auto&&... args) -> decltype(fun(std::forward<decltype(args)>(args)...)) {
post([fun {std::move(fun)},
forwardArgs = std::make_tuple(std::move(args)...)]() mutable {
std::apply(std::move(fun), std::move(forwardArgs));
});
};
}
public:
const char* file_;
uint32_t linum_;
// Empty wrapper: no callback associated.
// Used to initialize internal callback arrays.
SerializedCallbackWrapper() noexcept {}
// Create and initialize a wrapper to given callback.
SerializedCallbackWrapper(TFunc&& func, const char* filename, uint32_t linum) noexcept
: file_(filename)
, linum_(linum)
{
cb_ = ioContextWrapper(func);
}
// Create and initialize a wrapper from a generic CallbackWrapperBase
// shared pointer.
// Note: the given callback is copied into internal storage.
SerializedCallbackWrapper(const std::shared_ptr<CallbackWrapperBase>& p) noexcept
{
if (p) {
auto other = (CallbackWrapper<TProto>*) p.get();
cb_ = ioContextWrapper(other.cb_);
file_ = other->file_;
linum_ = other->linum_;
}
}
// Return user-callback reference.
// The returned std::function can be null-initialized if no callback
// has been set.
constexpr const TFunc& operator*() const noexcept { return cb_; }
// Return boolean true value if a non-null callback has been set
constexpr explicit operator bool() const noexcept { return static_cast<bool>(cb_); }
};
/**
* Return an exportable callback object.
* This object is a std::pair of a string and a CallbackWrapperBase shared_ptr.
* This last wraps given callback in a ABI-compatible way.
* Note: this version accepts callbacks as rvalue only.
*/
template<typename Ts>
std::pair<std::string, std::shared_ptr<CallbackWrapperBase>>
exportable_callback(std::function<typename Ts::cb_type>&& func,
const char* file = CURRENT_FILENAME(),
uint32_t linum = CURRENT_LINE())
{
return std::make_pair((const std::string&) Ts::name,
std::make_shared<CallbackWrapper<typename Ts::cb_type>>(
std::forward<std::function<typename Ts::cb_type>>(func), file, linum));
}
template<typename Ts>
std::pair<std::string, std::shared_ptr<CallbackWrapperBase>>
exportable_serialized_callback(std::function<typename Ts::cb_type>&& func,
const char* file = CURRENT_FILENAME(),
uint32_t linum = CURRENT_LINE())
{
return std::make_pair((const std::string&) Ts::name,
std::make_shared<SerializedCallbackWrapper<typename Ts::cb_type>>(
std::forward<std::function<typename Ts::cb_type>>(func), file, linum));
}
LIBJAMI_PUBLIC void registerSignalHandlers(
const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>&);
LIBJAMI_PUBLIC void unregisterSignalHandlers();
using MediaMap = std::map<std::string, std::string>;
} // namespace libjami
#endif /* LIBJAMI_H */
| 9,458
|
C++
|
.h
| 239
| 34.966527
| 101
| 0.699782
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,934
|
media_buffer.h
|
savoirfairelinux_jami-daemon/src/media/media_buffer.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "videomanager_interface.h"
#include "observer.h"
#include <memory>
#include <functional>
namespace jami {
using MediaFrame = libjami::MediaFrame;
using AudioFrame = libjami::AudioFrame;
using MediaObserver = std::function<void(std::shared_ptr<MediaFrame>&&)>;
#ifdef ENABLE_VIDEO
using VideoFrame = libjami::VideoFrame;
// Some helpers
int videoFrameSize(int format, int width, int height);
#endif // ENABLE_VIDEO
} // namespace jami
| 1,231
|
C++
|
.h
| 34
| 34.470588
| 73
| 0.764111
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,935
|
libav_utils.h
|
savoirfairelinux_jami-daemon/src/media/libav_utils.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <libavutil/samplefmt.h>
#include <vector>
#include <map>
#include <string>
#include <memory>
extern "C" {
struct AVDictionary;
struct AVFrame;
struct AVPixFmtDescriptor;
struct AVBufferRef;
struct AVCodec;
void av_buffer_unref(AVBufferRef **buf);
}
namespace jami {
namespace libav_utils {
void av_init();
const char* const DEFAULT_H264_PROFILE_LEVEL_ID = "profile-level-id=428029";
const char* const MAX_H264_PROFILE_LEVEL_ID = "profile-level-id=640034";
enum AVSampleFormat choose_sample_fmt(const AVCodec* codec, const enum AVSampleFormat* preferred_formats, int preferred_formats_count);
enum AVSampleFormat choose_sample_fmt_default(const AVCodec* codec, enum AVSampleFormat defaultFormat);
bool is_yuv_planar(const AVPixFmtDescriptor& desc);
std::string getError(int err);
const char* getDictValue(const AVDictionary* d, const std::string& key, int flags = 0);
void setDictValue(AVDictionary** d, const std::string& key, const std::string& value, int flags = 0);
void fillWithBlack(AVFrame* frame);
void fillWithSilence(AVFrame* frame);
struct AVBufferRef_deleter {
void operator()(AVBufferRef* buf) const { av_buffer_unref(&buf); }
};
typedef std::unique_ptr<AVBufferRef, AVBufferRef_deleter> AVBufferPtr;
} // namespace libav_utils
} // namespace jami
| 2,019
|
C++
|
.h
| 49
| 39.489796
| 135
| 0.775333
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,936
|
congestion_control.h
|
savoirfairelinux_jami-daemon/src/media/congestion_control.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_REMB_H_
#define MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_REMB_H_
#include <vector>
#include <cstdint>
#include "socket_pair.h"
namespace jami {
enum BandwidthUsage { bwNormal = 0, bwUnderusing = 1, bwOverusing = 2 };
// Receiver Estimated Max Bitrate (REMB) (draft-alvestrand-rmcat-remb).
class CongestionControl
{
public:
CongestionControl();
~CongestionControl();
uint64_t parseREMB(const rtcpREMBHeader& packet);
std::vector<uint8_t> createREMB(uint64_t bitrate_bps);
float kalmanFilter(uint64_t gradiant_delay);
float update_thresh(float m, int deltaT);
float get_thresh();
BandwidthUsage get_bw_state(float estimation, float thresh);
private:
using clock = std::chrono::steady_clock;
using time_point = clock::time_point;
float get_estimate_m(float k, int d_m);
float get_gain_k(float q, float dev_n);
float get_sys_var_p(float k, float q);
float get_var_n(int d_m);
float get_residual_z(float d_m);
float last_estimate_m_ {0.0f};
float last_var_p_ {0.1f};
float last_var_n_ {0.0f};
float last_thresh_y_ {2.0f};
unsigned overuse_counter_;
time_point t0_overuse {time_point::min()};
BandwidthUsage last_state_;
};
} // namespace jami
#endif
| 2,003
|
C++
|
.h
| 53
| 34.584906
| 73
| 0.72469
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,937
|
peerrecorder.h
|
savoirfairelinux_jami-daemon/src/media/peerrecorder.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "recordable.h"
namespace jami {
/*
* @file remoterecorder.h
* @brief Handles the peer's recording states.
*/
class PeerRecorder
{
public:
PeerRecorder() {};
virtual ~PeerRecorder() {};
virtual void peerRecording(bool state) = 0;
virtual bool isPeerRecording() const { return peerRecording_; }
virtual void peerMuted(bool muted, int streamIdx) = 0;
virtual bool isPeerMuted() const { return peerMuted_; }
virtual void peerVoice(bool voice) = 0;
virtual bool hasPeerVoice() const { return peerVoice_; }
protected:
bool peerRecording_ {false};
bool peerMuted_ {false};
bool peerVoice_ {false};
};
} // namespace jami
| 1,412
|
C++
|
.h
| 40
| 32.45
| 73
| 0.730882
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,938
|
socket_pair.h
|
savoirfairelinux_jami-daemon/src/media/socket_pair.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
* Copyright (C) 2012 VLC authors and VideoLAN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "media_io_handle.h"
#ifndef _WIN32
#include <sys/socket.h>
#include <netdb.h>
#include <poll.h>
#else
#include <winsock2.h>
#include <ws2tcpip.h>
using socklen_t = int;
#endif
#include <dhtnet/ip_utils.h>
#include <dhtnet/ice_socket.h>
#include <cstdint>
#include <mutex>
#include <memory>
#include <atomic>
#include <list>
#include <vector>
#include <condition_variable>
#include <functional>
namespace jami {
class SRTPProtoContext;
typedef struct
{
#ifdef WORDS_BIGENDIAN
uint32_t version : 2; /* protocol version */
uint32_t p : 1; /* padding flag */
uint32_t rc : 5; /* reception report count must be 201 for report */
#else
uint32_t rc : 5; /* reception report count must be 201 for report */
uint32_t p : 1; /* padding flag */
uint32_t version : 2; /* protocol version */
#endif
uint32_t pt : 8; /* payload type */
uint32_t len : 16; /* length of RTCP packet */
uint32_t ssrc; /* synchronization source identifier of packet send */
uint32_t id; /* synchronization source identifier of first source */
uint32_t fraction_lost : 8; /* 8 bits of fraction, 24 bits of total packets lost */
uint32_t cum_lost_packet : 24; /* cumulative number packet lost */
uint32_t ext_high; /* Extended highest sequence number received */
uint32_t jitter; /* jitter */
uint32_t lsr; /* last SR timestamp */
uint32_t dlsr; /* Delay since last SR timestamp */
} rtcpRRHeader;
typedef struct
{
#ifdef WORDS_BIGENDIAN
uint32_t version : 2; /* protocol version */
uint32_t p : 1; /* padding flag */
uint32_t rc : 5; /* reception report count must be 201 for report */
#else
uint32_t rc : 5; /* reception report count must be 201 for report */
uint32_t p : 1; /* padding flag */
uint32_t version : 2; /* protocol version */
#endif
uint32_t pt : 8; /* payload type */
uint32_t len : 16; /* length of RTCP packet */
uint32_t ssrc; /* synchronization source identifier of packet send */
uint32_t timestampMSB; /* timestamp MSB */
uint32_t timestampLSB; /* timestamp LSB */
uint32_t timestampRTP; /* RTP timestamp */
uint32_t spc; /* Sender's packet count */
uint32_t soc; /* Sender's octet count */
} rtcpSRHeader;
typedef struct
{
#ifdef WORDS_BIGENDIAN
uint32_t version : 2; /* protocol version */
uint32_t p : 1; /* padding flag always 0 */
uint32_t fmt : 5; /* Feedback message type always 15 */
#else
uint32_t fmt : 5; /* Feedback message type always 15 */
uint32_t p : 1; /* padding flag always 0 */
uint32_t version : 2; /* protocol version */
#endif
uint32_t pt : 8; /* payload type */
uint32_t len : 16; /* length of RTCP packet */
uint32_t ssrc; /* synchronization source identifier of packet sender */
uint32_t ssrc_source; /* synchronization source identifier of first source alway 0*/
uint32_t uid; /* Unique identifier Always ‘R’ ‘E’ ‘M’ ‘B’ (4 ASCII characters). */
uint32_t n_ssrc : 8; /* Number of SSRCs in this message. */
uint32_t br_exp : 6; /* BR Exp */
uint32_t br_mantis : 18; /* BR Mantissa */
uint32_t f_ssrc; /* SSRC feedback */
} rtcpREMBHeader;
typedef struct
{
uint64_t last_send_ts;
std::chrono::steady_clock::time_point last_receive_ts;
uint64_t send_ts;
std::chrono::steady_clock::time_point receive_ts;
} TS_Frame;
class SocketPair
{
public:
SocketPair(const char* uri, int localPort);
SocketPair(std::unique_ptr<dhtnet::IceSocket> rtp_sock, std::unique_ptr<dhtnet::IceSocket> rtcp_sock);
~SocketPair();
void interrupt();
// Set the read blocking mode.
// By default, the read operation will block until data is available
// on the socket. This method allows to switch to unblocking mode
// if to stop the receiver thread to exit and there is no more data
// to read (if the peer mutes/stops the media/RTP stream).
void setReadBlockingMode(bool blocking);
MediaIOHandle* createIOContext(const uint16_t mtu);
void openSockets(const char* uri, int localPort);
void closeSockets();
/*
Supported suites are:
AES_CM_128_HMAC_SHA1_80
SRTP_AES128_CM_HMAC_SHA1_80
AES_CM_128_HMAC_SHA1_32
SRTP_AES128_CM_HMAC_SHA1_3
Example (unsecure) usage:
createSRTP("AES_CM_128_HMAC_SHA1_80",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn",
"AES_CM_128_HMAC_SHA1_80",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn");
Will throw an std::runtime_error on failure, should be handled at a higher level
*/
void createSRTP(const char* out_suite,
const char* out_params,
const char* in_suite,
const char* in_params);
void stopSendOp(bool state = true);
std::list<rtcpRRHeader> getRtcpRR();
std::list<rtcpREMBHeader> getRtcpREMB();
bool waitForRTCP(std::chrono::seconds interval);
double getLastLatency();
void setPacketLossCallback(std::function<void(void)> cb)
{
packetLossCallback_ = std::move(cb);
}
void setRtpDelayCallback(std::function<void(int, int)> cb);
int writeData(uint8_t* buf, int buf_size);
uint16_t lastSeqValOut();
private:
NON_COPYABLE(SocketPair);
using clock = std::chrono::steady_clock;
using time_point = clock::time_point;
int readCallback(uint8_t* buf, int buf_size);
int writeCallback(uint8_t* buf, int buf_size);
int waitForData();
int readRtpData(void* buf, int buf_size);
int readRtcpData(void* buf, int buf_size);
void saveRtcpRRPacket(uint8_t* buf, size_t len);
void saveRtcpREMBPacket(uint8_t* buf, size_t len);
std::mutex dataBuffMutex_;
std::condition_variable cv_;
std::list<std::vector<uint8_t>> rtpDataBuff_;
std::list<std::vector<uint8_t>> rtcpDataBuff_;
std::unique_ptr<dhtnet::IceSocket> rtp_sock_;
std::unique_ptr<dhtnet::IceSocket> rtcp_sock_;
int rtpHandle_ {-1};
int rtcpHandle_ {-1};
dhtnet::IpAddr rtpDestAddr_;
dhtnet::IpAddr rtcpDestAddr_;
std::atomic_bool interrupted_ {false};
// Read operations are blocking. This will allow unblocking the
// receiver thread if the peer stops/mutes the media (RTP)
std::atomic_bool readBlockingMode_ {false};
std::atomic_bool noWrite_ {false};
std::unique_ptr<SRTPProtoContext> srtpContext_;
std::function<void(void)> packetLossCallback_;
std::function<void(int, int)> rtpDelayCallback_;
bool getOneWayDelayGradient(float sendTS, bool marker, int32_t* gradient, int32_t* deltaR);
bool parse_RTP_ext(uint8_t* buf, float* abs);
std::list<rtcpRRHeader> listRtcpRRHeader_;
std::list<rtcpREMBHeader> listRtcpREMBHeader_;
std::mutex rtcpInfo_mutex_;
std::condition_variable cvRtcpPacketReadyToRead_;
static constexpr unsigned MAX_LIST_SIZE {10};
mutable std::atomic_bool rtcpPacketLoss_ {false};
double lastSRTS_ {};
uint32_t lastDLSR_ {};
std::list<double> histoLatency_;
time_point lastRR_time;
uint16_t lastSeqNumIn_ {0};
float lastSendTS_ {0.0f};
time_point lastReceiveTS_ {};
time_point arrival_TS {};
TS_Frame svgTS = {};
};
} // namespace jami
| 8,309
|
C++
|
.h
| 206
| 35.771845
| 106
| 0.665093
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,939
|
decoder_finder.h
|
savoirfairelinux_jami-daemon/src/media/decoder_finder.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
extern "C" {
#include <libavcodec/avcodec.h>
}
namespace jami {
/**
* Attempt to find standalone AVCodec decoder using AVCodecID,
* or fallback to the default decoder.
*/
const AVCodec*
findDecoder(const enum AVCodecID codec_id)
{
const char* codec_name;
switch (codec_id) {
#if 0 && defined(__ANDROID__) && defined(RING_ACCEL)
case AV_CODEC_ID_MPEG4:
codec_name = "mpeg4_mediacodec"; break;
case AV_CODEC_ID_H264:
codec_name = "h264_mediacodec"; break;
case AV_CODEC_ID_HEVC:
codec_name = "hevc_mediacodec"; break;
case AV_CODEC_ID_VP8:
codec_name = "vp8_mediacodec"; break;
case AV_CODEC_ID_VP9:
codec_name = "vp9_mediacodec"; break;
#endif
case AV_CODEC_ID_OPUS:
codec_name = "libopus"; break;
default:
codec_name = nullptr;
}
const AVCodec* codec = nullptr;
if (codec_name)
codec = avcodec_find_decoder_by_name(codec_name);
if (not codec)
codec = avcodec_find_decoder(codec_id);
return codec;
}
} // namespace jami
| 1,784
|
C++
|
.h
| 55
| 28.709091
| 73
| 0.693913
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,940
|
media_recorder.h
|
savoirfairelinux_jami-daemon/src/media/media_recorder.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "media_buffer.h"
#include "media_encoder.h"
#include "media_filter.h"
#include "media_stream.h"
#include "noncopyable.h"
#include "observer.h"
#include <map>
#include <memory>
#include <mutex>
#include <queue>
#include <stdexcept>
#include <string>
#include <utility>
#include <condition_variable>
#include <atomic>
namespace jami {
class MediaRecorder : public std::enable_shared_from_this<MediaRecorder>
{
public:
MediaRecorder();
~MediaRecorder();
/**
* @brief Gets whether or not the recorder is active.
*/
bool isRecording() const;
/**
* @brief Get file path of file to be recorded.
*
* Same path as sent to @setPath, but with
* file extension appended.
*
* NOTE @audioOnly must be called to have the right extension.
*/
std::string getPath() const;
/**
* @brief Resulting file will be audio or video.
*
* Sets whether or not output file will have audio. Determines the extension of the
* output file (.ogg or .webm).
*/
void audioOnly(bool audioOnly);
/**
* @brief Sets output file path.
*
* NOTE An empty path will put the output file in the working directory.
*/
void setPath(const std::string& path);
/**
* @brief Sets title and description metadata for the file.
*
* Uses default if either is empty.
* Default title is "Conversation at %Y-%m-%d %H:%M:%S".
* Default description is "Recorded with Jami https://jami.net".
*
* NOTE replaces %TIMESTAMP with time at start of recording
*/
void setMetadata(const std::string& title, const std::string& desc);
/**
* @brief Adds a stream to the recorder.
*
* Caller must then attach this to the media source.
*/
Observer<std::shared_ptr<MediaFrame>>* addStream(const MediaStream& ms);
/**
* @brief Removes a stream from the recorder.
*
* Caller must then detach this from the media source.
*/
void removeStream(const MediaStream& ms);
/**
* @brief Gets the stream observer.
*
* This is so the caller can detach it from the media source.
*/
Observer<std::shared_ptr<MediaFrame>>* getStream(const std::string& name) const;
/**
* @brief Initializes the file.
*
* Streams must have been added using Observable::attach and @addStream.
*/
int startRecording();
/**
* @brief Finalizes the file.
*
* Streams must be removed using Observable::detach afterwards.
*/
void stopRecording();
private:
NON_COPYABLE(MediaRecorder);
struct StreamObserver;
void onFrame(const std::string& name, const std::shared_ptr<MediaFrame>& frame);
void flush();
void reset();
int initRecord();
void setupVideoOutput();
std::string buildVideoFilter(const std::vector<MediaStream>& peers,
const MediaStream& local) const;
void setupAudioOutput();
std::mutex mutexStreamSetup_;
std::string buildAudioFilter(const std::vector<MediaStream>& peers) const;
std::mutex mutexFrameBuff_;
std::mutex mutexFilterVideo_;
std::mutex mutexFilterAudio_;
std::map<std::string, std::unique_ptr<StreamObserver>> streams_;
std::string path_;
std::tm startTime_;
int64_t startTimeStamp_;
std::string title_;
std::string description_;
std::unique_ptr<MediaEncoder> encoder_;
std::mutex encoderMtx_;
std::unique_ptr<MediaFilter> outputVideoFilter_;
std::unique_ptr<MediaFilter> outputAudioFilter_;
std::unique_ptr<MediaFilter> videoFilter_;
std::unique_ptr<MediaFilter> audioFilter_;
int videoIdx_ = -1;
int audioIdx_ = -1;
bool isRecording_ = false;
bool audioOnly_ = false;
int lastVideoPts_ = 0;
std::condition_variable cv_;
std::atomic_bool interrupted_ {false};
std::list<std::shared_ptr<MediaFrame>> frameBuff_;
};
}; // namespace jami
| 4,745
|
C++
|
.h
| 145
| 28.068966
| 87
| 0.681321
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,941
|
localrecordermanager.h
|
savoirfairelinux_jami-daemon/src/media/localrecordermanager.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <memory>
#include <localrecorder.h>
namespace jami {
class LocalRecorderManager
{
public:
static LocalRecorderManager& instance();
/**
* Remove given local recorder instance from the map.
*/
void removeRecorderByPath(const std::string& path);
/**
* Insert passed local recorder into the map. Path is used as key.
*/
void insertRecorder(const std::string& path, std::unique_ptr<LocalRecorder> rec);
/**
* Get local recorder instance with passed path as key.
*/
LocalRecorder* getRecorderByPath(const std::string& path);
/**
* Return true if the manager owns at least one currently running
* local recorder.
*/
bool hasRunningRecorders();
private:
std::map<std::string, std::unique_ptr<LocalRecorder>> recorderMap_;
std::mutex recorderMapMutex_;
};
} // namespace jami
| 1,604
|
C++
|
.h
| 46
| 31.413043
| 85
| 0.721756
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,942
|
system_codec_container.h
|
savoirfairelinux_jami-daemon/src/media/system_codec_container.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __SYSTEM_CODEC_CONTAINER_H__
#define __SYSTEM_CODEC_CONTAINER_H__
#include "media_codec.h"
#include "ring_types.h"
#include <string>
#include <vector>
#include <memory>
namespace jami {
class SystemCodecContainer;
extern decltype(getGlobalInstance<SystemCodecContainer>)& getSystemCodecContainer;
class SystemCodecContainer
{
public:
SystemCodecContainer();
~SystemCodecContainer();
std::vector<std::shared_ptr<SystemCodecInfo>> getSystemCodecInfoList(
MediaType mediaType = MEDIA_ALL);
std::vector<unsigned> getSystemCodecInfoIdList(MediaType type = MEDIA_ALL);
std::shared_ptr<SystemCodecInfo> searchCodecById(unsigned codecId, MediaType type = MEDIA_ALL);
std::shared_ptr<SystemCodecInfo> searchCodecByName(const std::string& name,
MediaType type = MEDIA_ALL);
std::shared_ptr<SystemCodecInfo> searchCodecByPayload(unsigned payload,
MediaType type = MEDIA_ALL);
void removeCodecByName(const std::string& name, MediaType type = MEDIA_ALL);
void initCodecConfig();
private:
/* available audio & video codec */
std::vector<std::shared_ptr<SystemCodecInfo>> availableCodecList_;
bool setActiveH265();
void checkInstalledCodecs();
};
} // namespace jami
#endif // SYSTEM_CODEC_CONTAINER
| 2,102
|
C++
|
.h
| 49
| 37.693878
| 99
| 0.721376
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,943
|
media_decoder.h
|
savoirfairelinux_jami-daemon/src/media/media_decoder.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "rational.h"
#include "observer.h"
#ifdef ENABLE_VIDEO
#include "video/video_base.h"
#include "video/video_scaler.h"
#endif // ENABLE_VIDEO
#ifdef RING_ACCEL
#include "video/accel.h"
#endif
#include "logger.h"
#include "audio/audio_format.h"
#include "media_device.h"
#include "media_stream.h"
#include "media_buffer.h"
#include "media_attribute.h"
#include "noncopyable.h"
#include <map>
#include <string>
#include <memory>
#include <chrono>
#include <queue>
extern "C" {
struct AVCodecContext;
struct AVStream;
struct AVDictionary;
struct AVFormatContext;
struct AVCodec;
enum AVMediaType;
}
namespace libjami {
class AudioFrame;
}
namespace jami {
using AudioFrame = libjami::AudioFrame;
#ifdef ENABLE_VIDEO
using VideoFrame = libjami::VideoFrame;
#endif
struct AudioFormat;
class RingBuffer;
class Resampler;
class MediaIOHandle;
class MediaDecoder;
enum class DecodeStatus {
Success,
FrameFinished,
EndOfFile,
ReadError,
DecodeError,
RestartRequired,
FallBack
};
class MediaDemuxer
{
public:
MediaDemuxer();
~MediaDemuxer();
enum class Status {
Success,
EndOfFile,
ReadBufferOverflow,
ReadError,
FallBack,
RestartRequired
};
static const char* getStatusStr(Status status);
enum class CurrentState { Demuxing, Finished };
using StreamCallback = std::function<DecodeStatus(AVPacket&)>;
int openInput(const DeviceParams&);
void setInterruptCallback(int (*cb)(void*), void* opaque);
void setIOContext(MediaIOHandle* ioctx);
void findStreamInfo();
int selectStream(AVMediaType type);
void setStreamCallback(unsigned stream, StreamCallback cb = {})
{
if (streams_.size() <= stream)
streams_.resize(stream + 1);
streams_[stream] = std::move(cb);
}
void updateCurrentState(MediaDemuxer::CurrentState state) { currentState_ = state; }
void setFileFinishedCb(std::function<void(bool)> cb);
MediaDemuxer::CurrentState getCurrentState() { return currentState_; }
AVStream* getStream(unsigned stream)
{
if (stream >= inputCtx_->nb_streams) {
JAMI_ERR("Stream index is out of range: %u", stream);
return {};
}
return inputCtx_->streams[stream];
}
Status decode();
Status demuxe();
int64_t getDuration() const;
bool seekFrame(int stream_index, int64_t timestamp);
void setNeedFrameCb(std::function<void()> cb);
bool emitFrame(bool isAudio);
private:
bool streamInfoFound_ {false};
AVFormatContext* inputCtx_ = nullptr;
std::vector<StreamCallback> streams_;
int64_t startTime_;
int64_t lastReadPacketTime_ {};
DeviceParams inputParams_;
AVDictionary* options_ = nullptr;
MediaDemuxer::CurrentState currentState_;
std::mutex audioBufferMutex_ {};
std::mutex videoBufferMutex_ {};
std::queue<std::unique_ptr<AVPacket, std::function<void(AVPacket*)>>> videoBuffer_ {};
std::queue<std::unique_ptr<AVPacket, std::function<void(AVPacket*)>>> audioBuffer_ {};
std::function<void()> needFrameCb_;
std::function<void(bool)> fileFinishedCb_;
void clearFrames();
bool pushFrameFrom(std::queue<std::unique_ptr<AVPacket, std::function<void(AVPacket*)>>>& buffer,
bool isAudio,
std::mutex& mutex);
int baseWidth_ {};
int baseHeight_ {};
};
class MediaDecoder
{
public:
MediaDecoder();
MediaDecoder(MediaObserver observer);
MediaDecoder(const std::shared_ptr<MediaDemuxer>& demuxer, int index);
MediaDecoder(const std::shared_ptr<MediaDemuxer>& demuxer, int index, MediaObserver observer);
MediaDecoder(const std::shared_ptr<MediaDemuxer>& demuxer, AVMediaType type)
: MediaDecoder(demuxer, demuxer->selectStream(type))
{}
~MediaDecoder();
void emulateRate() { emulateRate_ = true; }
int openInput(const DeviceParams&);
void setInterruptCallback(int (*cb)(void*), void* opaque);
void setIOContext(MediaIOHandle* ioctx);
int setup(AVMediaType type);
int setupAudio() { return setup(AVMEDIA_TYPE_AUDIO); }
int setupVideo() { return setup(AVMEDIA_TYPE_VIDEO); }
MediaDemuxer::Status decode();
DecodeStatus flush();
int getWidth() const;
int getHeight() const;
std::string getDecoderName() const;
rational<double> getFps() const;
AVPixelFormat getPixelFormat() const;
void updateStartTime(int64_t startTime);
bool emitFrame(bool isAudio);
void flushBuffers();
void setSeekTime(int64_t time);
#ifdef RING_ACCEL
void enableAccel(bool enableAccel);
#endif
MediaStream getStream(std::string name = "") const;
void setResolutionChangedCallback(std::function<void(int, int)> cb)
{
resolutionChangedCallback_ = std::move(cb);
}
void setFEC(bool enable) { fecEnabled_ = enable; }
void setContextCallback(const std::function<void()>& cb)
{
firstDecode_.exchange(true);
contextCallback_ = cb;
}
private:
NON_COPYABLE(MediaDecoder);
DecodeStatus decode(AVPacket&);
rational<unsigned> getTimeBase() const;
std::shared_ptr<MediaDemuxer> demuxer_;
const AVCodec* inputDecoder_ = nullptr;
AVCodecContext* decoderCtx_ = nullptr;
AVStream* avStream_ = nullptr;
bool emulateRate_ = false;
int64_t startTime_;
int64_t lastTimestamp_ {0};
DeviceParams inputParams_;
int correctPixFmt(int input_pix_fmt);
int setupStream();
bool fallback_ = false;
#ifdef RING_ACCEL
bool enableAccel_ = true;
std::unique_ptr<video::HardwareAccel> accel_;
unsigned short accelFailures_ = 0;
#endif
MediaObserver callback_;
int prepareDecoderContext();
int64_t seekTime_ = -1;
void resetSeekTime() { seekTime_ = -1; }
std::function<void(int, int)> resolutionChangedCallback_;
int width_;
int height_;
bool fecEnabled_ {false};
std::function<void()> contextCallback_;
std::atomic_bool firstDecode_ {true};
protected:
AVDictionary* options_ = nullptr;
};
} // namespace jami
| 6,902
|
C++
|
.h
| 214
| 27.85514
| 101
| 0.707869
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,944
|
media_attribute.h
|
savoirfairelinux_jami-daemon/src/media/media_attribute.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "media/media_codec.h"
#include "jami.h"
namespace jami {
class MediaAttribute
{
public:
MediaAttribute(MediaType type = MediaType::MEDIA_NONE,
bool muted = false,
bool secure = true,
bool enabled = false,
std::string_view source = {},
std::string_view label = {},
bool onHold = false)
: type_(type)
, muted_(muted)
, secure_(secure)
, enabled_(enabled)
, sourceUri_(source)
, label_(label)
, onHold_(onHold)
{}
MediaAttribute(const libjami::MediaMap& mediaMap, bool secure);
static std::vector<MediaAttribute> buildMediaAttributesList(
const std::vector<libjami::MediaMap>& mediaList, bool secure);
static MediaType stringToMediaType(const std::string& mediaType);
static std::pair<bool, MediaType> getMediaType(const libjami::MediaMap& map);
static std::pair<bool, bool> getBoolValue(const libjami::MediaMap& mediaMap,
const std::string& key);
static std::pair<bool, std::string> getStringValue(const libjami::MediaMap& mediaMap,
const std::string& key);
// Return true if at least one media has a matching type.
static bool hasMediaType(const std::vector<MediaAttribute>& mediaList, MediaType type);
// Return a string of a boolean
static char const* boolToString(bool val);
// Return a string of the media type
static char const* mediaTypeToString(MediaType type);
// Convert MediaAttribute to MediaMap
static libjami::MediaMap toMediaMap(const MediaAttribute& mediaAttr);
// Serialize a vector of MediaAttribute to a vector of MediaMap
static std::vector<libjami::MediaMap> mediaAttributesToMediaMaps(
std::vector<MediaAttribute> mediaAttrList);
std::string toString(bool full = false) const;
MediaType type_ {MediaType::MEDIA_NONE};
bool muted_ {false};
bool secure_ {true};
bool enabled_ {false};
std::string sourceUri_ {};
std::string label_ {};
bool onHold_ {false};
// NOTE: the hold and mute attributes are related but not
// tightly coupled. A hold/un-hold operation should always
// trigger a new re-invite to notify the change in media
// direction.For instance, on an active call, the hold action
// would change the media direction attribute from "sendrecv"
// to "sendonly". A new SDP with the new media direction will
// be generated and sent to the peer in the re-invite.
// In contrast, the mute attribute is a local attribute, and
// describes the presence (or absence) of the media signal in
// the stream. In other words, the mute action can be performed
// with or without a media direction change (no re-invite).
// For instance, muting the audio can be done by disabling the
// audio input (capture) of the encoding session, resulting in
// sending RTP packets without actual audio (silence).
bool hasValidVideo();
};
} // namespace jami
| 3,920
|
C++
|
.h
| 86
| 38.94186
| 91
| 0.680734
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,945
|
media_codec.h
|
savoirfairelinux_jami-daemon/src/media/media_codec.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "audio/audio_format.h"
#include <dhtnet/ip_utils.h>
#include <cctype>
#include <string>
#include <vector>
#include <map>
#include <memory>
#include <iostream>
#include <unistd.h>
namespace jami {
enum class KeyExchangeProtocol { NONE, SDES };
enum CodecType : unsigned {
CODEC_NONE = 0, // indicates that no codec is used or defined
CODEC_ENCODER = 1,
CODEC_DECODER = 2,
CODEC_ENCODER_DECODER = CODEC_ENCODER | CODEC_DECODER
};
enum MediaType : unsigned {
MEDIA_NONE = 0, // indicates that no media is used or defined
MEDIA_AUDIO = 1,
MEDIA_VIDEO = 2,
MEDIA_ALL = MEDIA_AUDIO | MEDIA_VIDEO
};
enum class RateMode : unsigned { CRF_CONSTRAINED, CQ, CBR };
/*
* SystemCodecInfo
* represent information of a codec available on the system (using libav)
* store default codec values
*/
struct SystemCodecInfo
{
static constexpr unsigned DEFAULT_CODEC_QUALITY {30};
#ifdef ENABLE_VIDEO
static constexpr unsigned DEFAULT_H264_MIN_QUALITY {40};
static constexpr unsigned DEFAULT_H264_MAX_QUALITY {20};
static constexpr unsigned DEFAULT_VP8_MIN_QUALITY {50};
static constexpr unsigned DEFAULT_VP8_MAX_QUALITY {20};
#endif
// indicates that the codec does not use quality factor
static constexpr unsigned DEFAULT_NO_QUALITY {0};
static constexpr unsigned DEFAULT_MIN_BITRATE {200};
static constexpr unsigned DEFAULT_MAX_BITRATE {6000};
static constexpr unsigned DEFAULT_VIDEO_BITRATE {800}; // in Kbits/second
SystemCodecInfo(unsigned codecId,
unsigned avcodecId,
const std::string& longName,
const std::string& name,
const std::string& libName,
MediaType mediaType,
CodecType codecType = CODEC_NONE,
unsigned bitrate = 0,
unsigned payloadType = 0,
unsigned m_minQuality = DEFAULT_NO_QUALITY,
unsigned m_maxQuality = DEFAULT_NO_QUALITY);
virtual ~SystemCodecInfo();
virtual std::map<std::string, std::string> getCodecSpecifications() const;
/* generic codec information */
unsigned id; /* id of the codec used with dbus */
unsigned avcodecId; /* AVCodecID libav codec identifier */
std::string longName; /* User-friendly codec name */
std::string name; /* RTP codec name as specified by http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml */
std::string libName;
CodecType codecType;
MediaType mediaType;
/* default codec values */
unsigned payloadType;
unsigned bitrate;
unsigned minBitrate = DEFAULT_MIN_BITRATE;
unsigned maxBitrate = DEFAULT_MAX_BITRATE;
unsigned minQuality = DEFAULT_NO_QUALITY;
unsigned maxQuality = DEFAULT_NO_QUALITY;
// User-preferences from client
unsigned order {0}; /*used to define preferred codec list order in UI*/
bool isActive {false};
unsigned quality;
};
/*
* SystemAudioCodecInfo
* represent information of a audio codec available on the system (using libav)
* store default codec values
*/
struct SystemAudioCodecInfo : SystemCodecInfo
{
SystemAudioCodecInfo(unsigned codecId,
unsigned avcodecId,
const std::string& longName,
const std::string& name,
const std::string& libName,
CodecType type,
unsigned bitrate = 0,
unsigned sampleRate = 0,
unsigned nbChannels = 0,
unsigned payloadType = 0,
AVSampleFormat sampleFormat = AV_SAMPLE_FMT_S16);
~SystemAudioCodecInfo();
std::map<std::string, std::string> getCodecSpecifications() const override;
void setCodecSpecifications(const std::map<std::string, std::string>& details);
AudioFormat audioformat {AudioFormat::NONE()};
bool isPCMG722() const;
};
/*
* SystemVideoCodecInfo
* represent information of a video codec available on the system (using libav)
* store default codec values
*/
struct SystemVideoCodecInfo : SystemCodecInfo
{
SystemVideoCodecInfo(unsigned codecId,
unsigned avcodecId,
const std::string& longName,
const std::string& name,
const std::string& libName,
CodecType type = CODEC_NONE,
unsigned bitrate = 0,
unsigned m_minQuality = 0,
unsigned m_maxQuality = 0,
unsigned payloadType = 0,
unsigned frameRate = 0,
unsigned profileId = 0);
~SystemVideoCodecInfo();
void setCodecSpecifications(const std::map<std::string, std::string>& details);
std::map<std::string, std::string> getCodecSpecifications() const override;
unsigned frameRate;
unsigned profileId;
std::string parameters;
bool isAutoQualityEnabled {true};
};
bool operator==(SystemCodecInfo codec1, SystemCodecInfo codec2);
class CryptoAttribute
{
public:
CryptoAttribute() {}
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)
: tag_(tag)
, cryptoSuite_(cryptoSuite)
, srtpKeyMethod_(srtpKeyMethod)
, srtpKeyInfo_(srtpKeyInfo)
, lifetime_(lifetime)
, mkiValue_(mkiValue)
, mkiLength_(mkiLength)
{}
std::string getTag() const { return tag_; }
std::string getCryptoSuite() const { return cryptoSuite_; }
std::string getSrtpKeyMethod() const { return srtpKeyMethod_; }
std::string getSrtpKeyInfo() const { return srtpKeyInfo_; }
std::string getLifetime() const { return lifetime_; }
std::string getMkiValue() const { return mkiValue_; }
std::string getMkiLength() const { return mkiLength_; }
inline explicit operator bool() const { return not tag_.empty(); }
std::string to_string() const
{
return tag_ + " " + cryptoSuite_ + " " + srtpKeyMethod_ + ":" + srtpKeyInfo_;
}
private:
std::string tag_;
std::string cryptoSuite_;
std::string srtpKeyMethod_;
std::string srtpKeyInfo_;
std::string lifetime_;
std::string mkiValue_;
std::string mkiLength_;
};
// Possible values for media direction attribute. 'UNKNOWN' means that the
// direction was not set yet. Useful to detect errors when parsing the SDP.
enum class MediaDirection { SENDRECV, SENDONLY, RECVONLY, INACTIVE, UNKNOWN };
// Possible values for media transport attribute. 'UNKNOWN' means that the
// was not set, or not found when parsing. Useful to detect errors when
// parsing the SDP.
enum class MediaTransport { RTP_AVP, RTP_SAVP, UNKNOWN };
/**
* MediaDescription
* Negotiated RTP media slot
*/
struct MediaDescription
{
/** Audio / video */
MediaType type {};
bool enabled {false};
bool onHold {false};
MediaDirection direction_ {MediaDirection::UNKNOWN};
/** Endpoint socket address */
dhtnet::IpAddr addr {};
/** RTCP socket address */
dhtnet::IpAddr rtcp_addr {};
/** RTP */
std::shared_ptr<SystemCodecInfo> codec {};
unsigned payload_type {};
std::string receiving_sdp {};
unsigned bitrate {};
unsigned rtp_clockrate {8000};
/** Audio parameters */
unsigned frame_size {};
bool fecEnabled {false};
/** Video parameters */
std::string parameters {};
RateMode mode {RateMode::CRF_CONSTRAINED};
bool linkableHW {false};
/** Crypto parameters */
CryptoAttribute crypto {};
};
} // namespace jami
| 8,765
|
C++
|
.h
| 227
| 31.563877
| 132
| 0.656471
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,946
|
media_player.h
|
savoirfairelinux_jami-daemon/src/media/media_player.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "audio/audio_input.h"
#ifdef ENABLE_VIDEO
#include "video/video_input.h"
#endif
#include "media_decoder.h"
#include <atomic>
namespace jami {
class MediaPlayer
{
public:
MediaPlayer(const std::string& resource);
~MediaPlayer();
void pause(bool pause);
bool isInputValid();
const std::string& getId() const;
void muteAudio(bool mute);
bool seekToTime(int64_t time);
int64_t getPlayerPosition() const;
int64_t getPlayerDuration() const;
bool isPaused() const;
void setAutoRestart(bool state) { autoRestart_ = state; }
private:
std::string path_;
bool autoRestart_ {false};
// media inputs
#ifdef ENABLE_VIDEO
std::shared_ptr<jami::video::VideoInput> videoInput_;
#endif
std::shared_ptr<jami::AudioInput> audioInput_;
std::shared_ptr<MediaDemuxer> demuxer_;
ThreadLoop loop_;
int64_t startTime_;
int64_t lastPausedTime_;
int64_t pauseInterval_;
inline bool hasAudio() const { return audioStream_ >= 0; }
inline bool hasVideo() const { return videoStream_ >= 0; }
int audioStream_ = -1;
int videoStream_ = -1;
int64_t fileDuration_ = 0;
void playFileFromBeginning();
std::atomic_bool paused_ {true};
bool readBufferOverflow_ = false;
bool audioStreamEnded_ {false};
bool videoStreamEnded_ {false};
bool configureMediaInputs();
void process();
void emitInfo();
void flushMediaBuffers();
bool streamsFinished();
};
} // namespace jami
| 2,225
|
C++
|
.h
| 68
| 29.191176
| 73
| 0.716418
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,947
|
localrecorder.h
|
savoirfairelinux_jami-daemon/src/media/localrecorder.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "audio/audio_input.h"
#include "recordable.h"
#ifdef ENABLE_VIDEO
#include "video/video_input.h"
#endif
namespace jami {
/*
* @file localrecorder.h
* @brief Class for recording messages locally
*/
/*
* The LocalRecorder class exposes the Recordable interface for
* recording messages locally.
*/
class LocalRecorder : public Recordable
{
public:
LocalRecorder(const std::string& inputUri);
~LocalRecorder();
/**
* Set recording path
*/
void setPath(const std::string& path);
/**
* Start local recording. Return true if recording was successfully
* started, false otherwise.
*/
bool startRecording();
/**
* Stops recording.
*/
void stopRecording() override;
private:
std::string path_;
std::string inputUri_;
// media inputs
#ifdef ENABLE_VIDEO
std::shared_ptr<jami::video::VideoInput> videoInput_;
#endif
std::shared_ptr<jami::AudioInput> audioInput_;
};
} // namespace jami
| 1,718
|
C++
|
.h
| 59
| 26.101695
| 73
| 0.721481
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,948
|
recordable.h
|
savoirfairelinux_jami-daemon/src/media/recordable.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "media_recorder.h"
#include <string>
#include <memory>
#include <mutex>
namespace jami {
class Recordable
{
public:
Recordable();
virtual ~Recordable();
/**
* Return recording state (true/false)
*/
bool isRecording() const
{
std::lock_guard lk {apiMutex_};
return recording_;
}
/**
* This method must be implemented for this interface as calls and conferences
* have different behavior.
* Implementations must call the super method.
*/
virtual bool toggleRecording();
/**
* Stop recording
*/
virtual void stopRecording();
/**
* Start recording
*/
virtual bool startRecording(const std::string& path);
/**
* Return the file path for this recording
*/
virtual std::string getPath() const;
bool isAudioOnly() const;
protected:
mutable std::mutex apiMutex_;
bool recording_ {false};
std::shared_ptr<MediaRecorder> recorder_;
bool isAudioOnly_ {false};
};
} // namespace jami
| 1,774
|
C++
|
.h
| 61
| 25.147541
| 82
| 0.693122
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,949
|
srtp.h
|
savoirfairelinux_jami-daemon/src/media/srtp.h
|
/*
* SRTP encryption/decryption
* Copyright (c) 2012 Martin Storsjo
*
* This file is part of Libav.
*
* Libav is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Libav is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef SRTP_H
#define SRTP_H
#include <stdint.h>
struct AVAES;
struct AVHMAC;
struct SRTPContext
{
struct AVAES* aes;
struct AVHMAC* hmac;
int rtp_hmac_size, rtcp_hmac_size;
uint8_t master_key[16];
uint8_t master_salt[14];
uint8_t rtp_key[16], rtcp_key[16];
uint8_t rtp_salt[14], rtcp_salt[14];
uint8_t rtp_auth[20], rtcp_auth[20];
int seq_largest, seq_initialized;
uint32_t roc;
uint32_t rtcp_index;
};
int ff_srtp_set_crypto(struct SRTPContext* s, const char* suite, const char* params);
void ff_srtp_free(struct SRTPContext* s);
int ff_srtp_decrypt(struct SRTPContext* s, uint8_t* buf, int* lenptr);
int ff_srtp_encrypt(struct SRTPContext* s, const uint8_t* in, int len, uint8_t* out, int outlen);
/* RTCP packet types */
enum RTCPType { RTCP_FIR = 192, RTCP_IJ = 195, RTCP_SR = 200, RTCP_TOKEN = 210, RTCP_REMB = 206 };
#define RTP_PT_IS_RTCP(x) \
(((x) >= RTCP_FIR && (x) <= RTCP_IJ) || ((x) >= RTCP_SR && (x) <= RTCP_TOKEN))
#endif /* SRTP_H */
| 1,838
|
C++
|
.h
| 48
| 35.708333
| 98
| 0.711398
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,950
|
media_stream.h
|
savoirfairelinux_jami-daemon/src/media/media_stream.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "libav_deps.h"
#include "logger.h"
#include "rational.h"
#include "audio/audio_format.h"
#include <string>
namespace jami {
struct MediaStream
{
std::string name {};
int format {-1};
bool isVideo {false};
rational<int> timeBase;
int64_t firstTimestamp {0};
int width {0};
int height {0};
int bitrate {0};
rational<int> frameRate;
int sampleRate {0};
int nbChannels {0};
int frameSize {0};
MediaStream() {}
MediaStream(const std::string& streamName,
int fmt,
rational<int> tb,
int w,
int h,
int br,
rational<int> fr)
: name(streamName)
, format(fmt)
, isVideo(true)
, timeBase(tb)
, width(w)
, height(h)
, bitrate(br)
, frameRate(fr)
{}
MediaStream(
const std::string& streamName, int fmt, rational<int> tb, int sr, int channels, int size)
: name(streamName)
, format(fmt)
, isVideo(false)
, timeBase(tb)
, sampleRate(sr)
, nbChannels(channels)
, frameSize(size)
{}
MediaStream(const std::string& streamName, AudioFormat fmt)
: MediaStream(streamName, fmt, 0)
{}
MediaStream(const std::string& streamName, AudioFormat fmt, int64_t startTimestamp)
: name(streamName)
, format(fmt.sampleFormat)
, isVideo(false)
, timeBase(1, fmt.sample_rate)
, firstTimestamp(startTimestamp)
, sampleRate(fmt.sample_rate)
, nbChannels(fmt.nb_channels)
, frameSize(fmt.sample_rate / 50) // standard frame size for our encoder is 20 ms
{}
MediaStream(const std::string& streamName, AVCodecContext* c)
: MediaStream(streamName, c, 0)
{}
MediaStream(const std::string& streamName, AVCodecContext* c, int64_t startTimestamp)
: name(streamName)
, firstTimestamp(startTimestamp)
{
if (c) {
timeBase = c->time_base;
switch (c->codec_type) {
case AVMEDIA_TYPE_VIDEO:
format = c->pix_fmt;
isVideo = true;
width = c->width;
height = c->height;
bitrate = c->bit_rate;
frameRate = c->framerate;
break;
case AVMEDIA_TYPE_AUDIO:
format = c->sample_fmt;
isVideo = false;
sampleRate = c->sample_rate;
nbChannels = c->ch_layout.nb_channels;
frameSize = c->frame_size;
break;
default:
break;
}
} else {
JAMI_WARN() << "Attempting to get stream info from null codec context";
}
}
MediaStream(const MediaStream& other) = default;
bool isValid() const
{
if (format < 0)
return false;
if (isVideo)
return width > 0 && height > 0;
else
return sampleRate > 0 && nbChannels > 0;
}
void update(AVFrame* f)
{
// update all info possible (AVFrame has no fps or bitrate data)
format = f->format;
if (isVideo) {
width = f->width;
height = f->height;
} else {
sampleRate = f->sample_rate;
nbChannels = f->ch_layout.nb_channels;
timeBase = rational<int>(1, f->sample_rate);
if (!frameSize)
frameSize = f->nb_samples;
}
}
friend bool operator==(const MediaStream& ms1, const MediaStream& ms2)
{
return ms1.bitrate == ms2.bitrate and ms1.firstTimestamp == ms2.firstTimestamp
and ms1.format == ms2.format and ms1.frameRate == ms2.frameRate
and ms1.frameSize == ms2.frameSize and ms1.height == ms2.height
and ms1.isVideo == ms2.isVideo and ms1.name == ms2.name
and ms1.nbChannels == ms2.nbChannels and ms1.sampleRate == ms2.sampleRate
and ms1.timeBase == ms2.timeBase and ms1.width == ms2.width;
}
};
inline std::ostream&
operator<<(std::ostream& os, const MediaStream& ms)
{
if (ms.isVideo) {
auto formatName = av_get_pix_fmt_name(static_cast<AVPixelFormat>(ms.format));
os << (ms.name.empty() ? "(null)" : ms.name) << ": "
<< (formatName ? formatName : "(unknown format)") << " video, " << ms.width << "x"
<< ms.height << ", " << ms.frameRate << " fps (" << ms.timeBase << ")";
if (ms.bitrate > 0)
os << ", " << ms.bitrate << " kb/s";
} else {
os << (ms.name.empty() ? "(null)" : ms.name) << ": "
<< av_get_sample_fmt_name(static_cast<AVSampleFormat>(ms.format)) << " audio, "
<< ms.nbChannels << " channel(s), " << ms.sampleRate << " Hz (" << ms.timeBase << "), "
<< ms.frameSize << " samples per frame";
}
if (ms.firstTimestamp > 0)
os << ", start: " << ms.firstTimestamp;
return os;
}
}; // namespace jami
| 5,805
|
C++
|
.h
| 165
| 26.751515
| 98
| 0.569625
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,951
|
libav_deps.h
|
savoirfairelinux_jami-daemon/src/media/libav_deps.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __LIBAV_DEPS_H__
#define __LIBAV_DEPS_H__
// NOTE versions of FFmpeg's librairies can be checked using something like this:
// #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( major, minor, micro )
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavfilter/avfilter.h>
#include <libavformat/avformat.h>
#include <libavdevice/avdevice.h>
#include <libswscale/swscale.h>
#include <libavutil/avutil.h>
#include <libavutil/time.h>
#include <libavutil/pixdesc.h>
#include <libavutil/opt.h>
#include <libavutil/channel_layout.h>
#include <libavutil/imgutils.h>
#include <libavutil/intreadwrite.h>
#include <libavutil/log.h>
#include <libavutil/samplefmt.h>
#if LIBAVUTIL_VERSION_MAJOR < 56
AVFrameSideData* av_frame_new_side_data_from_buf(AVFrame* frame,
enum AVFrameSideDataType type,
AVBufferRef* buf);
#endif
}
#include "libav_utils.h"
#endif // __LIBAV_DEPS_H__
| 1,694
|
C++
|
.h
| 43
| 35.627907
| 81
| 0.718541
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,952
|
media_encoder.h
|
savoirfairelinux_jami-daemon/src/media/media_encoder.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef ENABLE_VIDEO
#include "video/video_base.h"
#include "video/video_scaler.h"
#endif
#include "noncopyable.h"
#include "media_buffer.h"
#include "media_codec.h"
#include "media_stream.h"
#include <map>
#include <memory>
#include <string>
#include <vector>
extern "C" {
struct AVCodecContext;
struct AVFormatContext;
struct AVDictionary;
struct AVCodec;
}
namespace jami {
struct MediaDescription;
#ifdef RING_ACCEL
namespace video {
class HardwareAccel;
}
#endif
class MediaEncoderException : public std::runtime_error
{
public:
MediaEncoderException(const char* msg)
: std::runtime_error(msg){}
MediaEncoderException(const std::string& msg)
: std::runtime_error(msg){}
};
class MediaEncoder
{
public:
MediaEncoder();
~MediaEncoder();
void openOutput(const std::string& filename, const std::string& format = "");
void setMetadata(const std::string& title, const std::string& description);
void setOptions(const MediaStream& opts);
void setOptions(const MediaDescription& args);
int addStream(const SystemCodecInfo& codec);
void setIOContext(AVIOContext* ioctx) { ioCtx_ = ioctx; }
void resetStreams(int width, int height);
bool send(AVPacket& packet, int streamIdx = -1);
#ifdef ENABLE_VIDEO
int encode(const std::shared_ptr<VideoFrame>& input, bool is_keyframe, int64_t frame_number);
#endif // ENABLE_VIDEO
int encodeAudio(AudioFrame& frame);
// frame should be ready to be sent to the encoder at this point
int encode(AVFrame* frame, int streamIdx);
int flush();
std::string print_sdp();
/* getWidth and getHeight return size of the encoded frame.
* Values have meaning only after openLiveOutput call.
*/
int getWidth() const { return videoOpts_.width; };
int getHeight() const { return videoOpts_.height; };
void setInitSeqVal(uint16_t seqVal);
uint16_t getLastSeqValue();
const std::string& getAudioCodec() const { return audioCodec_; }
const std::string& getVideoCodec() const { return videoCodec_; }
int setBitrate(uint64_t br);
int setPacketLoss(uint64_t pl);
#ifdef RING_ACCEL
void enableAccel(bool enableAccel);
#endif
static std::string testH265Accel();
unsigned getStreamCount() const;
MediaStream getStream(const std::string& name, int streamIdx = -1) const;
private:
NON_COPYABLE(MediaEncoder);
AVCodecContext* prepareEncoderContext(const AVCodec* outputCodec, bool is_video);
void forcePresetX2645(AVCodecContext* encoderCtx);
void extractProfileLevelID(const std::string& parameters, AVCodecContext* ctx);
int initStream(const std::string& codecName, AVBufferRef* framesCtx = {});
int initStream(const SystemCodecInfo& systemCodecInfo, AVBufferRef* framesCtx = {});
void openIOContext();
void startIO();
AVCodecContext* getCurrentVideoAVCtx();
AVCodecContext* getCurrentAudioAVCtx();
void stopEncoder();
AVCodecContext* initCodec(AVMediaType mediaType, AVCodecID avcodecId, uint64_t br);
void initH264(AVCodecContext* encoderCtx, uint64_t br);
void initH265(AVCodecContext* encoderCtx, uint64_t br);
void initVP8(AVCodecContext* encoderCtx, uint64_t br);
void initMPEG4(AVCodecContext* encoderCtx, uint64_t br);
void initH263(AVCodecContext* encoderCtx, uint64_t br);
void initOpus(AVCodecContext* encoderCtx);
bool isDynBitrateSupported(AVCodecID codecid);
bool isDynPacketLossSupported(AVCodecID codecid);
void initAccel(AVCodecContext* encoderCtx, uint64_t br);
#ifdef ENABLE_VIDEO
int getHWFrame(const std::shared_ptr<VideoFrame>& input, std::shared_ptr<VideoFrame>& output);
std::shared_ptr<VideoFrame> getUnlinkedHWFrame(const VideoFrame& input);
std::shared_ptr<VideoFrame> getHWFrameFromSWFrame(const VideoFrame& input);
std::shared_ptr<VideoFrame> getScaledSWFrame(const VideoFrame& input);
#endif
std::vector<AVCodecContext*> encoders_;
AVFormatContext* outputCtx_ = nullptr;
AVIOContext* ioCtx_ = nullptr;
int currentStreamIdx_ = -1;
unsigned sent_samples = 0;
bool initialized_ {false};
bool fileIO_ {false};
unsigned int currentVideoCodecID_ {0};
const AVCodec* outputCodec_ = nullptr;
std::mutex encMutex_;
bool linkableHW_ {false};
RateMode mode_ {RateMode::CRF_CONSTRAINED};
bool fecEnabled_ {false};
#ifdef ENABLE_VIDEO
video::VideoScaler scaler_;
std::shared_ptr<VideoFrame> scaledFrame_;
#endif // ENABLE_VIDEO
std::vector<uint8_t> scaledFrameBuffer_;
int scaledFrameBufferSize_ = 0;
#ifdef RING_ACCEL
bool enableAccel_ {false};
std::unique_ptr<video::HardwareAccel> accel_;
#endif
protected:
void readConfig(AVCodecContext* encoderCtx);
AVDictionary* options_ = nullptr;
MediaStream videoOpts_;
MediaStream audioOpts_;
std::string videoCodec_;
std::string audioCodec_;
};
} // namespace jami
| 5,690
|
C++
|
.h
| 151
| 34.066225
| 98
| 0.744055
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,953
|
rtp_session.h
|
savoirfairelinux_jami-daemon/src/media/rtp_session.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "socket_pair.h"
#include "connectivity/sip_utils.h"
#include "media/media_codec.h"
#include <functional>
#include <string>
#include <memory>
#include <mutex>
namespace jami {
class MediaRecorder;
class RtpSession
{
public:
// Media direction
enum class Direction { SEND, RECV };
// Note: callId is used for ring buffers and smarttools
RtpSession(const std::string& callId, const std::string& streamId, MediaType type)
: callId_(callId)
, streamId_(streamId)
, mediaType_(type)
{}
virtual ~RtpSession() {};
virtual void start(std::unique_ptr<dhtnet::IceSocket> rtp_sock, std::unique_ptr<dhtnet::IceSocket> rtcp_sock) = 0;
virtual void restartSender() = 0;
virtual void stop() = 0;
void setMediaSource(const std::string& resource) { input_ = resource; }
const std::string& getInput() const { return input_; }
MediaType getMediaType() const { return mediaType_; };
virtual void setMuted(bool mute, Direction dir = Direction::SEND) = 0;
virtual void updateMedia(const MediaDescription& send, const MediaDescription& receive)
{
send_ = send;
receive_ = receive;
}
void setMtu(uint16_t mtu) { mtu_ = mtu; }
void setSuccessfulSetupCb(const std::function<void(MediaType, bool)>& cb)
{
onSuccessfulSetup_ = cb;
}
virtual void initRecorder() = 0;
virtual void deinitRecorder() = 0;
std::shared_ptr<SystemCodecInfo> getCodec() const { return send_.codec; }
const dhtnet::IpAddr& getSendAddr() const { return send_.addr; };
const dhtnet::IpAddr& getRecvAddr() const { return receive_.addr; };
inline std::string streamId() const { return streamId_; }
protected:
std::recursive_mutex mutex_;
const std::string callId_;
const std::string streamId_;
MediaType mediaType_;
std::unique_ptr<SocketPair> socketPair_;
std::string input_ {};
MediaDescription send_;
MediaDescription receive_;
uint16_t mtu_;
std::shared_ptr<MediaRecorder> recorder_;
std::function<void(MediaType, bool)> onSuccessfulSetup_;
std::string getRemoteRtpUri() const { return "rtp://" + send_.addr.toString(true); }
};
} // namespace jami
| 2,948
|
C++
|
.h
| 76
| 34.763158
| 118
| 0.704235
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,954
|
media_io_handle.h
|
savoirfairelinux_jami-daemon/src/media/media_io_handle.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __MEDIA_IO_HANDLE_H__
#define __MEDIA_IO_HANDLE_H__
#include "noncopyable.h"
#include <cstdlib>
#include <cstdint>
#include <vector>
#ifndef AVFORMAT_AVIO_H
struct AVIOContext;
#endif
typedef int (*io_readcallback)(void* opaque, uint8_t* buf, int buf_size);
typedef int (*io_writecallback)(void* opaque, uint8_t* buf, int buf_size);
typedef int64_t (*io_seekcallback)(void* opaque, int64_t offset, int whence);
namespace jami {
class MediaIOHandle
{
public:
MediaIOHandle(std::size_t buffer_size,
bool writeable,
io_readcallback read_cb,
io_writecallback write_cb,
io_seekcallback seek_cb,
void* opaque);
~MediaIOHandle();
AVIOContext* getContext() { return ctx_; }
private:
NON_COPYABLE(MediaIOHandle);
AVIOContext* ctx_;
};
} // namespace jami
#endif // __MEDIA_DECODER_H__
| 1,622
|
C++
|
.h
| 46
| 31.304348
| 77
| 0.704153
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,955
|
media_filter.h
|
savoirfairelinux_jami-daemon/src/media/media_filter.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "media_stream.h"
#include "noncopyable.h"
#include "video/video_base.h"
#include <map>
#include <string>
#include <vector>
extern "C" {
struct AVFilterContext;
struct AVFilterGraph;
struct AVFilterInOut;
}
namespace jami {
/**
* @brief Provides access to libavfilter.
*
* Can be used for filters with unlimited number of inputs.
* Multiple outputs are not supported. They add complexity for little gain.
*
* For information on how to write a filter graph description, see:
* https://ffmpeg.org/ffmpeg-filters.html
* http://trac.ffmpeg.org/wiki/FilteringGuide
*
* It is required to name each filter graph input. These names are used to feed the correct input.
* It is the same name that will be passed as second argument to feedInput(AVFrame*, std::string).
*
* Examples:
*
* - "[in1] scale=320:240"
* Scales the input to 320x240.
*
* - "[in1] scale=iw/4:ih/4 [mid]; [in2] [mid] overlay=main_w-overlay_w-10:main_h-overlay_h-10"
* in1 will be scaled to 1/16th its size and placed over in2 in the bottom right corner. When
* feeding frames to the filter, you need to specify whether the frame is destined for in1 or in2.
*/
class MediaFilter
{
public:
MediaFilter();
~MediaFilter();
/**
* @brief Returns the current filter graph string.
*/
std::string getFilterDesc() const;
/**
* @brief Initializes the filter graph with one or more inputs and one output. Returns a
* negative code on error.
*/
int initialize(const std::string& filterDesc, const std::vector<MediaStream>& msps);
/**
* @brief Returns a MediaStream object describing the input specified by @inputName.
*/
const MediaStream& getInputParams(const std::string& inputName) const;
/**
* @brief Returns a MediaStream struct describing the frames that will be output.
*
* When called in an invalid state, the returned format will be invalid (less than 0).
*/
MediaStream getOutputParams() const;
/**
* @brief Give the specified source filter an input frame.
*
* Caller is responsible for freeing the frame.
*
* NOTE Will fail if @inputName is not found in the graph.
*/
int feedInput(AVFrame* frame, const std::string& inputName);
/**
* @brief Pull a frame from the filter graph. Caller owns the frame reference.
*
* Returns AVERROR(EAGAIN) if filter graph requires more input.
*
* NOTE Frame reference belongs to the caller
*/
std::unique_ptr<MediaFrame> readOutput();
/**
* @brief Flush filter to indicate EOF.
*/
void flush();
private:
NON_COPYABLE(MediaFilter);
/**
* @brief Initializes output of filter graph.
*/
int initOutputFilter(AVFilterInOut* out);
/**
* @brief Initializes an input of filter graph.
*/
int initInputFilter(AVFilterInOut* in, const MediaStream& msp);
/**
* @brief Reinitializes the filter graph.
*
* Reinitializes with @inputParams_, which should be updated beforehand.
*/
int reinitialize();
/**
* @brief Convenience method that prints @msg and returns err.
*
* NOTE @msg should not be null.
*/
int fail(std::string_view msg, int err) const;
/**
* @brief Frees resources used by MediaFilter.
*/
void clean();
/**
* @brief Filter graph pointer.
*/
AVFilterGraph* graph_ = nullptr;
/**
* @brief Filter graph output.
*
* Corresponds to a buffersink/abuffersink filter.
*/
AVFilterContext* output_ = nullptr;
/**
* @brief List of filter graph inputs.
*
* Each corresponds to a buffer/abuffer filter.
*/
std::vector<AVFilterContext*> inputs_;
/**
* @brief List of filter graph input parameters.
*
* Same order as @inputs_.
*/
std::vector<MediaStream> inputParams_;
/**
* @brief Filter graph string.
*/
std::string desc_ {};
/**
* @brief Flag to know whether or not the filter graph is initialized.
*/
bool initialized_ {false};
};
}; // namespace jami
| 4,907
|
C++
|
.h
| 156
| 27.230769
| 98
| 0.682116
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,956
|
media_device.h
|
savoirfairelinux_jami-daemon/src/media/media_device.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __MEDIA_DEVICE_H__
#define __MEDIA_DEVICE_H__
#include "rational.h"
#include <string>
#include <chrono>
namespace jami {
constexpr static auto NEWPARAMS_TIMEOUT = std::chrono::milliseconds(1000);
/**
* DeviceParams
* Parameters used by MediaDecoder and MediaEncoder
* to open a LibAV device/stream
*/
struct DeviceParams
{
std::string name {}; // friendly name (e.g. Logitech BRIO)
std::string input {}; // Device path (e.g. /dev/video0)
std::string unique_id {}; // unique id (e.g. 046d082d8A8B667F)
std::string format {};
unsigned width {}, height {};
rational<double> framerate {};
std::string pixel_format {};
std::string channel_name {};
unsigned channel {}; // Channel number
std::string loop {};
std::string sdp_flags {};
int offset_x {};
int offset_y {};
int orientation {};
std::string window_id {};
int fd {}; // file descriptor for PipeWire (only relevant on Wayland)
std::string node {}; // node id for PipeWire
int is_area {};
};
} // namespace jami
#endif // __MEDIA_DEVICE_H__
| 1,810
|
C++
|
.h
| 51
| 32.54902
| 74
| 0.693889
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,957
|
video_base.h
|
savoirfairelinux_jami-daemon/src/media/video/video_base.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "noncopyable.h"
#include "observer.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#pragma GCC diagnostic ignored "-Wshadow"
#include <yaml-cpp/yaml.h>
#pragma GCC diagnostic pop
#include <cstdlib>
#include <cstdint>
#include <memory>
#include <set>
#include <mutex>
#include <ciso646> // fix windows compiler bug
extern "C" {
#include <libavutil/pixfmt.h>
struct AVPacket;
struct AVDictionary;
#ifndef AVFORMAT_AVIO_H
struct AVIOContext;
#endif
}
namespace libjami {
class MediaFrame;
class VideoFrame;
} // namespace libjami
namespace jami {
using MediaFrame = libjami::MediaFrame;
using VideoFrame = libjami::VideoFrame;
} // namespace jami
namespace jami {
namespace video {
struct VideoFrameActiveWriter : Observable<std::shared_ptr<MediaFrame>>
{};
struct VideoFramePassiveReader : Observer<std::shared_ptr<MediaFrame>>
{};
/*=== VideoGenerator =========================================================*/
class VideoGenerator : public VideoFrameActiveWriter
{
public:
VideoGenerator() {}
virtual int getWidth() const = 0;
virtual int getHeight() const = 0;
virtual AVPixelFormat getPixelFormat() const = 0;
std::shared_ptr<VideoFrame> obtainLastFrame();
public:
// getNewFrame and publishFrame must be called by the same thread only
VideoFrame& getNewFrame();
void publishFrame();
void publishFrame(std::shared_ptr<VideoFrame>);
void flushFrames();
private:
std::shared_ptr<VideoFrame> writableFrame_ = nullptr;
std::shared_ptr<VideoFrame> lastFrame_ = nullptr;
std::mutex mutex_ {}; // lock writableFrame_/lastFrame_ access
};
struct VideoSettings
{
VideoSettings() {}
VideoSettings(const std::map<std::string, std::string>& settings);
std::map<std::string, std::string> to_map() const;
std::string unique_id {};
std::string input {};
std::string name {};
std::string channel {};
std::string video_size {};
std::string framerate {};
};
} // namespace video
} // namespace jami
namespace YAML {
template<>
struct convert<jami::video::VideoSettings>
{
static Node encode(const jami::video::VideoSettings& rhs);
static bool decode(const Node& node, jami::video::VideoSettings& rhs);
};
Emitter& operator<<(Emitter& out, const jami::video::VideoSettings& v);
} // namespace YAML
| 3,082
|
C++
|
.h
| 95
| 30.031579
| 80
| 0.731107
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,958
|
video_scaler.h
|
savoirfairelinux_jami-daemon/src/media/video/video_scaler.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __VIDEO_SCALER_H__
#define __VIDEO_SCALER_H__
#include "video_base.h"
#include "noncopyable.h"
struct SwsContext;
extern "C" {
struct AVFrame;
}
namespace jami {
namespace video {
class VideoScaler
{
public:
VideoScaler();
~VideoScaler();
void reset();
void scale(const AVFrame* input, AVFrame* output);
void scale(const VideoFrame& input, VideoFrame& output);
void scale_with_aspect(const VideoFrame& input, VideoFrame& output);
void scale_and_pad(const VideoFrame& input,
VideoFrame& output,
unsigned xoff,
unsigned yoff,
unsigned dest_width,
unsigned dest_height,
bool keep_aspect);
std::unique_ptr<VideoFrame> convertFormat(const VideoFrame& input, AVPixelFormat pix);
private:
NON_COPYABLE(VideoScaler);
SwsContext* ctx_;
int mode_;
uint8_t* tmp_data_[4]; // used by scale_and_pad
};
} // namespace video
} // namespace jami
#endif // __VIDEO_SCALER_H__
| 1,779
|
C++
|
.h
| 52
| 29.173077
| 90
| 0.681024
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,959
|
video_receive_thread.h
|
savoirfairelinux_jami-daemon/src/media/video/video_receive_thread.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _VIDEO_RECEIVE_THREAD_H_
#define _VIDEO_RECEIVE_THREAD_H_
#include "video_base.h"
#include "media/media_codec.h"
#include "media/media_io_handle.h"
#include "media/media_codec.h"
#include "media/media_device.h"
#include "media/media_stream.h"
#include "threadloop.h"
#include "noncopyable.h"
#include "media/libav_utils.h"
#include <functional>
#include <map>
#include <string>
#include <climits>
#include <sstream>
#include <memory>
namespace jami {
class SocketPair;
class MediaDecoder;
} // namespace jami
namespace jami {
namespace video {
class SinkClient;
class VideoReceiveThread : public VideoGenerator
{
public:
VideoReceiveThread(const std::string& id, bool useSink, const std::string& sdp, uint16_t mtu);
~VideoReceiveThread();
void startLoop();
void stopLoop();
void decodeFrame();
void addIOContext(SocketPair& socketPair);
void setRequestKeyFrameCallback(std::function<void(void)> cb)
{
keyFrameRequestCallback_ = std::move(cb);
};
void startSink();
void stopSink();
std::shared_ptr<SinkClient>& getSink() { return sink_; }
// as VideoGenerator
int getWidth() const;
int getHeight() const;
AVPixelFormat getPixelFormat() const;
MediaStream getInfo() const;
/**
* Set angle of rotation to apply to the video by the decoder
*
* @param angle Angle of rotation in degrees (counterclockwise)
*/
void setRotation(int angle);
void setSuccessfulSetupCb(const std::function<void(MediaType, bool)>& cb)
{
onSuccessfulSetup_ = cb;
}
void setRecorderCallback(
const std::function<void(const MediaStream& ms)>& cb);
private:
NON_COPYABLE(VideoReceiveThread);
DeviceParams args_;
/*-------------------------------------------------------------*/
/* These variables should be used in thread (i.e. run()) only! */
/*-------------------------------------------------------------*/
std::unique_ptr<MediaDecoder> videoDecoder_;
int dstWidth_ {0};
int dstHeight_ {0};
const std::string id_;
bool useSink_;
std::istringstream stream_;
MediaIOHandle sdpContext_;
std::unique_ptr<MediaIOHandle> demuxContext_;
std::shared_ptr<SinkClient> sink_;
bool isVideoConfigured_ {false};
uint16_t mtu_;
int rotation_ {0};
std::mutex rotationMtx_;
libav_utils::AVBufferPtr displayMatrix_;
static int interruptCb(void* ctx);
static int readFunction(void* opaque, uint8_t* buf, int buf_size);
bool configureVideoOutput();
ThreadLoop loop_;
// used by ThreadLoop
bool setup();
void process();
void cleanup();
std::function<void(void)> keyFrameRequestCallback_;
std::function<void(MediaType, bool)> onSuccessfulSetup_;
std::function<void(const MediaStream& ms)> recorderCallback_;
};
} // namespace video
} // namespace jami
#endif // _VIDEO_RECEIVE_THREAD_H_
| 3,639
|
C++
|
.h
| 108
| 29.981481
| 98
| 0.689655
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,960
|
video_input.h
|
savoirfairelinux_jami-daemon/src/media/video/video_input.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "noncopyable.h"
#include "threadloop.h"
#include "media/media_stream.h"
#include "media/media_device.h" // DeviceParams
#include "media/video/video_base.h"
#include "media/media_codec.h"
#include <map>
#include <atomic>
#include <future>
#include <string>
#include <mutex>
#include <condition_variable>
#include <array>
#if __APPLE__
#import "TargetConditionals.h"
#endif
namespace jami {
class MediaDecoder;
class MediaDemuxer;
} // namespace jami
namespace jami {
namespace video {
class SinkClient;
enum class VideoInputMode { ManagedByClient, ManagedByDaemon, Undefined };
class VideoInput : public VideoGenerator
{
public:
VideoInput(VideoInputMode inputMode = VideoInputMode::Undefined,
const std::string& resource = "local",
const std::string& sink = "");
~VideoInput();
// as VideoGenerator
const std::string& getName() const { return resource_; }
int getWidth() const;
int getHeight() const;
AVPixelFormat getPixelFormat() const;
const DeviceParams& getConfig() const {
return decOpts_;
}
std::shared_future<DeviceParams> getParams() const {
return futureDecOpts_;
}
MediaStream getInfo() const;
void setSink(const std::string& sinkId);
void updateStartTime(int64_t startTime);
void configureFilePlayback(const std::string& path,
std::shared_ptr<MediaDemuxer>& demuxer,
int index);
void flushBuffers();
void setPaused(bool paused) { paused_ = paused; }
void setSeekTime(int64_t time);
void setupSink(const int width, const int height);
void stopSink();
void setRecorderCallback(const std::function<void(const MediaStream& ms)>& cb);
#if VIDEO_CLIENT_INPUT
/*
* these functions are used to pass buffer from/to the daemon
* on the Android and UWP builds
*/
void* obtainFrame(int length);
void releaseFrame(void* frame);
#else
void stopInput();
#endif
void setSuccessfulSetupCb(const std::function<void(MediaType, bool)>& cb)
{
onSuccessfulSetup_ = cb;
}
/**
* Restart stopped video input
* @note if a media is removed, then re-added in a conference, the loop will be stopped
* and this input must be restarted
*/
void restart();
private:
NON_COPYABLE(VideoInput);
std::shared_future<DeviceParams> switchInput(const std::string& resource);
std::string resource_;
std::atomic<bool> switchPending_ = {false};
std::atomic_bool isStopped_ = {false};
DeviceParams decOpts_;
std::promise<DeviceParams> foundDecOpts_;
std::shared_future<DeviceParams> futureDecOpts_;
bool emulateRate_ = false;
std::atomic_bool decOptsFound_ {false};
void foundDecOpts(const DeviceParams& params);
void clearOptions();
// true if decOpts_ is ready to use, false if using promise/future
bool initCamera(const std::string& device);
bool initFile(std::string path);
#ifdef __APPLE__
bool initAVFoundation(const std::string& display);
#elif defined(WIN32)
bool initWindowsGrab(const std::string& display);
#else
bool initLinuxGrab(const std::string& display);
#endif
bool isCapturing() const noexcept;
void startLoop();
void switchDevice();
bool capturing_ {false};
void createDecoder();
void deleteDecoder();
std::unique_ptr<MediaDecoder> decoder_;
std::shared_ptr<SinkClient> sink_;
ThreadLoop loop_;
// for ThreadLoop
bool setup();
void process();
void cleanup();
bool captureFrame();
int rotation_ {0};
std::shared_ptr<AVBufferRef> displayMatrix_;
void setRotation(int angle);
VideoInputMode inputMode_;
inline bool videoManagedByClient() const
{
return inputMode_ == VideoInputMode::ManagedByClient;
}
bool playingFile_ = false;
std::atomic_bool paused_ {true};
std::function<void(MediaType, bool)> onSuccessfulSetup_;
std::function<void(const MediaStream& ms)> recorderCallback_;
};
} // namespace video
} // namespace jami
| 4,829
|
C++
|
.h
| 143
| 29.293706
| 91
| 0.705478
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,961
|
video_mixer.h
|
savoirfairelinux_jami-daemon/src/media/video/video_mixer.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "noncopyable.h"
#include "video_base.h"
#include "video_scaler.h"
#include "threadloop.h"
#include "media_stream.h"
#include <list>
#include <chrono>
#include <memory>
#include <shared_mutex>
namespace jami {
namespace video {
class SinkClient;
struct StreamInfo
{
std::string callId;
std::string streamId;
};
struct SourceInfo
{
Observable<std::shared_ptr<MediaFrame>>* source;
int x;
int y;
int w;
int h;
bool hasVideo;
std::string callId;
std::string streamId;
};
using OnSourcesUpdatedCb = std::function<void(std::vector<SourceInfo>&&)>;
enum class Layout { GRID, ONE_BIG_WITH_SMALL, ONE_BIG };
class VideoMixer : public VideoGenerator, public VideoFramePassiveReader
{
public:
VideoMixer(const std::string& id, const std::string& localInput = {}, bool attachHost = false);
~VideoMixer();
void setParameters(int width, int height, AVPixelFormat format = AV_PIX_FMT_YUV422P);
int getWidth() const override;
int getHeight() const override;
AVPixelFormat getPixelFormat() const override;
// as VideoFramePassiveReader
void update(Observable<std::shared_ptr<MediaFrame>>* ob,
const std::shared_ptr<MediaFrame>& v) override;
void attached(Observable<std::shared_ptr<MediaFrame>>* ob) override;
void detached(Observable<std::shared_ptr<MediaFrame>>* ob) override;
/**
* Set all inputs at once
* @param inputs New inputs
* @note previous inputs will be stopped
*/
void switchInputs(const std::vector<std::string>& inputs);
/**
* Stop all inputs
*/
void stopInputs();
void setActiveStream(const std::string& id);
void resetActiveStream()
{
activeStream_ = {};
updateLayout();
}
bool verifyActive(const std::string& id) { return activeStream_ == id; }
void setVideoLayout(Layout newLayout)
{
currentLayout_ = newLayout;
if (currentLayout_ == Layout::GRID)
resetActiveStream();
layoutUpdated_ += 1;
}
Layout getVideoLayout() const { return currentLayout_; }
void setOnSourcesUpdated(OnSourcesUpdatedCb&& cb) { onSourcesUpdated_ = std::move(cb); }
MediaStream getStream(const std::string& name) const;
std::shared_ptr<VideoFrameActiveWriter> getVideoLocal() const
{
if (!localInputs_.empty())
return *localInputs_.begin();
return {};
}
void updateLayout();
std::shared_ptr<SinkClient>& getSink() { return sink_; }
void addAudioOnlySource(const std::string& callId, const std::string& streamId)
{
std::unique_lock lk(audioOnlySourcesMtx_);
audioOnlySources_.insert({callId, streamId});
lk.unlock();
updateLayout();
}
void removeAudioOnlySource(const std::string& callId, const std::string& streamId)
{
std::unique_lock lk(audioOnlySourcesMtx_);
if (audioOnlySources_.erase({callId, streamId})) {
lk.unlock();
updateLayout();
}
}
void attachVideo(Observable<std::shared_ptr<MediaFrame>>* frame,
const std::string& callId,
const std::string& streamId);
void detachVideo(Observable<std::shared_ptr<MediaFrame>>* frame);
StreamInfo streamInfo(Observable<std::shared_ptr<MediaFrame>>* frame) const
{
std::lock_guard lk(videoToStreamInfoMtx_);
auto it = videoToStreamInfo_.find(frame);
if (it == videoToStreamInfo_.end())
return {};
return it->second;
}
private:
NON_COPYABLE(VideoMixer);
struct VideoMixerSource;
bool render_frame(VideoFrame& output,
const std::shared_ptr<VideoFrame>& input,
std::unique_ptr<VideoMixerSource>& source);
void calc_position(std::unique_ptr<VideoMixerSource>& source,
const std::shared_ptr<VideoFrame>& input,
int index);
void startSink();
void stopSink();
void process();
const std::string id_;
int width_ = 0;
int height_ = 0;
AVPixelFormat format_ = AV_PIX_FMT_YUV422P;
std::shared_mutex rwMutex_;
std::shared_ptr<SinkClient> sink_;
std::chrono::time_point<std::chrono::steady_clock> nextProcess_;
std::mutex localInputsMtx_;
std::vector<std::shared_ptr<VideoFrameActiveWriter>> localInputs_ {};
void stopInput(const std::shared_ptr<VideoFrameActiveWriter>& input);
VideoScaler scaler_;
ThreadLoop loop_; // as to be last member
Layout currentLayout_ {Layout::GRID};
std::list<std::unique_ptr<VideoMixerSource>> sources_;
// We need to convert call to frame
mutable std::mutex videoToStreamInfoMtx_ {};
std::map<Observable<std::shared_ptr<MediaFrame>>*, StreamInfo> videoToStreamInfo_ {};
std::mutex audioOnlySourcesMtx_;
std::set<std::pair<std::string, std::string>> audioOnlySources_;
std::string activeStream_ {};
std::atomic_int layoutUpdated_ {0};
OnSourcesUpdatedCb onSourcesUpdated_ {};
int64_t startTime_;
int64_t lastTimestamp_;
};
} // namespace video
} // namespace jami
| 5,900
|
C++
|
.h
| 162
| 30.691358
| 99
| 0.676496
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,962
|
video_rtp_session.h
|
savoirfairelinux_jami-daemon/src/media/video/video_rtp_session.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "media/rtp_session.h"
#include "media/media_device.h"
#include "video_base.h"
#include "threadloop.h"
#include <string>
#include <memory>
namespace jami {
class CongestionControl;
class Conference;
class MediaRecorder;
} // namespace jami
namespace jami {
namespace video {
class VideoInput;
class VideoMixer;
class VideoSender;
class VideoReceiveThread;
struct RTCPInfo
{
float packetLoss;
unsigned int jitter;
unsigned int nb_sample;
float latency;
};
struct VideoBitrateInfo
{
unsigned videoBitrateCurrent;
unsigned videoBitrateMin;
unsigned videoBitrateMax;
unsigned videoQualityCurrent;
unsigned videoQualityMin;
unsigned videoQualityMax;
unsigned cptBitrateChecking;
unsigned maxBitrateChecking;
float packetLostThreshold;
};
class VideoRtpSession : public RtpSession, public std::enable_shared_from_this<VideoRtpSession>
{
public:
using BaseType = RtpSession;
VideoRtpSession(const std::string& callId,
const std::string& streamId,
const DeviceParams& localVideoParams,
const std::shared_ptr<MediaRecorder>& rec);
~VideoRtpSession();
void setRequestKeyFrameCallback(std::function<void(void)> cb);
void updateMedia(const MediaDescription& send, const MediaDescription& receive) override;
void start(std::unique_ptr<dhtnet::IceSocket> rtp_sock, std::unique_ptr<dhtnet::IceSocket> rtcp_sock) override;
void restartSender() override;
void stop() override;
void setMuted(bool mute, Direction dir = Direction::SEND) override;
/**
* Set video orientation
*
* Send to the receive thread rotation to apply to the video (counterclockwise)
*
* @param rotation Rotation in degrees (counterclockwise)
*/
void setRotation(int rotation);
void forceKeyFrame();
void bindMixer(VideoMixer* mixer);
void unbindMixer();
void enterConference(Conference& conference);
void exitConference();
void setChangeOrientationCallback(std::function<void(int)> cb);
void initRecorder() override;
void deinitRecorder() override;
const VideoBitrateInfo& getVideoBitrateInfo();
bool hasConference() { return conference_; }
std::shared_ptr<VideoInput>& getVideoLocal() { return videoLocal_; }
std::shared_ptr<VideoMixer>& getVideoMixer() { return videoMixer_; }
std::shared_ptr<VideoReceiveThread>& getVideoReceive() { return receiveThread_; }
private:
void setupConferenceVideoPipeline(Conference& conference, Direction dir);
void setupVideoPipeline();
void startSender();
void stopSender(bool forceStopSocket = false);
void startReceiver();
void stopReceiver(bool forceStopSocket = false);
using clock = std::chrono::steady_clock;
using time_point = clock::time_point;
DeviceParams localVideoParams_;
std::unique_ptr<VideoSender> sender_;
std::shared_ptr<VideoReceiveThread> receiveThread_;
Conference* conference_ {nullptr};
std::shared_ptr<VideoMixer> videoMixer_;
std::shared_ptr<VideoInput> videoLocal_;
uint16_t initSeqVal_ = 0;
std::function<void(void)> requestKeyFrameCallback_;
bool check_RCTP_Info_RR(RTCPInfo&);
bool check_RCTP_Info_REMB(uint64_t*);
void adaptQualityAndBitrate();
void storeVideoBitrateInfo();
void setupVideoBitrateInfo();
void checkReceiver();
float getPonderateLoss(float lastLoss);
void delayMonitor(int gradient, int deltaT);
void dropProcessing(RTCPInfo* rtcpi);
void delayProcessing(int br);
void setNewBitrate(unsigned int newBR);
// no packet loss can be calculated as no data in input
static constexpr float NO_INFO_CALCULATED {-1.0};
// bitrate and quality info struct
VideoBitrateInfo videoBitrateInfo_;
std::list<std::pair<time_point, float>> histoLoss_;
// 5 tries in a row
static constexpr unsigned MAX_ADAPTATIVE_BITRATE_ITERATION {5};
// packet loss threshold
static constexpr float PACKET_LOSS_THRESHOLD {1.0};
InterruptedThreadLoop rtcpCheckerThread_;
void processRtcpChecker();
std::function<void(int)> changeOrientationCallback_;
std::function<void(bool)> recordingStateCallback_;
// interval in seconds between RTCP checkings
std::chrono::seconds rtcp_checking_interval {4};
time_point lastMediaRestart_ {time_point::min()};
time_point last_REMB_inc_ {time_point::min()};
time_point last_REMB_dec_ {time_point::min()};
time_point lastBitrateDecrease {time_point::min()};
unsigned remb_dec_cnt_ {0};
std::unique_ptr<CongestionControl> cc;
std::function<void(void)> cbKeyFrameRequest_;
std::atomic<int> rotation_ {0};
void attachRemoteRecorder(const MediaStream& ms);
void attachLocalRecorder(const MediaStream& ms);
};
} // namespace video
} // namespace jami
| 5,603
|
C++
|
.h
| 145
| 34.2
| 115
| 0.738192
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,963
|
sinkclient.h
|
savoirfairelinux_jami-daemon/src/media/video/sinkclient.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "video_base.h"
#include <videomanager_interface.h>
#include <string>
#include <vector>
#include <memory>
//#define DEBUG_FPS
namespace jami {
class MediaFilter;
}
namespace jami {
namespace video {
#ifdef ENABLE_SHM
class ShmHolder;
#endif // ENABLE_SHM
class VideoScaler;
class SinkClient : public VideoFramePassiveReader, public VideoFrameActiveWriter
{
public:
SinkClient(const std::string& id = "", bool mixer = false);
const std::string& getId() const noexcept { return id_; }
std::string openedName() const noexcept;
int getWidth() const noexcept { return width_; }
int getHeight() const noexcept { return height_; }
AVPixelFormat getPreferredFormat() const noexcept
{
return (AVPixelFormat) target_.preferredFormat;
}
// as VideoFramePassiveReader
void update(Observable<std::shared_ptr<jami::MediaFrame>>*,
const std::shared_ptr<jami::MediaFrame>&) override;
bool start() noexcept;
bool stop() noexcept;
void setFrameSize(int width, int height);
void setCrop(int x, int y, int w, int h);
void registerTarget(libjami::SinkTarget target) noexcept
{
std::lock_guard lock(mtx_);
target_ = std::move(target);
}
#ifdef ENABLE_SHM
void enableShm(bool value) { doShmTransfer_.store(value); }
#endif
private:
const std::string id_;
// True if the instance is used by a mixer.
const bool mixer_ {false};
int width_ {0};
int height_ {0};
struct Rect
{
int x {0}, y {0}, w {0}, h {0};
};
Rect crop_ {};
bool started_ {false}; // used to arbitrate client's stop signal.
int rotation_ {0};
libjami::SinkTarget target_;
std::unique_ptr<VideoScaler> scaler_;
std::unique_ptr<MediaFilter> filter_;
std::mutex mtx_;
void sendFrameDirect(const std::shared_ptr<jami::MediaFrame>&);
void sendFrameTransformed(AVFrame* frame);
/**
* Apply required transformations before sending frames to clients/observers:
* - Transfer the frame from gpu to main memory, if needed.
* - Rotate the frame as needed.
* - Apply cropping as needed
*/
std::shared_ptr<VideoFrame> applyTransform(VideoFrame& frame);
#ifdef DEBUG_FPS
unsigned frameCount_;
std::chrono::steady_clock::time_point lastFrameDebug_;
#endif
#ifdef ENABLE_SHM
// using shared_ptr and not unique_ptr as ShmHolder is forwared only
std::shared_ptr<ShmHolder> shm_;
std::atomic_bool doShmTransfer_ {false};
#endif // ENABLE_SHM
};
} // namespace video
} // namespace jami
| 3,362
|
C++
|
.h
| 100
| 29.79
| 81
| 0.706646
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,964
|
shm_header.h
|
savoirfairelinux_jami-daemon/src/media/video/shm_header.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef SHM_HEADER_H_
#define SHM_HEADER_H_
#include <cstdint>
#include <semaphore.h>
/* Implementation note: double-buffering
* Shared memory is divided in two regions, each representing one frame.
* First byte of each frame is guaranteed to be aligned on 16 bytes.
* One region is marked as readable: this region can be safely read.
* The other region is writeable: only the producer can use it.
*/
struct SHMHeader
{
sem_t mutex; // lock it before any operations on these fields
sem_t frameGenMutex; // unlocked by producer when frameGen is modified
unsigned frameGen; // monotonically incremented when a producer changes readOffset
unsigned frameSize; // size in bytes of 1 frame
unsigned mapSize; // size to map if you need all the data
unsigned readOffset; // offset of readable frame in data
unsigned writeOffset; // offset of writable frame in data
uint8_t data[]; // the whole shared memory
};
#endif
| 1,695
|
C++
|
.h
| 38
| 42.105263
| 89
| 0.740315
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
751,965
|
video_sender.h
|
savoirfairelinux_jami-daemon/src/media/video/video_sender.h
|
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "noncopyable.h"
#include "media_encoder.h"
#include "media_io_handle.h"
#include <map>
#include <string>
#include <memory>
#include <atomic>
// Forward declarations
namespace jami {
class SocketPair;
struct DeviceParams;
} // namespace jami
namespace jami {
namespace video {
class VideoSender : public VideoFramePassiveReader
{
public:
VideoSender(const std::string& dest,
const MediaStream& opts,
const MediaDescription& args,
SocketPair& socketPair,
const uint16_t seqVal,
uint16_t mtu,
bool allowHwAccel = true);
~VideoSender() {};
void forceKeyFrame();
// as VideoFramePassiveReader
void update(Observable<std::shared_ptr<MediaFrame>>* obs,
const std::shared_ptr<MediaFrame>& frame_p) override;
uint16_t getLastSeqValue();
void setChangeOrientationCallback(std::function<void(int)> cb);
int setBitrate(uint64_t br);
private:
static constexpr int KEYFRAMES_AT_START {1}; // Number of keyframes to enforce at stream startup
static constexpr unsigned KEY_FRAME_PERIOD {0}; // seconds before forcing a keyframe
NON_COPYABLE(VideoSender);
void encodeAndSendVideo(const std::shared_ptr<VideoFrame>&);
// encoder MUST be deleted before muxContext
std::unique_ptr<MediaIOHandle> muxContext_ = nullptr;
std::unique_ptr<MediaEncoder> videoEncoder_ = nullptr;
std::atomic<int> forceKeyFrame_ {KEYFRAMES_AT_START};
int keyFrameFreq_ {0}; // Set keyframe rate, 0 to disable auto-keyframe. Computed in constructor
int64_t frameNumber_ = 0;
int rotation_ = -1;
std::function<void(int)> changeOrientationCallback_;
};
} // namespace video
} // namespace jami
| 2,495
|
C++
|
.h
| 65
| 33.953846
| 100
| 0.717896
|
savoirfairelinux/jami-daemon
| 144
| 47
| 2
|
GPL-3.0
|
9/20/2024, 9:42:05 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.