|
AVPKit
|
This class wraps represents a Rational number for the AVPKit. More...
#include <IRational.h>


Public Types | |
| enum | Rounding { ROUND_ZERO = 0 , ROUND_INF = 1 , ROUND_DOWN = 2 , ROUND_UP = 3 , ROUND_NEAR_INF = 5 } |
| typedef enum com::avpkit::core::IRational::Rounding | Rounding |
Public Member Functions | |
| virtual int32_t | getNumerator ()=0 |
| Get the numerator for this rational. More... | |
| virtual int32_t | getDenominator ()=0 |
| Get the denominator for this rational. More... | |
| virtual IRational * | copy ()=0 |
| Creates a new IRational object by copying (by value) this object. More... | |
| virtual int32_t | compareTo (IRational *other)=0 |
| Compare a rational to this rational. More... | |
| virtual double | getDouble ()=0 |
| Rational to double conversion. More... | |
| virtual int32_t | reduce (int64_t num, int64_t den, int64_t max)=0 |
| Reduce a fraction to it's lowest common denominators. More... | |
| virtual IRational * | multiply (IRational *arg)=0 |
| Multiplies this number by arg. More... | |
| virtual IRational * | divide (IRational *arg)=0 |
| Divides this rational by arg. More... | |
| virtual IRational * | subtract (IRational *arg)=0 |
| Subtracts arg from this rational. More... | |
| virtual IRational * | add (IRational *arg)=0 |
| Adds arg to this rational. More... | |
| virtual int64_t | rescale (int64_t origValue, IRational *origBase)=0 |
| Takes a value scaled in increments of origBase and gives the equivalent value scaled in terms of this Rational. More... | |
| virtual int64_t | rescale (int64_t origValue, IRational *origBase, Rounding rounding)=0 |
| Takes a value scaled in increments of origBase and gives the equivalent value scaled in terms of this Rational. More... | |
| virtual void | setNumerator (int32_t value)=0 |
| Sets the numerator on this object. More... | |
| virtual void | setDenominator (int32_t value)=0 |
| Sets the denominator on this object. More... | |
| virtual void | setValue (double value)=0 |
| Sets the numerator and denominator on this object by reducing the double to the closest integer numerator and denominator. More... | |
| virtual double | getValue ()=0 |
| An alias for getDouble() but matching JavaBean conventions. More... | |
| virtual bool | isFinalized ()=0 |
| Returns true if init() has been called and this object is now considered finalized and immutable. More... | |
| virtual void | init ()=0 |
| Marks this object as finalized and immutable. 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 RefCounted * | copyReference () |
| 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 int32_t | sCompareTo (IRational *a, IRational *b) |
| Compare two rationals. More... | |
| static int32_t | sReduce (IRational *dst, int64_t num, int64_t den, int64_t max) |
| Reduce a fraction to it's lowest common denominators. More... | |
| static IRational * | sMultiply (IRational *a, IRational *b) |
| Multiples a by b. More... | |
| static IRational * | sDivide (IRational *a, IRational *b) |
| Divides a by b. More... | |
| static IRational * | sSubtract (IRational *a, IRational *b) |
| Subtracts a from b. More... | |
| static IRational * | sAdd (IRational *a, IRational *b) |
| Adds a to b. More... | |
| static int64_t | sRescale (int64_t origValue, IRational *origBase, IRational *newBase) |
| Takes a value scaled in increments of origBase and gives the equivalent value scaled in terms of this Rational. More... | |
| static IRational * | make () |
| Get a new rational that will be set to 0/0. More... | |
| static IRational * | make (double d) |
| Converts a double precision floating point number to a rational. More... | |
| static IRational * | make (IRational *src) |
| Creates deep copy of a Rational from another Rational. More... | |
| static IRational * | make (int32_t num, int32_t den) |
| Create a rational from a numerator and denominator. More... | |
| static int64_t | sRescale (int64_t origValue, IRational *origBase, IRational *newBase, Rounding rounding) |
| Takes a value scaled in increments of origBase and gives the equivalent value scaled in terms of this Rational. More... | |
| static int64_t | rescale (int64_t srcValue, int32_t dstNumerator, int32_t dstDenominator, int32_t srcNumerator, int32_t srcDenominator, Rounding rounding) |
| Rescales a long value to another long value. More... | |
Additional Inherited Members | |
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 | |
| AtomicInteger * | mRefCount |
| This is the internal reference count, represented as an AtomicInteger to make sure it is thread safe. | |
| void * | mAllocator |
| Not part of public API. | |
This class wraps represents a Rational number for the AVPKit.
Video formats often use rational numbers, and converting between them willy nilly can lead to rounding errors, and eventually, out of sync problems. Therefore we use IRational objects to pass around Rational Numbers and avoid conversion until the very last moment.
Note: There are some static convenience methods in this class that start with s*. They start with s (as opposed to overloading methods (e.g. sAdd(...) vs. add(...)).
Definition at line 42 of file IRational.h.
Adds arg to this rational.
| arg | The amount to add to this. |
Implemented in com::avpkit::core::Rational.
Referenced by sAdd().
|
pure virtual |
Compare a rational to this rational.
| other | second rational |
Implemented in com::avpkit::core::Rational.
Referenced by sCompareTo().
|
pure virtual |
Creates a new IRational object by copying (by value) this object.
Implemented in com::avpkit::core::Rational.
Divides this rational by arg.
| arg | The divisor to use. |
Implemented in com::avpkit::core::Rational.
Referenced by sDivide().
|
pure virtual |
Get the denominator for this rational.
Implemented in com::avpkit::core::Rational.
Referenced by com::avpkit::core::StreamCoder::setFrameRate(), com::avpkit::core::Property::setProperty(), com::avpkit::core::MediaFilter::setRationalProperty(), com::avpkit::core::Stream::setSampleAspectRatio(), and com::avpkit::core::StreamCoder::setTimeBase().
|
pure virtual |
|
pure virtual |
Get the numerator for this rational.
Implemented in com::avpkit::core::Rational.
Referenced by com::avpkit::core::StreamCoder::setFrameRate(), com::avpkit::core::Property::setProperty(), com::avpkit::core::MediaFilter::setRationalProperty(), com::avpkit::core::Stream::setSampleAspectRatio(), and com::avpkit::core::StreamCoder::setTimeBase().
|
pure virtual |
An alias for getDouble() but matching JavaBean conventions.
Implemented in com::avpkit::core::Rational.
|
pure virtual |
Marks this object as finalized and immutable.
Any setters called after the first init() call will be ignored.
Most make methods will call this method automatically, with the exception of the blank factory method make().
Implemented in com::avpkit::core::Rational.
|
pure virtual |
Returns true if init() has been called and this object is now considered finalized and immutable.
Implemented in com::avpkit::core::Rational.
|
static |
Get a new rational that will be set to 0/0.
The rational will not have init() called and hence will be modifiable by setValue(double) until init() is called.
Definition at line 79 of file IRational.cpp.
References com::avpkit::core::Global::init().
Referenced by com::avpkit::core::Rational::add(), com::avpkit::core::Rational::copy(), com::avpkit::core::Rational::divide(), com::avpkit::core::BufferSink::getFrameRate(), com::avpkit::core::Stream::getFrameRate(), com::avpkit::core::Property::getPropertyAsRational(), com::avpkit::core::Stream::getSampleAspectRatio(), com::avpkit::core::Codec::getSupportedVideoFrameRate(), com::avpkit::core::BufferSink::getTimeBase(), com::avpkit::core::Stream::getTimeBase(), make(), com::avpkit::core::Rational::make(), com::avpkit::core::Rational::multiply(), and com::avpkit::core::Rational::subtract().
|
static |
Converts a double precision floating point number to a rational.
| d | double to convert |
Definition at line 86 of file IRational.cpp.
References com::avpkit::core::Global::init(), and make().
|
static |
Create a rational from a numerator and denominator.
We will always reduce this to the lowest num/den pair we can, but never having den exceed what was passed in.
Definition at line 106 of file IRational.cpp.
References com::avpkit::core::Global::init(), and make().
Creates deep copy of a Rational from another Rational.
| src | The source Rational to copy. |
Definition at line 93 of file IRational.cpp.
References com::avpkit::core::Global::init(), and make().
Multiplies this number by arg.
| arg | number to mulitply by. |
Implemented in com::avpkit::core::Rational.
Referenced by sMultiply().
|
pure virtual |
Reduce a fraction to it's lowest common denominators.
This is useful for framerate calculations.
| num | the src numerator. |
| den | the src denominator. |
| max | the maximum allowed for nom & den in the reduced fraction. |
Implemented in com::avpkit::core::Rational.
Referenced by sReduce().
|
pure virtual |
Takes a value scaled in increments of origBase and gives the equivalent value scaled in terms of this Rational.
| origValue | The original int64_t value you care about. |
| origBase | The original base Rational that origValue is scaled with. |
Implemented in com::avpkit::core::Rational.
Referenced by com::avpkit::core::BufferSink::fillAudioSamples(), com::avpkit::core::BufferSink::fillVideoPicture(), and sRescale().
|
pure virtual |
Takes a value scaled in increments of origBase and gives the equivalent value scaled in terms of this Rational.
| origValue | The original int64_t value you care about. |
| origBase | The original base Rational that origValue is scaled with. |
| rounding | How you want rounding to occur |
Implemented in com::avpkit::core::Rational.
|
static |
Rescales a long value to another long value.
This method doesn't use IRational values, but instead uses numerators and denominators passed in by the caller. It will not result in any memory allocations.
| srcValue | The value to rescale. |
| dstNumerator | The numerator of the units you want to scale to. Must be non-zero. |
| dstDenominator | The denominator of the units you want to scale to. Must be non-zero. |
| srcNumerator | The numerator of the units srcValue is expressed in. Must be non-zero. |
| srcDenominator | The denominator of the units srcValue is expressed in. Must be non-zero. |
| rounding | How you want rounding to occur |
Definition at line 123 of file IRational.cpp.
References com::avpkit::core::Rational::rescale().
Adds a to b.
| a | The first number. @parma b The second number. |
Definition at line 61 of file IRational.cpp.
References add().
Compare two rationals.
| a | the first rational |
| b | the second rational |
Definition at line 36 of file IRational.cpp.
References compareTo().
Divides a by b.
| a | The first number. @parma b The second number. |
Definition at line 49 of file IRational.cpp.
References divide().
|
pure virtual |
Sets the denominator on this object.
If isFinalized is true, then this method is ignored.
Implemented in com::avpkit::core::Rational.
|
pure virtual |
Sets the numerator on this object.
If isFinalized is true, then this method is ignored.
Implemented in com::avpkit::core::Rational.
|
pure virtual |
Sets the numerator and denominator on this object by reducing the double to the closest integer numerator and denominator.
If isFinalized is true, then this method is ignored.
Implemented in com::avpkit::core::Rational.
Multiples a by b.
| a | the first number |
| b | the second number. |
Definition at line 67 of file IRational.cpp.
References multiply().
|
static |
Reduce a fraction to it's lowest common denominators.
This is useful for framerate calculations.
| dst | The destination rational |
| num | the src numerator. |
| den | the src denominator. |
| max | the maximum allowed for nom & den in the reduced fraction. |
Definition at line 42 of file IRational.cpp.
References reduce().
|
static |
Takes a value scaled in increments of origBase and gives the equivalent value scaled in terms of this Rational.
| origValue | The original int64_t value you care about. |
| origBase | The original base Rational that origValue is scaled with. |
| newBase | The rational you want to rescale origValue into. |
Definition at line 73 of file IRational.cpp.
References rescale().
|
static |
Takes a value scaled in increments of origBase and gives the equivalent value scaled in terms of this Rational.
| origValue | The original int64_t value you care about. |
| origBase | The original base Rational that origValue is scaled with. |
| newBase | The rational you want to rescale origValue into. |
| rounding | How you want rounding to occur |
Definition at line 113 of file IRational.cpp.
References rescale().
Subtracts a from b.
| a | The first number. @parma b The second number. |
Definition at line 55 of file IRational.cpp.
References subtract().
Subtracts arg from this rational.
| arg | The amount to subtract from this. |
Implemented in com::avpkit::core::Rational.
Referenced by sSubtract().