We illustrate the use of YAPI with an example of a filter
that scales video lines.
The purpose of the example is twofold. First we
illustrate the combination of deterministic and non-deterministic
communication. Second we illustrate the decoupling of the data types that are
used for communication and computation. To this end we assume that the filter
receives a stream of window widths from a window manager through input port
and a stream of pixels from a video source through input port
. The
function of the filter is to scale the incoming video frames according to the
incoming window widths and to transmit the resulting stream of pixels through
output port
as outlined in the code fragment shown in
Figure 1.4.
The video source and the window manager are not synchronized. We assume that
the video source produces frames at a constant rate using write action
, where
is an output port and
is
a video frame of
video lines that each contain
video pixels. The
behavior of the window manager is unknown because it is controlled by the
user. In order to cope with the non-deterministic behavior of the window
manager we guard the read action of the window width in the filter with the
select action
. If the select action
returns 0 then this indicates that port
can deliver one token. Hence, we
initiate the read action
to obtain the new window
width
without the danger of blocking forever. If the select action
returns 1 then this means that port
can deliver
tokens.
Hence, we initiate the filtering of the next video frame. The resulting
latency between input and output depends on the granularity of the filter. The
filter shown in the example is line-based which means that it reads the video
frame by
consecutive read actions
where
represents a video line of
pixels thereby introducing a latency of one
video line. Frame-based and pixel-based filters are also feasible. Note that
in this scenario it is possible to scale two or more video frames to the same
window width, but that it is not possible to change the width of a window in
the middle of a video frame. In order to specify the latter, for instance to
allow non-rectangular windows, the select action should be moved to the inner
loop that iterates over the video lines.