OLD | NEW |
| (Empty) |
1 // Copyright 2014 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. | |
4 | |
5 #include "content/renderer/media/render_media_client.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/logging.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" | |
13 #include "media/base/video_color_space.h" | |
14 #include "ui/display/display_switches.h" | |
15 | |
16 namespace content { | |
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 | |
96 bool RenderMediaClient::IsSupportedVideoConfig( | |
97 const media::VideoConfig& config) { | |
98 // Render media client does not customize decoder support. Defer to media/. | |
99 return ::media::IsSupportedVideoConfig(config); | |
100 } | |
101 | |
102 void RenderMediaClient::SetTickClockForTesting( | |
103 std::unique_ptr<base::TickClock> tick_clock) { | |
104 tick_clock_.swap(tick_clock); | |
105 } | |
106 | |
107 // static | |
108 RenderMediaClient* RenderMediaClient::GetInstance() { | |
109 static RenderMediaClient* client = new RenderMediaClient(); | |
110 return client; | |
111 } | |
112 | |
113 } // namespace content | |
OLD | NEW |