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/json/json_writer.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 | 13 |
14 namespace media { | 14 namespace media { |
15 | 15 |
16 // 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 |
17 // unique IDs. | 17 // unique IDs. |
18 static base::StaticAtomicSequenceNumber g_media_log_count; | 18 static base::StaticAtomicSequenceNumber g_media_log_count; |
19 | 19 |
20 std::string MediaLog::MediaLogLevelToString(MediaLogLevel level) { | |
21 switch (level) { | |
22 case MEDIALOG_ERROR: | |
23 return "error"; | |
24 case MEDIALOG_INFO: | |
25 return "info"; | |
26 case MEDIALOG_DEBUG: | |
27 return "debug"; | |
28 } | |
29 NOTREACHED(); | |
30 return NULL; | |
31 } | |
32 | |
33 MediaLogEvent::Type MediaLog::MediaLogLevelToEventType(MediaLogLevel level) { | |
34 switch (level) { | |
35 case MEDIALOG_ERROR: | |
36 return MediaLogEvent::MEDIA_ERROR_LOG_ENTRY; | |
37 case MEDIALOG_INFO: | |
38 return MediaLogEvent::MEDIA_INFO_LOG_ENTRY; | |
39 case MEDIALOG_DEBUG: | |
40 return MediaLogEvent::MEDIA_DEBUG_LOG_ENTRY; | |
41 } | |
42 NOTREACHED(); | |
43 return MediaLogEvent::MEDIA_ERROR_LOG_ENTRY; | |
44 } | |
45 | |
20 std::string MediaLog::EventTypeToString(MediaLogEvent::Type type) { | 46 std::string MediaLog::EventTypeToString(MediaLogEvent::Type type) { |
21 switch (type) { | 47 switch (type) { |
22 case MediaLogEvent::WEBMEDIAPLAYER_CREATED: | 48 case MediaLogEvent::WEBMEDIAPLAYER_CREATED: |
23 return "WEBMEDIAPLAYER_CREATED"; | 49 return "WEBMEDIAPLAYER_CREATED"; |
24 case MediaLogEvent::WEBMEDIAPLAYER_DESTROYED: | 50 case MediaLogEvent::WEBMEDIAPLAYER_DESTROYED: |
25 return "WEBMEDIAPLAYER_DESTROYED"; | 51 return "WEBMEDIAPLAYER_DESTROYED"; |
26 case MediaLogEvent::PIPELINE_CREATED: | 52 case MediaLogEvent::PIPELINE_CREATED: |
27 return "PIPELINE_CREATED"; | 53 return "PIPELINE_CREATED"; |
28 case MediaLogEvent::PIPELINE_DESTROYED: | 54 case MediaLogEvent::PIPELINE_DESTROYED: |
29 return "PIPELINE_DESTROYED"; | 55 return "PIPELINE_DESTROYED"; |
(...skipping 16 matching lines...) Expand all Loading... | |
46 case MediaLogEvent::TOTAL_BYTES_SET: | 72 case MediaLogEvent::TOTAL_BYTES_SET: |
47 return "TOTAL_BYTES_SET"; | 73 return "TOTAL_BYTES_SET"; |
48 case MediaLogEvent::NETWORK_ACTIVITY_SET: | 74 case MediaLogEvent::NETWORK_ACTIVITY_SET: |
49 return "NETWORK_ACTIVITY_SET"; | 75 return "NETWORK_ACTIVITY_SET"; |
50 case MediaLogEvent::ENDED: | 76 case MediaLogEvent::ENDED: |
51 return "ENDED"; | 77 return "ENDED"; |
52 case MediaLogEvent::TEXT_ENDED: | 78 case MediaLogEvent::TEXT_ENDED: |
53 return "TEXT_ENDED"; | 79 return "TEXT_ENDED"; |
54 case MediaLogEvent::BUFFERED_EXTENTS_CHANGED: | 80 case MediaLogEvent::BUFFERED_EXTENTS_CHANGED: |
55 return "BUFFERED_EXTENTS_CHANGED"; | 81 return "BUFFERED_EXTENTS_CHANGED"; |
56 case MediaLogEvent::MEDIA_SOURCE_ERROR: | 82 case MediaLogEvent::MEDIA_ERROR_LOG_ENTRY: |
57 return "MEDIA_SOURCE_ERROR"; | 83 return "MEDIA_ERROR_LOG_ENTRY"; |
84 case MediaLogEvent::MEDIA_INFO_LOG_ENTRY: | |
85 return "MEDIA_INFO_LOG_ENTRY"; | |
86 case MediaLogEvent::MEDIA_DEBUG_LOG_ENTRY: | |
87 return "MEDIA_DEBUG_LOG_ENTRY"; | |
58 case MediaLogEvent::PROPERTY_CHANGE: | 88 case MediaLogEvent::PROPERTY_CHANGE: |
59 return "PROPERTY_CHANGE"; | 89 return "PROPERTY_CHANGE"; |
60 } | 90 } |
61 NOTREACHED(); | 91 NOTREACHED(); |
62 return NULL; | 92 return NULL; |
63 } | 93 } |
64 | 94 |
65 std::string MediaLog::PipelineStatusToString(PipelineStatus status) { | 95 std::string MediaLog::PipelineStatusToString(PipelineStatus status) { |
66 switch (status) { | 96 switch (status) { |
67 case PIPELINE_OK: | 97 case PIPELINE_OK: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 event.params.GetInteger("pipeline_error", &error_code)) { | 138 event.params.GetInteger("pipeline_error", &error_code)) { |
109 PipelineStatus status = static_cast<PipelineStatus>(error_code); | 139 PipelineStatus status = static_cast<PipelineStatus>(error_code); |
110 return EventTypeToString(event.type) + " " + | 140 return EventTypeToString(event.type) + " " + |
111 media::MediaLog::PipelineStatusToString(status); | 141 media::MediaLog::PipelineStatusToString(status); |
112 } | 142 } |
113 std::string params_json; | 143 std::string params_json; |
114 base::JSONWriter::Write(&event.params, ¶ms_json); | 144 base::JSONWriter::Write(&event.params, ¶ms_json); |
115 return EventTypeToString(event.type) + " " + params_json; | 145 return EventTypeToString(event.type) + " " + params_json; |
116 } | 146 } |
117 | 147 |
118 LogHelper::LogHelper(const LogCB& log_cb) : log_cb_(log_cb) {} | |
119 | |
120 LogHelper::~LogHelper() { | |
121 if (log_cb_.is_null()) | |
122 return; | |
123 log_cb_.Run(stream_.str()); | |
124 } | |
125 | |
126 MediaLog::MediaLog() : id_(g_media_log_count.GetNext()) {} | 148 MediaLog::MediaLog() : id_(g_media_log_count.GetNext()) {} |
127 | 149 |
128 MediaLog::~MediaLog() {} | 150 MediaLog::~MediaLog() {} |
129 | 151 |
130 void MediaLog::AddEvent(scoped_ptr<MediaLogEvent> event) {} | 152 void MediaLog::AddEvent(scoped_ptr<MediaLogEvent> event) {} |
131 | 153 |
132 scoped_ptr<MediaLogEvent> MediaLog::CreateEvent(MediaLogEvent::Type type) { | 154 scoped_ptr<MediaLogEvent> MediaLog::CreateEvent(MediaLogEvent::Type type) { |
133 scoped_ptr<MediaLogEvent> event(new MediaLogEvent); | 155 scoped_ptr<MediaLogEvent> event(new MediaLogEvent); |
134 event->id = id_; | 156 event->id = id_; |
135 event->type = type; | 157 event->type = type; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 scoped_ptr<MediaLogEvent> event( | 229 scoped_ptr<MediaLogEvent> event( |
208 CreateEvent(MediaLogEvent::BUFFERED_EXTENTS_CHANGED)); | 230 CreateEvent(MediaLogEvent::BUFFERED_EXTENTS_CHANGED)); |
209 // These values are headed to JS where there is no int64 so we use a double | 231 // These values are headed to JS where there is no int64 so we use a double |
210 // and accept loss of precision above 2^53 bytes (8 Exabytes). | 232 // and accept loss of precision above 2^53 bytes (8 Exabytes). |
211 event->params.SetDouble("buffer_start", start); | 233 event->params.SetDouble("buffer_start", start); |
212 event->params.SetDouble("buffer_current", current); | 234 event->params.SetDouble("buffer_current", current); |
213 event->params.SetDouble("buffer_end", end); | 235 event->params.SetDouble("buffer_end", end); |
214 return event.Pass(); | 236 return event.Pass(); |
215 } | 237 } |
216 | 238 |
217 scoped_ptr<MediaLogEvent> MediaLog::CreateMediaSourceErrorEvent( | 239 scoped_ptr<MediaLogEvent> MediaLog::CreateLogEvent(MediaLogLevel level, |
218 const std::string& error) { | 240 const std::string& message) { |
219 scoped_ptr<MediaLogEvent> event( | 241 const MediaLogEvent::Type type = MediaLogLevelToEventType(level); |
DaleCurtis
2015/03/31 20:46:16
Just inline these two variables?
| |
220 CreateEvent(MediaLogEvent::MEDIA_SOURCE_ERROR)); | 242 const std::string param = MediaLogLevelToString(level); |
221 event->params.SetString("error", error); | 243 scoped_ptr<MediaLogEvent> event(CreateEvent(type)); |
244 event->params.SetString(param, message); | |
222 return event.Pass(); | 245 return event.Pass(); |
223 } | 246 } |
224 | 247 |
225 void MediaLog::SetStringProperty( | 248 void MediaLog::SetStringProperty( |
226 const std::string& key, const std::string& value) { | 249 const std::string& key, const std::string& value) { |
227 scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::PROPERTY_CHANGE)); | 250 scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::PROPERTY_CHANGE)); |
228 event->params.SetString(key, value); | 251 event->params.SetString(key, value); |
229 AddEvent(event.Pass()); | 252 AddEvent(event.Pass()); |
230 } | 253 } |
231 | 254 |
(...skipping 21 matching lines...) Expand all Loading... | |
253 void MediaLog::SetTimeProperty( | 276 void MediaLog::SetTimeProperty( |
254 const std::string& key, base::TimeDelta value) { | 277 const std::string& key, base::TimeDelta value) { |
255 scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::PROPERTY_CHANGE)); | 278 scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::PROPERTY_CHANGE)); |
256 if (value.is_max()) | 279 if (value.is_max()) |
257 event->params.SetString(key, "unknown"); | 280 event->params.SetString(key, "unknown"); |
258 else | 281 else |
259 event->params.SetDouble(key, value.InSecondsF()); | 282 event->params.SetDouble(key, value.InSecondsF()); |
260 AddEvent(event.Pass()); | 283 AddEvent(event.Pass()); |
261 } | 284 } |
262 | 285 |
286 LogHelper::LogHelper(MediaLog::MediaLogLevel level, const LogCB& log_cb) | |
287 : level_(level), log_cb_(log_cb) { | |
288 } | |
289 | |
290 LogHelper::~LogHelper() { | |
291 if (log_cb_.is_null()) | |
292 return; | |
293 log_cb_.Run(level_, stream_.str()); | |
294 } | |
295 | |
263 } //namespace media | 296 } //namespace media |
OLD | NEW |