| 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/audio_decoder.h" | 26 #include "media/base/audio_decoder.h" |
| 26 #include "media/base/buffers.h" | 27 #include "media/base/buffers.h" |
| 27 #include "media/base/filters.h" | 28 #include "media/base/filters.h" |
| 28 #include "media/filters/audio_renderer_algorithm_base.h" | 29 #include "media/filters/audio_renderer_algorithm_base.h" |
| 29 | 30 |
| 30 namespace media { | 31 namespace media { |
| 31 | 32 |
| 32 class MEDIA_EXPORT AudioRendererBase : public AudioRenderer { | 33 class MEDIA_EXPORT AudioRendererBase : public AudioRenderer { |
| 33 public: | 34 public: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 45 virtual void Initialize(const scoped_refptr<AudioDecoder>& decoder, | 46 virtual void Initialize(const scoped_refptr<AudioDecoder>& decoder, |
| 46 const PipelineStatusCB& init_callback, | 47 const PipelineStatusCB& init_callback, |
| 47 const base::Closure& underflow_callback, | 48 const base::Closure& underflow_callback, |
| 48 const AudioTimeCB& audio_time_cb) OVERRIDE; | 49 const AudioTimeCB& audio_time_cb) OVERRIDE; |
| 49 virtual bool HasEnded() OVERRIDE; | 50 virtual bool HasEnded() OVERRIDE; |
| 50 virtual void ResumeAfterUnderflow(bool buffer_more_audio) OVERRIDE; | 51 virtual void ResumeAfterUnderflow(bool buffer_more_audio) OVERRIDE; |
| 51 | 52 |
| 52 protected: | 53 protected: |
| 53 FRIEND_TEST_ALL_PREFIXES(AudioRendererBaseTest, EndOfStream); | 54 FRIEND_TEST_ALL_PREFIXES(AudioRendererBaseTest, EndOfStream); |
| 54 FRIEND_TEST_ALL_PREFIXES(AudioRendererBaseTest, Underflow_EndOfStream); | 55 FRIEND_TEST_ALL_PREFIXES(AudioRendererBaseTest, Underflow_EndOfStream); |
| 56 FRIEND_TEST_ALL_PREFIXES(AudioRendererImplTest, OnRenderEndOfStream); |
| 57 FRIEND_TEST_ALL_PREFIXES(AudioRendererImplTest, OnRenderEndOfStreamStopped); |
| 55 | 58 |
| 56 // Subclasses should return true if they were able to initialize, false | 59 // Subclasses should return true if they were able to initialize, false |
| 57 // otherwise. | 60 // otherwise. |
| 58 virtual bool OnInitialize(int bits_per_channel, | 61 virtual bool OnInitialize(int bits_per_channel, |
| 59 ChannelLayout channel_layout, | 62 ChannelLayout channel_layout, |
| 60 int sample_rate) = 0; | 63 int sample_rate) = 0; |
| 61 | 64 |
| 62 // Called by Stop(). Subclasses should perform any necessary cleanup during | 65 // Called by Stop(). Subclasses should perform any necessary cleanup during |
| 63 // this time, such as stopping any running threads. | 66 // this time, such as stopping any running threads. |
| 64 virtual void OnStop() = 0; | 67 virtual void OnStop() = 0; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 92 // OnRenderEndOfStream() that calls SignalEndOfStream() when all the hardware | 95 // OnRenderEndOfStream() that calls SignalEndOfStream() when all the hardware |
| 93 // buffers become empty (i.e. when all the data written to the device has | 96 // buffers become empty (i.e. when all the data written to the device has |
| 94 // been played). | 97 // been played). |
| 95 // | 98 // |
| 96 // Safe to call on any thread. | 99 // Safe to call on any thread. |
| 97 uint32 FillBuffer(uint8* dest, | 100 uint32 FillBuffer(uint8* dest, |
| 98 uint32 len, | 101 uint32 len, |
| 99 const base::TimeDelta& playback_delay); | 102 const base::TimeDelta& playback_delay); |
| 100 | 103 |
| 101 // Called by OnRenderEndOfStream() or some callback scheduled by derived class | 104 // Called by OnRenderEndOfStream() or some callback scheduled by derived class |
| 102 // to signal end of stream. | 105 // to signal end of stream. Made virtual so tests can override. |
| 103 void SignalEndOfStream(); | 106 virtual void SignalEndOfStream(); |
| 104 | 107 |
| 105 // Get/Set the playback rate of |algorithm_|. | 108 // Get/Set the playback rate of |algorithm_|. |
| 106 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; | 109 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; |
| 107 virtual float GetPlaybackRate(); | 110 virtual float GetPlaybackRate(); |
| 108 | 111 |
| 112 // Accessor used by tests. Made protected, not private, |
| 113 // so tests for derived classes can use it. |
| 114 void set_recieved_end_of_stream(bool recieved_end_of_stream) { |
| 115 recieved_end_of_stream_ = recieved_end_of_stream; |
| 116 } |
| 117 |
| 109 private: | 118 private: |
| 110 friend class AudioRendererBaseTest; | 119 friend class AudioRendererBaseTest; |
| 111 | 120 |
| 112 // Helper method that schedules an asynchronous read from the decoder and | 121 // Helper method that schedules an asynchronous read from the decoder and |
| 113 // increments |pending_reads_|. | 122 // increments |pending_reads_|. |
| 114 // | 123 // |
| 115 // Safe to call from any thread. | 124 // Safe to call from any thread. |
| 116 void ScheduleRead_Locked(); | 125 void ScheduleRead_Locked(); |
| 117 | 126 |
| 118 // Returns true if the data in the buffer is all before | 127 // Returns true if the data in the buffer is all before |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 base::TimeDelta seek_timestamp_; | 171 base::TimeDelta seek_timestamp_; |
| 163 | 172 |
| 164 AudioDecoder::ReadCB read_cb_; | 173 AudioDecoder::ReadCB read_cb_; |
| 165 | 174 |
| 166 DISALLOW_COPY_AND_ASSIGN(AudioRendererBase); | 175 DISALLOW_COPY_AND_ASSIGN(AudioRendererBase); |
| 167 }; | 176 }; |
| 168 | 177 |
| 169 } // namespace media | 178 } // namespace media |
| 170 | 179 |
| 171 #endif // MEDIA_FILTERS_AUDIO_RENDERER_BASE_H_ | 180 #endif // MEDIA_FILTERS_AUDIO_RENDERER_BASE_H_ |
| OLD | NEW |