39 #ifndef OPAL_CODEC_OPALPLUGIN_HPP 40 #define OPAL_CODEC_OPALPLUGIN_HPP 54 #ifndef PLUGINCODEC_TRACING 55 #define PLUGINCODEC_TRACING 1 58 #if PLUGINCODEC_TRACING 62 #define PLUGINCODEC_CONTROL_LOG_FUNCTION_DEF \ 63 PluginCodec_LogFunction PluginCodec_LogFunctionInstance; \ 64 int PluginCodec_SetLogFunction(const PluginCodec_Definition *, void *, const char *, void * parm, unsigned * len) \ 66 if (len == NULL || *len != sizeof(PluginCodec_LogFunction)) \ 69 PluginCodec_LogFunctionInstance = (PluginCodec_LogFunction)parm; \ 70 if (PluginCodec_LogFunctionInstance != NULL) \ 71 PluginCodec_LogFunctionInstance(4, __FILE__, __LINE__, "Plugin", "Started logging."); \ 76 #define PLUGINCODEC_CONTROL_LOG_FUNCTION_INC { PLUGINCODEC_CONTROL_SET_LOG_FUNCTION, PluginCodec_SetLogFunction }, 78 #define PLUGINCODEC_CONTROL_LOG_FUNCTION_DEF 79 #define PLUGINCODEC_CONTROL_LOG_FUNCTION_INC 83 #if PLUGINCODEC_TRACING 85 #define PTRACE_CHECK(level) \ 86 (PluginCodec_LogFunctionInstance != NULL && PluginCodec_LogFunctionInstance(level, NULL, 0, NULL, NULL)) 87 #define PTRACE(level, section, args) \ 88 if (PTRACE_CHECK(level)) { \ 89 std::ostringstream strm; strm << args; \ 90 PluginCodec_LogFunctionInstance(level, __FILE__, __LINE__, section, strm.str().c_str()); \ 93 #define PTRACE_CHECK(level) 94 #define PTRACE(level, section, expr) 134 if (parmLen == NULL || parm == NULL || *parmLen !=
sizeof(
char ***)) {
135 PTRACE(1,
"Plugin",
"Invalid parameters to AdjustOptions.");
139 OptionMap originalOptions;
140 for (
const char *
const * option = *(
const char *
const * *)parm; *option != NULL; option += 2)
141 originalOptions[option[0]] = option[1];
143 OptionMap changedOptions;
144 if (!(this->*adjuster)(originalOptions, changedOptions)) {
145 PTRACE(1,
"Plugin",
"Could not normalise/customise options.");
149 char ** options = (
char **)calloc(changedOptions.size()*2+1,
sizeof(
char *));
150 *(
char ***)parm = options;
151 if (options == NULL) {
152 PTRACE(1,
"Plugin",
"Could not allocate new option lists.");
156 for (OptionMap::iterator i = changedOptions.begin(); i != changedOptions.end(); ++i) {
157 *options++ = strdup(i->first.c_str());
158 *options++ = strdup(i->second.c_str());
166 virtual bool ToNormalised(OptionMap & original, OptionMap & changed) = 0;
170 virtual bool ToCustomised(OptionMap & original, OptionMap & changed) = 0;
174 OptionMap & original,
178 OptionMap::iterator it = original.find(option);
179 if (it != original.end() && it->second != value)
180 changed[option] = value;
186 return strtoul(str.c_str(), NULL, 10);
195 str += (char)(value%10 +
'0');
207 OptionMap & original,
217 OptionMap & original,
228 OptionMap & original,
263 template<
typename NAME>
269 , m_optionsSame(false)
270 , m_maxBitRate(defn->bitsPerSec)
271 , m_frameTime((defn->sampleRate/1000*defn->usPerFrame)/1000)
273 PTRACE(3,
"Plugin",
"Codec created: \"" << defn->
descr 302 virtual bool Transcode(
const void * fromPtr,
306 unsigned & flags) = 0;
338 m_optionsSame =
true;
341 for (
const char *
const * option = options; *option != NULL; option += 2) {
342 if (!SetOption(option[0], option[1])) {
343 PTRACE(1,
"Plugin",
"Could not set option \"" << option[0] <<
"\" to \"" << option[1] <<
'"');
351 return OnChangedOptions();
363 virtual bool SetOption(
const char * optionName,
const char * optionValue)
366 return SetOptionUnsigned(m_maxBitRate, optionValue, 1, m_definition->bitsPerSec);
369 return SetOptionUnsigned(m_frameTime, optionValue, m_definition->sampleRate/1000, m_definition->sampleRate);
375 template <
typename T>
376 bool SetOptionUnsigned(T & oldValue,
const char * optionValue,
unsigned minimum,
unsigned maximum = UINT_MAX)
378 unsigned newValue = oldValue;
379 if (!SetOptionUnsigned(newValue, optionValue, minimum, maximum))
381 oldValue = (T)newValue;
386 bool SetOptionUnsigned(
unsigned & oldValue,
const char * optionValue,
unsigned minimum,
unsigned maximum = UINT_MAX)
389 unsigned newValue = strtoul(optionValue, &end, 10);
393 if (newValue < minimum)
395 else if (newValue > maximum)
398 if (oldValue != newValue) {
400 m_optionsSame =
false;
407 template <
typename T>
410 bool opt = oldValue != 0;
411 if (!SetOptionBoolean(opt, optionValue))
421 if ( strcasecmp(optionValue,
"0") == 0 ||
422 strcasecmp(optionValue,
"n") == 0 ||
423 strcasecmp(optionValue,
"f") == 0 ||
424 strcasecmp(optionValue,
"no") == 0 ||
425 strcasecmp(optionValue,
"false") == 0)
427 else if (strcasecmp(optionValue,
"1") == 0 ||
428 strcasecmp(optionValue,
"y") == 0 ||
429 strcasecmp(optionValue,
"t") == 0 ||
430 strcasecmp(optionValue,
"yes") == 0 ||
431 strcasecmp(optionValue,
"true") == 0)
436 if (oldValue != newValue) {
438 m_optionsSame =
false;
445 bool SetOptionBit(
int & oldValue,
unsigned bit,
const char * optionValue)
447 return SetOptionBit((
unsigned &)oldValue, bit, optionValue);
451 bool SetOptionBit(
unsigned & oldValue,
unsigned bit,
const char * optionValue)
454 if (strcmp(optionValue,
"0") == 0)
456 else if (strcmp(optionValue,
"1") == 0)
461 if (((oldValue&bit) != 0) != newValue) {
466 m_optionsSame =
false;
475 CodecClass * codec =
new CodecClass(defn);
476 if (codec != NULL && codec->Construct())
479 PTRACE(1,
"Plugin",
"Could not open codec, no context being returned.");
493 const void * fromPtr,
497 unsigned int * flags)
499 if (context != NULL && fromPtr != NULL && fromLen != NULL && toPtr != NULL && toLen != NULL && flags != NULL)
500 return ((
PluginCodec *)context)->Transcode(fromPtr, *fromLen, toPtr, *toLen, *flags);
502 PTRACE(1,
"Plugin",
"Invalid parameter to Transcode.");
509 return context != NULL ? ((
PluginCodec *)context)->GetOutputDataSize() : 0;
527 if (parm == NULL || len == NULL || *len !=
sizeof(
char ***))
530 char ** strings = (
char **)parm;
531 for (
char **
string = strings; *
string != NULL;
string++)
552 return len != NULL && *len ==
sizeof(
const char **) && parm != NULL &&
553 codec != NULL && codec->
SetOptions((
const char *
const *)parm);
558 return len != NULL && *len ==
sizeof(
const char *) && parm != NULL && defn->
userData != NULL &&
565 return len != NULL && parm != NULL &&
566 codec != NULL && codec->
SetInstanceID((
const char *)parm, *len);
572 return len != NULL && parm != NULL &&
579 return codec != NULL && codec->
Terminate();
598 return ControlsTable;
610 #endif // OPAL_CODEC_OPALPLUGIN_HPP static int FreeOptions(const PluginCodec_Definition *, void *, const char *, void *parm, unsigned *len)
Definition: opalplugin.hpp:525
bool SetOptionBit(int &oldValue, unsigned bit, const char *optionValue)
Definition: opalplugin.hpp:445
#define PLUGINCODEC_CONTROL_SET_INSTANCE_ID
Definition: opalplugin.h:219
#define PLUGINCODEC_CONTROL_GET_STATISTICS
Definition: opalplugin.h:221
static int ToCustomised(const PluginCodec_Definition *defn, void *, const char *, void *parm, unsigned *len)
Definition: opalplugin.hpp:519
virtual bool SetOptions(const char *const *options)
Set all the options for the codec.
Definition: opalplugin.hpp:336
#define PLUGINCODEC_MEDIA_PACKETIZATIONS
Definition: opalplugin.h:824
Definition: opalplugin.h:328
bool SetOptionBoolean(bool &oldValue, const char *optionValue)
Definition: opalplugin.hpp:418
Definition: opalplugin.h:282
virtual bool Construct()
Complete construction of the plug in codec.
Definition: opalplugin.hpp:285
const char * sourceFormat
Definition: opalplugin.h:342
bool m_optionsSame
Definition: opalplugin.hpp:604
static int ValidForProtocol(const PluginCodec_Definition *defn, void *, const char *, void *parm, unsigned *len)
Definition: opalplugin.hpp:556
#define PLUGINCODEC_CONTROL_GET_OUTPUT_DATA_SIZE
Definition: opalplugin.h:215
#define PLUGINCODEC_CONTROL_VALID_FOR_PROTOCOL
Definition: opalplugin.h:212
static int ToNormalised(const PluginCodec_Definition *defn, void *, const char *, void *parm, unsigned *len)
Definition: opalplugin.hpp:513
bool SetOptionUnsigned(T &oldValue, const char *optionValue, unsigned minimum, unsigned maximum=UINT_MAX)
Definition: opalplugin.hpp:376
Definition: opalplugin.hpp:264
#define PLUGIN_CODEC_VERSION_INTERSECT
Definition: opalplugin.h:87
static void Destroy(const PluginCodec_Definition *, void *context)
Definition: opalplugin.hpp:485
static int GetOutputDataSize(const PluginCodec_Definition *, void *context, const char *, void *, unsigned *)
Definition: opalplugin.hpp:507
static int GetOptions(const struct PluginCodec_Definition *codec, void *, const char *, void *parm, unsigned *len)
Definition: opalplugin.hpp:538
static struct PluginCodec_ControlDefn * GetControls()
Definition: opalplugin.hpp:582
virtual bool OnChangedOptions()
Callback for if any options are changed.
Definition: opalplugin.hpp:356
virtual bool SetOption(const char *optionName, const char *optionValue)
Set an individual option of teh given name.
Definition: opalplugin.hpp:363
unsigned m_maxBitRate
Definition: opalplugin.hpp:605
PluginCodec_LogFunction PluginCodec_LogFunctionInstance
PluginCodec(const PluginCodec_Definition *defn)
Definition: opalplugin.hpp:267
bool SetOptionBit(unsigned &oldValue, unsigned bit, const char *optionValue)
Definition: opalplugin.hpp:451
static int Terminate(const PluginCodec_Definition *, void *context, const char *, void *, unsigned *)
Definition: opalplugin.hpp:576
#define PTRACE(level, section, args)
Definition: opalplugin.hpp:87
#define PLUGINCODEC_CONTROL_TO_NORMALISED_OPTIONS
Definition: opalplugin.h:217
Definition: opalplugin.h:237
#define PLUGINCODEC_CONTROL_SET_CODEC_OPTIONS
Definition: opalplugin.h:216
const PluginCodec_Definition * m_definition
Definition: opalplugin.hpp:602
static int SetOptions(const PluginCodec_Definition *, void *context, const char *, void *parm, unsigned *len)
Definition: opalplugin.hpp:549
#define PLUGINCODEC_CONTROL_LOG_FUNCTION_INC
Definition: opalplugin.hpp:76
virtual bool SetInstanceID(const char *, unsigned)
Definition: opalplugin.hpp:329
static bool Terminate()
Definition: opalplugin.hpp:295
virtual bool GetStatistics(char *, unsigned)
Gather any statistics as a string into the provide buffer.
Definition: opalplugin.hpp:310
const void * userData
Definition: opalplugin.h:345
#define PLUGINCODEC_OPTION_FRAME_TIME
Definition: opalplugin.h:304
static int GetStatistics(const PluginCodec_Definition *, void *context, const char *, void *parm, unsigned *len)
Definition: opalplugin.hpp:569
#define PLUGINCODEC_CONTROL_TO_CUSTOMISED_OPTIONS
Definition: opalplugin.h:218
unsigned m_frameTime
Definition: opalplugin.hpp:606
virtual size_t GetOutputDataSize()
Get the required output buffer size to be passed into Transcode.
Definition: opalplugin.hpp:317
static void * Create(const PluginCodec_Definition *defn)
Definition: opalplugin.hpp:473
static int SetInstanceID(const PluginCodec_Definition *, void *context, const char *, void *parm, unsigned *len)
Definition: opalplugin.hpp:562
#define PLUGINCODEC_CONTROL_FREE_CODEC_OPTIONS
Definition: opalplugin.h:214
#define PLUGINCODEC_OPTION_TARGET_BIT_RATE
Definition: opalplugin.h:308
bool SetOptionBoolean(T &oldValue, const char *optionValue)
Definition: opalplugin.hpp:408
const char * descr
Definition: opalplugin.h:340
bool SetOptionUnsigned(unsigned &oldValue, const char *optionValue, unsigned minimum, unsigned maximum=UINT_MAX)
Definition: opalplugin.hpp:386
#define PLUGINCODEC_CONTROL_GET_CODEC_OPTIONS
Definition: opalplugin.h:213
int PluginCodec_SetLogFunction(const PluginCodec_Definition *, void *, const char *, void *parm, unsigned *len)
#define PLUGINCODEC_CONTROL_TERMINATE_CODEC
Definition: opalplugin.h:222
virtual ~PluginCodec()
Definition: opalplugin.hpp:279
const char * destFormat
Definition: opalplugin.h:343
static int Transcode(const PluginCodec_Definition *, void *context, const void *fromPtr, unsigned *fromLen, void *toPtr, unsigned *toLen, unsigned int *flags)
Definition: opalplugin.hpp:491
int(* PluginCodec_LogFunction)(unsigned level, const char *file, unsigned line, const char *section, const char *log)
Definition: opalplugin.h:230