• Home
  • Raw
  • Download

Lines Matching refs:er

73     struct echo_reference *er;  in echo_reference_get_next_buffer()  local
79 er = (struct echo_reference *)((char *)buffer_provider - in echo_reference_get_next_buffer()
82 if (er->wr_src_buf == NULL || er->wr_frames_in == 0) { in echo_reference_get_next_buffer()
88 buffer->frame_count = (buffer->frame_count > er->wr_frames_in) ? in echo_reference_get_next_buffer()
89 er->wr_frames_in : buffer->frame_count; in echo_reference_get_next_buffer()
91 buffer->i16 = (int16_t *)er->wr_src_buf + (er->wr_curr_frame_size - er->wr_frames_in) * in echo_reference_get_next_buffer()
92 er->rd_channel_count; in echo_reference_get_next_buffer()
100 struct echo_reference *er; in echo_reference_release_buffer() local
106 er = (struct echo_reference *)((char *)buffer_provider - in echo_reference_release_buffer()
109 er->wr_frames_in -= buffer->frame_count; in echo_reference_release_buffer()
112 static void echo_reference_reset_l(struct echo_reference *er) in echo_reference_reset_l() argument
115 free(er->buffer); in echo_reference_reset_l()
116 er->buffer = NULL; in echo_reference_reset_l()
117 er->buf_size = 0; in echo_reference_reset_l()
118 er->frames_in = 0; in echo_reference_reset_l()
119 free(er->wr_buf); in echo_reference_reset_l()
120 er->wr_buf = NULL; in echo_reference_reset_l()
121 er->wr_buf_size = 0; in echo_reference_reset_l()
122 er->wr_render_time.tv_sec = 0; in echo_reference_reset_l()
123 er->wr_render_time.tv_nsec = 0; in echo_reference_reset_l()
124 er->delta_count = 0; in echo_reference_reset_l()
125 er->prev_delta_sign = 0; in echo_reference_reset_l()
136 struct echo_reference *er = (struct echo_reference *)echo_reference; in echo_reference_write() local
139 if (er == NULL) { in echo_reference_write()
143 pthread_mutex_lock(&er->lock); in echo_reference_write()
147 er->state &= ~ECHOREF_WRITING; in echo_reference_write()
148 echo_reference_reset_l(er); in echo_reference_write()
155 (int)buffer->time_stamp.tv_nsec, er->playback_delay); in echo_reference_write()
161 (er->wr_render_time.tv_sec == 0) && (er->wr_render_time.tv_nsec == 0)) { in echo_reference_write()
165 if ((er->state & ECHOREF_WRITING) == 0) { in echo_reference_write()
167 if (er->resampler != NULL) { in echo_reference_write()
168 er->resampler->reset(er->resampler); in echo_reference_write()
170 er->state |= ECHOREF_WRITING; in echo_reference_write()
173 if ((er->state & ECHOREF_READING) == 0) { in echo_reference_write()
177 er->wr_render_time.tv_sec = buffer->time_stamp.tv_sec; in echo_reference_write()
178 er->wr_render_time.tv_nsec = buffer->time_stamp.tv_nsec; in echo_reference_write()
180 er->playback_delay = buffer->delay_ns; in echo_reference_write()
183 er->wr_curr_frame_size = buffer->frame_count; in echo_reference_write()
188 if (er->rd_channel_count != er->wr_channel_count || in echo_reference_write()
189 er->rd_sampling_rate != er->wr_sampling_rate) { in echo_reference_write()
194 if (er->rd_sampling_rate != er->wr_sampling_rate) { in echo_reference_write()
195 inFrames = (buffer->frame_count * er->rd_sampling_rate) / er->wr_sampling_rate + in echo_reference_write()
204 if (er->wr_buf_size < wrBufSize) { in echo_reference_write()
206 er->wr_buf_size, wrBufSize); in echo_reference_write()
207 er->wr_buf_size = wrBufSize; in echo_reference_write()
208 er->wr_buf = realloc(er->wr_buf, er->wr_buf_size * er->rd_frame_size); in echo_reference_write()
211 if (er->rd_channel_count != er->wr_channel_count) { in echo_reference_write()
214 int16_t *dst16 = (int16_t *)er->wr_buf; in echo_reference_write()
221 if (er->wr_sampling_rate != er->rd_sampling_rate) { in echo_reference_write()
222 if (er->resampler == NULL) { in echo_reference_write()
225 er->wr_sampling_rate, er->rd_sampling_rate); in echo_reference_write()
226 er->provider.get_next_buffer = echo_reference_get_next_buffer; in echo_reference_write()
227 er->provider.release_buffer = echo_reference_release_buffer; in echo_reference_write()
228 rc = create_resampler(er->wr_sampling_rate, in echo_reference_write()
229 er->rd_sampling_rate, in echo_reference_write()
230 er->rd_channel_count, in echo_reference_write()
232 &er->provider, in echo_reference_write()
233 &er->resampler); in echo_reference_write()
235 er->resampler = NULL; in echo_reference_write()
243 if (er->rd_channel_count != er->wr_channel_count) { in echo_reference_write()
244 er->wr_src_buf = er->wr_buf; in echo_reference_write()
246 er->wr_src_buf = buffer->raw; in echo_reference_write()
248 er->wr_frames_in = buffer->frame_count; in echo_reference_write()
252 er->wr_sampling_rate, er->rd_sampling_rate); in echo_reference_write()
253 er->resampler->resample_from_provider(er->resampler, in echo_reference_write()
254 (int16_t *)er->wr_buf, &inFrames); in echo_reference_write()
255 ALOGV_IF(er->wr_frames_in != 0, in echo_reference_write()
257 er->wr_frames_in); in echo_reference_write()
259 srcBuf = er->wr_buf; in echo_reference_write()
265 if (er->frames_in + inFrames > er->buf_size) { in echo_reference_write()
267 er->buf_size, er->frames_in + inFrames); in echo_reference_write()
268 er->buf_size = er->frames_in + inFrames; in echo_reference_write()
269 er->buffer = realloc(er->buffer, er->buf_size * er->rd_frame_size); in echo_reference_write()
271 memcpy((char *)er->buffer + er->frames_in * er->rd_frame_size, in echo_reference_write()
273 inFrames * er->rd_frame_size); in echo_reference_write()
274 er->frames_in += inFrames; in echo_reference_write()
278 inFrames, er->frames_in, er->buf_size, in echo_reference_write()
279 (int)er->wr_render_time.tv_sec, (int)er->wr_render_time.tv_nsec, er->playback_delay); in echo_reference_write()
281 pthread_cond_signal(&er->cond); in echo_reference_write()
283 pthread_mutex_unlock(&er->lock); in echo_reference_write()
298 struct echo_reference *er = (struct echo_reference *)echo_reference; in echo_reference_read() local
300 if (er == NULL) { in echo_reference_read()
304 pthread_mutex_lock(&er->lock); in echo_reference_read()
308 er->state &= ~ECHOREF_READING; in echo_reference_read()
314 buffer->delay_ns, er->frames_in, buffer->frame_count); in echo_reference_read()
316 if ((er->state & ECHOREF_READING) == 0) { in echo_reference_read()
318 echo_reference_reset_l(er); in echo_reference_read()
319 er->state |= ECHOREF_READING; in echo_reference_read()
322 if ((er->state & ECHOREF_WRITING) == 0) { in echo_reference_read()
323 memset(buffer->raw, 0, er->rd_frame_size * buffer->frame_count); in echo_reference_read()
331 if (er->frames_in < buffer->frame_count) { in echo_reference_read()
332 uint32_t timeoutMs = (uint32_t)((1000 * buffer->frame_count) / er->rd_sampling_rate / 2); in echo_reference_read()
344 pthread_cond_timedwait(&er->cond, &er->lock, &ts); in echo_reference_read()
346 ALOGV_IF((er->frames_in < buffer->frame_count), in echo_reference_read()
349 timeoutMs, er->frames_in, buffer->frame_count); in echo_reference_read()
355 if ((er->wr_render_time.tv_sec == 0 && er->wr_render_time.tv_nsec == 0) || in echo_reference_read()
361 if (buffer->time_stamp.tv_nsec < er->wr_render_time.tv_nsec) { in echo_reference_read()
362 tmp.tv_sec = buffer->time_stamp.tv_sec - er->wr_render_time.tv_sec - 1; in echo_reference_read()
363 tmp.tv_nsec = 1000000000 + buffer->time_stamp.tv_nsec - er->wr_render_time.tv_nsec; in echo_reference_read()
365 tmp.tv_sec = buffer->time_stamp.tv_sec - er->wr_render_time.tv_sec; in echo_reference_read()
366 tmp.tv_nsec = buffer->time_stamp.tv_nsec - er->wr_render_time.tv_nsec; in echo_reference_read()
370 int64_t expectedDelayNs = er->playback_delay + buffer->delay_ns - timeDiff; in echo_reference_read()
372 if (er->resampler != NULL) { in echo_reference_read()
374 int32_t rsmp_delay = er->resampler->delay_ns(er->resampler); in echo_reference_read()
381 expectedDelayNs, er->playback_delay, buffer->delay_ns, timeDiff); in echo_reference_read()
384 int64_t delayNs = ((int64_t)er->frames_in * 1000000000) / er->rd_sampling_rate; in echo_reference_read()
395 if (delay_sign == er->prev_delta_sign) { in echo_reference_read()
396 er->delta_count++; in echo_reference_read()
398 er->delta_count = 1; in echo_reference_read()
400 er->prev_delta_sign = delay_sign; in echo_reference_read()
402 if (er->delta_count > MIN_DELTA_NUM) { in echo_reference_read()
403 size_t previousFrameIn = er->frames_in; in echo_reference_read()
404 er->frames_in = (size_t)((expectedDelayNs * er->rd_sampling_rate)/1000000000); in echo_reference_read()
405 int offset = er->frames_in - previousFrameIn; in echo_reference_read()
409 delay_sign ? "positive" : "negative", er->frames_in, previousFrameIn); in echo_reference_read()
413 if (er->frames_in > er->buf_size) { in echo_reference_read()
414 er->buf_size = er->frames_in; in echo_reference_read()
415 er->buffer = realloc(er->buffer, er->buf_size * er->rd_frame_size); in echo_reference_read()
417 er->buf_size); in echo_reference_read()
421 memset((char *)er->buffer + previousFrameIn * er->rd_frame_size, in echo_reference_read()
422 0, offset * er->rd_frame_size); in echo_reference_read()
429 memcpy(er->buffer, (char *)er->buffer + (offset * er->rd_frame_size), in echo_reference_read()
430 er->frames_in * er->rd_frame_size); in echo_reference_read()
432 er->frames_in); in echo_reference_read()
437 er->delta_count = 0; in echo_reference_read()
438 er->prev_delta_sign = 0; in echo_reference_read()
446 expectedDelayNs, er->playback_delay, buffer->delay_ns, timeDiff); in echo_reference_read()
450 if (er->frames_in < buffer->frame_count) { in echo_reference_read()
451 if (buffer->frame_count > er->buf_size) { in echo_reference_read()
452 er->buf_size = buffer->frame_count; in echo_reference_read()
453 er->buffer = realloc(er->buffer, er->buf_size * er->rd_frame_size); in echo_reference_read()
454 ALOGV("echo_reference_read(): increasing buffer size to %zu", er->buf_size); in echo_reference_read()
457 memset((char *)er->buffer + er->frames_in * er->rd_frame_size, in echo_reference_read()
458 0, (buffer->frame_count - er->frames_in) * er->rd_frame_size); in echo_reference_read()
459 er->frames_in = buffer->frame_count; in echo_reference_read()
463 (char *)er->buffer, in echo_reference_read()
464 buffer->frame_count * er->rd_frame_size); in echo_reference_read()
466 er->frames_in -= buffer->frame_count; in echo_reference_read()
467 memcpy(er->buffer, in echo_reference_read()
468 (char *)er->buffer + buffer->frame_count * er->rd_frame_size, in echo_reference_read()
469 er->frames_in * er->rd_frame_size); in echo_reference_read()
475 buffer->frame_count, er->frames_in); in echo_reference_read()
477 pthread_cond_signal(&er->cond); in echo_reference_read()
480 pthread_mutex_unlock(&er->lock); in echo_reference_read()
493 struct echo_reference *er; in create_echo_reference() local
515 er = (struct echo_reference *)calloc(1, sizeof(struct echo_reference)); in create_echo_reference()
517 er->itfe.read = echo_reference_read; in create_echo_reference()
518 er->itfe.write = echo_reference_write; in create_echo_reference()
520 er->state = ECHOREF_IDLE; in create_echo_reference()
521 er->rd_format = rdFormat; in create_echo_reference()
522 er->rd_channel_count = rdChannelCount; in create_echo_reference()
523 er->rd_sampling_rate = rdSamplingRate; in create_echo_reference()
524 er->wr_format = wrFormat; in create_echo_reference()
525 er->wr_channel_count = wrChannelCount; in create_echo_reference()
526 er->wr_sampling_rate = wrSamplingRate; in create_echo_reference()
527 er->rd_frame_size = audio_bytes_per_sample(rdFormat) * rdChannelCount; in create_echo_reference()
528 er->wr_frame_size = audio_bytes_per_sample(wrFormat) * wrChannelCount; in create_echo_reference()
529 *echo_reference = &er->itfe; in create_echo_reference()
534 struct echo_reference *er = (struct echo_reference *)echo_reference; in release_echo_reference() local
536 if (er == NULL) { in release_echo_reference()
541 echo_reference_reset_l(er); in release_echo_reference()
542 if (er->resampler != NULL) { in release_echo_reference()
543 release_resampler(er->resampler); in release_echo_reference()
545 free(er); in release_echo_reference()