| 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 // AudioRendererBase takes care of the tricky queuing work and provides simple | 5 // AudioRendererBase takes care of the tricky queuing work and provides simple |
| 6 // methods for subclasses to peek and poke at audio data. In addition to | 6 // methods for subclasses to peek and poke at audio data. In addition to |
| 7 // AudioRenderer interface methods this classes doesn't implement, subclasses | 7 // AudioRenderer interface methods this classes doesn't implement, subclasses |
| 8 // must also implement the following methods: | 8 // must also implement the following methods: |
| 9 // OnInitialized | 9 // OnInitialized |
| 10 // OnStop | 10 // OnStop |
| 11 // OnRenderEndOfStream | 11 // OnRenderEndOfStream |
| 12 // | 12 // |
| 13 // The general assumption is that subclasses start a callback-based audio thread | 13 // The general assumption is that subclasses start a callback-based audio thread |
| 14 // which needs to be filled with decoded audio data. AudioDecoderBase provides | 14 // which needs to be filled with decoded audio data. AudioDecoderBase provides |
| 15 // FillBuffer which handles filling the provided buffer, dequeuing items, | 15 // FillBuffer which handles filling the provided buffer, dequeuing items, |
| 16 // scheduling additional reads and updating the clock. In a sense, | 16 // scheduling additional reads and updating the clock. In a sense, |
| 17 // AudioRendererBase is the producer and the subclass is the consumer. | 17 // AudioRendererBase is the producer and the subclass is the consumer. |
| 18 | 18 |
| 19 #ifndef MEDIA_FILTERS_AUDIO_RENDERER_BASE_H_ | 19 #ifndef MEDIA_FILTERS_AUDIO_RENDERER_BASE_H_ |
| 20 #define MEDIA_FILTERS_AUDIO_RENDERER_BASE_H_ | 20 #define MEDIA_FILTERS_AUDIO_RENDERER_BASE_H_ |
| 21 | 21 |
| 22 #include <deque> | 22 #include <deque> |
| 23 | 23 |
| 24 #include "base/gtest_prod_util.h" |
| 24 #include "base/synchronization/lock.h" | 25 #include "base/synchronization/lock.h" |
| 25 #include "media/base/buffers.h" | 26 #include "media/base/buffers.h" |
| 26 #include "media/base/filters.h" | 27 #include "media/base/filters.h" |
| 27 #include "media/filters/audio_renderer_algorithm_base.h" | 28 #include "media/filters/audio_renderer_algorithm_base.h" |
| 28 | 29 |
| 29 namespace media { | 30 namespace media { |
| 30 | 31 |
| 31 class MEDIA_EXPORT AudioRendererBase : public AudioRenderer { | 32 class MEDIA_EXPORT AudioRendererBase : public AudioRenderer { |
| 32 public: | 33 public: |
| 33 AudioRendererBase(); | 34 AudioRendererBase(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 44 virtual void Initialize(AudioDecoder* decoder, | 45 virtual void Initialize(AudioDecoder* decoder, |
| 45 const PipelineStatusCB& init_callback, | 46 const PipelineStatusCB& init_callback, |
| 46 const base::Closure& underflow_callback, | 47 const base::Closure& underflow_callback, |
| 47 const AudioTimeCB& audio_time_cb) OVERRIDE; | 48 const AudioTimeCB& audio_time_cb) OVERRIDE; |
| 48 virtual bool HasEnded() OVERRIDE; | 49 virtual bool HasEnded() OVERRIDE; |
| 49 virtual void ResumeAfterUnderflow(bool buffer_more_audio) OVERRIDE; | 50 virtual void ResumeAfterUnderflow(bool buffer_more_audio) OVERRIDE; |
| 50 | 51 |
| 51 protected: | 52 protected: |
| 52 FRIEND_TEST_ALL_PREFIXES(AudioRendererBaseTest, EndOfStream); | 53 FRIEND_TEST_ALL_PREFIXES(AudioRendererBaseTest, EndOfStream); |
| 53 FRIEND_TEST_ALL_PREFIXES(AudioRendererBaseTest, Underflow_EndOfStream); | 54 FRIEND_TEST_ALL_PREFIXES(AudioRendererBaseTest, Underflow_EndOfStream); |
| 55 FRIEND_TEST_ALL_PREFIXES(AudioRendererImplTest, OnRenderEndOfStream); |
| 54 | 56 |
| 55 // Subclasses should return true if they were able to initialize, false | 57 // Subclasses should return true if they were able to initialize, false |
| 56 // otherwise. | 58 // otherwise. |
| 57 virtual bool OnInitialize(int bits_per_channel, | 59 virtual bool OnInitialize(int bits_per_channel, |
| 58 ChannelLayout channel_layout, | 60 ChannelLayout channel_layout, |
| 59 int sample_rate) = 0; | 61 int sample_rate) = 0; |
| 60 | 62 |
| 61 // Called by Stop(). Subclasses should perform any necessary cleanup during | 63 // Called by Stop(). Subclasses should perform any necessary cleanup during |
| 62 // this time, such as stopping any running threads. | 64 // this time, such as stopping any running threads. |
| 63 virtual void OnStop() = 0; | 65 virtual void OnStop() = 0; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 91 // OnRenderEndOfStream() that calls SignalEndOfStream() when all the hardware | 93 // OnRenderEndOfStream() that calls SignalEndOfStream() when all the hardware |
| 92 // buffers become empty (i.e. when all the data written to the device has | 94 // buffers become empty (i.e. when all the data written to the device has |
| 93 // been played). | 95 // been played). |
| 94 // | 96 // |
| 95 // Safe to call on any thread. | 97 // Safe to call on any thread. |
| 96 uint32 FillBuffer(uint8* dest, | 98 uint32 FillBuffer(uint8* dest, |
| 97 uint32 len, | 99 uint32 len, |
| 98 const base::TimeDelta& playback_delay); | 100 const base::TimeDelta& playback_delay); |
| 99 | 101 |
| 100 // Called by OnRenderEndOfStream() or some callback scheduled by derived class | 102 // Called by OnRenderEndOfStream() or some callback scheduled by derived class |
| 101 // to signal end of stream. | 103 // to signal end of stream. Made virtual so tests can override. |
| 102 void SignalEndOfStream(); | 104 virtual void SignalEndOfStream(); |
| 103 | 105 |
| 104 // Get/Set the playback rate of |algorithm_|. | 106 // Get/Set the playback rate of |algorithm_|. |
| 105 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; | 107 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; |
| 106 virtual float GetPlaybackRate(); | 108 virtual float GetPlaybackRate(); |
| 107 | 109 |
| 110 // Accessor used by tests. Made protected, not private, |
| 111 // so tests for derived classes can use it. |
| 112 void set_recieved_end_of_stream(bool recieved_end_of_stream) { |
| 113 recieved_end_of_stream_ = recieved_end_of_stream; |
| 114 } |
| 115 |
| 108 private: | 116 private: |
| 109 friend class AudioRendererBaseTest; | 117 friend class AudioRendererBaseTest; |
| 110 | 118 |
| 111 // Helper method that schedules an asynchronous read from the decoder and | 119 // Helper method that schedules an asynchronous read from the decoder and |
| 112 // increments |pending_reads_|. | 120 // increments |pending_reads_|. |
| 113 // | 121 // |
| 114 // Safe to call from any thread. | 122 // Safe to call from any thread. |
| 115 void ScheduleRead_Locked(); | 123 void ScheduleRead_Locked(); |
| 116 | 124 |
| 117 // Returns true if the data in the buffer is all before | 125 // Returns true if the data in the buffer is all before |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 base::TimeDelta seek_timestamp_; | 169 base::TimeDelta seek_timestamp_; |
| 162 | 170 |
| 163 AudioDecoder::ReadCB read_cb_; | 171 AudioDecoder::ReadCB read_cb_; |
| 164 | 172 |
| 165 DISALLOW_COPY_AND_ASSIGN(AudioRendererBase); | 173 DISALLOW_COPY_AND_ASSIGN(AudioRendererBase); |
| 166 }; | 174 }; |
| 167 | 175 |
| 168 } // namespace media | 176 } // namespace media |
| 169 | 177 |
| 170 #endif // MEDIA_FILTERS_AUDIO_RENDERER_BASE_H_ | 178 #endif // MEDIA_FILTERS_AUDIO_RENDERER_BASE_H_ |
| OLD | NEW |