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

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

Issue 1236543007: MSE: Log buffered audio splice generation to media-internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 <algorithm>
8
7 #include "base/atomic_sequence_num.h" 9 #include "base/atomic_sequence_num.h"
8 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
9 #include "base/values.h" 11 #include "base/values.h"
10 12
11 namespace media { 13 namespace media {
12 14
13 // A count of all MediaLogs created in the current process. Used to generate 15 // A count of all MediaLogs created in the current process. Used to generate
14 // unique IDs. 16 // unique IDs.
15 static base::StaticAtomicSequenceNumber g_media_log_count; 17 static base::StaticAtomicSequenceNumber g_media_log_count;
16 18
19 MediaLog::AudioSpliceStatistics::AudioSpliceStatistics()
20 : count_(0),
21 degenerate_count_(0),
22 total_duration_(0.0),
23 min_duration_(0.0),
24 max_duration_(0.0) {
25 }
26
27 MediaLog::AudioSpliceStatistics::AudioSpliceStatistics(int count,
28 int degenerate_count,
29 double total_duration,
30 double min_duration,
31 double max_duration)
32 : count_(count),
33 degenerate_count_(degenerate_count),
34 total_duration_(total_duration),
35 min_duration_(min_duration),
36 max_duration_(max_duration) {
37 }
38
39 void MediaLog::AudioSpliceStatistics::OnSplice(double duration) {
40 if (count_) {
41 min_duration_ = std::min(min_duration_, duration);
42 max_duration_ = std::max(max_duration_, duration);
43 total_duration_ += duration;
44 } else {
45 min_duration_ = max_duration_ = total_duration_ = duration;
46 }
47
48 count_++;
49 }
50
51 void MediaLog::AudioSpliceStatistics::OnDegenerateSplice() {
52 degenerate_count_++;
53 }
54
55 double MediaLog::AudioSpliceStatistics::AverageDuration() const {
56 return (count_ > 0) ? total_duration_ / count_ : 0.0;
57 }
58
17 std::string MediaLog::MediaLogLevelToString(MediaLogLevel level) { 59 std::string MediaLog::MediaLogLevelToString(MediaLogLevel level) {
18 switch (level) { 60 switch (level) {
19 case MEDIALOG_ERROR: 61 case MEDIALOG_ERROR:
20 return "error"; 62 return "error";
21 case MEDIALOG_INFO: 63 case MEDIALOG_INFO:
22 return "info"; 64 return "info";
23 case MEDIALOG_DEBUG: 65 case MEDIALOG_DEBUG:
24 return "debug"; 66 return "debug";
25 } 67 }
26 NOTREACHED(); 68 NOTREACHED();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 case MediaLogEvent::TOTAL_BYTES_SET: 107 case MediaLogEvent::TOTAL_BYTES_SET:
66 return "TOTAL_BYTES_SET"; 108 return "TOTAL_BYTES_SET";
67 case MediaLogEvent::NETWORK_ACTIVITY_SET: 109 case MediaLogEvent::NETWORK_ACTIVITY_SET:
68 return "NETWORK_ACTIVITY_SET"; 110 return "NETWORK_ACTIVITY_SET";
69 case MediaLogEvent::ENDED: 111 case MediaLogEvent::ENDED:
70 return "ENDED"; 112 return "ENDED";
71 case MediaLogEvent::TEXT_ENDED: 113 case MediaLogEvent::TEXT_ENDED:
72 return "TEXT_ENDED"; 114 return "TEXT_ENDED";
73 case MediaLogEvent::BUFFERED_EXTENTS_CHANGED: 115 case MediaLogEvent::BUFFERED_EXTENTS_CHANGED:
74 return "BUFFERED_EXTENTS_CHANGED"; 116 return "BUFFERED_EXTENTS_CHANGED";
117 case MediaLogEvent::BUFFERED_AUDIO_SPLICE_STATISTICS_CHANGED:
118 return "BUFFERED_AUDIO_SPLICE_STATISTICS_CHANGED";
75 case MediaLogEvent::MEDIA_ERROR_LOG_ENTRY: 119 case MediaLogEvent::MEDIA_ERROR_LOG_ENTRY:
76 return "MEDIA_ERROR_LOG_ENTRY"; 120 return "MEDIA_ERROR_LOG_ENTRY";
77 case MediaLogEvent::MEDIA_INFO_LOG_ENTRY: 121 case MediaLogEvent::MEDIA_INFO_LOG_ENTRY:
78 return "MEDIA_INFO_LOG_ENTRY"; 122 return "MEDIA_INFO_LOG_ENTRY";
79 case MediaLogEvent::MEDIA_DEBUG_LOG_ENTRY: 123 case MediaLogEvent::MEDIA_DEBUG_LOG_ENTRY:
80 return "MEDIA_DEBUG_LOG_ENTRY"; 124 return "MEDIA_DEBUG_LOG_ENTRY";
81 case MediaLogEvent::PROPERTY_CHANGE: 125 case MediaLogEvent::PROPERTY_CHANGE:
82 return "PROPERTY_CHANGE"; 126 return "PROPERTY_CHANGE";
83 } 127 }
84 NOTREACHED(); 128 NOTREACHED();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 scoped_ptr<MediaLogEvent> event( 264 scoped_ptr<MediaLogEvent> event(
221 CreateEvent(MediaLogEvent::BUFFERED_EXTENTS_CHANGED)); 265 CreateEvent(MediaLogEvent::BUFFERED_EXTENTS_CHANGED));
222 // These values are headed to JS where there is no int64 so we use a double 266 // These values are headed to JS where there is no int64 so we use a double
223 // and accept loss of precision above 2^53 bytes (8 Exabytes). 267 // and accept loss of precision above 2^53 bytes (8 Exabytes).
224 event->params.SetDouble("buffer_start", start); 268 event->params.SetDouble("buffer_start", start);
225 event->params.SetDouble("buffer_current", current); 269 event->params.SetDouble("buffer_current", current);
226 event->params.SetDouble("buffer_end", end); 270 event->params.SetDouble("buffer_end", end);
227 return event.Pass(); 271 return event.Pass();
228 } 272 }
229 273
274 scoped_ptr<MediaLogEvent> MediaLog::CreateBufferedSpliceStatisticsChangedEvent(
275 const AudioSpliceStatistics& statistics) {
276 scoped_ptr<MediaLogEvent> event(
277 CreateEvent(MediaLogEvent::BUFFERED_AUDIO_SPLICE_STATISTICS_CHANGED));
278 event->params.SetInteger("audio_splice_count", statistics.count());
279 event->params.SetInteger("audio_splice_degenerate_count",
280 statistics.degenerate_count());
281 event->params.SetDouble("audio_splice_duration_average",
282 statistics.AverageDuration());
283 event->params.SetDouble("audio_splice_duration_min",
284 statistics.min_duration());
285 event->params.SetDouble("audio_splice_duration_max",
286 statistics.max_duration());
287 return event.Pass();
288 }
289
230 void MediaLog::AddLogEvent(MediaLogLevel level, const std::string& message) { 290 void MediaLog::AddLogEvent(MediaLogLevel level, const std::string& message) {
231 scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogLevelToEventType(level))); 291 scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogLevelToEventType(level)));
232 event->params.SetString(MediaLogLevelToString(level), message); 292 event->params.SetString(MediaLogLevelToString(level), message);
233 AddEvent(event.Pass()); 293 AddEvent(event.Pass());
234 } 294 }
235 295
236 void MediaLog::SetStringProperty( 296 void MediaLog::SetStringProperty(
237 const std::string& key, const std::string& value) { 297 const std::string& key, const std::string& value) {
238 scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::PROPERTY_CHANGE)); 298 scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::PROPERTY_CHANGE));
239 event->params.SetString(key, value); 299 event->params.SetString(key, value);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 const scoped_refptr<MediaLog>& media_log) 335 const scoped_refptr<MediaLog>& media_log)
276 : level_(level), media_log_(media_log) { 336 : level_(level), media_log_(media_log) {
277 DCHECK(media_log_.get()); 337 DCHECK(media_log_.get());
278 } 338 }
279 339
280 LogHelper::~LogHelper() { 340 LogHelper::~LogHelper() {
281 media_log_->AddLogEvent(level_, stream_.str()); 341 media_log_->AddLogEvent(level_, stream_.str());
282 } 342 }
283 343
284 } //namespace media 344 } //namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698