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

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

Issue 2660003003: Add MediaError.message (Closed)
Patch Set: Address dalecurtis@'s comment: Document MediaLog::GetErrorMessage() potential for partial msg Created 3 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
« no previous file with comments | « media/base/media_log.h ('k') | media/blink/webmediaplayer_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 return "MEDIA_DEBUG_LOG_ENTRY"; 161 return "MEDIA_DEBUG_LOG_ENTRY";
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
171 #define STRINGIFY_STATUS_CASE(status) \
172 case status: \
173 return #status
174
170 std::string MediaLog::PipelineStatusToString(PipelineStatus status) { 175 std::string MediaLog::PipelineStatusToString(PipelineStatus status) {
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 }
DaleCurtis 2017/04/20 22:37:30 #undef macro after usage.
wolenetz 2017/04/20 23:01:30 Done in patch set 11 (and I moved the #define to w
207 NOTREACHED(); 195 NOTREACHED();
208 return NULL; 196 return NULL;
209 } 197 }
210 198
211 std::string MediaLog::MediaEventToLogString(const MediaLogEvent& event) { 199 std::string MediaLog::MediaEventToLogString(const MediaLogEvent& event) {
212 // Special case for PIPELINE_ERROR, since that's by far the most useful 200 // Special case for PIPELINE_ERROR, since that's by far the most useful
213 // event for figuring out media pipeline failures, and just reporting 201 // event for figuring out media pipeline failures, and just reporting
214 // pipeline status as numeric code is not very helpful/user-friendly. 202 // pipeline status as numeric code is not very helpful/user-friendly.
215 int error_code = 0; 203 int error_code = 0;
216 if (event.type == MediaLogEvent::PIPELINE_ERROR && 204 if (event.type == MediaLogEvent::PIPELINE_ERROR &&
217 event.params.GetInteger("pipeline_error", &error_code)) { 205 event.params.GetInteger("pipeline_error", &error_code)) {
218 PipelineStatus status = static_cast<PipelineStatus>(error_code); 206 PipelineStatus status = static_cast<PipelineStatus>(error_code);
219 return EventTypeToString(event.type) + " " + PipelineStatusToString(status); 207 return EventTypeToString(event.type) + " " + PipelineStatusToString(status);
220 } 208 }
209
221 std::string params_json; 210 std::string params_json;
222 base::JSONWriter::Write(event.params, &params_json); 211 base::JSONWriter::Write(event.params, &params_json);
223 return EventTypeToString(event.type) + " " + params_json; 212 return EventTypeToString(event.type) + " " + params_json;
224 } 213 }
225 214
215 std::string MediaLog::MediaEventToMessageString(const MediaLogEvent& event) {
216 switch (event.type) {
217 case MediaLogEvent::PIPELINE_ERROR: {
218 int error_code = 0;
219 event.params.GetInteger("pipeline_error", &error_code);
220 DCHECK_NE(error_code, 0);
221 return PipelineStatusToString(static_cast<PipelineStatus>(error_code));
222 }
223 case MediaLogEvent::MEDIA_ERROR_LOG_ENTRY: {
224 std::string result = "";
225 if (event.params.GetString(MediaLogLevelToString(MEDIALOG_ERROR),
226 &result))
227 base::ReplaceChars(result, "\n", " ", &result);
228 return result;
229 }
230 default:
231 NOTREACHED();
232 return "";
233 }
234 }
235
226 std::string MediaLog::BufferingStateToString(BufferingState state) { 236 std::string MediaLog::BufferingStateToString(BufferingState state) {
227 switch (state) { 237 switch (state) {
228 case BUFFERING_HAVE_NOTHING: 238 case BUFFERING_HAVE_NOTHING:
229 return "BUFFERING_HAVE_NOTHING"; 239 return "BUFFERING_HAVE_NOTHING";
230 case BUFFERING_HAVE_ENOUGH: 240 case BUFFERING_HAVE_ENOUGH:
231 return "BUFFERING_HAVE_ENOUGH"; 241 return "BUFFERING_HAVE_ENOUGH";
232 } 242 }
233 NOTREACHED(); 243 NOTREACHED();
234 return ""; 244 return "";
235 } 245 }
236 246
237 MediaLog::MediaLog() : id_(g_media_log_count.GetNext()) {} 247 MediaLog::MediaLog() : id_(g_media_log_count.GetNext()) {}
238 248
239 MediaLog::~MediaLog() {} 249 MediaLog::~MediaLog() {}
240 250
241 void MediaLog::AddEvent(std::unique_ptr<MediaLogEvent> event) {} 251 void MediaLog::AddEvent(std::unique_ptr<MediaLogEvent> event) {}
242 252
243 std::string MediaLog::GetLastErrorMessage() { 253 std::string MediaLog::GetErrorMessage() {
244 return ""; 254 return "";
245 } 255 }
246 256
247 void MediaLog::RecordRapporWithSecurityOrigin(const std::string& metric) { 257 void MediaLog::RecordRapporWithSecurityOrigin(const std::string& metric) {
248 DVLOG(1) << "Default MediaLog doesn't support rappor reporting."; 258 DVLOG(1) << "Default MediaLog doesn't support rappor reporting.";
249 } 259 }
250 260
251 std::unique_ptr<MediaLogEvent> MediaLog::CreateEvent(MediaLogEvent::Type type) { 261 std::unique_ptr<MediaLogEvent> MediaLog::CreateEvent(MediaLogEvent::Type type) {
252 std::unique_ptr<MediaLogEvent> event(new MediaLogEvent); 262 std::unique_ptr<MediaLogEvent> event(new MediaLogEvent);
253 event->id = id_; 263 event->id = id_;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 LogHelper::LogHelper(MediaLog::MediaLogLevel level, MediaLog* media_log) 391 LogHelper::LogHelper(MediaLog::MediaLogLevel level, MediaLog* media_log)
382 : level_(level), media_log_(media_log) { 392 : level_(level), media_log_(media_log) {
383 DCHECK(media_log_); 393 DCHECK(media_log_);
384 } 394 }
385 395
386 LogHelper::~LogHelper() { 396 LogHelper::~LogHelper() {
387 media_log_->AddLogEvent(level_, stream_.str()); 397 media_log_->AddLogEvent(level_, stream_.str());
388 } 398 }
389 399
390 } //namespace media 400 } //namespace media
OLDNEW
« no previous file with comments | « media/base/media_log.h ('k') | media/blink/webmediaplayer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698