Lines Matching +full:one +full:- +full:timer +full:- +full:only
1 .. SPDX-License-Identifier: GPL-2.0
4 Userspace-driven timers
12 This document describes the userspace-driven timers: virtual ALSA timers
15 stream with timer sources which we don't have ALSA timers exported for
17 two virtual sound devices using ``snd-aloop`` (for instance, when
18 we have a network application sending frames to one snd-aloop device,
19 and another sound application listening on the other end of snd-aloop).
21 Enabling userspace-driven timers
24 The userspace-driven timers could be enabled in the kernel using the
28 Userspace-driven timers API
31 Userspace application can create a userspace-driven ALSA timer by
33 ``/dev/snd/timer`` device file descriptor. The ``snd_timer_uinfo``
46 the virtual timer. ``resolution`` field simply provides an information
47 about the virtual timer, but does not affect the timing itself. ``id``
49 field after the call can be used as a timer subdevice number when
50 passing the timer to ``snd-aloop`` kernel module or other userspace
51 applications. There could be up to 128 userspace-driven timers in the
52 system at one moment of time, thus the id value ranges from 0 to 127.
55 a timer file descriptor, which can be used to trigger the timer, in the
57 descriptor for the timer guarantees that the timer can only be triggered
58 by the process which created it. The timer then can be triggered with
59 ``SNDRV_TIMER_IOCTL_TRIGGER`` ioctl call on the timer file descriptor.
61 So, the example code for creating and triggering the timer would be:
66 /* Timer is going to tick (presumably) every 1000000 ns */
68 .id = -1,
71 int timer_device_fd = open("/dev/snd/timer", O_RDWR | O_CLOEXEC);
74 perror("Failed to create the timer");
75 return -1;
81 * Now we want to trigger the timer. Callbacks of all of the
82 * timer instances binded to this timer will be executed after
89 /* Now, destroy the timer */
93 More detailed example of creating and ticking the timer could be found
96 Userspace-driven timers and snd-aloop
97 -------------------------------------
99 Userspace-driven timers could be easily used with ``snd-aloop`` module
101 sound loopback. For instance, if one of the applications receives sound
102 frames from network and sends them to snd-aloop pcm device, and another
103 application listens for frames on the other snd-aloop pcm device, it
106 not when the certain amount of jiffies elapses. Userspace-driven ALSA
109 To use userspace-driven ALSA timer as a timer source of snd-aloop, pass
110 the following string as the snd-aloop ``timer_source`` parameter:
114 # modprobe snd-aloop timer_source="-1.4.<utimer_id>"
116 Where ``utimer_id`` is the id of the timer you created with
118 userspace-driven timers device (``SNDRV_TIMER_GLOBAL_UDRIVEN``).
120 ``resolution`` for the userspace-driven ALSA timer used with snd-aloop
122 the timer is going to tick every time a new period of frames is ready.
124 After that, each time you trigger the timer with
126 from one snd-aloop device to another.