mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-12-22 12:16:31 +01:00
c2f79d9fdf
In alsa-lib PCM API, snd_pcm_read[i|n]() and snd_pcm_write[i|n]() are used to transfer data frames from/to hardware. When a handler is not opened with specific flags, these functions perform blocking operation; i.e. the function call doesn't return till all of request number of data frames are actually handled, or call is interrupted by Unix signals, or PCM substeam corrupts due to hardware reasons. This commit adds support for this type of data transmission. For cases that requested data frames are not processed by container interface, this commit adds internal cache mechanism to handle rest of data frames in next timing. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
47 lines
1.2 KiB
C
47 lines
1.2 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
//
|
|
// frame-cache.h - maintainer of cache for data frame.
|
|
//
|
|
// Copyright (c) 2018 Takashi Sakamoto <o-takashi@sakamocchi.jp>
|
|
//
|
|
// Licensed under the terms of the GNU General Public License, version 2.
|
|
|
|
#include <alsa/asoundlib.h>
|
|
|
|
struct frame_cache {
|
|
void *buf;
|
|
void *buf_ptr;
|
|
|
|
unsigned int remained_count;
|
|
|
|
snd_pcm_access_t access;
|
|
unsigned int bytes_per_sample;
|
|
unsigned int samples_per_frame;
|
|
unsigned int frames_per_cache;
|
|
|
|
void (*align_frames)(struct frame_cache *cache,
|
|
unsigned int consumed_count);
|
|
};
|
|
|
|
int frame_cache_init(struct frame_cache *cache, snd_pcm_access_t access,
|
|
unsigned int bytes_per_sample,
|
|
unsigned int samples_per_frame,
|
|
unsigned int frames_per_cache);
|
|
void frame_cache_destroy(struct frame_cache *cache);
|
|
|
|
static inline unsigned int frame_cache_get_count(struct frame_cache *cache)
|
|
{
|
|
return cache->remained_count;
|
|
}
|
|
|
|
static inline void frame_cache_increase_count(struct frame_cache *cache,
|
|
unsigned int frame_count)
|
|
{
|
|
cache->remained_count += frame_count;
|
|
}
|
|
|
|
static inline void frame_cache_reduce(struct frame_cache *cache,
|
|
unsigned int consumed_count)
|
|
{
|
|
cache->align_frames(cache, consumed_count);
|
|
}
|