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

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

Issue 129793012: Implement hook to change audio output device for PulseAudio. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix build error. Created 6 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
« no previous file with comments | « media/audio/pulse/pulse_util.h ('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_util.h" 5 #include "media/audio/pulse/pulse_util.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "media/audio/audio_manager_base.h" 9 #include "media/audio/audio_manager_base.h"
10 #include "media/audio/audio_parameters.h" 10 #include "media/audio/audio_parameters.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 pa_threaded_mainloop_wait(mainloop); 198 pa_threaded_mainloop_wait(mainloop);
199 } 199 }
200 200
201 return true; 201 return true;
202 } 202 }
203 203
204 bool CreateOutputStream(pa_threaded_mainloop** mainloop, 204 bool CreateOutputStream(pa_threaded_mainloop** mainloop,
205 pa_context** context, 205 pa_context** context,
206 pa_stream** stream, 206 pa_stream** stream,
207 const AudioParameters& params, 207 const AudioParameters& params,
208 const std::string& device_id,
208 pa_stream_notify_cb_t stream_callback, 209 pa_stream_notify_cb_t stream_callback,
209 pa_stream_request_cb_t write_callback, 210 pa_stream_request_cb_t write_callback,
210 void* user_data) { 211 void* user_data) {
211 DCHECK(!*mainloop); 212 DCHECK(!*mainloop);
212 DCHECK(!*context); 213 DCHECK(!*context);
213 214
214 *mainloop = pa_threaded_mainloop_new(); 215 *mainloop = pa_threaded_mainloop_new();
215 RETURN_ON_FAILURE(*mainloop, "Failed to create PulseAudio main loop."); 216 RETURN_ON_FAILURE(*mainloop, "Failed to create PulseAudio main loop.");
216 217
217 pa_mainloop_api* pa_mainloop_api = pa_threaded_mainloop_get_api(*mainloop); 218 pa_mainloop_api* pa_mainloop_api = pa_threaded_mainloop_get_api(*mainloop);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 pa_buffer_attributes.minreq = params.GetBytesPerBuffer(); 281 pa_buffer_attributes.minreq = params.GetBytesPerBuffer();
281 pa_buffer_attributes.prebuf = static_cast<uint32_t>(-1); 282 pa_buffer_attributes.prebuf = static_cast<uint32_t>(-1);
282 pa_buffer_attributes.tlength = params.GetBytesPerBuffer() * 3; 283 pa_buffer_attributes.tlength = params.GetBytesPerBuffer() * 3;
283 pa_buffer_attributes.fragsize = static_cast<uint32_t>(-1); 284 pa_buffer_attributes.fragsize = static_cast<uint32_t>(-1);
284 285
285 // Connect playback stream. Like pa_buffer_attr, the pa_stream_flags have a 286 // Connect playback stream. Like pa_buffer_attr, the pa_stream_flags have a
286 // huge impact on the performance of the stream and were chosen through trial 287 // huge impact on the performance of the stream and were chosen through trial
287 // and error. 288 // and error.
288 RETURN_ON_FAILURE( 289 RETURN_ON_FAILURE(
289 pa_stream_connect_playback( 290 pa_stream_connect_playback(
290 *stream, NULL, &pa_buffer_attributes, 291 *stream,
292 device_id == AudioManagerBase::kDefaultDeviceId ?
293 NULL : device_id.c_str(),
294 &pa_buffer_attributes,
291 static_cast<pa_stream_flags_t>( 295 static_cast<pa_stream_flags_t>(
292 PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_ADJUST_LATENCY | 296 PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_ADJUST_LATENCY |
293 PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_NOT_MONOTONIC | 297 PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_NOT_MONOTONIC |
294 PA_STREAM_START_CORKED), 298 PA_STREAM_START_CORKED),
295 NULL, NULL) == 0, 299 NULL,
300 NULL) == 0,
296 "pa_stream_connect_playback FAILED "); 301 "pa_stream_connect_playback FAILED ");
297 302
298 // Wait for the stream to be ready. 303 // Wait for the stream to be ready.
299 while (true) { 304 while (true) {
300 pa_stream_state_t stream_state = pa_stream_get_state(*stream); 305 pa_stream_state_t stream_state = pa_stream_get_state(*stream);
301 RETURN_ON_FAILURE( 306 RETURN_ON_FAILURE(
302 PA_STREAM_IS_GOOD(stream_state), "Invalid PulseAudio stream state"); 307 PA_STREAM_IS_GOOD(stream_state), "Invalid PulseAudio stream state");
303 if (stream_state == PA_STREAM_READY) 308 if (stream_state == PA_STREAM_READY)
304 break; 309 break;
305 pa_threaded_mainloop_wait(*mainloop); 310 pa_threaded_mainloop_wait(*mainloop);
306 } 311 }
307 312
308 return true; 313 return true;
309 } 314 }
310 315
311 #undef RETURN_ON_FAILURE 316 #undef RETURN_ON_FAILURE
312 317
313 } // namespace pulse 318 } // namespace pulse
314 319
315 } // namespace media 320 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/pulse/pulse_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698