1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
media / audio / alsa / alsa_wrapper.h [blame]
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// AlsaWrapper is a simple stateless class that wraps the alsa library commands
// we want to use. It's purpose is to allow injection of a mock so that the
// higher level code is testable.
#ifndef MEDIA_AUDIO_ALSA_ALSA_WRAPPER_H_
#define MEDIA_AUDIO_ALSA_ALSA_WRAPPER_H_
#include <alsa/asoundlib.h>
#include "media/base/media_export.h"
namespace media {
class MEDIA_EXPORT AlsaWrapper {
public:
AlsaWrapper();
AlsaWrapper(const AlsaWrapper&) = delete;
AlsaWrapper& operator=(const AlsaWrapper&) = delete;
virtual ~AlsaWrapper();
virtual int DeviceNameHint(int card, const char* iface, void*** hints);
virtual char* DeviceNameGetHint(const void* hint, const char* id);
virtual int DeviceNameFreeHint(void** hints);
virtual int CardNext(int* rcard);
virtual int PcmOpen(snd_pcm_t** handle,
const char* name,
snd_pcm_stream_t stream,
int mode);
virtual int PcmClose(snd_pcm_t* handle);
virtual int PcmPrepare(snd_pcm_t* handle);
virtual int PcmDrain(snd_pcm_t* handle);
virtual int PcmDrop(snd_pcm_t* handle);
virtual int PcmDelay(snd_pcm_t* handle, snd_pcm_sframes_t* delay);
virtual int PcmResume(snd_pcm_t* handle);
virtual snd_pcm_sframes_t PcmWritei(snd_pcm_t* handle,
const void* buffer,
snd_pcm_uframes_t size);
virtual snd_pcm_sframes_t PcmReadi(snd_pcm_t* handle,
void* buffer,
snd_pcm_uframes_t size);
virtual int PcmRecover(snd_pcm_t* handle, int err, int silent);
virtual int PcmSetParams(snd_pcm_t* handle,
snd_pcm_format_t format,
snd_pcm_access_t access,
unsigned int channels,
unsigned int rate,
int soft_resample,
unsigned int latency);
virtual int PcmGetParams(snd_pcm_t* handle,
snd_pcm_uframes_t* buffer_size,
snd_pcm_uframes_t* period_size);
virtual int PcmHwParamsMalloc(snd_pcm_hw_params_t** hw_params);
virtual int PcmHwParamsAny(snd_pcm_t* handle, snd_pcm_hw_params_t* hw_params);
virtual int PcmHwParamsCanResume(snd_pcm_hw_params_t* hw_params);
virtual int PcmHwParamsSetRateResample(snd_pcm_t* handle,
snd_pcm_hw_params_t* hw_params,
unsigned int value);
virtual int PcmHwParamsSetRateNear(snd_pcm_t* handle,
snd_pcm_hw_params_t* hw_params,
unsigned int* rate,
int* direction);
virtual int PcmHwParamsTestFormat(snd_pcm_t* handle,
snd_pcm_hw_params_t* hw_params,
snd_pcm_format_t format);
virtual int PcmFormatSize(snd_pcm_format_t format, size_t samples);
virtual int PcmHwParamsGetChannelsMin(const snd_pcm_hw_params_t* hw_params,
unsigned int* min_channels);
virtual int PcmHwParamsGetChannelsMax(const snd_pcm_hw_params_t* hw_params,
unsigned int* max_channels);
virtual int PcmHwParamsSetFormat(snd_pcm_t* handle,
snd_pcm_hw_params_t* hw_params,
snd_pcm_format_t format);
virtual int PcmHwParamsSetAccess(snd_pcm_t* handle,
snd_pcm_hw_params_t* hw_params,
snd_pcm_access_t access);
virtual int PcmHwParamsSetChannels(snd_pcm_t* handle,
snd_pcm_hw_params_t* hw_params,
unsigned int channels);
virtual int PcmHwParamsSetBufferSizeNear(snd_pcm_t* handle,
snd_pcm_hw_params_t* hw_params,
snd_pcm_uframes_t* buffer_size);
virtual int PcmHwParamsSetPeriodSizeNear(snd_pcm_t* handle,
snd_pcm_hw_params_t* hw_params,
snd_pcm_uframes_t* period_size,
int* direction);
virtual int PcmHwParams(snd_pcm_t* handle, snd_pcm_hw_params_t* hw_params);
virtual void PcmHwParamsFree(snd_pcm_hw_params_t* hw_params);
virtual int PcmSwParamsMalloc(snd_pcm_sw_params_t** sw_params);
virtual int PcmSwParamsCurrent(snd_pcm_t* handle,
snd_pcm_sw_params_t* sw_params);
virtual int PcmSwParamsSetStartThreshold(snd_pcm_t* handle,
snd_pcm_sw_params_t* sw_params,
snd_pcm_uframes_t start_threshold);
virtual int PcmSwParamsSetAvailMin(snd_pcm_t* handle,
snd_pcm_sw_params_t* sw_params,
snd_pcm_uframes_t period_size);
virtual int PcmSwParams(snd_pcm_t* handle, snd_pcm_sw_params_t* sw_params);
virtual void PcmSwParamsFree(snd_pcm_sw_params_t* sw_params);
virtual const char* PcmName(snd_pcm_t* handle);
virtual snd_pcm_sframes_t PcmAvailUpdate(snd_pcm_t* handle);
virtual snd_pcm_state_t PcmState(snd_pcm_t* handle);
virtual int PcmStart(snd_pcm_t* handle);
virtual int MixerOpen(snd_mixer_t** mixer, int mode);
virtual int MixerAttach(snd_mixer_t* mixer, const char* name);
virtual int MixerElementRegister(snd_mixer_t* mixer,
struct snd_mixer_selem_regopt* options,
snd_mixer_class_t** classp);
virtual void MixerFree(snd_mixer_t* mixer);
virtual int MixerDetach(snd_mixer_t* mixer, const char* name);
virtual int MixerClose(snd_mixer_t* mixer);
virtual int MixerLoad(snd_mixer_t* mixer);
virtual snd_mixer_elem_t* MixerFirstElem(snd_mixer_t* mixer);
virtual snd_mixer_elem_t* MixerNextElem(snd_mixer_elem_t* elem);
virtual int MixerSelemIsActive(snd_mixer_elem_t* elem);
virtual const char* MixerSelemName(snd_mixer_elem_t* elem);
virtual int MixerSelemSetCaptureVolumeAll(snd_mixer_elem_t* elem, long value);
virtual int MixerSelemGetCaptureVolume(snd_mixer_elem_t* elem,
snd_mixer_selem_channel_id_t channel,
long* value);
virtual int MixerSelemHasCaptureVolume(snd_mixer_elem_t* elem);
virtual int MixerSelemGetCaptureVolumeRange(snd_mixer_elem_t* elem,
long* min,
long* max);
virtual void* MixerElemGetCallbackPrivate(const snd_mixer_elem_t* obj);
virtual void MixerElemSetCallback(snd_mixer_elem_t* obj,
snd_mixer_elem_callback_t val);
virtual void MixerElemSetCallbackPrivate(snd_mixer_elem_t* obj, void* val);
virtual snd_mixer_elem_t* MixerFindSelem(snd_mixer_t* mixer,
const snd_mixer_selem_id_t* id);
virtual int MixerHandleEvents(snd_mixer_t* mixer);
virtual int MixerPollDescriptors(snd_mixer_t* mixer,
struct pollfd* pfds,
unsigned int space);
virtual int MixerPollDescriptorsCount(snd_mixer_t* mixer);
virtual int MixerSelemGetPlaybackSwitch(snd_mixer_elem_t* elem,
snd_mixer_selem_channel_id_t channel,
int* value);
virtual int MixerSelemGetPlaybackVolume(snd_mixer_elem_t* elem,
snd_mixer_selem_channel_id_t channel,
long* value);
virtual int MixerSelemGetPlaybackVolumeRange(snd_mixer_elem_t* elem,
long* min,
long* max);
virtual int MixerSelemAskPlaybackVolDb(snd_mixer_elem_t* elem,
long value,
long* db_value);
virtual int MixerSelemAskPlaybackDbVol(snd_mixer_elem_t* elem,
long db_value,
long* value);
virtual int MixerSelemHasPlaybackSwitch(snd_mixer_elem_t* elem);
virtual int MixerSelemHasPlaybackVolume(snd_mixer_elem_t* elem);
virtual void MixerSelemIdSetIndex(snd_mixer_selem_id_t* obj,
unsigned int val);
virtual void MixerSelemIdSetName(snd_mixer_selem_id_t* obj, const char* val);
virtual int MixerSelemSetPlaybackSwitch(snd_mixer_elem_t* elem,
snd_mixer_selem_channel_id_t channel,
int value);
virtual int MixerSelemSetPlaybackSwitchAll(snd_mixer_elem_t* elem,
int value);
virtual int MixerSelemSetPlaybackVolumeAll(snd_mixer_elem_t* elem,
long value);
virtual int MixerSelemIdMalloc(snd_mixer_selem_id_t** ptr);
virtual void MixerSelemIdFree(snd_mixer_selem_id_t* obj);
virtual const char* StrError(int errnum);
};
} // namespace media
#endif // MEDIA_AUDIO_ALSA_ALSA_WRAPPER_H_