[FFmpeg-devel] [PATCH] lavu/rational: add syntactic sugar.

Clément Bœsch u at pkh.me
Tue Dec 31 17:28:51 CET 2013


On Tue, Dec 31, 2013 at 05:24:21PM +0100, Nicolas George wrote:
> Add a function to create a rational
> and macros for common values.
> 
> Signed-off-by: Nicolas George <george at nsup.org>
> ---
>  libavutil/rational.h |   16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/libavutil/rational.h b/libavutil/rational.h
> index b9800ee..363d18c 100644
> --- a/libavutil/rational.h
> +++ b/libavutil/rational.h
> @@ -46,6 +46,22 @@ typedef struct AVRational{
>  } AVRational;
>  
>  /**
> + * Create a rational.
> + * Useful for compilers that do not support compound literals.
> + * @note  The return value is not reduced.
> + */
> +static inline AVRational av_make_q(int num, int den)
> +{
> +    AVRational r = { num, den };
> +    return r;
> +}
> +
> +#define AV_ZERO_Q         (av_make_q(0, 1))
> +#define AV_ONE_Q          (av_make_q(1, 1))

> +#define AV_UNDEF_Q        (av_make_q(1, 0))
> +#define AV_INVALID_Q      (av_make_q(0, 0))

I would switch those two. "undef" sounds like "all fields are 0 so it's
just not set/defined". 1/0 sounds like an explicit division by zero, so
invalid on purpose.

[...]

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20131231/ae824b81/attachment.asc>


More information about the ffmpeg-devel mailing list