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/files/file_path.h" | 7 #include "base/command_line.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/path_service.h" | 10 #include "base/metrics/field_trial.h" |
11 #include "base/synchronization/lock.h" | |
12 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
13 #include "build/build_config.h" | 12 #include "media/base/media_switches.h" |
14 #include "media/base/yuv_convert.h" | 13 #include "media/base/yuv_convert.h" |
15 | 14 |
| 15 #if defined(OS_ANDROID) |
| 16 #include "media/base/android/media_codec_util.h" |
| 17 #endif |
| 18 |
16 #if !defined(MEDIA_DISABLE_FFMPEG) | 19 #if !defined(MEDIA_DISABLE_FFMPEG) |
17 #include "media/ffmpeg/ffmpeg_common.h" | 20 #include "media/ffmpeg/ffmpeg_common.h" |
18 #endif | 21 #endif |
19 | 22 |
20 namespace media { | 23 namespace media { |
21 | 24 |
22 // Media must only be initialized once, so use a LazyInstance to ensure this. | 25 // Media must only be initialized once, so use a LazyInstance to ensure this. |
23 class MediaInitializer { | 26 class MediaInitializer { |
| 27 public: |
| 28 void enable_platform_decoder_support() { |
| 29 has_platform_decoder_support_ = true; |
| 30 } |
| 31 |
| 32 bool has_platform_decoder_support() { return has_platform_decoder_support_; } |
| 33 |
24 private: | 34 private: |
25 friend struct base::DefaultLazyInstanceTraits<MediaInitializer>; | 35 friend struct base::DefaultLazyInstanceTraits<MediaInitializer>; |
26 | 36 |
27 MediaInitializer() { | 37 MediaInitializer() { |
28 TRACE_EVENT_WARMUP_CATEGORY("audio"); | 38 TRACE_EVENT_WARMUP_CATEGORY("audio"); |
29 TRACE_EVENT_WARMUP_CATEGORY("media"); | 39 TRACE_EVENT_WARMUP_CATEGORY("media"); |
30 | 40 |
31 // Perform initialization of libraries which require runtime CPU detection. | 41 // Perform initialization of libraries which require runtime CPU detection. |
32 InitializeCPUSpecificYUVConversions(); | 42 InitializeCPUSpecificYUVConversions(); |
33 | 43 |
(...skipping 10 matching lines...) Expand all Loading... |
44 av_max_alloc(0); | 54 av_max_alloc(0); |
45 #endif // defined(ALLOCATOR_SHIM) | 55 #endif // defined(ALLOCATOR_SHIM) |
46 | 56 |
47 #endif // !defined(MEDIA_DISABLE_FFMPEG) | 57 #endif // !defined(MEDIA_DISABLE_FFMPEG) |
48 } | 58 } |
49 | 59 |
50 ~MediaInitializer() { | 60 ~MediaInitializer() { |
51 NOTREACHED() << "MediaInitializer should be leaky!"; | 61 NOTREACHED() << "MediaInitializer should be leaky!"; |
52 } | 62 } |
53 | 63 |
| 64 bool has_platform_decoder_support_ = false; |
| 65 |
54 DISALLOW_COPY_AND_ASSIGN(MediaInitializer); | 66 DISALLOW_COPY_AND_ASSIGN(MediaInitializer); |
55 }; | 67 }; |
56 | 68 |
57 static base::LazyInstance<MediaInitializer>::Leaky g_media_library = | 69 static base::LazyInstance<MediaInitializer>::Leaky g_media_library = |
58 LAZY_INSTANCE_INITIALIZER; | 70 LAZY_INSTANCE_INITIALIZER; |
59 | 71 |
60 void InitializeMediaLibrary() { | 72 void InitializeMediaLibrary() { |
61 g_media_library.Get(); | 73 g_media_library.Get(); |
62 } | 74 } |
63 | 75 |
| 76 #if defined(OS_ANDROID) |
| 77 void EnablePlatformDecoderSupport() { |
| 78 g_media_library.Pointer()->enable_platform_decoder_support(); |
| 79 } |
| 80 |
| 81 bool HasPlatformDecoderSupport() { |
| 82 return g_media_library.Pointer()->has_platform_decoder_support(); |
| 83 } |
| 84 |
| 85 bool IsUnifiedMediaPipelineEnabled() { |
| 86 // TODO(dalecurtis): This experiment is temporary and should be removed once |
| 87 // we have enough data to support the primacy of the unified media pipeline; |
| 88 // see http://crbug.com/533190 for details. |
| 89 // |
| 90 // Note: It's important to query the field trial state first, to ensure that |
| 91 // UMA reports the correct group. |
| 92 const std::string group_name = |
| 93 base::FieldTrialList::FindFullName("UnifiedMediaPipelineTrial"); |
| 94 const bool enabled_via_cli = |
| 95 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 96 switches::kEnableUnifiedMediaPipeline); |
| 97 return enabled_via_cli || |
| 98 base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE); |
| 99 } |
| 100 |
| 101 bool IsUnifiedMediaPipelineEnabledForMse() { |
| 102 return IsUnifiedMediaPipelineEnabled() || |
| 103 !MediaCodecUtil::IsMediaCodecAvailable(); |
| 104 } |
| 105 #endif |
| 106 |
64 } // namespace media | 107 } // namespace media |
OLD | NEW |