Home | History | Annotate | Download | only in hal

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 bool has_processing = in->num_preprocessors != 0;
1035 * In case of additional channels, we cannot work inplace
1037 size_t src_channels = in->config.channels;
1038 size_t dst_channels = audio_channel_count_from_in_mask(in->main_channels);
1044 /* since all the processing below is done in frames and using the config.channels
1045 * as the number of channels, no changes is required in case aux_channels are present */
1048 if (in->proc_buf_frames < (size_t)frames_num) {
1050 if (in->proc_buf_size < (size_t)frames_num) {
1051 in->proc_buf_size = (size_t)frames_num;
1052 in->proc_buf_in = realloc(in->proc_buf_in, src_buffer_size);
1053 ALOG_ASSERT((in->proc_buf_in != NULL),
1056 in->proc_buf_out = realloc(in->proc_buf_out, src_buffer_size);
1057 ALOG_ASSERT((in->proc_buf_out != NULL),
1059 proc_buf_out = in->proc_buf_out;
1062 frames_rd = read_frames(in,
1063 in->proc_buf_in +
1064 in->proc_buf_frames * src_channels * bytes_per_sample,
1065 frames_num - in->proc_buf_frames);
1071 in->proc_buf_frames += frames_rd;
1076 in_buf.frameCount = in->proc_buf_frames;
1077 in_buf.s16 = in->proc_buf_in;
1079 out_buf.s16 = (int16_t *)proc_buf_out + frames_wr * in->config.channels;
1086 for (i = 0; i < in->num_preprocessors; i++) {
1087 (*in->preprocessors[i].effect_itfe)->process(in->preprocessors[i].effect_itfe,
1092 /* process() has updated the number of frames consumed and produced in
1094 * move remaining frames to the beginning of in->proc_buf_in */
1095 in->proc_buf_frames -= in_buf.frameCount;
1097 if (in->proc_buf_frames) {
1098 memcpy(in->proc_buf_in,
1099 in->proc_buf_in + in_buf.frameCount * src_channels * bytes_per_sample,
1100 in->proc_buf_frames * in->config.channels * audio_bytes_per_sample(in_get_format(in)));
1112 /* The effect does not comply to the API. In theory, we should never end up here! */
1125 if (in->proc_buf_size < src_buffer_size) {
1126 in->proc_buf_size = src_buffer_size;
1127 in->proc_buf_out = realloc(in->proc_buf_out, src_buffer_size);
1128 ALOG_ASSERT((in->proc_buf_out != NULL),
1131 proc_buf_out = in->proc_buf_out;
1133 frames_wr = read_frames(in, proc_buf_out, frames_num);
1149 struct stream_in *in;
1155 in = (struct stream_in *)((char *)buffer_provider -
1158 if (list_empty(&in->pcm_dev_list)) {
1161 in->read_status = -ENODEV;
1165 pcm_device = node_to_item(list_head(&in->pcm_dev_list),
1168 if (in->read_buf_frames == 0) {
1169 size_t size_in_bytes = pcm_frames_to_bytes(pcm_device->pcm, in->config.period_size);
1170 if (in->read_buf_size < in->config.period_size) {
1171 in->read_buf_size = in->config.period_size;
1172 in->read_buf = (int16_t *) realloc(in->read_buf, size_in_bytes);
1173 ALOG_ASSERT((in->read_buf != NULL),
1177 in->read_status = pcm_read(pcm_device->pcm, (void*)in->read_buf, size_in_bytes);
1179 if (in->read_status != 0) {
1180 ALOGE("get_next_buffer() pcm_read error %d", in->read_status);
1183 return in->read_status;
1185 in->read_buf_frames = in->config.period_size;
1188 buffer->frame_count = (buffer->frame_count > in->read_buf_frames) ?
1189 in->read_buf_frames : buffer->frame_count;
1190 buffer->i16 = in->read_buf + (in->config.period_size - in->read_buf_frames) *
1191 in->config.channels;
1192 return in->read_status;
1198 struct stream_in *in;
1203 in = (struct stream_in *)((char *)buffer_provider -
1206 in->read_buf_frames -= buffer->frame_count;
1211 static ssize_t read_frames(struct stream_in *in, void *buffer, ssize_t frames)
1217 if (list_empty(&in->pcm_dev_list)) {
1222 pcm_device = node_to_item(list_head(&in->pcm_dev_list),
1227 ALOGVV("%s: frames_rd: %zd, frames_wr: %zd, in->config.channels: %d",
1228 __func__,frames_rd,frames_wr,in->config.channels);
1229 if (in->resampler != NULL) {
1230 in->resampler->resample_from_provider(in->resampler,
1239 get_next_buffer(&in->buf_provider, &buf);
1247 release_buffer(&in->buf_provider, &buf);
1249 /* in->read_status is updated by getNextBuffer() also called by
1250 * in->resampler->resample_from_provider() */
1251 if (in->read_status != 0)
1252 return in->read_status;
1259 static int in_release_pcm_devices(struct stream_in *in)
1265 list_for_each_safe(node, next, &in->pcm_dev_list) {
1274 static int stop_input_stream(struct stream_in *in)
1277 struct audio_device *adev = in->dev;
1281 in->usecase, use_case_table[in->usecase]);
1282 uc_info = get_usecase_from_id(adev, in->usecase);
1284 ALOGE("%s: Could not find the usecase (%d) in the list",
1285 __func__, in->usecase);
1295 if (list_empty(&in->pcm_dev_list)) {
1300 in_release_pcm_devices(in);
1301 list_init(&in->pcm_dev_list);
1306 int start_input_stream(struct stream_in *in)
1312 struct audio_device *adev = in->dev;
1316 ALOGV("%s: enter: usecase(%d)", __func__, in->usecase);
1317 adev->active_input = in;
1318 pcm_profile = get_pcm_device(in->usecase_type, in->devices);
1321 __func__, in->usecase);
1326 if (in->input_flags & AUDIO_INPUT_FLAG_FAST) {
1333 uc_info->id = in->usecase;
1335 uc_info->stream = (struct audio_stream *)in;
1336 uc_info->devices = in->devices;
1342 list_init(&in->pcm_dev_list);
1343 list_add_tail(&in->pcm_dev_list, &pcm_device->stream_list_node);
1352 select_devices(adev, in->usecase);
1358 if (in->config.rate != pcm_profile->config.rate) {
1361 in
1364 if (in->aux_channels_changed) {
1365 in->config.channels = audio_channel_count_from_in_mask(in->aux_channels);
1370 if (in->requested_rate != in->config.rate) {
1375 if (in->resampler) {
1376 release_resampler(in->resampler);
1377 in->resampler = NULL;
1379 in->buf_provider.get_next_buffer = get_next_buffer;
1380 in->buf_provider.release_buffer = release_buffer;
1381 ret = create_resampler(in->config.rate,
1382 in->requested_rate,
1383 in->config.channels,
1385 &in->buf_provider,
1386 &in->resampler);
1391 * As such a change in aux_channels will not have an effect.
1428 /* force read and proc buffer reallocation in case of frame size or
1431 in->proc_buf_frames = 0;
1433 in->proc_buf_size = 0;
1434 in->read_buf_size = 0;
1435 in->read_buf_frames = 0;
1438 if (in->resampler) {
1439 in->resampler->reset(in->resampler);
1446 if (in->resampler) {
1447 release_resampler(in->resampler);
1448 in->resampler = NULL;
1450 stop_input_stream(in);
1458 static void lock_input_stream(struct stream_in *in)
1460 pthread_mutex_lock(&in->pre_lock);
1461 pthread_mutex_lock(&in->lock);
1462 pthread_mutex_unlock(&in->pre_lock);
1619 ALOGE("%s: Could not find the usecase (%d) in the list",
1696 ALOGE("%s: Could not find the usecase (%d) in the list",
1893 struct stream_in *in = NULL; /* if non-NULL, then force input to standby */
1910 * - because a change in output device may change mic settings */
1913 in = adev->active_input;
1923 ALOGE("%s: Could not find the usecase (%d) in the list",
1957 if (in) {
1959 lock_input_stream(in);
1961 LOG_ALWAYS_FATAL_IF(in != adev->active_input);
1962 do_in_standby_l(in);
1964 pthread_mutex_unlock(&in->lock);
2074 struct stream_in *in = NULL;
2101 /* A change in output device may change the microphone selection */
2105 in = adev->active_input;
2111 if (!in) {
2112 /* Leave mutex locked iff in != NULL */
2206 if (in) {
2208 lock_input_stream(in);
2210 LOG_ALWAYS_FATAL_IF(in != adev->active_input);
2211 do_in_standby_l(in);
2213 pthread_mutex_unlock(&in->lock);
2214 /* This mutex was left locked iff in != NULL */
2275 /* It would be unusual for this value to be negative, but check just in case ... */
2291 struct stream_in *in = (struct stream_in *)stream;
2293 return in->requested_rate;
2305 struct stream_in *in = (struct stream_in *)stream;
2307 return in->main_channels;
2326 struct stream_in *in = (struct stream_in *)stream;
2328 return get_input_buffer_size(in->requested_rate,
2330 audio_channel_count_from_in_mask(in->main_channels),
2331 in->usecase_type,
2332 in->devices);
2335 static int in_close_pcm_devices(struct stream_in *in)
2339 struct audio_device *adev = in->dev;
2341 list_for_each(node, &in->pcm_dev_list) {
2358 static int do_in_standby_l(struct stream_in *in)
2362 if (!in->standby) {
2364 in_close_pcm_devices(in);
2366 in);
2368 if (in->read_buf) {
2369 free(in->read_buf);
2370 in->read_buf = NULL;
2373 in->standby = 1;
2379 static int in_standby_l(struct stream_in *in)
2381 struct audio_device *adev = in->dev;
2383 lock_input_stream(in);
2384 if (!in->standby) {
2386 status = do_in_standby_l(in);
2389 pthread_mutex_unlock(&in->lock);
2395 struct stream_in *in = (struct stream_in *)stream;
2396 struct audio_device *adev = in->dev;
2400 status = in_standby_l(in);
2416 struct stream_in *in = (struct stream_in *)stream;
2417 struct audio_device *adev = in->dev;
2434 lock_input_stream(in);
2439 if (((int)in->source != val) && (val != 0)) {
2440 in->source = val;
2447 if (((int)in->devices != val) && (val != 0)) {
2448 in->devices = val;
2449 /* If recording is in progress, change the tx device to new device */
2450 if (!in->standby) {
2451 uc_info = get_usecase_from_id(adev, in->usecase);
2453 ALOGE("%s: Could not find the usecase (%d) in the list",
2454 __func__, in->usecase);
2456 if (list_empty(&in->pcm_dev_list))
2459 pcm_device = node_to_item(list_head(&in->pcm_dev_list),
2467 ret = do_in_standby_l(in);
2469 ret = select_devices(adev, in->usecase);
2474 pthread_mutex_unlock(&in->lock);
2501 static ssize_t read_bytes_from_dsp(struct stream_in *in, void* buffer,
2505 struct audio_device *adev = in->dev;
2507 pcm_device = node_to_item(list_head(&in->pcm_dev_list),
2520 struct stream_in *in = (struct stream_in *)stream;
2521 struct audio_device *adev = in->dev;
2529 lock_input_stream(in);
2530 if (in->standby) {
2531 pthread_mutex_unlock(&in->lock);
2533 lock_input_stream(in);
2534 if (!in->standby) {
2539 ret = start_input_stream(in);
2545 in->standby = 0;
2549 if (!list_empty(&in->pcm_dev_list)) {
2550 if (in->usecase == USECASE_AUDIO_CAPTURE_HOTWORD) {
2551 bytes = read_bytes_from_dsp(in, buffer, bytes);
2575 pthread_mutex_unlock(&in->lock);
2578 in_standby(&in->stream.common);
2581 in->requested_rate);
2597 struct stream_in *in = (struct stream_in *)stream;
2598 struct audio_device *adev = in->dev;
2611 lock_input_stream(in);
2612 pthread_mutex_lock(&in->dev->lock);
2614 if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) &&
2615 in->enable_aec != enable &&
2617 in->enable_aec = enable;
2618 if (!in->standby)
2619 select_devices(in->dev, in->usecase);
2623 if (in->num_preprocessors >= MAX_PREPROCESSORS) {
2627 in->preprocessors[in->num_preprocessors].effect_itfe = effect;
2628 in->num_preprocessors ++;
2630 in_update_aux_channels(in, effect);//wesley crash
2631 in->aux_channels_changed = true;
2634 if (in->num_preprocessors <= 0) {
2639 for (i = 0; i < in->num_preprocessors && status != 0; i++) {
2640 if ( in->preprocessors[i].effect_itfe == effect ) {
2642 free(in->preprocessors[i].channel_configs);
2643 in->num_preprocessors--;
2644 memcpy(in->preprocessors + i,
2645 in->preprocessors + i + 1,
2646 (in->num_preprocessors - i) * sizeof(in->preprocessors[0]));
2647 memset(in->preprocessors + in->num_preprocessors,
2649 sizeof(in->preprocessors[0]));
2655 in->aux_channels_changed = false;
2656 ALOGV("%s: enable(%d), in->aux_channels_changed(%d)",
2657 __func__, enable, in->aux_channels_changed);
2659 ALOGI("%s: num_preprocessors = %d", __func__, in->num_preprocessors);
2664 pthread_mutex_unlock(&in->dev->lock);
2665 pthread_mutex_unlock(&in->lock);
3006 /* NOTE: we default to built in mic which may cause a mismatch between what we
3026 struct stream_in *in;
3042 in = (struct stream_in *)calloc(1, sizeof(struct stream_in));
3044 in->stream.common.get_sample_rate = in_get_sample_rate;
3045 in->stream.common.set_sample_rate = in_set_sample_rate;
3046 in->stream.common.get_buffer_size = in_get_buffer_size;
3047 in->stream.common.get_channels = in_get_channels;
3048 in->stream.common.get_format = in_get_format;
3049 in->stream.common.set_format = in_set_format;
3050 in->stream.common.standby = in_standby;
3051 in->stream.common.dump = in_dump;
3052 in->stream.common.set_parameters = in_set_parameters;
3053 in->stream.common.get_parameters = in_get_parameters;
3054 in->stream.common.add_audio_effect = in_add_audio_effect;
3055 in->stream.common.remove_audio_effect = in_remove_audio_effect;
3056 in->stream.set_gain = in_set_gain;
3057 in->stream.read = in_read;
3058 in->stream.get_input_frames_lost = in_get_input_frames_lost;
3060 in->devices = devices;
3061 in->source = source;
3062 in->dev = adev;
3063 in->standby = 1;
3064 in->main_channels = config->channel_mask;
3065 in->requested_rate = config->sample_rate;
3068 in->input_flags = flags;
3071 in->config = pcm_profile->config;
3075 in->usecase = USECASE_AUDIO_CAPTURE_HOTWORD;
3077 in->usecase = USECASE_AUDIO_CAPTURE;
3079 in->usecase_type = usecase_type;
3081 pthread_mutex_init(&in->lock, (const pthread_mutexattr_t *) NULL);
3082 pthread_mutex_init(&in->pre_lock, (const pthread_mutexattr_t *) NULL);
3084 *stream_in = &in->stream;
3093 struct stream_in *in = (struct stream_in*)stream;
3099 in_standby_l(in);
3100 pthread_mutex_destroy(&in->lock);
3101 pthread_mutex_destroy(&in->pre_lock);
3102 free(in->proc_buf_out);
3107 for (i=0; i<in->num_preprocessors; i++) {
3108 free(in->preprocessors[i].channel_configs);
3111 if (in->read_buf) {
3112 free(in->read_buf);
3115 if (in->proc_buf_in) {
3116 free(in->proc_buf_in);
3119 if (in->resampler) {
3120 release_resampler(in->resampler);
3231 ALOGE("%s: Error grabbing functions in %s", __func__,