Playback - radishengine/drowsy GitHub Wiki
A Playback object is a queue of Playback Frame objects and a collection of Playback Stream objects.
Methods
playback.queueFrame(frame)
Adds the frame object to the playback queue.
Returns the new value for playback.availableMemory
.
playback.openStream(stream)
Attaches the stream object to this playback. There must not already be an attached stream with the same .name
property as this one.
All playback objects start with a 'playback'
stream already open. The stream object in that case is the same as the playback object.
playback.closeStream(identifier)
Close the playback stream with the given identifier. The stream must currently exist, or an error is thrown.
Closing the 'playback'
stream terminates the entire playback, clears the queue and prevents further frames from being added to the queue.
Properties
playback.name
Always 'playback'
. This is the stream name of the playback object.
playback.width
, playback.height
It's possible to have multiple video streams of different sizes, and at different positions. The total dimensions of the video space, if known. Individual video streams do not need to cover the entire video space.
These values will be Infinity
if they are unknown.
playback.backgroundColor
A CSS color-value string for the background of the video space. By default, it is transparent.
playback.allocatedMemory
A number representing the maximum amount of memory we plan to be using at any one point in time (not in total) for this playback, in bytes.
By default this value is equivalent to screen.width * screen.height * 4 * 2
, which is enough memory to store two copies of the user's entire screen as RGBA pixel data. (This is a completely arbitrary default, a rough guess at what is reasonable, and very much open to re-evaluation.)
playback.usedMemory
The sum of the .usedMemory
values of each frame currently in the queue
Another way of looking at it is when a frame is added to the queue, its .usedMemory
value is added to this value, and when it is taken off the queue its .usedMemory
value is subtracted again.
playback.availableMemory
The same as (playback.allocatedMemory - playback.usedMemory)
.
It might be negative, these values are more of an experimental guideline than something to be strictly enforced.
Frames
Frame Properties
frame.delay
Time, in milliseconds, that should have elapsed since the previous frame in this stream.
frame.forStream
Identifier string for the stream that this frame is meant to be a part of.
frame.usedMemory
For a frame that represents pixel data or audio sample data, this should be the approximate size in bytes of the raw data involved. Non-data frames can have 0
for this value.
Frame Methods
frame.enter(playback, stream)
Method called to tell the frame that it is time for it to "go".
Streams
Most of the properties and methods depend on the kind of stream:
Stream Properties
stream.name
Identifier string for the stream. It needs to be unique, but only in the context of this playback, not globally.
Video Streams
Video Stream Properties
video.width
, video.height
Pixel dimensions of the video buffer.
video.top
, video.left
Pixel offset from the top-left corner of the playback video space.
Usually there will be one video stream with the same .width
and .height
as the playback video space, and zero for .top
and .left
video.zOrder
Usually, multiple overlapping video streams are overlaid in the order they were added, with the most recently-added one on top. Setting this property allows a later-added video stream to appear underneath an earlier-added one.
video.isOpaque
true
if the video is guaranteed to have no transparent or semi-transparent pixels, false
if not.
Audio Streams
Audio Stream Properties
audio.forChannel
Should be 'left'
, 'right'
or 'mono'
.