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 #ifndef MEDIA_BASE_MEDIA_LOG_H_ | 5 #ifndef MEDIA_BASE_MEDIA_LOG_H_ |
6 #define MEDIA_BASE_MEDIA_LOG_H_ | 6 #define MEDIA_BASE_MEDIA_LOG_H_ |
7 | 7 |
8 #include <sstream> | 8 #include <sstream> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "media/base/media_export.h" | 14 #include "media/base/media_export.h" |
15 #include "media/base/media_log_event.h" | 15 #include "media/base/media_log_event.h" |
16 #include "media/base/pipeline.h" | 16 #include "media/base/pipeline.h" |
17 #include "media/base/pipeline_status.h" | 17 #include "media/base/pipeline_status.h" |
18 | 18 |
19 namespace media { | 19 namespace media { |
20 | 20 |
21 // Indicates a string should be added to the log. | |
22 // First parameter - The string to add to the log. | |
23 typedef base::Callback<void(const std::string&)> LogCB; | |
24 | |
25 // Helper class to make it easier to use log_cb like DVLOG(). | |
26 class LogHelper { | |
27 public: | |
28 LogHelper(const LogCB& Log_cb); | |
29 ~LogHelper(); | |
30 | |
31 std::ostream& stream() { return stream_; } | |
32 | |
33 private: | |
34 LogCB log_cb_; | |
35 std::stringstream stream_; | |
36 }; | |
37 | |
38 #define MEDIA_LOG(log_cb) LogHelper(log_cb).stream() | |
39 | |
40 // Logs only while count < max. Increments count for each log. Use LAZY_STREAM | |
41 // to avoid wasteful evaluation of subsequent stream arguments. | |
42 #define LIMITED_MEDIA_LOG(log_cb, count, max) \ | |
43 LAZY_STREAM(MEDIA_LOG(log_cb), (count) < (max) && ((count)++ || true)) | |
44 | 21 |
45 class MEDIA_EXPORT MediaLog : public base::RefCountedThreadSafe<MediaLog> { | 22 class MEDIA_EXPORT MediaLog : public base::RefCountedThreadSafe<MediaLog> { |
46 public: | 23 public: |
24 enum MediaLogLevel { | |
25 MEDIALOG_ERROR, | |
26 MEDIALOG_INFO, | |
27 MEDIALOG_DEBUG, | |
28 }; | |
29 | |
47 // Convert various enums to strings. | 30 // Convert various enums to strings. |
31 static std::string MediaLogLevelToString(MediaLogLevel level); | |
48 static std::string EventTypeToString(MediaLogEvent::Type type); | 32 static std::string EventTypeToString(MediaLogEvent::Type type); |
49 static std::string PipelineStatusToString(PipelineStatus status); | 33 static std::string PipelineStatusToString(PipelineStatus status); |
50 | 34 |
51 static std::string MediaEventToLogString(const MediaLogEvent& event); | 35 static std::string MediaEventToLogString(const MediaLogEvent& event); |
52 | 36 |
53 MediaLog(); | 37 MediaLog(); |
54 | 38 |
55 // Add an event to this log. Overriden by inheritors to actually do something | 39 // Add an event to this log. Overriden by inheritors to actually do something |
56 // with it. | 40 // with it. |
57 virtual void AddEvent(scoped_ptr<MediaLogEvent> event); | 41 virtual void AddEvent(scoped_ptr<MediaLogEvent> event); |
(...skipping 10 matching lines...) Expand all Loading... | |
68 base::TimeDelta value); | 52 base::TimeDelta value); |
69 scoped_ptr<MediaLogEvent> CreateLoadEvent(const std::string& url); | 53 scoped_ptr<MediaLogEvent> CreateLoadEvent(const std::string& url); |
70 scoped_ptr<MediaLogEvent> CreateSeekEvent(float seconds); | 54 scoped_ptr<MediaLogEvent> CreateSeekEvent(float seconds); |
71 scoped_ptr<MediaLogEvent> CreatePipelineStateChangedEvent( | 55 scoped_ptr<MediaLogEvent> CreatePipelineStateChangedEvent( |
72 Pipeline::State state); | 56 Pipeline::State state); |
73 scoped_ptr<MediaLogEvent> CreatePipelineErrorEvent(PipelineStatus error); | 57 scoped_ptr<MediaLogEvent> CreatePipelineErrorEvent(PipelineStatus error); |
74 scoped_ptr<MediaLogEvent> CreateVideoSizeSetEvent( | 58 scoped_ptr<MediaLogEvent> CreateVideoSizeSetEvent( |
75 size_t width, size_t height); | 59 size_t width, size_t height); |
76 scoped_ptr<MediaLogEvent> CreateBufferedExtentsChangedEvent( | 60 scoped_ptr<MediaLogEvent> CreateBufferedExtentsChangedEvent( |
77 int64 start, int64 current, int64 end); | 61 int64 start, int64 current, int64 end); |
78 scoped_ptr<MediaLogEvent> CreateMediaSourceErrorEvent( | 62 scoped_ptr<MediaLogEvent> CreateLogEvent(MediaLogLevel level, |
79 const std::string& error); | 63 const std::string& message); |
80 | 64 |
81 // Report a property change without an accompanying event. | 65 // Report a property change without an accompanying event. |
82 void SetStringProperty(const std::string& key, const std::string& value); | 66 void SetStringProperty(const std::string& key, const std::string& value); |
83 void SetIntegerProperty(const std::string& key, int value); | 67 void SetIntegerProperty(const std::string& key, int value); |
84 void SetDoubleProperty(const std::string& key, double value); | 68 void SetDoubleProperty(const std::string& key, double value); |
85 void SetBooleanProperty(const std::string& key, bool value); | 69 void SetBooleanProperty(const std::string& key, bool value); |
86 void SetTimeProperty(const std::string& key, base::TimeDelta value); | 70 void SetTimeProperty(const std::string& key, base::TimeDelta value); |
87 | 71 |
88 protected: | 72 protected: |
89 friend class base::RefCountedThreadSafe<MediaLog>; | 73 friend class base::RefCountedThreadSafe<MediaLog>; |
90 virtual ~MediaLog(); | 74 virtual ~MediaLog(); |
91 | 75 |
92 private: | 76 private: |
93 // A unique (to this process) id for this MediaLog. | 77 // A unique (to this process) id for this MediaLog. |
94 int32 id_; | 78 int32 id_; |
95 | 79 |
96 DISALLOW_COPY_AND_ASSIGN(MediaLog); | 80 DISALLOW_COPY_AND_ASSIGN(MediaLog); |
97 }; | 81 }; |
98 | 82 |
83 // Indicates a string should be added to the log. | |
84 // First parameter - The log level for the string. | |
85 // Second parameter - The string to add to the log. | |
86 typedef base::Callback<void(MediaLog::MediaLogLevel, const std::string&)> LogCB; | |
87 | |
88 // Helper class to make it easier to use log_cb like DVLOG(). | |
89 class LogHelper { | |
90 public: | |
91 LogHelper(const LogCB& log_cb, MediaLog::MediaLogLevel level); | |
92 ~LogHelper(); | |
93 | |
94 std::ostream& stream() { return stream_; } | |
95 | |
96 private: | |
97 LogCB log_cb_; | |
98 MediaLog::MediaLogLevel level_; | |
99 std::stringstream stream_; | |
100 }; | |
101 | |
102 // Provides a stringstream to collect a log entry to pass to the provided | |
103 // LogCB at the requested level. | |
104 #define MEDIA_LOG(log_cb, level) \ | |
DaleCurtis
2015/03/31 00:12:26
Hmm, we typically have the level before any other
wolenetz
2015/03/31 00:30:11
No specific reason. I can change the sequence here
DaleCurtis
2015/03/31 00:34:25
I think the constructor can stay the same if you d
wolenetz
2015/03/31 19:20:22
Done (level first for both the macros and the .cto
| |
105 LogHelper((log_cb), (MediaLog::MEDIALOG_ ## level)).stream() | |
106 | |
107 // Logs only while count < max. Increments count for each log. Use LAZY_STREAM | |
108 // to avoid wasteful evaluation of subsequent stream arguments. | |
109 #define LIMITED_MEDIA_LOG(log_cb, level, count, max) \ | |
110 LAZY_STREAM(MEDIA_LOG(log_cb, level), (count) < (max) && ((count)++ || true)) | |
111 | |
99 } // namespace media | 112 } // namespace media |
100 | 113 |
101 #endif // MEDIA_BASE_MEDIA_LOG_H_ | 114 #endif // MEDIA_BASE_MEDIA_LOG_H_ |
OLD | NEW |