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.
5 #include "media/audio/linux/alsa_wrapper.h"
7 #include <alsa/asoundlib.h>
11 AlsaWrapper::AlsaWrapper() {
14 AlsaWrapper::~AlsaWrapper() {
17 int AlsaWrapper::PcmOpen(snd_pcm_t
** handle
, const char* name
,
18 snd_pcm_stream_t stream
, int mode
) {
19 return snd_pcm_open(handle
, name
, stream
, mode
);
22 int AlsaWrapper::DeviceNameHint(int card
, const char* iface
, void*** hints
) {
23 return snd_device_name_hint(card
, iface
, hints
);
26 char* AlsaWrapper::DeviceNameGetHint(const void* hint
, const char* id
) {
27 return snd_device_name_get_hint(hint
, id
);
30 int AlsaWrapper::DeviceNameFreeHint(void** hints
) {
31 return snd_device_name_free_hint(hints
);
34 int AlsaWrapper::CardNext(int* rcard
) {
35 return snd_card_next(rcard
);
38 int AlsaWrapper::PcmClose(snd_pcm_t
* handle
) {
39 return snd_pcm_close(handle
);
42 int AlsaWrapper::PcmPrepare(snd_pcm_t
* handle
) {
43 return snd_pcm_prepare(handle
);
46 int AlsaWrapper::PcmDrop(snd_pcm_t
* handle
) {
47 return snd_pcm_drop(handle
);
50 int AlsaWrapper::PcmDelay(snd_pcm_t
* handle
, snd_pcm_sframes_t
* delay
) {
51 return snd_pcm_delay(handle
, delay
);
54 snd_pcm_sframes_t
AlsaWrapper::PcmWritei(snd_pcm_t
* handle
,
56 snd_pcm_uframes_t size
) {
57 return snd_pcm_writei(handle
, buffer
, size
);
60 snd_pcm_sframes_t
AlsaWrapper::PcmReadi(snd_pcm_t
* handle
,
62 snd_pcm_uframes_t size
) {
63 return snd_pcm_readi(handle
, buffer
, size
);
66 int AlsaWrapper::PcmRecover(snd_pcm_t
* handle
, int err
, int silent
) {
67 return snd_pcm_recover(handle
, err
, silent
);
70 const char* AlsaWrapper::PcmName(snd_pcm_t
* handle
) {
71 return snd_pcm_name(handle
);
74 int AlsaWrapper::PcmSetParams(snd_pcm_t
* handle
, snd_pcm_format_t format
,
75 snd_pcm_access_t access
, unsigned int channels
,
76 unsigned int rate
, int soft_resample
,
77 unsigned int latency
) {
78 return snd_pcm_set_params(handle
,
87 int AlsaWrapper::PcmGetParams(snd_pcm_t
* handle
, snd_pcm_uframes_t
* buffer_size
,
88 snd_pcm_uframes_t
* period_size
) {
89 return snd_pcm_get_params(handle
, buffer_size
, period_size
);
92 snd_pcm_sframes_t
AlsaWrapper::PcmAvailUpdate(snd_pcm_t
* handle
) {
93 return snd_pcm_avail_update(handle
);
96 snd_pcm_state_t
AlsaWrapper::PcmState(snd_pcm_t
* handle
) {
97 return snd_pcm_state(handle
);
100 const char* AlsaWrapper::StrError(int errnum
) {
101 return snd_strerror(errnum
);
104 int AlsaWrapper::PcmStart(snd_pcm_t
* handle
) {
105 return snd_pcm_start(handle
);
108 int AlsaWrapper::MixerOpen(snd_mixer_t
** mixer
, int mode
) {
109 return snd_mixer_open(mixer
, mode
);
112 int AlsaWrapper::MixerAttach(snd_mixer_t
* mixer
, const char* name
) {
113 return snd_mixer_attach(mixer
, name
);
116 int AlsaWrapper::MixerElementRegister(snd_mixer_t
* mixer
,
117 struct snd_mixer_selem_regopt
* options
,
118 snd_mixer_class_t
** classp
) {
119 return snd_mixer_selem_register(mixer
, options
, classp
);
122 void AlsaWrapper::MixerFree(snd_mixer_t
* mixer
) {
123 snd_mixer_free(mixer
);
126 int AlsaWrapper::MixerDetach(snd_mixer_t
* mixer
, const char* name
) {
127 return snd_mixer_detach(mixer
, name
);
130 int AlsaWrapper::MixerClose(snd_mixer_t
* mixer
) {
131 return snd_mixer_close(mixer
);
134 int AlsaWrapper::MixerLoad(snd_mixer_t
* mixer
) {
135 return snd_mixer_load(mixer
);
138 snd_mixer_elem_t
* AlsaWrapper::MixerFirstElem(snd_mixer_t
* mixer
) {
139 return snd_mixer_first_elem(mixer
);
142 snd_mixer_elem_t
* AlsaWrapper::MixerNextElem(snd_mixer_elem_t
* elem
) {
143 return snd_mixer_elem_next(elem
);
146 int AlsaWrapper::MixerSelemIsActive(snd_mixer_elem_t
* elem
) {
147 return snd_mixer_selem_is_active(elem
);
150 const char* AlsaWrapper::MixerSelemName(snd_mixer_elem_t
* elem
) {
151 return snd_mixer_selem_get_name(elem
);
154 int AlsaWrapper::MixerSelemSetCaptureVolumeAll(
155 snd_mixer_elem_t
* elem
, long value
) {
156 return snd_mixer_selem_set_capture_volume_all(elem
, value
);
159 int AlsaWrapper::MixerSelemGetCaptureVolume(
160 snd_mixer_elem_t
* elem
, snd_mixer_selem_channel_id_t channel
, long* value
) {
161 return snd_mixer_selem_get_capture_volume(elem
, channel
, value
);
164 int AlsaWrapper::MixerSelemHasCaptureVolume(snd_mixer_elem_t
* elem
) {
165 return snd_mixer_selem_has_capture_volume(elem
);
168 int AlsaWrapper::MixerSelemGetCaptureVolumeRange(snd_mixer_elem_t
* elem
,
169 long* min
, long* max
) {
170 return snd_mixer_selem_get_capture_volume_range(elem
, min
, max
);