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 void enable_platform_decoder_support() { |
62 NOTREACHED() << "MediaInitializer should be leaky!"; | 52 has_platform_decoder_support_ = true; |
63 } | 53 } |
64 | 54 |
55 bool has_platform_decoder_support() { return has_platform_decoder_support_; } | |
56 | |
57 private: | |
58 ~MediaInitializer() { NOTREACHED() << "MediaInitializer should be leaky!"; } | |
scottmg
2017/01/31 21:10:34
Probably better just to remove this?
Mark Mentovai
2017/01/31 21:33:56
Use
~MediaInitializer() = delete;
instead. Tha
DaleCurtis
2017/01/31 22:04:33
Good idea. Done.
| |
59 | |
65 bool has_platform_decoder_support_ = false; | 60 bool has_platform_decoder_support_ = false; |
Mark Mentovai
2017/01/31 21:33:56
I don’t think anything is going to be smart enough
DaleCurtis
2017/01/31 22:04:33
Thanks for the commentary. When I wrote this I jus
| |
66 | 61 |
67 DISALLOW_COPY_AND_ASSIGN(MediaInitializer); | 62 DISALLOW_COPY_AND_ASSIGN(MediaInitializer); |
68 }; | 63 }; |
69 | 64 |
70 static base::LazyInstance<MediaInitializer>::Leaky g_media_library = | 65 static MediaInitializer* GetMediaInstance() { |
71 LAZY_INSTANCE_INITIALIZER; | 66 static MediaInitializer* instance = new MediaInitializer(); |
67 return instance; | |
68 } | |
72 | 69 |
73 void InitializeMediaLibrary() { | 70 void InitializeMediaLibrary() { |
74 g_media_library.Get(); | 71 GetMediaInstance(); |
75 } | 72 } |
76 | 73 |
77 #if defined(OS_ANDROID) | 74 #if defined(OS_ANDROID) |
78 void EnablePlatformDecoderSupport() { | 75 void EnablePlatformDecoderSupport() { |
79 g_media_library.Pointer()->enable_platform_decoder_support(); | 76 GetMediaInstance()->enable_platform_decoder_support(); |
80 } | 77 } |
81 | 78 |
82 bool HasPlatformDecoderSupport() { | 79 bool HasPlatformDecoderSupport() { |
83 return g_media_library.Pointer()->has_platform_decoder_support(); | 80 return GetMediaInstance()->has_platform_decoder_support(); |
84 } | 81 } |
85 | 82 |
86 bool PlatformHasOpusSupport() { | 83 bool PlatformHasOpusSupport() { |
87 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; | 84 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; |
88 } | 85 } |
89 | 86 |
90 bool IsUnifiedMediaPipelineEnabled() { | 87 bool IsUnifiedMediaPipelineEnabled() { |
91 return !base::CommandLine::ForCurrentProcess()->HasSwitch( | 88 return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
92 switches::kDisableUnifiedMediaPipeline); | 89 switches::kDisableUnifiedMediaPipeline); |
93 } | 90 } |
94 | 91 |
95 bool ArePlatformDecodersAvailable() { | 92 bool ArePlatformDecodersAvailable() { |
96 return IsUnifiedMediaPipelineEnabled() | 93 return IsUnifiedMediaPipelineEnabled() |
97 ? HasPlatformDecoderSupport() | 94 ? HasPlatformDecoderSupport() |
98 : MediaCodecUtil::IsMediaCodecAvailable(); | 95 : MediaCodecUtil::IsMediaCodecAvailable(); |
99 } | 96 } |
100 #endif | 97 #endif |
101 | 98 |
102 } // namespace media | 99 } // namespace media |
OLD | NEW |