sound: rawmidi: Add framing mode
PATCH v3 1/1 sound: rawmidi: Add framing mode
This commit adds a new framing mode that frames all MIDI data into 16-byte frames with a timestamp.
The main benefit is that we can get accurate timestamps even if userspace wakeup and processing is not immediate.
---
Changes in v3:
* Bumped protocol version
* More checks for invalid combinations in set_params
* Frame: Timestamp is 64 bit for seconds and 3 bytes for data
* Sets clock and framing individually.
(Clock_type is unsigned char instead of clockid_t to avoid padding issues.)
* Supports both monotonic and monotonic_raw timestamps
* Moved spin lock to after timestamp retreival. Both to decrease time spent in spin lock, and to get more accurate timestamp in case the spin lock is actually busy.
include/sound/rawmidi.h | 2 ++ include/uapi/sound/asound.h | 21 +++++++++++-- sound/core/rawmidi.c | 63 +++++++++++++++++++++++++++++++++++-- 3 files changed, 82 insertions(+), 4 deletions(-)
include/sound/rawmidi.h +2 -0
@@ -81,6 +81,8 @@ struct snd_rawmidi_substream {bool opened;/* open flag */ bool append;/* append flag (merge more streams) */ bool active_sensing;/* send active sensing when close */ +u8 framing;/* whether to frame input data */ +clockid_t clock_type;/* clock source to use for input framing */ int use_count;/* use counter (for output) */ size_t bytes;struct snd_rawmidi *rmidi;
include/uapi/sound/asound.h +19 -2
@@ -710,7 +710,7 @@ enum {* Raw MIDI section - /dev/snd/midi?? */ -#define SNDRV_RAWMIDI_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 1) +#define SNDRV_RAWMIDI_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 2)enum {SNDRV_RAWMIDI_STREAM_OUTPUT =0 ,
@@ -736,12 +736,29 @@ struct snd_rawmidi_info {unsigned char reserved[64 ];/* reserved for future use */ }; +enum { +SNDRV_RAWMIDI_FRAMING_NONE =0 , +SNDRV_RAWMIDI_FRAMING_TSTAMP , +SNDRV_RAWMIDI_FRAMING_LAST =SNDRV_RAWMIDI_FRAMING_TSTAMP , +}; + +#define SND_RAWMIDI_FRAMING_DATA_LENGTH 3 + +struct snd_rawmidi_framing_tstamp { +unsigned long long tv_sec;/* seconds */ +unsigned int tv_nsec;/* nanoseconds */ +unsigned char length; +unsigned char data[SND_RAWMIDI_FRAMING_DATA_LENGTH ]; +}; +struct snd_rawmidi_params {int stream;size_t buffer_size;/* queue size in bytes */ size_t avail_min;/* minimum avail bytes for wakeup */ unsigned int no_active_sensing:1 ;/* do not send active sensing byte in close() */ -unsigned char reserved[16 ];/* reserved for future use */ +unsigned char framing;/* For input data only, frame incoming data */ +unsigned char clock_type;/* Type of clock to use for framing, same as clockid_t */ +unsigned char reserved[14 ];/* reserved for future use */ };#ifndef __KERNEL__
sound/core/rawmidi.c +61 -2
100 lines not on this page · raw message
Signature · 1 line
2.25.1