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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
// Copyright (c) 2012 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/base/media_log.h"
#include <string>
#include "base/atomic_sequence_num.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/values.h"
namespace media {
// A count of all MediaLogs created in the current process. Used to generate
// unique IDs.
static base::StaticAtomicSequenceNumber g_media_log_count;
std::string MediaLog::MediaLogLevelToString(MediaLogLevel level) {
switch (level) {
case MEDIALOG_ERROR:
return "error";
case MEDIALOG_INFO:
return "info";
case MEDIALOG_DEBUG:
return "debug";
}
NOTREACHED();
return NULL;
}
MediaLogEvent::Type MediaLog::MediaLogLevelToEventType(MediaLogLevel level) {
switch (level) {
case MEDIALOG_ERROR:
return MediaLogEvent::MEDIA_ERROR_LOG_ENTRY;
case MEDIALOG_INFO:
return MediaLogEvent::MEDIA_INFO_LOG_ENTRY;
case MEDIALOG_DEBUG:
return MediaLogEvent::MEDIA_DEBUG_LOG_ENTRY;
}
NOTREACHED();
return MediaLogEvent::MEDIA_ERROR_LOG_ENTRY;
}
std::string MediaLog::EventTypeToString(MediaLogEvent::Type type) {
switch (type) {
case MediaLogEvent::WEBMEDIAPLAYER_CREATED:
return "WEBMEDIAPLAYER_CREATED";
case MediaLogEvent::WEBMEDIAPLAYER_DESTROYED:
return "WEBMEDIAPLAYER_DESTROYED";
case MediaLogEvent::PIPELINE_CREATED:
return "PIPELINE_CREATED";
case MediaLogEvent::PIPELINE_DESTROYED:
return "PIPELINE_DESTROYED";
case MediaLogEvent::LOAD:
return "LOAD";
case MediaLogEvent::SEEK:
return "SEEK";
case MediaLogEvent::PLAY:
return "PLAY";
case MediaLogEvent::PAUSE:
return "PAUSE";
case MediaLogEvent::PIPELINE_STATE_CHANGED:
return "PIPELINE_STATE_CHANGED";
case MediaLogEvent::PIPELINE_ERROR:
return "PIPELINE_ERROR";
case MediaLogEvent::VIDEO_SIZE_SET:
return "VIDEO_SIZE_SET";
case MediaLogEvent::DURATION_SET:
return "DURATION_SET";
case MediaLogEvent::TOTAL_BYTES_SET:
return "TOTAL_BYTES_SET";
case MediaLogEvent::NETWORK_ACTIVITY_SET:
return "NETWORK_ACTIVITY_SET";
case MediaLogEvent::ENDED:
return "ENDED";
case MediaLogEvent::TEXT_ENDED:
return "TEXT_ENDED";
case MediaLogEvent::BUFFERED_EXTENTS_CHANGED:
return "BUFFERED_EXTENTS_CHANGED";
case MediaLogEvent::MEDIA_ERROR_LOG_ENTRY:
return "MEDIA_ERROR_LOG_ENTRY";
case MediaLogEvent::MEDIA_INFO_LOG_ENTRY:
return "MEDIA_INFO_LOG_ENTRY";
case MediaLogEvent::MEDIA_DEBUG_LOG_ENTRY:
return "MEDIA_DEBUG_LOG_ENTRY";
case MediaLogEvent::PROPERTY_CHANGE:
return "PROPERTY_CHANGE";
}
NOTREACHED();
return NULL;
}
std::string MediaLog::PipelineStatusToString(PipelineStatus status) {
switch (status) {
case PIPELINE_OK:
return "pipeline: ok";
case PIPELINE_ERROR_URL_NOT_FOUND:
return "pipeline: url not found";
case PIPELINE_ERROR_NETWORK:
return "pipeline: network error";
case PIPELINE_ERROR_DECODE:
return "pipeline: decode error";
case PIPELINE_ERROR_DECRYPT:
return "pipeline: decrypt error";
case PIPELINE_ERROR_ABORT:
return "pipeline: abort";
case PIPELINE_ERROR_INITIALIZATION_FAILED:
return "pipeline: initialization failed";
case PIPELINE_ERROR_COULD_NOT_RENDER:
return "pipeline: could not render";
case PIPELINE_ERROR_READ:
return "pipeline: read error";
case PIPELINE_ERROR_OPERATION_PENDING:
return "pipeline: operation pending";
case PIPELINE_ERROR_INVALID_STATE:
return "pipeline: invalid state";
case DEMUXER_ERROR_COULD_NOT_OPEN:
return "demuxer: could not open";
case DEMUXER_ERROR_COULD_NOT_PARSE:
return "demuxer: could not parse";
case DEMUXER_ERROR_NO_SUPPORTED_STREAMS:
return "demuxer: no supported streams";
case DECODER_ERROR_NOT_SUPPORTED:
return "decoder: not supported";
}
NOTREACHED();
return NULL;
}
std::string MediaLog::MediaEventToLogString(const MediaLogEvent& event) {
// Special case for PIPELINE_ERROR, since that's by far the most useful
// event for figuring out media pipeline failures, and just reporting
// pipeline status as numeric code is not very helpful/user-friendly.
int error_code = 0;
if (event.type == MediaLogEvent::PIPELINE_ERROR &&
event.params.GetInteger("pipeline_error", &error_code)) {
PipelineStatus status = static_cast<PipelineStatus>(error_code);
return EventTypeToString(event.type) + " " +
media::MediaLog::PipelineStatusToString(status);
}
std::string params_json;
base::JSONWriter::Write(&event.params, ¶ms_json);
return EventTypeToString(event.type) + " " + params_json;
}
MediaLog::MediaLog() : id_(g_media_log_count.GetNext()) {}
MediaLog::~MediaLog() {}
void MediaLog::AddEvent(scoped_ptr<MediaLogEvent> event) {}
scoped_ptr<MediaLogEvent> MediaLog::CreateEvent(MediaLogEvent::Type type) {
scoped_ptr<MediaLogEvent> event(new MediaLogEvent);
event->id = id_;
event->type = type;
event->time = base::TimeTicks::Now();
return event.Pass();
}
scoped_ptr<MediaLogEvent> MediaLog::CreateBooleanEvent(
MediaLogEvent::Type type,
const std::string& property,
bool value) {
scoped_ptr<MediaLogEvent> event(CreateEvent(type));
event->params.SetBoolean(property, value);
return event.Pass();
}
scoped_ptr<MediaLogEvent> MediaLog::CreateStringEvent(
MediaLogEvent::Type type,
const std::string& property,
const std::string& value) {
scoped_ptr<MediaLogEvent> event(CreateEvent(type));
event->params.SetString(property, value);
return event.Pass();
}
scoped_ptr<MediaLogEvent> MediaLog::CreateTimeEvent(
MediaLogEvent::Type type,
const std::string& property,
base::TimeDelta value) {
scoped_ptr<MediaLogEvent> event(CreateEvent(type));
if (value.is_max())
event->params.SetString(property, "unknown");
else
event->params.SetDouble(property, value.InSecondsF());
return event.Pass();
}
scoped_ptr<MediaLogEvent> MediaLog::CreateLoadEvent(const std::string& url) {
scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::LOAD));
event->params.SetString("url", url);
return event.Pass();
}
scoped_ptr<MediaLogEvent> MediaLog::CreateSeekEvent(float seconds) {
scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::SEEK));
event->params.SetDouble("seek_target", seconds);
return event.Pass();
}
scoped_ptr<MediaLogEvent> MediaLog::CreatePipelineStateChangedEvent(
Pipeline::State state) {
scoped_ptr<MediaLogEvent> event(
CreateEvent(MediaLogEvent::PIPELINE_STATE_CHANGED));
event->params.SetString("pipeline_state", Pipeline::GetStateString(state));
return event.Pass();
}
scoped_ptr<MediaLogEvent> MediaLog::CreatePipelineErrorEvent(
PipelineStatus error) {
scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::PIPELINE_ERROR));
event->params.SetInteger("pipeline_error", error);
return event.Pass();
}
scoped_ptr<MediaLogEvent> MediaLog::CreateVideoSizeSetEvent(
size_t width, size_t height) {
scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::VIDEO_SIZE_SET));
event->params.SetInteger("width", width);
event->params.SetInteger("height", height);
return event.Pass();
}
scoped_ptr<MediaLogEvent> MediaLog::CreateBufferedExtentsChangedEvent(
int64 start, int64 current, int64 end) {
scoped_ptr<MediaLogEvent> event(
CreateEvent(MediaLogEvent::BUFFERED_EXTENTS_CHANGED));
// These values are headed to JS where there is no int64 so we use a double
// and accept loss of precision above 2^53 bytes (8 Exabytes).
event->params.SetDouble("buffer_start", start);
event->params.SetDouble("buffer_current", current);
event->params.SetDouble("buffer_end", end);
return event.Pass();
}
void MediaLog::AddLogEvent(MediaLogLevel level, const std::string& message) {
scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogLevelToEventType(level)));
event->params.SetString(MediaLogLevelToString(level), message);
AddEvent(event.Pass());
}
void MediaLog::SetStringProperty(
const std::string& key, const std::string& value) {
scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::PROPERTY_CHANGE));
event->params.SetString(key, value);
AddEvent(event.Pass());
}
void MediaLog::SetIntegerProperty(
const std::string& key, int value) {
scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::PROPERTY_CHANGE));
event->params.SetInteger(key, value);
AddEvent(event.Pass());
}
void MediaLog::SetDoubleProperty(
const std::string& key, double value) {
scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::PROPERTY_CHANGE));
event->params.SetDouble(key, value);
AddEvent(event.Pass());
}
void MediaLog::SetBooleanProperty(
const std::string& key, bool value) {
scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::PROPERTY_CHANGE));
event->params.SetBoolean(key, value);
AddEvent(event.Pass());
}
void MediaLog::SetTimeProperty(
const std::string& key, base::TimeDelta value) {
scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::PROPERTY_CHANGE));
if (value.is_max())
event->params.SetString(key, "unknown");
else
event->params.SetDouble(key, value.InSecondsF());
AddEvent(event.Pass());
}
LogHelper::LogHelper(MediaLog::MediaLogLevel level, const LogCB& log_cb)
: level_(level), log_cb_(log_cb) {
}
LogHelper::~LogHelper() {
if (log_cb_.is_null())
return;
log_cb_.Run(level_, stream_.str());
}
} //namespace media
|