Lines Matching defs: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) {
119 if (num_sample_frames < profile->min_period_size) {
120 num_sample_frames = profile->min_period_size;
126 unsigned int profile_get_period_size(alsa_device_profile* profile, unsigned sample_rate)
128 unsigned int period_size = profile_calc_min_period_size(profile, sample_rate);
136 unsigned profile_get_default_sample_rate(alsa_device_profile* profile)
142 return profile_is_valid(profile) ? profile->sample_rates[0] : DEFAULT_SAMPLE_RATE;
145 bool profile_is_sample_rate_valid(alsa_device_profile* profile, unsigned rate)
147 if (profile_is_valid(profile)) {
149 for (index = 0; profile->sample_rates[index] != 0; index++) {
150 if (profile->sample_rates[index] == rate) {
164 enum pcm_format profile_get_default_format(alsa_device_profile* profile)
169 return profile_is_valid(profile) ? profile->formats[0] : DEFAULT_SAMPLE_FORMAT;
172 bool profile_is_format_valid(alsa_device_profile* profile, enum pcm_format fmt) {
173 if (profile_is_valid(profile)) {
175 for (index = 0; profile->formats[index] != PCM_FORMAT_INVALID; index++) {
176 if (profile->formats[index] == fmt) {
190 unsigned profile_get_default_channel_count(alsa_device_profile* profile)
192 return profile_is_valid(profile) ? profile->channel_counts[0] : DEFAULT_CHANNEL_COUNT;
195 bool profile_is_channel_count_valid(alsa_device_profile* profile, unsigned count)
197 if (profile_is_initialized(profile)) {
198 return count >= profile->min_channel_count && count <= profile->max_channel_count;
204 static bool profile_test_sample_rate(alsa_device_profile* profile, unsigned rate)
206 struct pcm_config config = profile->default_config;
210 struct pcm * pcm = pcm_open(profile->card, profile->device,
211 profile->direction, &config);
221 static unsigned profile_enum_sample_rates(alsa_device_profile* profile, unsigned min, unsigned max)
227 num_entries < ARRAY_SIZE(profile->sample_rates) - 1;
230 && profile_test_sample_rate(profile, std_sample_rates[index])) {
231 profile->sample_rates[num_entries++] = std_sample_rates[index];
234 profile->sample_rates[num_entries] = 0; /* terminate */
238 static unsigned profile_enum_sample_formats(alsa_device_profile* profile, struct pcm_mask * mask)
258 profile->formats[num_written++] = format;
259 if (num_written == ARRAY_SIZE(profile->formats) - 1) {
270 profile->formats[num_written] = PCM_FORMAT_INVALID;
274 static unsigned profile_enum_channel_counts(alsa_device_profile* profile, unsigned min,
285 num_counts < ARRAY_SIZE(profile->channel_counts) - 1;
289 profile_test_channel_count(profile, channel_counts[index])*/) {
290 profile->channel_counts[num_counts++] = std_channel_counts[index];
297 profile->channel_counts[num_counts++] = std_channel_counts[0];
299 profile->channel_counts[num_counts] = 0;
306 static int read_alsa_device_config(alsa_device_profile * profile, struct pcm_config * config)
309 profile->card, profile->device, profile->direction);
311 if (profile->card < 0 || profile->device < 0) {
316 pcm_params_get(profile->card, profile->device, profile->direction);
321 profile->min_period_size = pcm_params_get_min(alsa_hw_params, PCM_PARAM_PERIOD_SIZE);
322 profile->max_period_size = pcm_params_get_max(alsa_hw_params, PCM_PARAM_PERIOD_SIZE);
324 profile->min_channel_count = pcm_params_get_min(alsa_hw_params, PCM_PARAM_CHANNELS);
325 profile->max_channel_count = pcm_params_get_max(alsa_hw_params, PCM_PARAM_CHANNELS);
339 if (profile->direction == PCM_OUT &&
352 config->period_size = profile_calc_min_period_size(profile, config->rate);
367 bool profile_read_device_info(alsa_device_profile* profile)
369 if (!profile_is_initialized(profile)) {
374 read_alsa_device_config(profile, &profile->default_config);
376 profile->default_config.channels, profile->default_config.rate,
377 profile->default_config.format, profile->default_config.period_count,
378 profile->default_config.period_size);
380 struct pcm_params * alsa_hw_params = pcm_params_get(profile->card,
381 profile->device,
382 profile->direction);
389 profile_enum_sample_formats(profile, format_mask);
393 profile, pcm_params_get_min(alsa_hw_params, PCM_PARAM_CHANNELS),
398 profile, pcm_params_get_min(alsa_hw_params, PCM_PARAM_RATE),
401 profile->is_valid = true;
406 char * profile_get_sample_rate_strs(alsa_device_profile* profile)
421 for (index = 0; profile->sample_rates[index] != 0; index++) {
422 snprintf(numBuffer, sizeof(numBuffer), "%u", profile->sample_rates[index]);
439 char * profile_get_format_strs(alsa_device_profile* profile)
452 for (index = 0; profile->formats[index] != PCM_FORMAT_INVALID; index++) {
454 if (buffSize - curStrLen < strlen(format_string_map[profile->formats[index]])
464 curStrLen = strlcat(buffer, format_string_map[profile->formats[index]], buffSize);
470 char * profile_get_channel_count_strs(alsa_device_profile* profile)
506 const bool isOutProfile = profile->direction == PCM_OUT;
535 (channel_count = profile->channel_counts[index]) != 0;