| 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 // Implementation of Pipeline & PipelineStatusNotification (an async-to-sync | 5 // Implementation of Pipeline & PipelineStatusNotification (an async-to-sync |
| 6 // callback adapter). | 6 // callback adapter). |
| 7 | 7 |
| 8 #ifndef MEDIA_BASE_PIPELINE_IMPL_H_ | 8 #ifndef MEDIA_BASE_PIPELINE_IMPL_H_ |
| 9 #define MEDIA_BASE_PIPELINE_IMPL_H_ | 9 #define MEDIA_BASE_PIPELINE_IMPL_H_ |
| 10 | 10 |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 19 #include "base/synchronization/condition_variable.h" | 19 #include "base/synchronization/condition_variable.h" |
| 20 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
| 21 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
| 22 #include "base/time.h" | 22 #include "base/time.h" |
| 23 #include "media/base/clock.h" | 23 #include "media/base/clock.h" |
| 24 #include "media/base/composite_filter.h" | 24 #include "media/base/composite_filter.h" |
| 25 #include "media/base/demuxer.h" | 25 #include "media/base/demuxer.h" |
| 26 #include "media/base/filter_host.h" | 26 #include "media/base/filter_host.h" |
| 27 #include "media/base/pipeline.h" | 27 #include "media/base/pipeline.h" |
| 28 #include "ui/gfx/size.h" |
| 28 | 29 |
| 29 namespace media { | 30 namespace media { |
| 30 | 31 |
| 31 class MediaLog; | 32 class MediaLog; |
| 32 | 33 |
| 33 // Adapter for using asynchronous Pipeline methods in code that wants to run | 34 // Adapter for using asynchronous Pipeline methods in code that wants to run |
| 34 // synchronously. To use, construct an instance of this class and pass the | 35 // synchronously. To use, construct an instance of this class and pass the |
| 35 // |Callback()| to the Pipeline method requiring a callback. Then Wait() for | 36 // |Callback()| to the Pipeline method requiring a callback. Then Wait() for |
| 36 // the callback to get fired and call status() to see what the callback's | 37 // the callback to get fired and call status() to see what the callback's |
| 37 // argument was. This object is for one-time use; call |Callback()| exactly | 38 // argument was. This object is for one-time use; call |Callback()| exactly |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // If any error ever happens, this object will transition to the "Error" state | 95 // If any error ever happens, this object will transition to the "Error" state |
| 95 // from any state. If Stop() is ever called, this object will transition to | 96 // from any state. If Stop() is ever called, this object will transition to |
| 96 // "Stopped" state. | 97 // "Stopped" state. |
| 97 class MEDIA_EXPORT PipelineImpl : public Pipeline, public FilterHost { | 98 class MEDIA_EXPORT PipelineImpl : public Pipeline, public FilterHost { |
| 98 public: | 99 public: |
| 99 explicit PipelineImpl(MessageLoop* message_loop, MediaLog* media_log); | 100 explicit PipelineImpl(MessageLoop* message_loop, MediaLog* media_log); |
| 100 | 101 |
| 101 // Pipeline implementation. | 102 // Pipeline implementation. |
| 102 virtual void Init(const PipelineStatusCB& ended_callback, | 103 virtual void Init(const PipelineStatusCB& ended_callback, |
| 103 const PipelineStatusCB& error_callback, | 104 const PipelineStatusCB& error_callback, |
| 104 const PipelineStatusCB& network_callback); | 105 const PipelineStatusCB& network_callback) OVERRIDE; |
| 105 virtual bool Start(FilterCollection* filter_collection, | 106 virtual bool Start(FilterCollection* filter_collection, |
| 106 const std::string& uri, | 107 const std::string& uri, |
| 107 const PipelineStatusCB& start_callback); | 108 const PipelineStatusCB& start_callback) OVERRIDE; |
| 108 virtual void Stop(const PipelineStatusCB& stop_callback); | 109 virtual void Stop(const PipelineStatusCB& stop_callback) OVERRIDE; |
| 109 virtual void Seek(base::TimeDelta time, | 110 virtual void Seek(base::TimeDelta time, |
| 110 const PipelineStatusCB& seek_callback); | 111 const PipelineStatusCB& seek_callback) OVERRIDE; |
| 111 virtual bool IsRunning() const; | 112 virtual bool IsRunning() const OVERRIDE; |
| 112 virtual bool IsInitialized() const; | 113 virtual bool IsInitialized() const OVERRIDE; |
| 113 virtual bool IsNetworkActive() const; | 114 virtual bool IsNetworkActive() const OVERRIDE; |
| 114 virtual bool HasAudio() const; | 115 virtual bool HasAudio() const OVERRIDE; |
| 115 virtual bool HasVideo() const; | 116 virtual bool HasVideo() const OVERRIDE; |
| 116 virtual float GetPlaybackRate() const; | 117 virtual float GetPlaybackRate() const OVERRIDE; |
| 117 virtual void SetPlaybackRate(float playback_rate); | 118 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; |
| 118 virtual float GetVolume() const; | 119 virtual float GetVolume() const OVERRIDE; |
| 119 virtual void SetVolume(float volume); | 120 virtual void SetVolume(float volume) OVERRIDE; |
| 120 virtual void SetPreload(Preload preload); | 121 virtual void SetPreload(Preload preload) OVERRIDE; |
| 121 virtual base::TimeDelta GetCurrentTime() const; | 122 virtual base::TimeDelta GetCurrentTime() const OVERRIDE; |
| 122 virtual base::TimeDelta GetBufferedTime(); | 123 virtual base::TimeDelta GetBufferedTime() OVERRIDE; |
| 123 virtual base::TimeDelta GetMediaDuration() const; | 124 virtual base::TimeDelta GetMediaDuration() const OVERRIDE; |
| 124 virtual int64 GetBufferedBytes() const; | 125 virtual int64 GetBufferedBytes() const OVERRIDE; |
| 125 virtual int64 GetTotalBytes() const; | 126 virtual int64 GetTotalBytes() const OVERRIDE; |
| 126 virtual void GetVideoSize(size_t* width_out, size_t* height_out) const; | 127 virtual void GetNaturalVideoSize(gfx::Size* out_size) const OVERRIDE; |
| 127 virtual bool IsStreaming() const; | 128 virtual bool IsStreaming() const OVERRIDE; |
| 128 virtual bool IsLoaded() const; | 129 virtual bool IsLoaded() const OVERRIDE; |
| 129 virtual PipelineStatistics GetStatistics() const; | 130 virtual PipelineStatistics GetStatistics() const OVERRIDE; |
| 130 | 131 |
| 131 void SetClockForTesting(Clock* clock); | 132 void SetClockForTesting(Clock* clock); |
| 132 | 133 |
| 133 private: | 134 private: |
| 134 friend class MediaLog; | 135 friend class MediaLog; |
| 135 | 136 |
| 136 // Pipeline states, as described above. | 137 // Pipeline states, as described above. |
| 137 enum State { | 138 enum State { |
| 138 kCreated, | 139 kCreated, |
| 139 kInitDemuxer, | 140 kInitDemuxer, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 void FinishInitialization(); | 184 void FinishInitialization(); |
| 184 | 185 |
| 185 // Returns true if the given state is one that transitions to a new state | 186 // Returns true if the given state is one that transitions to a new state |
| 186 // after iterating through each filter. | 187 // after iterating through each filter. |
| 187 static bool TransientState(State state); | 188 static bool TransientState(State state); |
| 188 | 189 |
| 189 // Given the current state, returns the next state. | 190 // Given the current state, returns the next state. |
| 190 State FindNextState(State current); | 191 State FindNextState(State current); |
| 191 | 192 |
| 192 // FilterHost implementation. | 193 // FilterHost implementation. |
| 193 virtual void SetError(PipelineStatus error); | 194 virtual void SetError(PipelineStatus error) OVERRIDE; |
| 194 virtual base::TimeDelta GetTime() const; | 195 virtual base::TimeDelta GetTime() const OVERRIDE; |
| 195 virtual base::TimeDelta GetDuration() const; | 196 virtual base::TimeDelta GetDuration() const OVERRIDE; |
| 196 virtual void SetTime(base::TimeDelta time); | 197 virtual void SetTime(base::TimeDelta time) OVERRIDE; |
| 197 virtual void SetDuration(base::TimeDelta duration); | 198 virtual void SetDuration(base::TimeDelta duration) OVERRIDE; |
| 198 virtual void SetBufferedTime(base::TimeDelta buffered_time); | 199 virtual void SetBufferedTime(base::TimeDelta buffered_time) OVERRIDE; |
| 199 virtual void SetTotalBytes(int64 total_bytes); | 200 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; |
| 200 virtual void SetBufferedBytes(int64 buffered_bytes); | 201 virtual void SetBufferedBytes(int64 buffered_bytes) OVERRIDE; |
| 201 virtual void SetVideoSize(size_t width, size_t height); | 202 virtual void SetNaturalVideoSize(const gfx::Size& size) OVERRIDE; |
| 202 virtual void SetStreaming(bool streamed); | 203 virtual void SetStreaming(bool streamed) OVERRIDE; |
| 203 virtual void SetLoaded(bool loaded); | 204 virtual void SetLoaded(bool loaded) OVERRIDE; |
| 204 virtual void SetNetworkActivity(bool network_activity); | 205 virtual void SetNetworkActivity(bool network_activity) OVERRIDE; |
| 205 virtual void NotifyEnded(); | 206 virtual void NotifyEnded() OVERRIDE; |
| 206 virtual void DisableAudioRenderer(); | 207 virtual void DisableAudioRenderer() OVERRIDE; |
| 207 virtual void SetCurrentReadPosition(int64 offset); | 208 virtual void SetCurrentReadPosition(int64 offset) OVERRIDE; |
| 208 virtual int64 GetCurrentReadPosition(); | 209 virtual int64 GetCurrentReadPosition() OVERRIDE; |
| 209 | 210 |
| 210 // Callback executed by filters upon completing initialization. | 211 // Callback executed by filters upon completing initialization. |
| 211 void OnFilterInitialize(); | 212 void OnFilterInitialize(); |
| 212 | 213 |
| 213 // Callback executed by filters upon completing Play(), Pause(), or Stop(). | 214 // Callback executed by filters upon completing Play(), Pause(), or Stop(). |
| 214 void OnFilterStateTransition(); | 215 void OnFilterStateTransition(); |
| 215 | 216 |
| 216 // Callback executed by filters upon completing Seek(). | 217 // Callback executed by filters upon completing Seek(). |
| 217 void OnFilterStateTransitionWithStatus(PipelineStatus status); | 218 void OnFilterStateTransitionWithStatus(PipelineStatus status); |
| 218 | 219 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 | 365 |
| 365 // Amount of available buffered data in microseconds. Set by filters. | 366 // Amount of available buffered data in microseconds. Set by filters. |
| 366 base::TimeDelta buffered_time_; | 367 base::TimeDelta buffered_time_; |
| 367 | 368 |
| 368 // Amount of available buffered data. Set by filters. | 369 // Amount of available buffered data. Set by filters. |
| 369 int64 buffered_bytes_; | 370 int64 buffered_bytes_; |
| 370 | 371 |
| 371 // Total size of the media. Set by filters. | 372 // Total size of the media. Set by filters. |
| 372 int64 total_bytes_; | 373 int64 total_bytes_; |
| 373 | 374 |
| 374 // Video width and height. Set by filters. | 375 // Video's natural width and height. Set by filters. |
| 375 size_t video_width_; | 376 gfx::Size natural_size_; |
| 376 size_t video_height_; | |
| 377 | 377 |
| 378 // Sets by the filters to indicate whether the data source is a streaming | 378 // Sets by the filters to indicate whether the data source is a streaming |
| 379 // source. | 379 // source. |
| 380 bool streaming_; | 380 bool streaming_; |
| 381 | 381 |
| 382 // Sets by the filters to indicate whether the data source is a fully | 382 // Sets by the filters to indicate whether the data source is a fully |
| 383 // loaded source. | 383 // loaded source. |
| 384 bool loaded_; | 384 bool loaded_; |
| 385 | 385 |
| 386 // Sets by the filters to indicate whether network is active. | 386 // Sets by the filters to indicate whether network is active. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 PipelineStatistics statistics_; | 479 PipelineStatistics statistics_; |
| 480 | 480 |
| 481 FRIEND_TEST_ALL_PREFIXES(PipelineImplTest, GetBufferedTime); | 481 FRIEND_TEST_ALL_PREFIXES(PipelineImplTest, GetBufferedTime); |
| 482 | 482 |
| 483 DISALLOW_COPY_AND_ASSIGN(PipelineImpl); | 483 DISALLOW_COPY_AND_ASSIGN(PipelineImpl); |
| 484 }; | 484 }; |
| 485 | 485 |
| 486 } // namespace media | 486 } // namespace media |
| 487 | 487 |
| 488 #endif // MEDIA_BASE_PIPELINE_IMPL_H_ | 488 #endif // MEDIA_BASE_PIPELINE_IMPL_H_ |
| OLD | NEW |