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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 case MediaLogEvent::PROPERTY_CHANGE: | 162 case MediaLogEvent::PROPERTY_CHANGE: |
162 return "PROPERTY_CHANGE"; | 163 return "PROPERTY_CHANGE"; |
163 case MediaLogEvent::WATCH_TIME_UPDATE: | 164 case MediaLogEvent::WATCH_TIME_UPDATE: |
164 return "WATCH_TIME_UPDATE"; | 165 return "WATCH_TIME_UPDATE"; |
165 } | 166 } |
166 NOTREACHED(); | 167 NOTREACHED(); |
167 return NULL; | 168 return NULL; |
168 } | 169 } |
169 | 170 |
170 std::string MediaLog::PipelineStatusToString(PipelineStatus status) { | 171 std::string MediaLog::PipelineStatusToString(PipelineStatus status) { |
| 172 #define STRINGIFY_STATUS_CASE(status) \ |
| 173 case status: \ |
| 174 return #status |
| 175 |
171 switch (status) { | 176 switch (status) { |
172 case PIPELINE_OK: | 177 STRINGIFY_STATUS_CASE(PIPELINE_OK); |
173 return "pipeline: ok"; | 178 STRINGIFY_STATUS_CASE(PIPELINE_ERROR_NETWORK); |
174 case PIPELINE_ERROR_NETWORK: | 179 STRINGIFY_STATUS_CASE(PIPELINE_ERROR_DECODE); |
175 return "pipeline: network error"; | 180 STRINGIFY_STATUS_CASE(PIPELINE_ERROR_ABORT); |
176 case PIPELINE_ERROR_DECODE: | 181 STRINGIFY_STATUS_CASE(PIPELINE_ERROR_INITIALIZATION_FAILED); |
177 return "pipeline: decode error"; | 182 STRINGIFY_STATUS_CASE(PIPELINE_ERROR_COULD_NOT_RENDER); |
178 case PIPELINE_ERROR_ABORT: | 183 STRINGIFY_STATUS_CASE(PIPELINE_ERROR_EXTERNAL_RENDERER_FAILED); |
179 return "pipeline: abort"; | 184 STRINGIFY_STATUS_CASE(PIPELINE_ERROR_READ); |
180 case PIPELINE_ERROR_INITIALIZATION_FAILED: | 185 STRINGIFY_STATUS_CASE(PIPELINE_ERROR_INVALID_STATE); |
181 return "pipeline: initialization failed"; | 186 STRINGIFY_STATUS_CASE(DEMUXER_ERROR_COULD_NOT_OPEN); |
182 case PIPELINE_ERROR_COULD_NOT_RENDER: | 187 STRINGIFY_STATUS_CASE(DEMUXER_ERROR_COULD_NOT_PARSE); |
183 return "pipeline: could not render"; | 188 STRINGIFY_STATUS_CASE(DEMUXER_ERROR_NO_SUPPORTED_STREAMS); |
184 case PIPELINE_ERROR_EXTERNAL_RENDERER_FAILED: | 189 STRINGIFY_STATUS_CASE(DECODER_ERROR_NOT_SUPPORTED); |
185 return "pipeline: external renderer failed"; | 190 STRINGIFY_STATUS_CASE(CHUNK_DEMUXER_ERROR_APPEND_FAILED); |
186 case PIPELINE_ERROR_READ: | 191 STRINGIFY_STATUS_CASE(CHUNK_DEMUXER_ERROR_EOS_STATUS_DECODE_ERROR); |
187 return "pipeline: read error"; | 192 STRINGIFY_STATUS_CASE(CHUNK_DEMUXER_ERROR_EOS_STATUS_NETWORK_ERROR); |
188 case PIPELINE_ERROR_INVALID_STATE: | 193 STRINGIFY_STATUS_CASE(AUDIO_RENDERER_ERROR); |
189 return "pipeline: invalid state"; | |
190 case DEMUXER_ERROR_COULD_NOT_OPEN: | |
191 return "demuxer: could not open"; | |
192 case DEMUXER_ERROR_COULD_NOT_PARSE: | |
193 return "demuxer: could not parse"; | |
194 case DEMUXER_ERROR_NO_SUPPORTED_STREAMS: | |
195 return "demuxer: no supported streams"; | |
196 case DECODER_ERROR_NOT_SUPPORTED: | |
197 return "decoder: not supported"; | |
198 case CHUNK_DEMUXER_ERROR_APPEND_FAILED: | |
199 return "chunk demuxer: append failed"; | |
200 case CHUNK_DEMUXER_ERROR_EOS_STATUS_DECODE_ERROR: | |
201 return "chunk demuxer: application requested decode error on eos"; | |
202 case CHUNK_DEMUXER_ERROR_EOS_STATUS_NETWORK_ERROR: | |
203 return "chunk demuxer: application requested network error on eos"; | |
204 case AUDIO_RENDERER_ERROR: | |
205 return "audio renderer: output device reported an error"; | |
206 } | 194 } |
| 195 |
| 196 #undef STRINGIFY_STATUS_CASE |
| 197 |
207 NOTREACHED(); | 198 NOTREACHED(); |
208 return NULL; | 199 return NULL; |
209 } | 200 } |
210 | 201 |
211 std::string MediaLog::MediaEventToLogString(const MediaLogEvent& event) { | 202 std::string MediaLog::MediaEventToLogString(const MediaLogEvent& event) { |
212 // Special case for PIPELINE_ERROR, since that's by far the most useful | 203 // Special case for PIPELINE_ERROR, since that's by far the most useful |
213 // event for figuring out media pipeline failures, and just reporting | 204 // event for figuring out media pipeline failures, and just reporting |
214 // pipeline status as numeric code is not very helpful/user-friendly. | 205 // pipeline status as numeric code is not very helpful/user-friendly. |
215 int error_code = 0; | 206 int error_code = 0; |
216 if (event.type == MediaLogEvent::PIPELINE_ERROR && | 207 if (event.type == MediaLogEvent::PIPELINE_ERROR && |
217 event.params.GetInteger("pipeline_error", &error_code)) { | 208 event.params.GetInteger("pipeline_error", &error_code)) { |
218 PipelineStatus status = static_cast<PipelineStatus>(error_code); | 209 PipelineStatus status = static_cast<PipelineStatus>(error_code); |
219 return EventTypeToString(event.type) + " " + PipelineStatusToString(status); | 210 return EventTypeToString(event.type) + " " + PipelineStatusToString(status); |
220 } | 211 } |
| 212 |
221 std::string params_json; | 213 std::string params_json; |
222 base::JSONWriter::Write(event.params, ¶ms_json); | 214 base::JSONWriter::Write(event.params, ¶ms_json); |
223 return EventTypeToString(event.type) + " " + params_json; | 215 return EventTypeToString(event.type) + " " + params_json; |
224 } | 216 } |
225 | 217 |
| 218 std::string MediaLog::MediaEventToMessageString(const MediaLogEvent& event) { |
| 219 switch (event.type) { |
| 220 case MediaLogEvent::PIPELINE_ERROR: { |
| 221 int error_code = 0; |
| 222 event.params.GetInteger("pipeline_error", &error_code); |
| 223 DCHECK_NE(error_code, 0); |
| 224 return PipelineStatusToString(static_cast<PipelineStatus>(error_code)); |
| 225 } |
| 226 case MediaLogEvent::MEDIA_ERROR_LOG_ENTRY: { |
| 227 std::string result = ""; |
| 228 if (event.params.GetString(MediaLogLevelToString(MEDIALOG_ERROR), |
| 229 &result)) |
| 230 base::ReplaceChars(result, "\n", " ", &result); |
| 231 return result; |
| 232 } |
| 233 default: |
| 234 NOTREACHED(); |
| 235 return ""; |
| 236 } |
| 237 } |
| 238 |
226 std::string MediaLog::BufferingStateToString(BufferingState state) { | 239 std::string MediaLog::BufferingStateToString(BufferingState state) { |
227 switch (state) { | 240 switch (state) { |
228 case BUFFERING_HAVE_NOTHING: | 241 case BUFFERING_HAVE_NOTHING: |
229 return "BUFFERING_HAVE_NOTHING"; | 242 return "BUFFERING_HAVE_NOTHING"; |
230 case BUFFERING_HAVE_ENOUGH: | 243 case BUFFERING_HAVE_ENOUGH: |
231 return "BUFFERING_HAVE_ENOUGH"; | 244 return "BUFFERING_HAVE_ENOUGH"; |
232 } | 245 } |
233 NOTREACHED(); | 246 NOTREACHED(); |
234 return ""; | 247 return ""; |
235 } | 248 } |
236 | 249 |
237 MediaLog::MediaLog() : id_(g_media_log_count.GetNext()) {} | 250 MediaLog::MediaLog() : id_(g_media_log_count.GetNext()) {} |
238 | 251 |
239 MediaLog::~MediaLog() {} | 252 MediaLog::~MediaLog() {} |
240 | 253 |
241 void MediaLog::AddEvent(std::unique_ptr<MediaLogEvent> event) {} | 254 void MediaLog::AddEvent(std::unique_ptr<MediaLogEvent> event) {} |
242 | 255 |
243 std::string MediaLog::GetLastErrorMessage() { | 256 std::string MediaLog::GetErrorMessage() { |
244 return ""; | 257 return ""; |
245 } | 258 } |
246 | 259 |
247 void MediaLog::RecordRapporWithSecurityOrigin(const std::string& metric) { | 260 void MediaLog::RecordRapporWithSecurityOrigin(const std::string& metric) { |
248 DVLOG(1) << "Default MediaLog doesn't support rappor reporting."; | 261 DVLOG(1) << "Default MediaLog doesn't support rappor reporting."; |
249 } | 262 } |
250 | 263 |
251 std::unique_ptr<MediaLogEvent> MediaLog::CreateEvent(MediaLogEvent::Type type) { | 264 std::unique_ptr<MediaLogEvent> MediaLog::CreateEvent(MediaLogEvent::Type type) { |
252 std::unique_ptr<MediaLogEvent> event(new MediaLogEvent); | 265 std::unique_ptr<MediaLogEvent> event(new MediaLogEvent); |
253 event->id = id_; | 266 event->id = id_; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 const scoped_refptr<MediaLog>& media_log) | 395 const scoped_refptr<MediaLog>& media_log) |
383 : level_(level), media_log_(media_log) { | 396 : level_(level), media_log_(media_log) { |
384 DCHECK(media_log_.get()); | 397 DCHECK(media_log_.get()); |
385 } | 398 } |
386 | 399 |
387 LogHelper::~LogHelper() { | 400 LogHelper::~LogHelper() { |
388 media_log_->AddLogEvent(level_, stream_.str()); | 401 media_log_->AddLogEvent(level_, stream_.str()); |
389 } | 402 } |
390 | 403 |
391 } //namespace media | 404 } //namespace media |
OLD | NEW |