Web Speech API: cancel outstanding infobar requests when aborting.
[chromium-blink-merge.git] / media / base / media.cc
blob75625fe5f36dae93a1d4bd17a5fa920488f930ce
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"
14 #include "media/base/yuv_convert.h"
16 namespace media {
18 namespace internal {
19 // Platform specific initialization method.
20 extern bool InitializeMediaLibraryInternal(const base::FilePath& module_dir);
21 } // namespace internal
23 // Media must only be initialized once, so use a LazyInstance to ensure this.
24 class MediaInitializer {
25 public:
26 bool Initialize(const base::FilePath& module_dir) {
27 base::AutoLock auto_lock(lock_);
28 if (!tried_initialize_) {
29 tried_initialize_ = true;
30 initialized_ = internal::InitializeMediaLibraryInternal(module_dir);
32 return initialized_;
35 bool IsInitialized() {
36 base::AutoLock auto_lock(lock_);
37 return initialized_;
40 private:
41 friend struct base::DefaultLazyInstanceTraits<MediaInitializer>;
43 MediaInitializer()
44 : initialized_(false),
45 tried_initialize_(false) {
46 // Perform initialization of libraries which require runtime CPU detection.
47 // TODO(dalecurtis): Add initialization of YUV, SincResampler.
48 vector_math::Initialize();
49 SincResampler::InitializeCPUSpecificFeatures();
50 InitializeCPUSpecificYUVConversions();
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