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.");
140 for (
const char *
const * option = *(
const char *
const * *)parm; *option != NULL; option += 2)
141 originalOptions[option[0]] = option[1];
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());
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');
263 template<
typename NAME>
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;
341 for (
const char *
const * option = options; *option != NULL; option += 2) {
343 PTRACE(1,
"Plugin",
"Could not set option \"" << option[0] <<
"\" to \"" << option[1] <<
'"');
363 virtual bool SetOption(
const char * optionName,
const char * optionValue)
375 template <
typename T>
376 bool SetOptionUnsigned(T & oldValue,
const char * optionValue,
unsigned minimum,
unsigned maximum = UINT_MAX)
378 unsigned newValue = oldValue;
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) {
407 template <
typename T>
410 bool opt = oldValue != 0;
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) {
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) {
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