AVPKit
com::avpkit::core::VideoResampler Class Reference
Inheritance diagram for com::avpkit::core::VideoResampler:
Collaboration diagram for com::avpkit::core::VideoResampler:

Public Member Functions

virtual int32_t getInputWidth ()
 Get the width in pixels we expect on the input frame to the resampler. More...
 
virtual int32_t getInputHeight ()
 Get the height in pixels we expect on the input frame to the resampler. More...
 
virtual IPixelFormat::Type getInputPixelFormat ()
 Get the input pixel format. More...
 
virtual int32_t getOutputWidth ()
 Get the output width, in pixels. More...
 
virtual int32_t getOutputHeight ()
 Get the output height, in pixels. More...
 
virtual IPixelFormat::Type getOutputPixelFormat ()
 Get the output pixel format. More...
 
virtual int32_t resample (IVideoPicture *pOutFrame, IVideoPicture *pInFrame)
 Resample in to out based on the resampler parameters. More...
 
virtual int32_t getNumProperties ()
 Returns the total number of settable properties on this object. More...
 
virtual IPropertygetPropertyMetaData (int32_t propertyNo)
 Returns the name of the numbered property. More...
 
virtual IPropertygetPropertyMetaData (const char *name)
 Returns the name of the numbered property. More...
 
virtual int32_t setProperty (const char *name, const char *value)
 Sets a property on this Object. More...
 
virtual int32_t setProperty (const char *name, double value)
 Looks up the property 'name' and sets the value of the property to 'value'. More...
 
virtual int32_t setProperty (const char *name, int64_t value)
 Looks up the property 'name' and sets the value of the property to 'value'. More...
 
virtual int32_t setProperty (const char *name, bool value)
 Looks up the property 'name' and sets the value of the property to 'value'. More...
 
virtual int32_t setProperty (const char *name, IRational *value)
 Looks up the property 'name' and sets the value of the property to 'value'. More...
 
virtual char * getPropertyAsString (const char *name)
 Gets a property on this Object. More...
 
virtual double getPropertyAsDouble (const char *name)
 Gets the value of this property, and returns as a double;. More...
 
virtual int64_t getPropertyAsLong (const char *name)
 Gets the value of this property, and returns as an long;. More...
 
virtual IRationalgetPropertyAsRational (const char *name)
 Gets the value of this property, and returns as an IRational;. More...
 
virtual bool getPropertyAsBoolean (const char *name)
 Gets the value of this property, and returns as a boolean. More...
 
virtual int32_t setProperty (IMetaData *valuesToSet, IMetaData *valuesNotFound)
 
- 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 VideoResamplermake (int32_t outputWidth, int32_t outputHeight, IPixelFormat::Type outputFmt, int32_t inputWidth, int32_t inputHeight, IPixelFormat::Type inputFmt)
 
- Static Public Member Functions inherited from com::avpkit::core::IVideoResampler
static IVideoResamplermake (int32_t outputWidth, int32_t outputHeight, IPixelFormat::Type outputFmt, int32_t inputWidth, int32_t inputHeight, IPixelFormat::Type inputFmt)
 Get a new video resampler. More...
 
static bool isSupported (Feature feature)
 Returns true if the asked for feature is supported. More...
 

Additional Inherited Members

- Public Types inherited from com::avpkit::core::IVideoResampler
enum  Feature { FEATURE_IMAGERESCALING , FEATURE_COLORSPACECONVERSION }
 Features that the VideoResampler may optionally support.
 
- 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

Definition at line 36 of file VideoResampler.h.

Member Function Documentation

◆ getInputHeight()

int32_t com::avpkit::core::VideoResampler::getInputHeight ( )
virtual

Get the height in pixels we expect on the input frame to the resampler.

Returns
The height we expect on the input frame to the resampler.

Implements com::avpkit::core::IVideoResampler.

Definition at line 64 of file VideoResampler.cpp.

65  {
66  return mIHeight;
67  }

◆ getInputPixelFormat()

IPixelFormat::Type com::avpkit::core::VideoResampler::getInputPixelFormat ( )
virtual

Get the input pixel format.

Returns
The pixel format we expect on the input frame to the resampler.

Implements com::avpkit::core::IVideoResampler.

Definition at line 88 of file VideoResampler.cpp.

89  {
90  return mIPixelFmt;
91  }

◆ getInputWidth()

int32_t com::avpkit::core::VideoResampler::getInputWidth ( )
virtual

Get the width in pixels we expect on the input frame to the resampler.

Returns
The width we expect on the input frame to the resampler.

Implements com::avpkit::core::IVideoResampler.

Definition at line 70 of file VideoResampler.cpp.

71  {
72  return mIWidth;
73  }

◆ getNumProperties()

int32_t com::avpkit::core::VideoResampler::getNumProperties ( )
virtual

Returns the total number of settable properties on this object.

Returns
total number of options (not including constant definitions)

Implements com::avpkit::core::IVideoResampler.

Definition at line 298 of file VideoResampler.cpp.

299  {
300  return Property::getNumProperties(mContext);
301  }
static int32_t getNumProperties(void *context)
For internal use.
Definition: Property.cpp:114

◆ getOutputHeight()

int32_t com::avpkit::core::VideoResampler::getOutputHeight ( )
virtual

Get the output height, in pixels.

Returns
The height we will resample the output frame to

Implements com::avpkit::core::IVideoResampler.

Definition at line 76 of file VideoResampler.cpp.

77  {
78  return mOHeight;
79  }

◆ getOutputPixelFormat()

IPixelFormat::Type com::avpkit::core::VideoResampler::getOutputPixelFormat ( )
virtual

Get the output pixel format.

Returns
The pixel format we will resample the output frame to

Implements com::avpkit::core::IVideoResampler.

Definition at line 94 of file VideoResampler.cpp.

95  {
96  return mOPixelFmt;
97  }

◆ getOutputWidth()

int32_t com::avpkit::core::VideoResampler::getOutputWidth ( )
virtual

Get the output width, in pixels.

Returns
The width we will resample the output frame to

Implements com::avpkit::core::IVideoResampler.

Definition at line 82 of file VideoResampler.cpp.

83  {
84  return mOWidth;
85  }

◆ getPropertyAsBoolean()

bool com::avpkit::core::VideoResampler::getPropertyAsBoolean ( const char *  name)
virtual

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

Parameters
namename of option
Returns
boolean value of property, or false on error.

Implements com::avpkit::core::IVideoResampler.

Definition at line 379 of file VideoResampler.cpp.

380  {
381  return Property::getPropertyAsBoolean(mContext, aName);
382  }
static bool getPropertyAsBoolean(void *context, const char *name)
Gets the value of this property, and returns as a boolean.
Definition: Property.cpp:491

◆ getPropertyAsDouble()

double com::avpkit::core::VideoResampler::getPropertyAsDouble ( const char *  name)
virtual

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

Parameters
namename of option
Returns
double value of property, or 0 on error.

Implements com::avpkit::core::IVideoResampler.

Definition at line 361 of file VideoResampler.cpp.

362  {
363  return Property::getPropertyAsDouble(mContext, aName);
364  }
static double getPropertyAsDouble(void *context, const char *name)
Gets the value of this property, and returns as a double;.
Definition: Property.cpp:422

◆ getPropertyAsLong()

int64_t com::avpkit::core::VideoResampler::getPropertyAsLong ( const char *  name)
virtual

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

Parameters
namename of option
Returns
long value of property, or 0 on error.

Implements com::avpkit::core::IVideoResampler.

Definition at line 367 of file VideoResampler.cpp.

368  {
369  return Property::getPropertyAsLong(mContext, aName);
370  }
static int64_t getPropertyAsLong(void *context, const char *name)
Gets the value of this property, and returns as an long;.
Definition: Property.cpp:446

◆ getPropertyAsRational()

IRational * com::avpkit::core::VideoResampler::getPropertyAsRational ( const char *  name)
virtual

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

Parameters
namename of option
Returns
long value of property, or 0 on error.

Implements com::avpkit::core::IVideoResampler.

Definition at line 373 of file VideoResampler.cpp.

374  {
375  return Property::getPropertyAsRational(mContext, aName);
376  }
static IRational * getPropertyAsRational(void *context, const char *name)
Gets the value of this property, and returns as an IRational;.
Definition: Property.cpp:467

◆ getPropertyAsString()

char * com::avpkit::core::VideoResampler::getPropertyAsString ( const char *  name)
virtual

Gets a property on this Object.

Note for C++ callers; you must free the returned array with delete[] in order to avoid a memory leak. Other language folks need not worry.

Parameters
nameproperty name
Returns
an string copy of the option value, or null if the option doesn't exist.

Implements com::avpkit::core::IVideoResampler.

Definition at line 355 of file VideoResampler.cpp.

356  {
357  return Property::getPropertyAsString(mContext, aName);
358  }
static char * getPropertyAsString(void *context, const char *name)
Gets the value of this property, and returns as a new[]ed string.
Definition: Property.cpp:238

◆ getPropertyMetaData() [1/2]

IProperty * com::avpkit::core::VideoResampler::getPropertyMetaData ( const char *  name)
virtual

Returns the name of the numbered property.

Parameters
nameThe property name.
Returns
an IProperty value for this properties meta-data

Implements com::avpkit::core::IVideoResampler.

Definition at line 310 of file VideoResampler.cpp.

311  {
312  return Property::getPropertyMetaData(mContext, name);
313  }
static IProperty * getPropertyMetaData(void *context, int32_t propertyNo)
Returns the metadata for the numbered property.
Definition: Property.cpp:133

◆ getPropertyMetaData() [2/2]

IProperty * com::avpkit::core::VideoResampler::getPropertyMetaData ( int32_t  propertyNo)
virtual

Returns the name of the numbered property.

Parameters
propertyNoThe property number in the options list.
Returns
an IProperty value for this properties meta-data

Implements com::avpkit::core::IVideoResampler.

Definition at line 304 of file VideoResampler.cpp.

305  {
306  return Property::getPropertyMetaData(mContext, propertyNo);
307  }

◆ resample()

int32_t com::avpkit::core::VideoResampler::resample ( IVideoPicture outVideoPicture,
IVideoPicture inVideoPicture 
)
virtual

Resample in to out based on the resampler parameters.

Resamples the in picture based on the parameters set when this resampler was constructed.

Parameters
outVideoPictureThe picture we'll resample to. Check IVideoPicture#isComplete() after the call.
inVideoPictureThe picture we'll resample from.
Returns
>= 0 on success; <0 on error.

Implements com::avpkit::core::IVideoResampler.

Definition at line 100 of file VideoResampler.cpp.

101  {
102  int32_t retval = -1;
103  VideoPicture* outFrame = static_cast<VideoPicture*>(pOutFrame);
104  VideoPicture* inFrame = static_cast<VideoPicture*>(pInFrame);
105  try
106  {
107  if (!outFrame)
108  throw std::invalid_argument("invalid output frame");
109  if (outFrame->getHeight() != mOHeight)
110  throw std::runtime_error("output frame height does not match expected value");
111  if (outFrame->getWidth() != mOWidth)
112  throw std::runtime_error("output frame width does not match expected value");
113  if (outFrame->getPixelType() != mOPixelFmt)
114  throw std::runtime_error("output frame pixel format does not match expected value");
115 
116 
117  if (!inFrame)
118  throw std::invalid_argument("invalid input frame");
119 
120  if (inFrame->getHeight() != mIHeight)
121  throw std::runtime_error("input frame height does not match expected value");
122  if (inFrame->getWidth() != mIWidth)
123  throw std::runtime_error("input frame width does not match expected value");
124  if (inFrame->getPixelType() != mIPixelFmt)
125  throw std::runtime_error("input frame pixel format does not match expected value");
126  if (!inFrame->isComplete())
127  throw std::runtime_error("incoming frame doesn't have complete data");
128 
129  // Allocate our output frame.
130  outFrame->setComplete(false, mOPixelFmt, mOWidth, mOHeight,
131  inFrame->getPts());
132  AVFrame *outAVFrame = outFrame->getAVFrame();
133 
134  // Get our input frame; since it's complete() we can pass anything
135  // for the argument
136  AVFrame *inAVFrame = inFrame->getAVFrame();
137 
138  /*
139  VS_LOG_DEBUG("%dx%d(%d:%d)=>%dx%d(%d:%d)",
140  inFrame->getWidth(), inFrame->getHeight(), inFrame->getPixelType(), inAVFrame->linesize[0],
141  outFrame->getWidth(), outFrame->getHeight(), outFrame->getPixelType(), outAVFrame->linesize[0]);
142 
143  memset(outAVFrame->data[0], 64*3-1, outAVFrame->linesize[0]);
144  */
145  // And do the conversion; works around FFmpeg checkin r30306
146  const uint8_t* srcFrame[4] = {
147  inAVFrame->data[0],
148  inAVFrame->data[1],
149  inAVFrame->data[2],
150  inAVFrame->data[3],
151  };
152  retval = sws_scale(mContext, srcFrame, inAVFrame->linesize, 0,
153  mIHeight, outAVFrame->data, outAVFrame->linesize);
154 
155  // and go home happy.
156  {
157  outFrame->setQuality(inFrame->getQuality());
158  outFrame->setComplete(retval >= 0,mOPixelFmt, mOWidth, mOHeight,
159  inFrame->getPts());
160  }
161  }
162  catch (std::bad_alloc& e)
163  {
164  throw e;
165  }
166  catch (std::exception& e)
167  {
168  VS_LOG_DEBUG("error: %s", e.what());
169  retval = -1;
170  }
171  return retval;
172  }

References com::avpkit::core::VideoPicture::getAVFrame(), com::avpkit::core::VideoPicture::getHeight(), com::avpkit::core::VideoPicture::getPixelType(), com::avpkit::core::VideoPicture::getPts(), com::avpkit::core::VideoPicture::getQuality(), com::avpkit::core::VideoPicture::getWidth(), com::avpkit::core::VideoPicture::isComplete(), com::avpkit::core::VideoPicture::setComplete(), and com::avpkit::core::VideoPicture::setQuality().

◆ setProperty() [1/5]

int32_t com::avpkit::core::VideoResampler::setProperty ( const char *  name,
bool  value 
)
virtual

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

Parameters
namename of option
valueValue of option
Returns
>= 0 on success; <0 on error.

Implements com::avpkit::core::IVideoResampler.

Definition at line 341 of file VideoResampler.cpp.

342  {
343  return Property::setProperty(mContext, aName, aValue);
344  }
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

◆ setProperty() [2/5]

int32_t com::avpkit::core::VideoResampler::setProperty ( const char *  name,
const char *  value 
)
virtual

Sets a property on this Object.

All AVOptions supported by the underlying AVClass are supported.

Parameters
nameThe property name. For example "b" for bit-rate.
valueThe value of the property.
Returns
>= 0 if the property was successfully set; <0 on error

Implements com::avpkit::core::IVideoResampler.

Definition at line 323 of file VideoResampler.cpp.

324  {
325  return Property::setProperty(mContext, aName, aValue);
326  }

◆ setProperty() [3/5]

int32_t com::avpkit::core::VideoResampler::setProperty ( const char *  name,
double  value 
)
virtual

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

Parameters
namename of option
valueValue of option
Returns
>= 0 on success; <0 on error.

Implements com::avpkit::core::IVideoResampler.

Definition at line 329 of file VideoResampler.cpp.

330  {
331  return Property::setProperty(mContext, aName, aValue);
332  }

◆ setProperty() [4/5]

int32_t com::avpkit::core::VideoResampler::setProperty ( const char *  name,
int64_t  value 
)
virtual

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

Parameters
namename of option
valueValue of option
Returns
>= 0 on success; <0 on error.

Implements com::avpkit::core::IVideoResampler.

Definition at line 335 of file VideoResampler.cpp.

336  {
337  return Property::setProperty(mContext, aName, aValue);
338  }

◆ setProperty() [5/5]

int32_t com::avpkit::core::VideoResampler::setProperty ( const char *  name,
IRational value 
)
virtual

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

Parameters
namename of option
valueValue of option
Returns
>= 0 on success; <0 on error.

Implements com::avpkit::core::IVideoResampler.

Definition at line 348 of file VideoResampler.cpp.

349  {
350  return Property::setProperty(mContext, aName, aValue);
351  }

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