OLD | NEW |
(Empty) | |
| 1 // Copyright 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 <pulse/pulseaudio.h> |
| 6 |
| 7 #include "base/basictypes.h" |
| 8 #include "base/scoped_native_library.h" |
| 9 |
| 10 namespace media { |
| 11 |
| 12 // PulseWrapper is a stateless class that loads the pulse audio library |
| 13 // dynamically and wraps the pulse library commands we want to use. |
| 14 class PulseWrapper { |
| 15 public: |
| 16 PulseWrapper(); |
| 17 virtual ~PulseWrapper(); |
| 18 |
| 19 static PulseWrapper* Create(); |
| 20 |
| 21 typedef pa_mainloop_api*(*PaThreadedMainloopGetApiT)(pa_threaded_mainloop* m); |
| 22 typedef void(*PaThreadedMainloopFreeT)(pa_threaded_mainloop* m); |
| 23 typedef pa_threaded_mainloop*(*PaThreadedMainloopNewT)(); |
| 24 typedef void(*PaThreadedMainloopLockT)(pa_threaded_mainloop* m); |
| 25 typedef void(*PaThreadedMainloopSignalT)( |
| 26 pa_threaded_mainloop* m, int wait_for_accept); |
| 27 typedef int(*PaThreadedMainloopStartT)(pa_threaded_mainloop* m); |
| 28 typedef void(*PaThreadedMainloopStopT)(pa_threaded_mainloop* m); |
| 29 typedef void(*PaThreadedMainloopUnlockT)(pa_threaded_mainloop* m); |
| 30 typedef void(*PaThreadedMainloopWaitT)(pa_threaded_mainloop* m); |
| 31 typedef pa_channel_map*(*PaChannelMapInitT)(pa_channel_map* m); |
| 32 typedef int(*PaContextConnectT)( |
| 33 pa_context* c, const char* server, pa_context_flags_t flags, |
| 34 const pa_spawn_api* api); |
| 35 typedef void(*PaContextDisconnectT)(pa_context* c); |
| 36 typedef pa_operation*(*PaContextGetServerInfoT)( |
| 37 pa_context* c, pa_server_info_cb_t cb, void* userdata); |
| 38 typedef pa_operation*(*PaContextGetSourceInfoByIndexT)( |
| 39 pa_context* c, uint32_t idx, pa_source_info_cb_t cb, void* userdata); |
| 40 typedef pa_operation*(*PaContextGetSourceInfoListT)( |
| 41 pa_context* c, pa_source_info_cb_t cb, void* userdata); |
| 42 typedef pa_context_state_t(*PaContextGetStateT)(pa_context* c); |
| 43 typedef pa_context*(*PaContextNew)( |
| 44 pa_mainloop_api* mainloop, const char* name); |
| 45 typedef pa_operation*(*PaContextSetSourceVolumeByIndexT)( |
| 46 pa_context* c, uint32_t idx, const pa_cvolume* volume, |
| 47 pa_context_success_cb_t cb, void* userdata); |
| 48 typedef void(*PaContextSetStateCallbackT)( |
| 49 pa_context* c, pa_context_notify_cb_t cb, void* userdata); |
| 50 typedef void(*PaContextUnrefT)(pa_context* c); |
| 51 typedef pa_operation_state_t(*PaOperationGetStateT)(pa_operation* o); |
| 52 typedef void(*PaOperationUnrefT)(pa_operation* o); |
| 53 typedef int(*PaStreamBeginWriteT)(pa_stream* p, void** data, size_t* nbytes); |
| 54 typedef int(*PaStreamConnectPlaybackT)( |
| 55 pa_stream* s, const char* dev, const pa_buffer_attr* attr, |
| 56 pa_stream_flags_t flags, const pa_cvolume* volume, |
| 57 pa_stream* sync_stream); |
| 58 typedef int(*PaStreamConnectRecordT)( |
| 59 pa_stream* s, const char* dev, const pa_buffer_attr* attr, |
| 60 pa_stream_flags_t flags); |
| 61 typedef pa_operation*(*PaStreamCorkT)( |
| 62 pa_stream* s, int b, pa_stream_success_cb_t cb, void* userdata); |
| 63 typedef int(*PaStreamDisconnectT)(pa_stream* s); |
| 64 typedef int(*PaStreamDropT)(pa_stream *p); |
| 65 typedef pa_operation*(*PaStreamFlushT)( |
| 66 pa_stream* s, pa_stream_success_cb_t cb, void* userdata); |
| 67 typedef uint32_t(*PaStreamGetDeviceIndexT)(pa_stream* s); |
| 68 typedef int(*PaStreamGetLatencyT)( |
| 69 pa_stream* s, pa_usec_t* r_usec, int* negative); |
| 70 typedef pa_stream_state_t(*PaStreamGetStateT)(pa_stream* p); |
| 71 typedef pa_stream*(*PaStreamNewT)( |
| 72 pa_context* c, const char* name, const pa_sample_spec* ss, |
| 73 const pa_channel_map * map); |
| 74 typedef size_t(*PaStreamReadableSizeT)(pa_stream *p); |
| 75 typedef int(*PaStreamPeekT)( |
| 76 pa_stream* p, const void** data, size_t* nbytes); |
| 77 typedef void(*PaStreamSetReadCallbackT)( |
| 78 pa_stream* p, pa_stream_request_cb_t cb, void* userdata); |
| 79 typedef void(*PaStreamSetStateCallbackT)( |
| 80 pa_stream* s, pa_stream_notify_cb_t cb, void* userdata); |
| 81 typedef void(*PaStreamUnrefT)(pa_stream* s); |
| 82 typedef void(*PaStreamSetWriteCallbackT)( |
| 83 pa_stream *p, pa_stream_request_cb_t cb, void *userdata); |
| 84 typedef int(*PaStreamWriteT)( |
| 85 pa_stream* p, const void* data, size_t nbytes, |
| 86 pa_free_cb_t free_cb, int64_t offset, pa_seek_mode_t seek); |
| 87 typedef int(*PaContextErrnoT)(pa_context *c); |
| 88 typedef const char*(*PaStrerrorT)(int error); |
| 89 typedef pa_cvolume*(*PaCvolumeSetT)( |
| 90 pa_cvolume* a, unsigned channels, pa_volume_t v); |
| 91 |
| 92 PaThreadedMainloopGetApiT pa_threaded_mainloop_get_api_; |
| 93 PaThreadedMainloopFreeT pa_threaded_mainloop_free_; |
| 94 PaThreadedMainloopNewT pa_threaded_mainloop_new_; |
| 95 PaThreadedMainloopLockT pa_threaded_mainloop_lock_; |
| 96 PaThreadedMainloopSignalT pa_threaded_mainloop_signal_; |
| 97 PaThreadedMainloopStartT pa_threaded_mainloop_start_; |
| 98 PaThreadedMainloopStopT pa_threaded_mainloop_stop_; |
| 99 PaThreadedMainloopUnlockT pa_threaded_mainloop_unlock_; |
| 100 PaThreadedMainloopWaitT pa_threaded_mainloop_wait_; |
| 101 PaChannelMapInitT pa_channel_map_init_; |
| 102 PaContextConnectT pa_context_connect_; |
| 103 PaContextDisconnectT pa_context_disconnect_; |
| 104 PaContextErrnoT pa_context_errno_; |
| 105 PaContextGetServerInfoT pa_context_get_server_info_; |
| 106 PaContextGetSourceInfoByIndexT pa_context_get_source_info_by_index_; |
| 107 PaContextGetSourceInfoListT pa_context_get_source_info_list_; |
| 108 PaContextGetStateT pa_context_get_state_; |
| 109 PaContextNew pa_context_new_; |
| 110 PaContextSetSourceVolumeByIndexT pa_context_set_source_volume_by_index_; |
| 111 PaContextSetStateCallbackT pa_context_set_state_callback_; |
| 112 PaContextUnrefT pa_context_unref_; |
| 113 PaOperationGetStateT pa_operation_get_state_; |
| 114 PaOperationUnrefT pa_operation_unref_; |
| 115 PaStreamBeginWriteT pa_stream_begin_write_; |
| 116 PaStreamConnectPlaybackT pa_stream_connect_playback_; |
| 117 PaStreamConnectRecordT pa_stream_connect_record_; |
| 118 PaStreamCorkT pa_stream_cork_; |
| 119 PaStreamDisconnectT pa_stream_disconnect_; |
| 120 PaStreamDropT pa_stream_drop_; |
| 121 PaStreamFlushT pa_stream_flush_; |
| 122 PaStreamGetDeviceIndexT pa_stream_get_device_index_; |
| 123 PaStreamGetLatencyT pa_stream_get_latency_; |
| 124 PaStreamGetStateT pa_stream_get_state_; |
| 125 PaStreamNewT pa_stream_new_; |
| 126 PaStreamPeekT pa_stream_peek_; |
| 127 PaStreamReadableSizeT pa_stream_readable_size_; |
| 128 PaStreamSetReadCallbackT pa_stream_set_read_callback_; |
| 129 PaStreamSetStateCallbackT pa_stream_set_state_callback_; |
| 130 PaStreamSetWriteCallbackT pa_stream_set_write_callback_; |
| 131 PaStreamUnrefT pa_stream_unref_; |
| 132 PaStreamWriteT pa_stream_write_; |
| 133 PaStrerrorT pa_strerror_; |
| 134 PaCvolumeSetT pa_cvolume_set_; |
| 135 |
| 136 private: |
| 137 // Loads the pulse library and symbols. |
| 138 bool Load(); |
| 139 |
| 140 // Binds the |function_pointer| to the Pulse function. |
| 141 template <class T> |
| 142 bool Bind(T* function_pointer, const std::string& function_name); |
| 143 |
| 144 base::ScopedNativeLibrary pulse_lib_; |
| 145 DISALLOW_COPY_AND_ASSIGN(PulseWrapper); |
| 146 }; |
| 147 |
| 148 } // namespace media |
OLD | NEW |