alsa_device_profile.h revision 2a3925e95a9d4954be789dc4594233d4cc2d251c
14fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden/* 24fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden * Copyright (C) 2014 The Android Open Source Project 34fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden * 44fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden * Licensed under the Apache License, Version 2.0 (the "License"); 54fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden * you may not use this file except in compliance with the License. 64fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden * You may obtain a copy of the License at 74fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden * 84fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden * http://www.apache.org/licenses/LICENSE-2.0 94fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden * 104fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden * Unless required by applicable law or agreed to in writing, software 114fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden * distributed under the License is distributed on an "AS IS" BASIS, 124fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden * See the License for the specific language governing permissions and 144fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden * limitations under the License. 154fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden */ 164fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 174fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden#ifndef ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROFILE_H 184fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden#define ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROFILE_H 194fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 204fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden#include <stdbool.h> 214fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 224fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden#include <tinyalsa/asoundlib.h> 234fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 244fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden#define MAX_PROFILE_FORMATS 6 /* We long support the 5 standard formats defined 254fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden * in asound.h, so we just need this to be 1 more 264fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden * than that */ 274fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden#define MAX_PROFILE_SAMPLE_RATES 14 /* this number needs to be 1 more than the number of 284fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden * sample rates in std_sample_rates[] 294fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden * (in alsa_device_profile.c) */ 304fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden#define MAX_PROFILE_CHANNEL_COUNTS 9 /* this number need to be 1 more than the number of 314fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden * standard channel formats in std_channel_counts[] 324fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden * (in alsa_device_profile.c) */ 334fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 344fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden#define DEFAULT_SAMPLE_RATE 44100 354fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden#define DEFAULT_SAMPLE_FORMAT PCM_FORMAT_S16_LE 364fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden#define DEFAULT_CHANNEL_COUNT 2 374fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 384fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willdentypedef struct { 394fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden int card; 404fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden int device; 414fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden int direction; /* PCM_OUT or PCM_IN */ 424fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 434fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden enum pcm_format formats[MAX_PROFILE_FORMATS]; 444fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 454fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden unsigned sample_rates[MAX_PROFILE_SAMPLE_RATES]; 464fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 474fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden unsigned channel_counts[MAX_PROFILE_CHANNEL_COUNTS]; 484fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 494fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden bool is_valid; 504fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 514fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden /* read from the hardware device */ 524fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden struct pcm_config default_config; 534fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 544fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden unsigned min_period_size; 554fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden unsigned max_period_size; 564fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 574fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden unsigned min_channel_count; 584fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden unsigned max_channel_count; 594fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden} alsa_device_profile; 604fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 614fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willdenvoid profile_init(alsa_device_profile* profile, int direction); 624fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willdenbool profile_is_initialized(alsa_device_profile* profile); 634fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willdenbool profile_is_valid(alsa_device_profile* profile); 644fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willdenbool profile_is_cached_for(alsa_device_profile* profile, int card, int device); 654fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willdenvoid profile_decache(alsa_device_profile* profile); 664fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 674fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willdenbool profile_read_device_info(alsa_device_profile* profile); 684fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 694fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden/* Audio Config Strings Methods */ 704fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willdenchar * profile_get_sample_rate_strs(alsa_device_profile* profile); 714fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willdenchar * profile_get_format_strs(alsa_device_profile* profile); 724fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willdenchar * profile_get_channel_count_strs(alsa_device_profile* profile); 734fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 744fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden/* Sample Rate Methods */ 754fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willdenunsigned profile_get_default_sample_rate(alsa_device_profile* profile); 764fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willdenbool profile_is_sample_rate_valid(alsa_device_profile* profile, unsigned rate); 774fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 784fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden/* Format Methods */ 794fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willdenenum pcm_format profile_get_default_format(alsa_device_profile* profile); 804fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willdenbool profile_is_format_valid(alsa_device_profile* profile, enum pcm_format fmt); 814fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 824fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden/* Channel Methods */ 834fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willdenunsigned profile_get_default_channel_count(alsa_device_profile* profile); 844fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willdenbool profile_is_channel_count_valid(alsa_device_profile* profile, unsigned count); 854fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 864fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden/* Utility */ 874fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willdenunsigned profile_calc_min_period_size(alsa_device_profile* profile, unsigned sample_rate); 884fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willdenunsigned int profile_get_period_size(alsa_device_profile* profile, unsigned sample_rate); 894fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden 904fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden#endif /* ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROFILE_H */ 914fbc1d574b87ccea982db541220fabe93efb1f1cShawn Willden