Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: media/base/decode_capabilities.cc

Issue 2758873003: New media/base/decode_capabilities.h|cc (Closed)
Patch Set: Rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/decode_capabilities.h ('k') | media/base/decode_capabilities_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "content/renderer/media/render_media_client.h" 5 #include "media/base/decode_capabilities.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/feature_list.h"
9 #include "base/time/default_tick_clock.h"
10 #include "content/public/common/content_client.h"
11 #include "content/public/renderer/content_renderer_client.h"
12 #include "media/base/media_switches.h" 9 #include "media/base/media_switches.h"
13 #include "media/base/video_color_space.h"
14 #include "ui/display/display_switches.h" 10 #include "ui/display/display_switches.h"
15 11
16 namespace content { 12 namespace media {
17
18 void RenderMediaClient::Initialize() {
19 GetInstance();
20 }
21
22 RenderMediaClient::RenderMediaClient()
23 : has_updated_(false),
24 is_update_needed_(true),
25 tick_clock_(new base::DefaultTickClock()) {
26 media::SetMediaClient(this);
27 }
28
29 RenderMediaClient::~RenderMediaClient() {
30 }
31
32 void RenderMediaClient::AddKeySystemsInfoForUMA(
33 std::vector<media::KeySystemInfoForUMA>* key_systems_info_for_uma) {
34 DVLOG(2) << __func__;
35 #if defined(WIDEVINE_CDM_AVAILABLE)
36 key_systems_info_for_uma->push_back(media::KeySystemInfoForUMA(
37 kWidevineKeySystem, kWidevineKeySystemNameForUMA));
38 #endif // WIDEVINE_CDM_AVAILABLE
39 }
40
41 bool RenderMediaClient::IsKeySystemsUpdateNeeded() {
42 DVLOG(2) << __func__;
43 DCHECK(thread_checker_.CalledOnValidThread());
44
45 // Always needs update if we have never updated, regardless the
46 // |last_update_time_ticks_|'s initial value.
47 if (!has_updated_) {
48 DCHECK(is_update_needed_);
49 return true;
50 }
51
52 if (!is_update_needed_)
53 return false;
54
55 // The update could be expensive. For example, it could involve a sync IPC to
56 // the browser process. Use a minimum update interval to avoid unnecessarily
57 // frequent update.
58 static const int kMinUpdateIntervalInMilliseconds = 1000;
59 if ((tick_clock_->NowTicks() - last_update_time_ticks_).InMilliseconds() <
60 kMinUpdateIntervalInMilliseconds) {
61 return false;
62 }
63
64 return true;
65 }
66
67 void RenderMediaClient::AddSupportedKeySystems(
68 std::vector<std::unique_ptr<media::KeySystemProperties>>*
69 key_systems_properties) {
70 DVLOG(2) << __func__;
71 DCHECK(thread_checker_.CalledOnValidThread());
72
73 GetContentClient()->renderer()->AddSupportedKeySystems(
74 key_systems_properties);
75
76 has_updated_ = true;
77 last_update_time_ticks_ = tick_clock_->NowTicks();
78
79 // Check whether all potentially supported key systems are supported. If so,
80 // no need to update again.
81 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
82 for (const auto& properties : *key_systems_properties) {
83 if (properties->GetKeySystemName() == kWidevineKeySystem)
84 is_update_needed_ = false;
85 }
86 #else
87 is_update_needed_ = false;
88 #endif
89 }
90
91 void RenderMediaClient::RecordRapporURL(const std::string& metric,
92 const GURL& url) {
93 GetContentClient()->renderer()->RecordRapporURL(metric, url);
94 }
95 13
96 bool IsColorSpaceSupported(const media::VideoColorSpace& color_space) { 14 bool IsColorSpaceSupported(const media::VideoColorSpace& color_space) {
97 bool color_management = 15 bool color_management =
98 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableHDR) || 16 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableHDR) ||
99 base::FeatureList::IsEnabled(media::kVideoColorManagement); 17 base::FeatureList::IsEnabled(media::kVideoColorManagement);
100 switch (color_space.primaries) { 18 switch (color_space.primaries) {
101 case media::VideoColorSpace::PrimaryID::EBU_3213_E: 19 case media::VideoColorSpace::PrimaryID::EBU_3213_E:
102 case media::VideoColorSpace::PrimaryID::INVALID: 20 case media::VideoColorSpace::PrimaryID::INVALID:
103 return false; 21 return false;
104 22
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 case media::VideoColorSpace::MatrixID::INVALID: 95 case media::VideoColorSpace::MatrixID::INVALID:
178 return false; 96 return false;
179 } 97 }
180 98
181 if (color_space.range == gfx::ColorSpace::RangeID::INVALID) 99 if (color_space.range == gfx::ColorSpace::RangeID::INVALID)
182 return false; 100 return false;
183 101
184 return true; 102 return true;
185 } 103 }
186 104
187 bool RenderMediaClient::IsSupportedVideoConfig( 105 // TODO(chcunningham): Query decoders for codec profile support. Add platform
188 const media::VideoConfig& config) { 106 // specific logic for Android (move from MimeUtilIntenral).
189 // TODO(chcunningham): Query decoders for codec profile support. 107 bool IsSupportedVideoConfig(const VideoConfig& config) {
190 switch (config.codec) { 108 switch (config.codec) {
191 case media::kCodecVP9: 109 case media::kCodecVP9:
192 // Color management required for HDR to not look terrible. 110 // Color management required for HDR to not look terrible.
193 return IsColorSpaceSupported(config.color_space); 111 return IsColorSpaceSupported(config.color_space);
194 112
195 case media::kCodecH264: 113 case media::kCodecH264:
196 case media::kCodecVP8: 114 case media::kCodecVP8:
197 case media::kCodecTheora: 115 case media::kCodecTheora:
198 return true; 116 return true;
199 117
200 case media::kUnknownVideoCodec: 118 case media::kUnknownVideoCodec:
201 case media::kCodecVC1: 119 case media::kCodecVC1:
202 case media::kCodecMPEG2: 120 case media::kCodecMPEG2:
203 case media::kCodecMPEG4: 121 case media::kCodecMPEG4:
204 case media::kCodecHEVC: 122 case media::kCodecHEVC:
205 case media::kCodecDolbyVision: 123 case media::kCodecDolbyVision:
206 return false; 124 return false;
207 } 125 }
208 126
209 NOTREACHED(); 127 NOTREACHED();
210 return false; 128 return false;
211 } 129 }
212 130
213 void RenderMediaClient::SetTickClockForTesting( 131 } // namespace media
214 std::unique_ptr<base::TickClock> tick_clock) {
215 tick_clock_.swap(tick_clock);
216 }
217
218 // static
219 RenderMediaClient* RenderMediaClient::GetInstance() {
220 static RenderMediaClient* client = new RenderMediaClient();
221 return client;
222 }
223
224 } // namespace content
OLDNEW
« no previous file with comments | « media/base/decode_capabilities.h ('k') | media/base/decode_capabilities_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698