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