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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "media/audio/pulse/pulse_wrapper.h"
6
7 #include "base/file_path.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10
11 namespace media {
12
13 // Static function to create a PulseWrapper object and return NULL if the
14 // library could not be loaded properly.
15 PulseWrapper* PulseWrapper::Create() {
16 scoped_ptr<PulseWrapper> pulse(new PulseWrapper());
17 return pulse->Load() ? pulse.release() : NULL;
18 }
19
20 PulseWrapper::PulseWrapper()
21 : pa_threaded_mainloop_get_api_(NULL),
22 pa_threaded_mainloop_free_(NULL),
23 pa_threaded_mainloop_new_(NULL),
24 pa_threaded_mainloop_lock_(NULL),
25 pa_threaded_mainloop_signal_(NULL),
26 pa_threaded_mainloop_start_(NULL),
27 pa_threaded_mainloop_stop_(NULL),
28 pa_threaded_mainloop_unlock_(NULL),
29 pa_threaded_mainloop_wait_(NULL),
30 pa_channel_map_init_(NULL),
31 pa_context_connect_(NULL),
32 pa_context_disconnect_(NULL),
33 pa_context_errno_(NULL),
34 pa_context_get_server_info_(NULL),
35 pa_context_get_source_info_by_index_(NULL),
36 pa_context_get_source_info_list_(NULL),
37 pa_context_get_state_(NULL),
38 pa_context_new_(NULL),
39 pa_context_set_source_volume_by_index_(NULL),
40 pa_context_set_state_callback_(NULL),
41 pa_context_unref_(NULL),
42 pa_operation_get_state_(NULL),
43 pa_operation_unref_(NULL),
44 pa_stream_begin_write_(NULL),
45 pa_stream_connect_playback_(NULL),
46 pa_stream_connect_record_(NULL),
47 pa_stream_cork_(NULL),
48 pa_stream_disconnect_(NULL),
49 pa_stream_drop_(NULL),
50 pa_stream_flush_(NULL),
51 pa_stream_get_device_index_(NULL),
52 pa_stream_get_latency_(NULL),
53 pa_stream_get_state_(NULL),
54 pa_stream_new_(NULL),
55 pa_stream_peek_(NULL),
56 pa_stream_readable_size_(NULL),
57 pa_stream_set_read_callback_(NULL),
58 pa_stream_set_state_callback_(NULL),
59 pa_stream_set_write_callback_(NULL),
60 pa_stream_unref_(NULL),
61 pa_stream_write_(NULL),
62 pa_strerror_(NULL),
63 pa_cvolume_set_(NULL) {}
64
65 PulseWrapper::~PulseWrapper() {}
66
67 bool PulseWrapper::Load() {
68 std::string error;
69 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
70 FilePath("libpulse.so.0"), &error);
71 if (!error.empty()) {
72 LOG(ERROR) << "Could not open PulseAudio library: " << error;
73 return false;
74 }
75
76 pulse_lib_.Reset(pulse_lib);
77
78 if (!Bind(&pa_threaded_mainloop_get_api_, "pa_threaded_mainloop_get_api"))
79 return false;
80 if (!Bind(&pa_threaded_mainloop_free_, "pa_threaded_mainloop_free"))
81 return false;
82 if (!Bind(&pa_threaded_mainloop_new_, "pa_threaded_mainloop_new"))
83 return false;
84 if (!Bind(&pa_threaded_mainloop_lock_, "pa_threaded_mainloop_lock"))
85 return false;
86 if (!Bind(&pa_threaded_mainloop_signal_, "pa_threaded_mainloop_signal"))
87 return false;
88 if (!Bind(&pa_threaded_mainloop_start_, "pa_threaded_mainloop_start"))
89 return false;
90 if (!Bind(&pa_threaded_mainloop_stop_, "pa_threaded_mainloop_stop"))
91 return false;
92 if (!Bind(&pa_threaded_mainloop_unlock_, "pa_threaded_mainloop_unlock"))
93 return false;
94 if (!Bind(&pa_threaded_mainloop_wait_, "pa_threaded_mainloop_wait"))
95 return false;
96 if (!Bind(&pa_channel_map_init_, "pa_channel_map_init"))
97 return false;
98 if (!Bind(&pa_context_connect_, "pa_context_connect"))
99 return false;
100 if (!Bind(&pa_context_disconnect_, "pa_context_disconnect"))
101 return false;
102 if (!Bind(&pa_context_errno_, "pa_context_errno"))
103 return false;
104 if (!Bind(&pa_context_get_server_info_, "pa_context_get_server_info"))
105 return false;
106 if (!Bind(&pa_context_get_source_info_by_index_,
107 "pa_context_get_source_info_by_index"))
108 return false;
109 if (!Bind(&pa_context_get_source_info_list_,
110 "pa_context_get_source_info_list"))
111 return false;
112 if (!Bind(&pa_context_get_state_, "pa_context_get_state"))
113 return false;
114 if (!Bind(&pa_context_new_, "pa_context_new"))
115 return false;
116 if (!Bind(&pa_context_set_source_volume_by_index_,
117 "pa_context_set_source_volume_by_index"))
118 return false;
119 if (!Bind(&pa_context_set_state_callback_, "pa_context_set_state_callback"))
120 return false;
121 if (!Bind(&pa_context_unref_, "pa_context_unref"))
122 return false;
123 if (!Bind(&pa_operation_get_state_, "pa_operation_get_state"))
124 return false;
125 if (!Bind(&pa_operation_unref_, "pa_operation_unref"))
126 return false;
127 if (!Bind(&pa_stream_begin_write_, "pa_stream_begin_write"))
128 return false;
129 if (!Bind(&pa_stream_connect_playback_, "pa_stream_connect_playback"))
130 return false;
131 if (!Bind(&pa_stream_connect_record_, "pa_stream_connect_record"))
132 return false;
133 if (!Bind(&pa_stream_cork_, "pa_stream_cork"))
134 return false;
135 if (!Bind(&pa_stream_disconnect_, "pa_stream_disconnect"))
136 return false;
137 if (!Bind(&pa_stream_drop_, "pa_stream_drop"))
138 return false;
139 if (!Bind(&pa_stream_flush_, "pa_stream_flush"))
140 return false;
141 if (!Bind(&pa_stream_get_device_index_, "pa_stream_get_device_index"))
142 return false;
143 if (!Bind(&pa_stream_get_latency_, "pa_stream_get_latency"))
144 return false;
145 if (!Bind(&pa_stream_get_state_, "pa_stream_get_state"))
146 return false;
147 if (!Bind(&pa_stream_new_, "pa_stream_new"))
148 return false;
149 if (!Bind(&pa_stream_peek_, "pa_stream_peek"))
150 return false;
151 if (!Bind(&pa_stream_readable_size_, "pa_stream_readable_size"))
152 return false;
153 if (!Bind(&pa_stream_set_read_callback_, "pa_stream_set_read_callback"))
154 return false;
155 if (!Bind(&pa_stream_set_state_callback_, "pa_stream_set_state_callback"))
156 return false;
157 if (!Bind(&pa_stream_set_write_callback_, "pa_stream_set_write_callback"))
158 return false;
159 if (!Bind(&pa_stream_unref_, "pa_stream_unref"))
160 return false;
161 if (!Bind(&pa_stream_write_, "pa_stream_write"))
162 return false;
163 if (!Bind(&pa_strerror_, "pa_strerror"))
164 return false;
165 if (!Bind(&pa_cvolume_set_, "pa_cvolume_set"))
166 return false;
167
168 return true;
169 }
170
171 template <class T>
172 bool PulseWrapper::Bind(T* function_pointer, const std::string& function_name) {
173 *function_pointer = reinterpret_cast<T>(
174 pulse_lib_.GetFunctionPointer(function_name.c_str()));
175 if (!*function_pointer) {
176 LOG(WARNING) << "Unable to bind function " << function_name;
177 return false;
178 }
179
180 return true;
181 }
182
183 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698