[FFmpeg-cvslog] Merge commit '3b08d9d932eef09403074d5af31e10d8011e840b'

Derek Buitenhuis git at videolan.org
Thu Apr 21 17:50:19 CEST 2016


ffmpeg | branch: master | Derek Buitenhuis <derek.buitenhuis at gmail.com> | Thu Apr 21 16:40:10 2016 +0100| [5f587b1daf90a8c0bf4f2eb5c13b4022252ec498] | committer: Derek Buitenhuis

Merge commit '3b08d9d932eef09403074d5af31e10d8011e840b'

* commit '3b08d9d932eef09403074d5af31e10d8011e840b':
  testprogs: K&R formatting cosmetics

Merged-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5f587b1daf90a8c0bf4f2eb5c13b4022252ec498
---

 libavcodec/iirfilter.c  |  122 +++++++++--------
 libavcodec/rangecoder.c |    2 +-
 libavutil/aes.c         |   39 +++---
 libavutil/crc.c         |   19 +--
 libavutil/des.c         |  273 ++++++++++++++++++------------------
 libavutil/lls.c         |    2 +-
 libavutil/md5.c         |   57 +++++---
 libavutil/opt.c         |  349 ++++++++++++++++++++++++++++-------------------
 8 files changed, 474 insertions(+), 389 deletions(-)

diff --git a/libavcodec/iirfilter.c b/libavcodec/iirfilter.c
index cb5871c..474f52f 100644
--- a/libavcodec/iirfilter.c
+++ b/libavcodec/iirfilter.c
@@ -24,27 +24,29 @@
  * different IIR filters implementation
  */
 
-#include "iirfilter.h"
 #include <math.h>
+
 #include "libavutil/attributes.h"
 #include "libavutil/common.h"
 
+#include "iirfilter.h"
+
 /**
  * IIR filter global parameters
  */
-typedef struct FFIIRFilterCoeffs{
+typedef struct FFIIRFilterCoeffs {
     int   order;
     float gain;
     int   *cx;
     float *cy;
-}FFIIRFilterCoeffs;
+} FFIIRFilterCoeffs;
 
 /**
  * IIR filter state
  */
-typedef struct FFIIRFilterState{
+typedef struct FFIIRFilterState {
     float x[1];
-}FFIIRFilterState;
+} FFIIRFilterState;
 
 /// maximum supported filter order
 #define MAXORDER 30
@@ -61,51 +63,50 @@ static av_cold int butterworth_init_coeffs(void *avc,
 
     if (filt_mode != FF_FILTER_MODE_LOWPASS) {
         av_log(avc, AV_LOG_ERROR, "Butterworth filter currently only supports "
-               "low-pass filter mode\n");
+                                  "low-pass filter mode\n");
         return -1;
     }
     if (order & 1) {
         av_log(avc, AV_LOG_ERROR, "Butterworth filter currently only supports "
-               "even filter orders\n");
+                                  "even filter orders\n");
         return -1;
     }
 
     wa = 2 * tan(M_PI * 0.5 * cutoff_ratio);
 
     c->cx[0] = 1;
-    for(i = 1; i < (order >> 1) + 1; i++)
+    for (i = 1; i < (order >> 1) + 1; i++)
         c->cx[i] = c->cx[i - 1] * (order - i + 1LL) / i;
 
     p[0][0] = 1.0;
     p[0][1] = 0.0;
-    for(i = 1; i <= order; i++)
+    for (i = 1; i <= order; i++)
         p[i][0] = p[i][1] = 0.0;
-    for(i = 0; i < order; i++){
+    for (i = 0; i < order; i++) {
         double zp[2];
         double th = (i + (order >> 1) + 0.5) * M_PI / order;
         double a_re, a_im, c_re, c_im;
         zp[0] = cos(th) * wa;
         zp[1] = sin(th) * wa;
-        a_re = zp[0] + 2.0;
-        c_re = zp[0] - 2.0;
-        a_im =
-        c_im = zp[1];
+        a_re  = zp[0] + 2.0;
+        c_re  = zp[0] - 2.0;
+        a_im  =
+        c_im  = zp[1];
         zp[0] = (a_re * c_re + a_im * c_im) / (c_re * c_re + c_im * c_im);
         zp[1] = (a_im * c_re - a_re * c_im) / (c_re * c_re + c_im * c_im);
 
-        for(j = order; j >= 1; j--)
-        {
-            a_re = p[j][0];
-            a_im = p[j][1];
-            p[j][0] = a_re*zp[0] - a_im*zp[1] + p[j-1][0];
-            p[j][1] = a_re*zp[1] + a_im*zp[0] + p[j-1][1];
+        for (j = order; j >= 1; j--) {
+            a_re    = p[j][0];
+            a_im    = p[j][1];
+            p[j][0] = a_re * zp[0] - a_im * zp[1] + p[j - 1][0];
+            p[j][1] = a_re * zp[1] + a_im * zp[0] + p[j - 1][1];
         }
-        a_re    = p[0][0]*zp[0] - p[0][1]*zp[1];
-        p[0][1] = p[0][0]*zp[1] + p[0][1]*zp[0];
+        a_re    = p[0][0] * zp[0] - p[0][1] * zp[1];
+        p[0][1] = p[0][0] * zp[1] + p[0][1] * zp[0];
         p[0][0] = a_re;
     }
     c->gain = p[order][0];
-    for(i = 0; i < order; i++){
+    for (i = 0; i < order; i++) {
         c->gain += p[i][0];
         c->cy[i] = (-p[i][0] * p[order][0] + -p[i][1] * p[order][1]) /
                    (p[order][0] * p[order][0] + p[order][1] * p[order][1]);
@@ -125,7 +126,7 @@ static av_cold int biquad_init_coeffs(void *avc, struct FFIIRFilterCoeffs *c,
     if (filt_mode != FF_FILTER_MODE_HIGHPASS &&
         filt_mode != FF_FILTER_MODE_LOWPASS) {
         av_log(avc, AV_LOG_ERROR, "Biquad filter currently only supports "
-               "high-pass and low-pass filter modes\n");
+                                  "high-pass and low-pass filter modes\n");
         return -1;
     }
     if (order != 2) {
@@ -158,11 +159,11 @@ static av_cold int biquad_init_coeffs(void *avc, struct FFIIRFilterCoeffs *c,
     return 0;
 }
 
-av_cold struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc,
-                                                enum IIRFilterType filt_type,
-                                                enum IIRFilterMode filt_mode,
-                                                int order, float cutoff_ratio,
-                                                float stopband, float ripple)
+av_cold struct FFIIRFilterCoeffs *ff_iir_filter_init_coeffs(void *avc,
+                                                            enum IIRFilterType filt_type,
+                                                            enum IIRFilterMode filt_mode,
+                                                            int order, float cutoff_ratio,
+                                                            float stopband, float ripple)
 {
     FFIIRFilterCoeffs *c;
     int ret = 0;
@@ -170,12 +171,12 @@ av_cold struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc,
     if (order <= 0 || order > MAXORDER || cutoff_ratio >= 1.0)
         return NULL;
 
-    FF_ALLOCZ_OR_GOTO(avc, c,     sizeof(FFIIRFilterCoeffs),
-                      init_fail);
-    FF_ALLOC_OR_GOTO (avc, c->cx, sizeof(c->cx[0]) * ((order >> 1) + 1),
-                      init_fail);
-    FF_ALLOC_OR_GOTO (avc, c->cy, sizeof(c->cy[0]) * order,
+    FF_ALLOCZ_OR_GOTO(avc, c, sizeof(FFIIRFilterCoeffs),
                       init_fail);
+    FF_ALLOC_OR_GOTO(avc, c->cx, sizeof(c->cx[0]) * ((order >> 1) + 1),
+                     init_fail);
+    FF_ALLOC_OR_GOTO(avc, c->cy, sizeof(c->cy[0]) * order,
+                     init_fail);
     c->order = order;
 
     switch (filt_type) {
@@ -200,9 +201,9 @@ init_fail:
     return NULL;
 }
 
-av_cold struct FFIIRFilterState* ff_iir_filter_init_state(int order)
+av_cold struct FFIIRFilterState *ff_iir_filter_init_state(int order)
 {
-    FFIIRFilterState* s = av_mallocz(sizeof(FFIIRFilterState) + sizeof(s->x[0]) * (order - 1));
+    FFIIRFilterState *s = av_mallocz(sizeof(FFIIRFilterState) + sizeof(s->x[0]) * (order - 1));
     return s;
 }
 
@@ -210,17 +211,19 @@ av_cold struct FFIIRFilterState* ff_iir_filter_init_state(int order)
 
 #define CONV_FLT(dest, source) dest = source;
 
-#define FILTER_BW_O4_1(i0, i1, i2, i3, fmt)         \
-    in = *src0 * c->gain                            \
-         + c->cy[0]*s->x[i0] + c->cy[1]*s->x[i1]    \
-         + c->cy[2]*s->x[i2] + c->cy[3]*s->x[i3];   \
-    res =  (s->x[i0] + in      )*1                  \
-         + (s->x[i1] + s->x[i3])*4                  \
-         +  s->x[i2]            *6;                 \
-    CONV_##fmt(*dst0, res)                          \
-    s->x[i0] = in;                                  \
-    src0 += sstep;                                  \
-    dst0 += dstep;
+#define FILTER_BW_O4_1(i0, i1, i2, i3, fmt)             \
+    in = *src0    * c->gain  +                          \
+         c->cy[0] * s->x[i0] +                          \
+         c->cy[1] * s->x[i1] +                          \
+         c->cy[2] * s->x[i2] +                          \
+         c->cy[3] * s->x[i3];                           \
+    res = (s->x[i0] + in)       * 1 +                   \
+          (s->x[i1] + s->x[i3]) * 4 +                   \
+           s->x[i2]             * 6;                    \
+    CONV_ ## fmt(*dst0, res)                            \
+    s->x[i0] = in;                                      \
+    src0    += sstep;                                   \
+    dst0    += dstep;
 
 #define FILTER_BW_O4(type, fmt) {           \
     int i;                                  \
@@ -243,17 +246,17 @@ av_cold struct FFIIRFilterState* ff_iir_filter_init_state(int order)
         int j;                                                              \
         float in, res;                                                      \
         in = *src0 * c->gain;                                               \
-        for(j = 0; j < c->order; j++)                                       \
+        for (j = 0; j < c->order; j++)                                      \
             in += c->cy[j] * s->x[j];                                       \
         res = s->x[0] + in + s->x[c->order >> 1] * c->cx[c->order >> 1];    \
-        for(j = 1; j < c->order >> 1; j++)                                  \
+        for (j = 1; j < c->order >> 1; j++)                                 \
             res += (s->x[j] + s->x[c->order - j]) * c->cx[j];               \
-        for(j = 0; j < c->order - 1; j++)                                   \
+        for (j = 0; j < c->order - 1; j++)                                  \
             s->x[j] = s->x[j + 1];                                          \
-        CONV_##fmt(*dst0, res)                                              \
+        CONV_ ## fmt(*dst0, res)                                            \
         s->x[c->order - 1] = in;                                            \
-        src0 += sstep;                                                      \
-        dst0 += dstep;                                                      \
+        src0              += sstep;                                         \
+        dst0              += dstep;                                         \
     }                                                                       \
 }
 
@@ -265,11 +268,11 @@ av_cold struct FFIIRFilterState* ff_iir_filter_init_state(int order)
         float in = *src0   * c->gain  +                                     \
                    s->x[0] * c->cy[0] +                                     \
                    s->x[1] * c->cy[1];                                      \
-        CONV_##fmt(*dst0, s->x[0] + in + s->x[1] * c->cx[1])                \
+        CONV_ ## fmt(*dst0, s->x[0] + in + s->x[1] * c->cx[1])              \
         s->x[0] = s->x[1];                                                  \
         s->x[1] = in;                                                       \
-        src0 += sstep;                                                      \
-        dst0 += dstep;                                                      \
+        src0   += sstep;                                                    \
+        dst0   += dstep;                                                    \
     }                                                                       \
 }
 
@@ -307,7 +310,7 @@ av_cold void ff_iir_filter_free_statep(struct FFIIRFilterState **state)
 av_cold void ff_iir_filter_free_coeffsp(struct FFIIRFilterCoeffs **coeffsp)
 {
     struct FFIIRFilterCoeffs *coeffs = *coeffsp;
-    if(coeffs){
+    if (coeffs) {
         av_freep(&coeffs->cx);
         av_freep(&coeffs->cy);
     }
@@ -339,9 +342,8 @@ int main(void)
                                         cutoff_coeff, 0.0, 0.0);
     fstate  = ff_iir_filter_init_state(FILT_ORDER);
 
-    for (i = 0; i < SIZE; i++) {
-        x[i] = lrint(0.75 * INT16_MAX * sin(0.5*M_PI*i*i/SIZE));
-    }
+    for (i = 0; i < SIZE; i++)
+        x[i] = lrint(0.75 * INT16_MAX * sin(0.5 * M_PI * i * i / SIZE));
 
     ff_iir_filter(fcoeffs, fstate, SIZE, x, 1, y, 1);
 
diff --git a/libavcodec/rangecoder.c b/libavcodec/rangecoder.c
index b81a6d0..31bbaa5 100644
--- a/libavcodec/rangecoder.c
+++ b/libavcodec/rangecoder.c
@@ -56,7 +56,7 @@ av_cold void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf,
     /* cast to avoid compiler warning */
     ff_init_range_encoder(c, (uint8_t *)buf, buf_size);
 
-    c->low = AV_RB16(c->bytestream);
+    c->low         = AV_RB16(c->bytestream);
     c->bytestream += 2;
 }
 
diff --git a/libavutil/aes.c b/libavutil/aes.c
index 9096f03..15dc602 100644
--- a/libavutil/aes.c
+++ b/libavutil/aes.c
@@ -25,6 +25,7 @@
 #include "aes_internal.h"
 #include "intreadwrite.h"
 #include "timer.h"
+#include "aes.h"
 
 const int av_aes_size= sizeof(AVAES);
 
@@ -34,7 +35,7 @@ struct AVAES *av_aes_alloc(void)
 }
 
 static const uint8_t rcon[10] = {
-  0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36
+    0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36
 };
 
 static uint8_t     sbox[256];
@@ -97,7 +98,8 @@ static void subshift(av_aes_block s0[2], int s, const uint8_t *box)
     s3[0].u8[ 5] = box[s3[1].u8[ 1]];
 }
 
-static inline int mix_core(uint32_t multbl[][256], int a, int b, int c, int d){
+static inline int mix_core(uint32_t multbl[][256], int a, int b, int c, int d)
+{
 #if CONFIG_SMALL
     return multbl[0][a] ^ ROT(multbl[0][b], 8) ^ ROT(multbl[0][c], 16) ^ ROT(multbl[0][d], 24);
 #else
@@ -105,12 +107,13 @@ static inline int mix_core(uint32_t multbl[][256], int a, int b, int c, int d){
 #endif
 }
 
-static inline void mix(av_aes_block state[2], uint32_t multbl[][256], int s1, int s3){
+static inline void mix(av_aes_block state[2], uint32_t multbl[][256], int s1, int s3)
+{
     uint8_t (*src)[4] = state[1].u8x4;
-    state[0].u32[0] = mix_core(multbl, src[0][0], src[s1  ][1], src[2][2], src[s3  ][3]);
-    state[0].u32[1] = mix_core(multbl, src[1][0], src[s3-1][1], src[3][2], src[s1-1][3]);
-    state[0].u32[2] = mix_core(multbl, src[2][0], src[s3  ][1], src[0][2], src[s1  ][3]);
-    state[0].u32[3] = mix_core(multbl, src[3][0], src[s1-1][1], src[1][2], src[s3-1][3]);
+    state[0].u32[0] = mix_core(multbl, src[0][0], src[s1    ][1], src[2][2], src[s3    ][3]);
+    state[0].u32[1] = mix_core(multbl, src[1][0], src[s3 - 1][1], src[3][2], src[s1 - 1][3]);
+    state[0].u32[2] = mix_core(multbl, src[2][0], src[s3    ][1], src[0][2], src[s1    ][3]);
+    state[0].u32[3] = mix_core(multbl, src[3][0], src[s1 - 1][1], src[1][2], src[s3 - 1][3]);
 }
 
 static inline void aes_crypt(AVAES *a, int s, const uint8_t *sbox,
@@ -179,7 +182,7 @@ static void init_multbl2(uint32_t tbl[][256], const int c[4],
             l = alog8[x + log8[c[1]]];
             m = alog8[x + log8[c[2]]];
             n = alog8[x + log8[c[3]]];
-            tbl[0][i] = AV_NE(MKBETAG(k,l,m,n), MKTAG(k,l,m,n));
+            tbl[0][i] = AV_NE(MKBETAG(k, l, m, n), MKTAG(k, l, m, n));
 #if !CONFIG_SMALL
             tbl[1][i] = ROT(tbl[0][i], 8);
             tbl[2][i] = ROT(tbl[0][i], 16);
@@ -201,7 +204,7 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
 
     a->crypt = decrypt ? aes_decrypt : aes_encrypt;
 
-    if (!enc_multbl[FF_ARRAY_ELEMS(enc_multbl)-1][FF_ARRAY_ELEMS(enc_multbl[0])-1]) {
+    if (!enc_multbl[FF_ARRAY_ELEMS(enc_multbl) - 1][FF_ARRAY_ELEMS(enc_multbl[0]) - 1]) {
         j = 1;
         for (i = 0; i < 255; i++) {
             alog8[i] = alog8[i + 255] = j;
@@ -215,7 +218,7 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
             j ^= (j << 1) ^ (j << 2) ^ (j << 3) ^ (j << 4);
             j = (j ^ (j >> 8) ^ 99) & 255;
             inv_sbox[j] = i;
-            sbox[i] = j;
+            sbox[i]     = j;
         }
         init_multbl2(dec_multbl, (const int[4]) { 0xe, 0x9, 0xd, 0xb },
                      log8, alog8, inv_sbox);
@@ -257,9 +260,8 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
             a->round_key[i] = tmp[0];
         }
     } else {
-        for (i = 0; i < (rounds + 1) >> 1; i++) {
-            FFSWAP(av_aes_block, a->round_key[i], a->round_key[rounds-i]);
-        }
+        for (i = 0; i < (rounds + 1) >> 1; i++)
+            FFSWAP(av_aes_block, a->round_key[i], a->round_key[rounds - i]);
     }
 
     return 0;
@@ -268,6 +270,7 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
 #ifdef TEST
 // LCOV_EXCL_START
 #include <string.h>
+
 #include "lfg.h"
 #include "log.h"
 
@@ -280,12 +283,12 @@ int main(int argc, char **argv)
         { 0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3,
           0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59 }
     };
-    uint8_t pt[32], rpt[2][16]= {
+    uint8_t pt[32], rpt[2][16] = {
         { 0x6a, 0x84, 0x86, 0x7c, 0xd7, 0x7e, 0x12, 0xad,
           0x07, 0xea, 0x1b, 0xe8, 0x95, 0xc5, 0x3f, 0xa3 },
         { 0 }
     };
-    uint8_t rct[2][16]= {
+    uint8_t rct[2][16] = {
         { 0x73, 0x22, 0x81, 0xc0, 0xa0, 0xaa, 0xb8, 0xf7,
           0xa5, 0x4a, 0x0c, 0x67, 0xa0, 0xc4, 0x5e, 0xcf },
         { 0x6d, 0x25, 0x1e, 0x69, 0x44, 0xb0, 0x51, 0xe0,
@@ -318,12 +321,10 @@ int main(int argc, char **argv)
         av_lfg_init(&prng, 1);
 
         for (i = 0; i < 10000; i++) {
-            for (j = 0; j < 32; j++) {
+            for (j = 0; j < 32; j++)
                 pt[j] = av_lfg_get(&prng);
-            }
-            for (j = 0; j < 16; j++) {
+            for (j = 0; j < 16; j++)
                 iv[0][j] = iv[1][j] = av_lfg_get(&prng);
-            }
             {
                 START_TIMER;
                 av_aes_crypt(&ae, temp, pt, 2, iv[0], 0);
diff --git a/libavutil/crc.c b/libavutil/crc.c
index 5a1ddf0..8d9cb32 100644
--- a/libavutil/crc.c
+++ b/libavutil/crc.c
@@ -19,8 +19,9 @@
  */
 
 #include "config.h"
-#include "common.h"
+
 #include "bswap.h"
+#include "common.h"
 #include "crc.h"
 
 #if CONFIG_HARDCODED_TABLES
@@ -332,7 +333,7 @@ int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size)
     if (ctx_size >= sizeof(AVCRC) * 1024)
         for (i = 0; i < 256; i++)
             for (j = 0; j < 3; j++)
-                ctx[256 *(j + 1) + i] =
+                ctx[256 * (j + 1) + i] =
                     (ctx[256 * j + i] >> 8) ^ ctx[ctx[256 * j + i] & 0xFF];
 #endif
 
@@ -383,13 +384,13 @@ int main(void)
 {
     uint8_t buf[1999];
     int i;
-    unsigned
-        p[6][3] = { { AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04 },
-                    { AV_CRC_32_IEEE   , 0x04C11DB7, 0xC0F5BAE0 },
-                    { AV_CRC_24_IEEE   , 0x864CFB  , 0xB704CE   },
-                    { AV_CRC_16_ANSI_LE, 0xA001    , 0xBFD8     },
-                    { AV_CRC_16_ANSI   , 0x8005    , 0x1FBB     },
-                    { AV_CRC_8_ATM     , 0x07      , 0xE3       }
+    unsigned p[6][3] = {
+        { AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04 },
+        { AV_CRC_32_IEEE   , 0x04C11DB7, 0xC0F5BAE0 },
+        { AV_CRC_24_IEEE   , 0x864CFB  , 0xB704CE   },
+        { AV_CRC_16_ANSI_LE, 0xA001    , 0xBFD8     },
+        { AV_CRC_16_ANSI   , 0x8005    , 0x1FBB     },
+        { AV_CRC_8_ATM     , 0x07      , 0xE3       }
     };
     const AVCRC *ctx;
 
diff --git a/libavutil/des.c b/libavutil/des.c
index ec2c399..25f3b6f 100644
--- a/libavutil/des.c
+++ b/libavutil/des.c
@@ -27,7 +27,7 @@
 #include "mem.h"
 #include "des.h"
 
-#define T(a, b, c, d, e, f, g, h) 64-a,64-b,64-c,64-d,64-e,64-f,64-g,64-h
+#define T(a, b, c, d, e, f, g, h) 64 - a, 64 - b, 64 - c, 64 - d, 64 - e, 64 - f, 64 - g, 64 - h
 static const uint8_t IP_shuffle[] = {
     T(58, 50, 42, 34, 26, 18, 10, 2),
     T(60, 52, 44, 36, 28, 20, 12, 4),
@@ -41,7 +41,7 @@ static const uint8_t IP_shuffle[] = {
 #undef T
 
 #if CONFIG_SMALL || defined(GENTABLES)
-#define T(a, b, c, d) 32-a,32-b,32-c,32-d
+#define T(a, b, c, d) 32 - a, 32 - b, 32 - c, 32 - d
 static const uint8_t P_shuffle[] = {
     T(16,  7, 20, 21),
     T(29, 12, 28, 17),
@@ -55,7 +55,7 @@ static const uint8_t P_shuffle[] = {
 #undef T
 #endif
 
-#define T(a, b, c, d, e, f, g) 64-a,64-b,64-c,64-d,64-e,64-f,64-g
+#define T(a, b, c, d, e, f, g) 64 - a, 64 - b, 64 - c, 64 - d, 64 - e, 64 - f, 64 - g
 static const uint8_t PC1_shuffle[] = {
     T(57, 49, 41, 33, 25, 17,  9),
     T( 1, 58, 50, 42, 34, 26, 18),
@@ -68,7 +68,7 @@ static const uint8_t PC1_shuffle[] = {
 };
 #undef T
 
-#define T(a, b, c, d, e, f) 56-a,56-b,56-c,56-d,56-e,56-f
+#define T(a, b, c, d, e, f) 56 - a, 56 - b, 56 - c, 56 - d, 56 - e, 56 - f
 static const uint8_t PC2_shuffle[] = {
     T(14, 17, 11, 24,  1,  5),
     T( 3, 28, 15,  6, 21, 10),
@@ -83,30 +83,22 @@ static const uint8_t PC2_shuffle[] = {
 
 #if CONFIG_SMALL
 static const uint8_t S_boxes[8][32] = {
-    {
-    0x0e, 0xf4, 0x7d, 0x41, 0xe2, 0x2f, 0xdb, 0x18, 0xa3, 0x6a, 0xc6, 0xbc, 0x95, 0x59, 0x30, 0x87,
-    0xf4, 0xc1, 0x8e, 0x28, 0x4d, 0x96, 0x12, 0x7b, 0x5f, 0xbc, 0x39, 0xe7, 0xa3, 0x0a, 0x65, 0xd0,
-    }, {
-    0x3f, 0xd1, 0x48, 0x7e, 0xf6, 0x2b, 0x83, 0xe4, 0xc9, 0x07, 0x12, 0xad, 0x6c, 0x90, 0xb5, 0x5a,
-    0xd0, 0x8e, 0xa7, 0x1b, 0x3a, 0xf4, 0x4d, 0x21, 0xb5, 0x68, 0x7c, 0xc6, 0x09, 0x53, 0xe2, 0x9f,
-    }, {
-    0xda, 0x70, 0x09, 0x9e, 0x36, 0x43, 0x6f, 0xa5, 0x21, 0x8d, 0x5c, 0xe7, 0xcb, 0xb4, 0xf2, 0x18,
-    0x1d, 0xa6, 0xd4, 0x09, 0x68, 0x9f, 0x83, 0x70, 0x4b, 0xf1, 0xe2, 0x3c, 0xb5, 0x5a, 0x2e, 0xc7,
-    }, {
-    0xd7, 0x8d, 0xbe, 0x53, 0x60, 0xf6, 0x09, 0x3a, 0x41, 0x72, 0x28, 0xc5, 0x1b, 0xac, 0xe4, 0x9f,
-    0x3a, 0xf6, 0x09, 0x60, 0xac, 0x1b, 0xd7, 0x8d, 0x9f, 0x41, 0x53, 0xbe, 0xc5, 0x72, 0x28, 0xe4,
-    }, {
-    0xe2, 0xbc, 0x24, 0xc1, 0x47, 0x7a, 0xdb, 0x16, 0x58, 0x05, 0xf3, 0xaf, 0x3d, 0x90, 0x8e, 0x69,
-    0xb4, 0x82, 0xc1, 0x7b, 0x1a, 0xed, 0x27, 0xd8, 0x6f, 0xf9, 0x0c, 0x95, 0xa6, 0x43, 0x50, 0x3e,
-    }, {
-    0xac, 0xf1, 0x4a, 0x2f, 0x79, 0xc2, 0x96, 0x58, 0x60, 0x1d, 0xd3, 0xe4, 0x0e, 0xb7, 0x35, 0x8b,
-    0x49, 0x3e, 0x2f, 0xc5, 0x92, 0x58, 0xfc, 0xa3, 0xb7, 0xe0, 0x14, 0x7a, 0x61, 0x0d, 0x8b, 0xd6,
-    }, {
-    0xd4, 0x0b, 0xb2, 0x7e, 0x4f, 0x90, 0x18, 0xad, 0xe3, 0x3c, 0x59, 0xc7, 0x25, 0xfa, 0x86, 0x61,
-    0x61, 0xb4, 0xdb, 0x8d, 0x1c, 0x43, 0xa7, 0x7e, 0x9a, 0x5f, 0x06, 0xf8, 0xe0, 0x25, 0x39, 0xc2,
-    }, {
-    0x1d, 0xf2, 0xd8, 0x84, 0xa6, 0x3f, 0x7b, 0x41, 0xca, 0x59, 0x63, 0xbe, 0x05, 0xe0, 0x9c, 0x27,
-    0x27, 0x1b, 0xe4, 0x71, 0x49, 0xac, 0x8e, 0xd2, 0xf0, 0xc6, 0x9a, 0x0d, 0x3f, 0x53, 0x65, 0xb8,
+    { 0x0e, 0xf4, 0x7d, 0x41, 0xe2, 0x2f, 0xdb, 0x18, 0xa3, 0x6a, 0xc6, 0xbc, 0x95, 0x59, 0x30, 0x87,
+      0xf4, 0xc1, 0x8e, 0x28, 0x4d, 0x96, 0x12, 0x7b, 0x5f, 0xbc, 0x39, 0xe7, 0xa3, 0x0a, 0x65, 0xd0, },
+    { 0x3f, 0xd1, 0x48, 0x7e, 0xf6, 0x2b, 0x83, 0xe4, 0xc9, 0x07, 0x12, 0xad, 0x6c, 0x90, 0xb5, 0x5a,
+      0xd0, 0x8e, 0xa7, 0x1b, 0x3a, 0xf4, 0x4d, 0x21, 0xb5, 0x68, 0x7c, 0xc6, 0x09, 0x53, 0xe2, 0x9f, },
+    { 0xda, 0x70, 0x09, 0x9e, 0x36, 0x43, 0x6f, 0xa5, 0x21, 0x8d, 0x5c, 0xe7, 0xcb, 0xb4, 0xf2, 0x18,
+      0x1d, 0xa6, 0xd4, 0x09, 0x68, 0x9f, 0x83, 0x70, 0x4b, 0xf1, 0xe2, 0x3c, 0xb5, 0x5a, 0x2e, 0xc7, },
+    { 0xd7, 0x8d, 0xbe, 0x53, 0x60, 0xf6, 0x09, 0x3a, 0x41, 0x72, 0x28, 0xc5, 0x1b, 0xac, 0xe4, 0x9f,
+      0x3a, 0xf6, 0x09, 0x60, 0xac, 0x1b, 0xd7, 0x8d, 0x9f, 0x41, 0x53, 0xbe, 0xc5, 0x72, 0x28, 0xe4, },
+    { 0xe2, 0xbc, 0x24, 0xc1, 0x47, 0x7a, 0xdb, 0x16, 0x58, 0x05, 0xf3, 0xaf, 0x3d, 0x90, 0x8e, 0x69,
+      0xb4, 0x82, 0xc1, 0x7b, 0x1a, 0xed, 0x27, 0xd8, 0x6f, 0xf9, 0x0c, 0x95, 0xa6, 0x43, 0x50, 0x3e, },
+    { 0xac, 0xf1, 0x4a, 0x2f, 0x79, 0xc2, 0x96, 0x58, 0x60, 0x1d, 0xd3, 0xe4, 0x0e, 0xb7, 0x35, 0x8b,
+      0x49, 0x3e, 0x2f, 0xc5, 0x92, 0x58, 0xfc, 0xa3, 0xb7, 0xe0, 0x14, 0x7a, 0x61, 0x0d, 0x8b, 0xd6, },
+    { 0xd4, 0x0b, 0xb2, 0x7e, 0x4f, 0x90, 0x18, 0xad, 0xe3, 0x3c, 0x59, 0xc7, 0x25, 0xfa, 0x86, 0x61,
+      0x61, 0xb4, 0xdb, 0x8d, 0x1c, 0x43, 0xa7, 0x7e, 0x9a, 0x5f, 0x06, 0xf8, 0xe0, 0x25, 0x39, 0xc2, },
+    { 0x1d, 0xf2, 0xd8, 0x84, 0xa6, 0x3f, 0x7b, 0x41, 0xca, 0x59, 0x63, 0xbe, 0x05, 0xe0, 0x9c, 0x27,
+      0x27, 0x1b, 0xe4, 0x71, 0x49, 0xac, 0x8e, 0xd2, 0xf0, 0xc6, 0x9a, 0x0d, 0x3f, 0x53, 0x65, 0xb8,
     }
 };
 #else
@@ -115,90 +107,75 @@ static const uint8_t S_boxes[8][32] = {
  * It can be regenerated by compiling this file with -DCONFIG_SMALL -DTEST -DGENTABLES
  */
 static const uint32_t S_boxes_P_shuffle[8][64] = {
-    {
-    0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202, 0x00000002, 0x00008000,
-    0x00000200, 0x00808200, 0x00808202, 0x00000200, 0x00800202, 0x00808002, 0x00800000, 0x00000002,
-    0x00000202, 0x00800200, 0x00800200, 0x00008200, 0x00008200, 0x00808000, 0x00808000, 0x00800202,
-    0x00008002, 0x00800002, 0x00800002, 0x00008002, 0x00000000, 0x00000202, 0x00008202, 0x00800000,
-    0x00008000, 0x00808202, 0x00000002, 0x00808000, 0x00808200, 0x00800000, 0x00800000, 0x00000200,
-    0x00808002, 0x00008000, 0x00008200, 0x00800002, 0x00000200, 0x00000002, 0x00800202, 0x00008202,
-    0x00808202, 0x00008002, 0x00808000, 0x00800202, 0x00800002, 0x00000202, 0x00008202, 0x00808200,
-    0x00000202, 0x00800200, 0x00800200, 0x00000000, 0x00008002, 0x00008200, 0x00000000, 0x00808002,
-    },
-    {
-    0x40084010, 0x40004000, 0x00004000, 0x00084010, 0x00080000, 0x00000010, 0x40080010, 0x40004010,
-    0x40000010, 0x40084010, 0x40084000, 0x40000000, 0x40004000, 0x00080000, 0x00000010, 0x40080010,
-    0x00084000, 0x00080010, 0x40004010, 0x00000000, 0x40000000, 0x00004000, 0x00084010, 0x40080000,
-    0x00080010, 0x40000010, 0x00000000, 0x00084000, 0x00004010, 0x40084000, 0x40080000, 0x00004010,
-    0x00000000, 0x00084010, 0x40080010, 0x00080000, 0x40004010, 0x40080000, 0x40084000, 0x00004000,
-    0x40080000, 0x40004000, 0x00000010, 0x40084010, 0x00084010, 0x00000010, 0x00004000, 0x40000000,
-    0x00004010, 0x40084000, 0x00080000, 0x40000010, 0x00080010, 0x40004010, 0x40000010, 0x00080010,
-    0x00084000, 0x00000000, 0x40004000, 0x00004010, 0x40000000, 0x40080010, 0x40084010, 0x00084000,
-    },
-    {
-    0x00000104, 0x04010100, 0x00000000, 0x04010004, 0x04000100, 0x00000000, 0x00010104, 0x04000100,
-    0x00010004, 0x04000004, 0x04000004, 0x00010000, 0x04010104, 0x00010004, 0x04010000, 0x00000104,
-    0x04000000, 0x00000004, 0x04010100, 0x00000100, 0x00010100, 0x04010000, 0x04010004, 0x00010104,
-    0x04000104, 0x00010100, 0x00010000, 0x04000104, 0x00000004, 0x04010104, 0x00000100, 0x04000000,
-    0x04010100, 0x04000000, 0x00010004, 0x00000104, 0x00010000, 0x04010100, 0x04000100, 0x00000000,
-    0x00000100, 0x00010004, 0x04010104, 0x04000100, 0x04000004, 0x00000100, 0x00000000, 0x04010004,
-    0x04000104, 0x00010000, 0x04000000, 0x04010104, 0x00000004, 0x00010104, 0x00010100, 0x04000004,
-    0x04010000, 0x04000104, 0x00000104, 0x04010000, 0x00010104, 0x00000004, 0x04010004, 0x00010100,
-    },
-    {
-    0x80401000, 0x80001040, 0x80001040, 0x00000040, 0x00401040, 0x80400040, 0x80400000, 0x80001000,
-    0x00000000, 0x00401000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00400040, 0x80400000,
-    0x80000000, 0x00001000, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x80001000, 0x00001040,
-    0x80400040, 0x80000000, 0x00001040, 0x00400040, 0x00001000, 0x00401040, 0x80401040, 0x80000040,
-    0x00400040, 0x80400000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00000000, 0x00401000,
-    0x00001040, 0x00400040, 0x80400040, 0x80000000, 0x80401000, 0x80001040, 0x80001040, 0x00000040,
-    0x80401040, 0x80000040, 0x80000000, 0x00001000, 0x80400000, 0x80001000, 0x00401040, 0x80400040,
-    0x80001000, 0x00001040, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x00001000, 0x00401040,
-    },
-    {
-    0x00000080, 0x01040080, 0x01040000, 0x21000080, 0x00040000, 0x00000080, 0x20000000, 0x01040000,
-    0x20040080, 0x00040000, 0x01000080, 0x20040080, 0x21000080, 0x21040000, 0x00040080, 0x20000000,
-    0x01000000, 0x20040000, 0x20040000, 0x00000000, 0x20000080, 0x21040080, 0x21040080, 0x01000080,
-    0x21040000, 0x20000080, 0x00000000, 0x21000000, 0x01040080, 0x01000000, 0x21000000, 0x00040080,
-    0x00040000, 0x21000080, 0x00000080, 0x01000000, 0x20000000, 0x01040000, 0x21000080, 0x20040080,
-    0x01000080, 0x20000000, 0x21040000, 0x01040080, 0x20040080, 0x00000080, 0x01000000, 0x21040000,
-    0x21040080, 0x00040080, 0x21000000, 0x21040080, 0x01040000, 0x00000000, 0x20040000, 0x21000000,
-    0x00040080, 0x01000080, 0x20000080, 0x00040000, 0x00000000, 0x20040000, 0x01040080, 0x20000080,
-    },
-    {
-    0x10000008, 0x10200000, 0x00002000, 0x10202008, 0x10200000, 0x00000008, 0x10202008, 0x00200000,
-    0x10002000, 0x00202008, 0x00200000, 0x10000008, 0x00200008, 0x10002000, 0x10000000, 0x00002008,
-    0x00000000, 0x00200008, 0x10002008, 0x00002000, 0x00202000, 0x10002008, 0x00000008, 0x10200008,
-    0x10200008, 0x00000000, 0x00202008, 0x10202000, 0x00002008, 0x00202000, 0x10202000, 0x10000000,
-    0x10002000, 0x00000008, 0x10200008, 0x00202000, 0x10202008, 0x00200000, 0x00002008, 0x10000008,
-    0x00200000, 0x10002000, 0x10000000, 0x00002008, 0x10000008, 0x10202008, 0x00202000, 0x10200000,
-    0x00202008, 0x10202000, 0x00000000, 0x10200008, 0x00000008, 0x00002000, 0x10200000, 0x00202008,
-    0x00002000, 0x00200008, 0x10002008, 0x00000000, 0x10202000, 0x10000000, 0x00200008, 0x10002008,
-    },
-    {
-    0x00100000, 0x02100001, 0x02000401, 0x00000000, 0x00000400, 0x02000401, 0x00100401, 0x02100400,
-    0x02100401, 0x00100000, 0x00000000, 0x02000001, 0x00000001, 0x02000000, 0x02100001, 0x00000401,
-    0x02000400, 0x00100401, 0x00100001, 0x02000400, 0x02000001, 0x02100000, 0x02100400, 0x00100001,
-    0x02100000, 0x00000400, 0x00000401, 0x02100401, 0x00100400, 0x00000001, 0x02000000, 0x00100400,
-    0x02000000, 0x00100400, 0x00100000, 0x02000401, 0x02000401, 0x02100001, 0x02100001, 0x00000001,
-    0x00100001, 0x02000000, 0x02000400, 0x00100000, 0x02100400, 0x00000401, 0x00100401, 0x02100400,
-    0x00000401, 0x02000001, 0x02100401, 0x02100000, 0x00100400, 0x00000000, 0x00000001, 0x02100401,
-    0x00000000, 0x00100401, 0x02100000, 0x00000400, 0x02000001, 0x02000400, 0x00000400, 0x00100001,
-    },
-    {
-    0x08000820, 0x00000800, 0x00020000, 0x08020820, 0x08000000, 0x08000820, 0x00000020, 0x08000000,
-    0x00020020, 0x08020000, 0x08020820, 0x00020800, 0x08020800, 0x00020820, 0x00000800, 0x00000020,
-    0x08020000, 0x08000020, 0x08000800, 0x00000820, 0x00020800, 0x00020020, 0x08020020, 0x08020800,
-    0x00000820, 0x00000000, 0x00000000, 0x08020020, 0x08000020, 0x08000800, 0x00020820, 0x00020000,
-    0x00020820, 0x00020000, 0x08020800, 0x00000800, 0x00000020, 0x08020020, 0x00000800, 0x00020820,
-    0x08000800, 0x00000020, 0x08000020, 0x08020000, 0x08020020, 0x08000000, 0x00020000, 0x08000820,
-    0x00000000, 0x08020820, 0x00020020, 0x08000020, 0x08020000, 0x08000800, 0x08000820, 0x00000000,
-    0x08020820, 0x00020800, 0x00020800, 0x00000820, 0x00000820, 0x00020020, 0x08000000, 0x08020800,
-    },
+    { 0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202, 0x00000002, 0x00008000,
+      0x00000200, 0x00808200, 0x00808202, 0x00000200, 0x00800202, 0x00808002, 0x00800000, 0x00000002,
+      0x00000202, 0x00800200, 0x00800200, 0x00008200, 0x00008200, 0x00808000, 0x00808000, 0x00800202,
+      0x00008002, 0x00800002, 0x00800002, 0x00008002, 0x00000000, 0x00000202, 0x00008202, 0x00800000,
+      0x00008000, 0x00808202, 0x00000002, 0x00808000, 0x00808200, 0x00800000, 0x00800000, 0x00000200,
+      0x00808002, 0x00008000, 0x00008200, 0x00800002, 0x00000200, 0x00000002, 0x00800202, 0x00008202,
+      0x00808202, 0x00008002, 0x00808000, 0x00800202, 0x00800002, 0x00000202, 0x00008202, 0x00808200,
+      0x00000202, 0x00800200, 0x00800200, 0x00000000, 0x00008002, 0x00008200, 0x00000000, 0x00808002, },
+    { 0x40084010, 0x40004000, 0x00004000, 0x00084010, 0x00080000, 0x00000010, 0x40080010, 0x40004010,
+      0x40000010, 0x40084010, 0x40084000, 0x40000000, 0x40004000, 0x00080000, 0x00000010, 0x40080010,
+      0x00084000, 0x00080010, 0x40004010, 0x00000000, 0x40000000, 0x00004000, 0x00084010, 0x40080000,
+      0x00080010, 0x40000010, 0x00000000, 0x00084000, 0x00004010, 0x40084000, 0x40080000, 0x00004010,
+      0x00000000, 0x00084010, 0x40080010, 0x00080000, 0x40004010, 0x40080000, 0x40084000, 0x00004000,
+      0x40080000, 0x40004000, 0x00000010, 0x40084010, 0x00084010, 0x00000010, 0x00004000, 0x40000000,
+      0x00004010, 0x40084000, 0x00080000, 0x40000010, 0x00080010, 0x40004010, 0x40000010, 0x00080010,
+      0x00084000, 0x00000000, 0x40004000, 0x00004010, 0x40000000, 0x40080010, 0x40084010, 0x00084000, },
+    { 0x00000104, 0x04010100, 0x00000000, 0x04010004, 0x04000100, 0x00000000, 0x00010104, 0x04000100,
+      0x00010004, 0x04000004, 0x04000004, 0x00010000, 0x04010104, 0x00010004, 0x04010000, 0x00000104,
+      0x04000000, 0x00000004, 0x04010100, 0x00000100, 0x00010100, 0x04010000, 0x04010004, 0x00010104,
+      0x04000104, 0x00010100, 0x00010000, 0x04000104, 0x00000004, 0x04010104, 0x00000100, 0x04000000,
+      0x04010100, 0x04000000, 0x00010004, 0x00000104, 0x00010000, 0x04010100, 0x04000100, 0x00000000,
+      0x00000100, 0x00010004, 0x04010104, 0x04000100, 0x04000004, 0x00000100, 0x00000000, 0x04010004,
+      0x04000104, 0x00010000, 0x04000000, 0x04010104, 0x00000004, 0x00010104, 0x00010100, 0x04000004,
+      0x04010000, 0x04000104, 0x00000104, 0x04010000, 0x00010104, 0x00000004, 0x04010004, 0x00010100, },
+    { 0x80401000, 0x80001040, 0x80001040, 0x00000040, 0x00401040, 0x80400040, 0x80400000, 0x80001000,
+      0x00000000, 0x00401000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00400040, 0x80400000,
+      0x80000000, 0x00001000, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x80001000, 0x00001040,
+      0x80400040, 0x80000000, 0x00001040, 0x00400040, 0x00001000, 0x00401040, 0x80401040, 0x80000040,
+      0x00400040, 0x80400000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00000000, 0x00401000,
+      0x00001040, 0x00400040, 0x80400040, 0x80000000, 0x80401000, 0x80001040, 0x80001040, 0x00000040,
+      0x80401040, 0x80000040, 0x80000000, 0x00001000, 0x80400000, 0x80001000, 0x00401040, 0x80400040,
+      0x80001000, 0x00001040, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x00001000, 0x00401040, },
+    { 0x00000080, 0x01040080, 0x01040000, 0x21000080, 0x00040000, 0x00000080, 0x20000000, 0x01040000,
+      0x20040080, 0x00040000, 0x01000080, 0x20040080, 0x21000080, 0x21040000, 0x00040080, 0x20000000,
+      0x01000000, 0x20040000, 0x20040000, 0x00000000, 0x20000080, 0x21040080, 0x21040080, 0x01000080,
+      0x21040000, 0x20000080, 0x00000000, 0x21000000, 0x01040080, 0x01000000, 0x21000000, 0x00040080,
+      0x00040000, 0x21000080, 0x00000080, 0x01000000, 0x20000000, 0x01040000, 0x21000080, 0x20040080,
+      0x01000080, 0x20000000, 0x21040000, 0x01040080, 0x20040080, 0x00000080, 0x01000000, 0x21040000,
+      0x21040080, 0x00040080, 0x21000000, 0x21040080, 0x01040000, 0x00000000, 0x20040000, 0x21000000,
+      0x00040080, 0x01000080, 0x20000080, 0x00040000, 0x00000000, 0x20040000, 0x01040080, 0x20000080, },
+    { 0x10000008, 0x10200000, 0x00002000, 0x10202008, 0x10200000, 0x00000008, 0x10202008, 0x00200000,
+      0x10002000, 0x00202008, 0x00200000, 0x10000008, 0x00200008, 0x10002000, 0x10000000, 0x00002008,
+      0x00000000, 0x00200008, 0x10002008, 0x00002000, 0x00202000, 0x10002008, 0x00000008, 0x10200008,
+      0x10200008, 0x00000000, 0x00202008, 0x10202000, 0x00002008, 0x00202000, 0x10202000, 0x10000000,
+      0x10002000, 0x00000008, 0x10200008, 0x00202000, 0x10202008, 0x00200000, 0x00002008, 0x10000008,
+      0x00200000, 0x10002000, 0x10000000, 0x00002008, 0x10000008, 0x10202008, 0x00202000, 0x10200000,
+      0x00202008, 0x10202000, 0x00000000, 0x10200008, 0x00000008, 0x00002000, 0x10200000, 0x00202008,
+      0x00002000, 0x00200008, 0x10002008, 0x00000000, 0x10202000, 0x10000000, 0x00200008, 0x10002008, },
+    { 0x00100000, 0x02100001, 0x02000401, 0x00000000, 0x00000400, 0x02000401, 0x00100401, 0x02100400,
+      0x02100401, 0x00100000, 0x00000000, 0x02000001, 0x00000001, 0x02000000, 0x02100001, 0x00000401,
+      0x02000400, 0x00100401, 0x00100001, 0x02000400, 0x02000001, 0x02100000, 0x02100400, 0x00100001,
+      0x02100000, 0x00000400, 0x00000401, 0x02100401, 0x00100400, 0x00000001, 0x02000000, 0x00100400,
+      0x02000000, 0x00100400, 0x00100000, 0x02000401, 0x02000401, 0x02100001, 0x02100001, 0x00000001,
+      0x00100001, 0x02000000, 0x02000400, 0x00100000, 0x02100400, 0x00000401, 0x00100401, 0x02100400,
+      0x00000401, 0x02000001, 0x02100401, 0x02100000, 0x00100400, 0x00000000, 0x00000001, 0x02100401,
+      0x00000000, 0x00100401, 0x02100000, 0x00000400, 0x02000001, 0x02000400, 0x00000400, 0x00100001, },
+    { 0x08000820, 0x00000800, 0x00020000, 0x08020820, 0x08000000, 0x08000820, 0x00000020, 0x08000000,
+      0x00020020, 0x08020000, 0x08020820, 0x00020800, 0x08020800, 0x00020820, 0x00000800, 0x00000020,
+      0x08020000, 0x08000020, 0x08000800, 0x00000820, 0x00020800, 0x00020020, 0x08020020, 0x08020800,
+      0x00000820, 0x00000000, 0x00000000, 0x08020020, 0x08000020, 0x08000800, 0x00020820, 0x00020000,
+      0x00020820, 0x00020000, 0x08020800, 0x00000800, 0x00000020, 0x08020020, 0x00000800, 0x00020820,
+      0x08000800, 0x00000020, 0x08000020, 0x08020000, 0x08020020, 0x08000000, 0x00020000, 0x08000820,
+      0x00000000, 0x08020820, 0x00020020, 0x08000020, 0x08020000, 0x08000800, 0x08000820, 0x00000000,
+      0x08020820, 0x00020800, 0x00020800, 0x00000820, 0x00000820, 0x00020020, 0x08000000, 0x08020800, },
 };
 #endif
 
-static uint64_t shuffle(uint64_t in, const uint8_t *shuffle, int shuffle_len) {
+static uint64_t shuffle(uint64_t in, const uint8_t *shuffle, int shuffle_len)
+{
     int i;
     uint64_t res = 0;
     for (i = 0; i < shuffle_len; i++)
@@ -206,7 +183,8 @@ static uint64_t shuffle(uint64_t in, const uint8_t *shuffle, int shuffle_len) {
     return res;
 }
 
-static uint64_t shuffle_inv(uint64_t in, const uint8_t *shuffle, int shuffle_len) {
+static uint64_t shuffle_inv(uint64_t in, const uint8_t *shuffle, int shuffle_len)
+{
     int i;
     uint64_t res = 0;
     shuffle += shuffle_len - 1;
@@ -217,7 +195,8 @@ static uint64_t shuffle_inv(uint64_t in, const uint8_t *shuffle, int shuffle_len
     return res;
 }
 
-static uint32_t f_func(uint32_t r, uint64_t k) {
+static uint32_t f_func(uint32_t r, uint64_t k)
+{
     int i;
     uint32_t out = 0;
     // rotate to get first part of E-shuffle in the lowest 6 bits
@@ -227,13 +206,14 @@ static uint32_t f_func(uint32_t r, uint64_t k) {
         uint8_t tmp = (r ^ k) & 0x3f;
 #if CONFIG_SMALL
         uint8_t v = S_boxes[i][tmp >> 1];
-        if (tmp & 1) v >>= 4;
+        if (tmp & 1)
+            v >>= 4;
         out = (out >> 4) | (v << 28);
 #else
         out |= S_boxes_P_shuffle[i][tmp];
 #endif
         // get next 6 bits of E-shuffle and round key k into the lowest bits
-        r = (r >> 4) | (r << 28);
+        r   = (r >> 4) | (r << 28);
         k >>= 6;
     }
 #if CONFIG_SMALL
@@ -248,15 +228,17 @@ static uint32_t f_func(uint32_t r, uint64_t k) {
  * Note: the specification calls this "shift", so I kept it although
  * it is confusing.
  */
-static uint64_t key_shift_left(uint64_t CDn) {
+static uint64_t key_shift_left(uint64_t CDn)
+{
     uint64_t carries = (CDn >> 27) & 0x10000001;
     CDn <<= 1;
-    CDn &= ~0x10000001;
-    CDn |= carries;
+    CDn  &= ~0x10000001;
+    CDn  |= carries;
     return CDn;
 }
 
-static void gen_roundkeys(uint64_t K[16], uint64_t key) {
+static void gen_roundkeys(uint64_t K[16], uint64_t key)
+{
     int i;
     // discard parity bits from key and shuffle it into C and D parts
     uint64_t CDn = shuffle(key, PC1_shuffle, sizeof(PC1_shuffle));
@@ -269,7 +251,8 @@ static void gen_roundkeys(uint64_t K[16], uint64_t key) {
     }
 }
 
-static uint64_t des_encdec(uint64_t in, uint64_t K[16], int decrypt) {
+static uint64_t des_encdec(uint64_t in, uint64_t K[16], int decrypt)
+{
     int i;
     // used to apply round keys in reverse order for decryption
     decrypt = decrypt ? 15 : 0;
@@ -278,8 +261,8 @@ static uint64_t des_encdec(uint64_t in, uint64_t K[16], int decrypt) {
     for (i = 0; i < 16; i++) {
         uint32_t f_res;
         f_res = f_func(in, K[decrypt ^ i]);
-        in = (in << 32) | (in >> 32);
-        in ^= f_res;
+        in    = (in << 32) | (in >> 32);
+        in   ^= f_res;
     }
     in = (in << 32) | (in >> 32);
     // reverse shuffle used to ease hardware implementations
@@ -304,7 +287,9 @@ int av_des_init(AVDES *d, const uint8_t *key, int key_bits, av_unused int decryp
     return 0;
 }
 
-static void av_des_crypt_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt, int mac) {
+static void av_des_crypt_mac(AVDES *d, uint8_t *dst, const uint8_t *src,
+                             int count, uint8_t *iv, int decrypt, int mac)
+{
     uint64_t iv_val = iv ? AV_RB64(iv) : 0;
     while (count-- > 0) {
         uint64_t dst_val;
@@ -316,7 +301,7 @@ static void av_des_crypt_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int cou
                 src_val = des_encdec(src_val, d->round_keys[1], 0);
             }
             dst_val = des_encdec(src_val, d->round_keys[0], 1) ^ iv_val;
-            iv_val = iv ? tmp : 0;
+            iv_val  = iv ? tmp : 0;
         } else {
             dst_val = des_encdec(src_val ^ iv_val, d->round_keys[0], 0);
             if (d->triple_des) {
@@ -334,12 +319,15 @@ static void av_des_crypt_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int cou
         AV_WB64(iv, iv_val);
 }
 
-void av_des_crypt(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt) {
+void av_des_crypt(AVDES *d, uint8_t *dst, const uint8_t *src,
+                  int count, uint8_t *iv, int decrypt)
+{
     av_des_crypt_mac(d, dst, src, count, iv, decrypt, 0);
 }
 
-void av_des_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int count) {
-    av_des_crypt_mac(d, dst, src, count, (uint8_t[8]){0}, 0, 1);
+void av_des_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int count)
+{
+    av_des_crypt_mac(d, dst, src, count, (uint8_t[8]) { 0 }, 0, 1);
 }
 
 #ifdef TEST
@@ -348,15 +336,16 @@ void av_des_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int count) {
 
 #include "time.h"
 
-static uint64_t rand64(void) {
+static uint64_t rand64(void)
+{
     uint64_t r = rand();
     r = (r << 32) | rand();
     return r;
 }
 
-static const uint8_t test_key[] = {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0};
-static const DECLARE_ALIGNED(8, uint8_t, plain)[] = {0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10};
-static const DECLARE_ALIGNED(8, uint8_t, crypt)[] = {0x4a, 0xb6, 0x5b, 0x3d, 0x4b, 0x06, 0x15, 0x18};
+static const uint8_t test_key[] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
+static const DECLARE_ALIGNED(8, uint8_t, plain)[] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
+static const DECLARE_ALIGNED(8, uint8_t, crypt)[] = { 0x4a, 0xb6, 0x5b, 0x3d, 0x4b, 0x06, 0x15, 0x18 };
 static DECLARE_ALIGNED(8, uint8_t, tmp)[8];
 static DECLARE_ALIGNED(8, uint8_t, large_buffer)[10002][8];
 static const uint8_t cbc_key[] = {
@@ -365,7 +354,8 @@ static const uint8_t cbc_key[] = {
     0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23
 };
 
-static int run_test(int cbc, int decrypt) {
+static int run_test(int cbc, int decrypt)
+{
     AVDES d;
     int delay = cbc && !decrypt ? 2 : 1;
     uint64_t res;
@@ -388,7 +378,8 @@ static int run_test(int cbc, int decrypt) {
     }
 }
 
-int main(void) {
+int main(void)
+{
     AVDES d;
     int i;
     uint64_t key[3];
@@ -397,7 +388,7 @@ int main(void) {
     uint64_t roundkeys[16];
     srand(av_gettime());
     key[0] = AV_RB64(test_key);
-    data = AV_RB64(plain);
+    data   = AV_RB64(plain);
     gen_roundkeys(roundkeys, key[0]);
     if (des_encdec(data, roundkeys, 0) != AV_RB64(crypt)) {
         printf("Test 1 failed\n");
@@ -414,12 +405,14 @@ int main(void) {
         return 1;
     }
     for (i = 0; i < 1000; i++) {
-        key[0] = rand64(); key[1] = rand64(); key[2] = rand64();
-        data = rand64();
-        av_des_init(&d, (uint8_t*)key, 192, 0);
-        av_des_crypt(&d, (uint8_t*)&ct, (uint8_t*)&data, 1, NULL, 0);
-        av_des_init(&d, (uint8_t*)key, 192, 1);
-        av_des_crypt(&d, (uint8_t*)&ct, (uint8_t*)&ct, 1, NULL, 1);
+        key[0] = rand64();
+        key[1] = rand64();
+        key[2] = rand64();
+        data   = rand64();
+        av_des_init(&d, (uint8_t *) key, 192, 0);
+        av_des_crypt(&d, (uint8_t *) &ct, (uint8_t *) &data, 1, NULL, 0);
+        av_des_init(&d, (uint8_t *) key, 192, 1);
+        av_des_crypt(&d, (uint8_t *) &ct, (uint8_t *) &ct, 1, NULL, 1);
         if (ct != data) {
             printf("Test 2 failed\n");
             return 1;
@@ -432,9 +425,9 @@ int main(void) {
         printf("    {");
         for (j = 0; j < 64; j++) {
             uint32_t v = S_boxes[i][j >> 1];
-            v = j & 1 ? v >> 4 : v & 0xf;
+            v   = j & 1 ? v >> 4 : v & 0xf;
             v <<= 28 - 4 * i;
-            v = shuffle(v, P_shuffle, sizeof(P_shuffle));
+            v   = shuffle(v, P_shuffle, sizeof(P_shuffle));
             printf((j & 7) == 0 ? "\n    " : " ");
             printf("0x%08X,", v);
         }
diff --git a/libavutil/lls.c b/libavutil/lls.c
index de3d58f..c5753ae 100644
--- a/libavutil/lls.c
+++ b/libavutil/lls.c
@@ -141,7 +141,7 @@ int main(void)
         LOCAL_ALIGNED(32, double, var, [4]);
         double eval;
 
-        var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2;
+        var[0] =         (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2;
         var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
         var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
         var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
diff --git a/libavutil/md5.c b/libavutil/md5.c
index 876bd55..482582b 100644
--- a/libavutil/md5.c
+++ b/libavutil/md5.c
@@ -31,12 +31,13 @@
  */
 
 #include <stdint.h>
+
 #include "bswap.h"
 #include "intreadwrite.h"
-#include "md5.h"
 #include "mem.h"
+#include "md5.h"
 
-typedef struct AVMD5{
+typedef struct AVMD5 {
     uint64_t len;
     uint8_t  block[64];
     uint32_t ABCD[4];
@@ -78,16 +79,21 @@ static const uint32_t T[64] = { // T[i]= fabs(sin(i+1)<<32)
     0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
 };
 
-#define CORE(i, a, b, c, d) do {                                        \
-        t = S[i >> 4][i & 3];                                           \
+#define CORE(i, a, b, c, d)                                             \
+    do {                                                                \
+        t  = S[i >> 4][i & 3];                                          \
         a += T[i];                                                      \
                                                                         \
         if (i < 32) {                                                   \
-            if (i < 16) a += (d ^ (b & (c ^ d)))  + X[       i  & 15];  \
-            else        a += ((d & b) | (~d & c)) + X[(1 + 5*i) & 15];  \
+            if (i < 16)                                                 \
+                a += (d ^ (b & (c ^ d)))  + X[       i  & 15];          \
+            else                                                        \
+                a += ((d & b) | (~d & c)) + X[(1 + 5*i) & 15];          \
         } else {                                                        \
-            if (i < 48) a += (b ^ c ^ d)          + X[(5 + 3*i) & 15];  \
-            else        a += (c ^ (b | ~d))       + X[(    7*i) & 15];  \
+            if (i < 48)                                                 \
+                a += (b ^ c ^ d)          + X[(5 + 3*i) & 15];          \
+            else                                                        \
+                a += (c ^ (b | ~d))       + X[(    7*i) & 15];          \
         }                                                               \
         a = b + (a << t | a >> (32 - t));                               \
     } while (0)
@@ -122,10 +128,13 @@ static void body(uint32_t ABCD[4], uint32_t *src, int nblocks)
         }
 #else
 #define CORE2(i)                                                        \
-        CORE( i,   a,b,c,d); CORE((i+1),d,a,b,c);                       \
-        CORE((i+2),c,d,a,b); CORE((i+3),b,c,d,a)
-#define CORE4(i) CORE2(i); CORE2((i+4)); CORE2((i+8)); CORE2((i+12))
-        CORE4(0); CORE4(16); CORE4(32); CORE4(48);
+        CORE(i, a, b, c, d); CORE((i + 1), d, a, b, c);                 \
+        CORE((i + 2), c, d, a, b); CORE((i + 3), b, c, d, a)
+#define CORE4(i) CORE2(i); CORE2((i + 4)); CORE2((i + 8)); CORE2((i + 12))
+        CORE4(0);
+        CORE4(16);
+        CORE4(32);
+        CORE4(48);
 #endif
 
         ABCD[0] += d;
@@ -150,7 +159,7 @@ void av_md5_update(AVMD5 *ctx, const uint8_t *src, int len)
     const uint8_t *end;
     int j;
 
-    j = ctx->len & 63;
+    j         = ctx->len & 63;
     ctx->len += len;
 
     if (j) {
@@ -189,10 +198,10 @@ void av_md5_final(AVMD5 *ctx, uint8_t *dst)
     while ((ctx->len & 63) != 56)
         av_md5_update(ctx, "", 1);
 
-    av_md5_update(ctx, (uint8_t *)&finalcount, 8);
+    av_md5_update(ctx, (uint8_t *) &finalcount, 8);
 
     for (i = 0; i < 4; i++)
-        AV_WL32(dst + 4*i, ctx->ABCD[3 - i]);
+        AV_WL32(dst + 4 * i, ctx->ABCD[3 - i]);
 }
 
 void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len)
@@ -215,7 +224,8 @@ static void print_md5(uint8_t *md5)
     printf("\n");
 }
 
-int main(void){
+int main(void)
+{
     uint8_t md5val[16];
     int i;
     volatile uint8_t in[1000]; // volatile to workaround http://llvm.org/bugs/show_bug.cgi?id=20849
@@ -223,13 +233,18 @@ int main(void){
 
     for (i = 0; i < 1000; i++)
         in[i] = i * i;
-    av_md5_sum(md5val, in, 1000); print_md5(md5val);
-    av_md5_sum(md5val, in,   63); print_md5(md5val);
-    av_md5_sum(md5val, in,   64); print_md5(md5val);
-    av_md5_sum(md5val, in,   65); print_md5(md5val);
+    av_md5_sum(md5val, in, 1000);
+    print_md5(md5val);
+    av_md5_sum(md5val, in, 63);
+    print_md5(md5val);
+    av_md5_sum(md5val, in, 64);
+    print_md5(md5val);
+    av_md5_sum(md5val, in, 65);
+    print_md5(md5val);
     for (i = 0; i < 1000; i++)
         in[i] = i % 127;
-    av_md5_sum(md5val, in,  999); print_md5(md5val);
+    av_md5_sum(md5val, in, 999);
+    print_md5(md5val);
 
     return 0;
 }
diff --git a/libavutil/opt.c b/libavutil/opt.c
index cbe36df..ae92da0 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -30,13 +30,13 @@
 #include "avstring.h"
 #include "channel_layout.h"
 #include "common.h"
-#include "opt.h"
-#include "eval.h"
 #include "dict.h"
+#include "eval.h"
 #include "log.h"
 #include "parseutils.h"
 #include "pixdesc.h"
 #include "mathematics.h"
+#include "opt.h"
 #include "samplefmt.h"
 #include "bprint.h"
 
@@ -58,20 +58,37 @@ const AVOption *av_opt_next(const void *obj, const AVOption *last)
 static int read_number(const AVOption *o, const void *dst, double *num, int *den, int64_t *intnum)
 {
     switch (o->type) {
-    case AV_OPT_TYPE_FLAGS:     *intnum = *(unsigned int*)dst;return 0;
-    case AV_OPT_TYPE_PIXEL_FMT: *intnum = *(enum AVPixelFormat *)dst;return 0;
-    case AV_OPT_TYPE_SAMPLE_FMT:*intnum = *(enum AVSampleFormat*)dst;return 0;
+    case AV_OPT_TYPE_FLAGS:
+        *intnum = *(unsigned int*)dst;
+        return 0;
+    case AV_OPT_TYPE_PIXEL_FMT:
+        *intnum = *(enum AVPixelFormat *)dst;
+        return 0;
+    case AV_OPT_TYPE_SAMPLE_FMT:
+        *intnum = *(enum AVSampleFormat *)dst;
+        return 0;
     case AV_OPT_TYPE_BOOL:
-    case AV_OPT_TYPE_INT:       *intnum = *(int         *)dst;return 0;
+    case AV_OPT_TYPE_INT:
+        *intnum = *(int *)dst;
+        return 0;
     case AV_OPT_TYPE_CHANNEL_LAYOUT:
     case AV_OPT_TYPE_DURATION:
-    case AV_OPT_TYPE_INT64:     *intnum = *(int64_t     *)dst;return 0;
-    case AV_OPT_TYPE_FLOAT:     *num    = *(float       *)dst;return 0;
-    case AV_OPT_TYPE_DOUBLE:    *num    = *(double      *)dst;return 0;
-    case AV_OPT_TYPE_RATIONAL:  *intnum = ((AVRational*)dst)->num;
-                                *den    = ((AVRational*)dst)->den;
-                                                        return 0;
-    case AV_OPT_TYPE_CONST:     *num    = o->default_val.dbl; return 0;
+    case AV_OPT_TYPE_INT64:
+        *intnum = *(int64_t *)dst;
+        return 0;
+    case AV_OPT_TYPE_FLOAT:
+        *num = *(float *)dst;
+        return 0;
+    case AV_OPT_TYPE_DOUBLE:
+        *num = *(double *)dst;
+        return 0;
+    case AV_OPT_TYPE_RATIONAL:
+        *intnum = ((AVRational *)dst)->num;
+        *den    = ((AVRational *)dst)->den;
+        return 0;
+    case AV_OPT_TYPE_CONST:
+        *num = o->default_val.dbl;
+        return 0;
     }
     return AVERROR(EINVAL);
 }
@@ -80,7 +97,7 @@ static int write_number(void *obj, const AVOption *o, void *dst, double num, int
 {
     if (o->type != AV_OPT_TYPE_FLAGS &&
         (o->max * den < num * intnum || o->min * den > num * intnum)) {
-        num = den ? num*intnum/den : (num*intnum ? INFINITY : NAN);
+        num = den ? num * intnum / den : (num * intnum ? INFINITY : NAN);
         av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n",
                num, o->name, o->min, o->max);
         return AVERROR(ERANGE);
@@ -96,19 +113,33 @@ static int write_number(void *obj, const AVOption *o, void *dst, double num, int
     }
 
     switch (o->type) {
-    case AV_OPT_TYPE_PIXEL_FMT: *(enum AVPixelFormat *)dst = llrint(num/den) * intnum; break;
-    case AV_OPT_TYPE_SAMPLE_FMT:*(enum AVSampleFormat*)dst = llrint(num/den) * intnum; break;
+    case AV_OPT_TYPE_PIXEL_FMT:
+        *(enum AVPixelFormat *)dst = llrint(num / den) * intnum;
+        break;
+    case AV_OPT_TYPE_SAMPLE_FMT:
+        *(enum AVSampleFormat *)dst = llrint(num / den) * intnum;
+        break;
     case AV_OPT_TYPE_BOOL:
     case AV_OPT_TYPE_FLAGS:
-    case AV_OPT_TYPE_INT:   *(int       *)dst= llrint(num/den)*intnum; break;
+    case AV_OPT_TYPE_INT:
+        *(int *)dst = llrint(num / den) * intnum;
+        break;
     case AV_OPT_TYPE_DURATION:
     case AV_OPT_TYPE_CHANNEL_LAYOUT:
-    case AV_OPT_TYPE_INT64: *(int64_t   *)dst= llrint(num/den)*intnum; break;
-    case AV_OPT_TYPE_FLOAT: *(float     *)dst= num*intnum/den;         break;
-    case AV_OPT_TYPE_DOUBLE:*(double    *)dst= num*intnum/den;         break;
+    case AV_OPT_TYPE_INT64:
+        *(int64_t *)dst = llrint(num / den) * intnum;
+        break;
+    case AV_OPT_TYPE_FLOAT:
+        *(float *)dst = num * intnum / den;
+        break;
+    case AV_OPT_TYPE_DOUBLE:
+        *(double    *)dst = num * intnum / den;
+        break;
     case AV_OPT_TYPE_RATIONAL:
-        if ((int)num == num) *(AVRational*)dst= (AVRational){num*intnum, den};
-        else                 *(AVRational*)dst= av_d2q(num*intnum/den, 1<<24);
+        if ((int) num == num)
+            *(AVRational *)dst = (AVRational) { num *intnum, den };
+        else
+            *(AVRational *)dst = av_d2q(num * intnum / den, 1 << 24);
         break;
     default:
         return AVERROR(EINVAL);
@@ -117,9 +148,12 @@ static int write_number(void *obj, const AVOption *o, void *dst, double num, int
 }
 
 static int hexchar2int(char c) {
-    if (c >= '0' && c <= '9') return c - '0';
-    if (c >= 'a' && c <= 'f') return c - 'a' + 10;
-    if (c >= 'A' && c <= 'F') return c - 'A' + 10;
+    if (c >= '0' && c <= '9')
+        return c - '0';
+    if (c >= 'a' && c <= 'f')
+        return c - 'a' + 10;
+    if (c >= 'A' && c <= 'F')
+        return c - 'A' + 10;
     return -1;
 }
 
@@ -151,7 +185,7 @@ static int set_string_binary(void *obj, const AVOption *o, const char *val, uint
         }
         *ptr++ = (a << 4) | b;
     }
-    *dst = bin;
+    *dst    = bin;
     *lendst = len;
 
     return 0;
@@ -167,8 +201,9 @@ static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **d
 #define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \
                               opt->type == AV_OPT_TYPE_CONST || \
                               opt->type == AV_OPT_TYPE_FLAGS || \
-                              opt->type == AV_OPT_TYPE_INT) ? \
-                             opt->default_val.i64 : opt->default_val.dbl)
+                              opt->type == AV_OPT_TYPE_INT)     \
+                             ? opt->default_val.i64             \
+                             : opt->default_val.dbl)
 
 static int set_string_number(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
 {
@@ -243,8 +278,10 @@ static int set_string_number(void *obj, void *target_obj, const AVOption *o, con
         }
         if (o->type == AV_OPT_TYPE_FLAGS) {
             read_number(o, dst, NULL, NULL, &intnum);
-            if      (cmd == '+') d = intnum | (int64_t)d;
-            else if (cmd == '-') d = intnum &~(int64_t)d;
+            if (cmd == '+')
+                d = intnum | (int64_t)d;
+            else if (cmd == '-')
+                d = intnum &~(int64_t)d;
         }
 
         if ((ret = write_number(obj, o, dst, d, 1, 1)) < 0)
@@ -407,21 +444,29 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
     if (o->flags & AV_OPT_FLAG_READONLY)
         return AVERROR(EINVAL);
 
-    dst = ((uint8_t*)target_obj) + o->offset;
+    dst = ((uint8_t *)target_obj) + o->offset;
     switch (o->type) {
-    case AV_OPT_TYPE_BOOL:     return set_string_bool(obj, o, val, dst);
-    case AV_OPT_TYPE_STRING:   return set_string(obj, o, val, dst);
-    case AV_OPT_TYPE_BINARY:   return set_string_binary(obj, o, val, dst);
+    case AV_OPT_TYPE_BOOL:
+        return set_string_bool(obj, o, val, dst);
+    case AV_OPT_TYPE_STRING:
+        return set_string(obj, o, val, dst);
+    case AV_OPT_TYPE_BINARY:
+        return set_string_binary(obj, o, val, dst);
     case AV_OPT_TYPE_FLAGS:
     case AV_OPT_TYPE_INT:
     case AV_OPT_TYPE_INT64:
     case AV_OPT_TYPE_FLOAT:
     case AV_OPT_TYPE_DOUBLE:
-    case AV_OPT_TYPE_RATIONAL: return set_string_number(obj, target_obj, o, val, dst);
-    case AV_OPT_TYPE_IMAGE_SIZE: return set_string_image_size(obj, o, val, dst);
-    case AV_OPT_TYPE_VIDEO_RATE: return set_string_video_rate(obj, o, val, dst);
-    case AV_OPT_TYPE_PIXEL_FMT:  return set_string_pixel_fmt(obj, o, val, dst);
-    case AV_OPT_TYPE_SAMPLE_FMT: return set_string_sample_fmt(obj, o, val, dst);
+    case AV_OPT_TYPE_RATIONAL:
+        return set_string_number(obj, target_obj, o, val, dst);
+    case AV_OPT_TYPE_IMAGE_SIZE:
+        return set_string_image_size(obj, o, val, dst);
+    case AV_OPT_TYPE_VIDEO_RATE:
+        return set_string_video_rate(obj, o, val, dst);
+    case AV_OPT_TYPE_PIXEL_FMT:
+        return set_string_pixel_fmt(obj, o, val, dst);
+    case AV_OPT_TYPE_SAMPLE_FMT:
+        return set_string_sample_fmt(obj, o, val, dst);
     case AV_OPT_TYPE_DURATION:
         if (!val) {
             *(int64_t *)dst = 0;
@@ -432,7 +477,8 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
             return ret;
         }
         break;
-    case AV_OPT_TYPE_COLOR:      return set_string_color(obj, o, val, dst);
+    case AV_OPT_TYPE_COLOR:
+        return set_string_color(obj, o, val, dst);
     case AV_OPT_TYPE_CHANNEL_LAYOUT:
         if (!val || !strcmp(val, "none")) {
             *(int64_t *)dst = 0;
@@ -452,13 +498,14 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
     return AVERROR(EINVAL);
 }
 
-#define OPT_EVAL_NUMBER(name, opttype, vartype)\
-    int av_opt_eval_ ## name(void *obj, const AVOption *o, const char *val, vartype *name ## _out)\
-    {\
-        if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY)\
-            return AVERROR(EINVAL);\
-        return set_string_number(obj, obj, o, val, name ## _out);\
-    }
+#define OPT_EVAL_NUMBER(name, opttype, vartype)                         \
+int av_opt_eval_ ## name(void *obj, const AVOption *o,                  \
+                         const char *val, vartype *name ## _out)        \
+{                                                                       \
+    if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY)    \
+        return AVERROR(EINVAL);                                         \
+    return set_string_number(obj, obj, o, val, name ## _out);           \
+}
 
 OPT_EVAL_NUMBER(flags,  AV_OPT_TYPE_FLAGS,    int)
 OPT_EVAL_NUMBER(int,    AV_OPT_TYPE_INT,      int)
@@ -468,7 +515,7 @@ OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE,   double)
 OPT_EVAL_NUMBER(q,      AV_OPT_TYPE_RATIONAL, AVRational)
 
 static int set_number(void *obj, const char *name, double num, int den, int64_t intnum,
-                                  int search_flags)
+                      int search_flags)
 {
     void *dst, *target_obj;
     const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
@@ -479,7 +526,7 @@ static int set_number(void *obj, const char *name, double num, int den, int64_t
     if (o->flags & AV_OPT_FLAG_READONLY)
         return AVERROR(EINVAL);
 
-    dst = ((uint8_t*)target_obj) + o->offset;
+    dst = ((uint8_t *)target_obj) + o->offset;
     return write_number(obj, o, dst, num, den, intnum);
 }
 
@@ -516,11 +563,11 @@ int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int
     if (len && !ptr)
         return AVERROR(ENOMEM);
 
-    dst = (uint8_t **)(((uint8_t *)target_obj) + o->offset);
+    dst    = (uint8_t **)(((uint8_t *)target_obj) + o->offset);
     lendst = (int *)(dst + 1);
 
     av_free(*dst);
-    *dst = ptr;
+    *dst    = ptr;
     *lendst = len;
     if (len)
         memcpy(ptr, val, len);
@@ -622,7 +669,8 @@ int av_opt_set_channel_layout(void *obj, const char *name, int64_t cl, int searc
     return 0;
 }
 
-int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, int search_flags)
+int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val,
+                        int search_flags)
 {
     void *target_obj;
     AVDictionary **dst;
@@ -686,24 +734,38 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
     if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST))
         return AVERROR_OPTION_NOT_FOUND;
 
-    dst = (uint8_t*)target_obj + o->offset;
+    dst = (uint8_t *)target_obj + o->offset;
 
     buf[0] = 0;
     switch (o->type) {
     case AV_OPT_TYPE_BOOL:
         ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(get_bool_name(*(int *)dst), "invalid"));
         break;
-    case AV_OPT_TYPE_FLAGS:     ret = snprintf(buf, sizeof(buf), "0x%08X",  *(int    *)dst);break;
-    case AV_OPT_TYPE_INT:       ret = snprintf(buf, sizeof(buf), "%d" ,     *(int    *)dst);break;
-    case AV_OPT_TYPE_INT64:     ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t*)dst);break;
-    case AV_OPT_TYPE_FLOAT:     ret = snprintf(buf, sizeof(buf), "%f" ,     *(float  *)dst);break;
-    case AV_OPT_TYPE_DOUBLE:    ret = snprintf(buf, sizeof(buf), "%f" ,     *(double *)dst);break;
+    case AV_OPT_TYPE_FLAGS:
+        ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);
+        break;
+    case AV_OPT_TYPE_INT:
+        ret = snprintf(buf, sizeof(buf), "%d", *(int *)dst);
+        break;
+    case AV_OPT_TYPE_INT64:
+        ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t *)dst);
+        break;
+    case AV_OPT_TYPE_FLOAT:
+        ret = snprintf(buf, sizeof(buf), "%f", *(float *)dst);
+        break;
+    case AV_OPT_TYPE_DOUBLE:
+        ret = snprintf(buf, sizeof(buf), "%f", *(double *)dst);
+        break;
     case AV_OPT_TYPE_VIDEO_RATE:
-    case AV_OPT_TYPE_RATIONAL:  ret = snprintf(buf, sizeof(buf), "%d/%d",   ((AVRational*)dst)->num, ((AVRational*)dst)->den);break;
-    case AV_OPT_TYPE_CONST:     ret = snprintf(buf, sizeof(buf), "%f" ,     o->default_val.dbl);break;
+    case AV_OPT_TYPE_RATIONAL:
+        ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational *)dst)->num, ((AVRational *)dst)->den);
+        break;
+    case AV_OPT_TYPE_CONST:
+        ret = snprintf(buf, sizeof(buf), "%f", o->default_val.dbl);
+        break;
     case AV_OPT_TYPE_STRING:
-        if (*(uint8_t**)dst) {
-            *out_val = av_strdup(*(uint8_t**)dst);
+        if (*(uint8_t **)dst) {
+            *out_val = av_strdup(*(uint8_t **)dst);
         } else if (search_flags & AV_OPT_ALLOW_NULL) {
             *out_val = NULL;
             return 0;
@@ -712,22 +774,22 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
         }
         return *out_val ? 0 : AVERROR(ENOMEM);
     case AV_OPT_TYPE_BINARY:
-        if (!*(uint8_t**)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
+        if (!*(uint8_t **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
             *out_val = NULL;
             return 0;
         }
-        len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *));
-        if ((uint64_t)len*2 + 1 > INT_MAX)
+        len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *));
+        if ((uint64_t)len * 2 + 1 > INT_MAX)
             return AVERROR(EINVAL);
-        if (!(*out_val = av_malloc(len*2 + 1)))
+        if (!(*out_val = av_malloc(len * 2 + 1)))
             return AVERROR(ENOMEM);
         if (!len) {
             *out_val[0] = '\0';
             return 0;
         }
-        bin = *(uint8_t**)dst;
+        bin = *(uint8_t **)dst;
         for (i = 0; i < len; i++)
-            snprintf(*out_val + i*2, 3, "%02X", bin[i]);
+            snprintf(*out_val + i * 2, 3, "%02X", bin[i]);
         return 0;
     case AV_OPT_TYPE_IMAGE_SIZE:
         ret = snprintf(buf, sizeof(buf), "%dx%d", ((int *)dst)[0], ((int *)dst)[1]);
@@ -770,46 +832,47 @@ static int get_number(void *obj, const char *name, const AVOption **o_out, doubl
     if (!o || !target_obj)
         goto error;
 
-    dst = ((uint8_t*)target_obj) + o->offset;
+    dst = ((uint8_t *)target_obj) + o->offset;
 
     if (o_out) *o_out= o;
 
     return read_number(o, dst, num, den, intnum);
 
 error:
-    *den=*intnum=0;
+    *den    =
+    *intnum = 0;
     return -1;
 }
 
 int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
 {
     int64_t intnum = 1;
-    double     num = 1;
-    int   ret, den = 1;
+    double num = 1;
+    int ret, den = 1;
 
     if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
         return ret;
-    *out_val = num*intnum/den;
+    *out_val = num * intnum / den;
     return 0;
 }
 
 int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
 {
     int64_t intnum = 1;
-    double     num = 1;
-    int   ret, den = 1;
+    double num = 1;
+    int ret, den = 1;
 
     if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
         return ret;
-    *out_val = num*intnum/den;
+    *out_val = num * intnum / den;
     return 0;
 }
 
 int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
 {
     int64_t intnum = 1;
-    double     num = 1;
-    int   ret, den = 1;
+    double num = 1;
+    int ret, den = 1;
 
     if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
         return ret;
@@ -849,9 +912,9 @@ int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRatio
         return ret;
 
     if (num == 1.0 && (int)intnum == intnum)
-        *out_val = (AVRational){intnum, den};
+        *out_val = (AVRational) { intnum, den };
     else
-        *out_val = av_d2q(num*intnum/den, 1<<24);
+        *out_val = av_d2q(num * intnum / den, 1 << 24);
     return 0;
 }
 
@@ -1000,7 +1063,7 @@ static char *get_opt_flags_string(void *obj, const char *unit, int64_t value)
 static void opt_list(void *obj, void *av_log_obj, const char *unit,
                      int req_flags, int rej_flags)
 {
-    const AVOption *opt=NULL;
+    const AVOption *opt = NULL;
     AVOptionRanges *r;
     int i;
 
@@ -1012,11 +1075,11 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
          * Don't print anything but CONST's on level two.
          * Only print items from the requested unit.
          */
-        if (!unit && opt->type==AV_OPT_TYPE_CONST)
+        if (!unit && opt->type == AV_OPT_TYPE_CONST)
             continue;
-        else if (unit && opt->type!=AV_OPT_TYPE_CONST)
+        else if (unit && opt->type != AV_OPT_TYPE_CONST)
             continue;
-        else if (unit && opt->type==AV_OPT_TYPE_CONST && strcmp(unit, opt->unit))
+        else if (unit && opt->type == AV_OPT_TYPE_CONST && strcmp(unit, opt->unit))
             continue;
         else if (unit && opt->type == AV_OPT_TYPE_CONST)
             av_log(av_log_obj, AV_LOG_INFO, "     %-15s ", opt->name);
@@ -1175,9 +1238,8 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
         }
 
         av_log(av_log_obj, AV_LOG_INFO, "\n");
-        if (opt->unit && opt->type != AV_OPT_TYPE_CONST) {
+        if (opt->unit && opt->type != AV_OPT_TYPE_CONST)
             opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags);
-        }
     }
 }
 
@@ -1186,7 +1248,7 @@ int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
     if (!obj)
         return -1;
 
-    av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass**)obj)->class_name);
+    av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass **)obj)->class_name);
 
     opt_list(obj, av_log_obj, NULL, req_flags, rej_flags);
 
@@ -1213,7 +1275,7 @@ void av_opt_set_defaults2(void *s, int mask, int flags)
         switch (opt->type) {
             case AV_OPT_TYPE_CONST:
                 /* Nothing to be done here */
-            break;
+                break;
             case AV_OPT_TYPE_BOOL:
             case AV_OPT_TYPE_FLAGS:
             case AV_OPT_TYPE_INT:
@@ -1255,8 +1317,9 @@ void av_opt_set_defaults2(void *s, int mask, int flags)
             case AV_OPT_TYPE_DICT:
                 /* Cannot set defaults for these types */
             break;
-            default:
-                av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", opt->type, opt->name);
+        default:
+            av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n",
+                   opt->type, opt->name);
         }
     }
 }
@@ -1546,7 +1609,7 @@ const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
 
 void *av_opt_child_next(void *obj, void *prev)
 {
-    const AVClass *c = *(AVClass**)obj;
+    const AVClass *c = *(AVClass **)obj;
     if (c->child_next)
         return c->child_next(obj, prev);
     return NULL;
@@ -1572,20 +1635,31 @@ static int opt_size(enum AVOptionType type)
     switch(type) {
     case AV_OPT_TYPE_BOOL:
     case AV_OPT_TYPE_INT:
-    case AV_OPT_TYPE_FLAGS:     return sizeof(int);
+    case AV_OPT_TYPE_FLAGS:
+        return sizeof(int);
     case AV_OPT_TYPE_DURATION:
     case AV_OPT_TYPE_CHANNEL_LAYOUT:
-    case AV_OPT_TYPE_INT64:     return sizeof(int64_t);
-    case AV_OPT_TYPE_DOUBLE:    return sizeof(double);
-    case AV_OPT_TYPE_FLOAT:     return sizeof(float);
-    case AV_OPT_TYPE_STRING:    return sizeof(uint8_t*);
+    case AV_OPT_TYPE_INT64:
+        return sizeof(int64_t);
+    case AV_OPT_TYPE_DOUBLE:
+        return sizeof(double);
+    case AV_OPT_TYPE_FLOAT:
+        return sizeof(float);
+    case AV_OPT_TYPE_STRING:
+        return sizeof(uint8_t*);
     case AV_OPT_TYPE_VIDEO_RATE:
-    case AV_OPT_TYPE_RATIONAL:  return sizeof(AVRational);
-    case AV_OPT_TYPE_BINARY:    return sizeof(uint8_t*) + sizeof(int);
-    case AV_OPT_TYPE_IMAGE_SIZE:return sizeof(int[2]);
-    case AV_OPT_TYPE_PIXEL_FMT: return sizeof(enum AVPixelFormat);
-    case AV_OPT_TYPE_SAMPLE_FMT:return sizeof(enum AVSampleFormat);
-    case AV_OPT_TYPE_COLOR:     return 4;
+    case AV_OPT_TYPE_RATIONAL:
+        return sizeof(AVRational);
+    case AV_OPT_TYPE_BINARY:
+        return sizeof(uint8_t*) + sizeof(int);
+    case AV_OPT_TYPE_IMAGE_SIZE:
+        return sizeof(int[2]);
+    case AV_OPT_TYPE_PIXEL_FMT:
+        return sizeof(enum AVPixelFormat);
+    case AV_OPT_TYPE_SAMPLE_FMT:
+        return sizeof(enum AVSampleFormat);
+    case AV_OPT_TYPE_COLOR:
+        return 4;
     }
     return AVERROR(EINVAL);
 }
@@ -1599,15 +1673,15 @@ int av_opt_copy(void *dst, const void *src)
     if (!src)
         return AVERROR(EINVAL);
 
-    c = *(AVClass**)src;
-    if (!c || c != *(AVClass**)dst)
+    c = *(AVClass **)src;
+    if (!c || c != *(AVClass **)dst)
         return AVERROR(EINVAL);
 
     while ((o = av_opt_next(src, o))) {
-        void *field_dst = ((uint8_t*)dst) + o->offset;
-        void *field_src = ((uint8_t*)src) + o->offset;
-        uint8_t **field_dst8 = (uint8_t**)field_dst;
-        uint8_t **field_src8 = (uint8_t**)field_src;
+        void *field_dst = (uint8_t *)dst + o->offset;
+        void *field_src = (uint8_t *)src + o->offset;
+        uint8_t **field_dst8 = (uint8_t **)field_dst;
+        uint8_t **field_src8 = (uint8_t **)field_src;
 
         if (o->type == AV_OPT_TYPE_STRING) {
             if (*field_dst8 != *field_src8)
@@ -1616,7 +1690,7 @@ int av_opt_copy(void *dst, const void *src)
             if (*field_src8 && !*field_dst8)
                 ret = AVERROR(ENOMEM);
         } else if (o->type == AV_OPT_TYPE_BINARY) {
-            int len = *(int*)(field_src8 + 1);
+            int len = *(int *)(field_src8 + 1);
             if (*field_dst8 != *field_src8)
                 av_freep(field_dst8);
             *field_dst8 = av_memdup(*field_src8, len);
@@ -1624,7 +1698,7 @@ int av_opt_copy(void *dst, const void *src)
                 ret = AVERROR(ENOMEM);
                 len = 0;
             }
-            *(int*)(field_dst8 + 1) = len;
+            *(int *)(field_dst8 + 1) = len;
         } else if (o->type == AV_OPT_TYPE_CONST) {
             // do nothing
         } else if (o->type == AV_OPT_TYPE_DICT) {
@@ -1915,8 +1989,7 @@ int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer,
 
 #ifdef TEST
 
-typedef struct TestContext
-{
+typedef struct TestContext {
     const AVClass *class;
     int num;
     int toggle;
@@ -1952,32 +2025,32 @@ typedef struct TestContext
 #define TEST_FLAG_MU   04
 
 static const AVOption test_options[]= {
-{"num",      "set num",        OFFSET(num),      AV_OPT_TYPE_INT,      {.i64 = 0},       0,        100, 1              },
-{"toggle",   "set toggle",     OFFSET(toggle),   AV_OPT_TYPE_INT,      {.i64 = 1},       0,        1,   1              },
-{"rational", "set rational",   OFFSET(rational), AV_OPT_TYPE_RATIONAL, {.dbl = 1},       0,        10,  1              },
-{"string",   "set string",     OFFSET(string),   AV_OPT_TYPE_STRING,   {.str = "default"}, CHAR_MIN, CHAR_MAX, 1       },
-{"escape",   "set escape str", OFFSET(escape),   AV_OPT_TYPE_STRING,   {.str = "\\=,"}, CHAR_MIN, CHAR_MAX, 1          },
-{"flags",    "set flags",      OFFSET(flags),    AV_OPT_TYPE_FLAGS,    {.i64 = 1},       0,        INT_MAX, 1, "flags" },
-{"cool",     "set cool flag",  0,                AV_OPT_TYPE_CONST,    {.i64 = TEST_FLAG_COOL}, INT_MIN,  INT_MAX, 1, "flags" },
-{"lame",     "set lame flag",  0,                AV_OPT_TYPE_CONST,    {.i64 = TEST_FLAG_LAME}, INT_MIN,  INT_MAX, 1, "flags" },
-{"mu",       "set mu flag",    0,                AV_OPT_TYPE_CONST,    {.i64 = TEST_FLAG_MU},   INT_MIN,  INT_MAX, 1, "flags" },
-{"size",     "set size",       OFFSET(w),        AV_OPT_TYPE_IMAGE_SIZE,{.str="200x300"},             0,        0, 1},
-{"pix_fmt",  "set pixfmt",     OFFSET(pix_fmt),  AV_OPT_TYPE_PIXEL_FMT, {.i64 = AV_PIX_FMT_0BGR}, -1, INT_MAX, 1},
-{"sample_fmt", "set samplefmt", OFFSET(sample_fmt), AV_OPT_TYPE_SAMPLE_FMT, {.i64 = AV_SAMPLE_FMT_S16}, -1, INT_MAX, 1},
-{"video_rate", "set videorate", OFFSET(video_rate), AV_OPT_TYPE_VIDEO_RATE,  {.str = "25"}, 0,     0                   , 1},
-{"duration", "set duration",   OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = 1000}, 0, INT64_MAX, 1},
-{"color", "set color",   OFFSET(color), AV_OPT_TYPE_COLOR, {.str = "pink"}, 0, 0, 1},
-{"cl", "set channel layout", OFFSET(channel_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64 = AV_CH_LAYOUT_HEXAGONAL}, 0, INT64_MAX, 1},
-{"bin", "set binary value",    OFFSET(binary),   AV_OPT_TYPE_BINARY,   {.str="62696e00"}, 0,        0, 1 },
-{"bin1", "set binary value",   OFFSET(binary1),  AV_OPT_TYPE_BINARY,   {.str=NULL},       0,        0, 1 },
-{"bin2", "set binary value",   OFFSET(binary2),  AV_OPT_TYPE_BINARY,   {.str=""},         0,        0, 1 },
-{"num64",    "set num 64bit",  OFFSET(num64),    AV_OPT_TYPE_INT64,    {.i64 = 1},        0,        100, 1 },
-{"flt",      "set float",      OFFSET(flt),      AV_OPT_TYPE_FLOAT,    {.dbl = 1.0/3},    0,        100, 1},
-{"dbl",      "set double",     OFFSET(dbl),      AV_OPT_TYPE_DOUBLE,   {.dbl = 1.0/3},    0,        100, 1 },
-{"bool1", "set boolean value",  OFFSET(bool1),   AV_OPT_TYPE_BOOL,     {.i64 = -1},      -1,        1, 1 },
-{"bool2", "set boolean value",  OFFSET(bool2),   AV_OPT_TYPE_BOOL,     {.i64 = 1},       -1,        1, 1 },
-{"bool3", "set boolean value",  OFFSET(bool3),   AV_OPT_TYPE_BOOL,     {.i64 = 0},        0,        1, 1 },
-{NULL},
+    {"num",        "set num",            OFFSET(num),            AV_OPT_TYPE_INT,            { .i64 = 0 },                      0,       100, 1 },
+    {"toggle",     "set toggle",         OFFSET(toggle),         AV_OPT_TYPE_INT,            { .i64 = 1 },                      0,         1, 1 },
+    {"rational",   "set rational",       OFFSET(rational),       AV_OPT_TYPE_RATIONAL,       { .dbl = 1 },                      0,        10, 1 },
+    {"string",     "set string",         OFFSET(string),         AV_OPT_TYPE_STRING,         { .str = "default" },       CHAR_MIN,  CHAR_MAX, 1 },
+    {"escape",     "set escape str",     OFFSET(escape),         AV_OPT_TYPE_STRING,         { .str = "\\=," },          CHAR_MIN,  CHAR_MAX, 1 },
+    {"flags",      "set flags",          OFFSET(flags),          AV_OPT_TYPE_FLAGS,          { .i64 = 1 },                      0,   INT_MAX, 1, "flags" },
+    {"cool",       "set cool flag",      0,                      AV_OPT_TYPE_CONST,          { .i64 = TEST_FLAG_COOL },   INT_MIN,   INT_MAX, 1, "flags" },
+    {"lame",       "set lame flag",      0,                      AV_OPT_TYPE_CONST,          { .i64 = TEST_FLAG_LAME },   INT_MIN,   INT_MAX, 1, "flags" },
+    {"mu",         "set mu flag",        0,                      AV_OPT_TYPE_CONST,          { .i64 = TEST_FLAG_MU },     INT_MIN,   INT_MAX, 1, "flags" },
+    {"size",       "set size",           OFFSET(w),              AV_OPT_TYPE_IMAGE_SIZE,     { .str="200x300" },                0,         0, 1 },
+    {"pix_fmt",    "set pixfmt",         OFFSET(pix_fmt),        AV_OPT_TYPE_PIXEL_FMT,      { .i64 = AV_PIX_FMT_0BGR },       -1,   INT_MAX, 1 },
+    {"sample_fmt", "set samplefmt",      OFFSET(sample_fmt),     AV_OPT_TYPE_SAMPLE_FMT,     { .i64 = AV_SAMPLE_FMT_S16 },     -1,   INT_MAX, 1 },
+    {"video_rate", "set videorate",      OFFSET(video_rate),     AV_OPT_TYPE_VIDEO_RATE,     { .str = "25" },                   0,         0, 1 },
+    {"duration",   "set duration",       OFFSET(duration),       AV_OPT_TYPE_DURATION,       { .i64 = 1000 },                   0, INT64_MAX, 1 },
+    {"color",      "set color",          OFFSET(color),          AV_OPT_TYPE_COLOR,          { .str = "pink" },                 0,         0, 1 },
+    {"cl",         "set channel layout", OFFSET(channel_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, { .i64 = AV_CH_LAYOUT_HEXAGONAL }, 0, INT64_MAX, 1 },
+    {"bin",        "set binary value",   OFFSET(binary),         AV_OPT_TYPE_BINARY,         { .str="62696e00" },               0,         0, 1 },
+    {"bin1",       "set binary value",   OFFSET(binary1),        AV_OPT_TYPE_BINARY,         { .str=NULL },                     0,         0, 1 },
+    {"bin2",       "set binary value",   OFFSET(binary2),        AV_OPT_TYPE_BINARY,         { .str="" },                       0,         0, 1 },
+    {"num64",      "set num 64bit",      OFFSET(num64),          AV_OPT_TYPE_INT64,          { .i64 = 1 },                      0,       100, 1 },
+    {"flt",        "set float",          OFFSET(flt),            AV_OPT_TYPE_FLOAT,          { .dbl = 1.0 / 3 },                0,       100, 1 },
+    {"dbl",        "set double",         OFFSET(dbl),            AV_OPT_TYPE_DOUBLE,         { .dbl = 1.0 / 3 },                0,       100, 1 },
+    {"bool1",      "set boolean value",  OFFSET(bool1),          AV_OPT_TYPE_BOOL,           { .i64 = -1 },                    -1,         1, 1 },
+    {"bool2",      "set boolean value",  OFFSET(bool2),          AV_OPT_TYPE_BOOL,           { .i64 = 1 },                     -1,         1, 1 },
+    {"bool3",      "set boolean value",  OFFSET(bool3),          AV_OPT_TYPE_BOOL,           { .i64 = 0 },                      0,         1, 1 },
+    { NULL },
 };
 
 static const char *test_get_name(void *ctx)


======================================================================

diff --cc libavcodec/iirfilter.c
index cb5871c,fba4ac8..474f52f
--- a/libavcodec/iirfilter.c
+++ b/libavcodec/iirfilter.c
@@@ -299,26 -302,18 +302,26 @@@ void ff_iir_filter_flt(const struct FFI
      }
  }
  
 -av_cold void ff_iir_filter_free_state(struct FFIIRFilterState *state)
 +av_cold void ff_iir_filter_free_statep(struct FFIIRFilterState **state)
  {
 -    av_free(state);
 +    av_freep(state);
  }
  
 -av_cold void ff_iir_filter_free_coeffs(struct FFIIRFilterCoeffs *coeffs)
 +av_cold void ff_iir_filter_free_coeffsp(struct FFIIRFilterCoeffs **coeffsp)
  {
 +    struct FFIIRFilterCoeffs *coeffs = *coeffsp;
-     if(coeffs){
+     if (coeffs) {
 -        av_free(coeffs->cx);
 -        av_free(coeffs->cy);
 +        av_freep(&coeffs->cx);
 +        av_freep(&coeffs->cy);
      }
 -    av_free(coeffs);
 +    av_freep(coeffsp);
 +}
 +
 +void ff_iir_filter_init(FFIIRFilterContext *f) {
 +    f->filter_flt = ff_iir_filter_flt;
 +
 +    if (HAVE_MIPSFPU)
 +        ff_iir_filter_init_mips(f);
  }
  
  #ifdef TEST
diff --cc libavutil/aes.c
index 9096f03,d534bc7..15dc602
--- a/libavutil/aes.c
+++ b/libavutil/aes.c
@@@ -21,12 -21,24 +21,13 @@@
   */
  
  #include "common.h"
 +#include "aes.h"
 +#include "aes_internal.h"
  #include "intreadwrite.h"
  #include "timer.h"
+ #include "aes.h"
  
 -typedef union {
 -    uint64_t u64[2];
 -    uint32_t u32[4];
 -    uint8_t u8x4[4][4];
 -    uint8_t u8[16];
 -} av_aes_block;
 -
 -typedef struct AVAES {
 -    // Note: round_key[16] is accessed in the init code, but this only
 -    // overwrites state, which does not matter (see also commit ba554c0).
 -    av_aes_block round_key[15];
 -    av_aes_block state[2];
 -    int rounds;
 -} AVAES;
 +const int av_aes_size= sizeof(AVAES);
  
  struct AVAES *av_aes_alloc(void)
  {
@@@ -105,15 -118,16 +107,16 @@@ static inline int mix_core(uint32_t mul
  #endif
  }
  
- static inline void mix(av_aes_block state[2], uint32_t multbl[][256], int s1, int s3){
+ static inline void mix(av_aes_block state[2], uint32_t multbl[][256], int s1, int s3)
+ {
      uint8_t (*src)[4] = state[1].u8x4;
-     state[0].u32[0] = mix_core(multbl, src[0][0], src[s1  ][1], src[2][2], src[s3  ][3]);
-     state[0].u32[1] = mix_core(multbl, src[1][0], src[s3-1][1], src[3][2], src[s1-1][3]);
-     state[0].u32[2] = mix_core(multbl, src[2][0], src[s3  ][1], src[0][2], src[s1  ][3]);
-     state[0].u32[3] = mix_core(multbl, src[3][0], src[s1-1][1], src[1][2], src[s3-1][3]);
+     state[0].u32[0] = mix_core(multbl, src[0][0], src[s1    ][1], src[2][2], src[s3    ][3]);
+     state[0].u32[1] = mix_core(multbl, src[1][0], src[s3 - 1][1], src[3][2], src[s1 - 1][3]);
+     state[0].u32[2] = mix_core(multbl, src[2][0], src[s3    ][1], src[0][2], src[s1    ][3]);
+     state[0].u32[3] = mix_core(multbl, src[3][0], src[s1 - 1][1], src[1][2], src[s3 - 1][3]);
  }
  
 -static inline void crypt(AVAES *a, int s, const uint8_t *sbox,
 +static inline void aes_crypt(AVAES *a, int s, const uint8_t *sbox,
                           uint32_t multbl[][256])
  {
      int r;
@@@ -199,9 -200,7 +202,9 @@@ int av_aes_init(AVAES *a, const uint8_
      uint8_t log8[256];
      uint8_t alog8[512];
  
 +    a->crypt = decrypt ? aes_decrypt : aes_encrypt;
 +
-     if (!enc_multbl[FF_ARRAY_ELEMS(enc_multbl)-1][FF_ARRAY_ELEMS(enc_multbl[0])-1]) {
+     if (!enc_multbl[FF_ARRAY_ELEMS(enc_multbl) - 1][FF_ARRAY_ELEMS(enc_multbl[0]) - 1]) {
          j = 1;
          for (i = 0; i < 255; i++) {
              alog8[i] = alog8[i + 255] = j;
@@@ -266,8 -264,8 +268,9 @@@
  }
  
  #ifdef TEST
 +// LCOV_EXCL_START
  #include <string.h>
+ 
  #include "lfg.h"
  #include "log.h"
  
@@@ -280,7 -278,7 +283,7 @@@ int main(int argc, char **argv
          { 0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3,
            0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59 }
      };
-     uint8_t pt[32], rpt[2][16]= {
 -    uint8_t pt[16], rpt[2][16] = {
++    uint8_t pt[32], rpt[2][16] = {
          { 0x6a, 0x84, 0x86, 0x7c, 0xd7, 0x7e, 0x12, 0xad,
            0x07, 0xea, 0x1b, 0xe8, 0x95, 0xc5, 0x3f, 0xa3 },
          { 0 }
@@@ -318,20 -315,11 +321,18 @@@
          av_lfg_init(&prng, 1);
  
          for (i = 0; i < 10000; i++) {
-             for (j = 0; j < 32; j++) {
 -            for (j = 0; j < 16; j++)
++            for (j = 0; j < 32; j++)
                  pt[j] = av_lfg_get(&prng);
-             }
-             for (j = 0; j < 16; j++) {
++            for (j = 0; j < 16; j++)
 +                iv[0][j] = iv[1][j] = av_lfg_get(&prng);
-             }
              {
                  START_TIMER;
 -                av_aes_crypt(&ae, temp, pt, 1, NULL, 0);
 +                av_aes_crypt(&ae, temp, pt, 2, iv[0], 0);
 +                if (!(i & (i - 1)))
 +                    av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n",
 +                           temp[0], temp[5], temp[10], temp[15]);
 +                av_aes_crypt(&ad, temp, temp, 2, iv[1], 1);
 +                av_aes_crypt(&ae, temp, pt, 2, NULL, 0);
                  if (!(i & (i - 1)))
                      av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n",
                             temp[0], temp[5], temp[10], temp[15]);
diff --cc libavutil/crc.c
index 5a1ddf0,ad43c73..8d9cb32
--- a/libavutil/crc.c
+++ b/libavutil/crc.c
@@@ -383,13 -339,12 +384,13 @@@ int main(void
  {
      uint8_t buf[1999];
      int i;
-     unsigned
-         p[6][3] = { { AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04 },
-                     { AV_CRC_32_IEEE   , 0x04C11DB7, 0xC0F5BAE0 },
-                     { AV_CRC_24_IEEE   , 0x864CFB  , 0xB704CE   },
-                     { AV_CRC_16_ANSI_LE, 0xA001    , 0xBFD8     },
-                     { AV_CRC_16_ANSI   , 0x8005    , 0x1FBB     },
-                     { AV_CRC_8_ATM     , 0x07      , 0xE3       }
 -    int p[5][3] = {
++    unsigned p[6][3] = {
+         { AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04 },
 -        { AV_CRC_32_IEEE,    0x04C11DB7, 0xC0F5BAE0 },
 -        { AV_CRC_16_ANSI_LE,     0xA001,     0xBFD8 },
 -        { AV_CRC_16_ANSI,        0x8005,     0x1FBB },
 -        { AV_CRC_8_ATM,            0x07,       0xE3 }
++        { AV_CRC_32_IEEE   , 0x04C11DB7, 0xC0F5BAE0 },
++        { AV_CRC_24_IEEE   , 0x864CFB  , 0xB704CE   },
++        { AV_CRC_16_ANSI_LE, 0xA001    , 0xBFD8     },
++        { AV_CRC_16_ANSI   , 0x8005    , 0x1FBB     },
++        { AV_CRC_8_ATM     , 0x07      , 0xE3       }
      };
      const AVCRC *ctx;
  
diff --cc libavutil/des.c
index ec2c399,7d9458c..25f3b6f
--- a/libavutil/des.c
+++ b/libavutil/des.c
@@@ -27,7 -27,14 +27,7 @@@
  #include "mem.h"
  #include "des.h"
  
- #define T(a, b, c, d, e, f, g, h) 64-a,64-b,64-c,64-d,64-e,64-f,64-g,64-h
 -#if !FF_API_CRYPTO_CONTEXT
 -struct AVDES {
 -    uint64_t round_keys[3][16];
 -    int triple_des;
 -};
 -#endif
 -
+ #define T(a, b, c, d, e, f, g, h) 64 - a, 64 - b, 64 - c, 64 - d, 64 - e, 64 - f, 64 - g, 64 - h
  static const uint8_t IP_shuffle[] = {
      T(58, 50, 42, 34, 26, 18, 10, 2),
      T(60, 52, 44, 36, 28, 20, 12, 4),
@@@ -414,12 -413,14 +405,14 @@@ int main(void
          return 1;
      }
      for (i = 0; i < 1000; i++) {
-         key[0] = rand64(); key[1] = rand64(); key[2] = rand64();
-         data = rand64();
-         av_des_init(&d, (uint8_t*)key, 192, 0);
-         av_des_crypt(&d, (uint8_t*)&ct, (uint8_t*)&data, 1, NULL, 0);
-         av_des_init(&d, (uint8_t*)key, 192, 1);
-         av_des_crypt(&d, (uint8_t*)&ct, (uint8_t*)&ct, 1, NULL, 1);
+         key[0] = rand64();
+         key[1] = rand64();
+         key[2] = rand64();
+         data   = rand64();
 -        av_des_init(&d, key, 192, 0);
 -        av_des_crypt(&d, &ct, &data, 1, NULL, 0);
 -        av_des_init(&d, key, 192, 1);
 -        av_des_crypt(&d, &ct, &ct, 1, NULL, 1);
++        av_des_init(&d, (uint8_t *) key, 192, 0);
++        av_des_crypt(&d, (uint8_t *) &ct, (uint8_t *) &data, 1, NULL, 0);
++        av_des_init(&d, (uint8_t *) key, 192, 1);
++        av_des_crypt(&d, (uint8_t *) &ct, (uint8_t *) &ct, 1, NULL, 1);
          if (ct != data) {
              printf("Test 2 failed\n");
              return 1;
diff --cc libavutil/md5.c
index 876bd55,79224ed..482582b
--- a/libavutil/md5.c
+++ b/libavutil/md5.c
@@@ -83,11 -83,15 +85,15 @@@ static const uint32_t T[64] = { // T[i]
          a += T[i];                                                      \
                                                                          \
          if (i < 32) {                                                   \
-             if (i < 16) a += (d ^ (b & (c ^ d)))  + X[       i  & 15];  \
-             else        a += ((d & b) | (~d & c)) + X[(1 + 5*i) & 15];  \
+             if (i < 16)                                                 \
 -                a += (d ^ (b & (c ^ d))) + X[i           & 15];         \
++                a += (d ^ (b & (c ^ d)))  + X[       i  & 15];          \
+             else                                                        \
 -                a += (c ^ (d & (c ^ b))) + X[(1 + 5 * i) & 15];         \
++                a += ((d & b) | (~d & c)) + X[(1 + 5*i) & 15];          \
          } else {                                                        \
-             if (i < 48) a += (b ^ c ^ d)          + X[(5 + 3*i) & 15];  \
-             else        a += (c ^ (b | ~d))       + X[(    7*i) & 15];  \
+             if (i < 48)                                                 \
 -                a += (b ^ c ^ d)    + X[(5 + 3 * i) & 15];              \
++                a += (b ^ c ^ d)          + X[(5 + 3*i) & 15];          \
+             else                                                        \
 -                a += (c ^ (b | ~d)) + X[(7     * i) & 15];              \
++                a += (c ^ (b | ~d))       + X[(    7*i) & 15];          \
          }                                                               \
          a = b + (a << t | a >> (32 - t));                               \
      } while (0)
@@@ -112,27 -111,29 +118,30 @@@ static void body(uint32_t ABCD[4], uint
  #endif
  
  #if CONFIG_SMALL
 -    for (i = 0; i < 64; i++) {
 -        CORE(i, a, b, c, d);
 -        t = d;
 -        d = c;
 -        c = b;
 -        b = a;
 -        a = t;
 -    }
 +        for (i = 0; i < 64; i++) {
 +            CORE(i, a, b, c, d);
 +            t = d;
 +            d = c;
 +            c = b;
 +            b = a;
 +            a = t;
 +        }
  #else
  #define CORE2(i)                                                        \
-         CORE( i,   a,b,c,d); CORE((i+1),d,a,b,c);                       \
-         CORE((i+2),c,d,a,b); CORE((i+3),b,c,d,a)
- #define CORE4(i) CORE2(i); CORE2((i+4)); CORE2((i+8)); CORE2((i+12))
-         CORE4(0); CORE4(16); CORE4(32); CORE4(48);
 -    CORE(i, a, b, c, d); CORE((i + 1), d, a, b, c);                     \
 -    CORE((i + 2), c, d, a, b); CORE((i + 3), b, c, d, a)
++        CORE(i, a, b, c, d); CORE((i + 1), d, a, b, c);                 \
++        CORE((i + 2), c, d, a, b); CORE((i + 3), b, c, d, a)
+ #define CORE4(i) CORE2(i); CORE2((i + 4)); CORE2((i + 8)); CORE2((i + 12))
 -    CORE4(0);
 -    CORE4(16);
 -    CORE4(32);
 -    CORE4(48);
++        CORE4(0);
++        CORE4(16);
++        CORE4(32);
++        CORE4(48);
  #endif
  
 -    ABCD[0] += d;
 -    ABCD[1] += c;
 -    ABCD[2] += b;
 -    ABCD[3] += a;
 +        ABCD[0] += d;
 +        ABCD[1] += c;
 +        ABCD[2] += b;
 +        ABCD[3] += a;
 +    }
  }
  
  void av_md5_init(AVMD5 *ctx)
@@@ -145,39 -146,20 +154,39 @@@
      ctx->ABCD[3] = 0x67452301;
  }
  
 -void av_md5_update(AVMD5 *ctx, const uint8_t *src, const int len)
 +void av_md5_update(AVMD5 *ctx, const uint8_t *src, int len)
  {
 -    int i, j;
 +    const uint8_t *end;
 +    int j;
  
-     j = ctx->len & 63;
+     j         = ctx->len & 63;
      ctx->len += len;
  
 -    for (i = 0; i < len; i++) {
 -        ctx->block[j++] = src[i];
 -        if (j == 64) {
 -            body(ctx->ABCD, (uint32_t *) ctx->block);
 -            j = 0;
 +    if (j) {
 +        int cnt = FFMIN(len, 64 - j);
 +        memcpy(ctx->block + j, src, cnt);
 +        src += cnt;
 +        len -= cnt;
 +        if (j + cnt < 64)
 +            return;
 +        body(ctx->ABCD, (uint32_t *)ctx->block, 1);
 +    }
 +
 +    end = src + (len & ~63);
 +    if (HAVE_BIGENDIAN || (!HAVE_FAST_UNALIGNED && ((intptr_t)src & 3))) {
 +       while (src < end) {
 +           memcpy(ctx->block, src, 64);
 +           body(ctx->ABCD, (uint32_t *) ctx->block, 1);
 +           src += 64;
          }
 +    } else {
 +        int nblocks = len / 64;
 +        body(ctx->ABCD, (uint32_t *)src, nblocks);
 +        src = end;
      }
 +    len &= 63;
 +    if (len > 0)
 +        memcpy(ctx->block, src, len);
  }
  
  void av_md5_final(AVMD5 *ctx, uint8_t *dst)
@@@ -215,11 -197,11 +224,12 @@@ static void print_md5(uint8_t *md5
      printf("\n");
  }
  
- int main(void){
+ int main(void)
+ {
      uint8_t md5val[16];
      int i;
 -    uint8_t in[1000];
 +    volatile uint8_t in[1000]; // volatile to workaround http://llvm.org/bugs/show_bug.cgi?id=20849
 +    // FIXME remove volatile once it has been fixed and all fate clients are updated
  
      for (i = 0; i < 1000; i++)
          in[i] = i * i;
diff --cc libavutil/opt.c
index cbe36df,df3cc08..ae92da0
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@@ -25,22 -25,14 +25,22 @@@
   * @author Michael Niedermayer <michaelni at gmx.at>
   */
  
 -#include "avstring.h"
  #include "avutil.h"
 +#include "avassert.h"
 +#include "avstring.h"
 +#include "channel_layout.h"
  #include "common.h"
- #include "opt.h"
- #include "eval.h"
  #include "dict.h"
+ #include "eval.h"
  #include "log.h"
 +#include "parseutils.h"
 +#include "pixdesc.h"
  #include "mathematics.h"
+ #include "opt.h"
 +#include "samplefmt.h"
 +#include "bprint.h"
 +
 +#include <float.h>
  
  const AVOption *av_opt_next(const void *obj, const AVOption *last)
  {
@@@ -58,20 -47,25 +58,37 @@@
  static int read_number(const AVOption *o, const void *dst, double *num, int *den, int64_t *intnum)
  {
      switch (o->type) {
-     case AV_OPT_TYPE_FLAGS:     *intnum = *(unsigned int*)dst;return 0;
-     case AV_OPT_TYPE_PIXEL_FMT: *intnum = *(enum AVPixelFormat *)dst;return 0;
-     case AV_OPT_TYPE_SAMPLE_FMT:*intnum = *(enum AVSampleFormat*)dst;return 0;
+     case AV_OPT_TYPE_FLAGS:
 -        *intnum = *(unsigned int *)dst;
++        *intnum = *(unsigned int*)dst;
++        return 0;
++    case AV_OPT_TYPE_PIXEL_FMT:
++        *intnum = *(enum AVPixelFormat *)dst;
++        return 0;
++    case AV_OPT_TYPE_SAMPLE_FMT:
++        *intnum = *(enum AVSampleFormat *)dst;
+         return 0;
 +    case AV_OPT_TYPE_BOOL:
-     case AV_OPT_TYPE_INT:       *intnum = *(int         *)dst;return 0;
+     case AV_OPT_TYPE_INT:
+         *intnum = *(int *)dst;
+         return 0;
 +    case AV_OPT_TYPE_CHANNEL_LAYOUT:
 +    case AV_OPT_TYPE_DURATION:
-     case AV_OPT_TYPE_INT64:     *intnum = *(int64_t     *)dst;return 0;
-     case AV_OPT_TYPE_FLOAT:     *num    = *(float       *)dst;return 0;
-     case AV_OPT_TYPE_DOUBLE:    *num    = *(double      *)dst;return 0;
-     case AV_OPT_TYPE_RATIONAL:  *intnum = ((AVRational*)dst)->num;
-                                 *den    = ((AVRational*)dst)->den;
-                                                         return 0;
-     case AV_OPT_TYPE_CONST:     *num    = o->default_val.dbl; return 0;
+     case AV_OPT_TYPE_INT64:
+         *intnum = *(int64_t *)dst;
+         return 0;
+     case AV_OPT_TYPE_FLOAT:
+         *num = *(float *)dst;
+         return 0;
+     case AV_OPT_TYPE_DOUBLE:
+         *num = *(double *)dst;
+         return 0;
+     case AV_OPT_TYPE_RATIONAL:
+         *intnum = ((AVRational *)dst)->num;
+         *den    = ((AVRational *)dst)->den;
+         return 0;
++    case AV_OPT_TYPE_CONST:
++        *num = o->default_val.dbl;
++        return 0;
      }
      return AVERROR(EINVAL);
  }
@@@ -80,35 -74,30 +97,49 @@@ static int write_number(void *obj, cons
  {
      if (o->type != AV_OPT_TYPE_FLAGS &&
          (o->max * den < num * intnum || o->min * den > num * intnum)) {
-         num = den ? num*intnum/den : (num*intnum ? INFINITY : NAN);
 -        av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range\n",
 -               num * intnum / den, o->name);
++        num = den ? num * intnum / den : (num * intnum ? INFINITY : NAN);
 +        av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n",
 +               num, o->name, o->min, o->max);
          return AVERROR(ERANGE);
      }
 +    if (o->type == AV_OPT_TYPE_FLAGS) {
 +        double d = num*intnum/den;
 +        if (d < -1.5 || d > 0xFFFFFFFF+0.5 || (llrint(d*256) & 255)) {
 +            av_log(obj, AV_LOG_ERROR,
 +                   "Value %f for parameter '%s' is not a valid set of 32bit integer flags\n",
 +                   num*intnum/den, o->name);
 +            return AVERROR(ERANGE);
 +        }
 +    }
  
      switch (o->type) {
-     case AV_OPT_TYPE_PIXEL_FMT: *(enum AVPixelFormat *)dst = llrint(num/den) * intnum; break;
-     case AV_OPT_TYPE_SAMPLE_FMT:*(enum AVSampleFormat*)dst = llrint(num/den) * intnum; break;
++    case AV_OPT_TYPE_PIXEL_FMT:
++        *(enum AVPixelFormat *)dst = llrint(num / den) * intnum;
++        break;
++    case AV_OPT_TYPE_SAMPLE_FMT:
++        *(enum AVSampleFormat *)dst = llrint(num / den) * intnum;
++        break;
 +    case AV_OPT_TYPE_BOOL:
      case AV_OPT_TYPE_FLAGS:
-     case AV_OPT_TYPE_INT:   *(int       *)dst= llrint(num/den)*intnum; break;
+     case AV_OPT_TYPE_INT:
+         *(int *)dst = llrint(num / den) * intnum;
+         break;
 +    case AV_OPT_TYPE_DURATION:
 +    case AV_OPT_TYPE_CHANNEL_LAYOUT:
-     case AV_OPT_TYPE_INT64: *(int64_t   *)dst= llrint(num/den)*intnum; break;
-     case AV_OPT_TYPE_FLOAT: *(float     *)dst= num*intnum/den;         break;
-     case AV_OPT_TYPE_DOUBLE:*(double    *)dst= num*intnum/den;         break;
+     case AV_OPT_TYPE_INT64:
+         *(int64_t *)dst = llrint(num / den) * intnum;
+         break;
+     case AV_OPT_TYPE_FLOAT:
+         *(float *)dst = num * intnum / den;
+         break;
+     case AV_OPT_TYPE_DOUBLE:
 -        *(double *)dst = num * intnum / den;
++        *(double    *)dst = num * intnum / den;
+         break;
      case AV_OPT_TYPE_RATIONAL:
-         if ((int)num == num) *(AVRational*)dst= (AVRational){num*intnum, den};
-         else                 *(AVRational*)dst= av_d2q(num*intnum/den, 1<<24);
+         if ((int) num == num)
+             *(AVRational *)dst = (AVRational) { num *intnum, den };
+         else
+             *(AVRational *)dst = av_d2q(num * intnum / den, 1 << 24);
          break;
      default:
          return AVERROR(EINVAL);
@@@ -116,10 -105,28 +147,13 @@@
      return 0;
  }
  
 -static const double const_values[] = {
 -    M_PI,
 -    M_E,
 -    FF_QP2LAMBDA,
 -    0
 -};
 -
 -static const char *const const_names[] = {
 -    "PI",
 -    "E",
 -    "QP2LAMBDA",
 -    0
 -};
 -
 -static int hexchar2int(char c)
 -{
 +static int hexchar2int(char c) {
-     if (c >= '0' && c <= '9') return c - '0';
-     if (c >= 'a' && c <= 'f') return c - 'a' + 10;
-     if (c >= 'A' && c <= 'F') return c - 'A' + 10;
+     if (c >= '0' && c <= '9')
+         return c - '0';
+     if (c >= 'a' && c <= 'f')
+         return c - 'a' + 10;
+     if (c >= 'A' && c <= 'F')
+         return c - 'A' + 10;
      return -1;
  }
  
@@@ -243,8 -221,16 +278,10 @@@ static int set_string_number(void *obj
          }
          if (o->type == AV_OPT_TYPE_FLAGS) {
              read_number(o, dst, NULL, NULL, &intnum);
-             if      (cmd == '+') d = intnum | (int64_t)d;
-             else if (cmd == '-') d = intnum &~(int64_t)d;
+             if (cmd == '+')
+                 d = intnum | (int64_t)d;
+             else if (cmd == '-')
 -                d = intnum & ~(int64_t)d;
 -        } else {
 -            read_number(o, dst, &num, &den, &intnum);
 -            if (cmd == '+')
 -                d = notfirst * num * intnum / den + d;
 -            else if (cmd == '-')
 -                d = notfirst * num * intnum / den - d;
++                d = intnum &~(int64_t)d;
          }
  
          if ((ret = write_number(obj, o, dst, d, 1, 1)) < 0)
@@@ -397,55 -250,22 +434,64 @@@ int av_opt_set(void *obj, const char *n
      const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
      if (!o || !target_obj)
          return AVERROR_OPTION_NOT_FOUND;
 -    if (!val || o->flags & AV_OPT_FLAG_READONLY)
 +    if (!val && (o->type != AV_OPT_TYPE_STRING &&
 +                 o->type != AV_OPT_TYPE_PIXEL_FMT && o->type != AV_OPT_TYPE_SAMPLE_FMT &&
 +                 o->type != AV_OPT_TYPE_IMAGE_SIZE && o->type != AV_OPT_TYPE_VIDEO_RATE &&
 +                 o->type != AV_OPT_TYPE_DURATION && o->type != AV_OPT_TYPE_COLOR &&
 +                 o->type != AV_OPT_TYPE_CHANNEL_LAYOUT && o->type != AV_OPT_TYPE_BOOL))
 +        return AVERROR(EINVAL);
 +
 +    if (o->flags & AV_OPT_FLAG_READONLY)
          return AVERROR(EINVAL);
  
-     dst = ((uint8_t*)target_obj) + o->offset;
+     dst = ((uint8_t *)target_obj) + o->offset;
      switch (o->type) {
-     case AV_OPT_TYPE_BOOL:     return set_string_bool(obj, o, val, dst);
-     case AV_OPT_TYPE_STRING:   return set_string(obj, o, val, dst);
-     case AV_OPT_TYPE_BINARY:   return set_string_binary(obj, o, val, dst);
++    case AV_OPT_TYPE_BOOL:
++        return set_string_bool(obj, o, val, dst);
+     case AV_OPT_TYPE_STRING:
+         return set_string(obj, o, val, dst);
+     case AV_OPT_TYPE_BINARY:
+         return set_string_binary(obj, o, val, dst);
      case AV_OPT_TYPE_FLAGS:
      case AV_OPT_TYPE_INT:
      case AV_OPT_TYPE_INT64:
      case AV_OPT_TYPE_FLOAT:
      case AV_OPT_TYPE_DOUBLE:
-     case AV_OPT_TYPE_RATIONAL: return set_string_number(obj, target_obj, o, val, dst);
-     case AV_OPT_TYPE_IMAGE_SIZE: return set_string_image_size(obj, o, val, dst);
-     case AV_OPT_TYPE_VIDEO_RATE: return set_string_video_rate(obj, o, val, dst);
-     case AV_OPT_TYPE_PIXEL_FMT:  return set_string_pixel_fmt(obj, o, val, dst);
-     case AV_OPT_TYPE_SAMPLE_FMT: return set_string_sample_fmt(obj, o, val, dst);
+     case AV_OPT_TYPE_RATIONAL:
+         return set_string_number(obj, target_obj, o, val, dst);
++    case AV_OPT_TYPE_IMAGE_SIZE:
++        return set_string_image_size(obj, o, val, dst);
++    case AV_OPT_TYPE_VIDEO_RATE:
++        return set_string_video_rate(obj, o, val, dst);
++    case AV_OPT_TYPE_PIXEL_FMT:
++        return set_string_pixel_fmt(obj, o, val, dst);
++    case AV_OPT_TYPE_SAMPLE_FMT:
++        return set_string_sample_fmt(obj, o, val, dst);
 +    case AV_OPT_TYPE_DURATION:
 +        if (!val) {
 +            *(int64_t *)dst = 0;
 +            return 0;
 +        } else {
 +            if ((ret = av_parse_time(dst, val, 1)) < 0)
 +                av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as duration\n", val);
 +            return ret;
 +        }
 +        break;
-     case AV_OPT_TYPE_COLOR:      return set_string_color(obj, o, val, dst);
++    case AV_OPT_TYPE_COLOR:
++        return set_string_color(obj, o, val, dst);
 +    case AV_OPT_TYPE_CHANNEL_LAYOUT:
 +        if (!val || !strcmp(val, "none")) {
 +            *(int64_t *)dst = 0;
 +        } else {
 +            int64_t cl = av_get_channel_layout(val);
 +            if (!cl) {
 +                av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as channel layout\n", val);
 +                ret = AVERROR(EINVAL);
 +            }
 +            *(int64_t *)dst = cl;
 +            return ret;
 +        }
 +        break;
      }
  
      av_log(obj, AV_LOG_ERROR, "Invalid option type.\n");
@@@ -512,117 -333,23 +559,118 @@@ int av_opt_set_bin(void *obj, const cha
      if (o->type != AV_OPT_TYPE_BINARY || o->flags & AV_OPT_FLAG_READONLY)
          return AVERROR(EINVAL);
  
 -    ptr = av_malloc(len);
 -    if (!ptr)
 +    ptr = len ? av_malloc(len) : NULL;
 +    if (len && !ptr)
          return AVERROR(ENOMEM);
  
-     dst = (uint8_t **)(((uint8_t *)target_obj) + o->offset);
+     dst    = (uint8_t **)(((uint8_t *)target_obj) + o->offset);
      lendst = (int *)(dst + 1);
  
      av_free(*dst);
-     *dst = ptr;
+     *dst    = ptr;
      *lendst = len;
 -    memcpy(ptr, val, len);
 +    if (len)
 +        memcpy(ptr, val, len);
  
      return 0;
  }
  
 +int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags)
 +{
 +    void *target_obj;
 +    const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
 +
 +    if (!o || !target_obj)
 +        return AVERROR_OPTION_NOT_FOUND;
 +    if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
 +        av_log(obj, AV_LOG_ERROR,
 +               "The value set by option '%s' is not an image size.\n", o->name);
 +        return AVERROR(EINVAL);
 +    }
 +    if (w<0 || h<0) {
 +        av_log(obj, AV_LOG_ERROR,
 +               "Invalid negative size value %dx%d for size '%s'\n", w, h, o->name);
 +        return AVERROR(EINVAL);
 +    }
 +    *(int *)(((uint8_t *)target_obj)             + o->offset) = w;
 +    *(int *)(((uint8_t *)target_obj+sizeof(int)) + o->offset) = h;
 +    return 0;
 +}
 +
 +int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags)
 +{
 +    void *target_obj;
 +    const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
 +
 +    if (!o || !target_obj)
 +        return AVERROR_OPTION_NOT_FOUND;
 +    if (o->type != AV_OPT_TYPE_VIDEO_RATE) {
 +        av_log(obj, AV_LOG_ERROR,
 +               "The value set by option '%s' is not a video rate.\n", o->name);
 +        return AVERROR(EINVAL);
 +    }
 +    if (val.num <= 0 || val.den <= 0)
 +        return AVERROR(EINVAL);
 +    return set_number(obj, name, val.num, val.den, 1, search_flags);
 +}
 +
 +static int set_format(void *obj, const char *name, int fmt, int search_flags,
 +                      enum AVOptionType type, const char *desc, int nb_fmts)
 +{
 +    void *target_obj;
 +    const AVOption *o = av_opt_find2(obj, name, NULL, 0,
 +                                     search_flags, &target_obj);
 +    int min, max;
 +
 +    if (!o || !target_obj)
 +        return AVERROR_OPTION_NOT_FOUND;
 +    if (o->type != type) {
 +        av_log(obj, AV_LOG_ERROR,
 +               "The value set by option '%s' is not a %s format", name, desc);
 +        return AVERROR(EINVAL);
 +    }
 +
 +    min = FFMAX(o->min, -1);
 +    max = FFMIN(o->max, nb_fmts-1);
 +
 +    if (fmt < min || fmt > max) {
 +        av_log(obj, AV_LOG_ERROR,
 +               "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
 +               fmt, name, desc, min, max);
 +        return AVERROR(ERANGE);
 +    }
 +    *(int *)(((uint8_t *)target_obj) + o->offset) = fmt;
 +    return 0;
 +}
 +
 +int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags)
 +{
 +    return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_PIXEL_FMT, "pixel", AV_PIX_FMT_NB);
 +}
 +
 +int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags)
 +{
 +    return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, "sample", AV_SAMPLE_FMT_NB);
 +}
 +
 +int av_opt_set_channel_layout(void *obj, const char *name, int64_t cl, int search_flags)
 +{
 +    void *target_obj;
 +    const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
 +
 +    if (!o || !target_obj)
 +        return AVERROR_OPTION_NOT_FOUND;
 +    if (o->type != AV_OPT_TYPE_CHANNEL_LAYOUT) {
 +        av_log(obj, AV_LOG_ERROR,
 +               "The value set by option '%s' is not a channel layout.\n", o->name);
 +        return AVERROR(EINVAL);
 +    }
 +    *(int64_t *)(((uint8_t *)target_obj) + o->offset) = cl;
 +    return 0;
 +}
 +
- int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, int search_flags)
+ int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val,
+                         int search_flags)
  {
      void *target_obj;
      AVDictionary **dst;
@@@ -681,77 -373,49 +729,91 @@@ int av_opt_get(void *obj, const char *n
      const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
      uint8_t *bin, buf[128];
      int len, i, ret;
 +    int64_t i64;
  
 -    if (!o || !target_obj)
 +    if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST))
          return AVERROR_OPTION_NOT_FOUND;
  
-     dst = (uint8_t*)target_obj + o->offset;
+     dst = (uint8_t *)target_obj + o->offset;
  
      buf[0] = 0;
      switch (o->type) {
 +    case AV_OPT_TYPE_BOOL:
 +        ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(get_bool_name(*(int *)dst), "invalid"));
 +        break;
-     case AV_OPT_TYPE_FLAGS:     ret = snprintf(buf, sizeof(buf), "0x%08X",  *(int    *)dst);break;
-     case AV_OPT_TYPE_INT:       ret = snprintf(buf, sizeof(buf), "%d" ,     *(int    *)dst);break;
-     case AV_OPT_TYPE_INT64:     ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t*)dst);break;
-     case AV_OPT_TYPE_FLOAT:     ret = snprintf(buf, sizeof(buf), "%f" ,     *(float  *)dst);break;
-     case AV_OPT_TYPE_DOUBLE:    ret = snprintf(buf, sizeof(buf), "%f" ,     *(double *)dst);break;
+     case AV_OPT_TYPE_FLAGS:
+         ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);
+         break;
+     case AV_OPT_TYPE_INT:
+         ret = snprintf(buf, sizeof(buf), "%d", *(int *)dst);
+         break;
+     case AV_OPT_TYPE_INT64:
 -        ret = snprintf(buf, sizeof(buf), "%" PRId64, *(int64_t *)dst);
++        ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t *)dst);
+         break;
+     case AV_OPT_TYPE_FLOAT:
+         ret = snprintf(buf, sizeof(buf), "%f", *(float *)dst);
+         break;
+     case AV_OPT_TYPE_DOUBLE:
+         ret = snprintf(buf, sizeof(buf), "%f", *(double *)dst);
+         break;
 +    case AV_OPT_TYPE_VIDEO_RATE:
-     case AV_OPT_TYPE_RATIONAL:  ret = snprintf(buf, sizeof(buf), "%d/%d",   ((AVRational*)dst)->num, ((AVRational*)dst)->den);break;
-     case AV_OPT_TYPE_CONST:     ret = snprintf(buf, sizeof(buf), "%f" ,     o->default_val.dbl);break;
+     case AV_OPT_TYPE_RATIONAL:
 -        ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational *)dst)->num,
 -                       ((AVRational *)dst)->den);
++        ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational *)dst)->num, ((AVRational *)dst)->den);
++        break;
++    case AV_OPT_TYPE_CONST:
++        ret = snprintf(buf, sizeof(buf), "%f", o->default_val.dbl);
+         break;
      case AV_OPT_TYPE_STRING:
-         if (*(uint8_t**)dst) {
-             *out_val = av_strdup(*(uint8_t**)dst);
 -        if (*(uint8_t **)dst)
++        if (*(uint8_t **)dst) {
+             *out_val = av_strdup(*(uint8_t **)dst);
 -        else
 +        } else if (search_flags & AV_OPT_ALLOW_NULL) {
 +            *out_val = NULL;
 +            return 0;
 +        } else {
              *out_val = av_strdup("");
 +        }
          return *out_val ? 0 : AVERROR(ENOMEM);
      case AV_OPT_TYPE_BINARY:
-         if (!*(uint8_t**)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
++        if (!*(uint8_t **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
 +            *out_val = NULL;
 +            return 0;
 +        }
-         len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *));
-         if ((uint64_t)len*2 + 1 > INT_MAX)
+         len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *));
+         if ((uint64_t)len * 2 + 1 > INT_MAX)
              return AVERROR(EINVAL);
-         if (!(*out_val = av_malloc(len*2 + 1)))
+         if (!(*out_val = av_malloc(len * 2 + 1)))
              return AVERROR(ENOMEM);
 +        if (!len) {
 +            *out_val[0] = '\0';
 +            return 0;
 +        }
-         bin = *(uint8_t**)dst;
+         bin = *(uint8_t **)dst;
          for (i = 0; i < len; i++)
-             snprintf(*out_val + i*2, 3, "%02X", bin[i]);
+             snprintf(*out_val + i * 2, 3, "%02X", bin[i]);
          return 0;
 +    case AV_OPT_TYPE_IMAGE_SIZE:
 +        ret = snprintf(buf, sizeof(buf), "%dx%d", ((int *)dst)[0], ((int *)dst)[1]);
 +        break;
 +    case AV_OPT_TYPE_PIXEL_FMT:
 +        ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum AVPixelFormat *)dst), "none"));
 +        break;
 +    case AV_OPT_TYPE_SAMPLE_FMT:
 +        ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_sample_fmt_name(*(enum AVSampleFormat *)dst), "none"));
 +        break;
 +    case AV_OPT_TYPE_DURATION:
 +        i64 = *(int64_t *)dst;
 +        format_duration(buf, sizeof(buf), i64);
 +        ret = strlen(buf); // no overflow possible, checked by an assert
 +        break;
 +    case AV_OPT_TYPE_COLOR:
 +        ret = snprintf(buf, sizeof(buf), "0x%02x%02x%02x%02x",
 +                       (int)((uint8_t *)dst)[0], (int)((uint8_t *)dst)[1],
 +                       (int)((uint8_t *)dst)[2], (int)((uint8_t *)dst)[3]);
 +        break;
 +    case AV_OPT_TYPE_CHANNEL_LAYOUT:
 +        i64 = *(int64_t *)dst;
 +        ret = snprintf(buf, sizeof(buf), "0x%"PRIx64, i64);
 +        break;
      default:
          return AVERROR(EINVAL);
      }
@@@ -770,10 -434,8 +832,10 @@@ static int get_number(void *obj, const 
      if (!o || !target_obj)
          goto error;
  
-     dst = ((uint8_t*)target_obj) + o->offset;
+     dst = ((uint8_t *)target_obj) + o->offset;
  
 +    if (o_out) *o_out= o;
 +
      return read_number(o, dst, num, den, intnum);
  
  error:
@@@ -784,68 -447,34 +847,68 @@@
  int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
  {
      int64_t intnum = 1;
-     double     num = 1;
-     int   ret, den = 1;
+     double num = 1;
+     int ret, den = 1;
  
 -    if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
 +    if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
          return ret;
-     *out_val = num*intnum/den;
+     *out_val = num * intnum / den;
      return 0;
  }
  
  int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
  {
      int64_t intnum = 1;
-     double     num = 1;
-     int   ret, den = 1;
+     double num = 1;
+     int ret, den = 1;
  
 -    if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
 +    if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
          return ret;
-     *out_val = num*intnum/den;
+     *out_val = num * intnum / den;
      return 0;
  }
  
  int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
  {
      int64_t intnum = 1;
-     double     num = 1;
-     int   ret, den = 1;
+     double num = 1;
+     int ret, den = 1;
  
 -    if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
 +    if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
 +        return ret;
 +
 +    if (num == 1.0 && (int)intnum == intnum)
 +        *out_val = (AVRational){intnum, den};
 +    else
 +        *out_val = av_d2q(num*intnum/den, 1<<24);
 +    return 0;
 +}
 +
 +int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out)
 +{
 +    void *dst, *target_obj;
 +    const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
 +    if (!o || !target_obj)
 +        return AVERROR_OPTION_NOT_FOUND;
 +    if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
 +        av_log(obj, AV_LOG_ERROR,
 +               "The value for option '%s' is not an image size.\n", name);
 +        return AVERROR(EINVAL);
 +    }
 +
 +    dst = ((uint8_t*)target_obj) + o->offset;
 +    if (w_out) *w_out = *(int *)dst;
 +    if (h_out) *h_out = *((int *)dst+1);
 +    return 0;
 +}
 +
 +int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val)
 +{
 +    int64_t intnum = 1;
 +    double     num = 1;
 +    int   ret, den = 1;
 +
 +    if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
          return ret;
  
      if (num == 1.0 && (int)intnum == intnum)
@@@ -1000,9 -517,7 +1063,9 @@@ static char *get_opt_flags_string(void 
  static void opt_list(void *obj, void *av_log_obj, const char *unit,
                       int req_flags, int rej_flags)
  {
-     const AVOption *opt=NULL;
+     const AVOption *opt = NULL;
 +    AVOptionRanges *r;
 +    int i;
  
      while ((opt = av_opt_next(obj, opt))) {
          if (!(opt->flags & req_flags) || (opt->flags & rej_flags))
@@@ -1012,72 -527,46 +1075,72 @@@
           * Don't print anything but CONST's on level two.
           * Only print items from the requested unit.
           */
-         if (!unit && opt->type==AV_OPT_TYPE_CONST)
+         if (!unit && opt->type == AV_OPT_TYPE_CONST)
              continue;
-         else if (unit && opt->type!=AV_OPT_TYPE_CONST)
+         else if (unit && opt->type != AV_OPT_TYPE_CONST)
              continue;
-         else if (unit && opt->type==AV_OPT_TYPE_CONST && strcmp(unit, opt->unit))
+         else if (unit && opt->type == AV_OPT_TYPE_CONST && strcmp(unit, opt->unit))
              continue;
          else if (unit && opt->type == AV_OPT_TYPE_CONST)
 -            av_log(av_log_obj, AV_LOG_INFO, "   %-15s ", opt->name);
 +            av_log(av_log_obj, AV_LOG_INFO, "     %-15s ", opt->name);
          else
 -            av_log(av_log_obj, AV_LOG_INFO, "-%-17s ", opt->name);
 +            av_log(av_log_obj, AV_LOG_INFO, "  %s%-17s ",
 +                   (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? "" : "-",
 +                   opt->name);
  
          switch (opt->type) {
 -        case AV_OPT_TYPE_FLAGS:
 -            av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<flags>");
 -            break;
 -        case AV_OPT_TYPE_INT:
 -            av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<int>");
 -            break;
 -        case AV_OPT_TYPE_INT64:
 -            av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<int64>");
 -            break;
 -        case AV_OPT_TYPE_DOUBLE:
 -            av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<double>");
 -            break;
 -        case AV_OPT_TYPE_FLOAT:
 -            av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<float>");
 -            break;
 -        case AV_OPT_TYPE_STRING:
 -            av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<string>");
 -            break;
 -        case AV_OPT_TYPE_RATIONAL:
 -            av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<rational>");
 -            break;
 -        case AV_OPT_TYPE_BINARY:
 -            av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<binary>");
 -            break;
 -        case AV_OPT_TYPE_CONST:
 -        default:
 -            av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "");
 -            break;
 +            case AV_OPT_TYPE_FLAGS:
 +                av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<flags>");
 +                break;
 +            case AV_OPT_TYPE_INT:
 +                av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<int>");
 +                break;
 +            case AV_OPT_TYPE_INT64:
 +                av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<int64>");
 +                break;
 +            case AV_OPT_TYPE_DOUBLE:
 +                av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<double>");
 +                break;
 +            case AV_OPT_TYPE_FLOAT:
 +                av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<float>");
 +                break;
 +            case AV_OPT_TYPE_STRING:
 +                av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<string>");
 +                break;
 +            case AV_OPT_TYPE_RATIONAL:
 +                av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<rational>");
 +                break;
 +            case AV_OPT_TYPE_BINARY:
 +                av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<binary>");
 +                break;
 +            case AV_OPT_TYPE_IMAGE_SIZE:
 +                av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<image_size>");
 +                break;
 +            case AV_OPT_TYPE_VIDEO_RATE:
 +                av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<video_rate>");
 +                break;
 +            case AV_OPT_TYPE_PIXEL_FMT:
 +                av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<pix_fmt>");
 +                break;
 +            case AV_OPT_TYPE_SAMPLE_FMT:
 +                av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<sample_fmt>");
 +                break;
 +            case AV_OPT_TYPE_DURATION:
 +                av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<duration>");
 +                break;
 +            case AV_OPT_TYPE_COLOR:
 +                av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<color>");
 +                break;
 +            case AV_OPT_TYPE_CHANNEL_LAYOUT:
 +                av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<channel_layout>");
 +                break;
 +            case AV_OPT_TYPE_BOOL:
 +                av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<boolean>");
 +                break;
 +            case AV_OPT_TYPE_CONST:
 +            default:
 +                av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
 +                break;
          }
          av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.');
          av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.');
@@@ -1090,94 -578,9 +1153,93 @@@
  
          if (opt->help)
              av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help);
 +
 +        if (av_opt_query_ranges(&r, obj, opt->name, AV_OPT_SEARCH_FAKE_OBJ) >= 0) {
 +            switch (opt->type) {
 +            case AV_OPT_TYPE_INT:
 +            case AV_OPT_TYPE_INT64:
 +            case AV_OPT_TYPE_DOUBLE:
 +            case AV_OPT_TYPE_FLOAT:
 +            case AV_OPT_TYPE_RATIONAL:
 +                for (i = 0; i < r->nb_ranges; i++) {
 +                    av_log(av_log_obj, AV_LOG_INFO, " (from ");
 +                    log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_min);
 +                    av_log(av_log_obj, AV_LOG_INFO, " to ");
 +                    log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_max);
 +                    av_log(av_log_obj, AV_LOG_INFO, ")");
 +                }
 +                break;
 +            }
 +            av_opt_freep_ranges(&r);
 +        }
 +
 +        if (opt->type != AV_OPT_TYPE_CONST  &&
 +            opt->type != AV_OPT_TYPE_BINARY &&
 +                !((opt->type == AV_OPT_TYPE_COLOR      ||
 +                   opt->type == AV_OPT_TYPE_IMAGE_SIZE ||
 +                   opt->type == AV_OPT_TYPE_STRING     ||
 +                   opt->type == AV_OPT_TYPE_VIDEO_RATE) &&
 +                  !opt->default_val.str)) {
 +            av_log(av_log_obj, AV_LOG_INFO, " (default ");
 +            switch (opt->type) {
 +            case AV_OPT_TYPE_BOOL:
 +                av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(get_bool_name(opt->default_val.i64), "invalid"));
 +                break;
 +            case AV_OPT_TYPE_FLAGS: {
 +                char *def_flags = get_opt_flags_string(obj, opt->unit, opt->default_val.i64);
 +                if (def_flags) {
 +                    av_log(av_log_obj, AV_LOG_INFO, "%s", def_flags);
 +                    av_freep(&def_flags);
 +                } else {
 +                    av_log(av_log_obj, AV_LOG_INFO, "%"PRIX64, opt->default_val.i64);
 +                }
 +                break;
 +            }
 +            case AV_OPT_TYPE_DURATION: {
 +                char buf[25];
 +                format_duration(buf, sizeof(buf), opt->default_val.i64);
 +                av_log(av_log_obj, AV_LOG_INFO, "%s", buf);
 +                break;
 +            }
 +            case AV_OPT_TYPE_INT:
 +            case AV_OPT_TYPE_INT64: {
 +                const char *def_const = get_opt_const_name(obj, opt->unit, opt->default_val.i64);
 +                if (def_const)
 +                    av_log(av_log_obj, AV_LOG_INFO, "%s", def_const);
 +                else
 +                    log_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64);
 +                break;
 +            }
 +            case AV_OPT_TYPE_DOUBLE:
 +            case AV_OPT_TYPE_FLOAT:
 +                log_value(av_log_obj, AV_LOG_INFO, opt->default_val.dbl);
 +                break;
 +            case AV_OPT_TYPE_RATIONAL: {
 +                AVRational q = av_d2q(opt->default_val.dbl, INT_MAX);
 +                av_log(av_log_obj, AV_LOG_INFO, "%d/%d", q.num, q.den); }
 +                break;
 +            case AV_OPT_TYPE_PIXEL_FMT:
 +                av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(opt->default_val.i64), "none"));
 +                break;
 +            case AV_OPT_TYPE_SAMPLE_FMT:
 +                av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(opt->default_val.i64), "none"));
 +                break;
 +            case AV_OPT_TYPE_COLOR:
 +            case AV_OPT_TYPE_IMAGE_SIZE:
 +            case AV_OPT_TYPE_STRING:
 +            case AV_OPT_TYPE_VIDEO_RATE:
 +                av_log(av_log_obj, AV_LOG_INFO, "\"%s\"", opt->default_val.str);
 +                break;
 +            case AV_OPT_TYPE_CHANNEL_LAYOUT:
 +                av_log(av_log_obj, AV_LOG_INFO, "0x%"PRIx64, opt->default_val.i64);
 +                break;
 +            }
 +            av_log(av_log_obj, AV_LOG_INFO, ")");
 +        }
 +
          av_log(av_log_obj, AV_LOG_INFO, "\n");
-         if (opt->unit && opt->type != AV_OPT_TYPE_CONST) {
+         if (opt->unit && opt->type != AV_OPT_TYPE_CONST)
              opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags);
-         }
      }
  }
  
@@@ -1211,52 -604,39 +1273,53 @@@ void av_opt_set_defaults2(void *s, int 
              continue;
  
          switch (opt->type) {
 -        case AV_OPT_TYPE_CONST:
 -            /* Nothing to be done here */
 -            break;
 -        case AV_OPT_TYPE_FLAGS:
 -        case AV_OPT_TYPE_INT:
 -        case AV_OPT_TYPE_INT64:
 -            av_opt_set_int(s, opt->name, opt->default_val.i64, 0);
 +            case AV_OPT_TYPE_CONST:
 +                /* Nothing to be done here */
-             break;
++                break;
 +            case AV_OPT_TYPE_BOOL:
 +            case AV_OPT_TYPE_FLAGS:
 +            case AV_OPT_TYPE_INT:
 +            case AV_OPT_TYPE_INT64:
 +            case AV_OPT_TYPE_DURATION:
 +            case AV_OPT_TYPE_CHANNEL_LAYOUT:
 +            case AV_OPT_TYPE_PIXEL_FMT:
 +            case AV_OPT_TYPE_SAMPLE_FMT:
 +                write_number(s, opt, dst, 1, 1, opt->default_val.i64);
 +                break;
 +            case AV_OPT_TYPE_DOUBLE:
 +            case AV_OPT_TYPE_FLOAT: {
 +                double val;
 +                val = opt->default_val.dbl;
 +                write_number(s, opt, dst, val, 1, 1);
 +            }
              break;
 -        case AV_OPT_TYPE_DOUBLE:
 -        case AV_OPT_TYPE_FLOAT:
 -        {
 -            double val;
 -            val = opt->default_val.dbl;
 -            av_opt_set_double(s, opt->name, val, 0);
 -        }
 -        break;
 -        case AV_OPT_TYPE_RATIONAL:
 -        {
 -            AVRational val;
 -            val = av_d2q(opt->default_val.dbl, INT_MAX);
 -            av_opt_set_q(s, opt->name, val, 0);
 -        }
 -        break;
 -        case AV_OPT_TYPE_STRING:
 -            av_opt_set(s, opt->name, opt->default_val.str, 0);
 +            case AV_OPT_TYPE_RATIONAL: {
 +                AVRational val;
 +                val = av_d2q(opt->default_val.dbl, INT_MAX);
 +                write_number(s, opt, dst, 1, val.den, val.num);
 +            }
              break;
 -        case AV_OPT_TYPE_BINARY:
 -        case AV_OPT_TYPE_DICT:
 -            /* Cannot set defaults for these types */
 +            case AV_OPT_TYPE_COLOR:
 +                set_string_color(s, opt, opt->default_val.str, dst);
 +                break;
 +            case AV_OPT_TYPE_STRING:
 +                set_string(s, opt, opt->default_val.str, dst);
 +                break;
 +            case AV_OPT_TYPE_IMAGE_SIZE:
 +                set_string_image_size(s, opt, opt->default_val.str, dst);
 +                break;
 +            case AV_OPT_TYPE_VIDEO_RATE:
 +                set_string_video_rate(s, opt, opt->default_val.str, dst);
 +                break;
 +            case AV_OPT_TYPE_BINARY:
 +                set_string_binary(s, opt, opt->default_val.str, dst);
 +                break;
 +            case AV_OPT_TYPE_DICT:
 +                /* Cannot set defaults for these types */
              break;
-             default:
-                 av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", opt->type, opt->name);
+         default:
+             av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n",
+                    opt->type, opt->name);
          }
      }
  }
@@@ -1559,33 -813,24 +1622,44 @@@ const AVClass *av_opt_child_class_next(
      return NULL;
  }
  
 +void *av_opt_ptr(const AVClass *class, void *obj, const char *name)
 +{
 +    const AVOption *opt= av_opt_find2(&class, name, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ, NULL);
 +    if(!opt)
 +        return NULL;
 +    return (uint8_t*)obj + opt->offset;
 +}
 +
  static int opt_size(enum AVOptionType type)
  {
 -    switch (type) {
 +    switch(type) {
 +    case AV_OPT_TYPE_BOOL:
      case AV_OPT_TYPE_INT:
-     case AV_OPT_TYPE_FLAGS:     return sizeof(int);
+     case AV_OPT_TYPE_FLAGS:
+         return sizeof(int);
 +    case AV_OPT_TYPE_DURATION:
 +    case AV_OPT_TYPE_CHANNEL_LAYOUT:
-     case AV_OPT_TYPE_INT64:     return sizeof(int64_t);
-     case AV_OPT_TYPE_DOUBLE:    return sizeof(double);
-     case AV_OPT_TYPE_FLOAT:     return sizeof(float);
-     case AV_OPT_TYPE_STRING:    return sizeof(uint8_t*);
+     case AV_OPT_TYPE_INT64:
+         return sizeof(int64_t);
+     case AV_OPT_TYPE_DOUBLE:
+         return sizeof(double);
+     case AV_OPT_TYPE_FLOAT:
+         return sizeof(float);
+     case AV_OPT_TYPE_STRING:
 -        return sizeof(uint8_t *);
++        return sizeof(uint8_t*);
 +    case AV_OPT_TYPE_VIDEO_RATE:
-     case AV_OPT_TYPE_RATIONAL:  return sizeof(AVRational);
-     case AV_OPT_TYPE_BINARY:    return sizeof(uint8_t*) + sizeof(int);
-     case AV_OPT_TYPE_IMAGE_SIZE:return sizeof(int[2]);
-     case AV_OPT_TYPE_PIXEL_FMT: return sizeof(enum AVPixelFormat);
-     case AV_OPT_TYPE_SAMPLE_FMT:return sizeof(enum AVSampleFormat);
-     case AV_OPT_TYPE_COLOR:     return 4;
+     case AV_OPT_TYPE_RATIONAL:
+         return sizeof(AVRational);
+     case AV_OPT_TYPE_BINARY:
 -        return sizeof(uint8_t *) + sizeof(int);
++        return sizeof(uint8_t*) + sizeof(int);
++    case AV_OPT_TYPE_IMAGE_SIZE:
++        return sizeof(int[2]);
++    case AV_OPT_TYPE_PIXEL_FMT:
++        return sizeof(enum AVPixelFormat);
++    case AV_OPT_TYPE_SAMPLE_FMT:
++        return sizeof(enum AVSampleFormat);
++    case AV_OPT_TYPE_COLOR:
++        return 4;
      }
      return AVERROR(EINVAL);
  }
@@@ -1604,38 -849,32 +1678,38 @@@ int av_opt_copy(void *dst, const void *
          return AVERROR(EINVAL);
  
      while ((o = av_opt_next(src, o))) {
-         void *field_dst = ((uint8_t*)dst) + o->offset;
-         void *field_src = ((uint8_t*)src) + o->offset;
-         uint8_t **field_dst8 = (uint8_t**)field_dst;
-         uint8_t **field_src8 = (uint8_t**)field_src;
+         void *field_dst = (uint8_t *)dst + o->offset;
+         void *field_src = (uint8_t *)src + o->offset;
+         uint8_t **field_dst8 = (uint8_t **)field_dst;
+         uint8_t **field_src8 = (uint8_t **)field_src;
  
          if (o->type == AV_OPT_TYPE_STRING) {
 -            set_string(dst, o, *field_src8, field_dst8);
 +            if (*field_dst8 != *field_src8)
 +                av_freep(field_dst8);
 +            *field_dst8 = av_strdup(*field_src8);
              if (*field_src8 && !*field_dst8)
                  ret = AVERROR(ENOMEM);
          } else if (o->type == AV_OPT_TYPE_BINARY) {
-             int len = *(int*)(field_src8 + 1);
+             int len = *(int *)(field_src8 + 1);
              if (*field_dst8 != *field_src8)
                  av_freep(field_dst8);
 -            if (len) {
 -                *field_dst8 = av_malloc(len);
 -                if (!*field_dst8) {
 -                    ret = AVERROR(ENOMEM);
 -                    len = 0;
 -                }
 -                memcpy(*field_dst8, *field_src8, len);
 -            } else {
 -                *field_dst8 = NULL;
 +            *field_dst8 = av_memdup(*field_src8, len);
 +            if (len && !*field_dst8) {
 +                ret = AVERROR(ENOMEM);
 +                len = 0;
              }
-             *(int*)(field_dst8 + 1) = len;
+             *(int *)(field_dst8 + 1) = len;
          } else if (o->type == AV_OPT_TYPE_CONST) {
              // do nothing
 +        } else if (o->type == AV_OPT_TYPE_DICT) {
 +            AVDictionary **sdict = (AVDictionary **) field_src;
 +            AVDictionary **ddict = (AVDictionary **) field_dst;
 +            if (*sdict != *ddict)
 +                av_dict_free(ddict);
 +            *ddict = NULL;
 +            av_dict_copy(ddict, *sdict, 0);
 +            if (av_dict_count(*sdict) != av_dict_count(*ddict))
 +                ret = AVERROR(ENOMEM);
          } else {
              int size = opt_size(o->type);
              if (size < 0)
@@@ -1647,276 -886,9 +1721,275 @@@
      return ret;
  }
  
 +int av_opt_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
 +{
 +    int ret;
 +    const AVClass *c = *(AVClass**)obj;
 +    int (*callback)(AVOptionRanges **, void *obj, const char *key, int flags) = NULL;
 +
 +    if (c->version > (52 << 16 | 11 << 8))
 +        callback = c->query_ranges;
 +
 +    if (!callback)
 +        callback = av_opt_query_ranges_default;
 +
 +    ret = callback(ranges_arg, obj, key, flags);
 +    if (ret >= 0) {
 +        if (!(flags & AV_OPT_MULTI_COMPONENT_RANGE))
 +            ret = 1;
 +        (*ranges_arg)->nb_components = ret;
 +    }
 +    return ret;
 +}
 +
 +int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
 +{
 +    AVOptionRanges *ranges = av_mallocz(sizeof(*ranges));
 +    AVOptionRange **range_array = av_mallocz(sizeof(void*));
 +    AVOptionRange *range = av_mallocz(sizeof(*range));
 +    const AVOption *field = av_opt_find(obj, key, NULL, 0, flags);
 +    int ret;
 +
 +    *ranges_arg = NULL;
 +
 +    if (!ranges || !range || !range_array || !field) {
 +        ret = AVERROR(ENOMEM);
 +        goto fail;
 +    }
 +
 +    ranges->range = range_array;
 +    ranges->range[0] = range;
 +    ranges->nb_ranges = 1;
 +    ranges->nb_components = 1;
 +    range->is_range = 1;
 +    range->value_min = field->min;
 +    range->value_max = field->max;
 +
 +    switch (field->type) {
 +    case AV_OPT_TYPE_BOOL:
 +    case AV_OPT_TYPE_INT:
 +    case AV_OPT_TYPE_INT64:
 +    case AV_OPT_TYPE_PIXEL_FMT:
 +    case AV_OPT_TYPE_SAMPLE_FMT:
 +    case AV_OPT_TYPE_FLOAT:
 +    case AV_OPT_TYPE_DOUBLE:
 +    case AV_OPT_TYPE_DURATION:
 +    case AV_OPT_TYPE_COLOR:
 +    case AV_OPT_TYPE_CHANNEL_LAYOUT:
 +        break;
 +    case AV_OPT_TYPE_STRING:
 +        range->component_min = 0;
 +        range->component_max = 0x10FFFF; // max unicode value
 +        range->value_min = -1;
 +        range->value_max = INT_MAX;
 +        break;
 +    case AV_OPT_TYPE_RATIONAL:
 +        range->component_min = INT_MIN;
 +        range->component_max = INT_MAX;
 +        break;
 +    case AV_OPT_TYPE_IMAGE_SIZE:
 +        range->component_min = 0;
 +        range->component_max = INT_MAX/128/8;
 +        range->value_min = 0;
 +        range->value_max = INT_MAX/8;
 +        break;
 +    case AV_OPT_TYPE_VIDEO_RATE:
 +        range->component_min = 1;
 +        range->component_max = INT_MAX;
 +        range->value_min = 1;
 +        range->value_max = INT_MAX;
 +        break;
 +    default:
 +        ret = AVERROR(ENOSYS);
 +        goto fail;
 +    }
 +
 +    *ranges_arg = ranges;
 +    return 1;
 +fail:
 +    av_free(ranges);
 +    av_free(range);
 +    av_free(range_array);
 +    return ret;
 +}
 +
 +void av_opt_freep_ranges(AVOptionRanges **rangesp)
 +{
 +    int i;
 +    AVOptionRanges *ranges = *rangesp;
 +
 +    if (!ranges)
 +        return;
 +
 +    for (i = 0; i < ranges->nb_ranges * ranges->nb_components; i++) {
 +        AVOptionRange *range = ranges->range[i];
 +        if (range) {
 +            av_freep(&range->str);
 +            av_freep(&ranges->range[i]);
 +        }
 +    }
 +    av_freep(&ranges->range);
 +    av_freep(rangesp);
 +}
 +
 +int av_opt_is_set_to_default(void *obj, const AVOption *o)
 +{
 +    int64_t i64;
 +    double d, d2;
 +    float f;
 +    AVRational q;
 +    int ret, w, h;
 +    char *str;
 +    void *dst;
 +
 +    if (!o || !obj)
 +        return AVERROR(EINVAL);
 +
 +    dst = ((uint8_t*)obj) + o->offset;
 +
 +    switch (o->type) {
 +    case AV_OPT_TYPE_CONST:
 +        return 1;
 +    case AV_OPT_TYPE_BOOL:
 +    case AV_OPT_TYPE_FLAGS:
 +    case AV_OPT_TYPE_PIXEL_FMT:
 +    case AV_OPT_TYPE_SAMPLE_FMT:
 +    case AV_OPT_TYPE_INT:
 +    case AV_OPT_TYPE_CHANNEL_LAYOUT:
 +    case AV_OPT_TYPE_DURATION:
 +    case AV_OPT_TYPE_INT64:
 +        read_number(o, dst, NULL, NULL, &i64);
 +        return o->default_val.i64 == i64;
 +    case AV_OPT_TYPE_STRING:
 +        str = *(char **)dst;
 +        if (str == o->default_val.str) //2 NULLs
 +            return 1;
 +        if (!str || !o->default_val.str) //1 NULL
 +            return 0;
 +        return !strcmp(str, o->default_val.str);
 +    case AV_OPT_TYPE_DOUBLE:
 +        read_number(o, dst, &d, NULL, NULL);
 +        return o->default_val.dbl == d;
 +    case AV_OPT_TYPE_FLOAT:
 +        read_number(o, dst, &d, NULL, NULL);
 +        f = o->default_val.dbl;
 +        d2 = f;
 +        return d2 == d;
 +    case AV_OPT_TYPE_RATIONAL:
 +        q = av_d2q(o->default_val.dbl, INT_MAX);
 +        return !av_cmp_q(*(AVRational*)dst, q);
 +    case AV_OPT_TYPE_BINARY: {
 +        struct {
 +            uint8_t *data;
 +            int size;
 +        } tmp = {0};
 +        int opt_size = *(int *)((void **)dst + 1);
 +        void *opt_ptr = *(void **)dst;
 +        if (!opt_size && (!o->default_val.str || !strlen(o->default_val.str)))
 +            return 1;
 +        if (!opt_size ||  !o->default_val.str || !strlen(o->default_val.str ))
 +            return 0;
 +        if (opt_size != strlen(o->default_val.str) / 2)
 +            return 0;
 +        ret = set_string_binary(NULL, NULL, o->default_val.str, &tmp.data);
 +        if (!ret)
 +            ret = !memcmp(opt_ptr, tmp.data, tmp.size);
 +        av_free(tmp.data);
 +        return ret;
 +    }
 +    case AV_OPT_TYPE_DICT:
 +        /* Binary and dict have not default support yet. Any pointer is not default. */
 +        return !!(*(void **)dst);
 +    case AV_OPT_TYPE_IMAGE_SIZE:
 +        if (!o->default_val.str || !strcmp(o->default_val.str, "none"))
 +            w = h = 0;
 +        else if ((ret = av_parse_video_size(&w, &h, o->default_val.str)) < 0)
 +            return ret;
 +        return (w == *(int *)dst) && (h == *((int *)dst+1));
 +    case AV_OPT_TYPE_VIDEO_RATE:
 +        q = (AVRational){0, 0};
 +        if (o->default_val.str) {
 +            if ((ret = av_parse_video_rate(&q, o->default_val.str)) < 0)
 +                return ret;
 +        }
 +        return !av_cmp_q(*(AVRational*)dst, q);
 +    case AV_OPT_TYPE_COLOR: {
 +        uint8_t color[4] = {0, 0, 0, 0};
 +        if (o->default_val.str) {
 +            if ((ret = av_parse_color(color, o->default_val.str, -1, NULL)) < 0)
 +                return ret;
 +        }
 +        return !memcmp(color, dst, sizeof(color));
 +    }
 +    default:
 +        av_log(obj, AV_LOG_WARNING, "Not supported option type: %d, option name: %s\n", o->type, o->name);
 +        break;
 +    }
 +    return AVERROR_PATCHWELCOME;
 +}
 +
 +int av_opt_is_set_to_default_by_name(void *obj, const char *name, int search_flags)
 +{
 +    const AVOption *o;
 +    void *target;
 +    if (!obj)
 +        return AVERROR(EINVAL);
 +    o = av_opt_find2(obj, name, NULL, 0, search_flags, &target);
 +    if (!o)
 +        return AVERROR_OPTION_NOT_FOUND;
 +    return av_opt_is_set_to_default(target, o);
 +}
 +
 +int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer,
 +                     const char key_val_sep, const char pairs_sep)
 +{
 +    const AVOption *o = NULL;
 +    uint8_t *buf;
 +    AVBPrint bprint;
 +    int ret, cnt = 0;
 +    const char special_chars[] = {pairs_sep, key_val_sep, '\0'};
 +
 +    if (pairs_sep == '\0' || key_val_sep == '\0' || pairs_sep == key_val_sep ||
 +        pairs_sep == '\\' || key_val_sep == '\\') {
 +        av_log(obj, AV_LOG_ERROR, "Invalid separator(s) found.");
 +        return AVERROR(EINVAL);
 +    }
 +
 +    if (!obj || !buffer)
 +        return AVERROR(EINVAL);
 +
 +    *buffer = NULL;
 +    av_bprint_init(&bprint, 64, AV_BPRINT_SIZE_UNLIMITED);
 +
 +    while (o = av_opt_next(obj, o)) {
 +        if (o->type == AV_OPT_TYPE_CONST)
 +            continue;
 +        if ((flags & AV_OPT_SERIALIZE_OPT_FLAGS_EXACT) && o->flags != opt_flags)
 +            continue;
 +        else if (((o->flags & opt_flags) != opt_flags))
 +            continue;
 +        if (flags & AV_OPT_SERIALIZE_SKIP_DEFAULTS && av_opt_is_set_to_default(obj, o) > 0)
 +            continue;
 +        if ((ret = av_opt_get(obj, o->name, 0, &buf)) < 0) {
 +            av_bprint_finalize(&bprint, NULL);
 +            return ret;
 +        }
 +        if (buf) {
 +            if (cnt++)
 +                av_bprint_append_data(&bprint, &pairs_sep, 1);
 +            av_bprint_escape(&bprint, o->name, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0);
 +            av_bprint_append_data(&bprint, &key_val_sep, 1);
 +            av_bprint_escape(&bprint, buf, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0);
 +            av_freep(&buf);
 +        }
 +    }
 +    av_bprint_finalize(&bprint, buffer);
 +    return 0;
 +}
 +
  #ifdef TEST
  
- typedef struct TestContext
- {
+ typedef struct TestContext {
      const AVClass *class;
      int num;
      int toggle;
@@@ -1951,33 -903,16 +2024,33 @@@
  #define TEST_FLAG_LAME 02
  #define TEST_FLAG_MU   04
  
 -static const AVOption test_options[] = {
 -    { "num",      "set num",        OFFSET(num),      AV_OPT_TYPE_INT,      { .i64 = 0 },                    0,      100 },
 -    { "toggle",   "set toggle",     OFFSET(toggle),   AV_OPT_TYPE_INT,      { .i64 = 0 },                    0,        1 },
 -    { "rational", "set rational",   OFFSET(rational), AV_OPT_TYPE_RATIONAL, { .dbl = 0 },                    0,       10 },
 -    { "string",   "set string",     OFFSET(string),   AV_OPT_TYPE_STRING,   { 0 },                    CHAR_MIN, CHAR_MAX },
 -    { "flags",    "set flags",      OFFSET(flags),    AV_OPT_TYPE_FLAGS,    { .i64 = 0 },                    0,  INT_MAX, 0, "flags"},
 -    { "cool",     "set cool flag ", 0,                AV_OPT_TYPE_CONST,    { .i64 = TEST_FLAG_COOL }, INT_MIN,  INT_MAX, 0, "flags"},
 -    { "lame",     "set lame flag ", 0,                AV_OPT_TYPE_CONST,    { .i64 = TEST_FLAG_LAME }, INT_MIN,  INT_MAX, 0, "flags"},
 -    { "mu",       "set mu flag ",   0,                AV_OPT_TYPE_CONST,    { .i64 = TEST_FLAG_MU },   INT_MIN,  INT_MAX, 0, "flags"},
 +static const AVOption test_options[]= {
- {"num",      "set num",        OFFSET(num),      AV_OPT_TYPE_INT,      {.i64 = 0},       0,        100, 1              },
- {"toggle",   "set toggle",     OFFSET(toggle),   AV_OPT_TYPE_INT,      {.i64 = 1},       0,        1,   1              },
- {"rational", "set rational",   OFFSET(rational), AV_OPT_TYPE_RATIONAL, {.dbl = 1},       0,        10,  1              },
- {"string",   "set string",     OFFSET(string),   AV_OPT_TYPE_STRING,   {.str = "default"}, CHAR_MIN, CHAR_MAX, 1       },
- {"escape",   "set escape str", OFFSET(escape),   AV_OPT_TYPE_STRING,   {.str = "\\=,"}, CHAR_MIN, CHAR_MAX, 1          },
- {"flags",    "set flags",      OFFSET(flags),    AV_OPT_TYPE_FLAGS,    {.i64 = 1},       0,        INT_MAX, 1, "flags" },
- {"cool",     "set cool flag",  0,                AV_OPT_TYPE_CONST,    {.i64 = TEST_FLAG_COOL}, INT_MIN,  INT_MAX, 1, "flags" },
- {"lame",     "set lame flag",  0,                AV_OPT_TYPE_CONST,    {.i64 = TEST_FLAG_LAME}, INT_MIN,  INT_MAX, 1, "flags" },
- {"mu",       "set mu flag",    0,                AV_OPT_TYPE_CONST,    {.i64 = TEST_FLAG_MU},   INT_MIN,  INT_MAX, 1, "flags" },
- {"size",     "set size",       OFFSET(w),        AV_OPT_TYPE_IMAGE_SIZE,{.str="200x300"},             0,        0, 1},
- {"pix_fmt",  "set pixfmt",     OFFSET(pix_fmt),  AV_OPT_TYPE_PIXEL_FMT, {.i64 = AV_PIX_FMT_0BGR}, -1, INT_MAX, 1},
- {"sample_fmt", "set samplefmt", OFFSET(sample_fmt), AV_OPT_TYPE_SAMPLE_FMT, {.i64 = AV_SAMPLE_FMT_S16}, -1, INT_MAX, 1},
- {"video_rate", "set videorate", OFFSET(video_rate), AV_OPT_TYPE_VIDEO_RATE,  {.str = "25"}, 0,     0                   , 1},
- {"duration", "set duration",   OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = 1000}, 0, INT64_MAX, 1},
- {"color", "set color",   OFFSET(color), AV_OPT_TYPE_COLOR, {.str = "pink"}, 0, 0, 1},
- {"cl", "set channel layout", OFFSET(channel_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64 = AV_CH_LAYOUT_HEXAGONAL}, 0, INT64_MAX, 1},
- {"bin", "set binary value",    OFFSET(binary),   AV_OPT_TYPE_BINARY,   {.str="62696e00"}, 0,        0, 1 },
- {"bin1", "set binary value",   OFFSET(binary1),  AV_OPT_TYPE_BINARY,   {.str=NULL},       0,        0, 1 },
- {"bin2", "set binary value",   OFFSET(binary2),  AV_OPT_TYPE_BINARY,   {.str=""},         0,        0, 1 },
- {"num64",    "set num 64bit",  OFFSET(num64),    AV_OPT_TYPE_INT64,    {.i64 = 1},        0,        100, 1 },
- {"flt",      "set float",      OFFSET(flt),      AV_OPT_TYPE_FLOAT,    {.dbl = 1.0/3},    0,        100, 1},
- {"dbl",      "set double",     OFFSET(dbl),      AV_OPT_TYPE_DOUBLE,   {.dbl = 1.0/3},    0,        100, 1 },
- {"bool1", "set boolean value",  OFFSET(bool1),   AV_OPT_TYPE_BOOL,     {.i64 = -1},      -1,        1, 1 },
- {"bool2", "set boolean value",  OFFSET(bool2),   AV_OPT_TYPE_BOOL,     {.i64 = 1},       -1,        1, 1 },
- {"bool3", "set boolean value",  OFFSET(bool3),   AV_OPT_TYPE_BOOL,     {.i64 = 0},        0,        1, 1 },
- {NULL},
++    {"num",        "set num",            OFFSET(num),            AV_OPT_TYPE_INT,            { .i64 = 0 },                      0,       100, 1 },
++    {"toggle",     "set toggle",         OFFSET(toggle),         AV_OPT_TYPE_INT,            { .i64 = 1 },                      0,         1, 1 },
++    {"rational",   "set rational",       OFFSET(rational),       AV_OPT_TYPE_RATIONAL,       { .dbl = 1 },                      0,        10, 1 },
++    {"string",     "set string",         OFFSET(string),         AV_OPT_TYPE_STRING,         { .str = "default" },       CHAR_MIN,  CHAR_MAX, 1 },
++    {"escape",     "set escape str",     OFFSET(escape),         AV_OPT_TYPE_STRING,         { .str = "\\=," },          CHAR_MIN,  CHAR_MAX, 1 },
++    {"flags",      "set flags",          OFFSET(flags),          AV_OPT_TYPE_FLAGS,          { .i64 = 1 },                      0,   INT_MAX, 1, "flags" },
++    {"cool",       "set cool flag",      0,                      AV_OPT_TYPE_CONST,          { .i64 = TEST_FLAG_COOL },   INT_MIN,   INT_MAX, 1, "flags" },
++    {"lame",       "set lame flag",      0,                      AV_OPT_TYPE_CONST,          { .i64 = TEST_FLAG_LAME },   INT_MIN,   INT_MAX, 1, "flags" },
++    {"mu",         "set mu flag",        0,                      AV_OPT_TYPE_CONST,          { .i64 = TEST_FLAG_MU },     INT_MIN,   INT_MAX, 1, "flags" },
++    {"size",       "set size",           OFFSET(w),              AV_OPT_TYPE_IMAGE_SIZE,     { .str="200x300" },                0,         0, 1 },
++    {"pix_fmt",    "set pixfmt",         OFFSET(pix_fmt),        AV_OPT_TYPE_PIXEL_FMT,      { .i64 = AV_PIX_FMT_0BGR },       -1,   INT_MAX, 1 },
++    {"sample_fmt", "set samplefmt",      OFFSET(sample_fmt),     AV_OPT_TYPE_SAMPLE_FMT,     { .i64 = AV_SAMPLE_FMT_S16 },     -1,   INT_MAX, 1 },
++    {"video_rate", "set videorate",      OFFSET(video_rate),     AV_OPT_TYPE_VIDEO_RATE,     { .str = "25" },                   0,         0, 1 },
++    {"duration",   "set duration",       OFFSET(duration),       AV_OPT_TYPE_DURATION,       { .i64 = 1000 },                   0, INT64_MAX, 1 },
++    {"color",      "set color",          OFFSET(color),          AV_OPT_TYPE_COLOR,          { .str = "pink" },                 0,         0, 1 },
++    {"cl",         "set channel layout", OFFSET(channel_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, { .i64 = AV_CH_LAYOUT_HEXAGONAL }, 0, INT64_MAX, 1 },
++    {"bin",        "set binary value",   OFFSET(binary),         AV_OPT_TYPE_BINARY,         { .str="62696e00" },               0,         0, 1 },
++    {"bin1",       "set binary value",   OFFSET(binary1),        AV_OPT_TYPE_BINARY,         { .str=NULL },                     0,         0, 1 },
++    {"bin2",       "set binary value",   OFFSET(binary2),        AV_OPT_TYPE_BINARY,         { .str="" },                       0,         0, 1 },
++    {"num64",      "set num 64bit",      OFFSET(num64),          AV_OPT_TYPE_INT64,          { .i64 = 1 },                      0,       100, 1 },
++    {"flt",        "set float",          OFFSET(flt),            AV_OPT_TYPE_FLOAT,          { .dbl = 1.0 / 3 },                0,       100, 1 },
++    {"dbl",        "set double",         OFFSET(dbl),            AV_OPT_TYPE_DOUBLE,         { .dbl = 1.0 / 3 },                0,       100, 1 },
++    {"bool1",      "set boolean value",  OFFSET(bool1),          AV_OPT_TYPE_BOOL,           { .i64 = -1 },                    -1,         1, 1 },
++    {"bool2",      "set boolean value",  OFFSET(bool2),          AV_OPT_TYPE_BOOL,           { .i64 = 1 },                     -1,         1, 1 },
++    {"bool3",      "set boolean value",  OFFSET(bool3),          AV_OPT_TYPE_BOOL,           { .i64 = 0 },                      0,         1, 1 },
+     { NULL },
  };
  
  static const char *test_get_name(void *ctx)



More information about the ffmpeg-cvslog mailing list