20 #include <com/avpkit/core/Property.h>
21 #include <com/avpkit/core/MetaData.h>
22 #include <com/avpkit/ferry/Logger.h>
23 #include <com/avpkit/core/Property.h>
25 #include "FfmpegIncludes.h"
26 #include <libavutil/log.h>
32 VS_LOG_SETUP(VS_CPP_PACKAGE);
34 namespace com {
namespace avpkit {
namespace core {
36 Property :: Property()
42 Property :: ~Property()
47 Property :: make(
const AVOption *start,
const AVOption *option)
53 throw std::bad_alloc();
55 throw std::bad_alloc();
56 retval = Property::make();
59 retval ->mOptionStart = start;
60 retval->mOption = option;
63 catch (std::bad_alloc & e)
65 VS_REF_RELEASE(retval);
74 return mOption ? mOption->name : 0;
80 return mOption ? mOption->help : 0;
86 return mOption ? mOption->unit : 0;
92 return mOption ? (
IProperty::Type) mOption->type : IProperty::PROPERTY_UNKNOWN;
104 return mOption ? mOption->default_val.dbl: 0.0;
110 return mOption ? mOption->flags : 0;
117 const AVOption* last = 0;
121 last = av_opt_next(aContext, last);
124 if (last->type != AV_OPT_TYPE_CONST)
136 const AVOption* last = 0;
141 throw std::runtime_error(
"no context passed in");
145 last = av_opt_next(aContext, last);
148 if (last->type != AV_OPT_TYPE_CONST)
152 if (optionNo == aPropertyNo)
154 retval = Property::make(av_opt_next(aContext, 0), last);
161 catch (std::exception & e)
163 VS_LOG_DEBUG(
"Error: %s", e.what());
164 VS_REF_RELEASE(retval);
173 const AVOption* last = 0;
178 throw std::runtime_error(
"no context passed in");
180 if (!aName || !*aName)
181 throw std::runtime_error(
"no property name passed in");
183 last = av_opt_find(aContext, aName, 0, 0, 0);
186 if (last->type != AV_OPT_TYPE_CONST)
188 retval = Property::make(av_opt_next(aContext, 0), last);
192 catch (std::exception & e)
194 VS_LOG_DEBUG(
"Error: %s", e.what());
195 VS_REF_RELEASE(retval);
208 throw std::runtime_error(
"no context passed in");
210 if (!aName || !*aName)
211 throw std::runtime_error(
"empty property name passed to setProperty");
216 AVClass *c = *(AVClass**)target;
218 VS_LOG_TRACE(
"Found option \"%s\" with help: %s; in unit: %s; object type: %s; instance name: %s",
223 c->item_name(aContext));
225 VS_LOG_TRACE(
"Setting %s to %s", aName, aValue);
228 catch (std::exception & e)
230 VS_LOG_DEBUG(
"Error: %s", e.what());
246 throw std::runtime_error(
"no context passed in");
248 if (!aName || !*aName)
249 throw std::runtime_error(
"empty property name passed to setProperty");
253 if (av_opt_get(aContext, aName, 0, (uint8_t**)&value) < 0)
254 throw std::runtime_error(
"could not get property");
259 int32_t valLen = strlen(value);
262 retval = (
char*)malloc((valLen+1)*
sizeof(char));
264 throw std::bad_alloc();
267 strncpy(retval, value, valLen+1);
271 catch (std::exception & e)
273 VS_LOG_DEBUG(
"Error: %s", e.what());
286 static const char * fakeContextToName(
void*)
296 if (
getType() != IProperty::PROPERTY_FLAGS)
297 throw std::runtime_error(
"flag is not of type PROPERTY_FLAGS");
303 throw std::runtime_error(
"flag doesn't have a unit setting, so can't tell what constants");
307 fakeClass.class_name=
"AVPKitFakeClass";
308 fakeClass.item_name = fakeContextToName;
309 fakeClass.option = mOptionStart;
310 AVClass *fakeClassPtr = &fakeClass;
312 const AVOption* last = 0;
315 last = av_opt_next(&fakeClassPtr, last);
318 last->type == AV_OPT_TYPE_CONST &&
319 strcmp(unit, last->unit)==0)
323 catch (std::exception & e)
325 VS_LOG_DEBUG(
"Error: %s", e.what());
337 if (
getType() != IProperty::PROPERTY_FLAGS)
338 throw std::runtime_error(
"flag is not of type PROPERTY_FLAGS");
344 throw std::runtime_error(
"flag doesn't have a unit setting, so can't tell what constants");
348 fakeClass.class_name=
"AVPKitFakeClass";
349 fakeClass.item_name = fakeContextToName;
350 fakeClass.option = mOptionStart;
351 AVClass *fakeClassPtr = &fakeClass;
353 const AVOption* last = 0;
354 int32_t constNo = -1;
357 last = av_opt_next(&fakeClassPtr, last);
360 last->type == AV_OPT_TYPE_CONST &&
361 strcmp(unit, last->unit)==0)
366 if (constNo == position)
368 retval = Property::make(av_opt_next(&fakeClassPtr, 0), last);
374 catch (std::exception & e)
376 VS_LOG_DEBUG(
"Error: %s", e.what());
377 VS_REF_RELEASE(retval);
388 if (
getType() != IProperty::PROPERTY_FLAGS)
389 throw std::runtime_error(
"flag is not of type PROPERTY_FLAGS");
395 throw std::runtime_error(
"flag doesn't have a unit setting, so can't tell what constants");
398 fakeClass.class_name=
"AVPKitFakeClass";
399 fakeClass.item_name = fakeContextToName;
400 fakeClass.option = mOptionStart;
402 const AVOption* last = 0;
403 last = av_opt_find(&fakeClass, aName, unit, 0, 0);
406 if (last->type == AV_OPT_TYPE_CONST)
408 retval = Property::make(av_opt_next(&fakeClass, 0), last);
413 catch (std::exception & e)
415 VS_LOG_DEBUG(
"Error: %s", e.what());
416 VS_REF_RELEASE(retval);
428 throw std::runtime_error(
"no context passed in");
430 if (!aName || !*aName)
431 throw std::runtime_error(
"empty property name passed to setProperty");
433 if (av_opt_get_double(aContext, aName, 0, &retval) < 0)
434 throw std::runtime_error(
"error getting property as double");
437 catch (std::exception &e)
439 VS_LOG_DEBUG(
"Error: %s", e.what());
452 throw std::runtime_error(
"no context passed in");
454 if (!aName || !*aName)
455 throw std::runtime_error(
"empty property name passed to setProperty");
456 av_opt_get_int(aContext, aName, 0, &retval);
458 catch (std::exception &e)
460 VS_LOG_DEBUG(
"Error: %s", e.what());
473 throw std::runtime_error(
"no context passed in");
475 if (!aName || !*aName)
476 throw std::runtime_error(
"empty property name passed to setProperty");
478 av_opt_get_q(aContext, aName, 0, &value);
481 catch (std::exception &e)
483 VS_LOG_DEBUG(
"Error: %s", e.what());
484 VS_REF_RELEASE(retval);
503 throw std::runtime_error(
"no context passed in");
505 if (!aName || !*aName)
506 throw std::runtime_error(
"empty property name passed to setProperty");
509 catch (std::exception &e)
511 VS_LOG_DEBUG(
"Error: %s", e.what());
524 throw std::runtime_error(
"no context passed in");
526 if (!aName || !*aName)
527 throw std::runtime_error(
"empty property name passed to setProperty");
531 catch (std::exception &e)
533 VS_LOG_DEBUG(
"Error: %s", e.what());
542 return setProperty(aContext, aName, (int64_t)value);
552 throw std::runtime_error(
"no context passed in");
554 if (!aName || !*aName)
555 throw std::runtime_error(
"empty property name passed to setProperty");
558 throw std::runtime_error(
"no rational value passed in");
565 catch (std::exception &e)
567 VS_LOG_DEBUG(
"Error: %s", e.what());
577 AVDictionary *tmp = 0;
580 AVDictionary *orig = valuesToSet ? valuesToSet->
getDictionary() : 0;
584 throw std::runtime_error(
"no context passed in");
587 av_dict_copy(&tmp, orig, 0);
590 retval = av_opt_set_dict(aContext, &tmp);
592 throw std::runtime_error(
"failed to set options on context");
595 retval = valuesNotFound->
copy(tmp);
598 }
catch (std::exception &e) {
Represents settable properties that effect how AVPKit objects operate.
Type
The different type of options that are supported by AVPKit.
@ PROPERTY_SEARCH_CHILDREN
Search children first.
This class wraps represents a Rational number for the AVPKit.
static IRational * make()
Get a new rational that will be set to 0/0.
virtual int32_t getDenominator()=0
Get the denominator for this rational.
virtual int32_t getNumerator()=0
Get the numerator for this rational.
virtual const char * getHelp()
Get the (English) help string for this property.
static int32_t setProperty(void *context, const char *name, const char *value)
Looks up the property 'name' in 'context' and sets the value of the property to 'value'.
virtual int32_t getFlags()
Get any set flags (a bitmask) for this option.
virtual int64_t getDefault()
Get the default setting this flag would have it not set.
static int32_t getNumProperties(void *context)
For internal use.
virtual IProperty * getFlagConstant(int32_t position)
If this IProperty is of the type Type#PROPERTY_FLAGS, this method will give you another IProperty rep...
static int64_t getPropertyAsLong(void *context, const char *name)
Gets the value of this property, and returns as an long;.
virtual Type getType()
Get the underlying native type of this property.
static IRational * getPropertyAsRational(void *context, const char *name)
Gets the value of this property, and returns as an IRational;.
static IProperty * getPropertyMetaData(void *context, int32_t propertyNo)
Returns the metadata for the numbered property.
virtual int32_t getNumFlagSettings()
If this IProperty is of the type Type#PROPERTY_FLAGS, this method will tell you how many different fl...
static double getPropertyAsDouble(void *context, const char *name)
Gets the value of this property, and returns as a double;.
static bool getPropertyAsBoolean(void *context, const char *name)
Gets the value of this property, and returns as a boolean.
static char * getPropertyAsString(void *context, const char *name)
Gets the value of this property, and returns as a new[]ed string.
virtual double getDefaultAsDouble()
Get the default setting this flag would have it not set.
virtual const char * getName()
IProperty implementation.
virtual const char * getUnit()
Get any sub-unit this option or constant belongs to.
WARNING: Do not use logging in this class, and do not set any static file variables to values other t...