mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-04 13:30:08 -05:00
rawmidi: define more abstract API for the timestamp reads
The frame structure is a bit internal thing for the kernel data transfer implementation. Introduce snd_rawmidi_tread() function which is straight for the application usage and hides the framing data transfers (kernel space API). The current code implements the read cache and does the merging of the frame reads with the similar timestamps (opposite to the kernel data split for big chunks). If the application wants to use super-duper-lighting-fast reads, the snd_rawmidi_read() may be used, but the structure must be defined on it's own, because this mechanism is not preferred and unsupported. BugLink: https://github.com/alsa-project/alsa-lib/issues/172 Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
42eeb5eca0
commit
5a5c2953ea
5 changed files with 144 additions and 37 deletions
|
|
@ -1071,11 +1071,30 @@ ssize_t snd_rawmidi_write(snd_rawmidi_t *rawmidi, const void *buffer, size_t siz
|
|||
* \param rawmidi RawMidi handle
|
||||
* \param buffer buffer to store the input MIDI bytes
|
||||
* \param size input buffer size in bytes
|
||||
* \retval count of MIDI bytes otherwise a negative error code
|
||||
*/
|
||||
ssize_t snd_rawmidi_read(snd_rawmidi_t *rawmidi, void *buffer, size_t size)
|
||||
{
|
||||
assert(rawmidi);
|
||||
assert(rawmidi->stream == SND_RAWMIDI_STREAM_INPUT);
|
||||
if ((rawmidi->params_mode & SNDRV_RAWMIDI_MODE_FRAMING_MASK) == SNDRV_RAWMIDI_MODE_FRAMING_TSTAMP)
|
||||
size &= ~(sizeof(struct snd_rawmidi_framing_tstamp) - 1);
|
||||
assert(buffer || size == 0);
|
||||
return (rawmidi->ops->read)(rawmidi, buffer, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief read MIDI bytes from MIDI stream with timestamp
|
||||
* \param rawmidi RawMidi handle
|
||||
* \param[out] tstamp timestamp for the returned MIDI bytes
|
||||
* \param buffer buffer to store the input MIDI bytes
|
||||
* \param size input buffer size in bytes
|
||||
* \retval count of MIDI bytes otherwise a negative error code
|
||||
*/
|
||||
ssize_t snd_rawmidi_tread(snd_rawmidi_t *rawmidi, struct timespec *tstamp, void *buffer, size_t size)
|
||||
{
|
||||
assert(rawmidi);
|
||||
assert(rawmidi->stream == SND_RAWMIDI_STREAM_INPUT);
|
||||
assert(buffer || size == 0);
|
||||
return (rawmidi->ops->tread)(rawmidi, tstamp, buffer, size);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue