Lines Matching refs:shm
158 void cras_audio_shm_destroy(struct cras_audio_shm *shm);
162 cras_shm_get_checked_buffer_offset(const struct cras_audio_shm *shm, in cras_shm_get_checked_buffer_offset() argument
165 unsigned buffer_offset = shm->header->buffer_offset[buf_idx]; in cras_shm_get_checked_buffer_offset()
168 return MIN(buffer_offset, shm->samples_info.length); in cras_shm_get_checked_buffer_offset()
172 static inline uint8_t *cras_shm_buff_for_idx(const struct cras_audio_shm *shm, in cras_shm_buff_for_idx() argument
178 return shm->samples + cras_shm_get_checked_buffer_offset(shm, idx); in cras_shm_buff_for_idx()
183 cras_shm_get_checked_read_offset(const struct cras_audio_shm *shm, in cras_shm_get_checked_read_offset() argument
187 cras_shm_get_checked_buffer_offset(shm, buf_idx); in cras_shm_get_checked_read_offset()
188 unsigned read_offset = shm->header->read_offset[buf_idx]; in cras_shm_get_checked_read_offset()
193 if (read_offset > shm->config.used_size) in cras_shm_get_checked_read_offset()
195 if (buffer_offset + read_offset > shm->samples_info.length) in cras_shm_get_checked_read_offset()
202 cras_shm_get_checked_write_offset(const struct cras_audio_shm *shm, in cras_shm_get_checked_write_offset() argument
205 unsigned write_offset = shm->header->write_offset[buf_idx]; in cras_shm_get_checked_write_offset()
207 cras_shm_get_checked_buffer_offset(shm, buf_idx); in cras_shm_get_checked_write_offset()
212 write_offset = MIN(write_offset, shm->config.used_size); in cras_shm_get_checked_write_offset()
216 if (buffer_offset + write_offset > shm->samples_info.length) in cras_shm_get_checked_write_offset()
217 return shm->samples_info.length - buffer_offset; in cras_shm_get_checked_write_offset()
223 cras_shm_get_curr_read_frames(const struct cras_audio_shm *shm) in cras_shm_get_curr_read_frames() argument
225 unsigned buf_idx = shm->header->read_buf_idx & CRAS_SHM_BUFFERS_MASK; in cras_shm_get_curr_read_frames()
228 read_offset = cras_shm_get_checked_read_offset(shm, buf_idx); in cras_shm_get_curr_read_frames()
229 write_offset = cras_shm_get_checked_write_offset(shm, buf_idx); in cras_shm_get_curr_read_frames()
234 return (write_offset - read_offset) / shm->config.frame_bytes; in cras_shm_get_curr_read_frames()
239 cras_shm_get_read_buffer_base(const struct cras_audio_shm *shm) in cras_shm_get_read_buffer_base() argument
241 unsigned i = shm->header->read_buf_idx & CRAS_SHM_BUFFERS_MASK; in cras_shm_get_read_buffer_base()
242 return cras_shm_buff_for_idx(shm, i); in cras_shm_get_read_buffer_base()
247 cras_shm_get_write_buffer_base(const struct cras_audio_shm *shm) in cras_shm_get_write_buffer_base() argument
249 unsigned i = shm->header->write_buf_idx & CRAS_SHM_BUFFERS_MASK; in cras_shm_get_write_buffer_base()
251 return cras_shm_buff_for_idx(shm, i); in cras_shm_get_write_buffer_base()
256 cras_shm_get_writeable_frames(const struct cras_audio_shm *shm, in cras_shm_get_writeable_frames() argument
259 unsigned buf_idx = shm->header->write_buf_idx & CRAS_SHM_BUFFERS_MASK; in cras_shm_get_writeable_frames()
261 const unsigned frame_bytes = shm->config.frame_bytes; in cras_shm_get_writeable_frames()
264 write_offset = cras_shm_get_checked_write_offset(shm, buf_idx); in cras_shm_get_writeable_frames()
273 return cras_shm_buff_for_idx(shm, buf_idx) + write_offset; in cras_shm_get_writeable_frames()
281 cras_shm_get_readable_frames(const struct cras_audio_shm *shm, size_t offset, in cras_shm_get_readable_frames() argument
284 unsigned buf_idx = shm->header->read_buf_idx & CRAS_SHM_BUFFERS_MASK; in cras_shm_get_readable_frames()
289 read_offset = cras_shm_get_checked_read_offset(shm, buf_idx); in cras_shm_get_readable_frames()
290 write_offset = cras_shm_get_checked_write_offset(shm, buf_idx); in cras_shm_get_readable_frames()
291 final_offset = read_offset + offset * shm->config.frame_bytes; in cras_shm_get_readable_frames()
296 write_offset = cras_shm_get_checked_write_offset(shm, buf_idx); in cras_shm_get_readable_frames()
303 *frames = (write_offset - final_offset) / shm->config.frame_bytes; in cras_shm_get_readable_frames()
304 return cras_shm_buff_for_idx(shm, buf_idx) + final_offset; in cras_shm_get_readable_frames()
308 static inline size_t cras_shm_get_bytes_queued(const struct cras_audio_shm *shm) in cras_shm_get_bytes_queued() argument
311 const unsigned used_size = shm->config.used_size; in cras_shm_get_bytes_queued()
317 read_offset = MIN(shm->header->read_offset[i], used_size); in cras_shm_get_bytes_queued()
318 write_offset = MIN(shm->header->write_offset[i], used_size); in cras_shm_get_bytes_queued()
327 static inline int cras_shm_get_frames(const struct cras_audio_shm *shm) in cras_shm_get_frames() argument
331 bytes = cras_shm_get_bytes_queued(shm); in cras_shm_get_frames()
332 if (bytes % shm->config.frame_bytes != 0) in cras_shm_get_frames()
334 return bytes / shm->config.frame_bytes; in cras_shm_get_frames()
339 cras_shm_get_frames_in_curr_buffer(const struct cras_audio_shm *shm) in cras_shm_get_frames_in_curr_buffer() argument
341 size_t buf_idx = shm->header->read_buf_idx & CRAS_SHM_BUFFERS_MASK; in cras_shm_get_frames_in_curr_buffer()
343 const unsigned used_size = shm->config.used_size; in cras_shm_get_frames_in_curr_buffer()
345 read_offset = MIN(shm->header->read_offset[buf_idx], used_size); in cras_shm_get_frames_in_curr_buffer()
346 write_offset = MIN(shm->header->write_offset[buf_idx], used_size); in cras_shm_get_frames_in_curr_buffer()
351 return (write_offset - read_offset) / shm->config.frame_bytes; in cras_shm_get_frames_in_curr_buffer()
355 static inline int cras_shm_is_buffer_available(const struct cras_audio_shm *shm) in cras_shm_is_buffer_available() argument
357 size_t buf_idx = shm->header->write_buf_idx & CRAS_SHM_BUFFERS_MASK; in cras_shm_is_buffer_available()
359 return (shm->header->write_offset[buf_idx] == 0); in cras_shm_is_buffer_available()
364 cras_shm_get_num_writeable(const struct cras_audio_shm *shm) in cras_shm_get_num_writeable() argument
367 if (!cras_shm_is_buffer_available(shm)) in cras_shm_get_num_writeable()
370 return shm->config.used_size / shm->config.frame_bytes; in cras_shm_get_num_writeable()
375 static inline int cras_shm_check_write_overrun(struct cras_audio_shm *shm) in cras_shm_check_write_overrun() argument
379 shm->header->write_buf_idx & CRAS_SHM_BUFFERS_MASK; in cras_shm_check_write_overrun()
381 if (!shm->header->write_in_progress[write_buf_idx]) { in cras_shm_check_write_overrun()
382 unsigned int used_size = shm->config.used_size; in cras_shm_check_write_overrun()
384 if (shm->header->write_offset[write_buf_idx]) { in cras_shm_check_write_overrun()
385 shm->header->num_overruns++; /* Will over-write unread */ in cras_shm_check_write_overrun()
389 memset(cras_shm_buff_for_idx(shm, write_buf_idx), 0, used_size); in cras_shm_check_write_overrun()
391 shm->header->write_in_progress[write_buf_idx] = 1; in cras_shm_check_write_overrun()
392 shm->header->write_offset[write_buf_idx] = 0; in cras_shm_check_write_overrun()
398 static inline void cras_shm_buffer_written(struct cras_audio_shm *shm, in cras_shm_buffer_written() argument
401 size_t buf_idx = shm->header->write_buf_idx & CRAS_SHM_BUFFERS_MASK; in cras_shm_buffer_written()
406 shm->header->write_offset[buf_idx] += frames * shm->config.frame_bytes; in cras_shm_buffer_written()
407 shm->header->read_offset[buf_idx] = 0; in cras_shm_buffer_written()
412 cras_shm_frames_written(const struct cras_audio_shm *shm) in cras_shm_frames_written() argument
414 size_t buf_idx = shm->header->write_buf_idx & CRAS_SHM_BUFFERS_MASK; in cras_shm_frames_written()
416 return shm->header->write_offset[buf_idx] / shm->config.frame_bytes; in cras_shm_frames_written()
420 static inline void cras_shm_buffer_write_complete(struct cras_audio_shm *shm) in cras_shm_buffer_write_complete() argument
422 size_t buf_idx = shm->header->write_buf_idx & CRAS_SHM_BUFFERS_MASK; in cras_shm_buffer_write_complete()
424 shm->header->write_in_progress[buf_idx] = 0; in cras_shm_buffer_write_complete()
428 shm->header->write_buf_idx = buf_idx; in cras_shm_buffer_write_complete()
432 static inline void cras_shm_buffer_written_start(struct cras_audio_shm *shm, in cras_shm_buffer_written_start() argument
435 size_t buf_idx = shm->header->write_buf_idx & CRAS_SHM_BUFFERS_MASK; in cras_shm_buffer_written_start()
437 shm->header->write_offset[buf_idx] = frames * shm->config.frame_bytes; in cras_shm_buffer_written_start()
438 shm->header->read_offset[buf_idx] = 0; in cras_shm_buffer_written_start()
439 cras_shm_buffer_write_complete(shm); in cras_shm_buffer_written_start()
444 static inline void cras_shm_buffer_read(struct cras_audio_shm *shm, in cras_shm_buffer_read() argument
447 size_t buf_idx = shm->header->read_buf_idx & CRAS_SHM_BUFFERS_MASK; in cras_shm_buffer_read()
449 struct cras_audio_shm_header *header = shm->header; in cras_shm_buffer_read()
450 struct cras_audio_shm_config *config = &shm->config; in cras_shm_buffer_read()
476 static inline void cras_shm_buffer_read_current(struct cras_audio_shm *shm, in cras_shm_buffer_read_current() argument
479 size_t buf_idx = shm->header->read_buf_idx & CRAS_SHM_BUFFERS_MASK; in cras_shm_buffer_read_current()
480 struct cras_audio_shm_header *header = shm->header; in cras_shm_buffer_read_current()
481 struct cras_audio_shm_config *config = &shm->config; in cras_shm_buffer_read_current()
494 static inline void cras_shm_set_volume_scaler(struct cras_audio_shm *shm, in cras_shm_set_volume_scaler() argument
498 shm->header->volume_scaler = MIN(volume_scaler, 1.0); in cras_shm_set_volume_scaler()
502 static inline float cras_shm_get_volume_scaler(const struct cras_audio_shm *shm) in cras_shm_get_volume_scaler() argument
504 return shm->header->volume_scaler; in cras_shm_get_volume_scaler()
508 static inline void cras_shm_set_mute(struct cras_audio_shm *shm, size_t mute) in cras_shm_set_mute() argument
510 shm->header->mute = !!mute; in cras_shm_set_mute()
514 static inline size_t cras_shm_get_mute(const struct cras_audio_shm *shm) in cras_shm_get_mute() argument
516 return shm->header->mute; in cras_shm_get_mute()
520 static inline void cras_shm_set_frame_bytes(struct cras_audio_shm *shm, in cras_shm_set_frame_bytes() argument
523 shm->config.frame_bytes = frame_bytes; in cras_shm_set_frame_bytes()
524 if (shm->header) in cras_shm_set_frame_bytes()
525 shm->header->config.frame_bytes = frame_bytes; in cras_shm_set_frame_bytes()
529 static inline unsigned cras_shm_frame_bytes(const struct cras_audio_shm *shm) in cras_shm_frame_bytes() argument
531 return shm->config.frame_bytes; in cras_shm_frame_bytes()
535 static inline void cras_shm_set_callback_pending(struct cras_audio_shm *shm, in cras_shm_set_callback_pending() argument
538 shm->header->callback_pending = !!pending; in cras_shm_set_callback_pending()
542 static inline int cras_shm_callback_pending(const struct cras_audio_shm *shm) in cras_shm_callback_pending() argument
544 return shm->header->callback_pending; in cras_shm_callback_pending()
548 static inline void cras_shm_set_buffer_offset(struct cras_audio_shm *shm, in cras_shm_set_buffer_offset() argument
551 shm->header->buffer_offset[buf_idx] = offset; in cras_shm_set_buffer_offset()
559 static inline void cras_shm_set_used_size(struct cras_audio_shm *shm, in cras_shm_set_used_size() argument
564 shm->config.used_size = used_size; in cras_shm_set_used_size()
565 if (shm->header) in cras_shm_set_used_size()
566 shm->header->config.used_size = used_size; in cras_shm_set_used_size()
569 cras_shm_set_buffer_offset(shm, i, i * used_size); in cras_shm_set_used_size()
573 static inline unsigned cras_shm_used_size(const struct cras_audio_shm *shm) in cras_shm_used_size() argument
575 return shm->config.used_size; in cras_shm_used_size()
579 static inline unsigned cras_shm_used_frames(const struct cras_audio_shm *shm) in cras_shm_used_frames() argument
581 return shm->config.used_size / shm->config.frame_bytes; in cras_shm_used_frames()
585 static inline unsigned cras_shm_samples_size(const struct cras_audio_shm *shm) in cras_shm_samples_size() argument
587 return shm->samples_info.length; in cras_shm_samples_size()
591 static inline unsigned cras_shm_num_overruns(const struct cras_audio_shm *shm) in cras_shm_num_overruns() argument
593 return shm->header->num_overruns; in cras_shm_num_overruns()
599 static inline void cras_shm_copy_shared_config(struct cras_audio_shm *shm) in cras_shm_copy_shared_config() argument
601 memcpy(&shm->config, &shm->header->config, sizeof(shm->config)); in cras_shm_copy_shared_config()