Commit f2d8655d authored by Guillaume Roguez's avatar Guillaume Roguez

daemon: remove dead code and add comments

Refs #67223

Change-Id: I732a8da1dc372edd3c73f54b5f76b65d9db9b7ce
parent 264d6eae
......@@ -297,88 +297,6 @@ Account::getVolatileAccountDetails() const
return a;
}
#ifdef RING_VIDEO
/*
* TODO ebail : *
* video codec information format changed (merged with audio mechanism)
* we need thus to adapt serialization / unserialization to it
*
*/
#if 0
static bool
isPositiveInteger(const std::string& s)
{
std::string::const_iterator it = s.begin();
while (it != s.end() and std::isdigit(*it))
++it;
return not s.empty() and it == s.end();
}
static bool
isBoolean(const std::string& s)
{
return s == "true" or s == "false";
}
template <typename Predicate>
static bool
isFieldValid(const std::map<std::string, std::string>& codec, const char* field, Predicate p)
{
std::map<std::string, std::string>::const_iterator key(codec.find(field));
return key != codec.end() and p(key->second);
}
static bool
isCodecValid(const std::map<std::string, std::string>& codec, const std::vector<std::map<std::string, std::string>>& defaults)
{
const std::map<std::string, std::string>::const_iterator name(codec.find(Account::VIDEO_CODEC_NAME));
if (name == codec.end()) {
RING_ERR("Field \"name\" missing in codec specification");
return false;
}
// check that it's in the list of valid codecs and that it has all the required fields
for (const auto &i : defaults) {
const auto defaultName = i.find(Account::VIDEO_CODEC_NAME);
if (defaultName->second == name->second) {
return isFieldValid(codec, Account::VIDEO_CODEC_BITRATE, isPositiveInteger)
and isFieldValid(codec, Account::VIDEO_CODEC_ENABLED, isBoolean);
}
}
RING_ERR("Codec %s not supported", name->second.c_str());
return false;
}
#endif // ebail
static bool
isCodecListValid(const std::vector<unsigned>& list UNUSED)
{
/*
* TODO ebail : *
* video codec information format changed (merged with audio mechanism)
* we need thus to adapt serialization / unserialization to it
*
*/
#if 1 /* ebail : for the moment always return true */
return true;
#else
const auto defaults(libav_utils::getDefaultVideoCodecs());
if (list.size() != defaults.size()) {
RING_ERR("New codec list has a different length than the list of supported codecs");
return false;
}
// make sure that all codecs are present
for (const auto &i : list) {
if (not isCodecValid(i, defaults))
return false;
}
return true;
#endif // ebail
}
#endif // RING_VIDEO
// Convert a list of payloads in a special format, readable by the server.
// Required format: payloads separated by slashes.
// @return std::string The serializable string
......
/*
* Copyright (C) 2004-2015 Savoir-Faire Linux Inc.
* Author: Yan Morin <yan.morin@savoirfairelinux.com>
* Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com>
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
* Author: Emmanuel Lepage <emmanuel.lepage@savoirfairelinux.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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "audiocodecfactory.h"
#include "audiocodec.h"
#include "plugin_manager.h"
#include "fileutils.h"
#include "array_size.h"
#include "logger.h"
#include <dirent.h>
#include <dlfcn.h>
#include <cstdlib>
#include <algorithm> // for std::find
#include <stdexcept>
#include <sstream>
#if 0
namespace ring {
AudioCodecFactory::AudioCodecFactory(PluginManager& pluginManager)
: pluginManager_(pluginManager)
{
/* Plugin has a C binding, this lambda is used to make the brigde
* with our C++ binding by providing 'this' access.
*/
const auto callback = [this](void* data) {
if (auto codec = reinterpret_cast<AudioCodec*>(data)) {
this->registerAudioCodec(codec);
return 0;
}
return -1;
};
pluginManager_.registerService("registerAudioCodec", callback);
scanCodecDirectory();
if (codecsMap_.empty())
RING_ERR("No codecs available");
}
AudioCodecFactory::~AudioCodecFactory()
{
pluginManager_.unRegisterService("registerAudioCodec");
}
void
AudioCodecFactory::registerAudioCodec(AudioCodec* codec)
{
codecsMap_[(int) codec->getPayloadType()] = std::shared_ptr<AudioCodec>(codec);
RING_DBG("Loaded codec %s" , codec->getMimeSubtype().c_str());
}
void
AudioCodecFactory::setDefaultOrder()
{
defaultCodecList_.clear();
for (const auto& codec : codecsMap_)
defaultCodecList_.push_back(codec.first);
}
std::string
AudioCodecFactory::getCodecName(Id payload) const
{
for (const auto& item : codecsMap_) {
const auto& codec = item.second;
if (codec and codec->getPayloadType() == payload)
return codec->getMimeSubtype();
}
return "";
}
std::vector<int32_t>
AudioCodecFactory::getCodecList() const
{
std::vector<int32_t> list;
for (const auto &codec : codecsMap_)
if (codec.second)
list.push_back((int32_t) codec.first);
return list;
}
std::shared_ptr<AudioCodec>
AudioCodecFactory::getCodec(int payload) const
{
const auto iter = codecsMap_.find(payload);
if (iter != codecsMap_.end())
return iter->second;
RING_ERR("Cannot find codec %i", payload);
return nullptr;
}
std::shared_ptr<AudioCodec>
AudioCodecFactory::getCodec(const std::string &name) const
{
for (const auto& item : codecsMap_) {
std::ostringstream os;
const auto& codec = item.second;
if (!codec)
continue;
const std::string channels(codec->getSDPChannels());
os << "/" << codec->getSDPClockRate();
if (not channels.empty())
os << "/" << channels;
const std::string match(codec->getMimeSubtype() + os.str());
RING_DBG("Trying %s", match.c_str());
if (name.find(match) != std::string::npos) {
RING_DBG("Found match");
return codec;
}
}
RING_ERR("Cannot find codec %s", name.c_str());
return nullptr;
}
double
AudioCodecFactory::getBitRate(int payload) const
{
auto iter = codecsMap_.find(payload);
if (iter != codecsMap_.end())
return iter->second->getBitRate();
return 0.0;
}
int
AudioCodecFactory::getSampleRate(int payload) const
{
auto iter = codecsMap_.find(payload);
if (iter != codecsMap_.end())
return iter->second->getClockRate();
return 0;
}
unsigned
AudioCodecFactory::getChannels(int payload) const
{
auto iter = codecsMap_.find(payload);
if (iter != codecsMap_.end())
return iter->second->getChannels();
return 0;
}
void
AudioCodecFactory::saveActiveCodecs(const std::vector<std::string>& list)
{
defaultCodecList_.clear();
// list contains the ordered payload of active codecs picked by the user
// we used the codec vector to save the order.
for (const auto &codec : list) {
int payload = std::atoi(codec.c_str());
if (isCodecLoaded(payload))
defaultCodecList_.push_back(static_cast<int>(payload));
}
}
void
AudioCodecFactory::scanCodecDirectory()
{
std::vector<std::string> dirToScan;
dirToScan.push_back(fileutils::get_home_dir() + DIR_SEPARATOR_STR "." PACKAGE "/");
dirToScan.push_back(CODECS_DIR "/");
const char *envDir = getenv("CODECS_PATH");
if (envDir)
dirToScan.push_back(std::string(envDir) + DIR_SEPARATOR_STR);
const char *progDir = fileutils::get_program_dir();
if (progDir) {
#ifdef __ANDROID__
dirToScan.push_back(std::string(progDir) + DIR_SEPARATOR_STR + "lib/");
#else
dirToScan.push_back(std::string(progDir) + DIR_SEPARATOR_STR + "audio/codecs/");
#endif
}
for (const auto& dirStr : dirToScan) {
RING_DBG("Scanning %s to find audio codecs....", dirStr.c_str());
DIR *dir = opendir(dirStr.c_str());
if (!dir)
continue;
dirent *dirStruct;
while ((dirStruct = readdir(dir))) {
std::string file = dirStruct->d_name;
if (file == "." or file == "..")
continue;
if (seemsValid(file))
pluginManager_.load(dirStr + file);
}
closedir(dir);
}
}
AudioCodec*
AudioCodecFactory::instantiateCodec(int payload) const
{
for (const auto& item : codecsMap_) {
const auto& codec = item.second;
if (codec->getPayloadType() == payload) {
try {
return codec->clone();
} catch (const std::runtime_error &e) {
RING_ERR("%s", e.what());
return nullptr;
}
}
}
return nullptr;
}
bool
AudioCodecFactory::seemsValid(const std::string &lib)
{
// The name of the shared library seems valid <==> it looks like libcodec_xxx.so
// We check this
static const std::string prefix("libcodec_");
static const std::string suffix(".so");
ssize_t len = lib.length() - prefix.length() - suffix.length();
if (len < 0)
return false;
// Second: check the extension of the file name.
// If it is different than RING_CODEC_VALID_EXTEN , not a SFL shared library
if (lib.substr(lib.length() - suffix.length(), lib.length()) != suffix)
return false;
static const std::string validCodecs[] = {
"ulaw",
"alaw",
"g722",
"g729", //G729 have to be loaded first, if it is valid or not is checked later
"opus", //Opus have to be loaded first, if it is valid or not is checked later
#ifdef HAVE_SPEEX_CODEC
"speex",
#endif
#ifdef HAVE_GSM_CODEC
"gsm",
#endif
#ifdef BUILD_ILBC
"ilbc",
#endif
""
};
const std::string name(lib.substr(prefix.length(), len));
const std::string *end = validCodecs + RING_ARRAYSIZE(validCodecs);
return find(validCodecs, end, name) != end;
}
bool
AudioCodecFactory::isCodecLoaded(int payload) const
{
for (const auto &codec : codecsMap_)
if (codec.first == payload)
return true;
return false;
}
std::vector <std::string>
AudioCodecFactory::getCodecSpecifications(const int32_t& payload) const
{
std::vector<std::string> v;
std::stringstream ss;
// Add the name of the codec
v.push_back(getCodecName(static_cast<int>(payload)));
// Add the sample rate
ss << getSampleRate(static_cast<int>(payload));
v.push_back(ss.str());
ss.str("");
// Add the bit rate
ss << getBitRate(static_cast<int>(payload));
v.push_back(ss.str());
ss.str("");
// Add the channel number
ss << getChannels(static_cast<int>(payload));
v.push_back(ss.str());
return v;
}
} // namespace ring
#endif
/*
* Copyright (C) 2004-2015 Savoir-Faire Linux Inc.
* Author: Yan Morin <yan.morin@savoirfairelinux.com>
* Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com>
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#ifndef __CODEC_DESCRIPTOR_H__
#define __CODEC_DESCRIPTOR_H__
#include "audiocodec.h"
#include <map>
#include <vector>
#if 0
namespace ring {
class PluginManager;
/*
* @file codecdescriptor.h
* @brief Handle audio codecs, load them in memory
*/
class AudioCodecFactory {
public:
using Id = int32_t;
AudioCodecFactory(PluginManager&);
~AudioCodecFactory();
/**
* Get codec name by its idientifier
* @param id the identifier.
* @return std::string the name of the codec
*/
std::string getCodecName(Id id) const;
std::vector<Id> getCodecList() const;
/**
* Get the codec object associated with the payload
* @param payload The payload looked for
* @return A shared pointer on a AudioCodec object
*/
std::shared_ptr<AudioCodec> getCodec(int payload) const;
/**
* Get the codec object associated with the codec attribute
* @param string The name to compare, should be in the form speex/16000
* @return A shared pointer to an AudioCodec object
*/
std::shared_ptr<AudioCodec> getCodec(const std::string &name) const;
/**
* Set the default codecs order.
* This order will be apply to each account by default
*/
void setDefaultOrder();
/**
* Get the bit rate of the specified codec.
* @param payload The payload of the codec
* @return double The bit rate
*/
double getBitRate(int payload) const;
/**
* Get the clock rate of the specified codec
* @param payload The payload of the codec
* @return int The clock rate of the specified codec
*/
int getSampleRate(int payload) const;
/**
* Get the number of channels of the specified codec
* @param payload The payload of the codec
* @return int The number of channels of the specified codec
*/
unsigned getChannels(int payload) const;
/**
* Set the order of codecs by their payload
* @param list The ordered list sent by DBus
*/
void saveActiveCodecs(const std::vector<std::string>& list);
/**
* Instantiate a codec, used in AudioRTP to get an instance of Codec per call
* @param CodecHandlePointer The map containing the pointer on the object and the pointer on the handle function
*/
AudioCodec* instantiateCodec(int payload) const;
/**
* For a given codec, return its specification
*
* @param payload The RTP payload of the codec
* @return std::vector <std::string> A vector containing codec's name, sample rate, bandwidth and bit rate
*/
std::vector <std::string> getCodecSpecifications(const int32_t& payload) const;
/**
* Check if the audiocodec object has been successfully created
* @param payload The payload of the codec
* @return bool True if the audiocodec has been created
* false otherwise
*/
bool isCodecLoaded(int payload) const;
private:
PluginManager& pluginManager_;
/** Maps a pointer on an audiocodec object to a payload */
typedef std::map<Id, std::shared_ptr<AudioCodec>> AudioCodecsMap;
/**
* Scan the installation directory ( --prefix configure option )
* and load dynamic libraries.
*/
void scanCodecDirectory();
/**
* Add a new audiocodec to the system.
* @note Steals the ownership on given codec.
*/
void registerAudioCodec(AudioCodec* codec);
/**
* Check if the files found in searched directories seems valid
* @param std::string The name of the file
* @return bool True if the file name begins with libcodec_ and ends with .so
* false otherwise
*/
static bool seemsValid(const std::string &lib);
/**
* Map the payload of a codec and the object associated ( AudioCodec * )
*/
AudioCodecsMap codecsMap_ {};
/**
* Vector containing a default order for the codecs
*/
std::vector<int> defaultCodecList_ {};
};
} // namespace ring
#endif
#endif // __CODEC_DESCRIPTOR_H__
......@@ -44,11 +44,10 @@
#include <unistd.h>
#if 0
TODO
* implement shutdown callback
* auto connect optional
#endif
/* TODO
* implement shutdown callback
* auto connect optional
*/
namespace ring {
......
......@@ -31,6 +31,8 @@
#include "audiostream.h"
#include "pulselayer.h"
#include "logger.h"
#include "intrin.h"
#include <stdexcept>
namespace ring {
......@@ -111,7 +113,7 @@ AudioStream::~AudioStream()
void
AudioStream::stream_state_callback(pa_stream* s, void* /*user_data*/)
{
char str[PA_SAMPLE_SPEC_SNPRINT_MAX];
UNUSED char str[PA_SAMPLE_SPEC_SNPRINT_MAX];
switch (pa_stream_get_state(s)) {
case PA_STREAM_CREATING:
......@@ -124,14 +126,12 @@ AudioStream::stream_state_callback(pa_stream* s, void* /*user_data*/)
case PA_STREAM_READY:
RING_DBG("Stream successfully created, connected to %s", pa_stream_get_device_name(s));
#if 0
RING_DBG("maxlength %u", pa_stream_get_buffer_attr(s)->maxlength);
RING_DBG("tlength %u", pa_stream_get_buffer_attr(s)->tlength);
RING_DBG("prebuf %u", pa_stream_get_buffer_attr(s)->prebuf);
RING_DBG("minreq %u", pa_stream_get_buffer_attr(s)->minreq);
RING_DBG("fragsize %u", pa_stream_get_buffer_attr(s)->fragsize);
#endif
RING_DBG("samplespec %s", pa_sample_spec_snprint(str, sizeof(str), pa_stream_get_sample_spec(s)));
//RING_DBG("maxlength %u", pa_stream_get_buffer_attr(s)->maxlength);
//RING_DBG("tlength %u", pa_stream_get_buffer_attr(s)->tlength);
//RING_DBG("prebuf %u", pa_stream_get_buffer_attr(s)->prebuf);
//RING_DBG("minreq %u", pa_stream_get_buffer_attr(s)->minreq);
//RING_DBG("fragsize %u", pa_stream_get_buffer_attr(s)->fragsize);
//RING_DBG("samplespec %s", pa_sample_spec_snprint(str, sizeof(str), pa_stream_get_sample_spec(s)));
break;
case PA_STREAM_UNCONNECTED:
......
......@@ -708,7 +708,7 @@ void RingAccount::doRegister_()
}
});
#if 0
#if 0 // enable if dht_ logging is needed
dht_.setLoggers(
[](char const* m, va_list args){ vlogger(LOG_ERR, m, args); },
[](char const* m, va_list args){ vlogger(LOG_WARNING, m, args); },
......
......@@ -135,24 +135,6 @@ void SIPAccountBase::unserialize(const YAML::Node &node)
Account::unserialize(node);
parseValue(node, VIDEO_ENABLED_KEY, videoEnabled_);
/*
* TODO ebail : *
* video codec information format changed (merged with audio mechanism)
* we need thus to adapt serialization / unserialization to it
*/
#if 0
const auto &vCodecNode = node[VIDEO_CODECS_KEY];
auto tmp = parseVectorMap(vCodecNode, {VIDEO_CODEC_BITRATE, VIDEO_CODEC_ENABLED, VIDEO_CODEC_NAME, VIDEO_CODEC_PARAMETERS});
#ifdef RING_VIDEO
if (tmp.empty()) {
// Video codecs are an empty list
RING_WARN("Loading default video codecs");
tmp = libav_utils::getDefaultVideoCodecs();
}
#endif
// validate it
setVideoCodecs(tmp);
#endif
parseValue(node, Conf::INTERFACE_KEY, interface_);
int port = DEFAULT_SIP_PORT;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment