Commit 9db2a2e6 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #18663: daemon: remove Codec class

parent f4c663b8
......@@ -39,7 +39,6 @@ noinst_LTLIBRARIES = libsflphone.la
noinst_HEADERS = \
global.h \
codec.h \
conference.h \
voiplink.h \
preferences.h \
......
......@@ -123,13 +123,13 @@ class Alaw : public sfl::AudioCodec {
// the class factories
// cppcheck-suppress unusedFunction
extern "C" sfl::Codec* CODEC_ENTRY()
extern "C" sfl::AudioCodec* AUDIO_CODEC_ENTRY()
{
return new Alaw;
}
// cppcheck-suppress unusedFunction
extern "C" void destroy(sfl::Codec* a)
extern "C" void destroy(sfl::AudioCodec* a)
{
delete a;
}
......
......@@ -36,11 +36,9 @@
#include "cc_config.h"
#include <ccrtp/formats.h> // for ost::DynamicPayloadFormat
#include "codec.h"
/* bump when codec binary interface changes */
#define CODEC_ENTRY create_1_2_0
#define CODEC_ENTRY_SYMBOL "create_1_2_0"
#define AUDIO_CODEC_ENTRY create_1_2_0
#define AUDIO_CODEC_ENTRY_SYMBOL "create_1_2_0"
// We assume all decoders will be fed 20ms of audio or less
// And we'll resample them to 44.1kHz or less
......@@ -49,7 +47,7 @@
namespace sfl {
class AudioCodec : public Codec {
class AudioCodec {
public:
AudioCodec(uint8 payload, const std::string &codecName, int clockRate,
int frameSize, int channel);
......@@ -61,10 +59,7 @@ class AudioCodec : public Codec {
virtual ~AudioCodec() {};
/**
* @Override
*/
std::string getMimeSubtype() const;
virtual std::string getMimeSubtype() const;
/**
* Decode an input buffer and fill the output buffer with the decoded data
......@@ -80,14 +75,8 @@ class AudioCodec : public Codec {
*/
virtual int encode(unsigned char *dst, short *src, size_t buffer_size) = 0;
/**
* @Override
*/
uint8 getPayloadType() const ;
virtual uint8 getPayloadType() const;
/**
* @Override
*/
void setPayloadType(uint8 pt) {
payload_ = pt;
}
......@@ -97,15 +86,9 @@ class AudioCodec : public Codec {
*/
bool hasDynamicPayload() const;
/**
* @Override
*/
uint32 getClockRate() const;
virtual uint32 getClockRate() const;
/**
* @Override
*/
double getBitRate() const;
virtual double getBitRate() const;
/**
* @return the framing size for this codec.
......@@ -139,4 +122,8 @@ protected:
};
} // end namespace sfl
typedef sfl::AudioCodec* create_t();
typedef void destroy_t(sfl::AudioCodec* codec);
#endif
......@@ -50,13 +50,13 @@
AudioCodecFactory::AudioCodecFactory() :
codecsMap_(), defaultCodecList_(), libCache_(), codecInMemory_()
{
typedef std::vector<sfl::Codec*> CodecVector;
CodecVector codecDynamicList(scanCodecDirectory());
typedef std::vector<sfl::AudioCodec*> AudioCodecVector;
AudioCodecVector codecDynamicList(scanCodecDirectory());
if (codecDynamicList.empty())
ERROR("No codecs available");
else {
for (CodecVector::const_iterator iter = codecDynamicList.begin();
for (AudioCodecVector::const_iterator iter = codecDynamicList.begin();
iter != codecDynamicList.end() ; ++iter) {
codecsMap_[(int)(*iter)->getPayloadType()] = *iter;
DEBUG("Loaded codec %s" , (*iter)->getMimeSubtype().c_str());
......@@ -64,17 +64,18 @@ AudioCodecFactory::AudioCodecFactory() :
}
}
void AudioCodecFactory::setDefaultOrder()
void
AudioCodecFactory::setDefaultOrder()
{
defaultCodecList_.clear();
for (CodecsMap::const_iterator i = codecsMap_.begin(); i != codecsMap_.end(); ++i)
for (AudioCodecsMap::const_iterator i = codecsMap_.begin(); i != codecsMap_.end(); ++i)
defaultCodecList_.push_back(i->first);
}
std::string
AudioCodecFactory::getCodecName(int payload) const
{
CodecsMap::const_iterator iter = codecsMap_.find(payload);
AudioCodecsMap::const_iterator iter = codecsMap_.find(payload);
if (iter != codecsMap_.end())
return iter->second->getMimeSubtype();
......@@ -83,10 +84,10 @@ AudioCodecFactory::getCodecName(int payload) const
}
std::vector<int32_t>
AudioCodecFactory::getAudioCodecList() const
AudioCodecFactory::getCodecList() const
{
std::vector<int32_t> list;
for (CodecsMap::const_iterator iter = codecsMap_.begin(); iter != codecsMap_.end(); ++iter)
for (AudioCodecsMap::const_iterator iter = codecsMap_.begin(); iter != codecsMap_.end(); ++iter)
if (iter->second)
list.push_back((int32_t) iter->first);
......@@ -96,7 +97,7 @@ AudioCodecFactory::getAudioCodecList() const
sfl::AudioCodec*
AudioCodecFactory::getCodec(int payload) const
{
CodecsMap::const_iterator iter = codecsMap_.find(payload);
AudioCodecsMap::const_iterator iter = codecsMap_.find(payload);
if (iter != codecsMap_.end())
return static_cast<sfl::AudioCodec *>(iter->second);
......@@ -106,9 +107,10 @@ AudioCodecFactory::getCodec(int payload) const
}
}
double AudioCodecFactory::getBitRate(int payload) const
double
AudioCodecFactory::getBitRate(int payload) const
{
CodecsMap::const_iterator iter = codecsMap_.find(payload);
AudioCodecsMap::const_iterator iter = codecsMap_.find(payload);
if (iter != codecsMap_.end())
return iter->second->getBitRate();
......@@ -117,9 +119,10 @@ double AudioCodecFactory::getBitRate(int payload) const
}
int AudioCodecFactory::getSampleRate(int payload) const
int
AudioCodecFactory::getSampleRate(int payload) const
{
CodecsMap::const_iterator iter = codecsMap_.find(payload);
AudioCodecsMap::const_iterator iter = codecsMap_.find(payload);
if (iter != codecsMap_.end())
return iter->second->getClockRate();
......@@ -127,7 +130,8 @@ int AudioCodecFactory::getSampleRate(int payload) const
return 0;
}
void AudioCodecFactory::saveActiveCodecs(const std::vector<std::string>& list)
void
AudioCodecFactory::saveActiveCodecs(const std::vector<std::string>& list)
{
defaultCodecList_.clear();
// list contains the ordered payload of active codecs picked by the user
......@@ -144,14 +148,15 @@ void AudioCodecFactory::saveActiveCodecs(const std::vector<std::string>& list)
AudioCodecFactory::~AudioCodecFactory()
{
for (std::vector<CodecHandlePointer>::const_iterator iter =
codecInMemory_.begin(); iter != codecInMemory_.end(); ++iter)
for (std::vector<AudioCodecHandlePointer>::iterator iter =
codecInMemory_.begin(); iter != codecInMemory_.end(); ++iter)
unloadCodec(*iter);
}
std::vector<sfl::Codec*> AudioCodecFactory::scanCodecDirectory()
std::vector<sfl::AudioCodec*>
AudioCodecFactory::scanCodecDirectory()
{
std::vector<sfl::Codec*> codecs;
std::vector<sfl::AudioCodec*> codecs;
std::vector<std::string> dirToScan;
dirToScan.push_back(std::string(HOMEDIR) + DIR_SEPARATOR_STR "." PACKAGE "/");
......@@ -184,7 +189,7 @@ std::vector<sfl::Codec*> AudioCodecFactory::scanCodecDirectory()
continue;
if (seemsValid(file) && !alreadyInCache(file)) {
sfl::Codec* audioCodec = loadCodec(dirStr + file);
sfl::AudioCodec *audioCodec(loadCodec(dirStr + file));
if (audioCodec) {
codecs.push_back(audioCodec);
......@@ -199,7 +204,8 @@ std::vector<sfl::Codec*> AudioCodecFactory::scanCodecDirectory()
return codecs;
}
sfl::AudioCodec *AudioCodecFactory::loadCodec(const std::string &path)
sfl::AudioCodec *
AudioCodecFactory::loadCodec(const std::string &path)
{
void * codecHandle = dlopen(path.c_str(), RTLD_NOW);
......@@ -208,7 +214,7 @@ sfl::AudioCodec *AudioCodecFactory::loadCodec(const std::string &path)
return NULL;
}
create_t* createCodec = (create_t*) dlsym(codecHandle, CODEC_ENTRY_SYMBOL);
create_t* createCodec = (create_t*) dlsym(codecHandle, AUDIO_CODEC_ENTRY_SYMBOL);
const char *error = dlerror();
if (error) {
......@@ -218,15 +224,16 @@ sfl::AudioCodec *AudioCodecFactory::loadCodec(const std::string &path)
sfl::AudioCodec *a = static_cast<sfl::AudioCodec *>(createCodec());
if (a)
codecInMemory_.push_back(CodecHandlePointer(a, codecHandle));
codecInMemory_.push_back(AudioCodecHandlePointer(a, codecHandle));
return a;
}
void AudioCodecFactory::unloadCodec(CodecHandlePointer p)
void
AudioCodecFactory::unloadCodec(AudioCodecHandlePointer &ptr)
{
destroy_t* destroyCodec = (destroy_t*) dlsym(p.second , "destroy");
destroy_t* destroyCodec = (destroy_t*) dlsym(ptr.second , "destroy");
const char *error = dlerror();
......@@ -235,34 +242,37 @@ void AudioCodecFactory::unloadCodec(CodecHandlePointer p)
return;
}
if (p.first)
destroyCodec(p.first);
if (ptr.first)
destroyCodec(ptr.first);
if (p.second)
dlclose(p.second);
if (ptr.second)
dlclose(ptr.second);
}
sfl::AudioCodec* AudioCodecFactory::instantiateCodec(int payload) const
sfl::AudioCodec*
AudioCodecFactory::instantiateCodec(int payload) const
{
std::vector< CodecHandlePointer >::const_iterator iter;
std::vector<AudioCodecHandlePointer>::const_iterator iter;
sfl::AudioCodec *result = NULL;
for (iter = codecInMemory_.begin(); iter != codecInMemory_.end(); ++iter) {
if (iter->first->getPayloadType() == payload) {
create_t* createCodec = (create_t*) dlsym(iter->second , CODEC_ENTRY_SYMBOL);
create_t* createCodec = (create_t*) dlsym(iter->second , AUDIO_CODEC_ENTRY_SYMBOL);
const char *error = dlerror();
if (error)
ERROR("%s", error);
else
return static_cast<sfl::AudioCodec *>(createCodec());
result = static_cast<sfl::AudioCodec *>(createCodec());
}
}
return NULL;
return result;
}
bool AudioCodecFactory::seemsValid(const std::string &lib)
bool
AudioCodecFactory::seemsValid(const std::string &lib)
{
// The name of the shared library seems valid <==> it looks like libcodec_xxx.so
// We check this
......@@ -312,9 +322,10 @@ AudioCodecFactory::alreadyInCache(const std::string &lib)
return std::find(libCache_.begin(), libCache_.end(), lib) != libCache_.end();
}
bool AudioCodecFactory::isCodecLoaded(int payload) const
bool
AudioCodecFactory::isCodecLoaded(int payload) const
{
CodecsMap::const_iterator iter;
AudioCodecsMap::const_iterator iter;
for (iter = codecsMap_.begin(); iter != codecsMap_.end(); ++iter)
if (iter->first == payload)
......
......@@ -45,9 +45,6 @@
* @brief Handle audio codecs, load them in memory
*/
/** Maps a pointer on an audiocodec object to a payload */
typedef std::map<int, sfl::Codec*> CodecsMap;
class AudioCodecFactory {
public:
AudioCodecFactory();
......@@ -62,7 +59,7 @@ class AudioCodecFactory {
*/
std::string getCodecName(int payload) const;
std::vector<int32_t > getAudioCodecList() const;
std::vector<int32_t > getCodecList() const;
/**
* Get the codec object associated with the payload
* @param payload The payload looked for
......@@ -119,16 +116,18 @@ class AudioCodecFactory {
bool isCodecLoaded(int payload) const;
private:
/** Enable us to keep the handle pointer on the codec dynamicaly loaded so that we could destroy when we dont need it anymore */
typedef std::pair<sfl::Codec* , void*> CodecHandlePointer;
/** Maps a pointer on an audiocodec object to a payload */
typedef std::map<int, sfl::AudioCodec*> AudioCodecsMap;
/** Enable us to keep the handle pointer on the codec dynamicaly loaded so that we could destroy when we dont need it anymore */
typedef std::pair<sfl::AudioCodec*, void*> AudioCodecHandlePointer;
/**
* Scan the installation directory ( --prefix configure option )
* And load the dynamic library
* @return std::vector<AudioCodec*> The list of the codec object successfully loaded in memory
*/
std::vector<sfl::Codec *> scanCodecDirectory();
std::vector<sfl::AudioCodec *> scanCodecDirectory();
/**
* Load a codec
......@@ -139,9 +138,9 @@ class AudioCodecFactory {
/**
* Unload a codec
* @param CodecHandlePointer The map containing the pointer on the object and the pointer on the handle function
* @param AudioCodecHandlePointer The map containing the pointer on the object and the pointer on the handle function
*/
void unloadCodec(CodecHandlePointer);
void unloadCodec(AudioCodecHandlePointer &ptr);
/**
* Check if the files found in searched directories seems valid
......@@ -163,7 +162,7 @@ class AudioCodecFactory {
/**
* Map the payload of a codec and the object associated ( AudioCodec * )
*/
CodecsMap codecsMap_;
AudioCodecsMap codecsMap_;
/**
* Vector containing a default order for the codecs
......@@ -179,7 +178,7 @@ class AudioCodecFactory {
* Vector containing pairs
* Pair between pointer on function handle and pointer on audiocodec object
*/
std::vector< CodecHandlePointer > codecInMemory_;
std::vector<AudioCodecHandlePointer> codecInMemory_;
};
#endif // __CODEC_DESCRIPTOR_H__
......@@ -758,13 +758,13 @@ class G722 : public sfl::AudioCodec {
// the class factories
// cppcheck-suppress unusedFunction
extern "C" sfl::Codec* CODEC_ENTRY()
extern "C" sfl::AudioCodec* AUDIO_CODEC_ENTRY()
{
return new G722;
}
// cppcheck-suppress unusedFunction
extern "C" void destroy(sfl::Codec* a)
extern "C" void destroy(sfl::AudioCodec* a)
{
delete a;
}
......
......@@ -92,7 +92,7 @@ void G729::loadError(const char *error)
}
// cppcheck-suppress unusedFunction
extern "C" sfl::Codec* CODEC_ENTRY()
extern "C" sfl::AudioCodec* AUDIO_CODEC_ENTRY()
{
try {
return new G729;
......@@ -103,7 +103,7 @@ extern "C" sfl::Codec* CODEC_ENTRY()
}
// cppcheck-suppress unusedFunction
extern "C" void destroy(sfl::Codec* a)
extern "C" void destroy(sfl::AudioCodec* a)
{
delete a;
}
......@@ -86,13 +86,13 @@ class Gsm : public sfl::AudioCodec {
};
// cppcheck-suppress unusedFunction
extern "C" sfl::Codec* CODEC_ENTRY()
extern "C" sfl::AudioCodec* AUDIO_CODEC_ENTRY()
{
return new Gsm;
}
// cppcheck-suppress unusedFunction
extern "C" void destroy(sfl::Codec* a)
extern "C" void destroy(sfl::AudioCodec* a)
{
delete a;
}
......@@ -85,12 +85,12 @@ class Ilbc: public sfl::AudioCodec {
};
// the class factories
extern "C" sfl::Codec* CODEC_ENTRY()
extern "C" sfl::AudioCodec* AUDIO_CODEC_ENTRY()
{
return new Ilbc;
}
extern "C" void destroy(sfl::Codec* a)
extern "C" void destroy(sfl::AudioCodec* a)
{
delete a;
}
......@@ -113,7 +113,7 @@ void Opus::loadError(const char *error)
}
// cppcheck-suppress unusedFunction
extern "C" sfl::Codec* CODEC_ENTRY()
extern "C" sfl::AudioCodec* AUDIO_CODEC_ENTRY()
{
try {
return new Opus;
......@@ -124,7 +124,7 @@ extern "C" sfl::Codec* CODEC_ENTRY()
}
// cppcheck-suppress unusedFunction
extern "C" void destroy(sfl::Codec* a)
extern "C" void destroy(sfl::AudioCodec* a)
{
delete a;
}
......@@ -33,13 +33,13 @@
#include "speexcodec.h"
// cppcheck-suppress unusedFunction
extern "C" sfl::Codec* CODEC_ENTRY()
extern "C" sfl::AudioCodec* AUDIO_CODEC_ENTRY()
{
return new Speex(110, 8000, 160, 24, true, &speex_nb_mode);
}
// cppcheck-suppress unusedFunction
extern "C" void destroy(sfl::Codec* a)
extern "C" void destroy(sfl::AudioCodec* a)
{
delete a;
}
......
......@@ -33,13 +33,13 @@
#include "speexcodec.h"
// cppcheck-suppress unusedFunction
extern "C" sfl::Codec* CODEC_ENTRY()
extern "C" sfl::AudioCodec* AUDIO_CODEC_ENTRY()
{
return new Speex(112, 32000, 640, 0, true, &speex_uwb_mode);
}
// cppcheck-suppress unusedFunction
extern "C" void destroy(sfl::Codec* a)
extern "C" void destroy(sfl::AudioCodec* a)
{
delete a;
}
......
......@@ -33,13 +33,13 @@
#include "speexcodec.h"
// cppcheck-suppress unusedFunction
extern "C" sfl::Codec* CODEC_ENTRY()
extern "C" sfl::AudioCodec* AUDIO_CODEC_ENTRY()
{
return new Speex(111, 16000, 320, 42, false, &speex_wb_mode);
}
// cppcheck-suppress unusedFunction
extern "C" void destroy(sfl::Codec* a)
extern "C" void destroy(sfl::AudioCodec* a)
{
delete a;
}
......
......@@ -115,13 +115,13 @@ class Ulaw : public sfl::AudioCodec {
// the class factories
// cppcheck-suppress unusedFunction
extern "C" sfl::Codec* CODEC_ENTRY()
extern "C" sfl::AudioCodec* AUDIO_CODEC_ENTRY()
{
return new Ulaw;
}
// cppcheck-suppress unusedFunction
extern "C" void destroy(sfl::Codec* a)
extern "C" void destroy(sfl::AudioCodec* a)
{
delete a;
}
/*
* Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
* Author: Pierre-Luc Bacon <pierre-luc.bacon@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_H_
#define CODEC_H_
#include "cc_config.h" // for types
/**
* Interface for both audio codecs as well as video codecs.
*/
namespace sfl {
class Codec {
public:
virtual ~Codec() {}
/**
* @return The mimesubtype for this codec. Eg. : "theora"
*/
virtual std::string getMimeSubtype() const = 0;
/**
* @return payload type numeric identifier.
*/
virtual uint8 getPayloadType() const = 0;
/**
* @return RTP clock rate in Hz.
*/
virtual uint32 getClockRate() const = 0;
/**
* @return The bitrate for which this codec is configured // TODO deal with VBR case.
*/
virtual double getBitRate() const = 0;
};
}
typedef sfl::Codec* create_t();
typedef void destroy_t (sfl::Codec*);
#endif // CODEC_H_