| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 11 #include "media/base/media_export.h" | 11 #include "media/base/media_export.h" |
| 12 #include "media/base/media_log_event.h" | 12 #include "media/base/media_log_event.h" |
| 13 #include "media/base/pipeline_impl.h" | 13 #include "media/base/pipeline_impl.h" |
| 14 #include "media/base/pipeline_status.h" | 14 #include "media/base/pipeline_status.h" |
| 15 | 15 |
| 16 namespace media { | 16 namespace media { |
| 17 | 17 |
| 18 class MEDIA_EXPORT MediaLog : public base::RefCountedThreadSafe<MediaLog> { | 18 class MEDIA_EXPORT MediaLog : public base::RefCountedThreadSafe<MediaLog> { |
| 19 public: | 19 public: |
| 20 // Convert various enums to strings. | 20 // Convert various enums to strings. |
| 21 static const char* EventTypeToString(MediaLogEvent::Type type); | 21 static const char* EventTypeToString(MediaLogEvent::Type type); |
| 22 static const char* PipelineStateToString(PipelineImpl::State); | 22 static const char* PipelineStateToString(PipelineImpl::State); |
| 23 static const char* PipelineStatusToString(PipelineStatus); | 23 static const char* PipelineStatusToString(PipelineStatus); |
| 24 | 24 |
| 25 MediaLog(); | 25 MediaLog(); |
| 26 | 26 |
| 27 // Add an event to this log. Overriden by inheritors to actually do something | 27 // Add an event to this log. Overriden by inheritors to actually do something |
| 28 // with it. | 28 // with it. |
| 29 // Takes ownership of |event|. | 29 virtual void AddEvent(scoped_ptr<MediaLogEvent> event); |
| 30 virtual void AddEvent(MediaLogEvent* event); | |
| 31 | 30 |
| 32 // Helper methods to create events and their parameters. | 31 // Helper methods to create events and their parameters. |
| 33 MediaLogEvent* CreateEvent(MediaLogEvent::Type type); | 32 scoped_ptr<MediaLogEvent> CreateEvent(MediaLogEvent::Type type); |
| 34 MediaLogEvent* CreateBooleanEvent(MediaLogEvent::Type type, | 33 scoped_ptr<MediaLogEvent> CreateBooleanEvent( |
| 35 const char* property, bool value); | 34 MediaLogEvent::Type type, const char* property, bool value); |
| 36 MediaLogEvent* CreateIntegerEvent(MediaLogEvent::Type type, | 35 scoped_ptr<MediaLogEvent> CreateIntegerEvent( |
| 37 const char* property, int64 value); | 36 MediaLogEvent::Type type, const char* property, int64 value); |
| 38 MediaLogEvent* CreateTimeEvent(MediaLogEvent::Type type, | 37 scoped_ptr<MediaLogEvent> CreateTimeEvent( |
| 39 const char* property, base::TimeDelta value); | 38 MediaLogEvent::Type type, const char* property, base::TimeDelta value); |
| 40 MediaLogEvent* CreateLoadEvent(const std::string& url); | 39 scoped_ptr<MediaLogEvent> CreateLoadEvent(const std::string& url); |
| 41 MediaLogEvent* CreateSeekEvent(float seconds); | 40 scoped_ptr<MediaLogEvent> CreateSeekEvent(float seconds); |
| 42 MediaLogEvent* CreatePipelineStateChangedEvent(PipelineImpl::State state); | 41 scoped_ptr<MediaLogEvent> CreatePipelineStateChangedEvent( |
| 43 MediaLogEvent* CreatePipelineErrorEvent(PipelineStatus error); | 42 PipelineImpl::State state); |
| 44 MediaLogEvent* CreateVideoSizeSetEvent(size_t width, size_t height); | 43 scoped_ptr<MediaLogEvent> CreatePipelineErrorEvent(PipelineStatus error); |
| 45 MediaLogEvent* CreateBufferedExtentsChangedEvent(size_t start, size_t current, | 44 scoped_ptr<MediaLogEvent> CreateVideoSizeSetEvent( |
| 46 size_t end); | 45 size_t width, size_t height); |
| 46 scoped_ptr<MediaLogEvent> CreateBufferedExtentsChangedEvent( |
| 47 size_t start, size_t current, size_t end); |
| 47 | 48 |
| 48 // Called when the pipeline statistics have been updated. | 49 // Called when the pipeline statistics have been updated. |
| 49 // This gets called every frame, so we send the most recent stats after 500ms. | 50 // This gets called every frame, so we send the most recent stats after 500ms. |
| 50 // This function is NOT thread safe. | 51 // This function is NOT thread safe. |
| 51 void QueueStatisticsUpdatedEvent(PipelineStatistics stats); | 52 void QueueStatisticsUpdatedEvent(PipelineStatistics stats); |
| 52 | 53 |
| 53 protected: | 54 protected: |
| 54 friend class base::RefCountedThreadSafe<MediaLog>; | 55 friend class base::RefCountedThreadSafe<MediaLog>; |
| 55 virtual ~MediaLog(); | 56 virtual ~MediaLog(); |
| 56 | 57 |
| 57 private: | 58 private: |
| 58 // Actually add a STATISTICS_UPDATED event. | 59 // Actually add a STATISTICS_UPDATED event. |
| 59 void AddStatisticsUpdatedEvent(); | 60 void AddStatisticsUpdatedEvent(); |
| 60 | 61 |
| 61 // A unique (to this process) id for this MediaLog. | 62 // A unique (to this process) id for this MediaLog. |
| 62 int32 id_; | 63 int32 id_; |
| 63 | 64 |
| 64 // The most recent set of pipeline stats. | 65 // The most recent set of pipeline stats. |
| 65 PipelineStatistics last_statistics_; | 66 PipelineStatistics last_statistics_; |
| 66 bool stats_update_pending_; | 67 bool stats_update_pending_; |
| 67 base::Lock stats_lock_; | 68 base::Lock stats_lock_; |
| 68 | 69 |
| 69 DISALLOW_COPY_AND_ASSIGN(MediaLog); | 70 DISALLOW_COPY_AND_ASSIGN(MediaLog); |
| 70 }; | 71 }; |
| 71 | 72 |
| 72 } // namespace media | 73 } // namespace media |
| 73 | 74 |
| 74 #endif // MEDIA_BASE_MEDIA_LOG_H_ | 75 #endif // MEDIA_BASE_MEDIA_LOG_H_ |
| OLD | NEW |