1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/blink/webmediaplayer_util.h"
#include <math.h>
#include "base/metrics/histogram.h"
#include "media/base/media_client.h"
#include "media/base/media_keys.h"
#include "third_party/WebKit/public/platform/WebMediaPlayerClient.h"
namespace media {
// Compile asserts shared by all platforms.
#define STATIC_ASSERT_MATCHING_ENUM(name) \
static_assert( \
static_cast<int>(blink::WebMediaPlayerClient::MediaKeyErrorCode ## name) == \
static_cast<int>(MediaKeys::k ## name ## Error), \
"mismatching enum values: " #name)
STATIC_ASSERT_MATCHING_ENUM(Unknown);
STATIC_ASSERT_MATCHING_ENUM(Client);
#undef STATIC_ASSERT_MATCHING_ENUM
base::TimeDelta ConvertSecondsToTimestamp(double seconds) {
double microseconds = seconds * base::Time::kMicrosecondsPerSecond;
return base::TimeDelta::FromMicroseconds(
microseconds > 0 ? microseconds + 0.5 : ceil(microseconds - 0.5));
}
blink::WebTimeRanges ConvertToWebTimeRanges(
const Ranges<base::TimeDelta>& ranges) {
blink::WebTimeRanges result(ranges.size());
for (size_t i = 0; i < ranges.size(); ++i) {
result[i].start = ranges.start(i).InSecondsF();
result[i].end = ranges.end(i).InSecondsF();
}
return result;
}
blink::WebMediaPlayer::NetworkState PipelineErrorToNetworkState(
PipelineStatus error) {
DCHECK_NE(error, PIPELINE_OK);
switch (error) {
case PIPELINE_ERROR_NETWORK:
case PIPELINE_ERROR_READ:
return blink::WebMediaPlayer::NetworkStateNetworkError;
// TODO(vrk): Because OnPipelineInitialize() directly reports the
// NetworkStateFormatError instead of calling OnPipelineError(), I believe
// this block can be deleted. Should look into it! (crbug.com/126070)
case PIPELINE_ERROR_INITIALIZATION_FAILED:
case PIPELINE_ERROR_COULD_NOT_RENDER:
case PIPELINE_ERROR_URL_NOT_FOUND:
case DEMUXER_ERROR_COULD_NOT_OPEN:
case DEMUXER_ERROR_COULD_NOT_PARSE:
case DEMUXER_ERROR_NO_SUPPORTED_STREAMS:
case DECODER_ERROR_NOT_SUPPORTED:
return blink::WebMediaPlayer::NetworkStateFormatError;
case PIPELINE_ERROR_DECODE:
case PIPELINE_ERROR_ABORT:
case PIPELINE_ERROR_OPERATION_PENDING:
case PIPELINE_ERROR_INVALID_STATE:
return blink::WebMediaPlayer::NetworkStateDecodeError;
case PIPELINE_ERROR_DECRYPT:
// TODO(xhwang): Change to use NetworkStateDecryptError once it's added in
// Webkit (see http://crbug.com/124486).
return blink::WebMediaPlayer::NetworkStateDecodeError;
case PIPELINE_OK:
NOTREACHED() << "Unexpected status! " << error;
}
return blink::WebMediaPlayer::NetworkStateFormatError;
}
namespace {
// Helper enum for reporting scheme histograms.
enum URLSchemeForHistogram {
kUnknownURLScheme,
kMissingURLScheme,
kHttpURLScheme,
kHttpsURLScheme,
kFtpURLScheme,
kChromeExtensionURLScheme,
kJavascriptURLScheme,
kFileURLScheme,
kBlobURLScheme,
kDataURLScheme,
kFileSystemScheme,
kMaxURLScheme = kFileSystemScheme // Must be equal to highest enum value.
};
URLSchemeForHistogram URLScheme(const GURL& url) {
if (!url.has_scheme()) return kMissingURLScheme;
if (url.SchemeIs("http")) return kHttpURLScheme;
if (url.SchemeIs("https")) return kHttpsURLScheme;
if (url.SchemeIs("ftp")) return kFtpURLScheme;
if (url.SchemeIs("chrome-extension")) return kChromeExtensionURLScheme;
if (url.SchemeIs("javascript")) return kJavascriptURLScheme;
if (url.SchemeIs("file")) return kFileURLScheme;
if (url.SchemeIs("blob")) return kBlobURLScheme;
if (url.SchemeIs("data")) return kDataURLScheme;
if (url.SchemeIs("filesystem")) return kFileSystemScheme;
return kUnknownURLScheme;
}
std::string LoadTypeToString(blink::WebMediaPlayer::LoadType load_type) {
switch (load_type) {
case blink::WebMediaPlayer::LoadTypeURL:
return "SRC";
case blink::WebMediaPlayer::LoadTypeMediaSource:
return "MSE";
case blink::WebMediaPlayer::LoadTypeMediaStream:
return "MS";
}
NOTREACHED();
return "Unknown";
}
} // namespace
// TODO(xhwang): Call this from WebMediaPlayerMS to report metrics for
// MediaStream as well.
void ReportMetrics(blink::WebMediaPlayer::LoadType load_type,
const GURL& url,
const GURL& origin_url) {
// Report URL scheme, such as http, https, file, blob etc.
UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(url),
kMaxURLScheme + 1);
// Keep track if this is a MSE or non-MSE playback.
// TODO(xhwang): This name is not intuitive. We should have a histogram for
// all load types.
UMA_HISTOGRAM_BOOLEAN(
"Media.MSE.Playback",
load_type == blink::WebMediaPlayer::LoadTypeMediaSource);
// Report the origin from where the media player is created.
if (GetMediaClient()) {
GetMediaClient()->RecordRapporURL(
"Media.OriginUrl." + LoadTypeToString(load_type), origin_url);
}
}
EmeInitDataType ConvertToEmeInitDataType(
blink::WebEncryptedMediaInitDataType init_data_type) {
switch (init_data_type) {
case blink::WebEncryptedMediaInitDataType::Webm:
return EmeInitDataType::WEBM;
case blink::WebEncryptedMediaInitDataType::Cenc:
return EmeInitDataType::CENC;
case blink::WebEncryptedMediaInitDataType::Keyids:
return EmeInitDataType::KEYIDS;
case blink::WebEncryptedMediaInitDataType::Unknown:
return EmeInitDataType::UNKNOWN;
}
NOTREACHED();
return EmeInitDataType::UNKNOWN;
}
blink::WebEncryptedMediaInitDataType ConvertToWebInitDataType(
EmeInitDataType init_data_type) {
switch (init_data_type) {
case EmeInitDataType::WEBM:
return blink::WebEncryptedMediaInitDataType::Webm;
case EmeInitDataType::CENC:
return blink::WebEncryptedMediaInitDataType::Cenc;
case EmeInitDataType::KEYIDS:
return blink::WebEncryptedMediaInitDataType::Keyids;
case EmeInitDataType::UNKNOWN:
return blink::WebEncryptedMediaInitDataType::Unknown;
}
NOTREACHED();
return blink::WebEncryptedMediaInitDataType::Unknown;
}
} // namespace media
|