[FFmpeg-devel,v3,1/5] avcodec/v210enc: add depth parameter for WRITE_PIXELS and CLIP

Submitted by lance.lmwang@gmail.com on Sept. 1, 2019, 1:20 p.m.

Details

Message ID 20190901132023.28531-1-lance.lmwang@gmail.com
State New
Headers show

Commit Message

lance.lmwang@gmail.com Sept. 1, 2019, 1:20 p.m.
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavcodec/v210enc.c | 83 +++++++++++++++++++++++-----------------------------
 1 file changed, 36 insertions(+), 47 deletions(-)

Comments

lance.lmwang@gmail.com Sept. 12, 2019, 3:32 p.m.
ping for the patchset.

On Sun, Sep 01, 2019 at 09:20:19PM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavcodec/v210enc.c | 83 +++++++++++++++++++++++-----------------------------
>  1 file changed, 36 insertions(+), 47 deletions(-)
> 
> diff --git a/libavcodec/v210enc.c b/libavcodec/v210enc.c
> index b024806..1b840b2 100644
> --- a/libavcodec/v210enc.c
> +++ b/libavcodec/v210enc.c
> @@ -26,25 +26,14 @@
>  #include "internal.h"
>  #include "v210enc.h"
>  
> -#define CLIP(v) av_clip(v, 4, 1019)
> -#define CLIP8(v) av_clip(v, 1, 254)
> -
> -#define WRITE_PIXELS(a, b, c)           \
> -    do {                                \
> -        val  =  CLIP(*a++);             \
> -        val |= (CLIP(*b++) << 10) |     \
> -               (CLIP(*c++) << 20);      \
> -        AV_WL32(dst, val);              \
> -        dst += 4;                       \
> -    } while (0)
> -
> -#define WRITE_PIXELS8(a, b, c)          \
> -    do {                                \
> -        val  = (CLIP8(*a++) << 2);      \
> -        val |= (CLIP8(*b++) << 12) |    \
> -               (CLIP8(*c++) << 22);     \
> -        AV_WL32(dst, val);              \
> -        dst += 4;                       \
> +#define CLIP(v, depth) av_clip(v, 1 << (depth-8), ((1 << depth)-(1 << (depth-8))-1))
> +#define WRITE_PIXELS(a, b, c, depth)                      \
> +    do {                                                  \
> +        val  =  CLIP(*a++, depth)  << (10-depth);         \
> +        val |=  (CLIP(*b++, depth) << (20-depth)) |       \
> +                (CLIP(*c++, depth) << (30-depth));        \
> +        AV_WL32(dst, val);                                \
> +        dst += 4;                                         \
>      } while (0)
>  
>  static void v210_planar_pack_8_c(const uint8_t *y, const uint8_t *u,
> @@ -56,14 +45,14 @@ static void v210_planar_pack_8_c(const uint8_t *y, const uint8_t *u,
>  
>      /* unroll this to match the assembly */
>      for (i = 0; i < width - 11; i += 12) {
> -        WRITE_PIXELS8(u, y, v);
> -        WRITE_PIXELS8(y, u, y);
> -        WRITE_PIXELS8(v, y, u);
> -        WRITE_PIXELS8(y, v, y);
> -        WRITE_PIXELS8(u, y, v);
> -        WRITE_PIXELS8(y, u, y);
> -        WRITE_PIXELS8(v, y, u);
> -        WRITE_PIXELS8(y, v, y);
> +        WRITE_PIXELS(u, y, v, 8);
> +        WRITE_PIXELS(y, u, y, 8);
> +        WRITE_PIXELS(v, y, u, 8);
> +        WRITE_PIXELS(y, v, y, 8);
> +        WRITE_PIXELS(u, y, v, 8);
> +        WRITE_PIXELS(y, u, y, 8);
> +        WRITE_PIXELS(v, y, u, 8);
> +        WRITE_PIXELS(y, v, y, 8);
>      }
>  }
>  
> @@ -75,10 +64,10 @@ static void v210_planar_pack_10_c(const uint16_t *y, const uint16_t *u,
>      int i;
>  
>      for (i = 0; i < width - 5; i += 6) {
> -        WRITE_PIXELS(u, y, v);
> -        WRITE_PIXELS(y, u, y);
> -        WRITE_PIXELS(v, y, u);
> -        WRITE_PIXELS(y, v, y);
> +        WRITE_PIXELS(u, y, v, 10);
> +        WRITE_PIXELS(y, u, y, 10);
> +        WRITE_PIXELS(v, y, u, 10);
> +        WRITE_PIXELS(y, v, y, 10);
>      }
>  }
>  
> @@ -153,26 +142,26 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
>              dst += sample_w * 16 * s->sample_factor_10;
>  
>              for (; w < avctx->width - 5; w += 6) {
> -                WRITE_PIXELS(u, y, v);
> -                WRITE_PIXELS(y, u, y);
> -                WRITE_PIXELS(v, y, u);
> -                WRITE_PIXELS(y, v, y);
> +                WRITE_PIXELS(u, y, v, 10);
> +                WRITE_PIXELS(y, u, y, 10);
> +                WRITE_PIXELS(v, y, u, 10);
> +                WRITE_PIXELS(y, v, y, 10);
>              }
>              if (w < avctx->width - 1) {
> -                WRITE_PIXELS(u, y, v);
> +                WRITE_PIXELS(u, y, v, 10);
>  
> -                val = CLIP(*y++);
> +                val = CLIP(*y++, 10);
>                  if (w == avctx->width - 2) {
>                      AV_WL32(dst, val);
>                      dst += 4;
>                  }
>              }
>              if (w < avctx->width - 3) {
> -                val |= (CLIP(*u++) << 10) | (CLIP(*y++) << 20);
> +                val |= (CLIP(*u++, 10) << 10) | (CLIP(*y++, 10) << 20);
>                  AV_WL32(dst, val);
>                  dst += 4;
>  
> -                val = CLIP(*v++) | (CLIP(*y++) << 10);
> +                val = CLIP(*v++, 10) | (CLIP(*y++, 10) << 10);
>                  AV_WL32(dst, val);
>                  dst += 4;
>              }
> @@ -202,26 +191,26 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
>              dst += sample_w * 32 * s->sample_factor_8;
>  
>              for (; w < avctx->width - 5; w += 6) {
> -                WRITE_PIXELS8(u, y, v);
> -                WRITE_PIXELS8(y, u, y);
> -                WRITE_PIXELS8(v, y, u);
> -                WRITE_PIXELS8(y, v, y);
> +                WRITE_PIXELS(u, y, v, 8);
> +                WRITE_PIXELS(y, u, y, 8);
> +                WRITE_PIXELS(v, y, u, 8);
> +                WRITE_PIXELS(y, v, y, 8);
>              }
>              if (w < avctx->width - 1) {
> -                WRITE_PIXELS8(u, y, v);
> +                WRITE_PIXELS(u, y, v, 8);
>  
> -                val = CLIP8(*y++) << 2;
> +                val = CLIP(*y++, 8) << 2;
>                  if (w == avctx->width - 2) {
>                      AV_WL32(dst, val);
>                      dst += 4;
>                  }
>              }
>              if (w < avctx->width - 3) {
> -                val |= (CLIP8(*u++) << 12) | (CLIP8(*y++) << 22);
> +                val |= (CLIP(*u++, 8) << 12) | (CLIP(*y++, 8) << 22);
>                  AV_WL32(dst, val);
>                  dst += 4;
>  
> -                val = (CLIP8(*v++) << 2) | (CLIP8(*y++) << 12);
> +                val = (CLIP(*v++, 8) << 2) | (CLIP(*y++, 8) << 12);
>                  AV_WL32(dst, val);
>                  dst += 4;
>              }
> -- 
> 2.6.4
>
Michael Niedermayer Sept. 16, 2019, 10:05 a.m.
On Thu, Sep 12, 2019 at 11:32:32PM +0800, Limin Wang wrote:
> 
> ping for the patchset.

output support for swscale would simplify testing

./ffplay matrixbench_mpeg2.mpg -vf format=y210
...
Impossible to convert between the formats supported by the filter 'ffplay_buffer' and the filter 'auto_scaler_0'


[...]
lance.lmwang@gmail.com Sept. 16, 2019, 11:11 a.m.
On Mon, Sep 16, 2019 at 12:05:45PM +0200, Michael Niedermayer wrote:
> On Thu, Sep 12, 2019 at 11:32:32PM +0800, Limin Wang wrote:
> > 
> > ping for the patchset.
> 
> output support for swscale would simplify testing
> 
> ./ffplay matrixbench_mpeg2.mpg -vf format=y210
> ...
> Impossible to convert between the formats supported by the filter 'ffplay_buffer' and the filter 'auto_scaler_0'
> 
Sorry, I haven't catch what's your intention. 
v210 is packed format, if we want to play *.v210 file, you can play by below
command:
./ffplay -s 3840x2160  ~/Movies/1.v210

or force to convertto yuv420p:
./ffplay -s 3840x2160  ~/Movies/1.v210 -vf format=yuv420p

For v210 in AVI, we can play it directly:
ffplay ../fate-suite/v210/v210_720p-partial.avi


> 
> [...]
> -- 
> 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
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Michael Niedermayer Sept. 16, 2019, 11:14 p.m.
On Mon, Sep 16, 2019 at 07:11:06PM +0800, Limin Wang wrote:
> On Mon, Sep 16, 2019 at 12:05:45PM +0200, Michael Niedermayer wrote:
> > On Thu, Sep 12, 2019 at 11:32:32PM +0800, Limin Wang wrote:
> > > 
> > > ping for the patchset.
> > 
> > output support for swscale would simplify testing
> > 
> > ./ffplay matrixbench_mpeg2.mpg -vf format=y210
> > ...
> > Impossible to convert between the formats supported by the filter 'ffplay_buffer' and the filter 'auto_scaler_0'
> > 
> Sorry, I haven't catch what's your intention. 
> v210 is packed format, if we want to play *.v210 file, you can play by below
> command:
> ./ffplay -s 3840x2160  ~/Movies/1.v210
> 
> or force to convertto yuv420p:
> ./ffplay -s 3840x2160  ~/Movies/1.v210 -vf format=yuv420p
> 
> For v210 in AVI, we can play it directly:
> ffplay ../fate-suite/v210/v210_720p-partial.avi

v210dec produces yuv422p10le unless i missed a patch not the v210 format so 
that doesnt work for testing the v210 pixel format

thx

[...]

Patch hide | download patch | download mbox

diff --git a/libavcodec/v210enc.c b/libavcodec/v210enc.c
index b024806..1b840b2 100644
--- a/libavcodec/v210enc.c
+++ b/libavcodec/v210enc.c
@@ -26,25 +26,14 @@ 
 #include "internal.h"
 #include "v210enc.h"
 
-#define CLIP(v) av_clip(v, 4, 1019)
-#define CLIP8(v) av_clip(v, 1, 254)
-
-#define WRITE_PIXELS(a, b, c)           \
-    do {                                \
-        val  =  CLIP(*a++);             \
-        val |= (CLIP(*b++) << 10) |     \
-               (CLIP(*c++) << 20);      \
-        AV_WL32(dst, val);              \
-        dst += 4;                       \
-    } while (0)
-
-#define WRITE_PIXELS8(a, b, c)          \
-    do {                                \
-        val  = (CLIP8(*a++) << 2);      \
-        val |= (CLIP8(*b++) << 12) |    \
-               (CLIP8(*c++) << 22);     \
-        AV_WL32(dst, val);              \
-        dst += 4;                       \
+#define CLIP(v, depth) av_clip(v, 1 << (depth-8), ((1 << depth)-(1 << (depth-8))-1))
+#define WRITE_PIXELS(a, b, c, depth)                      \
+    do {                                                  \
+        val  =  CLIP(*a++, depth)  << (10-depth);         \
+        val |=  (CLIP(*b++, depth) << (20-depth)) |       \
+                (CLIP(*c++, depth) << (30-depth));        \
+        AV_WL32(dst, val);                                \
+        dst += 4;                                         \
     } while (0)
 
 static void v210_planar_pack_8_c(const uint8_t *y, const uint8_t *u,
@@ -56,14 +45,14 @@  static void v210_planar_pack_8_c(const uint8_t *y, const uint8_t *u,
 
     /* unroll this to match the assembly */
     for (i = 0; i < width - 11; i += 12) {
-        WRITE_PIXELS8(u, y, v);
-        WRITE_PIXELS8(y, u, y);
-        WRITE_PIXELS8(v, y, u);
-        WRITE_PIXELS8(y, v, y);
-        WRITE_PIXELS8(u, y, v);
-        WRITE_PIXELS8(y, u, y);
-        WRITE_PIXELS8(v, y, u);
-        WRITE_PIXELS8(y, v, y);
+        WRITE_PIXELS(u, y, v, 8);
+        WRITE_PIXELS(y, u, y, 8);
+        WRITE_PIXELS(v, y, u, 8);
+        WRITE_PIXELS(y, v, y, 8);
+        WRITE_PIXELS(u, y, v, 8);
+        WRITE_PIXELS(y, u, y, 8);
+        WRITE_PIXELS(v, y, u, 8);
+        WRITE_PIXELS(y, v, y, 8);
     }
 }
 
@@ -75,10 +64,10 @@  static void v210_planar_pack_10_c(const uint16_t *y, const uint16_t *u,
     int i;
 
     for (i = 0; i < width - 5; i += 6) {
-        WRITE_PIXELS(u, y, v);
-        WRITE_PIXELS(y, u, y);
-        WRITE_PIXELS(v, y, u);
-        WRITE_PIXELS(y, v, y);
+        WRITE_PIXELS(u, y, v, 10);
+        WRITE_PIXELS(y, u, y, 10);
+        WRITE_PIXELS(v, y, u, 10);
+        WRITE_PIXELS(y, v, y, 10);
     }
 }
 
@@ -153,26 +142,26 @@  static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
             dst += sample_w * 16 * s->sample_factor_10;
 
             for (; w < avctx->width - 5; w += 6) {
-                WRITE_PIXELS(u, y, v);
-                WRITE_PIXELS(y, u, y);
-                WRITE_PIXELS(v, y, u);
-                WRITE_PIXELS(y, v, y);
+                WRITE_PIXELS(u, y, v, 10);
+                WRITE_PIXELS(y, u, y, 10);
+                WRITE_PIXELS(v, y, u, 10);
+                WRITE_PIXELS(y, v, y, 10);
             }
             if (w < avctx->width - 1) {
-                WRITE_PIXELS(u, y, v);
+                WRITE_PIXELS(u, y, v, 10);
 
-                val = CLIP(*y++);
+                val = CLIP(*y++, 10);
                 if (w == avctx->width - 2) {
                     AV_WL32(dst, val);
                     dst += 4;
                 }
             }
             if (w < avctx->width - 3) {
-                val |= (CLIP(*u++) << 10) | (CLIP(*y++) << 20);
+                val |= (CLIP(*u++, 10) << 10) | (CLIP(*y++, 10) << 20);
                 AV_WL32(dst, val);
                 dst += 4;
 
-                val = CLIP(*v++) | (CLIP(*y++) << 10);
+                val = CLIP(*v++, 10) | (CLIP(*y++, 10) << 10);
                 AV_WL32(dst, val);
                 dst += 4;
             }
@@ -202,26 +191,26 @@  static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
             dst += sample_w * 32 * s->sample_factor_8;
 
             for (; w < avctx->width - 5; w += 6) {
-                WRITE_PIXELS8(u, y, v);
-                WRITE_PIXELS8(y, u, y);
-                WRITE_PIXELS8(v, y, u);
-                WRITE_PIXELS8(y, v, y);
+                WRITE_PIXELS(u, y, v, 8);
+                WRITE_PIXELS(y, u, y, 8);
+                WRITE_PIXELS(v, y, u, 8);
+                WRITE_PIXELS(y, v, y, 8);
             }
             if (w < avctx->width - 1) {
-                WRITE_PIXELS8(u, y, v);
+                WRITE_PIXELS(u, y, v, 8);
 
-                val = CLIP8(*y++) << 2;
+                val = CLIP(*y++, 8) << 2;
                 if (w == avctx->width - 2) {
                     AV_WL32(dst, val);
                     dst += 4;
                 }
             }
             if (w < avctx->width - 3) {
-                val |= (CLIP8(*u++) << 12) | (CLIP8(*y++) << 22);
+                val |= (CLIP(*u++, 8) << 12) | (CLIP(*y++, 8) << 22);
                 AV_WL32(dst, val);
                 dst += 4;
 
-                val = (CLIP8(*v++) << 2) | (CLIP8(*y++) << 12);
+                val = (CLIP(*v++, 8) << 2) | (CLIP(*y++, 8) << 12);
                 AV_WL32(dst, val);
                 dst += 4;
             }