Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1008)

Side by Side Diff: media/base/media_log.cc

Issue 1041353002: media-internals: Differentiate error, info, and debug log messages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Attempt to fix android compile error Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
20 std::string MediaLog::EventTypeToString(MediaLogEvent::Type type) { 33 std::string MediaLog::EventTypeToString(MediaLogEvent::Type type) {
21 switch (type) { 34 switch (type) {
22 case MediaLogEvent::WEBMEDIAPLAYER_CREATED: 35 case MediaLogEvent::WEBMEDIAPLAYER_CREATED:
23 return "WEBMEDIAPLAYER_CREATED"; 36 return "WEBMEDIAPLAYER_CREATED";
24 case MediaLogEvent::WEBMEDIAPLAYER_DESTROYED: 37 case MediaLogEvent::WEBMEDIAPLAYER_DESTROYED:
25 return "WEBMEDIAPLAYER_DESTROYED"; 38 return "WEBMEDIAPLAYER_DESTROYED";
26 case MediaLogEvent::PIPELINE_CREATED: 39 case MediaLogEvent::PIPELINE_CREATED:
27 return "PIPELINE_CREATED"; 40 return "PIPELINE_CREATED";
28 case MediaLogEvent::PIPELINE_DESTROYED: 41 case MediaLogEvent::PIPELINE_DESTROYED:
29 return "PIPELINE_DESTROYED"; 42 return "PIPELINE_DESTROYED";
(...skipping 16 matching lines...) Expand all
46 case MediaLogEvent::TOTAL_BYTES_SET: 59 case MediaLogEvent::TOTAL_BYTES_SET:
47 return "TOTAL_BYTES_SET"; 60 return "TOTAL_BYTES_SET";
48 case MediaLogEvent::NETWORK_ACTIVITY_SET: 61 case MediaLogEvent::NETWORK_ACTIVITY_SET:
49 return "NETWORK_ACTIVITY_SET"; 62 return "NETWORK_ACTIVITY_SET";
50 case MediaLogEvent::ENDED: 63 case MediaLogEvent::ENDED:
51 return "ENDED"; 64 return "ENDED";
52 case MediaLogEvent::TEXT_ENDED: 65 case MediaLogEvent::TEXT_ENDED:
53 return "TEXT_ENDED"; 66 return "TEXT_ENDED";
54 case MediaLogEvent::BUFFERED_EXTENTS_CHANGED: 67 case MediaLogEvent::BUFFERED_EXTENTS_CHANGED:
55 return "BUFFERED_EXTENTS_CHANGED"; 68 return "BUFFERED_EXTENTS_CHANGED";
56 case MediaLogEvent::MEDIA_SOURCE_ERROR: 69 case MediaLogEvent::MEDIA_ERROR_LOG_ENTRY:
57 return "MEDIA_SOURCE_ERROR"; 70 return "MEDIA_ERROR_LOG_ENTRY";
71 case MediaLogEvent::MEDIA_INFO_LOG_ENTRY:
72 return "MEDIA_INFO_LOG_ENTRY";
73 case MediaLogEvent::MEDIA_DEBUG_LOG_ENTRY:
74 return "MEDIA_DEBUG_LOG_ENTRY";
58 case MediaLogEvent::PROPERTY_CHANGE: 75 case MediaLogEvent::PROPERTY_CHANGE:
59 return "PROPERTY_CHANGE"; 76 return "PROPERTY_CHANGE";
60 } 77 }
61 NOTREACHED(); 78 NOTREACHED();
62 return NULL; 79 return NULL;
63 } 80 }
64 81
65 std::string MediaLog::PipelineStatusToString(PipelineStatus status) { 82 std::string MediaLog::PipelineStatusToString(PipelineStatus status) {
66 switch (status) { 83 switch (status) {
67 case PIPELINE_OK: 84 case PIPELINE_OK:
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 event.params.GetInteger("pipeline_error", &error_code)) { 125 event.params.GetInteger("pipeline_error", &error_code)) {
109 PipelineStatus status = static_cast<PipelineStatus>(error_code); 126 PipelineStatus status = static_cast<PipelineStatus>(error_code);
110 return EventTypeToString(event.type) + " " + 127 return EventTypeToString(event.type) + " " +
111 media::MediaLog::PipelineStatusToString(status); 128 media::MediaLog::PipelineStatusToString(status);
112 } 129 }
113 std::string params_json; 130 std::string params_json;
114 base::JSONWriter::Write(&event.params, &params_json); 131 base::JSONWriter::Write(&event.params, &params_json);
115 return EventTypeToString(event.type) + " " + params_json; 132 return EventTypeToString(event.type) + " " + params_json;
116 } 133 }
117 134
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()) {} 135 MediaLog::MediaLog() : id_(g_media_log_count.GetNext()) {}
127 136
128 MediaLog::~MediaLog() {} 137 MediaLog::~MediaLog() {}
129 138
130 void MediaLog::AddEvent(scoped_ptr<MediaLogEvent> event) {} 139 void MediaLog::AddEvent(scoped_ptr<MediaLogEvent> event) {}
131 140
132 scoped_ptr<MediaLogEvent> MediaLog::CreateEvent(MediaLogEvent::Type type) { 141 scoped_ptr<MediaLogEvent> MediaLog::CreateEvent(MediaLogEvent::Type type) {
133 scoped_ptr<MediaLogEvent> event(new MediaLogEvent); 142 scoped_ptr<MediaLogEvent> event(new MediaLogEvent);
134 event->id = id_; 143 event->id = id_;
135 event->type = type; 144 event->type = type;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 scoped_ptr<MediaLogEvent> event( 216 scoped_ptr<MediaLogEvent> event(
208 CreateEvent(MediaLogEvent::BUFFERED_EXTENTS_CHANGED)); 217 CreateEvent(MediaLogEvent::BUFFERED_EXTENTS_CHANGED));
209 // These values are headed to JS where there is no int64 so we use a double 218 // 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). 219 // and accept loss of precision above 2^53 bytes (8 Exabytes).
211 event->params.SetDouble("buffer_start", start); 220 event->params.SetDouble("buffer_start", start);
212 event->params.SetDouble("buffer_current", current); 221 event->params.SetDouble("buffer_current", current);
213 event->params.SetDouble("buffer_end", end); 222 event->params.SetDouble("buffer_end", end);
214 return event.Pass(); 223 return event.Pass();
215 } 224 }
216 225
217 scoped_ptr<MediaLogEvent> MediaLog::CreateMediaSourceErrorEvent( 226 scoped_ptr<MediaLogEvent> MediaLog::CreateLogEvent(MediaLogLevel level,
218 const std::string& error) { 227 const std::string& message) {
219 scoped_ptr<MediaLogEvent> event( 228 switch (level) {
220 CreateEvent(MediaLogEvent::MEDIA_SOURCE_ERROR)); 229 case MEDIALOG_ERROR:
DaleCurtis 2015/03/31 00:12:26 Just use the MediaLogLevelToString() function inst
wolenetz 2015/03/31 00:30:11 Yeah, I'll update that function to emit e.g. "erro
wolenetz 2015/03/31 19:20:22 Done.
221 event->params.SetString("error", error); 230 {
DaleCurtis 2015/03/31 00:12:26 { with : or did clang-format do this?
wolenetz 2015/03/31 00:30:11 I did this because otherwise event is declared mul
DaleCurtis 2015/03/31 00:34:25 I just meant the style, { should be on the same li
wolenetz 2015/03/31 19:20:22 I've now git-cl-format'ed the whole thing. It was
222 return event.Pass(); 231 scoped_ptr<MediaLogEvent> event(
232 CreateEvent(MediaLogEvent::MEDIA_ERROR_LOG_ENTRY));
233 event->params.SetString("error", message);
234 return event.Pass();
235 }
236 case MEDIALOG_INFO:
237 {
238 scoped_ptr<MediaLogEvent> event(
239 CreateEvent(MediaLogEvent::MEDIA_INFO_LOG_ENTRY));
240 event->params.SetString("info", message);
241 return event.Pass();
242 }
243 case MEDIALOG_DEBUG:
244 {
245 scoped_ptr<MediaLogEvent> event(
246 CreateEvent(MediaLogEvent::MEDIA_DEBUG_LOG_ENTRY));
247 event->params.SetString("debug", message);
248 return event.Pass();
249 }
250 }
251 NOTREACHED();
252 return NULL;
223 } 253 }
224 254
225 void MediaLog::SetStringProperty( 255 void MediaLog::SetStringProperty(
226 const std::string& key, const std::string& value) { 256 const std::string& key, const std::string& value) {
227 scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::PROPERTY_CHANGE)); 257 scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::PROPERTY_CHANGE));
228 event->params.SetString(key, value); 258 event->params.SetString(key, value);
229 AddEvent(event.Pass()); 259 AddEvent(event.Pass());
230 } 260 }
231 261
232 void MediaLog::SetIntegerProperty( 262 void MediaLog::SetIntegerProperty(
(...skipping 20 matching lines...) Expand all
253 void MediaLog::SetTimeProperty( 283 void MediaLog::SetTimeProperty(
254 const std::string& key, base::TimeDelta value) { 284 const std::string& key, base::TimeDelta value) {
255 scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::PROPERTY_CHANGE)); 285 scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::PROPERTY_CHANGE));
256 if (value.is_max()) 286 if (value.is_max())
257 event->params.SetString(key, "unknown"); 287 event->params.SetString(key, "unknown");
258 else 288 else
259 event->params.SetDouble(key, value.InSecondsF()); 289 event->params.SetDouble(key, value.InSecondsF());
260 AddEvent(event.Pass()); 290 AddEvent(event.Pass());
261 } 291 }
262 292
293 LogHelper::LogHelper(const LogCB& log_cb, MediaLog::MediaLogLevel level)
294 : log_cb_(log_cb),
295 level_(level) {
296 }
297
298 LogHelper::~LogHelper() {
299 if (log_cb_.is_null())
300 return;
301 log_cb_.Run(level_, stream_.str());
302 }
303
263 } //namespace media 304 } //namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698