OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/base/media.h" | 5 #include "media/base/media.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/lazy_instance.h" | |
9 #include "base/macros.h" | 8 #include "base/macros.h" |
10 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
11 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
12 #include "media/base/media_switches.h" | 11 #include "media/base/media_switches.h" |
13 #include "media/base/yuv_convert.h" | 12 #include "media/base/yuv_convert.h" |
14 | 13 |
15 #if defined(OS_ANDROID) | 14 #if defined(OS_ANDROID) |
16 #include "base/android/build_info.h" | 15 #include "base/android/build_info.h" |
17 #include "media/base/android/media_codec_util.h" | 16 #include "media/base/android/media_codec_util.h" |
18 #endif | 17 #endif |
19 | 18 |
20 #if !defined(MEDIA_DISABLE_FFMPEG) | 19 #if !defined(MEDIA_DISABLE_FFMPEG) |
21 #include "media/ffmpeg/ffmpeg_common.h" | 20 #include "media/ffmpeg/ffmpeg_common.h" |
22 #endif | 21 #endif |
23 | 22 |
24 namespace media { | 23 namespace media { |
25 | 24 |
26 // Media must only be initialized once, so use a LazyInstance to ensure this. | 25 // Media must only be initialized once; use a thread-safe static to do this. |
27 class MediaInitializer { | 26 class MediaInitializer { |
28 public: | 27 public: |
29 void enable_platform_decoder_support() { | |
30 has_platform_decoder_support_ = true; | |
31 } | |
32 | |
33 bool has_platform_decoder_support() { return has_platform_decoder_support_; } | |
34 | |
35 private: | |
36 friend struct base::DefaultLazyInstanceTraits<MediaInitializer>; | |
37 | |
38 MediaInitializer() { | 28 MediaInitializer() { |
39 TRACE_EVENT_WARMUP_CATEGORY("audio"); | 29 TRACE_EVENT_WARMUP_CATEGORY("audio"); |
40 TRACE_EVENT_WARMUP_CATEGORY("media"); | 30 TRACE_EVENT_WARMUP_CATEGORY("media"); |
41 | 31 |
42 // Perform initialization of libraries which require runtime CPU detection. | 32 // Perform initialization of libraries which require runtime CPU detection. |
43 InitializeCPUSpecificYUVConversions(); | 33 InitializeCPUSpecificYUVConversions(); |
44 | 34 |
45 #if !defined(MEDIA_DISABLE_FFMPEG) | 35 #if !defined(MEDIA_DISABLE_FFMPEG) |
46 // Initialize CPU flags outside of the sandbox as this may query /proc for | 36 // Initialize CPU flags outside of the sandbox as this may query /proc for |
47 // details on the current CPU for NEON, VFP, etc optimizations. | 37 // details on the current CPU for NEON, VFP, etc optimizations. |
48 av_get_cpu_flags(); | 38 av_get_cpu_flags(); |
49 | 39 |
50 // Disable logging as it interferes with layout tests. | 40 // Disable logging as it interferes with layout tests. |
51 av_log_set_level(AV_LOG_QUIET); | 41 av_log_set_level(AV_LOG_QUIET); |
52 | 42 |
53 #if defined(ALLOCATOR_SHIM) | 43 #if defined(ALLOCATOR_SHIM) |
54 // Remove allocation limit from ffmpeg, so calls go down to shim layer. | 44 // Remove allocation limit from ffmpeg, so calls go down to shim layer. |
55 av_max_alloc(0); | 45 av_max_alloc(0); |
56 #endif // defined(ALLOCATOR_SHIM) | 46 #endif // defined(ALLOCATOR_SHIM) |
57 | 47 |
58 #endif // !defined(MEDIA_DISABLE_FFMPEG) | 48 #endif // !defined(MEDIA_DISABLE_FFMPEG) |
59 } | 49 } |
60 | 50 |
61 ~MediaInitializer() { | 51 #if defined(OS_ANDROID) |
62 NOTREACHED() << "MediaInitializer should be leaky!"; | 52 void enable_platform_decoder_support() { |
| 53 has_platform_decoder_support_ = true; |
63 } | 54 } |
64 | 55 |
| 56 bool has_platform_decoder_support() const { |
| 57 return has_platform_decoder_support_; |
| 58 } |
| 59 #endif // defined(OS_ANDROID) |
| 60 |
| 61 private: |
| 62 ~MediaInitializer() = delete; |
| 63 |
| 64 #if defined(OS_ANDROID) |
65 bool has_platform_decoder_support_ = false; | 65 bool has_platform_decoder_support_ = false; |
| 66 #endif // defined(OS_ANDROID) |
66 | 67 |
67 DISALLOW_COPY_AND_ASSIGN(MediaInitializer); | 68 DISALLOW_COPY_AND_ASSIGN(MediaInitializer); |
68 }; | 69 }; |
69 | 70 |
70 static base::LazyInstance<MediaInitializer>::Leaky g_media_library = | 71 static MediaInitializer* GetMediaInstance() { |
71 LAZY_INSTANCE_INITIALIZER; | 72 static MediaInitializer* instance = new MediaInitializer(); |
| 73 return instance; |
| 74 } |
72 | 75 |
73 void InitializeMediaLibrary() { | 76 void InitializeMediaLibrary() { |
74 g_media_library.Get(); | 77 GetMediaInstance(); |
75 } | 78 } |
76 | 79 |
77 #if defined(OS_ANDROID) | 80 #if defined(OS_ANDROID) |
78 void EnablePlatformDecoderSupport() { | 81 void EnablePlatformDecoderSupport() { |
79 g_media_library.Pointer()->enable_platform_decoder_support(); | 82 GetMediaInstance()->enable_platform_decoder_support(); |
80 } | 83 } |
81 | 84 |
82 bool HasPlatformDecoderSupport() { | 85 bool HasPlatformDecoderSupport() { |
83 return g_media_library.Pointer()->has_platform_decoder_support(); | 86 return GetMediaInstance()->has_platform_decoder_support(); |
84 } | 87 } |
85 | 88 |
86 bool PlatformHasOpusSupport() { | 89 bool PlatformHasOpusSupport() { |
87 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; | 90 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; |
88 } | 91 } |
89 #endif | 92 #endif // defined(OS_ANDROID) |
90 | 93 |
91 } // namespace media | 94 } // namespace media |
OLD | NEW |