Lines Matching refs:profile
61 static void profile_reset(alsa_device_profile* profile) in profile_reset() argument
63 profile->card = profile->device = -1; in profile_reset()
66 profile->formats[0] = PCM_FORMAT_INVALID; in profile_reset()
67 profile->sample_rates[0] = 0; in profile_reset()
68 profile->channel_counts[0] = 0; in profile_reset()
70 profile->min_period_size = profile->max_period_size = 0; in profile_reset()
71 profile->min_channel_count = profile->max_channel_count = DEFAULT_CHANNEL_COUNT; in profile_reset()
73 profile->is_valid = false; in profile_reset()
76 void profile_init(alsa_device_profile* profile, int direction) in profile_init() argument
78 profile->direction = direction; in profile_init()
79 profile_reset(profile); in profile_init()
82 bool profile_is_initialized(alsa_device_profile* profile) in profile_is_initialized() argument
84 return profile->card >= 0 && profile->device >= 0; in profile_is_initialized()
87 bool profile_is_valid(alsa_device_profile* profile) { in profile_is_valid() argument
88 return profile->is_valid; in profile_is_valid()
91 bool profile_is_cached_for(alsa_device_profile* profile, int card, int device) { in profile_is_cached_for() argument
92 return card == profile->card && device == profile->device; in profile_is_cached_for()
95 void profile_decache(alsa_device_profile* profile) { in profile_decache() argument
96 profile_reset(profile); in profile_decache()
110 unsigned profile_calc_min_period_size(alsa_device_profile* profile, unsigned sample_rate) in profile_calc_min_period_size() argument
112 ALOGV("profile_calc_min_period_size(%p, rate:%d)", profile, sample_rate); in profile_calc_min_period_size()
113 if (profile == NULL) { in profile_calc_min_period_size()
117 if (num_sample_frames < profile->min_period_size) { in profile_calc_min_period_size()
118 num_sample_frames = profile->min_period_size; in profile_calc_min_period_size()
124 unsigned int profile_get_period_size(alsa_device_profile* profile, unsigned sample_rate) in profile_get_period_size() argument
126 unsigned int period_size = profile_calc_min_period_size(profile, sample_rate); in profile_get_period_size()
134 unsigned profile_get_default_sample_rate(alsa_device_profile* profile) in profile_get_default_sample_rate() argument
140 return profile_is_valid(profile) ? profile->sample_rates[0] : DEFAULT_SAMPLE_RATE; in profile_get_default_sample_rate()
143 bool profile_is_sample_rate_valid(alsa_device_profile* profile, unsigned rate) in profile_is_sample_rate_valid() argument
145 if (profile_is_valid(profile)) { in profile_is_sample_rate_valid()
147 for (index = 0; profile->sample_rates[index] != 0; index++) { in profile_is_sample_rate_valid()
148 if (profile->sample_rates[index] == rate) { in profile_is_sample_rate_valid()
162 enum pcm_format profile_get_default_format(alsa_device_profile* profile) in profile_get_default_format() argument
167 return profile_is_valid(profile) ? profile->formats[0] : DEFAULT_SAMPLE_FORMAT; in profile_get_default_format()
170 bool profile_is_format_valid(alsa_device_profile* profile, enum pcm_format fmt) { in profile_is_format_valid() argument
171 if (profile_is_valid(profile)) { in profile_is_format_valid()
173 for (index = 0; profile->formats[index] != PCM_FORMAT_INVALID; index++) { in profile_is_format_valid()
174 if (profile->formats[index] == fmt) { in profile_is_format_valid()
188 unsigned profile_get_default_channel_count(alsa_device_profile* profile) in profile_get_default_channel_count() argument
190 return profile_is_valid(profile) ? profile->channel_counts[0] : DEFAULT_CHANNEL_COUNT; in profile_get_default_channel_count()
193 bool profile_is_channel_count_valid(alsa_device_profile* profile, unsigned count) in profile_is_channel_count_valid() argument
195 if (profile_is_initialized(profile)) { in profile_is_channel_count_valid()
196 return count >= profile->min_channel_count && count <= profile->max_channel_count; in profile_is_channel_count_valid()
202 static bool profile_test_sample_rate(alsa_device_profile* profile, unsigned rate) in profile_test_sample_rate() argument
204 struct pcm_config config = profile->default_config; in profile_test_sample_rate()
208 struct pcm * pcm = pcm_open(profile->card, profile->device, in profile_test_sample_rate()
209 profile->direction, &config); in profile_test_sample_rate()
219 static unsigned profile_enum_sample_rates(alsa_device_profile* profile, unsigned min, unsigned max) in profile_enum_sample_rates() argument
225 num_entries < ARRAY_SIZE(profile->sample_rates) - 1; in profile_enum_sample_rates()
228 && profile_test_sample_rate(profile, std_sample_rates[index])) { in profile_enum_sample_rates()
229 profile->sample_rates[num_entries++] = std_sample_rates[index]; in profile_enum_sample_rates()
232 profile->sample_rates[num_entries] = 0; /* terminate */ in profile_enum_sample_rates()
236 static unsigned profile_enum_sample_formats(alsa_device_profile* profile, struct pcm_mask * mask) in profile_enum_sample_formats() argument
256 profile->formats[num_written++] = format; in profile_enum_sample_formats()
257 if (num_written == ARRAY_SIZE(profile->formats) - 1) { in profile_enum_sample_formats()
268 profile->formats[num_written] = PCM_FORMAT_INVALID; in profile_enum_sample_formats()
272 static unsigned profile_enum_channel_counts(alsa_device_profile* profile, unsigned min, in profile_enum_channel_counts() argument
283 num_counts < ARRAY_SIZE(profile->channel_counts) - 1; in profile_enum_channel_counts()
288 profile->channel_counts[num_counts++] = std_channel_counts[index]; in profile_enum_channel_counts()
291 profile->channel_counts[num_counts] = 0; in profile_enum_channel_counts()
298 static int read_alsa_device_config(alsa_device_profile * profile, struct pcm_config * config) in read_alsa_device_config() argument
301 profile->card, profile->device, profile->direction); in read_alsa_device_config()
303 if (profile->card < 0 || profile->device < 0) { in read_alsa_device_config()
308 pcm_params_get(profile->card, profile->device, profile->direction); in read_alsa_device_config()
313 profile->min_period_size = pcm_params_get_min(alsa_hw_params, PCM_PARAM_PERIOD_SIZE); in read_alsa_device_config()
314 profile->max_period_size = pcm_params_get_max(alsa_hw_params, PCM_PARAM_PERIOD_SIZE); in read_alsa_device_config()
316 profile->min_channel_count = pcm_params_get_min(alsa_hw_params, PCM_PARAM_CHANNELS); in read_alsa_device_config()
317 profile->max_channel_count = pcm_params_get_max(alsa_hw_params, PCM_PARAM_CHANNELS); in read_alsa_device_config()
330 config->period_size = profile_calc_min_period_size(profile, config->rate); in read_alsa_device_config()
345 bool profile_read_device_info(alsa_device_profile* profile) in profile_read_device_info() argument
347 if (!profile_is_initialized(profile)) { in profile_read_device_info()
352 read_alsa_device_config(profile, &profile->default_config); in profile_read_device_info()
354 profile->default_config.channels, profile->default_config.rate, in profile_read_device_info()
355 profile->default_config.format, profile->default_config.period_count, in profile_read_device_info()
356 profile->default_config.period_size); in profile_read_device_info()
358 struct pcm_params * alsa_hw_params = pcm_params_get(profile->card, in profile_read_device_info()
359 profile->device, in profile_read_device_info()
360 profile->direction); in profile_read_device_info()
367 profile_enum_sample_formats(profile, format_mask); in profile_read_device_info()
371 profile, pcm_params_get_min(alsa_hw_params, PCM_PARAM_CHANNELS), in profile_read_device_info()
376 profile, pcm_params_get_min(alsa_hw_params, PCM_PARAM_RATE), in profile_read_device_info()
379 profile->is_valid = true; in profile_read_device_info()
384 char * profile_get_sample_rate_strs(alsa_device_profile* profile) in profile_get_sample_rate_strs() argument
399 for (index = 0; profile->sample_rates[index] != 0; index++) { in profile_get_sample_rate_strs()
400 snprintf(numBuffer, sizeof(numBuffer), "%u", profile->sample_rates[index]); in profile_get_sample_rate_strs()
417 char * profile_get_format_strs(alsa_device_profile* profile) in profile_get_format_strs() argument
430 for (index = 0; profile->formats[index] != PCM_FORMAT_INVALID; index++) { in profile_get_format_strs()
432 if (buffSize - curStrLen < strlen(format_string_map[profile->formats[index]]) in profile_get_format_strs()
442 curStrLen = strlcat(buffer, format_string_map[profile->formats[index]], buffSize); in profile_get_format_strs()
448 char * profile_get_channel_count_strs(alsa_device_profile* profile) in profile_get_channel_count_strs() argument
484 const bool isOutProfile = profile->direction == PCM_OUT; in profile_get_channel_count_strs()
513 (channel_count = profile->channel_counts[index]) != 0; in profile_get_channel_count_strs()