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

Side by Side Diff: media/audio/pulse/pulse_input.cc

Issue 621093002: Clear the FIFO when calling input stream::Stop() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed alsa Created 6 years, 2 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
« no previous file with comments | « media/audio/mac/audio_low_latency_input_mac.cc ('k') | no next file » | 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) 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
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
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
OLDNEW
« no previous file with comments | « media/audio/mac/audio_low_latency_input_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698