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

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

Issue 8763010: Replace AudioDecoder::ProduceAudioSamples/ConsumeAudioSamples with read callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix mac tests Created 9 years 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
« no previous file with comments | « media/filters/audio_renderer_algorithm_base.cc ('k') | media/filters/audio_renderer_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // 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
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // Subclasses should return true if they were able to initialize, false 50 // Subclasses should return true if they were able to initialize, false
51 // otherwise. 51 // otherwise.
52 virtual bool OnInitialize(int bits_per_channel, 52 virtual bool OnInitialize(int bits_per_channel,
53 ChannelLayout channel_layout, 53 ChannelLayout channel_layout,
54 int sample_rate) = 0; 54 int sample_rate) = 0;
55 55
56 // Called by Stop(). Subclasses should perform any necessary cleanup during 56 // Called by Stop(). Subclasses should perform any necessary cleanup during
57 // this time, such as stopping any running threads. 57 // this time, such as stopping any running threads.
58 virtual void OnStop() = 0; 58 virtual void OnStop() = 0;
59 59
60 // Called when a AudioDecoder completes decoding and decrements 60 // Callback from the audio decoder delivering decoded audio samples.
61 // |pending_reads_|. 61 void DecodedAudioReady(scoped_refptr<Buffer> buffer);
62 virtual void ConsumeAudioSamples(scoped_refptr<Buffer> buffer_in);
63 62
64 // Fills the given buffer with audio data by delegating to its |algorithm_|. 63 // Fills the given buffer with audio data by delegating to its |algorithm_|.
65 // FillBuffer() also takes care of updating the clock. Returns the number of 64 // FillBuffer() also takes care of updating the clock. Returns the number of
66 // bytes copied into |dest|, which may be less than or equal to |len|. 65 // bytes copied into |dest|, which may be less than or equal to |len|.
67 // 66 //
68 // If this method is returns less bytes than |len| (including zero), it could 67 // If this method is returns less bytes than |len| (including zero), it could
69 // be a sign that the pipeline is stalled or unable to stream the data fast 68 // be a sign that the pipeline is stalled or unable to stream the data fast
70 // enough. In such scenarios, the callee should zero out unused portions 69 // enough. In such scenarios, the callee should zero out unused portions
71 // of their buffer to playback silence. 70 // of their buffer to playback silence.
72 // 71 //
(...skipping 12 matching lines...) Expand all
85 uint32 FillBuffer(uint8* dest, 84 uint32 FillBuffer(uint8* dest,
86 uint32 len, 85 uint32 len,
87 const base::TimeDelta& playback_delay, 86 const base::TimeDelta& playback_delay,
88 bool buffers_empty); 87 bool buffers_empty);
89 88
90 // Get/Set the playback rate of |algorithm_|. 89 // Get/Set the playback rate of |algorithm_|.
91 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; 90 virtual void SetPlaybackRate(float playback_rate) OVERRIDE;
92 virtual float GetPlaybackRate(); 91 virtual float GetPlaybackRate();
93 92
94 private: 93 private:
94 friend class AudioRendererBaseTest;
95
95 // Helper method that schedules an asynchronous read from the decoder and 96 // Helper method that schedules an asynchronous read from the decoder and
96 // increments |pending_reads_|. 97 // increments |pending_reads_|.
97 // 98 //
98 // Safe to call from any thread. 99 // Safe to call from any thread.
99 void ScheduleRead_Locked(); 100 void ScheduleRead_Locked();
100 101
101 // Audio decoder. 102 // Audio decoder.
102 scoped_refptr<AudioDecoder> decoder_; 103 scoped_refptr<AudioDecoder> decoder_;
103 104
104 // Algorithm for scaling audio. 105 // Algorithm for scaling audio.
105 scoped_ptr<AudioRendererAlgorithmBase> algorithm_; 106 scoped_ptr<AudioRendererAlgorithmBase> algorithm_;
106 107
107 base::Lock lock_; 108 base::Lock lock_;
108 109
109 // Simple state tracking variable. 110 // Simple state tracking variable.
110 enum State { 111 enum State {
111 kUninitialized, 112 kUninitialized,
112 kPaused, 113 kPaused,
113 kSeeking, 114 kSeeking,
114 kPlaying, 115 kPlaying,
115 kStopped, 116 kStopped,
116 kError, 117 kError,
117 kUnderflow, 118 kUnderflow,
118 kRebuffering, 119 kRebuffering,
119 }; 120 };
120 State state_; 121 State state_;
121 122
123 // Keep track of our outstanding read to |decoder_|.
124 bool pending_read_;
125
122 // Keeps track of whether we received and rendered the end of stream buffer. 126 // Keeps track of whether we received and rendered the end of stream buffer.
123 bool recieved_end_of_stream_; 127 bool recieved_end_of_stream_;
124 bool rendered_end_of_stream_; 128 bool rendered_end_of_stream_;
125 129
126 // Keeps track of our pending reads. We *must* have no pending reads before
127 // executing the pause callback, otherwise we breach the contract that all
128 // filters are idling.
129 //
130 // We use size_t since we compare against std::deque::size().
131 size_t pending_reads_;
132
133 // Audio time at end of last call to FillBuffer(). 130 // Audio time at end of last call to FillBuffer().
134 // TODO(ralphl): Update this value after seeking. 131 // TODO(ralphl): Update this value after seeking.
135 base::TimeDelta last_fill_buffer_time_; 132 base::TimeDelta last_fill_buffer_time_;
136 133
137 // Filter callbacks. 134 // Filter callbacks.
138 base::Closure pause_callback_; 135 base::Closure pause_callback_;
139 FilterStatusCB seek_cb_; 136 FilterStatusCB seek_cb_;
140 137
141 base::Closure underflow_callback_; 138 base::Closure underflow_callback_;
142 139
143 base::TimeDelta seek_timestamp_; 140 base::TimeDelta seek_timestamp_;
144 141
142 AudioDecoder::ReadCB read_cb_;
143
145 DISALLOW_COPY_AND_ASSIGN(AudioRendererBase); 144 DISALLOW_COPY_AND_ASSIGN(AudioRendererBase);
146 }; 145 };
147 146
148 } // namespace media 147 } // namespace media
149 148
150 #endif // MEDIA_FILTERS_AUDIO_RENDERER_BASE_H_ 149 #endif // MEDIA_FILTERS_AUDIO_RENDERER_BASE_H_
OLDNEW
« no previous file with comments | « media/filters/audio_renderer_algorithm_base.cc ('k') | media/filters/audio_renderer_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698