1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_BASE_MEDIA_LOG_H_
#define MEDIA_BASE_MEDIA_LOG_H_
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <sstream>
#include <string>
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "media/base/buffering_state.h"
#include "media/base/media_export.h"
#include "media/base/media_log_event.h"
#include "media/base/pipeline_impl.h"
#include "media/base/pipeline_status.h"
namespace media {
class MEDIA_EXPORT MediaLog : public base::RefCountedThreadSafe<MediaLog> {
public:
enum MediaLogLevel {
MEDIALOG_ERROR,
MEDIALOG_INFO,
MEDIALOG_DEBUG,
};
// Convert various enums to strings.
static std::string MediaLogLevelToString(MediaLogLevel level);
static MediaLogEvent::Type MediaLogLevelToEventType(MediaLogLevel level);
static std::string EventTypeToString(MediaLogEvent::Type type);
static std::string PipelineStatusToString(PipelineStatus status);
static std::string BufferingStateToString(BufferingState state);
static std::string MediaEventToLogString(const MediaLogEvent& event);
MediaLog();
// Add an event to this log. Overriden by inheritors to actually do something
// with it.
virtual void AddEvent(std::unique_ptr<MediaLogEvent> event);
// Retrieve an error message, if any.
virtual std::string GetLastErrorMessage();
// Records the domain and registry of the current frame security origin to a
// Rappor privacy-preserving metric. See:
// https://www.chromium.org/developers/design-documents/rappor
virtual void RecordRapporWithSecurityOrigin(const std::string& metric);
// Helper methods to create events and their parameters.
std::unique_ptr<MediaLogEvent> CreateEvent(MediaLogEvent::Type type);
std::unique_ptr<MediaLogEvent> CreateBooleanEvent(MediaLogEvent::Type type,
const std::string& property,
bool value);
std::unique_ptr<MediaLogEvent> CreateStringEvent(MediaLogEvent::Type type,
const std::string& property,
const std::string& value);
std::unique_ptr<MediaLogEvent> CreateTimeEvent(MediaLogEvent::Type type,
const std::string& property,
base::TimeDelta value);
std::unique_ptr<MediaLogEvent> CreateLoadEvent(const std::string& url);
std::unique_ptr<MediaLogEvent> CreateSeekEvent(float seconds);
std::unique_ptr<MediaLogEvent> CreatePipelineStateChangedEvent(
PipelineImpl::State state);
std::unique_ptr<MediaLogEvent> CreatePipelineErrorEvent(PipelineStatus error);
std::unique_ptr<MediaLogEvent> CreateVideoSizeSetEvent(size_t width,
size_t height);
std::unique_ptr<MediaLogEvent> CreateBufferedExtentsChangedEvent(
int64_t start,
int64_t current,
int64_t end);
std::unique_ptr<MediaLogEvent> CreateBufferingStateChangedEvent(
const std::string& property,
BufferingState state);
// Report a log message at the specified log level.
void AddLogEvent(MediaLogLevel level, const std::string& message);
// Report a property change without an accompanying event.
void SetStringProperty(const std::string& key, const std::string& value);
void SetDoubleProperty(const std::string& key, double value);
void SetBooleanProperty(const std::string& key, bool value);
// Histogram names used for reporting; also double as MediaLog key names.
static const char kWatchTimeAudioAll[];
static const char kWatchTimeAudioMse[];
static const char kWatchTimeAudioEme[];
static const char kWatchTimeAudioSrc[];
static const char kWatchTimeAudioBattery[];
static const char kWatchTimeAudioAc[];
static const char kWatchTimeAudioVideoAll[];
static const char kWatchTimeAudioVideoMse[];
static const char kWatchTimeAudioVideoEme[];
static const char kWatchTimeAudioVideoSrc[];
static const char kWatchTimeAudioVideoBattery[];
static const char kWatchTimeAudioVideoAc[];
// Markers which signify the watch time should be finalized immediately.
static const char kWatchTimeFinalize[];
static const char kWatchTimeFinalizePower[];
protected:
friend class base::RefCountedThreadSafe<MediaLog>;
virtual ~MediaLog();
private:
// A unique (to this process) id for this MediaLog.
int32_t id_;
DISALLOW_COPY_AND_ASSIGN(MediaLog);
};
// Helper class to make it easier to use MediaLog like DVLOG().
class MEDIA_EXPORT LogHelper {
public:
LogHelper(MediaLog::MediaLogLevel level,
const scoped_refptr<MediaLog>& media_log);
~LogHelper();
std::ostream& stream() { return stream_; }
private:
MediaLog::MediaLogLevel level_;
const scoped_refptr<MediaLog> media_log_;
std::stringstream stream_;
};
// Provides a stringstream to collect a log entry to pass to the provided
// MediaLog at the requested level.
#define MEDIA_LOG(level, media_log) \
LogHelper((MediaLog::MEDIALOG_##level), (media_log)).stream()
// Logs only while |count| < |max|, increments |count| for each log, and warns
// in the log if |count| has just reached |max|.
// Multiple short-circuit evaluations are involved in this macro:
// 1) LAZY_STREAM avoids wasteful MEDIA_LOG and evaluation of subsequent stream
// arguments if |count| is >= |max|, and
// 2) the |condition| given to LAZY_STREAM itself short-circuits to prevent
// incrementing |count| beyond |max|.
// Note that LAZY_STREAM guarantees exactly one evaluation of |condition|, so
// |count| will be incremented at most once each time this macro runs.
// The "|| true" portion of |condition| lets logging occur correctly when
// |count| < |max| and |count|++ is 0.
// TODO(wolenetz,chcunningham): Consider using a helper class instead of a macro
// to improve readability.
#define LIMITED_MEDIA_LOG(level, media_log, count, max) \
LAZY_STREAM(MEDIA_LOG(level, media_log), \
(count) < (max) && ((count)++ || true)) \
<< (((count) == (max)) ? "(Log limit reached. Further similar entries " \
"may be suppressed): " \
: "")
} // namespace media
#endif // MEDIA_BASE_MEDIA_LOG_H_
|