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 #include "media/audio/pulse/pulse_input.h" | 5 #include "media/audio/pulse/pulse_input.h" |
6 | 6 |
7 #include <pulse/pulseaudio.h> | 7 #include <pulse/pulseaudio.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "media/audio/pulse/audio_manager_pulse.h" | 10 #include "media/audio/pulse/audio_manager_pulse.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 DCHECK(handle_); | 67 DCHECK(handle_); |
68 | 68 |
69 // AGC needs to be started out of the lock. | 69 // AGC needs to be started out of the lock. |
70 StartAgc(); | 70 StartAgc(); |
71 | 71 |
72 AutoPulseLock auto_lock(pa_mainloop_); | 72 AutoPulseLock auto_lock(pa_mainloop_); |
73 | 73 |
74 if (stream_started_) | 74 if (stream_started_) |
75 return; | 75 return; |
76 | 76 |
77 // Clean up the old buffer. | |
78 pa_stream_drop(handle_); | |
79 fifo_.Clear(); | |
80 | |
81 // Start the streaming. | 77 // Start the streaming. |
82 callback_ = callback; | 78 callback_ = callback; |
83 pa_stream_set_read_callback(handle_, &ReadCallback, this); | 79 pa_stream_set_read_callback(handle_, &ReadCallback, this); |
84 pa_stream_readable_size(handle_); | 80 pa_stream_readable_size(handle_); |
85 stream_started_ = true; | 81 stream_started_ = true; |
86 | 82 |
87 pa_operation* operation = pa_stream_cork(handle_, 0, NULL, NULL); | 83 pa_operation* operation = pa_stream_cork(handle_, 0, NULL, NULL); |
88 WaitForOperationCompletion(pa_mainloop_, operation); | 84 WaitForOperationCompletion(pa_mainloop_, operation); |
89 } | 85 } |
90 | 86 |
91 void PulseAudioInputStream::Stop() { | 87 void PulseAudioInputStream::Stop() { |
92 DCHECK(thread_checker_.CalledOnValidThread()); | 88 DCHECK(thread_checker_.CalledOnValidThread()); |
93 AutoPulseLock auto_lock(pa_mainloop_); | 89 AutoPulseLock auto_lock(pa_mainloop_); |
94 if (!stream_started_) | 90 if (!stream_started_) |
95 return; | 91 return; |
96 | 92 |
97 StopAgc(); | 93 StopAgc(); |
98 | 94 |
99 // Set the flag to false to stop filling new data to soundcard. | 95 // Set the flag to false to stop filling new data to soundcard. |
100 stream_started_ = false; | 96 stream_started_ = false; |
101 | 97 |
| 98 // Clean up the old buffer. |
| 99 pa_stream_drop(handle_); |
| 100 fifo_.Clear(); |
| 101 |
102 pa_operation* operation = pa_stream_flush(handle_, | 102 pa_operation* operation = pa_stream_flush(handle_, |
103 &pulse::StreamSuccessCallback, | 103 &pulse::StreamSuccessCallback, |
104 pa_mainloop_); | 104 pa_mainloop_); |
105 WaitForOperationCompletion(pa_mainloop_, operation); | 105 WaitForOperationCompletion(pa_mainloop_, operation); |
106 | 106 |
107 // Stop the stream. | 107 // Stop the stream. |
108 pa_stream_set_read_callback(handle_, NULL, NULL); | 108 pa_stream_set_read_callback(handle_, NULL, NULL); |
109 operation = pa_stream_cork(handle_, 1, &pulse::StreamSuccessCallback, | 109 operation = pa_stream_cork(handle_, 1, &pulse::StreamSuccessCallback, |
110 pa_mainloop_); | 110 pa_mainloop_); |
111 WaitForOperationCompletion(pa_mainloop_, operation); | 111 WaitForOperationCompletion(pa_mainloop_, operation); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 // Sleep 5ms to wait until render consumes the data in order to avoid | 295 // Sleep 5ms to wait until render consumes the data in order to avoid |
296 // back to back OnData() method. | 296 // back to back OnData() method. |
297 if (fifo_.available_blocks()) | 297 if (fifo_.available_blocks()) |
298 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(5)); | 298 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(5)); |
299 } | 299 } |
300 | 300 |
301 pa_threaded_mainloop_signal(pa_mainloop_, 0); | 301 pa_threaded_mainloop_signal(pa_mainloop_, 0); |
302 } | 302 } |
303 | 303 |
304 } // namespace media | 304 } // namespace media |
OLD | NEW |