[FFmpeg-devel] [PATCH 2/5] pp: add pp_get_context2().

Clément Bœsch ubitux at gmail.com
Sat Nov 17 19:59:50 CET 2012


On Sat, Nov 17, 2012 at 07:33:21PM +0100, Michael Niedermayer wrote:
> On Sat, Nov 17, 2012 at 01:07:10PM +0100, Clément Bœsch wrote:
> > ---
> >  libpostproc/postprocess.c | 42 +++++++++++++++++++++++++++++++++++++-----
> >  libpostproc/postprocess.h |  3 ++-
> >  libpostproc/version.h     |  2 +-
> >  3 files changed, 40 insertions(+), 7 deletions(-)
> > 
> > diff --git a/libpostproc/postprocess.c b/libpostproc/postprocess.c
> > index b4ae866..21238fd 100644
> > --- a/libpostproc/postprocess.c
> > +++ b/libpostproc/postprocess.c
> > @@ -88,6 +88,7 @@ try to unroll inner for(x=0 ... loop to avoid these damn if(x ... checks
> >  #include "postprocess.h"
> >  #include "postprocess_internal.h"
> >  #include "libavutil/avstring.h"
> > +#include "libavutil/pixdesc.h"
> >  
> >  unsigned postproc_version(void)
> >  {
> > @@ -586,11 +587,11 @@ static inline void postProcess(const uint8_t src[], int srcStride, uint8_t dst[]
> >  #if CONFIG_RUNTIME_CPUDETECT
> >  #if ARCH_X86 && HAVE_INLINE_ASM
> >          // ordered per speed fastest first
> > -        if      (c->cpuCaps & PP_CPU_CAPS_MMX2)     pp = postProcess_MMX2;
> > -        else if (c->cpuCaps & PP_CPU_CAPS_3DNOW)    pp = postProcess_3DNow;
> > -        else if (c->cpuCaps & PP_CPU_CAPS_MMX)      pp = postProcess_MMX;
> > +        if      (c->cpuCaps & AV_CPU_FLAG_MMXEXT)   pp = postProcess_MMX2;
> > +        else if (c->cpuCaps & AV_CPU_FLAG_3DNOW)    pp = postProcess_3DNow;
> > +        else if (c->cpuCaps & AV_CPU_FLAG_MMX)      pp = postProcess_MMX;
> >  #elif HAVE_ALTIVEC
> > -        if      (c->cpuCaps & PP_CPU_CAPS_ALTIVEC)  pp = postProcess_altivec;
> > +        if      (c->cpuCaps & AV_CPU_FLAG_ALTIVEC)  pp = postProcess_altivec;
> >  #endif
> >  #else /* CONFIG_RUNTIME_CPUDETECT */
> >  #if   HAVE_MMXEXT_INLINE
> > @@ -896,7 +897,6 @@ pp_context *pp_get_context(int width, int height, int cpuCaps){
> >  
> >      memset(c, 0, sizeof(PPContext));
> >      c->av_class = &av_codec_context_class;
> > -    c->cpuCaps= cpuCaps;
> >      if(cpuCaps&PP_FORMAT){
> >          c->hChromaSubSample= cpuCaps&0x3;
> >          c->vChromaSubSample= (cpuCaps>>4)&0x3;
> > @@ -904,6 +904,11 @@ pp_context *pp_get_context(int width, int height, int cpuCaps){
> >          c->hChromaSubSample= 1;
> >          c->vChromaSubSample= 1;
> >      }
> > +    c->cpuCaps = 0;
> > +    if (cpuCaps & PP_CPU_CAPS_MMX)      c->cpuCaps |= AV_CPU_FLAG_MMX;
> > +    if (cpuCaps & PP_CPU_CAPS_MMX2)     c->cpuCaps |= AV_CPU_FLAG_MMXEXT;
> > +    if (cpuCaps & PP_CPU_CAPS_3DNOW)    c->cpuCaps |= AV_CPU_FLAG_3DNOW;
> > +    if (cpuCaps & PP_CPU_CAPS_ALTIVEC)  c->cpuCaps |= AV_CPU_FLAG_ALTIVEC;
> >  
> >      reallocBuffers(c, width, height, stride, qpStride);
> >  
> > @@ -912,6 +917,33 @@ pp_context *pp_get_context(int width, int height, int cpuCaps){
> >      return c;
> >  }
> >  
> > +pp_context *pp_get_context2(int width, int height, int pixfmt)
> > +{
> > +    PPContext *c;
> > +    int stride   = FFALIGN(width, 16);  //assumed / will realloc if needed
> > +    int qpStride = (width+15)/16 + 2;   //assumed / will realloc if needed
> > +    const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(pixfmt);
> > +
> > +    if (!pix_desc) {
> > +        av_log(NULL, AV_LOG_ERROR, "Unknown pixel format %d\n", pixfmt);
> > +        return NULL;
> > +    }
> > +
> > +    c = av_mallocz(sizeof(*c));
> > +    if (!c)
> > +        return NULL;
> > +
> > +    c->cpuCaps  = av_get_cpu_flags();
> > +    c->av_class = &av_codec_context_class;
> > +    c->hChromaSubSample = pix_desc->log2_chroma_w;
> > +    c->vChromaSubSample = pix_desc->log2_chroma_h;
> > +
> > +    reallocBuffers(c, width, height, stride, qpStride);
> > +
> > +    c->frameNum = -1;
> > +    return c;
> > +}
> > +
> >  void pp_free_context(void *vc){
> >      PPContext *c = (PPContext*)vc;
> >      int i;
> > diff --git a/libpostproc/postprocess.h b/libpostproc/postprocess.h
> > index 623b3b5..af6d55a 100644
> > --- a/libpostproc/postprocess.h
> > +++ b/libpostproc/postprocess.h
> > @@ -77,7 +77,8 @@ void  pp_postprocess(const uint8_t * src[3], const int srcStride[3],
> >  pp_mode *pp_get_mode_by_name_and_quality(const char *name, int quality);
> >  void pp_free_mode(pp_mode *mode);
> >  
> > -pp_context *pp_get_context(int width, int height, int flags);
> > +attribute_deprecated pp_context *pp_get_context(int width, int height, int flags);
> > +pp_context *pp_get_context2(int width, int height, int pixfmt);
> >  void pp_free_context(pp_context *ppContext);
> 
> Is this neccessary ?
> wouldnt simply adding a PP_CPU_CAPS_AUTO achive nearly the same ?
> 

Sure, but I thought it would be better to get rid at some point of the
duplicated flags and pixel formats; that's the main reason of that patch,
we can remove all the PP macro and allow a better integration with FFmpeg.

This will also allow a native vf pp to not bother anymore about a pixel
formats mapping.

New attached patch clarifies how it would look at next major bump.

-- 
Clément B.
-------------- next part --------------
From f4de7b21a3e7f5df332b967ca3a77a47f86269f2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <ubitux at gmail.com>
Date: Wed, 14 Nov 2012 23:21:56 +0100
Subject: [PATCH 2/5] pp: add pp_get_context2().

---
 libpostproc/postprocess.c | 44 +++++++++++++++++++++++++++++++++++++++-----
 libpostproc/postprocess.h |  5 ++++-
 libpostproc/version.h     |  6 +++++-
 3 files changed, 48 insertions(+), 7 deletions(-)

diff --git a/libpostproc/postprocess.c b/libpostproc/postprocess.c
index b4ae866..8db20bf 100644
--- a/libpostproc/postprocess.c
+++ b/libpostproc/postprocess.c
@@ -88,6 +88,7 @@ try to unroll inner for(x=0 ... loop to avoid these damn if(x ... checks
 #include "postprocess.h"
 #include "postprocess_internal.h"
 #include "libavutil/avstring.h"
+#include "libavutil/pixdesc.h"
 
 unsigned postproc_version(void)
 {
@@ -586,11 +587,11 @@ static inline void postProcess(const uint8_t src[], int srcStride, uint8_t dst[]
 #if CONFIG_RUNTIME_CPUDETECT
 #if ARCH_X86 && HAVE_INLINE_ASM
         // ordered per speed fastest first
-        if      (c->cpuCaps & PP_CPU_CAPS_MMX2)     pp = postProcess_MMX2;
-        else if (c->cpuCaps & PP_CPU_CAPS_3DNOW)    pp = postProcess_3DNow;
-        else if (c->cpuCaps & PP_CPU_CAPS_MMX)      pp = postProcess_MMX;
+        if      (c->cpuCaps & AV_CPU_FLAG_MMXEXT)   pp = postProcess_MMX2;
+        else if (c->cpuCaps & AV_CPU_FLAG_3DNOW)    pp = postProcess_3DNow;
+        else if (c->cpuCaps & AV_CPU_FLAG_MMX)      pp = postProcess_MMX;
 #elif HAVE_ALTIVEC
-        if      (c->cpuCaps & PP_CPU_CAPS_ALTIVEC)  pp = postProcess_altivec;
+        if      (c->cpuCaps & AV_CPU_FLAG_ALTIVEC)  pp = postProcess_altivec;
 #endif
 #else /* CONFIG_RUNTIME_CPUDETECT */
 #if   HAVE_MMXEXT_INLINE
@@ -889,6 +890,7 @@ static const char * context_to_name(void * ptr) {
 
 static const AVClass av_codec_context_class = { "Postproc", context_to_name, NULL };
 
+#if PP_API_GET_CONTEXT
 pp_context *pp_get_context(int width, int height, int cpuCaps){
     PPContext *c= av_malloc(sizeof(PPContext));
     int stride= FFALIGN(width, 16);  //assumed / will realloc if needed
@@ -896,7 +898,6 @@ pp_context *pp_get_context(int width, int height, int cpuCaps){
 
     memset(c, 0, sizeof(PPContext));
     c->av_class = &av_codec_context_class;
-    c->cpuCaps= cpuCaps;
     if(cpuCaps&PP_FORMAT){
         c->hChromaSubSample= cpuCaps&0x3;
         c->vChromaSubSample= (cpuCaps>>4)&0x3;
@@ -904,6 +905,11 @@ pp_context *pp_get_context(int width, int height, int cpuCaps){
         c->hChromaSubSample= 1;
         c->vChromaSubSample= 1;
     }
+    c->cpuCaps = 0;
+    if (cpuCaps & PP_CPU_CAPS_MMX)      c->cpuCaps |= AV_CPU_FLAG_MMX;
+    if (cpuCaps & PP_CPU_CAPS_MMX2)     c->cpuCaps |= AV_CPU_FLAG_MMXEXT;
+    if (cpuCaps & PP_CPU_CAPS_3DNOW)    c->cpuCaps |= AV_CPU_FLAG_3DNOW;
+    if (cpuCaps & PP_CPU_CAPS_ALTIVEC)  c->cpuCaps |= AV_CPU_FLAG_ALTIVEC;
 
     reallocBuffers(c, width, height, stride, qpStride);
 
@@ -911,6 +917,34 @@ pp_context *pp_get_context(int width, int height, int cpuCaps){
 
     return c;
 }
+#endif
+
+pp_context *pp_get_context2(int width, int height, int pixfmt)
+{
+    PPContext *c;
+    int stride   = FFALIGN(width, 16);  //assumed / will realloc if needed
+    int qpStride = (width+15)/16 + 2;   //assumed / will realloc if needed
+    const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(pixfmt);
+
+    if (!pix_desc) {
+        av_log(NULL, AV_LOG_ERROR, "Unknown pixel format %d\n", pixfmt);
+        return NULL;
+    }
+
+    c = av_mallocz(sizeof(*c));
+    if (!c)
+        return NULL;
+
+    c->cpuCaps  = av_get_cpu_flags();
+    c->av_class = &av_codec_context_class;
+    c->hChromaSubSample = pix_desc->log2_chroma_w;
+    c->vChromaSubSample = pix_desc->log2_chroma_h;
+
+    reallocBuffers(c, width, height, stride, qpStride);
+
+    c->frameNum = -1;
+    return c;
+}
 
 void pp_free_context(void *vc){
     PPContext *c = (PPContext*)vc;
diff --git a/libpostproc/postprocess.h b/libpostproc/postprocess.h
index 623b3b5..4107141 100644
--- a/libpostproc/postprocess.h
+++ b/libpostproc/postprocess.h
@@ -77,9 +77,11 @@ void  pp_postprocess(const uint8_t * src[3], const int srcStride[3],
 pp_mode *pp_get_mode_by_name_and_quality(const char *name, int quality);
 void pp_free_mode(pp_mode *mode);
 
-pp_context *pp_get_context(int width, int height, int flags);
+pp_context *pp_get_context2(int width, int height, int pixfmt);
 void pp_free_context(pp_context *ppContext);
 
+#if PP_API_GET_CONTEXT
+attribute_deprecated pp_context *pp_get_context(int width, int height, int flags);
 #define PP_CPU_CAPS_MMX   0x80000000
 #define PP_CPU_CAPS_MMX2  0x20000000
 #define PP_CPU_CAPS_3DNOW 0x40000000
@@ -90,6 +92,7 @@ void pp_free_context(pp_context *ppContext);
 #define PP_FORMAT_422    (0x00000001|PP_FORMAT)
 #define PP_FORMAT_411    (0x00000002|PP_FORMAT)
 #define PP_FORMAT_444    (0x00000000|PP_FORMAT)
+#endif
 
 #define PP_PICT_TYPE_QP2  0x00000010 ///< MPEG2 style QScale
 
diff --git a/libpostproc/version.h b/libpostproc/version.h
index f634630..fca8bc4 100644
--- a/libpostproc/version.h
+++ b/libpostproc/version.h
@@ -30,7 +30,7 @@
 
 #ifndef LIBPOSTPROC_VERSION_MAJOR
 #define LIBPOSTPROC_VERSION_MAJOR 52
-#define LIBPOSTPROC_VERSION_MINOR  1
+#define LIBPOSTPROC_VERSION_MINOR  2
 #define LIBPOSTPROC_VERSION_MICRO 100
 #endif
 
@@ -44,4 +44,8 @@
 
 #define LIBPOSTPROC_IDENT       "postproc" AV_STRINGIFY(LIBPOSTPROC_VERSION)
 
+#ifndef PP_API_GET_CONTEXT
+#define PP_API_GET_CONTEXT (LIBPOSTPROC_VERSION_MAJOR < 53)
+#endif
+
 #endif /* POSTPROC_POSTPROCESS_VERSION_H */
-- 
1.8.0

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121117/423073ce/attachment.asc>


More information about the ffmpeg-devel mailing list