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

Clément Bœsch ubitux at gmail.com
Sun Nov 18 16:23:17 CET 2012


On Sun, Nov 18, 2012 at 01:06:29AM +0100, Michael Niedermayer wrote:
> On Sun, Nov 18, 2012 at 12:34:33AM +0100, Clément Bœsch wrote:
> > On Sun, Nov 18, 2012 at 12:24:45AM +0100, Michael Niedermayer wrote:
> > [...]
> > > > > 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.
> > > [...]
> > > 
> > > > --- 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);
> > > 
> > > before this there are general purpose flags allowing future extension
> > > after this they are not there anymore.
> > > I dont know if we will ever need such flags but it doesnt seem
> > > a good idea to me to drop them
> > > 
> > 
> > If that occurs, won't we instead choose to use AVOptions/av_class (like
> > every other libs of the projects), which should allow such flexibility? We
> > should be able to add this without major bumps.
> 
> Currently there are many projects using pp_get_context()
> If we would drop pp_get_context() every of them would need to be
> updated.
> If later we require yet another API to access some flags that again
> would reuquire every of these applications to be updated (if they
> want to use the flags or we drop pp_get_context2())
> also if they want to support older libpostproc prior to these
> changes it will get even harder for them
> 
> Thus i think droping either flags or pp_get_context() is not a good
> idea. 
> 

OK, as you prefer. New patch attached, along with a replacement for the
3rd patch.

-- 
Clément B.
-------------- next part --------------
From 59d686f100863d00b8f171dd891e893c2bfd951e 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 auto detection cpu flag.

---
 libpostproc/postprocess.c | 18 +++++++++++++-----
 libpostproc/postprocess.h |  1 +
 libpostproc/version.h     |  2 +-
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/libpostproc/postprocess.c b/libpostproc/postprocess.c
index b4ae866..c403298 100644
--- a/libpostproc/postprocess.c
+++ b/libpostproc/postprocess.c
@@ -586,11 +586,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 +896,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 +903,15 @@ pp_context *pp_get_context(int width, int height, int cpuCaps){
         c->hChromaSubSample= 1;
         c->vChromaSubSample= 1;
     }
+    if (cpuCaps & PP_CPU_CAPS_AUTO) {
+        c->cpuCaps = av_get_cpu_flags();
+    } else {
+        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);
 
diff --git a/libpostproc/postprocess.h b/libpostproc/postprocess.h
index 623b3b5..b1a357a 100644
--- a/libpostproc/postprocess.h
+++ b/libpostproc/postprocess.h
@@ -84,6 +84,7 @@ void pp_free_context(pp_context *ppContext);
 #define PP_CPU_CAPS_MMX2  0x20000000
 #define PP_CPU_CAPS_3DNOW 0x40000000
 #define PP_CPU_CAPS_ALTIVEC 0x10000000
+#define PP_CPU_CAPS_AUTO  0x00080000
 
 #define PP_FORMAT         0x00000008
 #define PP_FORMAT_420    (0x00000011|PP_FORMAT)
diff --git a/libpostproc/version.h b/libpostproc/version.h
index f634630..35e1772 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
 
-- 
1.8.0

-------------- next part --------------
From f6be711a69edd9f717e1728d04334d280dfd559a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <ubitux at gmail.com>
Date: Sun, 18 Nov 2012 15:12:37 +0100
Subject: [PATCH 3/5] lavfi/mp/pp: use PP_CPU_CAPS_AUTO.

---
 libavfilter/libmpcodecs/vf_pp.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/libavfilter/libmpcodecs/vf_pp.c b/libavfilter/libmpcodecs/vf_pp.c
index 78cce1f..713056f 100644
--- a/libavfilter/libmpcodecs/vf_pp.c
+++ b/libavfilter/libmpcodecs/vf_pp.c
@@ -54,10 +54,7 @@ struct vf_priv_s {
 static int config(struct vf_instance *vf,
         int width, int height, int d_width, int d_height,
         unsigned int voflags, unsigned int outfmt){
-    int flags=
-          (gCpuCaps.hasMMX   ? PP_CPU_CAPS_MMX   : 0)
-        | (gCpuCaps.hasMMX2  ? PP_CPU_CAPS_MMX2  : 0)
-        | (gCpuCaps.has3DNow ? PP_CPU_CAPS_3DNOW : 0);
+    int flags= PP_CPU_CAPS_AUTO;
 
     switch(outfmt){
     case IMGFMT_444P: flags|= PP_FORMAT_444; break;
-- 
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/20121118/f2209be5/attachment.asc>


More information about the ffmpeg-devel mailing list