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

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

Issue 10952024: Adding pulseaudio input support to chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: switched to dynamic linking and addressed Andrew's comments. Created 7 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 side-by-side diff with in-line comments
Download patch
Index: media/audio/pulse/pulse_wrapper.cc
diff --git a/media/audio/pulse/pulse_wrapper.cc b/media/audio/pulse/pulse_wrapper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7f987b127e8fc4ca4c6b7427cf346dc0f69ada52
--- /dev/null
+++ b/media/audio/pulse/pulse_wrapper.cc
@@ -0,0 +1,183 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/audio/pulse/pulse_wrapper.h"
+
+#include "base/file_path.h"
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+
+namespace media {
+
+// Static function to create a PulseWrapper object and return NULL if the
+// library could not be loaded properly.
+PulseWrapper* PulseWrapper::Create() {
+ scoped_ptr<PulseWrapper> pulse(new PulseWrapper());
+ return pulse->Load() ? pulse.release() : NULL;
+}
+
+PulseWrapper::PulseWrapper()
+ : pa_threaded_mainloop_get_api_(NULL),
+ pa_threaded_mainloop_free_(NULL),
+ pa_threaded_mainloop_new_(NULL),
+ pa_threaded_mainloop_lock_(NULL),
+ pa_threaded_mainloop_signal_(NULL),
+ pa_threaded_mainloop_start_(NULL),
+ pa_threaded_mainloop_stop_(NULL),
+ pa_threaded_mainloop_unlock_(NULL),
+ pa_threaded_mainloop_wait_(NULL),
+ pa_channel_map_init_(NULL),
+ pa_context_connect_(NULL),
+ pa_context_disconnect_(NULL),
+ pa_context_errno_(NULL),
+ pa_context_get_server_info_(NULL),
+ pa_context_get_source_info_by_index_(NULL),
+ pa_context_get_source_info_list_(NULL),
+ pa_context_get_state_(NULL),
+ pa_context_new_(NULL),
+ pa_context_set_source_volume_by_index_(NULL),
+ pa_context_set_state_callback_(NULL),
+ pa_context_unref_(NULL),
+ pa_operation_get_state_(NULL),
+ pa_operation_unref_(NULL),
+ pa_stream_begin_write_(NULL),
+ pa_stream_connect_playback_(NULL),
+ pa_stream_connect_record_(NULL),
+ pa_stream_cork_(NULL),
+ pa_stream_disconnect_(NULL),
+ pa_stream_drop_(NULL),
+ pa_stream_flush_(NULL),
+ pa_stream_get_device_index_(NULL),
+ pa_stream_get_latency_(NULL),
+ pa_stream_get_state_(NULL),
+ pa_stream_new_(NULL),
+ pa_stream_peek_(NULL),
+ pa_stream_readable_size_(NULL),
+ pa_stream_set_read_callback_(NULL),
+ pa_stream_set_state_callback_(NULL),
+ pa_stream_set_write_callback_(NULL),
+ pa_stream_unref_(NULL),
+ pa_stream_write_(NULL),
+ pa_strerror_(NULL),
+ pa_cvolume_set_(NULL) {}
+
+PulseWrapper::~PulseWrapper() {}
+
+bool PulseWrapper::Load() {
+ std::string error;
+ base::NativeLibrary pulse_lib = base::LoadNativeLibrary(
DaleCurtis 2013/02/15 00:28:51 Hmm, this is way different than what I was thinkin
no longer working on chromium 2013/02/15 16:07:33 Simply because I don't way we have a script to do
+ FilePath("libpulse.so.0"), &error);
+ if (!error.empty()) {
+ LOG(ERROR) << "Could not open PulseAudio library: " << error;
+ return false;
+ }
+
+ pulse_lib_.Reset(pulse_lib);
+
+ if (!Bind(&pa_threaded_mainloop_get_api_, "pa_threaded_mainloop_get_api"))
+ return false;
+ if (!Bind(&pa_threaded_mainloop_free_, "pa_threaded_mainloop_free"))
+ return false;
+ if (!Bind(&pa_threaded_mainloop_new_, "pa_threaded_mainloop_new"))
+ return false;
+ if (!Bind(&pa_threaded_mainloop_lock_, "pa_threaded_mainloop_lock"))
+ return false;
+ if (!Bind(&pa_threaded_mainloop_signal_, "pa_threaded_mainloop_signal"))
+ return false;
+ if (!Bind(&pa_threaded_mainloop_start_, "pa_threaded_mainloop_start"))
+ return false;
+ if (!Bind(&pa_threaded_mainloop_stop_, "pa_threaded_mainloop_stop"))
+ return false;
+ if (!Bind(&pa_threaded_mainloop_unlock_, "pa_threaded_mainloop_unlock"))
+ return false;
+ if (!Bind(&pa_threaded_mainloop_wait_, "pa_threaded_mainloop_wait"))
+ return false;
+ if (!Bind(&pa_channel_map_init_, "pa_channel_map_init"))
+ return false;
+ if (!Bind(&pa_context_connect_, "pa_context_connect"))
+ return false;
+ if (!Bind(&pa_context_disconnect_, "pa_context_disconnect"))
+ return false;
+ if (!Bind(&pa_context_errno_, "pa_context_errno"))
+ return false;
+ if (!Bind(&pa_context_get_server_info_, "pa_context_get_server_info"))
+ return false;
+ if (!Bind(&pa_context_get_source_info_by_index_,
+ "pa_context_get_source_info_by_index"))
+ return false;
+ if (!Bind(&pa_context_get_source_info_list_,
+ "pa_context_get_source_info_list"))
+ return false;
+ if (!Bind(&pa_context_get_state_, "pa_context_get_state"))
+ return false;
+ if (!Bind(&pa_context_new_, "pa_context_new"))
+ return false;
+ if (!Bind(&pa_context_set_source_volume_by_index_,
+ "pa_context_set_source_volume_by_index"))
+ return false;
+ if (!Bind(&pa_context_set_state_callback_, "pa_context_set_state_callback"))
+ return false;
+ if (!Bind(&pa_context_unref_, "pa_context_unref"))
+ return false;
+ if (!Bind(&pa_operation_get_state_, "pa_operation_get_state"))
+ return false;
+ if (!Bind(&pa_operation_unref_, "pa_operation_unref"))
+ return false;
+ if (!Bind(&pa_stream_begin_write_, "pa_stream_begin_write"))
+ return false;
+ if (!Bind(&pa_stream_connect_playback_, "pa_stream_connect_playback"))
+ return false;
+ if (!Bind(&pa_stream_connect_record_, "pa_stream_connect_record"))
+ return false;
+ if (!Bind(&pa_stream_cork_, "pa_stream_cork"))
+ return false;
+ if (!Bind(&pa_stream_disconnect_, "pa_stream_disconnect"))
+ return false;
+ if (!Bind(&pa_stream_drop_, "pa_stream_drop"))
+ return false;
+ if (!Bind(&pa_stream_flush_, "pa_stream_flush"))
+ return false;
+ if (!Bind(&pa_stream_get_device_index_, "pa_stream_get_device_index"))
+ return false;
+ if (!Bind(&pa_stream_get_latency_, "pa_stream_get_latency"))
+ return false;
+ if (!Bind(&pa_stream_get_state_, "pa_stream_get_state"))
+ return false;
+ if (!Bind(&pa_stream_new_, "pa_stream_new"))
+ return false;
+ if (!Bind(&pa_stream_peek_, "pa_stream_peek"))
+ return false;
+ if (!Bind(&pa_stream_readable_size_, "pa_stream_readable_size"))
+ return false;
+ if (!Bind(&pa_stream_set_read_callback_, "pa_stream_set_read_callback"))
+ return false;
+ if (!Bind(&pa_stream_set_state_callback_, "pa_stream_set_state_callback"))
+ return false;
+ if (!Bind(&pa_stream_set_write_callback_, "pa_stream_set_write_callback"))
+ return false;
+ if (!Bind(&pa_stream_unref_, "pa_stream_unref"))
+ return false;
+ if (!Bind(&pa_stream_write_, "pa_stream_write"))
+ return false;
+ if (!Bind(&pa_strerror_, "pa_strerror"))
+ return false;
+ if (!Bind(&pa_cvolume_set_, "pa_cvolume_set"))
+ return false;
+
+ return true;
+}
+
+template <class T>
+bool PulseWrapper::Bind(T* function_pointer, const std::string& function_name) {
+ *function_pointer = reinterpret_cast<T>(
+ pulse_lib_.GetFunctionPointer(function_name.c_str()));
+ if (!*function_pointer) {
+ LOG(WARNING) << "Unable to bind function " << function_name;
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698