shithub: openh264

Download patch

ref: fc8fcc2e626cd146fcc724cf8575c21aa5653334
parent: 73cc5862bad6518709f9a74f194d008fd2150734
parent: d411d768b6cf3d6b5e51f279eaec3d59e6233a2c
author: volvet <[email protected]>
date: Tue Mar 4 15:57:32 EST 2014

Merge pull request #402 from mstorsjo/unify-cpu-feature-detect

Unify the interface for the different variants of WelsCPUFeatureDetect

--- a/codec/common/cpu.cpp
+++ b/codec/common/cpu.cpp
@@ -38,6 +38,7 @@
  *************************************************************************************
  */
 #include <string.h>
+#include <stdio.h>
 #ifdef ANDROID_NDK
 #include <cpu-features.h>
 #endif
@@ -212,9 +213,7 @@
 void WelsXmmRegEmptyOp(void * pSrc) {
 }
 
-#endif
-
-#if defined(HAVE_NEON)//For supporting both android platform and iOS platform
+#elif defined(HAVE_NEON) //For supporting both android platform and iOS platform
 #if defined(ANDROID_NDK)
 uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors)
 {
@@ -242,10 +241,8 @@
   return uiCPU;
 }
 
-#endif
-
-#if defined(APPLE_IOS)
-uint32_t WelsCPUFeatureDetectIOS() //Need to be updated for the new device of APPLE
+#elif defined(APPLE_IOS)
+uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors)
 {
     uint32_t       uiCPU = 0;
     struct utsname sSystemInfo;
@@ -262,7 +259,47 @@
     }
     return uiCPU;
 }
+#elif defined(__linux__)
+
+/* Generic arm/linux cpu feature detection */
+uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors) {
+  FILE *f = fopen("/proc/cpuinfo", "r");
+
+  if (!f)
+    return 0;
+
+  char buf[200];
+  int flags = 0;
+  while (fgets(buf, sizeof(buf), f)) {
+    if (!strncmp(buf, "Features", strlen("Features"))) {
+      if (strstr(buf, " neon "))
+        flags |= WELS_CPU_NEON;
+      if (strstr(buf, " vfpv3 "))
+        flags |= WELS_CPU_VFPv3;
+      break;
+    }
+  }
+  fclose(f);
+  return flags;
+}
+
+#else /* HAVE_NEON enabled but no runtime detection */
+
+/* No runtime feature detection available, but built with HAVE_NEON - assume
+ * that NEON and all associated features are available. */
+
+uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors) {
+  return WELS_CPU_ARMv7 |
+         WELS_CPU_VFPv3 |
+         WELS_CPU_NEON;
+}
 #endif
+#else /* Neither X86_ASM nor HAVE_NEON */
+
+uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors) {
+  return 0;
+}
+
 #endif
 
 
--- a/codec/common/cpu.h
+++ b/codec/common/cpu.h
@@ -62,8 +62,6 @@
 
 void WelsEmms();
 
-uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors);
-
 /*
  *	clear FPU registers states for potential float based calculation if support
  */
@@ -80,17 +78,7 @@
 
 void     WelsXmmRegEmptyOp(void * pSrc);
 
-#if defined(HAVE_NEON)
-#if defined(ANDROID_NDK)
-
 uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors);
-
-#endif
-
-#if defined(APPLE_IOS)
-	uint32_t WelsCPUFeatureDetectIOS();
-#endif
-#endif
 
 #if defined(__cplusplus)
 }
--- a/codec/decoder/core/src/decoder.cpp
+++ b/codec/decoder/core/src/decoder.cpp
@@ -144,16 +144,7 @@
   pCtx->bAuReadyFlag				= 0; // au data is not ready
 
 
-#if defined(X86_ASM)
   pCtx->uiCpuFlag = WelsCPUFeatureDetect (&iCpuCores);
-#elif defined(HAVE_NEON)
-#if defined(ANDROID_NDK)
-  pCtx->uiCpuFlag	= WelsCPUFeatureDetect(&iCpuCores);
-#endif
-#if defined(APPLE_IOS)
-  pCtx->uiCpuFlag	= WelsCPUFeatureDetectIOS();
-#endif
-#endif
 
   pCtx->iImgWidthInPixel		= 0;
   pCtx->iImgHeightInPixel		= 0;		// alloc picture data when picture size is available
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -1933,8 +1933,8 @@
   }
 
   // for cpu features detection, Only detect once??
-#ifdef X86_ASM
   uiCpuFeatureFlags	= WelsCPUFeatureDetect (&uiCpuCores);	// detect cpu capacity features
+#ifdef X86_ASM
   if (uiCpuFeatureFlags & WELS_CPU_CACHELINE_128)
     iCacheLineSize = 128;
   else if (uiCpuFeatureFlags & WELS_CPU_CACHELINE_64)
--- a/codec/processing/src/common/WelsFrameWork.cpp
+++ b/codec/processing/src/common/WelsFrameWork.cpp
@@ -87,11 +87,7 @@
 
 CVpFrameWork::CVpFrameWork (uint32_t uiThreadsNum, EResult& eReturn) {
   int32_t iCoreNum = 1;
-#ifndef X86_ASM
-  uint32_t uiCPUFlag = 0;
-#else
   uint32_t uiCPUFlag = WelsCPUFeatureDetect (&iCoreNum);
-#endif
 
   for (int32_t i = 0; i < MAX_STRATEGY_NUM; i++) {
     IStrategy* pStrategy = m_pStgChain[i];