Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROFILE_H
     18 #define ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROFILE_H
     19 
     20 #include <stdbool.h>
     21 
     22 #include <tinyalsa/asoundlib.h>
     23 
     24 #define MAX_PROFILE_FORMATS         6  /* We long support the 5 standard formats defined
     25                                         * in asound.h, so we just need this to be 1 more
     26                                         * than that */
     27 #define MAX_PROFILE_SAMPLE_RATES    14 /* this number needs to be 1 more than the number of
     28                                         * sample rates in std_sample_rates[]
     29                                         * (in alsa_device_profile.c) */
     30 #define MAX_PROFILE_CHANNEL_COUNTS  9  /* this number need to be 1 more than the number of
     31                                         * standard channel formats in std_channel_counts[]
     32                                         * (in alsa_device_profile.c) */
     33 
     34 #define DEFAULT_SAMPLE_RATE         44100
     35 #define DEFAULT_SAMPLE_FORMAT       PCM_FORMAT_S16_LE
     36 #define DEFAULT_CHANNEL_COUNT       2
     37 
     38 typedef struct  {
     39     int card;
     40     int device;
     41     int direction; /* PCM_OUT or PCM_IN */
     42 
     43     enum pcm_format formats[MAX_PROFILE_FORMATS];
     44 
     45     unsigned sample_rates[MAX_PROFILE_SAMPLE_RATES];
     46 
     47     unsigned channel_counts[MAX_PROFILE_CHANNEL_COUNTS];
     48 
     49     bool is_valid;
     50 
     51     /* read from the hardware device */
     52     struct pcm_config default_config;
     53 
     54     unsigned min_period_size;
     55     unsigned max_period_size;
     56 
     57     unsigned min_channel_count;
     58     unsigned max_channel_count;
     59 } alsa_device_profile;
     60 
     61 void profile_init(alsa_device_profile* profile, int direction);
     62 bool profile_is_initialized(alsa_device_profile* profile);
     63 bool profile_is_valid(alsa_device_profile* profile);
     64 bool profile_is_cached_for(alsa_device_profile* profile, int card, int device);
     65 void profile_decache(alsa_device_profile* profile);
     66 
     67 bool profile_read_device_info(alsa_device_profile* profile);
     68 
     69 /* Audio Config Strings Methods */
     70 char * profile_get_sample_rate_strs(alsa_device_profile* profile);
     71 char * profile_get_format_strs(alsa_device_profile* profile);
     72 char * profile_get_channel_count_strs(alsa_device_profile* profile);
     73 
     74 /* Sample Rate Methods */
     75 unsigned profile_get_default_sample_rate(alsa_device_profile* profile);
     76 bool profile_is_sample_rate_valid(alsa_device_profile* profile, unsigned rate);
     77 
     78 /* Format Methods */
     79 enum pcm_format profile_get_default_format(alsa_device_profile* profile);
     80 bool profile_is_format_valid(alsa_device_profile* profile, enum pcm_format fmt);
     81 
     82 /* Channel Methods */
     83 unsigned profile_get_default_channel_count(alsa_device_profile* profile);
     84 unsigned profile_get_closest_channel_count(alsa_device_profile* profile, unsigned count);
     85 bool profile_is_channel_count_valid(alsa_device_profile* profile, unsigned count);
     86 
     87 /* Utility */
     88 unsigned profile_calc_min_period_size(alsa_device_profile* profile, unsigned sample_rate);
     89 unsigned int profile_get_period_size(alsa_device_profile* profile, unsigned sample_rate);
     90 
     91 /* Debugging */
     92 void profile_dump(const alsa_device_profile* profile, int fd);
     93 
     94 #endif /* ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROFILE_H */
     95