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
677 /* Delay in Us */
860 static ssize_t read_frames(struct stream_in *in, void *buffer, ssize_t frames);
861 static int do_in_standby_l(struct stream_in *in);
873 static uint32_t in_get_aux_channels(struct stream_in *in)
875 if (in->num_preprocessors == 0)
880 if (!(in->devices & AUDIO_DEVICE_IN_BUILTIN_MIC & ~AUDIO_DEVICE_BIT_IN))
946 static int in_reconfigure_channels(struct stream_in *in,
960 for (i = 0; i < in->num_preprocessors; i++) {
961 int cur_status = in_configure_effect_channels(in->preprocessors[i].effect_itfe,
983 static void in_update_aux_channels(struct stream_in *in,
990 aux_channels = in_get_aux_channels(in);
992 channel_config.main_channels = in->main_channels;
994 status = in_reconfigure_channels(in,
997 (aux_channels != in->aux_channels));
1004 in_reconfigure_channels(in, effect, &channel_config, true);
1006 ALOGV("%s: aux_channels=%d, in->aux_channels_changed=%d", __func__, aux_channels, in->aux_channels_changed);
1007 if (in->aux_channels != aux_channels) {
1008 in->aux_channels_changed = true;
1009 in->aux_channels = aux_channels;
1010 do_in_standby_l(in);
1022 struct stream_in *in = (struct stream_in *)stream;
1030 * In case of additional channels, we cannot work inplace
1032 size_t src_channels = in->config.channels;
1033 size_t dst_channels = audio_channel_count_from_in_mask(in->main_channels);
1038 const bool has_processing = in->num_preprocessors != 0;
1047 if (in->proc_buf_size < src_buffer_size) {
1048 in->proc_buf_size = src_buffer_size;
1050 /* we always reallocate both buffers in case # of effects change dynamically. */
1051 in->proc_buf_in = realloc(in->proc_buf_in, src_buffer_size);
1052 ALOG_ASSERT((in->proc_buf_in != NULL),
1055 in->proc_buf_out = realloc(in->proc_buf_out, src_buffer_size);
1056 ALOG_ASSERT((in->proc_buf_out != NULL),
1060 proc_buf_out = in->proc_buf_out;
1066 /* since all the processing below is done in frames and using the config.channels
1067 * as the number of channels, no changes is required in case aux_channels are present */
1070 if (in->proc_buf_frames < (size_t)frames_num) {
1071 ssize_t frames_rd = read_frames(in,
1072 (char *)in->proc_buf_in + in->proc_buf_frames * src_frame_size,
1073 frames_num - in->proc_buf_frames);
1079 in->proc_buf_frames += frames_rd;
1087 in_buf.frameCount = in->proc_buf_frames;
1088 in_buf.s16 = in->proc_buf_in; /* currently assumes PCM 16 effects */
1097 for (int i = 0; i < in->num_preprocessors; i++) {
1098 (*in->preprocessors[i].effect_itfe)->process(in->preprocessors[i].effect_itfe,
1103 /* process() has updated the number of frames consumed and produced in
1105 * move remaining frames to the beginning of in->proc_buf_in */
1106 in->proc_buf_frames -= in_buf.frameCount;
1108 if (in->proc_buf_frames) {
1109 memcpy(in->proc_buf_in,
1110 (char *)in->proc_buf_in + in_buf.frameCount * src_frame_size,
1111 in->proc_buf_frames * src_frame_size);
1123 /* The effect does not comply to the API. In theory, we should never end up here! */
1134 frames_wr = read_frames(in, proc_buf_out, frames_num);
1151 struct stream_in *in;
1157 in = (struct stream_in *)((char *)buffer_provider -
1160 if (list_empty(&in->pcm_dev_list)) {
1163 in->read_status = -ENODEV;
1167 pcm_device = node_to_item(list_head(&in->pcm_dev_list),
1170 if (in->read_buf_frames == 0) {
1171 size_t size_in_bytes = pcm_frames_to_bytes(pcm_device->pcm, in->config.period_size);
1172 if (in->read_buf_size < in->config.period_size) {
1173 in->read_buf_size = in->config.period_size;
1174 in->read_buf = (int16_t *) realloc(in->read_buf, size_in_bytes);
1175 ALOG_ASSERT((in->read_buf != NULL),
1179 in->read_status = pcm_read(pcm_device->pcm, (void*)in->read_buf, size_in_bytes);
1181 if (in->read_status != 0) {
1182 ALOGE("get_next_buffer() pcm_read error %d", in->read_status);
1185 return in->read_status;
1187 in->read_buf_frames = in->config.period_size;
1190 buffer->frame_count = (buffer->frame_count > in->read_buf_frames) ?
1191 in->read_buf_frames : buffer->frame_count;
1192 buffer->i16 = in->read_buf + (in->config.period_size - in->read_buf_frames) *
1193 in->config.channels;
1194 return in->read_status;
1200 struct stream_in *in;
1205 in = (struct stream_in *)((char *)buffer_provider -
1208 in->read_buf_frames -= buffer->frame_count;
1213 static ssize_t read_frames(struct stream_in *in, void *buffer, ssize_t frames)
1219 if (list_empty(&in->pcm_dev_list)) {
1224 pcm_device = node_to_item(list_head(&in->pcm_dev_list),
1229 ALOGVV("%s: frames_rd: %zd, frames_wr: %zd, in->config.channels: %d",
1230 __func__,frames_rd,frames_wr,in->config.channels);
1231 if (in->resampler != NULL) {
1232 in->resampler->resample_from_provider(in->resampler,
1241 get_next_buffer(&in->buf_provider, &buf);
1249 release_buffer(&in->buf_provider, &buf);
1251 /* in->read_status is updated by getNextBuffer() also called by
1252 * in->resampler->resample_from_provider() */
1253 if (in->read_status != 0)
1254 return in->read_status;
1261 static int in_release_pcm_devices(struct stream_in *in)
1267 list_for_each_safe(node, next, &in->pcm_dev_list) {
1276 static int stop_input_stream(struct stream_in *in)
1279 struct audio_device *adev = in->dev;
1283 in->usecase, use_case_table[in->usecase]);
1284 uc_info = get_usecase_from_id(adev, in->usecase);
1286 ALOGE("%s: Could not find the usecase (%d) in the list",
1287 __func__, in->usecase);
1297 if (list_empty(&in->pcm_dev_list)) {
1302 in_release_pcm_devices(in);
1303 list_init(&in->pcm_dev_list);
1308 int start_input_stream(struct stream_in *in)
1314 struct audio_device *adev = in->dev;
1318 ALOGV("%s: enter: usecase(%d)", __func__, in->usecase);
1319 adev->active_input = in;
1320 pcm_profile = get_pcm_device(in->usecase_type, in->devices);
1323 __func__, in->usecase);
1328 if (in->input_flags & AUDIO_INPUT_FLAG_FAST) {
1335 uc_info->id = in->usecase;
1337 uc_info->stream = (struct audio_stream *)in;
1338 uc_info->devices = in->devices;
1344 list_init(&in->pcm_dev_list);
1345 list_add_tail(&in->pcm_dev_list, &pcm_device->stream_list_node);
1354 select_devices(adev, in->usecase);
1360 if (in->config.rate != pcm_profile->config.rate) {
1363 in->config = pcm_profile->config;
1366 if (in->aux_channels_changed) {
1367 in->config.channels = audio_channel_count_from_in_mask(in->aux_channels);
1372 if (in->requested_rate != in->config.rate) {
1377 if (in->resampler) {
1378 release_resampler(in->resampler);
1379 in->resampler = NULL;
1381 in->buf_provider.get_next_buffer = get_next_buffer;
1382 in->buf_provider.release_buffer = release_buffer;
1383 ret = create_resampler(in->config.rate,
1384 in->requested_rate,
1385 in->config.channels,
1387 &in->buf_provider,
1388 &in->resampler);
1393 * As such a change in aux_channels will not have an effect.
1430 /* force read and proc buffer reallocation in case of frame size or
1433 in->proc_buf_frames = 0;
1435 in->proc_buf_size = 0;
1436 in->read_buf_size = 0;
1437 in->read_buf_frames = 0;
1440 if (in->resampler) {
1441 in->resampler->reset(in->resampler);
1448 if (in->resampler) {
1449 release_resampler(in->resampler);
1450 in->resampler = NULL;
1452 stop_input_stream(in);
1460 static void lock_input_stream(struct stream_in *in)
1462 pthread_mutex_lock(&in->pre_lock);
1463 pthread_mutex_lock(&in->lock);
1464 pthread_mutex_unlock(&in->pre_lock);
1621 ALOGE("%s: Could not find the usecase (%d) in the list",
1698 ALOGE("%s: Could not find the usecase (%d) in the list",
1894 struct stream_in *in = NULL; /* if non-NULL, then force input to standby */
1911 * - because a change in output device may change mic settings */
1914 in = adev->active_input;
1945 if (in) {
1947 lock_input_stream(in);
1949 LOG_ALWAYS_FATAL_IF(in != adev->active_input);
1950 do_in_standby_l(in);
1952 pthread_mutex_unlock(&in->lock);
2062 struct stream_in *in = NULL;
2089 /* A change in output device may change the microphone selection */
2093 in = adev->active_input;
2099 if (!in) {
2100 /* Leave mutex locked iff in != NULL */
2194 if (in) {
2196 lock_input_stream(in);
2198 LOG_ALWAYS_FATAL_IF(in != adev->active_input);
2199 do_in_standby_l(in);
2201 pthread_mutex_unlock(&in->lock);
2202 /* This mutex was left locked iff in != NULL */
2263 /* It would be unusual for this value to be negative, but check just in case ... */
2279 struct stream_in *in = (struct stream_in *)stream;
2281 return in->requested_rate;
2293 struct stream_in *in = (struct stream_in *)stream;
2295 return in->main_channels;
2314 struct stream_in *in = (struct stream_in *)stream;
2316 return get_input_buffer_size(in->requested_rate,
2318 audio_channel_count_from_in_mask(in->main_channels),
2319 in->usecase_type,
2320 in->devices);
2323 static int in_close_pcm_devices(struct stream_in *in)
2327 struct audio_device *adev = in->dev;
2329 list_for_each(node, &in->pcm_dev_list) {
2346 static int do_in_standby_l(struct stream_in *in)
2350 if (!in->standby) {
2352 in_close_pcm_devices(in);
2354 status = stop_input_stream(in);
2356 if (in->read_buf) {
2357 free(in->read_buf);
2358 in->read_buf = NULL;
2361 in->standby = 1;
2367 static int in_standby_l(struct stream_in *in)
2369 struct audio_device *adev = in->dev;
2371 lock_input_stream(in);
2372 if (!in->standby) {
2374 status = do_in_standby_l(in);
2377 pthread_mutex_unlock(&in->lock);
2383 struct stream_in *in = (struct stream_in *)stream;
2384 struct audio_device *adev = in->dev;
2388 status = in_standby_l(in);
2404 struct stream_in *in = (struct stream_in *)stream;
2405 struct audio_device *adev = in->dev;
2422 lock_input_stream(in);
2427 if (((int)in->source != val) && (val != 0)) {
2428 in->source = val;
2435 if (((int)in->devices != val) && (val != 0)) {
2436 in->devices = val;
2437 /* If recording is in progress, change the tx device to new device */
2438 if (!in->standby) {
2439 uc_info = get_usecase_from_id(adev, in->usecase);
2441 ALOGE("%s: Could not find the usecase (%d) in the list",
2442 __func__, in->usecase);
2444 if (list_empty(&in->pcm_dev_list))
2447 pcm_device = node_to_item(list_head(&in->pcm_dev_list),
2455 ret = do_in_standby_l(in);
2457 ret = select_devices(adev, in->usecase);
2462 pthread_mutex_unlock(&in->lock);
2489 static ssize_t read_bytes_from_dsp(struct stream_in *in, void* buffer,
2493 struct audio_device *adev = in->dev;
2495 pcm_device = node_to_item(list_head(&in->pcm_dev_list),
2508 struct stream_in *in = (struct stream_in *)stream;
2509 struct audio_device *adev = in->dev;
2517 lock_input_stream(in);
2518 if (in->standby) {
2519 pthread_mutex_unlock(&in->lock);
2521 lock_input_stream(in);
2522 if (!in->standby) {
2527 ret = start_input_stream(in);
2533 in->standby = 0;
2537 if (!list_empty(&in->pcm_dev_list)) {
2538 if (in->usecase == USECASE_AUDIO_CAPTURE_HOTWORD) {
2539 bytes = read_bytes_from_dsp(in, buffer, bytes);
2563 pthread_mutex_unlock(&in->lock);
2566 in_standby(&in->stream.common);
2569 in->requested_rate);
2585 struct stream_in *in = (struct stream_in *)stream;
2586 struct audio_device *adev = in->dev;
2599 lock_input_stream(in);
2600 pthread_mutex_lock(&in->dev->lock);
2602 if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) &&
2603 in->enable_aec != enable &&
2605 in->enable_aec = enable;
2606 if (!in->standby)
2607 select_devices(in->dev, in->usecase);
2611 if (in->num_preprocessors >= MAX_PREPROCESSORS) {
2615 in->preprocessors[in->num_preprocessors].effect_itfe = effect;
2616 in->num_preprocessors ++;
2618 in_update_aux_channels(in, effect);//wesley crash
2619 in->aux_channels_changed = true;
2622 if (in->num_preprocessors <= 0) {
2627 for (i = 0; i < in->num_preprocessors && status != 0; i++) {
2628 if ( in->preprocessors[i].effect_itfe == effect ) {
2630 free(in->preprocessors[i].channel_configs);
2631 in->num_preprocessors--;
2632 memcpy(in->preprocessors + i,
2633 in->preprocessors + i + 1,
2634 (in->num_preprocessors - i) * sizeof(in->preprocessors[0]));
2635 memset(in->preprocessors + in->num_preprocessors,
2637 sizeof(in->preprocessors[0]));
2643 in->aux_channels_changed = false;
2644 ALOGV("%s: enable(%d), in->aux_channels_changed(%d)",
2645 __func__, enable, in->aux_channels_changed);
2647 ALOGI("%s: num_preprocessors = %d", __func__, in->num_preprocessors);
2652 pthread_mutex_unlock(&in->dev->lock);
2653 pthread_mutex_unlock(&in->lock);
2994 /* NOTE: we default to built in mic which may cause a mismatch between what we
3014 struct stream_in *in;
3030 in = (struct stream_in *)calloc(1, sizeof(struct stream_in));
3032 in->stream.common.get_sample_rate = in_get_sample_rate;
3033 in->stream.common.set_sample_rate = in_set_sample_rate;
3034 in->stream.common.get_buffer_size = in_get_buffer_size;
3035 in->stream.common.get_channels = in_get_channels;
3036 in->stream.common.get_format = in_get_format;
3037 in->stream.common.set_format = in_set_format;
3038 in->stream.common.standby = in_standby;
3039 in->stream.common.dump = in_dump;
3040 in->stream.common.set_parameters = in_set_parameters;
3041 in->stream.common.get_parameters = in_get_parameters;
3042 in->stream.common.add_audio_effect = in_add_audio_effect;
3043 in->stream.common.remove_audio_effect = in_remove_audio_effect;
3044 in->stream.set_gain = in_set_gain;
3045 in->stream.read = in_read;
3046 in->stream.get_input_frames_lost = in_get_input_frames_lost;
3048 in->devices = devices;
3049 in->source = source;
3050 in->dev = adev;
3051 in->standby = 1;
3052 in->main_channels = config->channel_mask;
3053 in->requested_rate = config->sample_rate;
3056 in->input_flags = flags;
3059 in->config = pcm_profile->config;
3063 in->usecase = USECASE_AUDIO_CAPTURE_HOTWORD;
3065 in->usecase = USECASE_AUDIO_CAPTURE;
3067 in->usecase_type = usecase_type;
3069 pthread_mutex_init(&in->lock, (const pthread_mutexattr_t *) NULL);
3070 pthread_mutex_init(&in->pre_lock, (const pthread_mutexattr_t *) NULL);
3072 *stream_in = &in->stream;
3081 struct stream_in *in = (struct stream_in*)stream;
3087 in_standby_l(in);
3088 pthread_mutex_destroy(&in->lock);
3089 pthread_mutex_destroy(&in->pre_lock);
3090 free(in->proc_buf_out);
3095 for (i=0; i<in->num_preprocessors; i++) {
3096 free(in->preprocessors[i].channel_configs);
3099 if (in->read_buf) {
3100 free(in->read_buf);
3103 if (in->proc_buf_in) {
3104 free(in->proc_buf_in);
3107 if (in->resampler) {
3108 release_resampler(in->resampler);
3219 ALOGE("%s: Error grabbing functions in %s", __func__,