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

Unified Diff: media/audio/pulse/pulse_util.cc

Issue 1711823004: Let default device in PulseAudio be the system default device (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: latest Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« media/audio/pulse/pulse_output.cc ('K') | « media/audio/pulse/pulse_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/pulse/pulse_util.cc
diff --git a/media/audio/pulse/pulse_util.cc b/media/audio/pulse/pulse_util.cc
index 5044fa4d26eb4ab76dce0811433a8fb11d298299..7d4d964192b51e5e48a90f800452982afc20f515 100644
--- a/media/audio/pulse/pulse_util.cc
+++ b/media/audio/pulse/pulse_util.cc
@@ -170,7 +170,7 @@ bool CreateInputStream(pa_threaded_mainloop* mainloop,
void* user_data) {
DCHECK(mainloop);
DCHECK(context);
-
+ DCHECK_NE(device_id, AudioManagerBase::kDefaultDeviceId);
// Set sample specifications.
pa_sample_spec sample_specifications;
sample_specifications.format = BitsToPASampleFormat(
@@ -211,12 +211,8 @@ bool CreateInputStream(pa_threaded_mainloop* mainloop,
PA_STREAM_ADJUST_LATENCY |
PA_STREAM_START_CORKED;
RETURN_ON_FAILURE(
- pa_stream_connect_record(
- *stream,
- device_id == AudioManagerBase::kDefaultDeviceId ?
- NULL : device_id.c_str(),
- &buffer_attributes,
- static_cast<pa_stream_flags_t>(flags)) == 0,
+ pa_stream_connect_record(*stream, device_id.c_str(), &buffer_attributes,
+ static_cast<pa_stream_flags_t>(flags)) == 0,
"pa_stream_connect_record FAILED ");
// Wait for the stream to be ready.
@@ -232,8 +228,8 @@ bool CreateInputStream(pa_threaded_mainloop* mainloop,
return true;
}
-bool CreateOutputStream(pa_threaded_mainloop** mainloop,
- pa_context** context,
+bool CreateOutputStream(pa_threaded_mainloop* mainloop,
+ pa_context* context,
pa_stream** stream,
const AudioParameters& params,
const std::string& device_id,
@@ -241,42 +237,9 @@ bool CreateOutputStream(pa_threaded_mainloop** mainloop,
pa_stream_notify_cb_t stream_callback,
pa_stream_request_cb_t write_callback,
void* user_data) {
- DCHECK(!*mainloop);
- DCHECK(!*context);
-
- *mainloop = pa_threaded_mainloop_new();
- RETURN_ON_FAILURE(*mainloop, "Failed to create PulseAudio main loop.");
-
- pa_mainloop_api* pa_mainloop_api = pa_threaded_mainloop_get_api(*mainloop);
- *context = pa_context_new(pa_mainloop_api,
- app_name.empty() ? "Chromium" : app_name.c_str());
- RETURN_ON_FAILURE(*context, "Failed to create PulseAudio context.");
-
- // A state callback must be set before calling pa_threaded_mainloop_lock() or
- // pa_threaded_mainloop_wait() calls may lead to dead lock.
- pa_context_set_state_callback(*context, &ContextStateCallback, *mainloop);
-
- // Lock the main loop while setting up the context. Failure to do so may lead
- // to crashes as the PulseAudio thread tries to run before things are ready.
- AutoPulseLock auto_lock(*mainloop);
-
- RETURN_ON_FAILURE(pa_threaded_mainloop_start(*mainloop) == 0,
- "Failed to start PulseAudio main loop.");
- RETURN_ON_FAILURE(
- pa_context_connect(*context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL) == 0,
- "Failed to connect PulseAudio context.");
-
- // Wait until |pa_context_| is ready. pa_threaded_mainloop_wait() must be
- // called after pa_context_get_state() in case the context is already ready,
- // otherwise pa_threaded_mainloop_wait() will hang indefinitely.
- while (true) {
- pa_context_state_t context_state = pa_context_get_state(*context);
- RETURN_ON_FAILURE(
- PA_CONTEXT_IS_GOOD(context_state), "Invalid PulseAudio context state.");
- if (context_state == PA_CONTEXT_READY)
- break;
- pa_threaded_mainloop_wait(*mainloop);
- }
+ DCHECK(mainloop);
+ DCHECK(context);
+ DCHECK(device_id != AudioManagerBase::kDefaultDeviceId);
// Set sample specifications.
pa_sample_spec sample_specifications;
@@ -301,7 +264,7 @@ bool CreateOutputStream(pa_threaded_mainloop** mainloop,
pa_proplist_sets(property_list.get(), PA_PROP_APPLICATION_ICON_NAME,
kBrowserDisplayName);
*stream = pa_stream_new_with_proplist(
- *context, "Playback", &sample_specifications, map, property_list.get());
+ context, "Playback", &sample_specifications, map, property_list.get());
RETURN_ON_FAILURE(*stream, "failed to create PA playback stream");
pa_stream_set_state_callback(*stream, stream_callback, user_data);
@@ -332,16 +295,12 @@ bool CreateOutputStream(pa_threaded_mainloop** mainloop,
// and error.
RETURN_ON_FAILURE(
pa_stream_connect_playback(
- *stream,
- device_id == AudioManagerBase::kDefaultDeviceId ?
- NULL : device_id.c_str(),
- &pa_buffer_attributes,
+ *stream, device_id.c_str(), &pa_buffer_attributes,
static_cast<pa_stream_flags_t>(
PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_ADJUST_LATENCY |
PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_NOT_MONOTONIC |
PA_STREAM_START_CORKED),
- NULL,
- NULL) == 0,
+ NULL, NULL) == 0,
"pa_stream_connect_playback FAILED ");
// Wait for the stream to be ready.
@@ -351,7 +310,7 @@ bool CreateOutputStream(pa_threaded_mainloop** mainloop,
PA_STREAM_IS_GOOD(stream_state), "Invalid PulseAudio stream state");
if (stream_state == PA_STREAM_READY)
break;
- pa_threaded_mainloop_wait(*mainloop);
+ pa_threaded_mainloop_wait(mainloop);
}
return true;
« media/audio/pulse/pulse_output.cc ('K') | « media/audio/pulse/pulse_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698