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/blink/webmediaplayer_util.h" | 5 #include "media/blink/webmediaplayer_util.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
13 #include "media/base/bind_to_current_loop.h" | 13 #include "media/base/bind_to_current_loop.h" |
14 #include "media/base/media_client.h" | 14 #include "media/base/media_log.h" |
15 #include "third_party/WebKit/public/platform/URLConversion.h" | 15 #include "third_party/WebKit/public/platform/URLConversion.h" |
16 #include "third_party/WebKit/public/platform/WebMediaPlayerEncryptedMediaClient.
h" | 16 #include "third_party/WebKit/public/platform/WebMediaPlayerEncryptedMediaClient.
h" |
17 | 17 |
18 namespace media { | 18 namespace media { |
19 | 19 |
20 blink::WebTimeRanges ConvertToWebTimeRanges( | 20 blink::WebTimeRanges ConvertToWebTimeRanges( |
21 const Ranges<base::TimeDelta>& ranges) { | 21 const Ranges<base::TimeDelta>& ranges) { |
22 blink::WebTimeRanges result(ranges.size()); | 22 blink::WebTimeRanges result(ranges.size()); |
23 for (size_t i = 0; i < ranges.size(); ++i) { | 23 for (size_t i = 0; i < ranges.size(); ++i) { |
24 result[i].start = ranges.start(i).InSecondsF(); | 24 result[i].start = ranges.start(i).InSecondsF(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 } | 102 } |
103 | 103 |
104 NOTREACHED(); | 104 NOTREACHED(); |
105 return "Unknown"; | 105 return "Unknown"; |
106 } | 106 } |
107 | 107 |
108 } // namespace | 108 } // namespace |
109 | 109 |
110 void ReportMetrics(blink::WebMediaPlayer::LoadType load_type, | 110 void ReportMetrics(blink::WebMediaPlayer::LoadType load_type, |
111 const GURL& url, | 111 const GURL& url, |
112 const blink::WebSecurityOrigin& security_origin) { | 112 const blink::WebSecurityOrigin& security_origin, |
| 113 scoped_refptr<MediaLog> media_log) { |
| 114 DCHECK(media_log); |
| 115 |
113 // Report URL scheme, such as http, https, file, blob etc. | 116 // Report URL scheme, such as http, https, file, blob etc. |
114 UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(url), | 117 UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(url), |
115 kMaxURLScheme + 1); | 118 kMaxURLScheme + 1); |
116 | 119 |
117 // Report load type, such as URL, MediaSource or MediaStream. | 120 // Report load type, such as URL, MediaSource or MediaStream. |
118 UMA_HISTOGRAM_ENUMERATION("Media.LoadType", load_type, | 121 UMA_HISTOGRAM_ENUMERATION("Media.LoadType", load_type, |
119 blink::WebMediaPlayer::LoadTypeMax + 1); | 122 blink::WebMediaPlayer::LoadTypeMax + 1); |
120 | 123 |
121 // Report the origin from where the media player is created. | 124 // Report the origin from where the media player is created. |
122 if (GetMediaClient()) { | 125 GURL security_origin_url(url::Origin(security_origin).GetURL()); |
123 GURL security_origin_url(url::Origin(security_origin).GetURL()); | 126 media_log->RecordRapporWithURL( |
| 127 "Media.OriginUrl." + LoadTypeToString(load_type), security_origin_url); |
124 | 128 |
125 GetMediaClient()->RecordRapporURL( | 129 // For MSE, also report usage by secure/insecure origin. |
126 "Media.OriginUrl." + LoadTypeToString(load_type), security_origin_url); | 130 if (load_type == blink::WebMediaPlayer::LoadTypeMediaSource) { |
127 | 131 if (security_origin.isPotentiallyTrustworthy()) { |
128 // For MSE, also report usage by secure/insecure origin. | 132 media_log->RecordRapporWithURL("Media.OriginUrl.MSE.Secure", |
129 if (load_type == blink::WebMediaPlayer::LoadTypeMediaSource) { | 133 security_origin_url); |
130 if (security_origin.isPotentiallyTrustworthy()) { | 134 } else { |
131 GetMediaClient()->RecordRapporURL("Media.OriginUrl.MSE.Secure", | 135 media_log->RecordRapporWithURL("Media.OriginUrl.MSE.Insecure", |
132 security_origin_url); | 136 security_origin_url); |
133 } else { | |
134 GetMediaClient()->RecordRapporURL("Media.OriginUrl.MSE.Insecure", | |
135 security_origin_url); | |
136 } | |
137 } | 137 } |
138 } | 138 } |
139 } | 139 } |
140 | 140 |
141 void ReportPipelineError(blink::WebMediaPlayer::LoadType load_type, | 141 void ReportPipelineError(blink::WebMediaPlayer::LoadType load_type, |
142 const blink::WebSecurityOrigin& security_origin, | 142 const blink::WebSecurityOrigin& security_origin, |
143 PipelineStatus error) { | 143 PipelineStatus error, |
| 144 scoped_refptr<MediaLog> media_log) { |
144 DCHECK_NE(PIPELINE_OK, error); | 145 DCHECK_NE(PIPELINE_OK, error); |
145 | 146 |
146 // Report the origin from where the media player is created. | 147 // Report the origin from where the media player is created. |
147 if (!GetMediaClient()) | 148 media_log->RecordRapporWithURL( |
148 return; | |
149 | |
150 GetMediaClient()->RecordRapporURL( | |
151 "Media.OriginUrl." + LoadTypeToString(load_type) + ".PipelineError", | 149 "Media.OriginUrl." + LoadTypeToString(load_type) + ".PipelineError", |
152 url::Origin(security_origin).GetURL()); | 150 url::Origin(security_origin).GetURL()); |
153 } | 151 } |
154 | 152 |
155 void RecordOriginOfHLSPlayback(const GURL& origin_url) { | |
156 if (media::GetMediaClient()) | |
157 GetMediaClient()->RecordRapporURL("Media.OriginUrl.HLS", origin_url); | |
158 } | |
159 | |
160 EmeInitDataType ConvertToEmeInitDataType( | 153 EmeInitDataType ConvertToEmeInitDataType( |
161 blink::WebEncryptedMediaInitDataType init_data_type) { | 154 blink::WebEncryptedMediaInitDataType init_data_type) { |
162 switch (init_data_type) { | 155 switch (init_data_type) { |
163 case blink::WebEncryptedMediaInitDataType::Webm: | 156 case blink::WebEncryptedMediaInitDataType::Webm: |
164 return EmeInitDataType::WEBM; | 157 return EmeInitDataType::WEBM; |
165 case blink::WebEncryptedMediaInitDataType::Cenc: | 158 case blink::WebEncryptedMediaInitDataType::Cenc: |
166 return EmeInitDataType::CENC; | 159 return EmeInitDataType::CENC; |
167 case blink::WebEncryptedMediaInitDataType::Keyids: | 160 case blink::WebEncryptedMediaInitDataType::Keyids: |
168 return EmeInitDataType::KEYIDS; | 161 return EmeInitDataType::KEYIDS; |
169 case blink::WebEncryptedMediaInitDataType::Unknown: | 162 case blink::WebEncryptedMediaInitDataType::Unknown: |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 241 |
249 } // namespace | 242 } // namespace |
250 | 243 |
251 OutputDeviceStatusCB ConvertToOutputDeviceStatusCB( | 244 OutputDeviceStatusCB ConvertToOutputDeviceStatusCB( |
252 blink::WebSetSinkIdCallbacks* web_callbacks) { | 245 blink::WebSetSinkIdCallbacks* web_callbacks) { |
253 return media::BindToCurrentLoop( | 246 return media::BindToCurrentLoop( |
254 base::Bind(RunSetSinkIdCallback, SetSinkIdCallback(web_callbacks))); | 247 base::Bind(RunSetSinkIdCallback, SetSinkIdCallback(web_callbacks))); |
255 } | 248 } |
256 | 249 |
257 } // namespace media | 250 } // namespace media |
OLD | NEW |