Roku Objects (RO) are the standardized way Roku software exposes functionality for our products’ public
SDKs. In other words, to publish a new API, Roku will create a new Roku Object. The first product to
use this method is the BrightSign.
Roku Objects have these key objectives:
• To be largely language independent.
• To be robust to software upgrades. A RO interface, once established, never changes its methods
or its binary linkage.
•To be compatible with compiled or interpreted languages. ROs are completely discoverable and
callable at run time or compile time.
•To support multiple abstract interfaces. This allows objects to be used in powerful ways as we’ll
see below.
As well as the core Roku Object architecture, this reference also defines event architecture and the required
interfaces to participate in this scheme. The event scheme is a fundamental piece of any multi-threaded
application. Its standardization is the first part in a sequence of RO based standards Roku will adopt across
our products, to maximize compatibility of third party plug-ins.
This document describes the Roku Object architecture as two main sections:
• how to use them (as a script writer)
• the initial objects defined for BrightSign
Roku Object Interfaces and Methods
Every Roku Object consists of one or more “Interfaces”. An RO Interface consists of one or more
Methods. For example, the roVideoPlayer has two interfaces: ifMediaTransport and ifSetMessagePort.
The Interface ifSetMessagePort has one Member: SetPort.
For example:
p = CreateObject("roMessagePort")
video= CreateObject("roVideoPlayer")
This syntax makes use of a short cut provided by the language: The interface name is optional, unless it is
needed to resolve name conflicts.
For example:
gpio.SetPort(p)
is the same as:
gpio.ifSetMessagePort.SetPort(p)
Note that the abstract Interface ifSetMessagePort is exposed and implemented by both the
roGpioControlPort and the roVideoPlayer objects. Once the method SetPort is called, these objects will
send their events to the supplied message port. This is discussed more in the Event section below.
Once an interface is defined and published, it is never changed. For example, imagine if Roku decided in a
future release that the ifSetMessagePort really needed another method, say “ClearMessagePort”. Instead of
changing the ifSetMessagePort interface, we would create a new interface ifSetMessagePort2. This
4
interface would contain only the new methods. The “old” method still exists in the original Interface.
Older applications will only use the original interface, but newer applications could use the original and the
new interface. This ensures full backwards compatibility with the installed base of Roku scripts and
applications with future versions of Roku products.
Roku Objects consist only of interfaces. Interfaces define only methods. There is no concept of a
“property” or variable at the Object or Interface level. These must be implemented as Set/Get methods in
an Interface.
Inheritance
There is no explicit support for Inheritance in the RO architecture. However, this section is a brief
discussion of how C++ concepts of inheritance map to ROs.
•Use of Virtual Base classes to abstract interfaces. For example, in C++ one might create a
virtual base class for a AsciiStream Object. Then create implementation class for an RS232Port,
TCP, or Keyboard. This type of functionality is accomplished with Roku Objects by defining an
Interface (for example ifAsciiStream), then ROs that expose this interface (e.g. the roTCP)
•Use of “Mix-in” classes to bring-in existing functionality. ROs don’t have an exact equivalent.
If the writer of an object wants to bring-in existing RO they can create them and hold a reference
to them internally. If the object creator wants to expose a created objects Interface(s), it must
expose the same interface (all interfaces are public), and then when an interface method is called,
the RO calls the appropriate Interface of a called object.
Classes
A Class Name is the name used to create a Roku Object. For example:
video= CreateObject("roVideoPlayer")
roVideoPlayer is the class name.
Object and Class Name Syntax
Class names:
• must start with an alphabetic character (a – z)
• may consist of alphabetic characters, numbers, or the symbol “_” (underscore)
• they are not case sensitive
• may be of any reasonable length
Zones
With the BrightSign Zones feature, you can divide the screen into rectangles and play different content in
each rectangle.
A zone can contain video and images, images, a clock, or text. There can be only one video zone per
screen. However, there can be multiple of other types of zones on the screen. A text zone can contain
simple text strings or can be configured to display an RSS feed in a ticker type display.
To enable zone functionality, the following global function must be called in the script:
EnableZoneSupport(enable As Boolean) As Void
When zones are enabled, the image layer is always on top of the video layer. When zones are not enabled,
the image layer is hidden whenever video is played, and the video layer is hidden whenever images are
played.
5
Example:
This script creates 5 zones. The first one contains a video player, the next two contain image players, the
fourth has a clock widget and the last is a text widget. The objects used in this example are explained in
subsequent sections of this document.
r=CreateObject("roRectangle", 60, 900, 1800, 100)
t=CreateObject("roTextWidget", r, 3, 0, 5)
t.SetForegroundColor(&ha0a0a0)
t.PushString("The next Museum tour will be starting at 2:30pm in
the lobby.")
t.PushString("Visit the Museum Store today for 15% all
purchases.")
t.PushString("Become a museum member and today's visit is free.")
6
t.PushString("BrightSign solid-state media players power
interactive video exhibits with simplicity, reliability and
interactivity to high-impact digital signage. Learn more at
www.roku.com/brightsign.")
if type(msg)="roGpioButton"then if debug AND msg=12 then'Video Select end endif else print "Unknown event "; type(event)
endif
goto msg_loop
BrightSign Object Library
This section specifies each of the Roku Objects that are included with BrigthScript.
Event Loops
When creating anything more than a very simple script, an Event Loop will need to be created. An Event
Loop typically has this structure:
1. wait for the event
2. process the event
3. jump back to 1
Events are things like a button press, a timer that has triggered, a video that has finished playing back, etc.
By convention, Roku Object (RO) events work as follows.
• A RO of type “roMessagePort” is created. In BrightScript, by the user’s script.
• ROs that can send events are instructed to send their events to this message port. You could set up
multiple message ports, and have each event go to its own message port, but it is usually simpler
to just create one message port, and have the events all go to this one port. To instruct the RO to
send events to a specific port, use the ifSetMessagePort Interface.
•The script waits for an event. The actual function to do this is the ifMessagePort.WaitMessage(),
but if you are using BrightScript, the built-in statement WAIT makes this easy.
•If multiple event types are possible, your script should determine which event that the wait
received, then process it. The script then jumps back to the Wait.
An “Event” can be generated by any Roku Object. For example, the class “roGpioControlPort” sends
events of type “roGpioButton”. The “roGpioButton” has one interface: ifInt. ifInt allows access to an
integer. An event loop needs to be aware of the possible events it can get, and process them.
7
Example
print "BrightSign Button-LED Test Running"
p = CreateObject("roMessagePort")
tmr = CreateObject("roMessagePort")
gpio = CreateObject("roGpioControlPort")
gpio.SetPort(p)
event_loop:
msg=wait(0, p)
if type(msg)<>"roGpioButton" then event_loop
butn = msg.GetInt()
if butn > 5 then event_loop
gpio.SetOutputState(butn+17,1)
print "Button Pressed: ";butn
msg = wait (500, tmr)
gpio.SetOutputState(butn+17,0)
clear_events:
msg=p.GetMessage():if type(msg)<>"rotINT32" then clear_events
goto event_loop
Classes
For each class a brief description is given, a list of interfaces, and the member functions in the interfaces.
roList
A general purpose doubly link list. It can be used as a container for arbitrary length lists of Roku Objects.
Interfaces:
• ifList
Count() As Integer
IsEmpty() As Boolean
ResetIndex() As Boolean
AddTail(obj As Object) As Void
AddHead(obj As Object) As Void
FindIndex(name As String) As Boolean
RemoveIndex() As Object
GetIndex() As Object
RemoveTail() As Object
RemoveHead() As Object
GetTail() As Object
GetHead() As Object
8
roMessagePort
A message port is the place messages (events) are sent. See the “Event Loops” section for more details.
When using Roku BrightScript, you would not call these functions directly. Instead, use the “Wait”
BrightScript statement (see the BrightScript documentation).
Interfaces:
• ifMessagePort
GetMessage() As Object
WaitMessage(timeout As Integer) As Object
PostMessage(msg As Object) As Void
9
roVideoMode
This class allows you to set the output video resolution. The same video resolution is applied to all video
outputs on BrightSign. Video or images that are subsequently decoded and displayed will be scaled (using
the hardware scalar) to this output resolution if necessary.
Interfaces:
• ifVideoMode
SetMode(mode As String) As Boolean
• ifVideoMode
GetResX() As Integer
• ifVideoMode
GetResY() As Integer
• ifVideoMode
GetSafeX() As Integer
• ifVideoMode
GetSafeY() As Integer
• ifVideoMode
GetSafeWidth() As Integer
• ifVideoMode
GetSafeHeight() As Integer
• ifVideoMode
SetPowerSaveMode(power_save_enable As Boolean) As Boolean
• ifSetMessagePort
SetPort(obj As Object) As Void
Supported modes that can be passed to SetMode on the HD110, HD210, HD410, HD810 and HD1010 are:
• “auto”
• “640x480x60p”
• “800x600x75p”
• “1024x768x75p”
• “1360x768x60p”
• “720x576x50p”
• “720x480x60p”
• “1280x720x50p”
• “1280x720x59.94p”
• “1280x720x60p”
• “1920x1080x50i”
• “1920x1080x59.94i”
• “1920x1080x60i”
• “1920x1080x29.97p”
• “1920x1080x50p”
• “1920x1080x60p”
10
If the mode is set to ‘auto’, BrightSign will try to determine the best video mode to use based on connected
hardware. The algorithm is:
• Try VGA first – if VGA is attached use the best mode as reported by the monitor.
• Try HDMI next – if HDMI is attached use the best mode as reported by the monitor.
• Default to 1024x768x75p
Supported modes that can be passed to SetMode on the HD2000 are:
• "1024x768x60p"
• "720x480x60p"
• “720x576x50p”
• "1280x720x60p"
• “1280x720x50p”
• “1280x768x60p”
• “1920x1080x60i”
GetResX, GetResY ()
Get the total display size for the current video mode.
GetSafeX, GetSafeY ()
Get the left and top coordinates for the start of the "safe area". For modes
that are generally displayed with no overscan, both will be zero.
GetSafeWidth, GetSafeHeight ()
Get the width and height of the "safe area". For modes that are generally
displayed with no overscan, these will return the same as GetResX and GetResY.
More information about safe areas can be found at:
http://en.wikipedia.org/wiki/Safe_area and
http://en.wikipedia.org/wiki/Overscan_amounts
SetPowerSaveMode ()
Turns off the syncs for VGA output and the DAC output for component video. For some monitors, this will
cause the monitor to go into standby mode.
Note that the BrightSign Hardware has a video anti-aliasing low pass filter that is set automatically. See
the hardware manual for more information.
If the video mode specified in SetMode is different than the object’s current video mode, the unit will
reboot and set the unit’s video mode to the new setting during system initialization.
11
roVideoPlayer
A Video Player is used to playback video files (using the generic ifMediaTransport Interface). If the
message port is set, the object will send events of type roVideoEvent. All object calls are asynchronous.
That is, video playback is handled in another thread from the script. The script will continue to run while
video is playing. Decoded video will be scaled to the output resolution specified by roVideoMode.
NOTE:
• Currently only MPEG2 files are supported by BrightSign
• On the HD110, HD210, HD410, HD810, and HD1010, only MPEG2 transport streams are
supported. Audio can be either AC3 or MP3, however AC3 audio will currently not be decoded on
the BrightSign – its raw data will be sent out over HDMI.
•On the HD2000, only MPEG2 program streams are supported. Simple elementary video streams
are not supported. A video stream must be muxed into a program stream. Audio can be either AC3
or PCM.
Interfaces:
• ifSetMessagePort
SetPort(obj As Object)As Void
• ifAudioControl – see roAudioPlayer for docs
• ifVideoControl
SetViewMode(mode As Integer) As Boolean
SetRectangle(r As roRectangle) As Void
• ifMediaTransport
PlayFile(filename As String) As Boolean
PlayStaticImage(filename As String) As Boolean
Stop() As Boolean
Play() As Boolean
SetLoopMode(mode As Integer) As Boolean
ClearEvents() As Boolean
AddEvent(userdata As Integer, time_in_ms As Integer) As Boolean
StopClear()As Boolean
If you wish to use a view mode different from the default, it must be set prior to starting video
playback.
view_mode values:
0 - Scale to fill (default). The aspect ratio can alter.
1 - Letterboxed and centered. The aspect ratio is maintained and the video has black borders.
2 - Fill screen and centered. The aspect ratio is maintained and the screen is filled.
To display the video in a zone, SetRectangle() must be called. EnableZoneSupport() must be
called to use zones functionality.
MPEG2 video files are encoded with a specific aspect ratio, and output display resolutions have an aspect
ratio. Video display modes 1 and 2 use these aspect ratios to ensure that the video file aspect ratio is
preserved when it is displayed. The only time that this will fail is when a widescreen monitor displays a 4:3
output resolution such as 800x600 across the whole screen i.e. the monitor doesn't respect the aspect ratio.
Please note that this feature relies on the correct aspect ratio marking of the MPEG2 video files.
Unfortunately, not all files are marked correctly.
12
Users can add events which trigger messages of the roVideoEvent “Timecode Hit” at the specified
millisecond times in a video file. The data field of the roVideoEvent holds the userdata passed in with
AddEvent.
Here is an example script that uses timecode events. The script prints out 2, 5 and 10 at 2 seconds, 5
seconds and 10 seconds into the video. The msg is approaching frame accurate.
10 v = CreateObject("roVideoPlayer")
20 p = CreateObject("roMessagePort")
30 v.SetPort(p)
40 ok = v.AddEvent(2, 2000) ' Add timed events to video
50 ok = v.AddEvent(5, 5000)
60 ok = v.AddEvent(10, 10000)
70 ok = v.AddEvent(100, 100000)
80 ok = v.PlayFile("ATA:/C5_d5_phil.vob")
90 msg = wait(0,p) ' Wait for all events
95 if msg.GetInt() = 8 then stop ' End of file
100 if msg.GetInt() <> 12 goto 90 ' I only care about time events
110 print msg.GetData() ' Print out index when the time event happens
120 goto 90
Calling PlayStaticImage displays an image on the video layer. The image is stretched to fill the
video rectangle.
13
roAudioPlayer
An audio player is used to play back audio files (using the generic ifMediaTransport Interface). If the
message port is set, the object will send events of type roAudioEvent. All object calls are asynchronous.
That is, audio playback is handled in another thread from the script. The script may continue to run while
audio is playing.
NOTE:
•MP3 files are supported on all BrightSigns while the HD2000 also supports WAV files.
Interfaces:
• ifSetMessagePort
SetPort(As Object) As Void
• ifMediaTransport
See roVideoPlayer for docs
• ifAudioControl
SetAudioOutput(audio_output As Integer) As Boolean
SetAudioMode(audio_mode As Integer) As Boolean
MapStereoOutput(mapping As Integer) As Boolean
SetVolume(volume As Integer) As Boolean
SetChannelVolumes(channel_mask As Integer, volume As Integer) As
Boolean
SetAudioOutputAux(audio_output As Integer) As Boolean
SetAudioModeAux(audio_mode As Integer) As Boolean
MapStereoOutputAux(mapping As Integer) As Boolean
SetVolumeAux(volume As Integer) As Boolean
SetChannelVolumesAux(channel_mask As Integer, volume As Integer)
As Boolean
SetAudioStream(stream_index As Integer) As Boolean
SetAudioStreamAux(stream_index As Integer) As Boolean
Before changing the audio output when a video file is playing or has played, a call to video.Stop()
is needed.
The following functions are currently only available on the HD2000:
• SetAudioOutput
• SetAudioMode
• MapStereoOutput
• SetChannelVolumes
• SetAudioOutputAux
• SetAudioModeAux
• MapStereoOutputAux
• SetVolumeAux
• SetChannelVolumesAux
• SetAudioStream
• SetAudioStreamAux
audio_output values:
0 - Analog audio
14
1 - USB audio
2 - SPDIF audio, stereo PCM
3 - SPDIF audio, raw AC3
4 - analog audio with SPDIF mirroring raw AC3
audio_mode values
(Options 0 and 1 only apply to video files; 2 applies to all audio sources)
0 - AC3 Surround
1 - AC3 mixed down to stereo
2 - No audio
mapping values
(used to select which analog output if audio_output set to 0)
0 - Stereo audio is mapped AUDIO-3
1 - Stereo audio is mapped to AUDIO-2
2 - Stereo audio is mapped to AUDIO-1
set_volume
Volume is a percentage and so takes a value 0-100. The volume value is clipped prior to use i.e.
SetVoume(101) will set the volume to 100 and return TRUE. The volume is the same for all
mapped outputs and USB/SPDIF/analog. There is however a separate volume level stored for
audioplayer and videoplayer.
Set_channel_volumes
You can control volume on individual audio channels. This volume command takes a hex channel
mask which determines which channels to apply the volume to and a level which is a percentage
of full scale. The volume control works on the channel of audio rather than the output. The
channel mask is a bit mask with the following bits for AC3 output:
&H01 Left
&H02 Right
&H04 Center
&H08 Subwoofer
&H10 Left surround
&H20 Right surround
&H3f is all channels, &H07 is just the LCR channels (Left, Center, Right), &H03 would just be
right and left, &H30 just the surrounds, etc. The channels are the channels in the audio file and not
the output channels i.e. if you are playing a stereo file but have mapped it to the middle analog
output then its volume is still controlled by the Left and Right bits &H01 and &H02.
Example: This code sets audio output to come out the Audio 1 port:
video = CreateObject("roVideoPlayer")
video.SetAudioMode(1) ‘ STEREO
video.SetAudioOutput(0)
video.MapStereoOutput(2)
Example: This code sets audio output to come out USB port to a USB Speaker
video.SetAudioMode(0) ‘ SURROUND 5.1 decoder
video.SetAudioOutput(1) ‘ USB
Example: This code sets the volume level for individual channels
15
audio = CreateObject(“roAudioPlayer”)
audio.SetChannelVolumes(&H01, 60) ‘left channel to 60%
audio.SetChannelVolumes(&H02, 75) ‘right channel to 75%
audio.SetChannelVolumes(&H04, 80) ‘center channel to 80%
audio.SetChannelVolumes(&H07, 70) ‘left, right, center channel to 70%
audio.SetChannelVolumes(&H3f, 65) ‘all channels to 65%
Playing Multiple Audio Files Simultaneously (HD2000 only)
Multiple MP3 files along with an audio track as part of a video file can be played to any combination of the
following:
• Analog outputs 1, 2, or 3
• SPDIF / HDMI
• USB
Only a single file can be sent to an output at any given time. For example, two roAudioPlayers cannot
simultaneously play to the SPDIF output - the second one to attempt a PlayFile will get an error. To free an
output, the audio or video stream must be stopped (using ifMediaTransport’s Stop or StopClear calls).
Notes on this functionality:
• SPDIF and HDMI are the same audio output.
• Currently only a single set of USB speakers is supported.
• Only similar files may be played out of analog outputs simultaneously (meaning that it is not possible
to play a WAV file out of one analog output while simultaneously playing an MP3 file out of another
analog output).
•If the audio for a playing video is connected to one of the analog outputs, any remaining analog
outputs cannot be used by other sources. That is, the remaining analog outputs cannot be used for MP3
or WAV file playback.
•Each audio and video stream played consumes some of the finite CPU resources. The amount
consumed depends on the bitrates of the streams. Testing is the only way to really tell whether a given
set of audio files can be played at the same time as a video
Example: This code plays a video with audio over SPDIF/HDMI and an mp3 file to an analog port:
Playing Video Files with Multiple Audio Streams (HD2000 only)
MPEG-2 program streams can optionally contain a number of audio streams. These can all be the same or
different formats. Generally this is used either to provide alternative audio formats, or alternative
mixes/languages.
The HD2000 supports the playback of two audio streams from within a single program stream. The two
audio streams may be played back simultaneously (subject to the limitations documented above for playing
back multiple audio files simultaneously), or a specific audio stream from within a program stream can be
selected to support multiple languages / mixes.
The following functions control the auxiliary stream:
• SetAudioOutputAux (audio_output)
• SetAudioModeAux (audio_mode)
16
• MapStereoOutputAux (mapping)
• SetVolumeAux (volume)
• SetChannelVolumesAux (channel_mask, volume)
The following functions control which specific streams are played
• SetAudioStream (stream_index)
• SetAudioStreamAux (stream_index)
The stream_index is the index of the audio stream within the program stream to be played. A value of -1
indicates that the first audio stream found within the multiplex will be played.
Example: This code plays a video with the main audio stream over SPDIF/HDMI and the auxiliary
stream to an analog port:
Example: This code shows how to play a video with multiple languages:
REM – select language from first audio track
video.SetAudioStream(0)
video.PlayFile("Language.mpg")
REM – select language from second audio track
video.SetAudioStream(1)
video.PlayFile("Language.mpg")
Because the streams to be played are specified prior to playing the file, there are some rules necessary as to
what happens if the streams selected are invalid:
• If the main stream is set to -1 then the first audio stream found within the multiplex will be played.
• If the main stream is not -1 but is invalid, then no stream will be played. The aux stream will also be
disabled in this case.
•If the aux stream is -1 or invalid, then no audio will be played out of the aux output.
17
roVideoEvent() and roAudioEvent()
Video and Audio events can have one of these integer values. They are declared as separate classes as they
are likely to diverge in the future.
0 Undefined Player is in an undefined state.
1 Stopped Playback of the current media item is stopped.
3 Playing The current media item is playing.
4 ScanForward The current media item is fast forwarding.
5 ScanReverse The current media item is fast rewinding.
6 Buffering The current media item is getting additional data
from the server.
7 Waiting Connection is established, but the server is not
sending data. Waiting for session to begin.
8 MediaEnded Media item has completed playback.
9 Transitioning Preparing new media item.
10 Ready Ready to begin playing.
11 Reconnecting Reconnecting to stream.
12 TimeHit A particular timecode is hit. See roVideoPlayer.
Interfaces:
• ifInt – contains event id enumerated above
GetInt() As Integer
• ifData – contains userdata
GetData() As Integer
Example Code Clip:
vp_msg_loop:
msg=wait(tiut, p) if type(msg)="roVideoEvent" thenif debug then print "Video Event";msg.GetInt()
if msg.GetInt() = 8 then if debug then print "VideoFinished"
retcode=5
return endif elseif type(msg)="roGpioButton" then if debug then print "Button Press";msg
if escm and msg=BM then retcode=1:return if esc1 and msg=B1 then retcode=2:return if esc2 and msg=B2 then retcode=3:return if esc3 and msg=B3 then retcode=4:return elseif type(msg)="rotINT32" then if debug then print "TimeOut"
retcode=6
return endif
goto vp_msg_loop
18
roGpioControlPort
This object is used to control and wait for events on the BrightSign generic DB15 control port (HD
Compacts) or the DB25 control port and front panel (HD2000). Typically LEDs or Buttons are connected
to the DB15 / DB25 port.
Turning on a GPIO output puts the voltage on the GPIO port to 3.3V. Turning off a GPIO output puts the
voltage on the GPIO port to 0 V.
On the HD 410, HD810, and HD1010, the GPIO’s are bidirectional and must be programmed as either
inputs or outputs. The ids range from 0 – 7.
On the HD20000, the output ids are as follows:
Front panel LEDs start at id 0 on the left and go up to id 16 on the right
DB25 GPIO outputs start at id 17 and go up to id 22.
And the input ids are as follows
DB25 GPIO inputs start at id 0 and go up to id 11
Front panel switch is id 12
Note: SetWholeState will overwrite any prior output settings.
SetOutputState takes an output id (1, 2, or 6 for example.)
SetWholeState takes a mask – for example SetWholeState(2^1 + 2^2 ) to set ids 1 and 2.
Interfaces:
• ifSetMessagePort
SetPort(obj As Object) As Void
• ifGpioControlPort
IsInputActive(input_id As Integer) As Boolean
GetWholeState() As Integer
SetOutputState(output_id As Integer, onState As Boolean) As Void
SetWholeState(on_state As Integer) As Void
EnableInput(input_id As Integer) As Boolean (HD410, HD810, HD1010
only)
EnableOutput(output_id As Integer) As Boolean (HD410, HD810,
HD1010 only)
roGpioButton
Interfaces:
• ifInt – contains input id listed above
GetInt() As Integer
19
Loading...
+ 43 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.