Remove ScrollbarLayerImplBase.
[chromium-blink-merge.git] / media / base / media.cc
blob5e573b58dd0ab88c0f1fa271eae5234da8f5b411
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/base/media.h"
7 #include "base/files/file_path.h"
8 #include "base/lazy_instance.h"
9 #include "base/path_service.h"
10 #include "base/synchronization/lock.h"
11 #include "build/build_config.h"
12 #include "media/base/sinc_resampler.h"
13 #include "media/base/vector_math.h"
15 namespace media {
17 namespace internal {
18 // Platform specific initialization method.
19 extern bool InitializeMediaLibraryInternal(const base::FilePath& module_dir);
20 } // namespace internal
22 // Media must only be initialized once, so use a LazyInstance to ensure this.
23 class MediaInitializer {
24 public:
25 bool Initialize(const base::FilePath& module_dir) {
26 base::AutoLock auto_lock(lock_);
27 if (!tried_initialize_) {
28 tried_initialize_ = true;
29 initialized_ = internal::InitializeMediaLibraryInternal(module_dir);
31 return initialized_;
34 bool IsInitialized() {
35 base::AutoLock auto_lock(lock_);
36 return initialized_;
39 private:
40 friend struct base::DefaultLazyInstanceTraits<MediaInitializer>;
42 MediaInitializer()
43 : initialized_(false),
44 tried_initialize_(false) {
45 // Perform initialization of libraries which require runtime CPU detection.
46 // TODO(dalecurtis): Add initialization of YUV, SincResampler.
47 vector_math::Initialize();
48 #if !defined(OS_IOS)
49 SincResampler::InitializeCPUSpecificFeatures();
50 #endif
53 ~MediaInitializer() {
54 NOTREACHED() << "MediaInitializer should be leaky!";
57 base::Lock lock_;
58 bool initialized_;
59 bool tried_initialize_;
61 DISALLOW_COPY_AND_ASSIGN(MediaInitializer);
64 static base::LazyInstance<MediaInitializer>::Leaky g_media_library =
65 LAZY_INSTANCE_INITIALIZER;
67 bool InitializeMediaLibrary(const base::FilePath& module_dir) {
68 return g_media_library.Get().Initialize(module_dir);
71 void InitializeMediaLibraryForTesting() {
72 base::FilePath module_dir;
73 CHECK(PathService::Get(base::DIR_EXE, &module_dir));
74 CHECK(g_media_library.Get().Initialize(module_dir));
77 bool IsMediaLibraryInitialized() {
78 return g_media_library.Get().IsInitialized();
81 void InitializeCPUSpecificMediaFeatures() {
82 // Force initialization of the media initializer, but don't call Initialize().
83 g_media_library.Get();
86 } // namespace media