Home | History | Annotate | Download | only in alsa
      1 // Copyright 2013 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/alsa/alsa_wrapper.h"
      6 
      7 #include <alsa/asoundlib.h>
      8 
      9 namespace media {
     10 
     11 AlsaWrapper::AlsaWrapper() {
     12 }
     13 
     14 AlsaWrapper::~AlsaWrapper() {
     15 }
     16 
     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);
     20 }
     21 
     22 int AlsaWrapper::DeviceNameHint(int card, const char* iface, void*** hints) {
     23   return snd_device_name_hint(card, iface, hints);
     24 }
     25 
     26 char* AlsaWrapper::DeviceNameGetHint(const void* hint, const char* id) {
     27   return snd_device_name_get_hint(hint, id);
     28 }
     29 
     30 int AlsaWrapper::DeviceNameFreeHint(void** hints) {
     31   return snd_device_name_free_hint(hints);
     32 }
     33 
     34 int AlsaWrapper::CardNext(int* rcard) {
     35   return snd_card_next(rcard);
     36 }
     37 
     38 int AlsaWrapper::PcmClose(snd_pcm_t* handle) {
     39   return snd_pcm_close(handle);
     40 }
     41 
     42 int AlsaWrapper::PcmPrepare(snd_pcm_t* handle) {
     43   return snd_pcm_prepare(handle);
     44 }
     45 
     46 int AlsaWrapper::PcmDrop(snd_pcm_t* handle) {
     47   return snd_pcm_drop(handle);
     48 }
     49 
     50 int AlsaWrapper::PcmDelay(snd_pcm_t* handle, snd_pcm_sframes_t* delay) {
     51   return snd_pcm_delay(handle, delay);
     52 }
     53 
     54 snd_pcm_sframes_t AlsaWrapper::PcmWritei(snd_pcm_t* handle,
     55                                          const void* buffer,
     56                                          snd_pcm_uframes_t size) {
     57   return snd_pcm_writei(handle, buffer, size);
     58 }
     59 
     60 snd_pcm_sframes_t AlsaWrapper::PcmReadi(snd_pcm_t* handle,
     61                                         void* buffer,
     62                                         snd_pcm_uframes_t size) {
     63   return snd_pcm_readi(handle, buffer, size);
     64 }
     65 
     66 int AlsaWrapper::PcmRecover(snd_pcm_t* handle, int err, int silent) {
     67   return snd_pcm_recover(handle, err, silent);
     68 }
     69 
     70 const char* AlsaWrapper::PcmName(snd_pcm_t* handle) {
     71   return snd_pcm_name(handle);
     72 }
     73 
     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,
     79                             format,
     80                             access,
     81                             channels,
     82                             rate,
     83                             soft_resample,
     84                             latency);
     85 }
     86 
     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);
     90 }
     91 
     92 snd_pcm_sframes_t AlsaWrapper::PcmAvailUpdate(snd_pcm_t* handle) {
     93   return snd_pcm_avail_update(handle);
     94 }
     95 
     96 snd_pcm_state_t AlsaWrapper::PcmState(snd_pcm_t* handle) {
     97   return snd_pcm_state(handle);
     98 }
     99 
    100 const char* AlsaWrapper::StrError(int errnum) {
    101   return snd_strerror(errnum);
    102 }
    103 
    104 int AlsaWrapper::PcmStart(snd_pcm_t* handle) {
    105   return snd_pcm_start(handle);
    106 }
    107 
    108 int AlsaWrapper::MixerOpen(snd_mixer_t** mixer, int mode) {
    109   return snd_mixer_open(mixer, mode);
    110 }
    111 
    112 int AlsaWrapper::MixerAttach(snd_mixer_t* mixer, const char* name) {
    113   return snd_mixer_attach(mixer, name);
    114 }
    115 
    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);
    120 }
    121 
    122 void AlsaWrapper::MixerFree(snd_mixer_t* mixer) {
    123   snd_mixer_free(mixer);
    124 }
    125 
    126 int AlsaWrapper::MixerDetach(snd_mixer_t* mixer, const char* name) {
    127   return snd_mixer_detach(mixer, name);
    128 }
    129 
    130 int AlsaWrapper::MixerClose(snd_mixer_t* mixer) {
    131   return snd_mixer_close(mixer);
    132 }
    133 
    134 int AlsaWrapper::MixerLoad(snd_mixer_t* mixer) {
    135   return snd_mixer_load(mixer);
    136 }
    137 
    138 snd_mixer_elem_t* AlsaWrapper::MixerFirstElem(snd_mixer_t* mixer) {
    139   return snd_mixer_first_elem(mixer);
    140 }
    141 
    142 snd_mixer_elem_t* AlsaWrapper::MixerNextElem(snd_mixer_elem_t* elem) {
    143   return snd_mixer_elem_next(elem);
    144 }
    145 
    146 int AlsaWrapper::MixerSelemIsActive(snd_mixer_elem_t* elem) {
    147   return snd_mixer_selem_is_active(elem);
    148 }
    149 
    150 const char* AlsaWrapper::MixerSelemName(snd_mixer_elem_t* elem) {
    151   return snd_mixer_selem_get_name(elem);
    152 }
    153 
    154 int AlsaWrapper::MixerSelemSetCaptureVolumeAll(
    155     snd_mixer_elem_t* elem, long value) {
    156   return snd_mixer_selem_set_capture_volume_all(elem, value);
    157 }
    158 
    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);
    162 }
    163 
    164 int AlsaWrapper::MixerSelemHasCaptureVolume(snd_mixer_elem_t* elem) {
    165   return snd_mixer_selem_has_capture_volume(elem);
    166 }
    167 
    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);
    171 }
    172 
    173 }  // namespace media
    174