| 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> |
| 9 #include <string> |
| 10 |
| 8 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 10 #include "media/base/media_export.h" | 13 #include "media/base/media_export.h" |
| 11 #include "media/base/media_log_event.h" | 14 #include "media/base/media_log_event.h" |
| 12 #include "media/base/pipeline.h" | 15 #include "media/base/pipeline.h" |
| 13 #include "media/base/pipeline_status.h" | 16 #include "media/base/pipeline_status.h" |
| 14 | 17 |
| 15 namespace media { | 18 namespace media { |
| 16 | 19 |
| 20 // Indicates a string should be added to the log. |
| 21 // First parameter - The string to add to the log. |
| 22 typedef base::Callback<void(const std::string&)> LogCB; |
| 23 |
| 24 // Helper class to make it easier to use log_cb like DVLOG(). |
| 25 class LogHelper { |
| 26 public: |
| 27 LogHelper(const LogCB& Log_cb); |
| 28 ~LogHelper(); |
| 29 |
| 30 std::ostream& stream() { return stream_; } |
| 31 |
| 32 private: |
| 33 LogCB log_cb_; |
| 34 std::stringstream stream_; |
| 35 }; |
| 36 |
| 37 #define MEDIA_LOG(log_cb) LogHelper(log_cb).stream() |
| 38 |
| 17 class MEDIA_EXPORT MediaLog : public base::RefCountedThreadSafe<MediaLog> { | 39 class MEDIA_EXPORT MediaLog : public base::RefCountedThreadSafe<MediaLog> { |
| 18 public: | 40 public: |
| 19 // Convert various enums to strings. | 41 // Convert various enums to strings. |
| 20 static const char* EventTypeToString(MediaLogEvent::Type type); | 42 static const char* EventTypeToString(MediaLogEvent::Type type); |
| 21 static const char* PipelineStatusToString(PipelineStatus); | 43 static const char* PipelineStatusToString(PipelineStatus); |
| 22 | 44 |
| 23 MediaLog(); | 45 MediaLog(); |
| 24 | 46 |
| 25 // Add an event to this log. Overriden by inheritors to actually do something | 47 // Add an event to this log. Overriden by inheritors to actually do something |
| 26 // with it. | 48 // with it. |
| 27 virtual void AddEvent(scoped_ptr<MediaLogEvent> event); | 49 virtual void AddEvent(scoped_ptr<MediaLogEvent> event); |
| 28 | 50 |
| 29 // Helper methods to create events and their parameters. | 51 // Helper methods to create events and their parameters. |
| 30 scoped_ptr<MediaLogEvent> CreateEvent(MediaLogEvent::Type type); | 52 scoped_ptr<MediaLogEvent> CreateEvent(MediaLogEvent::Type type); |
| 31 scoped_ptr<MediaLogEvent> CreateBooleanEvent( | 53 scoped_ptr<MediaLogEvent> CreateBooleanEvent( |
| 32 MediaLogEvent::Type type, const char* property, bool value); | 54 MediaLogEvent::Type type, const char* property, bool value); |
| 33 scoped_ptr<MediaLogEvent> CreateStringEvent( | 55 scoped_ptr<MediaLogEvent> CreateStringEvent( |
| 34 MediaLogEvent::Type type, const char* property, const std::string& value); | 56 MediaLogEvent::Type type, const char* property, const std::string& value); |
| 35 scoped_ptr<MediaLogEvent> CreateTimeEvent( | 57 scoped_ptr<MediaLogEvent> CreateTimeEvent( |
| 36 MediaLogEvent::Type type, const char* property, base::TimeDelta value); | 58 MediaLogEvent::Type type, const char* property, base::TimeDelta value); |
| 37 scoped_ptr<MediaLogEvent> CreateLoadEvent(const std::string& url); | 59 scoped_ptr<MediaLogEvent> CreateLoadEvent(const std::string& url); |
| 38 scoped_ptr<MediaLogEvent> CreateSeekEvent(float seconds); | 60 scoped_ptr<MediaLogEvent> CreateSeekEvent(float seconds); |
| 39 scoped_ptr<MediaLogEvent> CreatePipelineStateChangedEvent( | 61 scoped_ptr<MediaLogEvent> CreatePipelineStateChangedEvent( |
| 40 Pipeline::State state); | 62 Pipeline::State state); |
| 41 scoped_ptr<MediaLogEvent> CreatePipelineErrorEvent(PipelineStatus error); | 63 scoped_ptr<MediaLogEvent> CreatePipelineErrorEvent(PipelineStatus error); |
| 42 scoped_ptr<MediaLogEvent> CreateVideoSizeSetEvent( | 64 scoped_ptr<MediaLogEvent> CreateVideoSizeSetEvent( |
| 43 size_t width, size_t height); | 65 size_t width, size_t height); |
| 44 scoped_ptr<MediaLogEvent> CreateBufferedExtentsChangedEvent( | 66 scoped_ptr<MediaLogEvent> CreateBufferedExtentsChangedEvent( |
| 45 size_t start, size_t current, size_t end); | 67 size_t start, size_t current, size_t end); |
| 68 scoped_ptr<MediaLogEvent> CreateMediaSourceErrorEvent( |
| 69 const std::string& error); |
| 46 | 70 |
| 47 protected: | 71 protected: |
| 48 friend class base::RefCountedThreadSafe<MediaLog>; | 72 friend class base::RefCountedThreadSafe<MediaLog>; |
| 49 virtual ~MediaLog(); | 73 virtual ~MediaLog(); |
| 50 | 74 |
| 51 private: | 75 private: |
| 52 // A unique (to this process) id for this MediaLog. | 76 // A unique (to this process) id for this MediaLog. |
| 53 int32 id_; | 77 int32 id_; |
| 54 | 78 |
| 55 DISALLOW_COPY_AND_ASSIGN(MediaLog); | 79 DISALLOW_COPY_AND_ASSIGN(MediaLog); |
| 56 }; | 80 }; |
| 57 | 81 |
| 58 } // namespace media | 82 } // namespace media |
| 59 | 83 |
| 60 #endif // MEDIA_BASE_MEDIA_LOG_H_ | 84 #endif // MEDIA_BASE_MEDIA_LOG_H_ |
| OLD | NEW |