Lines Matching defs:in
5 * you may not use this file except in compliance with the License.
10 * Unless required by applicable law or agreed to in writing, software
66 /* ToDo: Check and update a proper value in msec */
367 static void register_in_stream(struct stream_in *in)
369 struct audio_device *adev = in->dev;
374 in->capture_handle,
375 in->flags);
380 if (in->realtime) {
382 in->capture_handle,
383 in->pcm,
384 &in->config);
399 static void request_in_focus(struct stream_in *in, long ns)
401 struct audio_device *adev = in->dev;
404 adev->adm_request_focus_v2(adev->adm_data, in->capture_handle, ns);
406 adev->adm_request_focus(adev->adm_data, in->capture_handle);
418 static void release_in_focus(struct stream_in *in, long ns __unused)
420 struct audio_device *adev = in->dev;
422 adev->adm_abandon_focus(adev->adm_data, in->capture_handle);
811 // and a new usecase requests one device in this combo pair.
982 * Do not handle stereo output in Multi-channel cases
983 * Stereo case is handled in normal playback path
1230 usecase->devices = usecase->stream.in->device;
1292 * Limitation: While in call, to do a device switch we need to disable
1318 * the devices to reduce in-call device switch time.
1375 static int stop_input_stream(struct stream_in *in)
1379 struct audio_device *adev = in->dev;
1382 in->usecase, use_case_table[in->usecase]);
1385 if (adev->active_input->usecase == in->usecase) {
1388 ALOGW("%s adev->active_input->usecase %s, v/s in->usecase %s",
1391 use_case_table[in->usecase]);
1395 uc_info = get_usecase_from_list(adev, in->usecase);
1397 ALOGE("%s: Could not find the usecase (%d) in the list",
1398 __func__, in->usecase);
1402 /* Close in-call recording streams */
1403 voice_check_and_stop_incall_rec_usecase(adev, in);
1418 int start_input_stream(struct stream_in *in)
1423 struct audio_device *adev = in->dev;
1425 ALOGV("%s: enter: usecase(%d)", __func__, in->usecase);
1430 if (in->card_status == CARD_STATUS_OFFLINE ||
1432 ALOGW("in->card_status or adev->card_status offline, try again");
1438 ret = voice_check_and_set_incall_rec_usecase(adev, in);
1442 ALOGV("%s: usecase(%d)", __func__, in->usecase);
1444 in->pcm_device_id = platform_get_pcm_device_id(in->usecase, PCM_CAPTURE);
1445 if (in->pcm_device_id < 0) {
1447 __func__, in->usecase);
1452 adev->active_input = in;
1454 uc_info->id = in->usecase;
1456 uc_info->stream.in = in;
1457 uc_info->devices = in->device;
1465 select_devices(adev, in->usecase);
1467 if (in->usecase == USECASE_AUDIO_RECORD_MMAP) {
1468 if (in->pcm == NULL || !pcm_is_ready(in->pcm)) {
1472 ret = pcm_start(in->pcm);
1481 if (in->usecase == USECASE_AUDIO_RECORD_AFE_PROXY) {
1484 } else if (in->realtime) {
1489 __func__, adev->snd_card, in->pcm_device_id, in->config.channels);
1492 in->pcm = pcm_open(adev->snd_card, in->pcm_device_id,
1493 flags, &in->config);
1494 if (in->pcm == NULL || !pcm_is_ready(in->pcm)) {
1495 ALOGE("%s: %s", __func__, pcm_get_error(in->pcm));
1496 if (in->pcm != NULL) {
1497 pcm_close(in->pcm);
1498 in->pcm = NULL;
1511 ret = pcm_prepare(in->pcm);
1514 pcm_close(in->pcm);
1515 in->pcm = NULL;
1518 if (in->realtime) {
1519 ret = pcm_start(in->pcm);
1522 pcm_close(in->pcm);
1523 in->pcm = NULL;
1528 register_in_stream(in);
1535 stop_input_stream(in);
1544 void lock_input_stream(struct stream_in *in)
1546 pthread_mutex_lock(&in->pre_lock);
1547 pthread_mutex_lock(&in->lock);
1548 pthread_mutex_unlock(&in->pre_lock);
1721 ALOGV("%s: voice call is active, no change in HDMI channels",
1727 "no change in HDMI channels", __func__);
1742 /* Check if change in HDMI channel config is allowed */
1792 ALOGE("%s: Could not find the usecase (%d) in the list",
2161 // If we're not in standby, we may be blocked on a write.
2246 // By forcing the stream in standby, the usb stack refcount drops to 0
2250 ALOGD("%s() putting the usb device in standby after disconnection", __func__);
2285 * backend to the new device. Refer to check_and_route_playback_usecases() in
2435 // snprintf already put a \0 in place.
2535 // if in standby, cached volume will be sent after stream is opened
2547 // removed first in close_output_stream (as is done now).
2815 // It would be unusual for this value to be negative, but check just in case ...
3086 struct stream_in *in = (struct stream_in *)stream;
3088 return in->config.rate;
3098 struct stream_in *in = (struct stream_in *)stream;
3099 return in->config.period_size * in->af_period_multiplier *
3105 struct stream_in *in = (struct stream_in *)stream;
3107 return in->channel_mask;
3112 struct stream_in *in = (struct stream_in *)stream;
3113 return in->format;
3123 struct stream_in *in = (struct stream_in *)stream;
3124 struct audio_device *adev = in->dev;
3130 lock_input_stream(in);
3132 if (!in->standby && in->is_st_session) {
3134 audio_extn_sound_trigger_stop_lab(in);
3135 in->standby = true;
3138 if (!in->standby) {
3140 adev->adm_deregister_stream(adev->adm_data, in->capture_handle);
3143 in->standby = true;
3144 if (in->usecase == USECASE_AUDIO_RECORD_MMAP) {
3145 do_stop = in->capture_started;
3146 in->capture_started = false;
3148 if (in->pcm) {
3149 pcm_close(in->pcm);
3150 in->pcm = NULL;
3155 status = stop_input_stream(in);
3159 pthread_mutex_unlock(&in->lock);
3166 struct stream_in *in = (struct stream_in *)stream;
3170 // If we're not in standby, we may be blocked on a read.
3171 const bool locked = (pthread_mutex_trylock(&in->lock) == 0);
3172 dprintf(fd, " Standby: %s\n", in->standby ? "yes" : "no");
3173 dprintf(fd, " Frames read: %lld\n", (long long)in->frames_read);
3174 dprintf(fd, " Frames muted: %lld\n", (long long)in->frames_muted);
3177 pthread_mutex_unlock(&in->lock);
3182 in->error_log, fd, " " /* prefix */, 0 /* lines */, 0 /* limit_ns */);
3188 struct stream_in *in = (struct stream_in *)stream;
3189 struct audio_device *adev = in->dev;
3201 lock_input_stream(in);
3207 if ((in->source != val) && (val != 0)) {
3208 in->source = val;
3216 if (((int)in->device != val) && (val != 0) && audio_is_input_device(val) ) {
3228 in->device = val;
3229 /* If recording is in progress, change the tx device to new device */
3230 if (!in->standby) {
3235 in->capture_handle);
3237 select_devices(adev, in->usecase);
3244 pthread_mutex_unlock(&in->lock);
3254 struct stream_in *in = (struct stream_in *)stream;
3262 &in->supported_channel_masks[0]);
3264 &in->supported_formats[0]);
3266 &in->supported_sample_rates[0]);
3288 struct stream_in *in = (struct stream_in *)stream;
3289 struct audio_device *adev = in->dev;
3303 lock_input_stream(in);
3304 if (in->card_status != status)
3305 in->card_status = status;
3306 pthread_mutex_unlock(&in->lock);
3309 use_case_table[in->usecase],
3315 in_standby(&in->stream.common);
3323 struct stream_in *in = (struct stream_in *)stream;
3324 struct audio_device *adev = in->dev;
3329 lock_input_stream(in);
3333 if (in->is_st_session) {
3336 audio_extn_sound_trigger_read(in, buffer, bytes);
3337 pthread_mutex_unlock(&in->lock);
3341 if (in->usecase == USECASE_AUDIO_RECORD_MMAP) {
3346 if (in->standby) {
3348 ret = start_input_stream(in);
3353 in->standby = 0;
3360 long ns = pcm_bytes_to_frames(in->pcm, bytes)*1000000000LL/
3361 in->config.rate;
3362 request_in_focus(in, ns);
3364 bool use_mmap = is_mmap_usecase(in->usecase) || in->realtime;
3365 if (in->pcm) {
3367 ret = pcm_mmap_read(in->pcm, buffer, bytes);
3369 ret = pcm_read(in->pcm, buffer, bytes);
3375 if (!ret && bytes > 0 && (in->format == AUDIO_FORMAT_PCM_8_24_BIT)) {
3377 /* data from DSP comes in 24_8 format, convert it to 8_24 */
3390 release_in_focus(in, ns);
3397 if (ret == 0 && adev->mic_muted && in->usecase != USECASE_AUDIO_RECORD_AFE_PROXY) {
3399 in->frames_muted += frames;
3403 pthread_mutex_unlock(&in->lock);
3406 error_log_log(in->error_log, error_code, audio_utils_get_real_time_ns());
3407 in_standby(&in->stream.common);
3409 usleep(frames * 1000000LL / in_get_sample_rate(&in->stream.common));
3411 in->frames_muted += frames;
3414 in->frames_read += frames;
3430 struct stream_in *in = (struct stream_in *)stream;
3433 lock_input_stream(in);
3434 if (in->pcm) {
3437 if (pcm_get_htimestamp(in->pcm, &avail, ×tamp) == 0) {
3438 *frames = in->frames_read + avail;
3443 pthread_mutex_unlock(&in->lock);
3451 struct stream_in *in = (struct stream_in *)stream;
3452 struct audio_device *adev = in->dev;
3460 lock_input_stream(in);
3461 pthread_mutex_lock(&in->dev->lock);
3462 if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
3463 in->source == AUDIO_SOURCE_VOICE_RECOGNITION ||
3465 in->enable_aec != enable &&
3467 in->enable_aec = enable;
3469 platform_set_echo_reference(in->dev, enable, AUDIO_DEVICE_NONE);
3470 if (in->source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
3481 if (!in->standby)
3482 select_devices(in->dev, in->usecase);
3484 if (in->enable_ns != enable &&
3486 in->enable_ns = enable;
3487 if (!in->standby)
3488 select_devices(in->dev, in->usecase);
3490 pthread_mutex_unlock(&in->dev->lock);
3491 pthread_mutex_unlock(&in->lock);
3512 struct stream_in *in = (struct stream_in *)stream;
3513 struct audio_device *adev = in->dev;
3518 if (in->usecase == USECASE_AUDIO_RECORD_MMAP && !in->standby &&
3519 in->capture_started && in->pcm != NULL) {
3520 pcm_stop(in->pcm);
3521 ret = stop_input_stream(in);
3522 in->capture_started = false;
3530 struct stream_in *in = (struct stream_in *)stream;
3531 struct audio_device *adev = in->dev;
3534 ALOGV("%s in %p", __func__, in);
3536 if (in->usecase == USECASE_AUDIO_RECORD_MMAP && !in->standby &&
3537 !in->capture_started && in->pcm != NULL) {
3538 if (!in->capture_started) {
3539 ret = start_input_stream(in);
3541 in->capture_started = true;
3553 struct stream_in *in = (struct stream_in *)stream;
3554 struct audio_device *adev = in->dev;
3563 ALOGV("%s in %p", __func__, in);
3570 if (in->usecase != USECASE_AUDIO_RECORD_MMAP || !in->standby) {
3571 ALOGE("%s: usecase = %d, standby = %d", __func__, in->usecase, in->standby);
3572 ALOGV("%s in %p", __func__, in);
3576 in->pcm_device_id = platform_get_pcm_device_id(in->usecase, PCM_CAPTURE);
3577 if (in->pcm_device_id < 0) {
3579 __func__, in->pcm_device_id, in->usecase);
3584 adjust_mmap_period_count(&in->config, min_size_frames);
3587 __func__, adev->snd_card, in->pcm_device_id, in->config.channels);
3588 in->pcm = pcm_open(adev->snd_card, in->pcm_device_id,
3589 (PCM_IN | PCM_MMAP | PCM_NOIRQ | PCM_MONOTONIC), &in->config);
3590 if (in->pcm == NULL || !pcm_is_ready(in->pcm)) {
3596 ret = pcm_mmap_begin(in->pcm, &info->shared_memory_address, &offset1, &frames1);
3601 info->buffer_size_frames = pcm_get_buffer_size(in->pcm);
3602 buffer_size = pcm_frames_to_bytes(in->pcm, info->buffer_size_frames);
3603 info->burst_size_frames = in->config.period_size;
3605 in->pcm_device_id, 1 /*capture*/,
3610 info->shared_memory_fd = pcm_get_poll_fd(in->pcm);
3622 ret = pcm_mmap_commit(in->pcm, 0, MMAP_PERIOD_SIZE);
3628 in->standby = false;
3636 if (in->pcm == NULL) {
3639 ALOGE("%s: %s %s", __func__, step, pcm_get_error(in->pcm));
3640 pcm_close(in->pcm);
3641 in->pcm = NULL;
3651 struct stream_in *in = (struct stream_in *)stream;
3656 if (in->usecase != USECASE_AUDIO_RECORD_MMAP) {
3659 if (in->pcm == NULL) {
3663 int ret = pcm_mmap_get_hw_ptr(in->pcm, (unsigned int *)&position->position_frames, &ts);
3665 ALOGE("%s: %s", __func__, pcm_get_error(in->pcm));
3948 1000000000 /* aggregate consecutive identical errors within one second in ns */);
4048 // FIXME: note that the code below assumes that the speakers are in the correct placement
4230 /* Don't know if USB HIFI in this context so use true to be conservative */
4287 struct stream_in *in;
4321 in = (struct stream_in *)calloc(1, sizeof(struct stream_in));
4323 pthread_mutex_init(&in->lock, (const pthread_mutexattr_t *) NULL);
4324 pthread_mutex_init(&in->pre_lock, (const pthread_mutexattr_t *) NULL);
4326 in->stream.common.get_sample_rate = in_get_sample_rate;
4327 in->stream.common.set_sample_rate = in_set_sample_rate;
4328 in->stream.common.get_buffer_size = in_get_buffer_size;
4329 in->stream.common.get_channels = in_get_channels;
4330 in->stream.common.get_format = in_get_format;
4331 in->stream.common.set_format = in_set_format;
4332 in->stream.common.standby = in_standby;
4333 in->stream.common.dump = in_dump;
4334 in->stream.common.set_parameters = in_set_parameters;
4335 in->stream.common.get_parameters = in_get_parameters;
4336 in->stream.common.add_audio_effect = in_add_audio_effect;
4337 in->stream.common.remove_audio_effect = in_remove_audio_effect;
4338 in->stream.set_gain = in_set_gain;
4339 in->stream.read = in_read;
4340 in->stream.get_input_frames_lost = in_get_input_frames_lost;
4341 in->stream.get_capture_position = in_get_capture_position;
4343 in->device = devices;
4344 in->source = source;
4345 in->dev = adev;
4346 in->standby = 1;
4347 in->capture_handle = handle;
4348 in->flags = flags;
4355 &in->supported_formats[0],
4358 &in->supported_channel_masks[0],
4361 &in->supported_sample_rates[0],
4376 *> In case of UNPROCESSED source, for 24 bit, if format requested is other than
4378 *> In case of any other source requesting 24 bit or float return error
4397 in->format = config->format;
4398 in->channel_mask = config->channel_mask;
4401 if (in->device == AUDIO_DEVICE_IN_TELEPHONY_RX) {
4417 in->usecase = USECASE_AUDIO_RECORD_AFE_PROXY;
4418 in->config = pcm_config_afe_proxy_record;
4419 in->af_period_multiplier = 1;
4421 in->usecase = USECASE_AUDIO_RECORD_HIFI;
4422 in->config = pcm_config_audio_capture;
4423 frame_size = audio_stream_in_frame_size(&in->stream);
4429 in->config.period_size = buffer_size / frame_size;
4430 in->config.rate = config->sample_rate;
4431 in->af_period_multiplier = 1;
4432 in->config.format = pcm_format_from_audio_format(config->format);
4434 in->usecase = USECASE_AUDIO_RECORD;
4436 (in->flags & AUDIO_INPUT_FLAG_FAST) != 0) {
4439 in->usecase = USECASE_AUDIO_RECORD_LOW_LATENCY;
4441 in->realtime = may_use_noirq_mode(adev, in->usecase, in->flags);
4442 if (!in->realtime) {
4443 in->config = pcm_config_audio_capture;
4444 frame_size = audio_stream_in_frame_size(&in->stream);
4450 in->config.period_size = buffer_size / frame_size;
4451 in->config.rate = config->sample_rate;
4452 in->af_period_multiplier = 1;
4455 in->config = pcm_config_audio_capture_rt;
4456 in->af_period_multiplier = af_period_multiplier;
4459 ((in->flags & AUDIO_INPUT_FLAG_MMAP_NOIRQ) != 0)) {
4461 in->usecase = USECASE_AUDIO_RECORD_MMAP;
4462 in->config = pcm_config_mmap_capture;
4463 in->stream.start = in_start;
4464 in->stream.stop = in_stop;
4465 in->stream.create_mmap_buffer = in_create_mmap_buffer;
4466 in->stream.get_mmap_position = in_get_mmap_position;
4467 in->af_period_multiplier = 1;
4469 } else if (in->source == AUDIO_SOURCE_VOICE_COMMUNICATION &&
4470 in->flags & AUDIO_INPUT_FLAG_VOIP_TX &&
4476 in->usecase = USECASE_AUDIO_RECORD_VOIP;
4477 in->config = pcm_config_audio_capture;
4478 frame_size = audio_stream_in_frame_size(&in->stream);
4483 in->config.period_size = buffer_size / frame_size;
4484 in->config.period_count = VOIP_CAPTURE_PERIOD_COUNT;
4485 in->config.rate = config->sample_rate;
4486 in->af_period_multiplier = 1;
4488 in->config = pcm_config_audio_capture;
4489 frame_size = audio_stream_in_frame_size(&in->stream);
4495 in->config.period_size = buffer_size / frame_size;
4496 in->config.rate = config->sample_rate;
4497 in->af_period_multiplier = 1;
4500 in->config.format = PCM_FORMAT_S24_LE;
4503 in->config.channels = channel_count;
4504 in->sample_rate = in->config.rate;
4506 in->error_log = error_log_create(
4512 audio_extn_sound_trigger_check_and_get_session(in);
4514 lock_input_stream(in);
4515 audio_extn_snd_mon_register_listener(in, in_snd_mon_cb);
4517 in->card_status = adev->card_status;
4519 pthread_mutex_unlock(&in->lock);
4521 stream_app_type_cfg_init(&in->app_type_cfg);
4523 *stream_in = &in->stream;
4528 free(in);
4536 struct stream_in *in = (struct stream_in *)stream;
4544 error_log_destroy(in->error_log);
4545 in->error_log = NULL;
4566 * in order to power up the devices and read the device parameters.
4574 * In this case there are the following use cases and device ids.
4588 /* should be the usecases enabled in adev_open_input_stream() */
4593 /* should be the usecases enabled in adev_open_output_stream()*/
4628 struct stream_in in;
4646 adev->active_input = ∈
4647 memset(&in, 0, sizeof(in));
4648 in.device = audio_device;
4649 in.source = AUDIO_SOURCE_VOICE_COMMUNICATION;
4650 uc_info.stream.in = ∈
4655 out.devices = audio_device; /* only field needed in select_devices */
4662 /* select device - similar to start_(in/out)put_stream() */
4677 /* deselect device - similar to stop_(in/out)put_stream() */