AVPKit
com::avpkit::core::Property Class Reference

A wrapper for an FFMPEG AVOption value. More...

#include <Property.h>

Inheritance diagram for com::avpkit::core::Property:
Collaboration diagram for com::avpkit::core::Property:

Public Member Functions

virtual const char * getName ()
 IProperty implementation.
 
virtual const char * getHelp ()
 Get the (English) help string for this property. More...
 
virtual const char * getUnit ()
 Get any sub-unit this option or constant belongs to. More...
 
virtual Type getType ()
 Get the underlying native type of this property. More...
 
virtual int64_t getDefault ()
 Get the default setting this flag would have it not set. More...
 
virtual double getDefaultAsDouble ()
 Get the default setting this flag would have it not set. More...
 
virtual int32_t getFlags ()
 Get any set flags (a bitmask) for this option. More...
 
virtual int32_t getNumFlagSettings ()
 If this IProperty is of the type Type#PROPERTY_FLAGS, this method will tell you how many different flag settings it takes. More...
 
virtual IPropertygetFlagConstant (int32_t position)
 If this IProperty is of the type Type#PROPERTY_FLAGS, this method will give you another IProperty representing a constant setting for that flag. More...
 
virtual IPropertygetFlagConstant (const char *name)
 If this IProperty is of the type Type#PROPERTY_FLAGS, this method will give you another IProperty representing a constant setting for that flag. More...
 
- Public Member Functions inherited from com::avpkit::ferry::RefCounted
virtual int32_t acquire ()
 Internal Only. More...
 
virtual int32_t release ()
 Internal Only. More...
 
virtual RefCountedcopyReference ()
 Create a new Java object that refers to the same native object. More...
 
virtual int32_t getCurrentRefCount ()
 Return the current reference count on this object. More...
 
void setJavaAllocator (void *allocator)
 This method is public but not part of the standard API. More...
 
void * getJavaAllocator ()
 This method is public but not part of the standard API. More...
 

Static Public Member Functions

static Propertymake (const AVOption *start, const AVOption *option)
 
static int32_t getNumProperties (void *context)
 For internal use. More...
 
static IPropertygetPropertyMetaData (void *context, int32_t propertyNo)
 Returns the metadata for the numbered property. More...
 
static IPropertygetPropertyMetaData (void *context, const char *name)
 Returns the metadata for the named property. More...
 
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'. More...
 
static int32_t setProperty (void *context, const char *name, double value)
 Looks up the property 'name' in 'context' and sets the value of the property to 'value'. More...
 
static int32_t setProperty (void *context, const char *name, int64_t value)
 Looks up the property 'name' in 'context' and sets the value of the property to 'value'. More...
 
static int32_t setProperty (void *context, const char *name, bool value)
 Looks up the property 'name' in 'context' and sets the value of the property to 'value'. More...
 
static int32_t setProperty (void *context, const char *name, IRational *value)
 Looks up the property 'name' in 'context' and sets the value of the property to 'value'. More...
 
static char * getPropertyAsString (void *context, const char *name)
 Gets the value of this property, and returns as a new[]ed string. More...
 
static double getPropertyAsDouble (void *context, const char *name)
 Gets the value of this property, and returns as a double;. More...
 
static int64_t getPropertyAsLong (void *context, const char *name)
 Gets the value of this property, and returns as an long;. More...
 
static IRationalgetPropertyAsRational (void *context, const char *name)
 Gets the value of this property, and returns as an IRational;. More...
 
static bool getPropertyAsBoolean (void *context, const char *name)
 Gets the value of this property, and returns as a boolean. More...
 
static int32_t setProperty (void *context, IMetaData *valuesToSet, IMetaData *valuesNotFound)
 Sets all properties in valuesToSet on object context. More...
 

Additional Inherited Members

- Public Types inherited from com::avpkit::core::IProperty
enum  Type {
  PROPERTY_FLAGS , PROPERTY_INT , PROPERTY_INT64 , PROPERTY_DOUBLE ,
  PROPERTY_FLOAT , PROPERTY_STRING , PROPERTY_RATIONAL , PROPERTY_BINARY ,
  PROPERTY_DICT , PROPERTY_UINT64 , PROPERTY_CONST , PROPERTY_IMAGE_SIZE ,
  PROPERTY_PIXEL_FMT , PROPERTY_SAMPLE_FMT , PROPERTY_VIDEO_RATE , PROPERTY_DURATION ,
  PROPERTY_COLOR , PROPERTY_CHANNEL_LAYOUT , PROPERTY_BOOL , PROPERTY_UNKNOWN =-1
}
 The different type of options that are supported by AVPKit. More...
 
enum  Flags {
  FLAG_ENCODING_PARAM =1 , FLAG_DECODING_PARAM =2 , FLAG_METADATA =4 , FLAG_AUDIO_PARAM =8 ,
  FLAG_VIDEO_PARAM =16 , FLAG_SUBTITLE_PARAM =32 , FLAG_EXPORT =64 , FLAG_READONLY =128 ,
  FLAG_FILTERING_PARAM =(1<<16)
}
 
enum  Search { PROPERTY_SEARCH_DEFAULT =0x0000 , PROPERTY_SEARCH_CHILDREN =0x0001 }
 How to search options when looking for different values. More...
 
- Protected Member Functions inherited from com::avpkit::ferry::RefCounted
virtual void destroy ()
 This method is called by RefCounted objects when their Ref Count reaches zero and they are about to be destroyed.
 
- Protected Attributes inherited from com::avpkit::ferry::RefCounted
AtomicIntegermRefCount
 This is the internal reference count, represented as an AtomicInteger to make sure it is thread safe.
 
void * mAllocator
 Not part of public API.
 

Detailed Description

A wrapper for an FFMPEG AVOption value.

Definition at line 35 of file Property.h.

Member Function Documentation

◆ getDefault()

int64_t com::avpkit::core::Property::getDefault ( )
virtual

Get the default setting this flag would have it not set.

Returns
the default

Implements com::avpkit::core::IProperty.

Definition at line 96 of file Property.cpp.

97  {
98  return (int64_t)getDefaultAsDouble();
99  }
virtual double getDefaultAsDouble()
Get the default setting this flag would have it not set.
Definition: Property.cpp:102

References getDefaultAsDouble().

◆ getDefaultAsDouble()

double com::avpkit::core::Property::getDefaultAsDouble ( )
virtual

Get the default setting this flag would have it not set.

Returns
the default

Implements com::avpkit::core::IProperty.

Definition at line 102 of file Property.cpp.

103  {
104  return mOption ? mOption->default_val.dbl: 0.0;
105  }

Referenced by getDefault().

◆ getFlagConstant() [1/2]

IProperty * com::avpkit::core::Property::getFlagConstant ( const char *  name)
virtual

If this IProperty is of the type Type#PROPERTY_FLAGS, this method will give you another IProperty representing a constant setting for that flag.

Parameters
nameThe name of the constant.
Returns
An IProperty object for the flag setting, or null if not available.

Implements com::avpkit::core::IProperty.

Definition at line 383 of file Property.cpp.

384  {
385  IProperty *retval = 0;
386  try
387  {
388  if (getType() != IProperty::PROPERTY_FLAGS)
389  throw std::runtime_error("flag is not of type PROPERTY_FLAGS");
390 
391  // now, iterate through all options, counting all CONSTS that belong
392  // to the same unit as this option
393  const char* unit = getUnit();
394  if (!unit || !*unit)
395  throw std::runtime_error("flag doesn't have a unit setting, so can't tell what constants");
396 
397  AVClass fakeClass;
398  fakeClass.class_name="AVPKitFakeClass";
399  fakeClass.item_name = fakeContextToName;
400  fakeClass.option = mOptionStart;
401 
402  const AVOption* last = 0;
403  last = av_opt_find(&fakeClass, aName, unit, 0, 0);
404  if (last)
405  {
406  if (last->type == AV_OPT_TYPE_CONST)
407  {
408  retval = Property::make(av_opt_next(&fakeClass, 0), last);
409  }
410  }
411 
412  }
413  catch (std::exception & e)
414  {
415  VS_LOG_DEBUG("Error: %s", e.what());
416  VS_REF_RELEASE(retval);
417  }
418  return retval;
419  }
virtual Type getType()
Get the underlying native type of this property.
Definition: Property.cpp:90
virtual const char * getUnit()
Get any sub-unit this option or constant belongs to.
Definition: Property.cpp:84

References getType(), and getUnit().

◆ getFlagConstant() [2/2]

IProperty * com::avpkit::core::Property::getFlagConstant ( int32_t  position)
virtual

If this IProperty is of the type Type#PROPERTY_FLAGS, this method will give you another IProperty representing a constant setting for that flag.

Parameters
positionThe position number for the flag; Must be in range 0 <= position <= getNumFlagSettings().
Returns
An IProperty object for the flag setting, or null if not available.

Implements com::avpkit::core::IProperty.

Definition at line 332 of file Property.cpp.

333  {
334  IProperty *retval = 0;
335  try
336  {
337  if (getType() != IProperty::PROPERTY_FLAGS)
338  throw std::runtime_error("flag is not of type PROPERTY_FLAGS");
339 
340  // now, iterate through all options, counting all CONSTS that belong
341  // to the same unit as this option
342  const char* unit = getUnit();
343  if (!unit || !*unit)
344  throw std::runtime_error("flag doesn't have a unit setting, so can't tell what constants");
345 
346  // Create a fake class
347  AVClass fakeClass;
348  fakeClass.class_name="AVPKitFakeClass";
349  fakeClass.item_name = fakeContextToName;
350  fakeClass.option = mOptionStart;
351  AVClass *fakeClassPtr = &fakeClass;
352 
353  const AVOption* last = 0;
354  int32_t constNo = -1;
355  do
356  {
357  last = av_opt_next(&fakeClassPtr, last);
358  if (last &&
359  last->unit &&
360  last->type == AV_OPT_TYPE_CONST &&
361  strcmp(unit, last->unit)==0)
362  {
363  // count in the same was as getNumFlagSettings,
364  // and then return if the position is equal
365  ++constNo;
366  if (constNo == position)
367  {
368  retval = Property::make(av_opt_next(&fakeClassPtr, 0), last);
369  }
370  }
371  } while(last);
372 
373  }
374  catch (std::exception & e)
375  {
376  VS_LOG_DEBUG("Error: %s", e.what());
377  VS_REF_RELEASE(retval);
378  }
379  return retval;
380  }

References getType(), and getUnit().

◆ getFlags()

int32_t com::avpkit::core::Property::getFlags ( )
virtual

Get any set flags (a bitmask) for this option.

Returns
the flags

Implements com::avpkit::core::IProperty.

Definition at line 108 of file Property.cpp.

109  {
110  return mOption ? mOption->flags : 0;
111  }

◆ getHelp()

const char * com::avpkit::core::Property::getHelp ( )
virtual

Get the (English) help string for this property.

Returns
the help string

Implements com::avpkit::core::IProperty.

Definition at line 78 of file Property.cpp.

79  {
80  return mOption ? mOption->help : 0;
81  }

◆ getNumFlagSettings()

int32_t com::avpkit::core::Property::getNumFlagSettings ( )
virtual

If this IProperty is of the type Type#PROPERTY_FLAGS, this method will tell you how many different flag settings it takes.

Returns
Number of flag settings, or <0 if not a FLAGS value

Implements com::avpkit::core::IProperty.

Definition at line 292 of file Property.cpp.

293  {
294  int32_t retval = 0;
295  try {
296  if (getType() != IProperty::PROPERTY_FLAGS)
297  throw std::runtime_error("flag is not of type PROPERTY_FLAGS");
298 
299  // now, iterate through all options, counting all CONSTS that belong
300  // to the same unit as this option
301  const char* unit = getUnit();
302  if (!unit || !*unit)
303  throw std::runtime_error("flag doesn't have a unit setting, so can't tell what constants");
304 
305  // Create a fake class
306  AVClass fakeClass;
307  fakeClass.class_name="AVPKitFakeClass";
308  fakeClass.item_name = fakeContextToName;
309  fakeClass.option = mOptionStart;
310  AVClass *fakeClassPtr = &fakeClass;
311 
312  const AVOption* last = 0;
313  do
314  {
315  last = av_opt_next(&fakeClassPtr, last);
316  if (last &&
317  last->unit &&
318  last->type == AV_OPT_TYPE_CONST &&
319  strcmp(unit, last->unit)==0)
320  ++retval;
321  } while(last);
322  }
323  catch (std::exception & e)
324  {
325  VS_LOG_DEBUG("Error: %s", e.what());
326  retval = -1;
327  }
328  return retval;
329  }

References getType(), and getUnit().

◆ getNumProperties()

int32_t com::avpkit::core::Property::getNumProperties ( void *  context)
static

For internal use.

Returns the total number of settable properties on this object

Parameters
contextAVClass to search for options in
Returns
total number of options (not including constant definitions)

Definition at line 114 of file Property.cpp.

115  {
116  int32_t retval=0;
117  const AVOption* last = 0;
118  if (aContext)
119  {
120  do {
121  last = av_opt_next(aContext, last);
122  if (last)
123  {
124  if (last->type != AV_OPT_TYPE_CONST)
125  ++retval;
126  }
127  } while (last);
128  }
129  return retval;
130  }

◆ getPropertyAsBoolean()

bool com::avpkit::core::Property::getPropertyAsBoolean ( void *  context,
const char *  name 
)
static

Gets the value of this property, and returns as a boolean.

Parameters
contextAVClass context to search for option in.
namename of option
Returns
boolean value of property, or false on error.

Definition at line 491 of file Property.cpp.

492  {
493  return (bool) getPropertyAsLong(aContext, aName);
494  }
static int64_t getPropertyAsLong(void *context, const char *name)
Gets the value of this property, and returns as an long;.
Definition: Property.cpp:446

References getPropertyAsLong().

◆ getPropertyAsDouble()

double com::avpkit::core::Property::getPropertyAsDouble ( void *  context,
const char *  name 
)
static

Gets the value of this property, and returns as a double;.

Parameters
contextAVClass context to search for option in.
namename of option
Returns
double value of property, or 0 on error.

Definition at line 422 of file Property.cpp.

423  {
424  double retval = 0;
425  try
426  {
427  if (!aContext)
428  throw std::runtime_error("no context passed in");
429 
430  if (!aName || !*aName)
431  throw std::runtime_error("empty property name passed to setProperty");
432 
433  if (av_opt_get_double(aContext, aName, 0, &retval) < 0)
434  throw std::runtime_error("error getting property as double");
435 
436  }
437  catch (std::exception &e)
438  {
439  VS_LOG_DEBUG("Error: %s", e.what());
440  retval = 0;
441  }
442  return retval;
443  }

◆ getPropertyAsLong()

int64_t com::avpkit::core::Property::getPropertyAsLong ( void *  context,
const char *  name 
)
static

Gets the value of this property, and returns as an long;.

Parameters
contextAVClass context to search for option in.
namename of option
Returns
long value of property, or 0 on error.

Definition at line 446 of file Property.cpp.

447  {
448  int64_t retval = 0;
449  try
450  {
451  if (!aContext)
452  throw std::runtime_error("no context passed in");
453 
454  if (!aName || !*aName)
455  throw std::runtime_error("empty property name passed to setProperty");
456  av_opt_get_int(aContext, aName, 0, &retval);
457  }
458  catch (std::exception &e)
459  {
460  VS_LOG_DEBUG("Error: %s", e.what());
461  retval = 0;
462  }
463  return retval;
464  }

Referenced by getPropertyAsBoolean().

◆ getPropertyAsRational()

IRational * com::avpkit::core::Property::getPropertyAsRational ( void *  context,
const char *  name 
)
static

Gets the value of this property, and returns as an IRational;.

Parameters
contextAVClass context to search for option in.
namename of option
Returns
long value of property, or 0 on error.

Definition at line 467 of file Property.cpp.

468  {
469  IRational *retval = 0;
470  try
471  {
472  if (!aContext)
473  throw std::runtime_error("no context passed in");
474 
475  if (!aName || !*aName)
476  throw std::runtime_error("empty property name passed to setProperty");
477  AVRational value;
478  av_opt_get_q(aContext, aName, 0, &value);
479  retval = IRational::make(value.num, value.den);
480  }
481  catch (std::exception &e)
482  {
483  VS_LOG_DEBUG("Error: %s", e.what());
484  VS_REF_RELEASE(retval);
485  }
486  return retval;
487  }
static IRational * make()
Get a new rational that will be set to 0/0.
Definition: IRational.cpp:79

References com::avpkit::core::IRational::make().

◆ getPropertyAsString()

char * com::avpkit::core::Property::getPropertyAsString ( void *  context,
const char *  name 
)
static

Gets the value of this property, and returns as a new[]ed string.

Caller must call delete[] on string.

Parameters
contextAVClass context to search for option in.
namename of option
Returns
string version of option value (caller must call delete[]) or null on error.

Definition at line 238 of file Property.cpp.

239  {
240  char* retval = 0;
241  char *value = 0;
242 
243  try
244  {
245  if (!aContext)
246  throw std::runtime_error("no context passed in");
247 
248  if (!aName || !*aName)
249  throw std::runtime_error("empty property name passed to setProperty");
250 
251  // we don't allow a string value longer than this. This is
252  // actually safe because this buffer is only used for non-string options
253  if (av_opt_get(aContext, aName, 0, (uint8_t**)&value) < 0)
254  throw std::runtime_error("could not get property");
255 
256  if (value)
257  {
258  // let's make a copy of the data
259  int32_t valLen = strlen(value);
260  if (valLen > 0)
261  {
262  retval = (char*)malloc((valLen+1)*sizeof(char));
263  if (!retval)
264  throw std::bad_alloc();
265 
266  // copy the data
267  strncpy(retval, value, valLen+1);
268  }
269  }
270  }
271  catch (std::exception & e)
272  {
273  VS_LOG_DEBUG("Error: %s", e.what());
274  if (retval)
275  free(retval);
276  retval = 0;
277  }
278  if (value)
279  av_free(value);
280 
281  // NOTE: Caller must call free() on returned value; we mean it!
282  return retval;
283 
284  }

◆ getPropertyMetaData() [1/2]

IProperty * com::avpkit::core::Property::getPropertyMetaData ( void *  context,
const char *  name 
)
static

Returns the metadata for the named property.

Parameters
contextAVClass to search for options in
nameThe property number in the options list.
Returns
the meta data for this property, or null if not found

Definition at line 170 of file Property.cpp.

171  {
172  IProperty *retval = 0;
173  const AVOption* last = 0;
174 
175  try
176  {
177  if (!aContext)
178  throw std::runtime_error("no context passed in");
179 
180  if (!aName || !*aName)
181  throw std::runtime_error("no property name passed in");
182 
183  last = av_opt_find(aContext, aName, 0, 0, 0);
184  if (last)
185  {
186  if (last->type != AV_OPT_TYPE_CONST)
187  {
188  retval = Property::make(av_opt_next(aContext, 0), last);
189  }
190  }
191  }
192  catch (std::exception & e)
193  {
194  VS_LOG_DEBUG("Error: %s", e.what());
195  VS_REF_RELEASE(retval);
196  }
197  return retval;
198  }

◆ getPropertyMetaData() [2/2]

IProperty * com::avpkit::core::Property::getPropertyMetaData ( void *  context,
int32_t  propertyNo 
)
static

Returns the metadata for the numbered property.

Note that a property number is guaranteed to stay constant during this run of AVPKit, but the property number may change if the process restarts.

Parameters
contextAVClass to search for options in
propertyNoThe property number in the options list.
Returns
the meta data for this property, or null if not found

Definition at line 133 of file Property.cpp.

134  {
135  IProperty *retval = 0;
136  const AVOption* last = 0;
137 
138  try
139  {
140  if (!aContext)
141  throw std::runtime_error("no context passed in");
142 
143  int32_t optionNo=-1;
144  do {
145  last = av_opt_next(aContext, last);
146  if (last)
147  {
148  if (last->type != AV_OPT_TYPE_CONST)
149  {
150  ++optionNo;
151  // now see if this option position matches the property asked for
152  if (optionNo == aPropertyNo)
153  {
154  retval = Property::make(av_opt_next(aContext, 0), last);
155  break;
156  }
157  }
158  }
159  } while (last);
160  }
161  catch (std::exception & e)
162  {
163  VS_LOG_DEBUG("Error: %s", e.what());
164  VS_REF_RELEASE(retval);
165  }
166  return retval;
167  }

◆ getType()

IProperty::Type com::avpkit::core::Property::getType ( )
virtual

Get the underlying native type of this property.

Returns
the type

Implements com::avpkit::core::IProperty.

Definition at line 90 of file Property.cpp.

91  {
92  return mOption ? (IProperty::Type) mOption->type : IProperty::PROPERTY_UNKNOWN;
93  }
Type
The different type of options that are supported by AVPKit.
Definition: IProperty.h:44

Referenced by getFlagConstant(), and getNumFlagSettings().

◆ getUnit()

const char * com::avpkit::core::Property::getUnit ( )
virtual

Get any sub-unit this option or constant belongs to.

Returns
the unit, or null if none.

Implements com::avpkit::core::IProperty.

Definition at line 84 of file Property.cpp.

85  {
86  return mOption ? mOption->unit : 0;
87  }

Referenced by getFlagConstant(), and getNumFlagSettings().

◆ setProperty() [1/6]

int32_t com::avpkit::core::Property::setProperty ( void *  context,
const char *  name,
bool  value 
)
static

Looks up the property 'name' in 'context' and sets the value of the property to 'value'.

Parameters
contextAVClass to search for option in.
namename of option
valueValue of option
Returns
>= 0 on success; <0 on error.

Definition at line 540 of file Property.cpp.

541  {
542  return setProperty(aContext, aName, (int64_t)value);
543  }
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'.
Definition: Property.cpp:201

References setProperty().

◆ setProperty() [2/6]

int32_t com::avpkit::core::Property::setProperty ( void *  context,
const char *  name,
const char *  value 
)
static

Looks up the property 'name' in 'context' and sets the value of the property to 'value'.

Parameters
contextAVClass to search for option in.
namename of option
valueValue of option
Returns
>= 0 on success; <0 on error.

Definition at line 201 of file Property.cpp.

202  {
203  int32_t retval = -1;
204 
205  try
206  {
207  if (!aContext)
208  throw std::runtime_error("no context passed in");
209 
210  if (!aName || !*aName)
211  throw std::runtime_error("empty property name passed to setProperty");
212 
213  void * target=0;
214  const AVOption *o = av_opt_find2(aContext, aName, 0, PROPERTY_SEARCH_CHILDREN, 1, &target);
215  if (o) {
216  AVClass *c = *(AVClass**)target;
217  (void) c;
218  VS_LOG_TRACE("Found option \"%s\" with help: %s; in unit: %s; object type: %s; instance name: %s",
219  o->name,
220  o->help,
221  o->unit,
222  c->class_name,
223  c->item_name(aContext));
224  }
225  VS_LOG_TRACE("Setting %s to %s", aName, aValue);
226  retval = av_opt_set(aContext, aName, aValue, PROPERTY_SEARCH_CHILDREN);
227  }
228  catch (std::exception & e)
229  {
230  VS_LOG_DEBUG("Error: %s", e.what());
231  retval = -1;
232  }
233 
234  return retval;
235  }
@ PROPERTY_SEARCH_CHILDREN
Search children first.
Definition: IProperty.h:86

References com::avpkit::core::IProperty::PROPERTY_SEARCH_CHILDREN.

Referenced by setProperty().

◆ setProperty() [3/6]

int32_t com::avpkit::core::Property::setProperty ( void *  context,
const char *  name,
double  value 
)
static

Looks up the property 'name' in 'context' and sets the value of the property to 'value'.

Parameters
contextAVClass to search for option in.
namename of option
valueValue of option
Returns
>= 0 on success; <0 on error.

Definition at line 497 of file Property.cpp.

498  {
499  int32_t retval = 0;
500  try
501  {
502  if (!aContext)
503  throw std::runtime_error("no context passed in");
504 
505  if (!aName || !*aName)
506  throw std::runtime_error("empty property name passed to setProperty");
507  retval = av_opt_set_double(aContext, aName, value, PROPERTY_SEARCH_CHILDREN);
508  }
509  catch (std::exception &e)
510  {
511  VS_LOG_DEBUG("Error: %s", e.what());
512  retval = -1;
513  }
514  return retval;
515  }

References com::avpkit::core::IProperty::PROPERTY_SEARCH_CHILDREN.

◆ setProperty() [4/6]

int32_t com::avpkit::core::Property::setProperty ( void *  context,
const char *  name,
int64_t  value 
)
static

Looks up the property 'name' in 'context' and sets the value of the property to 'value'.

Parameters
contextAVClass to search for option in.
namename of option
valueValue of option
Returns
>= 0 on success; <0 on error.

Definition at line 518 of file Property.cpp.

519  {
520  int32_t retval = 0;
521  try
522  {
523  if (!aContext)
524  throw std::runtime_error("no context passed in");
525 
526  if (!aName || !*aName)
527  throw std::runtime_error("empty property name passed to setProperty");
528 
529  retval = av_opt_set_int(aContext, aName, value, PROPERTY_SEARCH_CHILDREN);
530  }
531  catch (std::exception &e)
532  {
533  VS_LOG_DEBUG("Error: %s", e.what());
534  retval = -1;
535  }
536  return retval;
537  }

References com::avpkit::core::IProperty::PROPERTY_SEARCH_CHILDREN.

◆ setProperty() [5/6]

int32_t com::avpkit::core::Property::setProperty ( void *  context,
const char *  name,
IRational value 
)
static

Looks up the property 'name' in 'context' and sets the value of the property to 'value'.

Parameters
contextAVClass to search for option in.
namename of option
valueValue of option
Returns
>= 0 on success; <0 on error.

Definition at line 546 of file Property.cpp.

547  {
548  int32_t retval = 0;
549  try
550  {
551  if (!aContext)
552  throw std::runtime_error("no context passed in");
553 
554  if (!aName || !*aName)
555  throw std::runtime_error("empty property name passed to setProperty");
556 
557  if (!value)
558  throw std::runtime_error("no rational value passed in");
559 
560  AVRational rational;
561  rational.num = value->getNumerator();
562  rational.den = value->getDenominator();
563  retval = av_opt_set_q(aContext, aName, rational, PROPERTY_SEARCH_CHILDREN);
564  }
565  catch (std::exception &e)
566  {
567  VS_LOG_DEBUG("Error: %s", e.what());
568  retval = -1;
569  }
570  return retval;
571  }

References com::avpkit::core::IRational::getDenominator(), com::avpkit::core::IRational::getNumerator(), and com::avpkit::core::IProperty::PROPERTY_SEARCH_CHILDREN.

◆ setProperty() [6/6]

int32_t com::avpkit::core::Property::setProperty ( void *  context,
IMetaData valuesToSet,
IMetaData valuesNotFound 
)
static

Sets all properties in valuesToSet on object context.

Parameters
contextAVClass context to set options on
valuesToSetThe set of key-value pairs to try to set
valuesNotFoundIf non null will contain all key-values pairs in valuesToSet that were not found in context.
Returns
0 on success; <0 on failure
Since
5.0

Definition at line 574 of file Property.cpp.

575  {
576  int32_t retval =-1;
577  AVDictionary *tmp = 0;
578  MetaData* valuesToSet = dynamic_cast<MetaData*>(aValuesToSet);
579  MetaData* valuesNotFound = dynamic_cast<MetaData*>(aValuesNotFound);
580  AVDictionary *orig = valuesToSet ? valuesToSet->getDictionary() : 0;
581 
582  try {
583  if (!aContext)
584  throw std::runtime_error("no context passed in");
585 
586  if (orig)
587  av_dict_copy(&tmp, orig, 0);
588 
589  // try setting the values.
590  retval = av_opt_set_dict(aContext, &tmp);
591  if (retval < 0)
592  throw std::runtime_error("failed to set options on context");
593 
594  if (valuesNotFound)
595  retval = valuesNotFound->copy(tmp);
596  av_dict_free(&tmp);
597  retval = 0;
598  } catch (std::exception &e) {
599  av_dict_free(&tmp);
600  retval = -1;
601  }
602  return retval;
603  }

References com::avpkit::core::MetaData::copy(), and com::avpkit::core::MetaData::getDictionary().


The documentation for this class was generated from the following files: