[FFmpeg-devel] [PATCH 2/5] swscale: preparation for use of AV_CPU_FLAG_*
Janne Grunau
janne-ffmpeg
Tue Sep 28 00:25:00 CEST 2010
add dsp_mask to swsContext and AVOptions to fill them
add function to convert sws_cpu_caps* to av_cpu_flag*
---
libswscale/options.c | 10 ++++++++++
libswscale/swscale_internal.h | 1 +
libswscale/utils.c | 34 ++++++++++++++++++++++++++++++++--
3 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/libswscale/options.c b/libswscale/options.c
index 96e64c6..2d80941 100644
--- a/libswscale/options.c
+++ b/libswscale/options.c
@@ -19,6 +19,7 @@
*/
#include "libavutil/avutil.h"
+#include "libavutil/cpu.h"
#include "libavcodec/opt.h"
#include "swscale.h"
#include "swscale_internal.h"
@@ -68,6 +69,15 @@ static const AVOption options[] = {
{ "param0" , "scaler param 0" , OFFSET(param[0]) , FF_OPT_TYPE_DOUBLE, DEFAULT, INT_MIN, INT_MAX, VE },
{ "param1" , "scaler param 1" , OFFSET(param[1]) , FF_OPT_TYPE_DOUBLE, DEFAULT, INT_MIN, INT_MAX, VE },
+ { "sws_dsp_mask", "override cpu flags", OFFSET(dsp_mask), FF_OPT_TYPE_FLAGS, DEFAULT, 0, UINT_MAX, VE, "sws_dsp_mask" },
+ { "null", "no SIMD acceleration", 0, FF_OPT_TYPE_CONST, AV_CPU_FLAG_FORCE, INT_MIN, INT_MAX, VE, "sws_dsp_mask" },
+ { "mmx", "MMX SIMD acceleration", 0, FF_OPT_TYPE_CONST, AV_CPU_FLAG_FORCE|AV_CPU_FLAG_MMX, INT_MIN, INT_MAX, VE, "sws_dsp_mask" },
+ { "mmx2", "MMX2 SIMD acceleration", 0, FF_OPT_TYPE_CONST, AV_CPU_FLAG_FORCE|AV_CPU_FLAG_MMX2, INT_MIN, INT_MAX, VE, "sws_dsp_mask" },
+ { "sse2", "SSE2 SIMD acceleration", 0, FF_OPT_TYPE_CONST, AV_CPU_FLAG_FORCE|AV_CPU_FLAG_SSE2, INT_MIN, INT_MAX, VE, "sws_dsp_mask" },
+ { "3dnow", "3DNOW SIMD acceleration", 0, FF_OPT_TYPE_CONST, AV_CPU_FLAG_FORCE|AV_CPU_FLAG_3DNOW, INT_MIN, INT_MAX, VE, "sws_dsp_mask" },
+ { "altivec", "AltiVec SIMD acceleration", 0, FF_OPT_TYPE_CONST, AV_CPU_FLAG_FORCE|AV_CPU_FLAG_ALTIVEC, INT_MIN, UINT_MAX, VE, "sws_dsp_mask" },
+ { "bfin", "Blackfin SIMD acceleration", 0, FF_OPT_TYPE_CONST, AV_CPU_FLAG_FORCE|AV_CPU_FLAG_BFIN, INT_MIN, INT_MAX, VE, "sws_dsp_mask" },
+
{ NULL }
};
diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index d5df298..ad81a89 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -314,6 +314,7 @@ typedef struct SwsContext {
int needs_hcscale; ///< Set if there are chroma planes to be converted.
+ unsigned dsp_mask; ///< Flags passed by the user to select optimizations
} SwsContext;
//FIXME check init (where 0)
diff --git a/libswscale/utils.c b/libswscale/utils.c
index b52a793..24dc1fc 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -43,6 +43,7 @@
#include "libavutil/x86_cpu.h"
#include "libavutil/avutil.h"
#include "libavutil/bswap.h"
+#include "libavutil/cpu.h"
#include "libavutil/pixdesc.h"
unsigned swscale_version(void)
@@ -726,15 +727,21 @@ static int handle_jpeg(enum PixelFormat *format)
}
}
-static int update_flags_cpu(int flags)
+static int strip_cpu_flags(int flags)
{
-#if !CONFIG_RUNTIME_CPUDETECT //ensure that the flags match the compiled variant if cpudetect is off
flags &= ~( SWS_CPU_CAPS_MMX
|SWS_CPU_CAPS_MMX2
|SWS_CPU_CAPS_3DNOW
|SWS_CPU_CAPS_SSE2
|SWS_CPU_CAPS_ALTIVEC
|SWS_CPU_CAPS_BFIN);
+ return flags;
+}
+
+static int update_flags_cpu(int flags)
+{
+#if !CONFIG_RUNTIME_CPUDETECT //ensure that the flags match the compiled variant if cpudetect is off
+ flags = strip_cpu_flags(flags);
flags |= ff_hardcodedcpuflags();
#endif /* CONFIG_RUNTIME_CPUDETECT */
return flags;
@@ -748,6 +755,26 @@ SwsContext *sws_alloc_context(void){
return c;
}
+static unsigned sws_cpu_caps2av_cpu_flags(int flags)
+{
+ unsigned cpuflags = 0;
+
+ if (ARCH_X86 && flags & SWS_CPU_CAPS_MMX)
+ cpuflags |= AV_CPU_FLAG_MMX;
+ if (ARCH_X86 && flags & SWS_CPU_CAPS_MMX2)
+ cpuflags |= AV_CPU_FLAG_MMX2;
+ if (ARCH_X86 && flags & SWS_CPU_CAPS_3DNOW)
+ cpuflags |= AV_CPU_FLAG_3DNOW;;
+ if (ARCH_X86 && flags & SWS_CPU_CAPS_SSE2)
+ cpuflags |= AV_CPU_FLAG_SSE2;
+ if (ARCH_PPC && flags & SWS_CPU_CAPS_ALTIVEC)
+ cpuflags |= AV_CPU_FLAG_ALTIVEC;
+ if (ARCH_BFIN && flags & SWS_CPU_CAPS_BFIN)
+ cpuflags |= AV_CPU_FLAG_BFIN;
+
+ return cpuflags;
+}
+
int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter){
int i;
int usesVFilter, usesHFilter;
@@ -758,9 +785,12 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter){
int dstW= c->dstW;
int dstH= c->dstH;
int flags;
+ unsigned dsp_mask;
enum PixelFormat srcFormat= c->srcFormat;
enum PixelFormat dstFormat= c->dstFormat;
+ dsp_mask = c->dsp_mask = sws_cpu_caps2av_cpu_flags(update_flags_cpu(c->flags));
+
flags= c->flags = update_flags_cpu(c->flags);
#if ARCH_X86
if (flags & SWS_CPU_CAPS_MMX)
--
1.7.3
More information about the ffmpeg-devel
mailing list