>this would fail on beos acording to doc/errno.txt
Fixed, replaced with EINVAL in my private tree (
https://github.com/atomnuker/FFmpeg) and in the patch attached with this
email. Not sure how appropriate EINVAL is but other decoders use it too.

Also as suggested moved the vector functions to daala_pvq and unmarked the
larger functions as inline.

On 1 January 2016 at 20:44, Michael Niedermayer <mich...@niedermayer.cc>
wrote:

> On Fri, Jan 01, 2016 at 08:16:12PM +0000, Rostislav Pehlivanov wrote:
> [...]
>
> > +static av_cold int daala_decode_init(AVCodecContext *avctx)
> > +{
> > +    int i, r_w, r_h, err = 0;
> > +    DaalaContext *s = avctx->priv_data;
> > +
> > +    /* Inits a default QM, if the file isn't using the default it will
> be reinit */
> > +    s->last_qm = 1;
> > +    daala_init_qmatrix(s->pvq.qmatrix, s->pvq.qmatrix_inv, s->last_qm);
> > +
> > +    s->fmt = find_pix_fmt(avctx->pix_fmt);
> > +    if (!s->fmt) {
> > +        av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format - %s!\n",
> > +               av_get_pix_fmt_name(avctx->pix_fmt));
>
> > +        return AVERROR(ENOTSUP);
>
> this would fail on beos acording to doc/errno.txt
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> It is what and why we do it that matters, not just one of them.
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
From 7c18bb441fe993e855d7dc931edc19c0ccc6dbaa Mon Sep 17 00:00:00 2001
From: Rostislav Pehlivanov <atomnu...@gmail.com>
Date: Fri, 1 Jan 2016 21:15:32 +0000
Subject: [PATCH] Fixed errors on BeOS, moved functions and unmarked some as
 inline

Signed-off-by: Rostislav Pehlivanov <atomnu...@gmail.com>
---
 libavcodec/daala_entropy.h | 110 +-----------------------------------
 libavcodec/daala_pvq.h     | 136 +++++++++++++++++++++++++++++++++++++++------
 libavcodec/daaladec.c      |  22 ++++----
 3 files changed, 132 insertions(+), 136 deletions(-)

diff --git a/libavcodec/daala_entropy.h b/libavcodec/daala_entropy.h
index 11912d8..ace404f 100644
--- a/libavcodec/daala_entropy.h
+++ b/libavcodec/daala_entropy.h
@@ -58,12 +58,6 @@
 #define DAALAENT_WSIZE          (int)sizeof(ent_win)*CHAR_BIT
 #define DAALAENT_CDF_ACCESS(n)  (&ff_daalaent_cdf_tab[((n)*((n) - 1) >> 1) - 1])
 
-#define DAALAENT_PVQ_COUNT      2
-#define DAALAENT_PVQ_COUNT_EX   3
-#define DAALAENT_PVQ_K          0
-#define DAALAENT_PVQ_SUM_EX     1
-#define DAALAENT_PVQ_NOVAL      INT32_MIN
-
 enum DaalaCDFDecodeType {
     CDF_NORM = 0,
     CDF_Q15,
@@ -174,9 +168,9 @@ static inline uint8_t daalaent_decode_bool(DaalaEntropy *e, uint32_t p,
 }
 
 /* Decodes a symbol from a CDF table */
-static inline int daalaent_decode_cdf(DaalaEntropy *e, const ent_rng *cdf,
-                                      int cdf_size, uint32_t p_tot,
-                                      enum DaalaCDFDecodeType type)
+static int daalaent_decode_cdf(DaalaEntropy *e, const ent_rng *cdf,
+                               int cdf_size, uint32_t p_tot,
+                               enum DaalaCDFDecodeType type)
 {
     int d, lim, g, scale, ret = 0;
     ent_rng range = e->range;
@@ -360,104 +354,6 @@ static inline int daalaent_decode_laplace_pvq(DaalaEntropy *e, unsigned int exp_
     return (sym << shift) + lsb;
 }
 
-static inline void daalaent_decode_laplace_delta(DaalaEntropy *e, dctcoef *y,
-                                                 int n, int k, dctcoef *curr,
-                                                 const dctcoef *means)
-{
-    int i, k0 = k, k_left = k;
-    int prev = 0, sum_ex = 0, sum_c = 0, pos = 0;
-    int coef = 256*means[DAALAENT_PVQ_COUNT]/(1 + means[DAALAENT_PVQ_COUNT_EX]);
-    memset(y, 0, n*sizeof(dctcoef));
-    coef = FFMAX(coef, 1);
-    for (i = 0; i < k0; i++) {
-        int count;
-        if (!i) {
-            int decay;
-            int ex = coef*(n - prev)/k_left;
-            if (ex > 65280)
-                decay = 255;
-            else
-                decay = FFMIN(255, (int)((256*ex/(ex + 256) + (ex>>5)*ex/((n + 1)*(n - 1)*(n - 1)))));
-            count = daalaent_decode_laplace(e, decay, n - 1);
-        }
-        else
-            count = daalaent_decode_laplace_pvq(e, coef*(n - prev)/k_left, n - prev - 1);
-        sum_ex += 256*(n - prev);
-        sum_c += count*k_left;
-        pos += count;
-        av_assert0(pos < n);
-        y[pos] += daalaent_cphase(e, !y[pos]);
-        prev = pos;
-        k_left--;
-        if (!k_left)
-            break;
-    }
-    if (k > 0) {
-        curr[DAALAENT_PVQ_COUNT] = 256*sum_c;
-        curr[DAALAENT_PVQ_COUNT_EX] = sum_ex;
-    }
-    else {
-        curr[DAALAENT_PVQ_COUNT] = -1;
-        curr[DAALAENT_PVQ_COUNT_EX] = 0;
-    }
-    curr[DAALAENT_PVQ_K] = 0;
-    curr[DAALAENT_PVQ_SUM_EX] = 0;
-}
-
-/* Decodes quantized coefficients from  the bitsteam */
-static inline void daalaent_decode_laplace_vector(DaalaEntropy *e, dctcoef *y,
-                                                  int n, int k, dctcoef *curr,
-                                                  const dctcoef *means)
-{
-    int i, exp_q8, mean_k_q8, mean_sum_ex_q8, sum_ex = 0, kn = k, ran_delta = 0;
-    if (k <= 1) {
-        daalaent_decode_laplace_delta(e, y, n, k, curr, means);
-        return;
-    }
-    if (!k) {
-        curr[DAALAENT_PVQ_COUNT] = DAALAENT_PVQ_NOVAL;
-        curr[DAALAENT_PVQ_COUNT_EX] = DAALAENT_PVQ_NOVAL;
-        curr[DAALAENT_PVQ_K] = 0;
-        curr[DAALAENT_PVQ_SUM_EX] = 0;
-        memset(y, 0, n*sizeof(dctcoef));
-        return;
-    }
-    mean_k_q8 = means[DAALAENT_PVQ_K];
-    mean_sum_ex_q8 = means[DAALAENT_PVQ_SUM_EX];
-    if (mean_k_q8 < 1 << 23)
-        exp_q8 = 256*mean_k_q8/(1 + mean_sum_ex_q8);
-    else
-        exp_q8 = mean_k_q8/(1 + (mean_sum_ex_q8 >> 8));
-    for (i = 0; i < n; i++) {
-        int x, ex;
-        if (!kn)
-            break;
-        if (kn <= 1 && i != n - 1) {
-            daalaent_decode_laplace_delta(e, y + i, n - i, kn, curr, means);
-            ran_delta = 1;
-            i = n;
-            break;
-        }
-        ex = (2*exp_q8*kn + (n - i))/(2*(n - i));
-        if (ex > kn*256)
-            ex = kn*256;
-        sum_ex += (2*256*kn + (n - i))/(2*(n - i));
-        if (i != n - 1)
-            x = daalaent_decode_laplace_pvq(e, ex, kn);
-        else
-            x = kn;
-        y[i] = x*daalaent_cphase(e, x);
-        kn -= abs(x);
-    }
-    memset(&y[i], 0, (n - i)*sizeof(dctcoef)); /* Zero the rest */
-    if (!ran_delta) {
-        curr[DAALAENT_PVQ_COUNT] = DAALAENT_PVQ_NOVAL;
-        curr[DAALAENT_PVQ_COUNT_EX] = DAALAENT_PVQ_NOVAL;
-    }
-    curr[DAALAENT_PVQ_K] = k - kn;
-    curr[DAALAENT_PVQ_SUM_EX] = sum_ex;
-}
-
 /* Expectation value is in Q16 */
 static inline int daalaent_decode_generic(DaalaEntropy *e, DaalaCDF *c, int *ex,
                                           int max, int integrate)
diff --git a/libavcodec/daala_pvq.h b/libavcodec/daala_pvq.h
index d44e7e2..fcc446b 100644
--- a/libavcodec/daala_pvq.h
+++ b/libavcodec/daala_pvq.h
@@ -54,6 +54,12 @@
 #define DAALAPVQ_SKIP_COPY 2
 #define DAALAPVQ_PARTITIONS_MAX 9
 
+#define DAALAPVQ_COUNT      2
+#define DAALAPVQ_COUNT_EX   3
+#define DAALAPVQ_K          0
+#define DAALAPVQ_SUM_EX     1
+#define DAALAPVQ_NOVAL      INT32_MIN
+
 #define DAALAPVQ_MAX_PART_SIZE   (DAALA_QM_BSIZE/2)
 #define DAALAPVQ_COMPAND_SCALE   (256 << DAALA_CSHIFT)
 #define DAALAPVQ_COMPAND_SCALE_1 (1.0f/DAALAPVQ_COMPAND_SCALE)
@@ -226,6 +232,102 @@ static inline void daalapvq_synth(dctcoef *xcoeff, dctcoef *ypulse, dctcoef *ref
     }
 }
 
+static void daalapvq_decode_laplace_delta(DaalaEntropy *e, dctcoef *y,
+                                          int n, int k, dctcoef *curr,
+                                          const dctcoef *means)
+{
+    int i, k0 = k, k_left = k;
+    int prev = 0, sum_ex = 0, sum_c = 0, pos = 0;
+    int coef = 256*means[DAALAPVQ_COUNT]/(1 + means[DAALAPVQ_COUNT_EX]);
+    memset(y, 0, n*sizeof(dctcoef));
+    coef = FFMAX(coef, 1);
+    for (i = 0; i < k0; i++) {
+        int count;
+        if (!i) {
+            int decay;
+            int ex = coef*(n - prev)/k_left;
+            if (ex > 65280)
+                decay = 255;
+            else
+                decay = FFMIN(255, (int)((256*ex/(ex + 256) + (ex>>5)*ex/((n + 1)*(n - 1)*(n - 1)))));
+            count = daalaent_decode_laplace(e, decay, n - 1);
+        } else {
+            count = daalaent_decode_laplace_pvq(e, coef*(n - prev)/k_left, n - prev - 1);
+        }
+        sum_ex += 256*(n - prev);
+        sum_c += count*k_left;
+        pos += count;
+        av_assert0(pos < n);
+        y[pos] += daalaent_cphase(e, !y[pos]);
+        prev = pos;
+        k_left--;
+        if (!k_left)
+            break;
+    }
+    if (k > 0) {
+        curr[DAALAPVQ_COUNT] = 256*sum_c;
+        curr[DAALAPVQ_COUNT_EX] = sum_ex;
+    } else {
+        curr[DAALAPVQ_COUNT] = -1;
+        curr[DAALAPVQ_COUNT_EX] = 0;
+    }
+    curr[DAALAPVQ_SUM_EX] = curr[DAALAPVQ_K] = 0;
+}
+
+/* Decodes quantized coefficients from  the bitsteam */
+static void daalapvq_decode_laplace_vector(DaalaEntropy *e, dctcoef *y,
+                                           int n, int k, dctcoef *curr,
+                                           const dctcoef *means)
+{
+    int i, exp_q8, mean_k_q8, mean_sum_ex_q8, sum_ex = 0, kn = k, ran_delta = 0;
+    if (k <= 1) {
+        daalapvq_decode_laplace_delta(e, y, n, k, curr, means);
+        return;
+    }
+    if (!k) {
+        curr[DAALAPVQ_COUNT] = DAALAPVQ_NOVAL;
+        curr[DAALAPVQ_COUNT_EX] = DAALAPVQ_NOVAL;
+        curr[DAALAPVQ_K] = 0;
+        curr[DAALAPVQ_SUM_EX] = 0;
+        memset(y, 0, n*sizeof(dctcoef));
+        return;
+    }
+    mean_k_q8 = means[DAALAPVQ_K];
+    mean_sum_ex_q8 = means[DAALAPVQ_SUM_EX];
+    if (mean_k_q8 < 1 << 23)
+        exp_q8 = 256*mean_k_q8/(1 + mean_sum_ex_q8);
+    else
+        exp_q8 = mean_k_q8/(1 + (mean_sum_ex_q8 >> 8));
+    for (i = 0; i < n; i++) {
+        int x, ex;
+        if (!kn)
+            break;
+        if (kn <= 1 && i != n - 1) {
+            daalapvq_decode_laplace_delta(e, y + i, n - i, kn, curr, means);
+            ran_delta = 1;
+            i = n;
+            break;
+        }
+        ex = (2*exp_q8*kn + (n - i))/(2*(n - i));
+        if (ex > kn*256)
+            ex = kn*256;
+        sum_ex += (2*256*kn + (n - i))/(2*(n - i));
+        if (i != n - 1)
+            x = daalaent_decode_laplace_pvq(e, ex, kn);
+        else
+            x = kn;
+        y[i] = x*daalaent_cphase(e, x);
+        kn -= abs(x);
+    }
+    memset(&y[i], 0, (n - i)*sizeof(dctcoef)); /* Zero the rest */
+    if (!ran_delta) {
+        curr[DAALAPVQ_COUNT] = DAALAPVQ_NOVAL;
+        curr[DAALAPVQ_COUNT_EX] = DAALAPVQ_NOVAL;
+    }
+    curr[DAALAPVQ_K] = k - kn;
+    curr[DAALAPVQ_SUM_EX] = sum_ex;
+}
+
 static av_always_inline void daalapvq_adapt_shuffle(int *dst, int *src, int spd,
                                                     int idx, int mul)
 {
@@ -235,9 +337,9 @@ static av_always_inline void daalapvq_adapt_shuffle(int *dst, int *src, int spd,
     dst[idx+1] += (    src[idx+1] - dst[idx+1]) >> spd;
 }
 
-static inline void daalapvq_decode_codeword(DaalaEntropy *e, DaalaPVQ *pvq,
-                                            dctcoef *y, int n, int k, uint8_t has_ref,
-                                            enum DaalaBsize bsize)
+static void daalapvq_decode_codeword(DaalaEntropy *e, DaalaPVQ *pvq,
+                                     dctcoef *y, int n, int k, uint8_t has_ref,
+                                     enum DaalaBsize bsize)
 {
     int pos, adapt_curr[DAALAPVQ_NUM_ADAPTS] = {0};
     int *pvq_adapt = pvq->pvqadapt + 4*(2*bsize + !has_ref);
@@ -247,19 +349,17 @@ static inline void daalapvq_decode_codeword(DaalaEntropy *e, DaalaPVQ *pvq,
         memset(y, 0, n*sizeof(dctcoef));
         y[pos] = daalaent_cphase(e, 1);
     } else {
-        daalaent_decode_laplace_vector(e, y, n - !!has_ref, k, adapt_curr, pvq_adapt);
-        daalapvq_adapt_shuffle(pvq_adapt, adapt_curr, spd, DAALAENT_PVQ_K,   256);
-        daalapvq_adapt_shuffle(pvq_adapt, adapt_curr, spd, DAALAENT_PVQ_COUNT, 1);
+        daalapvq_decode_laplace_vector(e, y, n - !!has_ref, k, adapt_curr, pvq_adapt);
+        daalapvq_adapt_shuffle(pvq_adapt, adapt_curr, spd, DAALAPVQ_K,   256);
+        daalapvq_adapt_shuffle(pvq_adapt, adapt_curr, spd, DAALAPVQ_COUNT, 1);
     }
 }
 
-static inline void daalapvq_decode_vector(DaalaEntropy *e, DaalaPVQ *pvq,
-                                          dctcoef *out, dctcoef *ref,
-                                          const double beta,
-                                          uint8_t key_frame, int p,
-                                          uint8_t *skip_rest,
-                                          uint8_t has_err, int band_idx,
-                                          int qm_off, enum DaalaBsize bsize)
+static void daalapvq_decode_vector(DaalaEntropy *e, DaalaPVQ *pvq,
+                                   dctcoef *out, dctcoef *ref, const double beta,
+                                   uint8_t key_frame, int p, uint8_t *skip_rest,
+                                   uint8_t has_err, int band_idx,
+                                   int qm_off, enum DaalaBsize bsize)
 {
     int i, k;
     int qg = 0, skip = 0, itheta = (!!key_frame), has_ref = !key_frame;
@@ -347,11 +447,11 @@ static inline void daalapvq_decode_vector(DaalaEntropy *e, DaalaPVQ *pvq,
 }
 
 /* q: quantizer, qm = bitstream_header->pvq_qm[p] */
-static inline void daalapvq_decode(DaalaEntropy *e, DaalaPVQ *pvq,
-                                   DaalaBitstreamHeader *b, dctcoef *ref,
-                                   dctcoef *out, int q, uint8_t *pvq_qm, uint8_t p,
-                                   enum DaalaBsize bsize, const double *beta,
-                                   int qm_off, int bskip)
+static void daalapvq_decode(DaalaEntropy *e, DaalaPVQ *pvq,
+                            DaalaBitstreamHeader *b, dctcoef *ref,
+                            dctcoef *out, int q, uint8_t *pvq_qm, uint8_t p,
+                            enum DaalaBsize bsize, const double *beta,
+                            int qm_off, int bskip)
 {
     int i, j;
     int bands = ff_daala_layouts[bsize].band_offset_size;
diff --git a/libavcodec/daaladec.c b/libavcodec/daaladec.c
index 1beab11..ba8f11d 100644
--- a/libavcodec/daaladec.c
+++ b/libavcodec/daaladec.c
@@ -375,7 +375,7 @@ static void decode_block_haar(DaalaContext *s, int x, int y, uint8_t p,
                     (uint8_t *)(s->dcoef[p] + boffset), aw, bsize);
 }
 
-static void init_skipped(dctcoef *d, int ostride, dctcoef *pred, int istride,
+static inline void init_skipped(dctcoef *d, int ostride, dctcoef *pred, int istride,
                          int key_frame)
 {
     int i, j;
@@ -388,8 +388,8 @@ static void init_skipped(dctcoef *d, int ostride, dctcoef *pred, int istride,
 }
 
 /* PVQ decoding and transform */
-static inline void decode_block_pvq(DaalaContext *s, int x, int y, uint8_t p,
-                                    enum DaalaBsize bsize, int skip)
+static void decode_block_pvq(DaalaContext *s, int x, int y, uint8_t p,
+                             enum DaalaBsize bsize, int skip)
 {
     const int sx = x << bsize;
     const int sy = y << bsize;
@@ -424,8 +424,8 @@ static inline void decode_block_pvq(DaalaContext *s, int x, int y, uint8_t p,
 }
 
 /* Segments frame && decodes */
-static inline int decode_block_rec(DaalaContext *s, HaarGradient g,
-                                   int x, int y, uint8_t p, enum DaalaBsize bsize)
+static int decode_block_rec(DaalaContext *s, HaarGradient g, int x, int y,
+                            uint8_t p, enum DaalaBsize bsize)
 {
     int i, j, lc_skip, cbs;
     const int sx = x << bsize;
@@ -558,10 +558,10 @@ static void reset_cdfs(DaalaContext *s)
         s->pvq.pvqtheta_ex[i] = s->h.key_frame ? 24576 : pvq_ex_const;
 
     for (i = 0; i < 2*DAALA_NBSIZES; i++) {
-        s->pvq.pvqadapt[4*i + DAALAENT_PVQ_K] = 384;
-        s->pvq.pvqadapt[4*i + DAALAENT_PVQ_SUM_EX] = 256;
-        s->pvq.pvqadapt[4*i + DAALAENT_PVQ_COUNT] = 104;
-        s->pvq.pvqadapt[4*i + DAALAENT_PVQ_COUNT_EX] = 128;
+        s->pvq.pvqadapt[4*i + DAALAPVQ_K] = 384;
+        s->pvq.pvqadapt[4*i + DAALAPVQ_SUM_EX] = 256;
+        s->pvq.pvqadapt[4*i + DAALAPVQ_COUNT] = 104;
+        s->pvq.pvqadapt[4*i + DAALAPVQ_COUNT_EX] = 128;
     }
 
     for (i = 0; i < s->fmt->planes; i++) {
@@ -711,13 +711,13 @@ static av_cold int daala_decode_init(AVCodecContext *avctx)
     if (!s->fmt) {
         av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format - %s!\n",
                av_get_pix_fmt_name(avctx->pix_fmt));
-        return AVERROR(ENOTSUP);
+        return AVERROR(EINVAL);
     }
 
     if (ff_daaladsp_init(&s->dsp, s->fmt->depth)) {
         av_log(avctx, AV_LOG_ERROR, "Unsupported bit depth - %i!\n",
                s->fmt->depth);
-        return AVERROR(ENOTSUP);
+        return AVERROR(EINVAL);
     }
 
     /* Can be turned on for 8 bit files too and the demuxer gets it, but how
-- 
2.6.4

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to