OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/base/media_log.h" | 5 #include "media/base/media_log.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/atomic_sequence_num.h" | 9 #include "base/atomic_sequence_num.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 11 #include "base/strings/string_util.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 | 13 |
13 namespace media { | 14 namespace media { |
14 | 15 |
15 // A count of all MediaLogs created in the current process. Used to generate | 16 // A count of all MediaLogs created in the current process. Used to generate |
16 // unique IDs. | 17 // unique IDs. |
17 static base::StaticAtomicSequenceNumber g_media_log_count; | 18 static base::StaticAtomicSequenceNumber g_media_log_count; |
18 | 19 |
19 // Audio+video watch time metrics. | 20 // Audio+video watch time metrics. |
20 const char MediaLog::kWatchTimeAudioVideoAll[] = | 21 const char MediaLog::kWatchTimeAudioVideoAll[] = |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 std::string MediaLog::MediaEventToLogString(const MediaLogEvent& event) { | 212 std::string MediaLog::MediaEventToLogString(const MediaLogEvent& event) { |
212 // Special case for PIPELINE_ERROR, since that's by far the most useful | 213 // Special case for PIPELINE_ERROR, since that's by far the most useful |
213 // event for figuring out media pipeline failures, and just reporting | 214 // event for figuring out media pipeline failures, and just reporting |
214 // pipeline status as numeric code is not very helpful/user-friendly. | 215 // pipeline status as numeric code is not very helpful/user-friendly. |
215 int error_code = 0; | 216 int error_code = 0; |
216 if (event.type == MediaLogEvent::PIPELINE_ERROR && | 217 if (event.type == MediaLogEvent::PIPELINE_ERROR && |
217 event.params.GetInteger("pipeline_error", &error_code)) { | 218 event.params.GetInteger("pipeline_error", &error_code)) { |
218 PipelineStatus status = static_cast<PipelineStatus>(error_code); | 219 PipelineStatus status = static_cast<PipelineStatus>(error_code); |
219 return EventTypeToString(event.type) + " " + PipelineStatusToString(status); | 220 return EventTypeToString(event.type) + " " + PipelineStatusToString(status); |
220 } | 221 } |
| 222 |
221 std::string params_json; | 223 std::string params_json; |
222 base::JSONWriter::Write(event.params, ¶ms_json); | 224 base::JSONWriter::Write(event.params, ¶ms_json); |
223 return EventTypeToString(event.type) + " " + params_json; | 225 return EventTypeToString(event.type) + " " + params_json; |
224 } | 226 } |
225 | 227 |
| 228 std::string MediaLog::MediaEventToMessageString(const MediaLogEvent& event) { |
| 229 switch (event.type) { |
| 230 case MediaLogEvent::PIPELINE_ERROR: { |
| 231 int error_code = 0; |
| 232 event.params.GetInteger("pipeline_error", &error_code); |
| 233 DCHECK_NE(error_code, 0); |
| 234 return PipelineStatusToString(static_cast<PipelineStatus>(error_code)); |
| 235 } |
| 236 case MediaLogEvent::MEDIA_ERROR_LOG_ENTRY: { |
| 237 std::string result = ""; |
| 238 if (event.params.GetString(MediaLogLevelToString(MEDIALOG_ERROR), |
| 239 &result)) |
| 240 base::ReplaceChars(result, "\n", " ", &result); |
| 241 return result; |
| 242 } |
| 243 default: |
| 244 NOTREACHED(); |
| 245 return ""; |
| 246 } |
| 247 } |
| 248 |
226 std::string MediaLog::BufferingStateToString(BufferingState state) { | 249 std::string MediaLog::BufferingStateToString(BufferingState state) { |
227 switch (state) { | 250 switch (state) { |
228 case BUFFERING_HAVE_NOTHING: | 251 case BUFFERING_HAVE_NOTHING: |
229 return "BUFFERING_HAVE_NOTHING"; | 252 return "BUFFERING_HAVE_NOTHING"; |
230 case BUFFERING_HAVE_ENOUGH: | 253 case BUFFERING_HAVE_ENOUGH: |
231 return "BUFFERING_HAVE_ENOUGH"; | 254 return "BUFFERING_HAVE_ENOUGH"; |
232 } | 255 } |
233 NOTREACHED(); | 256 NOTREACHED(); |
234 return ""; | 257 return ""; |
235 } | 258 } |
236 | 259 |
237 MediaLog::MediaLog() : id_(g_media_log_count.GetNext()) {} | 260 MediaLog::MediaLog() : id_(g_media_log_count.GetNext()) {} |
238 | 261 |
239 MediaLog::~MediaLog() {} | 262 MediaLog::~MediaLog() {} |
240 | 263 |
241 void MediaLog::AddEvent(std::unique_ptr<MediaLogEvent> event) {} | 264 void MediaLog::AddEvent(std::unique_ptr<MediaLogEvent> event) {} |
242 | 265 |
243 std::string MediaLog::GetLastErrorMessage() { | 266 std::string MediaLog::GetErrorMessage() { |
244 return ""; | 267 return ""; |
245 } | 268 } |
246 | 269 |
247 void MediaLog::RecordRapporWithSecurityOrigin(const std::string& metric) { | 270 void MediaLog::RecordRapporWithSecurityOrigin(const std::string& metric) { |
248 DVLOG(1) << "Default MediaLog doesn't support rappor reporting."; | 271 DVLOG(1) << "Default MediaLog doesn't support rappor reporting."; |
249 } | 272 } |
250 | 273 |
251 std::unique_ptr<MediaLogEvent> MediaLog::CreateEvent(MediaLogEvent::Type type) { | 274 std::unique_ptr<MediaLogEvent> MediaLog::CreateEvent(MediaLogEvent::Type type) { |
252 std::unique_ptr<MediaLogEvent> event(new MediaLogEvent); | 275 std::unique_ptr<MediaLogEvent> event(new MediaLogEvent); |
253 event->id = id_; | 276 event->id = id_; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 const scoped_refptr<MediaLog>& media_log) | 405 const scoped_refptr<MediaLog>& media_log) |
383 : level_(level), media_log_(media_log) { | 406 : level_(level), media_log_(media_log) { |
384 DCHECK(media_log_.get()); | 407 DCHECK(media_log_.get()); |
385 } | 408 } |
386 | 409 |
387 LogHelper::~LogHelper() { | 410 LogHelper::~LogHelper() { |
388 media_log_->AddLogEvent(level_, stream_.str()); | 411 media_log_->AddLogEvent(level_, stream_.str()); |
389 } | 412 } |
390 | 413 |
391 } //namespace media | 414 } //namespace media |
OLD | NEW |