OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ | 5 #ifndef CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ |
6 #define CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ | 6 #define CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ |
7 | 7 |
8 #include <alsa/asoundlib.h> | 8 #include <alsa/asoundlib.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
| 11 #include <memory> |
11 #include <string> | 12 #include <string> |
12 #include <vector> | 13 #include <vector> |
13 | 14 |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | |
17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
19 #include "base/timer/timer.h" | 19 #include "base/timer/timer.h" |
20 #include "chromecast/media/cma/backend/alsa/media_pipeline_backend_alsa.h" | 20 #include "chromecast/media/cma/backend/alsa/media_pipeline_backend_alsa.h" |
21 #include "chromecast/public/cast_media_shlib.h" | 21 #include "chromecast/public/cast_media_shlib.h" |
22 | 22 |
23 namespace media { | 23 namespace media { |
24 class AudioBus; | 24 class AudioBus; |
25 } // namespace media | 25 } // namespace media |
26 | 26 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 bool empty() const { return inputs_.empty(); } | 121 bool empty() const { return inputs_.empty(); } |
122 State state() const { return state_; } | 122 State state() const { return state_; } |
123 int num_output_channels() const { return num_output_channels_; } | 123 int num_output_channels() const { return num_output_channels_; } |
124 | 124 |
125 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner() const { | 125 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner() const { |
126 return mixer_task_runner_; | 126 return mixer_task_runner_; |
127 } | 127 } |
128 | 128 |
129 // Adds an input to the mixer. The input will live at least until | 129 // Adds an input to the mixer. The input will live at least until |
130 // RemoveInput(input) is called. Can be called on any thread. | 130 // RemoveInput(input) is called. Can be called on any thread. |
131 void AddInput(scoped_ptr<InputQueue> input); | 131 void AddInput(std::unique_ptr<InputQueue> input); |
132 // Instructs the mixer to remove an input. The input should not be referenced | 132 // Instructs the mixer to remove an input. The input should not be referenced |
133 // after this is called. Can be called on any thread. | 133 // after this is called. Can be called on any thread. |
134 void RemoveInput(InputQueue* input); | 134 void RemoveInput(InputQueue* input); |
135 | 135 |
136 // Attempts to write some frames of audio to ALSA. Must only be called on the | 136 // Attempts to write some frames of audio to ALSA. Must only be called on the |
137 // mixer thread. | 137 // mixer thread. |
138 void OnFramesQueued(); | 138 void OnFramesQueued(); |
139 | 139 |
140 void SetAlsaWrapperForTest(scoped_ptr<AlsaWrapper> alsa_wrapper); | 140 void SetAlsaWrapperForTest(std::unique_ptr<AlsaWrapper> alsa_wrapper); |
141 void WriteFramesForTest(); // Can be called on any thread. | 141 void WriteFramesForTest(); // Can be called on any thread. |
142 void ClearInputsForTest(); // Removes all inputs. | 142 void ClearInputsForTest(); // Removes all inputs. |
143 | 143 |
144 void AddLoopbackAudioObserver( | 144 void AddLoopbackAudioObserver( |
145 CastMediaShlib::LoopbackAudioObserver* observer); | 145 CastMediaShlib::LoopbackAudioObserver* observer); |
146 | 146 |
147 void RemoveLoopbackAudioObserver( | 147 void RemoveLoopbackAudioObserver( |
148 CastMediaShlib::LoopbackAudioObserver* observer); | 148 CastMediaShlib::LoopbackAudioObserver* observer); |
149 | 149 |
150 protected: | 150 protected: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 void CheckClose(); | 184 void CheckClose(); |
185 | 185 |
186 void WriteFrames(); | 186 void WriteFrames(); |
187 bool TryWriteFrames(); | 187 bool TryWriteFrames(); |
188 void WriteMixedPcm(const ::media::AudioBus& mixed, int frames); | 188 void WriteMixedPcm(const ::media::AudioBus& mixed, int frames); |
189 void UpdateRenderingDelay(int newly_pushed_frames); | 189 void UpdateRenderingDelay(int newly_pushed_frames); |
190 ssize_t BytesPerOutputFormatSample(); | 190 ssize_t BytesPerOutputFormatSample(); |
191 | 191 |
192 static bool single_threaded_for_test_; | 192 static bool single_threaded_for_test_; |
193 | 193 |
194 scoped_ptr<AlsaWrapper> alsa_; | 194 std::unique_ptr<AlsaWrapper> alsa_; |
195 scoped_ptr<base::Thread> mixer_thread_; | 195 std::unique_ptr<base::Thread> mixer_thread_; |
196 scoped_refptr<base::SingleThreadTaskRunner> mixer_task_runner_; | 196 scoped_refptr<base::SingleThreadTaskRunner> mixer_task_runner_; |
197 | 197 |
198 unsigned int fixed_output_samples_per_second_; | 198 unsigned int fixed_output_samples_per_second_; |
199 int requested_output_samples_per_second_; | 199 int requested_output_samples_per_second_; |
200 int output_samples_per_second_; | 200 int output_samples_per_second_; |
201 snd_pcm_t* pcm_; | 201 snd_pcm_t* pcm_; |
202 snd_pcm_hw_params_t* pcm_hw_params_; | 202 snd_pcm_hw_params_t* pcm_hw_params_; |
203 snd_pcm_status_t* pcm_status_; | 203 snd_pcm_status_t* pcm_status_; |
204 snd_pcm_format_t pcm_format_; | 204 snd_pcm_format_t pcm_format_; |
205 | 205 |
(...skipping 11 matching lines...) Expand all Loading... |
217 | 217 |
218 ScopedVector<InputQueue> inputs_; | 218 ScopedVector<InputQueue> inputs_; |
219 ScopedVector<InputQueue> ignored_inputs_; | 219 ScopedVector<InputQueue> ignored_inputs_; |
220 MediaPipelineBackendAlsa::RenderingDelay rendering_delay_; | 220 MediaPipelineBackendAlsa::RenderingDelay rendering_delay_; |
221 // Buffer to write final interleaved data before sending to snd_pcm_writei(). | 221 // Buffer to write final interleaved data before sending to snd_pcm_writei(). |
222 std::vector<uint8_t> interleaved_; | 222 std::vector<uint8_t> interleaved_; |
223 | 223 |
224 // Buffers that hold audio data while it is mixed, before it is passed to the | 224 // Buffers that hold audio data while it is mixed, before it is passed to the |
225 // ALSA layer. These are kept as members of this class to minimize copies and | 225 // ALSA layer. These are kept as members of this class to minimize copies and |
226 // allocations. | 226 // allocations. |
227 scoped_ptr<::media::AudioBus> temp_; | 227 std::unique_ptr<::media::AudioBus> temp_; |
228 scoped_ptr<::media::AudioBus> mixed_; | 228 std::unique_ptr<::media::AudioBus> mixed_; |
229 | 229 |
230 scoped_ptr<base::Timer> retry_write_frames_timer_; | 230 std::unique_ptr<base::Timer> retry_write_frames_timer_; |
231 | 231 |
232 int check_close_timeout_; | 232 int check_close_timeout_; |
233 scoped_ptr<base::Timer> check_close_timer_; | 233 std::unique_ptr<base::Timer> check_close_timer_; |
234 | 234 |
235 std::vector<CastMediaShlib::LoopbackAudioObserver*> loopback_observers_; | 235 std::vector<CastMediaShlib::LoopbackAudioObserver*> loopback_observers_; |
236 | 236 |
237 DISALLOW_COPY_AND_ASSIGN(StreamMixerAlsa); | 237 DISALLOW_COPY_AND_ASSIGN(StreamMixerAlsa); |
238 }; | 238 }; |
239 | 239 |
240 } // namespace media | 240 } // namespace media |
241 } // namespace chromecast | 241 } // namespace chromecast |
242 | 242 |
243 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ | 243 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ |
OLD | NEW |