summaryrefslogtreecommitdiffstats
path: root/media/base
diff options
context:
space:
mode:
authordalecurtis@google.com <dalecurtis@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-10 00:30:15 +0000
committerdalecurtis@google.com <dalecurtis@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-10 00:30:15 +0000
commit8e15369cbf87280213729638ae27284d0f66e1b3 (patch)
tree28d7b470952a6d37e13a3ce9b55c399277928c48 /media/base
parent92e81fd1f5b5f9c65fcbad91fd8399b88bbc495e (diff)
downloadchromium_src-8e15369cbf87280213729638ae27284d0f66e1b3.zip
chromium_src-8e15369cbf87280213729638ae27284d0f66e1b3.tar.gz
chromium_src-8e15369cbf87280213729638ae27284d0f66e1b3.tar.bz2
Remove function level static initializers from VectorMath.
Since VectorMath routines (and other features) are used both in the renderer process and the browser process, relying on InitializeMediaLibrary() alone is insufficient. Enter: InitializeCPUSpecificMediaFeatures(), a method which can be called from the browser process without initializing any of the loadable media modules. BUG=224662 TEST=media_unittests R=scherkus@chromium.org, sky@chromium.org Review URL: https://codereview.chromium.org/15044005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199315 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base')
-rw-r--r--media/base/media.cc10
-rw-r--r--media/base/media.h5
-rw-r--r--media/base/vector_math.cc78
-rw-r--r--media/base/vector_math.h5
4 files changed, 55 insertions, 43 deletions
diff --git a/media/base/media.cc b/media/base/media.cc
index f70d7ca..600eedc 100644
--- a/media/base/media.cc
+++ b/media/base/media.cc
@@ -9,6 +9,7 @@
#include "base/path_service.h"
#include "base/synchronization/lock.h"
#include "build/build_config.h"
+#include "media/base/vector_math.h"
namespace media {
@@ -40,7 +41,9 @@ class MediaInitializer {
MediaInitializer()
: initialized_(false),
tried_initialize_(false) {
- // TODO(dalecurtis): Add initialization of YUV and VectorMath libraries.
+ // Perform initialization of libraries which require runtime CPU detection.
+ // TODO(dalecurtis): Add initialization of YUV, SincResampler.
+ vector_math::Initialize();
}
~MediaInitializer() {
@@ -71,4 +74,9 @@ bool IsMediaLibraryInitialized() {
return g_media_library.Get().IsInitialized();
}
+void InitializeCPUSpecificMediaFeatures() {
+ // Force initialization of the media initializer, but don't call Initialize().
+ g_media_library.Get();
+}
+
} // namespace media
diff --git a/media/base/media.h b/media/base/media.h
index 0eeb092..c86e568 100644
--- a/media/base/media.h
+++ b/media/base/media.h
@@ -38,6 +38,11 @@ MEDIA_EXPORT void InitializeMediaLibraryForTesting();
// for the this process, without actually trying to initialize it.
MEDIA_EXPORT bool IsMediaLibraryInitialized();
+// Use this if you need to initialize CPU specific features WITHOUT loading
+// DLLs, DSOs, etc. Only necessary if InitializeMediaLibrary() is not called;
+// does nothing if the media library has already been initialized.
+MEDIA_EXPORT void InitializeCPUSpecificMediaFeatures();
+
} // namespace media
#endif // MEDIA_BASE_MEDIA_H_
diff --git a/media/base/vector_math.cc b/media/base/vector_math.cc
index 603ae0b..ac6de92 100644
--- a/media/base/vector_math.cc
+++ b/media/base/vector_math.cc
@@ -16,33 +16,49 @@
namespace media {
namespace vector_math {
-void FMAC(const float src[], float scale, int len, float dest[]) {
- // Ensure |src| and |dest| are 16-byte aligned.
- DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(src) & (kRequiredAlignment - 1));
- DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(dest) & (kRequiredAlignment - 1));
-
- typedef void (*VectorFMACProc)(const float src[], float scale, int len,
- float dest[]);
-
- // No NaCl code uses the SSE functionality of AudioBus and plumbing the -msse
- // built library is non-trivial, so simply disable for now. iOS lies about
- // its architecture, so we need to exclude it here.
+// If we know the minimum architecture at compile time, avoid CPU detection.
+// Force NaCl code to use C routines since (at present) nothing there uses these
+// methods and plumbing the -msse built library is non-trivial. iOS lies about
+// its architecture, so we also need to exclude it here.
#if defined(ARCH_CPU_X86_FAMILY) && !defined(OS_NACL) && !defined(OS_IOS)
#if defined(__SSE__)
- static const VectorFMACProc kVectorFMACProc = FMAC_SSE;
+#define FMAC_FUNC FMAC_SSE
+#define FMUL_FUNC FMUL_SSE
+void Initialize() {}
#else
- // TODO(dalecurtis): Remove function level static initialization, it's not
- // thread safe: http://crbug.com/224662.
- static const VectorFMACProc kVectorFMACProc =
- base::CPU().has_sse() ? FMAC_SSE : FMAC_C;
+// X86 CPU detection required. Functions will be set by Initialize().
+// TODO(dalecurtis): Once Chrome moves to an SSE baseline this can be removed.
+#define FMAC_FUNC g_fmac_proc_
+#define FMUL_FUNC g_fmul_proc_
+
+typedef void (*MathProc)(const float src[], float scale, int len, float dest[]);
+static MathProc g_fmac_proc_ = NULL;
+static MathProc g_fmul_proc_ = NULL;
+
+void Initialize() {
+ CHECK(!g_fmac_proc_);
+ CHECK(!g_fmul_proc_);
+ const bool kUseSSE = base::CPU().has_sse();
+ g_fmac_proc_ = kUseSSE ? FMAC_SSE : FMAC_C;
+ g_fmul_proc_ = kUseSSE ? FMUL_SSE : FMUL_C;
+}
#endif
#elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON)
- static const VectorFMACProc kVectorFMACProc = FMAC_NEON;
+#define FMAC_FUNC FMAC_NEON
+#define FMUL_FUNC FMUL_NEON
+void Initialize() {}
#else
- static const VectorFMACProc kVectorFMACProc = FMAC_C;
+// Unknown architecture.
+#define FMAC_FUNC FMAC_C
+#define FMUL_FUNC FMUL_C
+void Initialize() {}
#endif
- return kVectorFMACProc(src, scale, len, dest);
+void FMAC(const float src[], float scale, int len, float dest[]) {
+ // Ensure |src| and |dest| are 16-byte aligned.
+ DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(src) & (kRequiredAlignment - 1));
+ DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(dest) & (kRequiredAlignment - 1));
+ return FMAC_FUNC(src, scale, len, dest);
}
void FMAC_C(const float src[], float scale, int len, float dest[]) {
@@ -54,29 +70,7 @@ void FMUL(const float src[], float scale, int len, float dest[]) {
// Ensure |src| and |dest| are 16-byte aligned.
DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(src) & (kRequiredAlignment - 1));
DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(dest) & (kRequiredAlignment - 1));
-
- typedef void (*VectorFMULProc)(const float src[], float scale, int len,
- float dest[]);
-
- // No NaCl code uses the SSE functionality of AudioBus and plumbing the -msse
- // built library is non-trivial, so simply disable for now. iOS lies about
- // its architecture, so we need to exclude it here.
-#if defined(ARCH_CPU_X86_FAMILY) && !defined(OS_NACL) && !defined(OS_IOS)
-#if defined(__SSE__)
- static const VectorFMULProc kVectorFMULProc = FMUL_SSE;
-#else
- // TODO(dalecurtis): Remove function level static initialization, it's not
- // thread safe: http://crbug.com/224662.
- static const VectorFMULProc kVectorFMULProc =
- base::CPU().has_sse() ? FMUL_SSE : FMUL_C;
-#endif
-#elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON)
- static const VectorFMULProc kVectorFMULProc = FMUL_NEON;
-#else
- static const VectorFMULProc kVectorFMULProc = FMUL_C;
-#endif
-
- return kVectorFMULProc(src, scale, len, dest);
+ return FMUL_FUNC(src, scale, len, dest);
}
void FMUL_C(const float src[], float scale, int len, float dest[]) {
diff --git a/media/base/vector_math.h b/media/base/vector_math.h
index 2618687..4764f0b 100644
--- a/media/base/vector_math.h
+++ b/media/base/vector_math.h
@@ -13,6 +13,11 @@ namespace vector_math {
// Required alignment for inputs and outputs to all vector math functions
enum { kRequiredAlignment = 16 };
+// Selects runtime specific optimizations such as SSE. Must be called prior to
+// calling FMAC() or FMUL(). Called during media library initialization; most
+// users should never have to call this.
+MEDIA_EXPORT void Initialize();
+
// Multiply each element of |src| (up to |len|) by |scale| and add to |dest|.
// |src| and |dest| must be aligned by kRequiredAlignment.
MEDIA_EXPORT void FMAC(const float src[], float scale, int len, float dest[]);