Home | History | Annotate | Download | only in common

Lines Matching refs:shm

19 /* Configuration of the shm area.
29 /* Structure that is shared as shm between client and server.
64 /* Structure that holds the config for and a pointer to the audio shm area.
67 * area - Acutal shm region that is shared.
75 static inline uint8_t *cras_shm_buff_for_idx(const struct cras_audio_shm *shm,
80 return shm->area->samples + shm->config.used_size * idx;
85 unsigned cras_shm_check_read_offset(const struct cras_audio_shm *shm,
91 if (offset > shm->config.used_size)
98 unsigned cras_shm_check_write_offset(const struct cras_audio_shm *shm,
104 if (offset > shm->config.used_size)
105 return shm->config.used_size;
111 unsigned cras_shm_get_curr_read_frames(const struct cras_audio_shm *shm)
113 unsigned i = shm->area->read_buf_idx & CRAS_SHM_BUFFERS_MASK;
117 cras_shm_check_read_offset(shm, shm->area->read_offset[i]);
119 cras_shm_check_write_offset(shm, shm->area->write_offset[i]);
124 return (write_offset - read_offset) / shm->config.frame_bytes;
129 uint8_t *cras_shm_get_read_buffer_base(const struct cras_audio_shm *shm)
131 unsigned i = shm->area->read_buf_idx & CRAS_SHM_BUFFERS_MASK;
132 return cras_shm_buff_for_idx(shm, i);
137 uint8_t *cras_shm_get_write_buffer_base(const struct cras_audio_shm *shm)
139 unsigned i = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
141 return cras_shm_buff_for_idx(shm, i);
146 uint8_t *cras_shm_get_writeable_frames(const struct cras_audio_shm *shm,
150 unsigned i = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
152 const unsigned frame_bytes = shm->config.frame_bytes;
155 write_offset = cras_shm_check_write_offset(shm,
156 shm->area->write_offset[i]);
165 return cras_shm_buff_for_idx(shm, i) + write_offset;
173 uint8_t *cras_shm_get_readable_frames(const struct cras_audio_shm *shm,
177 unsigned buf_idx = shm->area->read_buf_idx & CRAS_SHM_BUFFERS_MASK;
183 cras_shm_check_read_offset(shm,
184 shm->area->read_offset[buf_idx]);
186 cras_shm_check_write_offset(shm,
187 shm->area->write_offset[buf_idx]);
188 final_offset = read_offset + offset * shm->config.frame_bytes;
194 shm, shm->area->write_offset[buf_idx]);
201 *frames = (write_offset - final_offset) / shm->config.frame_bytes;
202 return cras_shm_buff_for_idx(shm, buf_idx) + final_offset;
206 static inline size_t cras_shm_get_bytes_queued(const struct cras_audio_shm *shm)
209 const unsigned used_size = shm->config.used_size;
215 read_offset = MIN(shm->area->read_offset[i], used_size);
216 write_offset = MIN(shm->area->write_offset[i], used_size);
225 static inline int cras_shm_get_frames(const struct cras_audio_shm *shm)
229 bytes = cras_shm_get_bytes_queued(shm);
230 if (bytes % shm->config.frame_bytes != 0)
232 return bytes / shm->config.frame_bytes;
237 size_t cras_shm_get_frames_in_curr_buffer(const struct cras_audio_shm *shm)
239 size_t buf_idx = shm->area->read_buf_idx & CRAS_SHM_BUFFERS_MASK;
241 const unsigned used_size = shm->config.used_size;
243 read_offset = MIN(shm->area->read_offset[buf_idx], used_size);
244 write_offset = MIN(shm->area->write_offset[buf_idx], used_size);
249 return (write_offset - read_offset) / shm->config.frame_bytes;
253 static inline int cras_shm_is_buffer_available(const struct cras_audio_shm *shm)
255 size_t buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
257 return (shm->area->write_offset[buf_idx] == 0);
262 size_t cras_shm_get_num_writeable(const struct cras_audio_shm *shm)
265 if (!cras_shm_is_buffer_available(shm))
268 return shm->config.used_size / shm->config.frame_bytes;
273 static inline int cras_shm_check_write_overrun(struct cras_audio_shm *shm)
276 size_t write_buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
278 if (!shm->area->write_in_progress[write_buf_idx]) {
279 unsigned int used_size = shm->config.used_size;
281 if (shm->area->write_offset[write_buf_idx]) {
282 shm->area->num_overruns++; /* Will over-write unread */
286 memset(cras_shm_buff_for_idx(shm, write_buf_idx), 0, used_size);
288 shm->area->write_in_progress[write_buf_idx] = 1;
289 shm->area->write_offset[write_buf_idx] = 0;
296 void cras_shm_buffer_written(struct cras_audio_shm *shm, size_t frames)
298 size_t buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
303 shm->area->write_offset[buf_idx] += frames * shm->config.frame_bytes;
304 shm->area->read_offset[buf_idx] = 0;
309 unsigned int cras_shm_frames_written(const struct cras_audio_shm *shm)
311 size_t buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
313 return shm->area->write_offset[buf_idx] / shm->config.frame_bytes;
317 static inline void cras_shm_buffer_write_complete(struct cras_audio_shm *shm)
319 size_t buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
321 shm->area->write_in_progress[buf_idx] = 0;
325 shm->area->write_buf_idx = buf_idx;
330 void cras_shm_buffer_written_start(struct cras_audio_shm *shm, size_t frames)
332 size_t buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
334 shm->area->write_offset[buf_idx] = frames * shm->config.frame_bytes;
335 shm->area->read_offset[buf_idx] = 0;
336 cras_shm_buffer_write_complete(shm);
342 void cras_shm_buffer_read(struct cras_audio_shm *shm, size_t frames)
344 size_t buf_idx = shm->area->read_buf_idx & CRAS_SHM_BUFFERS_MASK;
346 struct cras_audio_shm_area *area = shm->area;
347 struct cras_audio_shm_config *config = &shm->config;
374 void cras_shm_buffer_read_current(struct cras_audio_shm *shm, size_t frames)
376 size_t buf_idx = shm->area->read_buf_idx & CRAS_SHM_BUFFERS_MASK;
377 struct cras_audio_shm_area *area = shm->area;
378 struct cras_audio_shm_config *config = &shm->config;
392 void cras_shm_set_volume_scaler(struct cras_audio_shm *shm, float volume_scaler)
395 shm->area->volume_scaler = MIN(volume_scaler, 1.0);
399 static inline float cras_shm_get_volume_scaler(const struct cras_audio_shm *shm)
401 return shm->area->volume_scaler;
405 static inline void cras_shm_set_mute(struct cras_audio_shm *shm, size_t mute)
407 shm->area->mute = !!mute;
411 static inline size_t cras_shm_get_mute(const struct cras_audio_shm *shm)
413 return shm->area->mute;
417 static inline void cras_shm_set_frame_bytes(struct cras_audio_shm *shm,
420 shm->config.frame_bytes = frame_bytes;
421 if (shm->area)
422 shm->area->config.frame_bytes = frame_bytes;
426 static inline unsigned cras_shm_frame_bytes(const struct cras_audio_shm *shm)
428 return shm->config.frame_bytes;
433 void cras_shm_set_callback_pending(struct cras_audio_shm *shm, int pending)
435 shm->area->callback_pending = !!pending;
438 /* Returns non-zero if a callback is pending for this shm region. */
439 static inline int cras_shm_callback_pending(const struct cras_audio_shm *shm)
441 return shm->area->callback_pending;
444 /* Sets the used_size of the shm region. This is the maximum number of bytes
448 void cras_shm_set_used_size(struct cras_audio_shm *shm, unsigned used_size)
450 shm->config.used_size = used_size;
451 if (shm->area)
452 shm->area->config.used_size = used_size;
455 /* Returns the used size of the shm region in bytes. */
456 static inline unsigned cras_shm_used_size(const struct cras_audio_shm *shm)
458 return shm->config.used_size;
461 /* Returns the used size of the shm region in frames. */
462 static inline unsigned cras_shm_used_frames(const struct cras_audio_shm *shm)
464 return shm->config.used_size / shm->config.frame_bytes;
468 static inline unsigned cras_shm_total_size(const struct cras_audio_shm *shm)
470 return cras_shm_used_size(shm) * CRAS_NUM_SHM_BUFFERS +
471 sizeof(*shm->area);
476 unsigned cras_shm_num_overruns(const struct cras_audio_shm *shm)
478 return shm->area->num_overruns;
481 /* Copy the config from the shm region to the local config. Used by clients
484 static inline void cras_shm_copy_shared_config(struct cras_audio_shm *shm)
486 memcpy(&shm->config, &shm->area->config, sizeof(shm->config));
521 * rw_fd_out - Filled with the RW fd for the shm
522 * ro_fd_out - Filled with the RO fd for the shm region.