198ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean/* 298ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean * Copyright (C) 2014 The Android Open Source Project 398ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean * 498ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean * Licensed under the Apache License, Version 2.0 (the "License"); 598ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean * you may not use this file except in compliance with the License. 698ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean * You may obtain a copy of the License at 798ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean * 898ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean * http://www.apache.org/licenses/LICENSE-2.0 998ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean * 1098ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean * Unless required by applicable law or agreed to in writing, software 1198ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean * distributed under the License is distributed on an "AS IS" BASIS, 1298ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1398ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean * See the License for the specific language governing permissions and 1498ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean * limitations under the License. 1598ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean */ 1698ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 1798ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean#ifndef ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROFILE_H 1898ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean#define ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROFILE_H 1998ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 2098ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean#include <stdbool.h> 2198ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 2298ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean#include <tinyalsa/asoundlib.h> 2398ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 2498ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean#define MAX_PROFILE_FORMATS 6 /* We long support the 5 standard formats defined 2598ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean * in asound.h, so we just need this to be 1 more 2698ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean * than that */ 27b290670d9ceb730556909afb4a5a28076b4e3771Andy Hung#define MAX_PROFILE_SAMPLE_RATES 14 /* this number needs to be 1 more than the number of 28b290670d9ceb730556909afb4a5a28076b4e3771Andy Hung * sample rates in std_sample_rates[] 2998ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean * (in alsa_device_profile.c) */ 30e7d87cb8c4440080189fdacc98225762ab8e7662Andy Hung#define MAX_PROFILE_CHANNEL_COUNTS 9 /* this number need to be 1 more than the number of 3198ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean * standard channel formats in std_channel_counts[] 3298ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean * (in alsa_device_profile.c) */ 3398ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 3498ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean#define DEFAULT_SAMPLE_RATE 44100 3598ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean#define DEFAULT_SAMPLE_FORMAT PCM_FORMAT_S16_LE 3698ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean#define DEFAULT_CHANNEL_COUNT 2 3798ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 3898ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLeantypedef struct { 3998ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean int card; 4098ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean int device; 4198ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean int direction; /* PCM_OUT or PCM_IN */ 4298ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 4398ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean enum pcm_format formats[MAX_PROFILE_FORMATS]; 4498ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 45948a6a4ba0fdda99dc36bfc2ff9dec121792c051Paul McLean /* note that this list is sorted highest rate to lowest */ 4698ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean unsigned sample_rates[MAX_PROFILE_SAMPLE_RATES]; 4798ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 4898ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean unsigned channel_counts[MAX_PROFILE_CHANNEL_COUNTS]; 4998ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 5098ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean bool is_valid; 5198ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 5298ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean /* read from the hardware device */ 5398ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean struct pcm_config default_config; 5498ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 5598ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean unsigned min_period_size; 5698ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean unsigned max_period_size; 5798ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 5898ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean unsigned min_channel_count; 5998ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean unsigned max_channel_count; 6098ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean} alsa_device_profile; 6198ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 6298ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLeanvoid profile_init(alsa_device_profile* profile, int direction); 632c95978c66d7e030b53832b6a61bfca51694ab9fAndy Hungbool profile_is_initialized(const alsa_device_profile* profile); 642c95978c66d7e030b53832b6a61bfca51694ab9fAndy Hungbool profile_is_valid(const alsa_device_profile* profile); 652c95978c66d7e030b53832b6a61bfca51694ab9fAndy Hungbool profile_is_cached_for(const alsa_device_profile* profile, int card, int device); 6698ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLeanvoid profile_decache(alsa_device_profile* profile); 6798ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 6898ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLeanbool profile_read_device_info(alsa_device_profile* profile); 6998ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 7098ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean/* Audio Config Strings Methods */ 712c95978c66d7e030b53832b6a61bfca51694ab9fAndy Hungchar * profile_get_sample_rate_strs(const alsa_device_profile* profile); 722c95978c66d7e030b53832b6a61bfca51694ab9fAndy Hungchar * profile_get_format_strs(const alsa_device_profile* profile); 732c95978c66d7e030b53832b6a61bfca51694ab9fAndy Hungchar * profile_get_channel_count_strs(const alsa_device_profile* profile); 7498ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 7598ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean/* Sample Rate Methods */ 762c95978c66d7e030b53832b6a61bfca51694ab9fAndy Hungunsigned profile_get_default_sample_rate(const alsa_device_profile* profile); 772c95978c66d7e030b53832b6a61bfca51694ab9fAndy Hungbool profile_is_sample_rate_valid(const alsa_device_profile* profile, unsigned rate); 7898ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 7998ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean/* Format Methods */ 802c95978c66d7e030b53832b6a61bfca51694ab9fAndy Hungenum pcm_format profile_get_default_format(const alsa_device_profile* profile); 812c95978c66d7e030b53832b6a61bfca51694ab9fAndy Hungbool profile_is_format_valid(const alsa_device_profile* profile, enum pcm_format fmt); 8298ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 8398ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean/* Channel Methods */ 842c95978c66d7e030b53832b6a61bfca51694ab9fAndy Hungunsigned profile_get_default_channel_count(const alsa_device_profile* profile); 852c95978c66d7e030b53832b6a61bfca51694ab9fAndy Hungunsigned profile_get_closest_channel_count(const alsa_device_profile* profile, unsigned count); 862c95978c66d7e030b53832b6a61bfca51694ab9fAndy Hungbool profile_is_channel_count_valid(const alsa_device_profile* profile, unsigned count); 8798ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 8898ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean/* Utility */ 892c95978c66d7e030b53832b6a61bfca51694ab9fAndy Hungunsigned profile_calc_min_period_size(const alsa_device_profile* profile, unsigned sample_rate); 902c95978c66d7e030b53832b6a61bfca51694ab9fAndy Hungunsigned int profile_get_period_size(const alsa_device_profile* profile, unsigned sample_rate); 9198ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean 9221b04ade57e5cbf33eff11f3f400f77eed5e2e75Paul McLean/* Debugging */ 9321b04ade57e5cbf33eff11f3f400f77eed5e2e75Paul McLeanvoid profile_dump(const alsa_device_profile* profile, int fd); 9421b04ade57e5cbf33eff11f3f400f77eed5e2e75Paul McLean 9598ca8d42b782987cd1ceb370c10460c3eb79223ePaul McLean#endif /* ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROFILE_H */ 96