Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(618)

Side by Side Diff: media/filters/audio_renderer_base.h

Issue 9347029: Decouple 'give me more data' and 'rendered end of stream' audio callbacks. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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);
55 57
56 // Subclasses should return true if they were able to initialize, false 58 // Subclasses should return true if they were able to initialize, false
57 // otherwise. 59 // otherwise.
58 virtual bool OnInitialize(int bits_per_channel, 60 virtual bool OnInitialize(int bits_per_channel,
59 ChannelLayout channel_layout, 61 ChannelLayout channel_layout,
60 int sample_rate) = 0; 62 int sample_rate) = 0;
61 63
62 // Called by Stop(). Subclasses should perform any necessary cleanup during 64 // Called by Stop(). Subclasses should perform any necessary cleanup during
63 // this time, such as stopping any running threads. 65 // this time, such as stopping any running threads.
64 virtual void OnStop() = 0; 66 virtual void OnStop() = 0;
(...skipping 27 matching lines...) Expand all
92 // OnRenderEndOfStream() that calls SignalEndOfStream() when all the hardware 94 // OnRenderEndOfStream() that calls SignalEndOfStream() when all the hardware
93 // buffers become empty (i.e. when all the data written to the device has 95 // buffers become empty (i.e. when all the data written to the device has
94 // been played). 96 // been played).
95 // 97 //
96 // Safe to call on any thread. 98 // Safe to call on any thread.
97 uint32 FillBuffer(uint8* dest, 99 uint32 FillBuffer(uint8* dest,
98 uint32 len, 100 uint32 len,
99 const base::TimeDelta& playback_delay); 101 const base::TimeDelta& playback_delay);
100 102
101 // Called by OnRenderEndOfStream() or some callback scheduled by derived class 103 // Called by OnRenderEndOfStream() or some callback scheduled by derived class
102 // to signal end of stream. 104 // to signal end of stream. Made virtual so tests can override.
103 void SignalEndOfStream(); 105 virtual void SignalEndOfStream();
104 106
105 // Get/Set the playback rate of |algorithm_|. 107 // Get/Set the playback rate of |algorithm_|.
106 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; 108 virtual void SetPlaybackRate(float playback_rate) OVERRIDE;
107 virtual float GetPlaybackRate(); 109 virtual float GetPlaybackRate();
108 110
111 // Accessor used by tests. Made protected, not private,
112 // so tests for derived classes can use it.
113 void set_recieved_end_of_stream(bool recieved_end_of_stream) {
114 recieved_end_of_stream_ = recieved_end_of_stream;
115 }
116
109 private: 117 private:
110 friend class AudioRendererBaseTest; 118 friend class AudioRendererBaseTest;
111 119
112 // Helper method that schedules an asynchronous read from the decoder and 120 // Helper method that schedules an asynchronous read from the decoder and
113 // increments |pending_reads_|. 121 // increments |pending_reads_|.
114 // 122 //
115 // Safe to call from any thread. 123 // Safe to call from any thread.
116 void ScheduleRead_Locked(); 124 void ScheduleRead_Locked();
117 125
118 // Returns true if the data in the buffer is all before 126 // Returns true if the data in the buffer is all before
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 base::TimeDelta seek_timestamp_; 170 base::TimeDelta seek_timestamp_;
163 171
164 AudioDecoder::ReadCB read_cb_; 172 AudioDecoder::ReadCB read_cb_;
165 173
166 DISALLOW_COPY_AND_ASSIGN(AudioRendererBase); 174 DISALLOW_COPY_AND_ASSIGN(AudioRendererBase);
167 }; 175 };
168 176
169 } // namespace media 177 } // namespace media
170 178
171 #endif // MEDIA_FILTERS_AUDIO_RENDERER_BASE_H_ 179 #endif // MEDIA_FILTERS_AUDIO_RENDERER_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698