| 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/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "media/base/media_export.h" | 14 #include "media/base/media_export.h" |
| 14 #include "media/base/media_log_event.h" | 15 #include "media/base/media_log_event.h" |
| 15 #include "media/base/pipeline.h" | 16 #include "media/base/pipeline.h" |
| 16 #include "media/base/pipeline_status.h" | 17 #include "media/base/pipeline_status.h" |
| 17 | 18 |
| 18 namespace media { | 19 namespace media { |
| 19 | 20 |
| 20 // Indicates a string should be added to the log. | 21 // Indicates a string should be added to the log. |
| 21 // First parameter - The string to add to the log. | 22 // First parameter - The string to add to the log. |
| 22 typedef base::Callback<void(const std::string&)> LogCB; | 23 typedef base::Callback<void(const std::string&)> LogCB; |
| 23 | 24 |
| 24 // Helper class to make it easier to use log_cb like DVLOG(). | 25 // Helper class to make it easier to use log_cb like DVLOG(). |
| 25 class LogHelper { | 26 class LogHelper { |
| 26 public: | 27 public: |
| 27 LogHelper(const LogCB& Log_cb); | 28 LogHelper(const LogCB& Log_cb); |
| 28 ~LogHelper(); | 29 ~LogHelper(); |
| 29 | 30 |
| 30 std::ostream& stream() { return stream_; } | 31 std::ostream& stream() { return stream_; } |
| 31 | 32 |
| 32 private: | 33 private: |
| 33 LogCB log_cb_; | 34 LogCB log_cb_; |
| 34 std::stringstream stream_; | 35 std::stringstream stream_; |
| 35 }; | 36 }; |
| 36 | 37 |
| 37 #define MEDIA_LOG(log_cb) LogHelper(log_cb).stream() | 38 #define MEDIA_LOG(log_cb) LogHelper(log_cb).stream() |
| 38 | 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 |
| 39 class MEDIA_EXPORT MediaLog : public base::RefCountedThreadSafe<MediaLog> { | 45 class MEDIA_EXPORT MediaLog : public base::RefCountedThreadSafe<MediaLog> { |
| 40 public: | 46 public: |
| 41 // Convert various enums to strings. | 47 // Convert various enums to strings. |
| 42 static std::string EventTypeToString(MediaLogEvent::Type type); | 48 static std::string EventTypeToString(MediaLogEvent::Type type); |
| 43 static std::string PipelineStatusToString(PipelineStatus status); | 49 static std::string PipelineStatusToString(PipelineStatus status); |
| 44 | 50 |
| 45 MediaLog(); | 51 MediaLog(); |
| 46 | 52 |
| 47 // Add an event to this log. Overriden by inheritors to actually do something | 53 // Add an event to this log. Overriden by inheritors to actually do something |
| 48 // with it. | 54 // with it. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 private: | 90 private: |
| 85 // A unique (to this process) id for this MediaLog. | 91 // A unique (to this process) id for this MediaLog. |
| 86 int32 id_; | 92 int32 id_; |
| 87 | 93 |
| 88 DISALLOW_COPY_AND_ASSIGN(MediaLog); | 94 DISALLOW_COPY_AND_ASSIGN(MediaLog); |
| 89 }; | 95 }; |
| 90 | 96 |
| 91 } // namespace media | 97 } // namespace media |
| 92 | 98 |
| 93 #endif // MEDIA_BASE_MEDIA_LOG_H_ | 99 #endif // MEDIA_BASE_MEDIA_LOG_H_ |
| OLD | NEW |