| 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/bind.h" | |
| 11 #include "base/lazy_instance.h" | |
| 12 #include "base/logging.h" | 10 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/message_loop.h" | |
| 15 #include "base/values.h" | 11 #include "base/values.h" |
| 16 | 12 |
| 17 namespace media { | 13 namespace media { |
| 18 | 14 |
| 19 // A count of all MediaLogs created on this render process. | 15 // A count of all MediaLogs created in the current process. Used to generate |
| 20 // Used to generate unique ids. | 16 // unique IDs. |
| 21 static base::StaticAtomicSequenceNumber media_log_count; | 17 static base::StaticAtomicSequenceNumber g_media_log_count; |
| 22 | 18 |
| 23 const char* MediaLog::EventTypeToString(MediaLogEvent::Type type) { | 19 const char* MediaLog::EventTypeToString(MediaLogEvent::Type type) { |
| 24 switch (type) { | 20 switch (type) { |
| 25 case MediaLogEvent::WEBMEDIAPLAYER_CREATED: | 21 case MediaLogEvent::WEBMEDIAPLAYER_CREATED: |
| 26 return "WEBMEDIAPLAYER_CREATED"; | 22 return "WEBMEDIAPLAYER_CREATED"; |
| 27 case MediaLogEvent::WEBMEDIAPLAYER_DESTROYED: | 23 case MediaLogEvent::WEBMEDIAPLAYER_DESTROYED: |
| 28 return "WEBMEDIAPLAYER_DESTROYED"; | 24 return "WEBMEDIAPLAYER_DESTROYED"; |
| 29 case MediaLogEvent::PIPELINE_CREATED: | 25 case MediaLogEvent::PIPELINE_CREATED: |
| 30 return "PIPELINE_CREATED"; | 26 return "PIPELINE_CREATED"; |
| 31 case MediaLogEvent::PIPELINE_DESTROYED: | 27 case MediaLogEvent::PIPELINE_DESTROYED: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 49 case MediaLogEvent::TOTAL_BYTES_SET: | 45 case MediaLogEvent::TOTAL_BYTES_SET: |
| 50 return "TOTAL_BYTES_SET"; | 46 return "TOTAL_BYTES_SET"; |
| 51 case MediaLogEvent::NETWORK_ACTIVITY_SET: | 47 case MediaLogEvent::NETWORK_ACTIVITY_SET: |
| 52 return "NETWORK_ACTIVITY_SET"; | 48 return "NETWORK_ACTIVITY_SET"; |
| 53 case MediaLogEvent::ENDED: | 49 case MediaLogEvent::ENDED: |
| 54 return "ENDED"; | 50 return "ENDED"; |
| 55 case MediaLogEvent::AUDIO_RENDERER_DISABLED: | 51 case MediaLogEvent::AUDIO_RENDERER_DISABLED: |
| 56 return "AUDIO_RENDERER_DISABLED"; | 52 return "AUDIO_RENDERER_DISABLED"; |
| 57 case MediaLogEvent::BUFFERED_EXTENTS_CHANGED: | 53 case MediaLogEvent::BUFFERED_EXTENTS_CHANGED: |
| 58 return "BUFFERED_EXTENTS_CHANGED"; | 54 return "BUFFERED_EXTENTS_CHANGED"; |
| 59 case MediaLogEvent::STATISTICS_UPDATED: | |
| 60 return "STATISTICS_UPDATED"; | |
| 61 } | 55 } |
| 62 NOTREACHED(); | 56 NOTREACHED(); |
| 63 return NULL; | 57 return NULL; |
| 64 } | 58 } |
| 65 | 59 |
| 66 const char* MediaLog::PipelineStateToString(Pipeline::State state) { | 60 const char* MediaLog::PipelineStateToString(Pipeline::State state) { |
| 67 switch (state) { | 61 switch (state) { |
| 68 case Pipeline::kCreated: | 62 case Pipeline::kCreated: |
| 69 return "created"; | 63 return "created"; |
| 70 case Pipeline::kInitDemuxer: | 64 case Pipeline::kInitDemuxer: |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 return "dumuxer: could not parse"; | 126 return "dumuxer: could not parse"; |
| 133 case DEMUXER_ERROR_NO_SUPPORTED_STREAMS: | 127 case DEMUXER_ERROR_NO_SUPPORTED_STREAMS: |
| 134 return "demuxer: no supported streams"; | 128 return "demuxer: no supported streams"; |
| 135 case DECODER_ERROR_NOT_SUPPORTED: | 129 case DECODER_ERROR_NOT_SUPPORTED: |
| 136 return "decoder: not supported"; | 130 return "decoder: not supported"; |
| 137 } | 131 } |
| 138 NOTREACHED(); | 132 NOTREACHED(); |
| 139 return NULL; | 133 return NULL; |
| 140 } | 134 } |
| 141 | 135 |
| 142 MediaLog::MediaLog() { | 136 MediaLog::MediaLog() : id_(g_media_log_count.GetNext()) {} |
| 143 id_ = media_log_count.GetNext(); | |
| 144 stats_update_pending_ = false; | |
| 145 } | |
| 146 | 137 |
| 147 MediaLog::~MediaLog() {} | 138 MediaLog::~MediaLog() {} |
| 148 | 139 |
| 149 void MediaLog::AddEvent(scoped_ptr<MediaLogEvent> event) { | 140 void MediaLog::AddEvent(scoped_ptr<MediaLogEvent> event) {} |
| 150 } | |
| 151 | 141 |
| 152 scoped_ptr<MediaLogEvent> MediaLog::CreateEvent(MediaLogEvent::Type type) { | 142 scoped_ptr<MediaLogEvent> MediaLog::CreateEvent(MediaLogEvent::Type type) { |
| 153 scoped_ptr<MediaLogEvent> event(new MediaLogEvent); | 143 scoped_ptr<MediaLogEvent> event(new MediaLogEvent); |
| 154 event->id = id_; | 144 event->id = id_; |
| 155 event->type = type; | 145 event->type = type; |
| 156 event->time = base::Time::Now(); | 146 event->time = base::Time::Now(); |
| 157 return event.Pass(); | 147 return event.Pass(); |
| 158 } | 148 } |
| 159 | 149 |
| 160 scoped_ptr<MediaLogEvent> MediaLog::CreateBooleanEvent( | 150 scoped_ptr<MediaLogEvent> MediaLog::CreateBooleanEvent( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 scoped_ptr<MediaLogEvent> MediaLog::CreateBufferedExtentsChangedEvent( | 206 scoped_ptr<MediaLogEvent> MediaLog::CreateBufferedExtentsChangedEvent( |
| 217 size_t start, size_t current, size_t end) { | 207 size_t start, size_t current, size_t end) { |
| 218 scoped_ptr<MediaLogEvent> event( | 208 scoped_ptr<MediaLogEvent> event( |
| 219 CreateEvent(MediaLogEvent::BUFFERED_EXTENTS_CHANGED)); | 209 CreateEvent(MediaLogEvent::BUFFERED_EXTENTS_CHANGED)); |
| 220 event->params.SetInteger("buffer_start", start); | 210 event->params.SetInteger("buffer_start", start); |
| 221 event->params.SetInteger("buffer_current", current); | 211 event->params.SetInteger("buffer_current", current); |
| 222 event->params.SetInteger("buffer_end", end); | 212 event->params.SetInteger("buffer_end", end); |
| 223 return event.Pass(); | 213 return event.Pass(); |
| 224 } | 214 } |
| 225 | 215 |
| 226 void MediaLog::QueueStatisticsUpdatedEvent(PipelineStatistics stats) { | |
| 227 base::AutoLock auto_lock(stats_lock_); | |
| 228 last_statistics_ = stats; | |
| 229 | |
| 230 // Sadly, this function can get dispatched on threads not running a message | |
| 231 // loop. Happily, this is pretty rare (only VideoRendererBase at this time) | |
| 232 // so we simply leave stats updating for another call to trigger. | |
| 233 if (!stats_update_pending_ && MessageLoop::current()) { | |
| 234 stats_update_pending_ = true; | |
| 235 MessageLoop::current()->PostDelayedTask( | |
| 236 FROM_HERE, | |
| 237 base::Bind(&media::MediaLog::AddStatisticsUpdatedEvent, this), | |
| 238 base::TimeDelta::FromMilliseconds(500)); | |
| 239 } | |
| 240 } | |
| 241 | |
| 242 void MediaLog::AddStatisticsUpdatedEvent() { | |
| 243 base::AutoLock auto_lock(stats_lock_); | |
| 244 scoped_ptr<MediaLogEvent> event( | |
| 245 CreateEvent(MediaLogEvent::STATISTICS_UPDATED)); | |
| 246 event->params.SetInteger("audio_bytes_decoded", | |
| 247 last_statistics_.audio_bytes_decoded); | |
| 248 event->params.SetInteger("video_bytes_decoded", | |
| 249 last_statistics_.video_bytes_decoded); | |
| 250 event->params.SetInteger("video_frames_decoded", | |
| 251 last_statistics_.video_frames_decoded); | |
| 252 event->params.SetInteger("video_frames_dropped", | |
| 253 last_statistics_.video_frames_dropped); | |
| 254 AddEvent(event.Pass()); | |
| 255 stats_update_pending_ = false; | |
| 256 } | |
| 257 | |
| 258 } //namespace media | 216 } //namespace media |
| OLD | NEW |