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()
64 profile->extra_latency_ms = 0; in profile_reset()
67 profile->formats[0] = PCM_FORMAT_INVALID; in profile_reset()
68 profile->sample_rates[0] = 0; in profile_reset()
69 profile->channel_counts[0] = 0; in profile_reset()
71 profile->min_period_size = profile->max_period_size = 0; in profile_reset()
72 profile->min_channel_count = profile->max_channel_count = DEFAULT_CHANNEL_COUNT; in profile_reset()
74 profile->is_valid = false; in profile_reset()
77 void profile_init(alsa_device_profile* profile, int direction) in profile_init() argument
79 profile->direction = direction; in profile_init()
80 profile_reset(profile); in profile_init()
83 bool profile_is_initialized(const alsa_device_profile* profile) in profile_is_initialized() argument
85 return profile->card >= 0 && profile->device >= 0; in profile_is_initialized()
88 bool profile_is_valid(const alsa_device_profile* profile) { in profile_is_valid() argument
89 return profile->is_valid; in profile_is_valid()
92 bool profile_is_cached_for(const alsa_device_profile* profile, int card, int device) { in profile_is_cached_for() argument
93 return card == profile->card && device == profile->device; in profile_is_cached_for()
96 void profile_decache(alsa_device_profile* profile) { in profile_decache() argument
97 profile_reset(profile); in profile_decache()
111 unsigned profile_calc_min_period_size(const alsa_device_profile* profile, unsigned sample_rate) in profile_calc_min_period_size() argument
113 ALOGV("profile_calc_min_period_size(%p, rate:%d)", profile, sample_rate); in profile_calc_min_period_size()
114 if (profile == NULL) { in profile_calc_min_period_size()
120 if (num_sample_frames < profile->min_period_size) { in profile_calc_min_period_size()
121 num_sample_frames = profile->min_period_size; in profile_calc_min_period_size()
127 unsigned int profile_get_period_size(const alsa_device_profile* profile, unsigned sample_rate) in profile_get_period_size() argument
129 unsigned int period_size = profile_calc_min_period_size(profile, sample_rate); in profile_get_period_size()
137 unsigned profile_get_default_sample_rate(const alsa_device_profile* profile) in profile_get_default_sample_rate() argument
148 return profile_is_valid(profile) ? profile->sample_rates[0] : DEFAULT_SAMPLE_RATE; in profile_get_default_sample_rate()
151 unsigned profile_get_highest_sample_rate(const alsa_device_profile* profile) { in profile_get_highest_sample_rate() argument
156 return profile->sample_rates[0]; in profile_get_highest_sample_rate()
159 bool profile_is_sample_rate_valid(const alsa_device_profile* profile, unsigned rate) in profile_is_sample_rate_valid() argument
161 if (profile_is_valid(profile)) { in profile_is_sample_rate_valid()
163 for (index = 0; profile->sample_rates[index] != 0; index++) { in profile_is_sample_rate_valid()
164 if (profile->sample_rates[index] == rate) { in profile_is_sample_rate_valid()
179 enum pcm_format profile_get_default_format(const alsa_device_profile* profile) in profile_get_default_format() argument
184 return profile_is_valid(profile) ? profile->formats[0] : DEFAULT_SAMPLE_FORMAT; in profile_get_default_format()
187 bool profile_is_format_valid(const alsa_device_profile* profile, enum pcm_format fmt) { in profile_is_format_valid() argument
188 if (profile_is_valid(profile)) { in profile_is_format_valid()
190 for (index = 0; profile->formats[index] != PCM_FORMAT_INVALID; index++) { in profile_is_format_valid()
191 if (profile->formats[index] == fmt) { in profile_is_format_valid()
205 unsigned profile_get_default_channel_count(const alsa_device_profile* profile) in profile_get_default_channel_count() argument
207 return profile_is_valid(profile) ? profile->channel_counts[0] : DEFAULT_CHANNEL_COUNT; in profile_get_default_channel_count()
210 unsigned profile_get_closest_channel_count(const alsa_device_profile* profile, unsigned count) in profile_get_closest_channel_count() argument
212 if (profile_is_valid(profile)) { in profile_get_closest_channel_count()
213 if (count < profile->min_channel_count) { in profile_get_closest_channel_count()
214 return profile->min_channel_count; in profile_get_closest_channel_count()
215 } else if (count > profile->max_channel_count) { in profile_get_closest_channel_count()
216 return profile->max_channel_count; in profile_get_closest_channel_count()
225 bool profile_is_channel_count_valid(const alsa_device_profile* profile, unsigned count) in profile_is_channel_count_valid() argument
227 if (profile_is_initialized(profile)) { in profile_is_channel_count_valid()
228 return count >= profile->min_channel_count && count <= profile->max_channel_count; in profile_is_channel_count_valid()
234 static bool profile_test_sample_rate(const alsa_device_profile* profile, unsigned rate) in profile_test_sample_rate() argument
236 struct pcm_config config = profile->default_config; in profile_test_sample_rate()
259 config.channels = profile->max_channel_count; in profile_test_sample_rate()
263 struct pcm * pcm = pcm_open(profile->card, profile->device, in profile_test_sample_rate()
264 profile->direction, &config); in profile_test_sample_rate()
274 static unsigned profile_enum_sample_rates(alsa_device_profile* profile, unsigned min, unsigned max) in profile_enum_sample_rates() argument
280 num_entries < ARRAY_SIZE(profile->sample_rates) - 1; in profile_enum_sample_rates()
283 && profile_test_sample_rate(profile, std_sample_rates[index])) { in profile_enum_sample_rates()
284 profile->sample_rates[num_entries++] = std_sample_rates[index]; in profile_enum_sample_rates()
287 profile->sample_rates[num_entries] = 0; /* terminate */ in profile_enum_sample_rates()
291 static unsigned profile_enum_sample_formats(alsa_device_profile* profile, in profile_enum_sample_formats() argument
312 profile->formats[num_written++] = format; in profile_enum_sample_formats()
313 if (num_written == ARRAY_SIZE(profile->formats) - 1) { in profile_enum_sample_formats()
324 profile->formats[num_written] = PCM_FORMAT_INVALID; in profile_enum_sample_formats()
328 static unsigned profile_enum_channel_counts(alsa_device_profile* profile, unsigned min, in profile_enum_channel_counts() argument
347 num_counts < ARRAY_SIZE(profile->channel_counts) - 1; in profile_enum_channel_counts()
354 profile->channel_counts[num_counts++] = test_count; in profile_enum_channel_counts()
367 profile->channel_counts[num_counts++] = std_channel_counts[max_allowed_index]; in profile_enum_channel_counts()
369 profile->channel_counts[num_counts] = 0; in profile_enum_channel_counts()
376 static int read_alsa_device_config(alsa_device_profile * profile, struct pcm_config * config) in read_alsa_device_config() argument
379 profile->card, profile->device, profile->direction); in read_alsa_device_config()
381 if (profile->card < 0 || profile->device < 0) { in read_alsa_device_config()
386 pcm_params_get(profile->card, profile->device, profile->direction); in read_alsa_device_config()
391 profile->min_period_size = pcm_params_get_min(alsa_hw_params, PCM_PARAM_PERIOD_SIZE); in read_alsa_device_config()
392 profile->max_period_size = pcm_params_get_max(alsa_hw_params, PCM_PARAM_PERIOD_SIZE); in read_alsa_device_config()
394 profile->min_channel_count = pcm_params_get_min(alsa_hw_params, PCM_PARAM_CHANNELS); in read_alsa_device_config()
395 profile->max_channel_count = pcm_params_get_max(alsa_hw_params, PCM_PARAM_CHANNELS); in read_alsa_device_config()
409 if (profile->direction == PCM_OUT && in read_alsa_device_config()
422 config->period_size = profile_calc_min_period_size(profile, config->rate); in read_alsa_device_config()
437 bool profile_fill_builtin_device_info(alsa_device_profile* profile, struct pcm_config* config, in profile_fill_builtin_device_info() argument
439 if (!profile_is_initialized(profile)) { in profile_fill_builtin_device_info()
442 profile->extra_latency_ms = property_get_int32( in profile_fill_builtin_device_info()
444 profile->default_config.channels = config->channels; in profile_fill_builtin_device_info()
445 profile->default_config.rate = config->rate; in profile_fill_builtin_device_info()
446 profile->default_config.format = config->format; in profile_fill_builtin_device_info()
450 profile->default_config.period_count = period_count; in profile_fill_builtin_device_info()
454 profile->default_config.period_size = in profile_fill_builtin_device_info()
456 profile->min_period_size = profile->max_period_size = profile->default_config.period_size; in profile_fill_builtin_device_info()
457 profile->formats[0] = config->format; in profile_fill_builtin_device_info()
458 profile->formats[1] = PCM_FORMAT_INVALID; in profile_fill_builtin_device_info()
459 profile->channel_counts[0] = config->channels; in profile_fill_builtin_device_info()
460 profile->channel_counts[1] = 0; in profile_fill_builtin_device_info()
461 profile->min_channel_count = profile->max_channel_count = config->channels; in profile_fill_builtin_device_info()
462 profile->sample_rates[0] = config->rate; in profile_fill_builtin_device_info()
463 profile->sample_rates[1] = 0; in profile_fill_builtin_device_info()
464 profile->is_valid = true; in profile_fill_builtin_device_info()
468 bool profile_read_device_info(alsa_device_profile* profile) in profile_read_device_info() argument
470 if (!profile_is_initialized(profile)) { in profile_read_device_info()
475 read_alsa_device_config(profile, &profile->default_config); in profile_read_device_info()
477 profile->default_config.channels, profile->default_config.rate, in profile_read_device_info()
478 profile->default_config.format, profile->default_config.period_count, in profile_read_device_info()
479 profile->default_config.period_size); in profile_read_device_info()
481 struct pcm_params * alsa_hw_params = pcm_params_get(profile->card, in profile_read_device_info()
482 profile->device, in profile_read_device_info()
483 profile->direction); in profile_read_device_info()
490 profile_enum_sample_formats(profile, format_mask); in profile_read_device_info()
494 profile, pcm_params_get_min(alsa_hw_params, PCM_PARAM_CHANNELS), in profile_read_device_info()
499 profile, pcm_params_get_min(alsa_hw_params, PCM_PARAM_RATE), in profile_read_device_info()
502 profile->is_valid = true; in profile_read_device_info()
508 char * profile_get_sample_rate_strs(const alsa_device_profile* profile) in profile_get_sample_rate_strs() argument
523 for (index = 0; profile->sample_rates[index] != 0; index++) { in profile_get_sample_rate_strs()
524 snprintf(numBuffer, sizeof(numBuffer), "%u", profile->sample_rates[index]); in profile_get_sample_rate_strs()
541 char * profile_get_format_strs(const alsa_device_profile* profile) in profile_get_format_strs() argument
554 for (index = 0; profile->formats[index] != PCM_FORMAT_INVALID; index++) { in profile_get_format_strs()
556 if (buffSize - curStrLen < strlen(format_string_map[profile->formats[index]]) in profile_get_format_strs()
566 curStrLen = strlcat(buffer, format_string_map[profile->formats[index]], buffSize); in profile_get_format_strs()
572 char * profile_get_channel_count_strs(const alsa_device_profile* profile) in profile_get_channel_count_strs() argument
624 const bool isOutProfile = profile->direction == PCM_OUT; in profile_get_channel_count_strs()
657 (channel_count = profile->channel_counts[index]) != 0; in profile_get_channel_count_strs()
694 void profile_dump(const alsa_device_profile* profile, int fd) in profile_dump() argument
696 if (profile == NULL) { in profile_dump()
701 if (!profile->is_valid) { in profile_dump()
707 profile->card, profile->device, profile->direction == PCM_OUT ? "OUT" : "IN"); in profile_dump()
712 fmtIndex < MAX_PROFILE_FORMATS && profile->formats[fmtIndex] != PCM_FORMAT_INVALID; in profile_dump()
714 dprintf(fd, "%d ", profile->formats[fmtIndex]); in profile_dump()
721 rateIndex < MAX_PROFILE_SAMPLE_RATES && profile->sample_rates[rateIndex] != 0; in profile_dump()
723 dprintf(fd, "%u ", profile->sample_rates[rateIndex]); in profile_dump()
730 cntIndex < MAX_PROFILE_CHANNEL_COUNTS && profile->channel_counts[cntIndex] != 0; in profile_dump()
732 dprintf(fd, "%u ", profile->channel_counts[cntIndex]); in profile_dump()
737 profile->min_period_size,profile-> max_period_size); in profile_dump()
739 profile->min_channel_count, profile->max_channel_count); in profile_dump()
743 dprintf(fd, " channels: %d\n", profile->default_config.channels); in profile_dump()
744 dprintf(fd, " rate: %d\n", profile->default_config.rate); in profile_dump()
745 dprintf(fd, " period_size: %d\n", profile->default_config.period_size); in profile_dump()
746 dprintf(fd, " period_count: %d\n", profile->default_config.period_count); in profile_dump()
747 dprintf(fd, " format: %d\n", profile->default_config.format); in profile_dump()