---
 libavcodec/flacdec.c          |   10 +++++++--
 libavcodec/flacdsp.c          |   27 +++++++++++++++++++++++
 libavcodec/flacdsp_template.c |   47 ++++++++++++++++++++++++++++-------------
 3 files changed, 67 insertions(+), 17 deletions(-)

diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c
index 7295e2e..b92d5f0 100644
--- a/libavcodec/flacdec.c
+++ b/libavcodec/flacdec.c
@@ -105,10 +105,16 @@ int avpriv_flac_is_extradata_valid(AVCodecContext *avctx,
 static void flac_set_bps(FLACContext *s)
 {
     if (s->bps > 16) {
-        s->avctx->sample_fmt = AV_SAMPLE_FMT_S32;
+        if (s->avctx->request_sample_fmt == AV_SAMPLE_FMT_S32P)
+            s->avctx->sample_fmt = AV_SAMPLE_FMT_S32P;
+        else
+            s->avctx->sample_fmt = AV_SAMPLE_FMT_S32;
         s->sample_shift = 32 - s->bps;
     } else {
-        s->avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+        if (s->avctx->request_sample_fmt == AV_SAMPLE_FMT_S16P)
+            s->avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
+        else
+            s->avctx->sample_fmt = AV_SAMPLE_FMT_S16;
         s->sample_shift = 16 - s->bps;
     }
 }
diff --git a/libavcodec/flacdsp.c b/libavcodec/flacdsp.c
index fcee8e4..305830b 100644
--- a/libavcodec/flacdsp.c
+++ b/libavcodec/flacdsp.c
@@ -23,10 +23,21 @@
 #include "flacdsp.h"
 
 #define SAMPLE_SIZE 16
+#define PLANAR 0
+#include "flacdsp_template.c"
+
+#undef  PLANAR
+#define PLANAR 1
 #include "flacdsp_template.c"
 
 #undef  SAMPLE_SIZE
+#undef  PLANAR
 #define SAMPLE_SIZE 32
+#define PLANAR 0
+#include "flacdsp_template.c"
+
+#undef  PLANAR
+#define PLANAR 1
 #include "flacdsp_template.c"
 
 static void flac_lpc_16_c(int32_t *decoded, const int coeffs[32],
@@ -83,6 +94,14 @@ av_cold void ff_flacdsp_init(FLACDSPContext *c, enum 
AVSampleFormat fmt)
         c->lpc            = flac_lpc_32_c;
         break;
 
+    case AV_SAMPLE_FMT_S32P:
+        c->decorrelate[0] = flac_decorrelate_indep_c_32p;
+        c->decorrelate[1] = flac_decorrelate_ls_c_32p;
+        c->decorrelate[2] = flac_decorrelate_rs_c_32p;
+        c->decorrelate[3] = flac_decorrelate_ms_c_32p;
+        c->lpc            = flac_lpc_32_c;
+        break;
+
     case AV_SAMPLE_FMT_S16:
         c->decorrelate[0] = flac_decorrelate_indep_c_16;
         c->decorrelate[1] = flac_decorrelate_ls_c_16;
@@ -90,5 +109,13 @@ av_cold void ff_flacdsp_init(FLACDSPContext *c, enum 
AVSampleFormat fmt)
         c->decorrelate[3] = flac_decorrelate_ms_c_16;
         c->lpc            = flac_lpc_16_c;
         break;
+
+    case AV_SAMPLE_FMT_S16P:
+        c->decorrelate[0] = flac_decorrelate_indep_c_16p;
+        c->decorrelate[1] = flac_decorrelate_ls_c_16p;
+        c->decorrelate[2] = flac_decorrelate_rs_c_16p;
+        c->decorrelate[3] = flac_decorrelate_ms_c_16p;
+        c->lpc            = flac_lpc_16_c;
+        break;
     }
 }
diff --git a/libavcodec/flacdsp_template.c b/libavcodec/flacdsp_template.c
index 34da5a6..0affe22 100644
--- a/libavcodec/flacdsp_template.c
+++ b/libavcodec/flacdsp_template.c
@@ -19,68 +19,85 @@
  */
 
 #include <stdint.h>
+#include "libavutil/avutil.h"
 
 #undef FUNC
+#undef FSUF
 #undef sample
+#undef sample_type
+#undef OUT
+#undef S
 
 #if SAMPLE_SIZE == 32
-#   define FUNC(n) n ## _32
-#   define sample  int32_t
+#   define sample_type  int32_t
 #else
-#   define FUNC(n) n ## _16
-#   define sample  int16_t
+#   define sample_type  int16_t
 #endif
 
+#if PLANAR
+#   define FSUF   AV_JOIN(SAMPLE_SIZE, p)
+#   define sample sample_type *
+#   define OUT(n) n
+#   define S(s, c, i) (s[c][i])
+#else
+#   define FSUF   SAMPLE_SIZE
+#   define sample sample_type
+#   define OUT(n) n[0]
+#   define S(s, c, i) (*s++)
+#endif
+
+#define FUNC(n) AV_JOIN(n ## _, FSUF)
+
 static void FUNC(flac_decorrelate_indep_c)(uint8_t **out, int32_t **in,
                                            int channels, int len, int shift)
 {
-    sample *samples = (sample *) out[0];
+    sample *samples = (sample *) OUT(out);
     int i, j;
 
     for (j = 0; j < len; j++)
         for (i = 0; i < channels; i++)
-            *samples++ = in[i][j] << shift;
+            S(samples, i, j) = in[i][j] << shift;
 }
 
 static void FUNC(flac_decorrelate_ls_c)(uint8_t **out, int32_t **in,
                                         int channels, int len, int shift)
 {
-    sample *samples = (sample *) out[0];
+    sample *samples = (sample *) OUT(out);
     int i;
 
     for (i = 0; i < len; i++) {
         int a = in[0][i];
         int b = in[1][i];
-        *samples++ =  a      << shift;
-        *samples++ = (a - b) << shift;
+        S(samples, 0, i) =  a      << shift;
+        S(samples, 1, i) = (a - b) << shift;
     }
 }
 
 static void FUNC(flac_decorrelate_rs_c)(uint8_t **out, int32_t **in,
                                         int channels, int len, int shift)
 {
-    sample *samples = (sample *) out[0];
+    sample *samples = (sample *) OUT(out);
     int i;
 
     for (i = 0; i < len; i++) {
         int a = in[0][i];
         int b = in[1][i];
-        *samples++ = (a + b) << shift;
-        *samples++ =  b      << shift;
+        S(samples, 0, i) = (a + b) << shift;
+        S(samples, 1, i) =  b      << shift;
     }
 }
 
 static void FUNC(flac_decorrelate_ms_c)(uint8_t **out, int32_t **in,
                                         int channels, int len, int shift)
 {
-    sample *samples = (sample *) out[0];
+    sample *samples = (sample *) OUT(out);
     int i;
 
     for (i = 0; i < len; i++) {
         int a = in[0][i];
         int b = in[1][i];
         a -= b >> 1;
-        *samples++ = (a + b) << shift;
-        *samples++ =  a      << shift;
+        S(samples, 0, i) = (a + b) << shift;
+        S(samples, 1, i) =  a      << shift;
     }
 }
-- 
1.7.10.2

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to