Chromium Code Reviews| 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 <string> | 7 #include <string> |
| 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/logging.h" | 11 #include "base/logging.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 std::string MediaLog::EventTypeToString(MediaLogEvent::Type type) { | 20 std::string MediaLog::EventTypeToString(MediaLogEvent::Type type) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 return "demuxer: could not parse"; | 92 return "demuxer: could not parse"; |
| 92 case DEMUXER_ERROR_NO_SUPPORTED_STREAMS: | 93 case DEMUXER_ERROR_NO_SUPPORTED_STREAMS: |
| 93 return "demuxer: no supported streams"; | 94 return "demuxer: no supported streams"; |
| 94 case DECODER_ERROR_NOT_SUPPORTED: | 95 case DECODER_ERROR_NOT_SUPPORTED: |
| 95 return "decoder: not supported"; | 96 return "decoder: not supported"; |
| 96 } | 97 } |
| 97 NOTREACHED(); | 98 NOTREACHED(); |
| 98 return NULL; | 99 return NULL; |
| 99 } | 100 } |
| 100 | 101 |
| 102 std::string MediaLog::MediaEventToLogString(const MediaLogEvent& event) { | |
| 103 // Special case for PIPELINE_ERROR, since that's by far the most useful | |
| 104 // event for figuring out media pipeline failures, and just reporting | |
| 105 // pipeline status as numberic code is not very helpful/user-friendly. | |
|
wolenetz
2015/03/26 01:38:52
nit: s/numberic/numeric/
servolk
2015/03/26 17:06:47
Done.
| |
| 106 int error_code = 0; | |
| 107 if (event.type == MediaLogEvent::PIPELINE_ERROR && | |
| 108 event.params.GetInteger("pipeline_error", &error_code)) { | |
| 109 PipelineStatus status = static_cast<PipelineStatus>(error_code); | |
| 110 return EventTypeToString(event.type) + " " + | |
| 111 media::MediaLog::PipelineStatusToString(status); | |
| 112 } | |
| 113 std::string params_json; | |
| 114 base::JSONWriter::Write(&event.params, ¶ms_json); | |
| 115 return EventTypeToString(event.type) + " " + params_json; | |
| 116 } | |
| 117 | |
| 101 LogHelper::LogHelper(const LogCB& log_cb) : log_cb_(log_cb) {} | 118 LogHelper::LogHelper(const LogCB& log_cb) : log_cb_(log_cb) {} |
| 102 | 119 |
| 103 LogHelper::~LogHelper() { | 120 LogHelper::~LogHelper() { |
| 104 if (log_cb_.is_null()) | 121 if (log_cb_.is_null()) |
| 105 return; | 122 return; |
| 106 log_cb_.Run(stream_.str()); | 123 log_cb_.Run(stream_.str()); |
| 107 } | 124 } |
| 108 | 125 |
| 109 MediaLog::MediaLog() : id_(g_media_log_count.GetNext()) {} | 126 MediaLog::MediaLog() : id_(g_media_log_count.GetNext()) {} |
| 110 | 127 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 const std::string& key, base::TimeDelta value) { | 254 const std::string& key, base::TimeDelta value) { |
| 238 scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::PROPERTY_CHANGE)); | 255 scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::PROPERTY_CHANGE)); |
| 239 if (value.is_max()) | 256 if (value.is_max()) |
| 240 event->params.SetString(key, "unknown"); | 257 event->params.SetString(key, "unknown"); |
| 241 else | 258 else |
| 242 event->params.SetDouble(key, value.InSecondsF()); | 259 event->params.SetDouble(key, value.InSecondsF()); |
| 243 AddEvent(event.Pass()); | 260 AddEvent(event.Pass()); |
| 244 } | 261 } |
| 245 | 262 |
| 246 } //namespace media | 263 } //namespace media |
| OLD | NEW |