Dune JavaScript STB API version 0.2 =================================== References ---------- [EN 300 468] ETSI EN 300 468 "Digital Video Broadcasting (DVB); Specification for Service Information (SI) in DVB systems" [UR IRD] NorDig Unified "NorDig Unified Requirements for Integrated Receiver Decoders for use in cable, satellite, terrestrial and IP-based networks" JavaScript API initialization ----------------------------- HTML: JavaScript: var stb = document.getElementById("duneapi"); if (!stb || !stb.init()) alert("STB API initialization failed"); Only single instance of "application/x-dune-stb-api" plugin can be active at the moment. In the example above all functions of the API are accessible via "stb" JavaScript object. E.g., JavaScript: stb.play("http://server/video.m3u8"); JavaScript API deinitialization ------------------------------- HTML: Type conventions ---------------- Functions in this specification are defined in terms of pseudocode that is trivially mapped to JavaScript. If type of argument or result is not specified it is assumed it is "void". Functions can further restrict allowed values of arguments and results, see function description for details. JavaScript value "undefined" is used for unknown result value or in case of error. If not specified otherwise, on use of incorrect value for argument error is returned. If not specified otherwise, all arguments are required in function calls and cannot be omitted. Unnecessary arguments in function calls are treated as an error. "rc" is "enum" type for return codes. See section "Return codes" for values of this type. In case complex data like structures, objects, etc need to be passed as arguments or returned as a result, in most cases "string" type with semantics defined by function is used. API setter functions use return codes to indicate errors. API getter functions use "undefined" value as a result to indicate errors if not specified otherwise in function description. For convenience "int" and "rc" used as enums have corresponding constants in the API that are provided by plugin object. E.g., JavaScript: stb.PLAYBACK_STATE_PLAYING Return codes ------------ The following return codes are supported by the API functions with "rc" result type: OK 0 ALREADY_INITIALIZED 1 NOT_INITIALIZED 2 POWER_OFF 3 ERROR 1000 INVALID_ARGUMENT 1001 NOT_SUPPORTED 1002 Initialization functions ------------------------ bool init() deinit() System functions ---------------- string getApiVersion() string getProductId() string getSerialNumber() string getFirmwareVersion() string getMacAddress() Returns MAC address of current network interface. string getPrimaryMacAddress() Returns MAC address of Ethernet network interface. string getIpAddress() Returns current effective IP address. string getDns1Address() string getDns2Address() string getGatewayAddress() rc log(string message) Logs message to application's stderr. rc reboot() Reboots device. int getStandbyMode() Result: STANDBY_MODE_OFF 0 STANDBY_MODE_ON 1 rc setStandbyMode(int mode) Puts device into standby mode or returns it back to normal mode. Argument: STANDBY_MODE_OFF 0 STANDBY_MODE_ON 1 bool fileExists(string path) string getUserSetting(string key) rc setUserSetting(string key, string value) string getFirmwareUpgradeUrl() Returns URL of firmware image got from DHCP server. string getFirmwareUpgradeVersion() Returns version of firmware got from DHCP server. rc startFirmwareUpgrade(string url, string version) Arguments: url - HTTP or multicast URL of firmware image version - firmware version string rc resetSettings(int reset) Resets STB settings to factory defaults. In case reset is performed successfully function does not return and makes reboot of STB. Argument: RESET_SETTINGS_FULL 0 RESET_SETTINGS_SOFT 1 Playback functions ------------------ int getPlaybackState() Result: PLAYBACK_STATE_STOPPED 1 PLAYBACK_STATE_INITIALIZING 2 PLAYBACK_STATE_PLAYING 3 PLAYBACK_STATE_PAUSED 4 PLAYBACK_STATE_SEEKING 5 PLAYBACK_STATE_BUFFERING 6 PLAYBACK_STATE_FINISHED 7 PLAYBACK_STATE_DEINITIALIZING 8 rc play(string mediaUrl) Argument: url - media URL, see http://files.dune-hd.com/partners/sdk/media_url.txt for details rc stop() bool canPause() Returns true if zero argument can be used in setSpeed() function or pause() function can be called successfully. rc pause() rc resume() rc setInitialSpeed(int speed) Argument must be power of 2. Argument: -8192..-512 - -32x..-2x -256 - -1x -128..-8 - -1/2x..-1/32x 0 - paused 8..128 - 1/32x..1/2x 256 - 1x 512..8192 - 2x..32x int getSpeed() Result is always power of 2. Result: -8192..-512 - -32x..-2x -256 - -1x -128..-8 - -1/2x..-1/32x 0 - paused 8..128 - 1/32x..1/2x 256 - 1x 512..8192 - 2x..32x rc setSpeed(int speed) Argument must be power of 2. Argument: -8192..-512 - -32x..-2x -256 - -1x -128..-8 - -1/2x..-1/32x 0 - paused 8..128 - 1/32x..1/2x 256 - 1x 512..8192 - 2x..32x bool hasLength() Returns true if length of media is known. int getLengthInSeconds() Result: 0..N - media length in seconds rc setInitialPositionInSeconds(int seconds) Argument: 0..N - position in seconds int getPositionInSeconds() Result: 0..N - current position in seconds rc setPositionInSeconds(int seconds) Argument: 0..N - position in seconds rc setSpeedAndPositionInSeconds(int speed, int seconds) Arguments: speed: -8192..-512 - -32x..-2x -256 - -1x -128..-8 - -1/2x..-1/32x 0 - paused 8..128 - 1/32x..1/2x 256 - 1x 512..8192 - 2x..32x position: 0..N - position in seconds bool isScramblingDetected() Returns true if scrambled stream is detected during current playback. int getSegmentLengthInSeconds() Returns the length of one media segment for segment-based media. For HLS, returns the value of X-EXT-TARGETDURATION. Result: 0..N - media segment length in seconds Audio functions --------------- int getVolume() Result: 0..100 - current volume in percents rc setVolume(int volume) Argument: 0..100 - volume in percents bool isMuteEnabled() rc enableMute() rc disableMute() rc setInitialAudioPid(int pid) Argument: 1..8191 - audio track PID string getAudioTracksDescription() Result: String "[ ]" if list of tracks is empty or error occurred. String in format "[ { index: , lang: , codec: , pid: , type: }, ... ]", where , are ints, , are strings, is enum described in the getDefaultAudioType(). int getAudioTrack() Result: 0..N - current audio track index rc setAudioTrack(int track) Argument: 0..N - audio track index int getDigitalAudioOutput() Result: DIGITAL_AUDIO_OUTPUT_PCM 0 DIGITAL_AUDIO_OUTPUT_BITSTREAM 1 rc setDigitalAudioOutput(int output) Argument: DIGITAL_AUDIO_OUTPUT_PCM 0 DIGITAL_AUDIO_OUTPUT_BITSTREAM 1 string getDefaultAudioLanguage() Returns preferred language of audio track used for playback. Result: 3 letter language code, see section "Supported languages" below. rc setDefaultAudioLanguage(string language) Sets preferred language of audio track used for playback. Argument: 3 letter language code, see section "Supported languages" below. Value "auto" can be used to allow STB to select preferred language automatically. string getDefaultSecondaryAudioLanguage() Returns preferred secondary language of audio track used for playback. Result: 3 letter language code, see section "Supported languages" below. Value "auto" is returned if STB is allowed to select preferred language automatically. rc setDefaultSecondaryAudioLanguage(string language) Sets preferred secondary language of audio track used for playback. Argument: 3 letter language code, see section "Supported languages" below. Value "auto" can be used to allow STB to select preferred language automatically. int getDefaultAudioType() Returns preferred type of audio track used for playback. Result: AUDIO_TYPE_NORMAL 0 AUDIO_TYPE_HEARING_IMPAIRED 1 AUDIO_TYPE_VISUAL_IMPAIRED 2 rc setDefaultAudioType(int type) Sets preferred type of audio track used for playback. Argument: type - enum described in the getDefaultAudioType(). Subtitle functions ------------------ string getSubtitleTracksDescription() Result: String "[ ]" if list of tracks is empty or error occurred. String in format "[ { index: , lang: , codec: , pid: , type: }, ... ]", where , are ints, , are strings. is enum described in the getDefaultSubtitleType(). int getSubtitleTrack() Result: 0..N - current subtitle track index rc setSubtitleTrack(int track) Argument: 0..N - subtitle track index rc disableSubtitleTrack() string getDefaultSubtitleLanguage() Returns preferred language of subtitle track used for playback. Result: 3 letter language code, see section "Supported languages" below. rc setDefaultSubtitleLanguage(string language) Sets preferred language of subtitle track used for playback. Argument: 3 letter language code, see section "Supported languages" below. Value "auto" can be used to allow STB to select preferred language automatically. string getDefaultSecondarySubtitleLanguage() Returns preferred secondary language of subtitle track used for playback. Result: 3 letter language code, see section "Supported languages" below. Value "auto" is returned if STB is allowed to select preferred language automatically. rc setDefaultSecondarySubtitleLanguage(string language) Sets preferred secondary language of subtitle track used for playback. Argument: 3 letter language code, see section "Supported languages" below. Value "auto" can be used to allow STB to select preferred language automatically. int getDefaultSubtitleType() Returns preferred type of subtitle track used for playback. Result: SUBTITLE_TYPE_NORMAL 0 SUBTITLE_TYPE_HEARING_IMPAIRED 1 SUBTITLE_TYPE_CLOSED_CAPTION 1 Value SUBTITLE_TYPE_CLOSED_CAPTION is considered as legacy one, instead SUBTITLE_TYPE_HEARING_IMPAIRED is recommended for use. rc setDefaultSubtitleType(int type) Sets preferred type of subtitle track used for playback. Argument: type - enum described in the getDefaultSubtitleType(). int getDefaultSubtitlesEnabled() Returns preferred kind of subtitles enabled automatically on start of playback. Result: SUBTITLES_ENABLED_NO 0 SUBTITLES_ENABLED_YES 1 SUBTITLES_ENABLED_EXTERNAL_ONLY 2 SUBTITLES_ENABLED_INTERNAL_ONLY 3 rc setDefaultSubtitlesEnabled(int kind) Sets preferred kind of subtitles enabled automatically on start of playback. Argument: kind - enum described in the getDefaultSubtitlesEnabled(). Teletext functions ------------------ bool isTeletextAvailable() Returns true if teletext is available in the current stream and false if it is not. bool isTeletextEnabled() Returns true if teletext mode is turned on and false if it is turned off. rc enableTeletext() Turns teletext mode on. rc disableTeletext() Turns teletext mode off. int getTeletextPageNumber() Result: Current teletext page number. rc setTeletextPageNumber(int page) Sets teletext page number. Page number should be >= 100 and <= 899. bool isTeletextMixModeEnabled() Returns true if teletext mix mode is turned on and false if it is turned off. rc enableTeletextMixMode() Turns teletext mix mode on. rc disableTeletextMixMode() Turns teletext mix mode off. rc inputTeletextKey(int key) Handles key in teletext mode. Argument: KEY_0..KEY_9 KEY_CLEAR KEY_UP KEY_DOWN See section "Key codes" below. Video functions --------------- int getColorKey() Result: 0xXXXXXX - current color key rc setColorKey(int color) Argument: 0xXXXXXX - color key rc disableColorKey() Disables color key. bool isVideoEnabled() Returns true if primary video showing during primary video playback is enabled. When primary video playback is performed and primary video showing is disabled, primary video playback internally runs in the usual way, but primary video is hidden. By default, primary video showing is enabled. rc enableVideo() Enables showing of primary video when primary video playback is running. rc disableVideo() Disables showing of primary video when primary video playback is running. Does not affect primary video playback itself (i.e. the primary video playback internally continues, only primary video becomes hidden). int getVideoZOrder() Returns current Z-order of primary video. Default value for primary video Z-order is 200. Result: 0..1000 - current Z-order rc setVideoZOrder(int zorder) Sets Z-order of primary video. If primary video playback is not running or primary video showing is disabled, primary video layer is absent and this setting has no effect. Z-ordering of primary video, PiP video and OSD layers works in the following way. Layers with greater Z-order are put above layers with lesser Z-order. Default Z-order values for primary video, PiP video, OSD are: 200, 400, 500. If some of the layers (primary video, PiP video, OSD) have the same Z-order, the following ordering rules are used: OSD is above PiP video, PiP video is above primary video. Argument: 0..1000 - Z-order int getOSDZOrder() Returns current Z-order of OSD. Default value for OSD Z-order is 500. Result: 0..1000 - current Z-order rc setOSDZOrder(int zorder) Sets Z-order of OSD. See also setVideoZOrder() for details. Argument: 0..1000 - Z-order bool isVideoOnTop() Returns true if primary video has Z-order greater than Z-order of OSD. rc enableVideoOnTop() Puts primary video above OSD. The function is equivalent to setVideoZOrder(900) and setOSDZOrder(500). NOTE: This function is intended to be used by applications which do not use PiP video; if PiP video is used, it is recommended not to use this function and instead use set{Video,PIP,OSD}ZOrder functions directly. rc disableVideoOnTop() Puts primary video below OSD. The function is equivalent to setVideoZOrder(200) and setOSDZOrder(500)). NOTE: This function is intended to be used by applications which do not use PiP video; if PiP video is used, it is recommended not to use this function and instead use set{Video,PIP,OSD}ZOrder functions directly. bool isWindowFullScreen() rc enableWindowFullScreen() int getWindowRectX() int getWindowRectY() int getWindowRectWidth() int getWindowRectHeight() rc setWindowRect(int x, int y, int width, int height) int getClipRectX() int getClipRectY() int getClipRectWidth() int getClipRectHeight() rc setClipRect(int x, int y, int width, int height) int getVideoSourceRectX() Returns current X coordinate of the original video portion, see setVideoSourceRect() for details. int getVideoSourceRectY() Returns current Y coordinate of the original video portion, see setVideoSourceRect() for details. int getVideoSourceRectWidth() Returns current width of the original video portion, see setVideoSourceRect() for details. int getVideoSourceRectHeight() Returns current height of the original video portion, see setVideoSourceRect() for details. rc setVideoSourceRect(int x, int y, int width, int height) Sets coordinates of a portion of the original video for displaying in window or on full screen as specified via setWindowRect(). The specification of the portion coordinates is in 0-4096 scale for all arguments instead of OSD size scale in setWindowRect() and setClipRect() thus setVideoSourceRect(0, 0, 4096, 4096) specifies complete original video. The coordinates are specified relative to the original video dimensions with no dependence on display/window aspect ratio so if there is, say, 4:3 video that should be displayed in a 3:1 window and setVideoSourceRect(0, 0, 1024, 4096) is called then the resulting video will have 1:3 aspect ratio with appropriate black bars added in the window if normal zoom mode is specified. The video source rectangle specification is also compatible with VIDEO_ZOOM_STRETCH_TO_FULL_SCREEN preset, in this case the portion of the original video is stretched to full screen or window as expected. Other zoom presets are not compatible, just like with setClipRect() call - setVideoSourceRect() fails if an incompatible zoom preset is set and setVideoZoom() fails with an incompatible zoom preset if a partial video source rectangle is already in effect. Note that both video source rectangle and clip rectangle may be specified with setVideoSourceRect() and setClipRect() respectively but if both are in effect then the clip rectangle setting is ignored until setVideoSourceRect() is set to complete original video so programmer should take care to avoid such situations. Arguments: x - X coordinate of the original video portion y - Y coordinate of the original video portion width - width of the original video portion height - height of the original video portion rc getVideoWidth() rc getVideoHeight() int getVideoConnector() Result: VIDEO_CONNECTOR_HDMI 0 VIDEO_CONNECTOR_COMPONENT 1 VIDEO_CONNECTOR_COMPOSITE 2 VIDEO_CONNECTOR_SVIDEO 3 rc setVideoConnector(int connector) Argument: VIDEO_CONNECTOR_HDMI 0 VIDEO_CONNECTOR_COMPONENT 1 VIDEO_CONNECTOR_COMPOSITE 2 VIDEO_CONNECTOR_SVIDEO 3 int getVideoMode() Result: VIDEO_MODE_NTSC 0 VIDEO_MODE_480P 1 VIDEO_MODE_PAL 2 VIDEO_MODE_576P 3 VIDEO_MODE_720P50 4 VIDEO_MODE_720P60 5 VIDEO_MODE_1080I50 6 VIDEO_MODE_1080I60 7 VIDEO_MODE_1080P23 8 VIDEO_MODE_1080P24 9 VIDEO_MODE_1080P50 10 VIDEO_MODE_1080P60 11 rc setVideoMode(int mode) Argument: VIDEO_MODE_NTSC 0 VIDEO_MODE_480P 1 VIDEO_MODE_PAL 2 VIDEO_MODE_576P 3 VIDEO_MODE_720P50 4 VIDEO_MODE_720P60 5 VIDEO_MODE_1080I50 6 VIDEO_MODE_1080I60 7 VIDEO_MODE_1080P23 8 VIDEO_MODE_1080P24 9 VIDEO_MODE_1080P50 10 VIDEO_MODE_1080P60 11 int getComponentOutputMode() Result: COMPONENT_OUTPUT_MODE_HD 0 - component video out can output HD resolution when possible COMPONENT_OUTPUT_MODE_SD 1 - component video out is restricted to SD resolution COMPONENT_OUTPUT_MODE_NONE 2 - component video out is disabled rc setComponentOutputMode(int mode) Argument: COMPONENT_OUTPUT_MODE_HD 0 - component video out can output HD resolution when possible COMPONENT_OUTPUT_MODE_SD 1 - component video out is restricted to SD resolution COMPONENT_OUTPUT_MODE_NONE 2 - component video out is disabled int getAspectRatio() Result: ASPECT_RATIO_AUTO 0 ASPECT_RATIO_16_9 1 ASPECT_RATIO_4_3 2 rc setAspectRatio(int ratio) Argument: ASPECT_RATIO_AUTO 0 ASPECT_RATIO_16_9 1 ASPECT_RATIO_4_3 2 int getVideoZoom() Result: VIDEO_ZOOM_NORMAL 0 VIDEO_ZOOM_ENLARGE 1 VIDEO_ZOOM_MAKE_WIDER 2 VIDEO_ZOOM_NON_LINEAR_STRETCH 3 VIDEO_ZOOM_NON_LINEAR_STRETCH_TO_FULL_SCREEN 4 VIDEO_ZOOM_MAKE_TALLER 5 VIDEO_ZOOM_CUT_EDGES 6 VIDEO_ZOOM_FULL_SCREEN 8 VIDEO_ZOOM_STRETCH_TO_FULL_SCREEN 9 rc setVideoZoom(int zoom) Argument: VIDEO_ZOOM_NORMAL 0 VIDEO_ZOOM_ENLARGE 1 VIDEO_ZOOM_MAKE_WIDER 2 VIDEO_ZOOM_NON_LINEAR_STRETCH 3 VIDEO_ZOOM_NON_LINEAR_STRETCH_TO_FULL_SCREEN 4 VIDEO_ZOOM_MAKE_TALLER 5 VIDEO_ZOOM_CUT_EDGES 6 VIDEO_ZOOM_FULL_SCREEN 8 VIDEO_ZOOM_STRETCH_TO_FULL_SCREEN 9 Browser functions ----------------- int getBrowserAlphaLevel() Result: 0..255 - current alpha level rc setBrowserAlphaLevel(int level) Argument: 0..255 - alpha level int getScreenSize() Result: SCREEN_SIZE_AUTO 0 SCREEN_SIZE_720_480 1 SCREEN_SIZE_720_576 2 SCREEN_SIZE_1280_720 3 SCREEN_SIZE_1920_1080 4 rc setScreenSize(int size) Argument: SCREEN_SIZE_AUTO 0 SCREEN_SIZE_720_480 1 SCREEN_SIZE_720_576 2 SCREEN_SIZE_1280_720 3 SCREEN_SIZE_1920_1080 4 string getHomePage() Returns home page URL got from DHCP server. Can be used for loading initial page on device start. rc exitBrowser(int mode) Exits or restarts Web browser without restarting device. Can be used for applying audio and video settings that cannot be changed in run-time. Argument: EXIT_BROWSER_MODE_RESTART 0 EXIT_BROWSER_MODE_STANDBY 1 EXIT_BROWSER_MODE_POWER_OFF 2 EXIT_BROWSER_MODE_CLOSE 1000 rc launchNativeUi(string returnUrl) Argument: returnUrl - optional URL that should be loaded after return to browser, if URL is not specified default URL is loaded rc launchNativeUiExt(string nativeUrl, string returnUrl) Argument: nativeUrl - optional URL to be loaded by native UI. The following values are supported: root:// setup://network setup://network:::standalone=1 returnUrl - optional URL that should be loaded after return to browser, if URL is not specified default URL is loaded string getBrowserProxies() Result: String "[ ]" if list of proxies is empty or error occurred. String in format "[ { type: , host: , port: , user: , password: , exceptions: }, ... ]", where is one of the following: BROWSER_PROXY_TYPE_SSL 1 BROWSER_PROXY_TYPE_HTTP 2 is int, , , , are strings. is a list of host names that are communicated directly without using browser proxy. Space is used as separator. rc setBrowserProxy(int type, string host, int port, string user, string password, string exceptions) Arguments: type - is one of the following: BROWSER_PROXY_TYPE_SSL 1 BROWSER_PROXY_TYPE_HTTP 2 exceptions - list of host names that are communicated directly without using browser proxy. Space should be used as separator. Pass empty string to disable exceptions. rc removeBrowserProxies() int getRcAutoRepeatPeriod() Result: 50..500 - RC auto-repeat interval in milliseconds rc setRcAutoRepeatPeriod(int period) Argument: 50..500 - RC auto-repeat interval in milliseconds string getRcAutoRepeatKeys() Result: String "[ ]" if list of keys is empty or error occurred. String in format "[ , ... ]", where is int. See section "Key codes" below. rc setRcAutoRepeatKeys(int keys[]) Argument: Array of RC key codes. See section "Key codes" below. rc saveScreenshot(struct screenshotParameters params) Saves screenshot of specified screen area to BMP image file with specified dimensions. If area width or height are zero or not specified they are calculated from OSD size. If image width or height are specified and not equal to area width or height scaling is performed. Resulting image is stored in file /tmp/screenshot/image{imageName}.bmp. The file is intended for processing by separate application working on STB. The application is also responsible for deletion of image files to preserve memory consumption. Argument: struct screenshotParameters { int areaX; int areaY; int areaWidth; int areaHeight; int imageWidth; int imageHeight; string imageName; } rc saveVideoPicture(struct saveVideoPictureParameters params) Saves specified area of playing video to BMP image file with specified dimensions. Video area coordinates are relative to video. Relative coordinates have a range from 0 to 4096 where [0,0] specifies the left top corner of video and [4096,4096] specifies the bottom right corner. If area width or height are zero they will be recalculated from the playing video sizes. If image width or height are specified and not equal to area width or height scaling is performed. Resulting image is stored in file /tmp/screenshot/image{imageName}.bmp. The file is intended for processing by separate application working on STB. The application is also responsible for deletion of image files to preserve memory consumption. Argument: struct saveVideoPictureParameters { int areaX; int areaY; int areaWidth; int areaHeight; int imageWidth; int imageHeight; string imageName; } rc setOnKeyPressUrl(int key, string url) Sets URL which should be loaded by the web browser when the given key is pressed. When such a URL is configured for a key, key events for this key are not delivered to JS code (and the default handling of this key by the web browser, if any, is overridden too). Can be used e.g. before launching a 3-party HTML application / web site to set a key that should be used to return to the original application. Arguments: key - key code. See section "Key codes". url - URL to load in the web browser when the key is pressed. Empty value means do nothing (i.e. restore the default behavior). Storage access -------------- bool isStorageAvailable() Returns true if at least one storage is mounted successfully and is available and false otherwise. string getMainStorageDescription() Returns description of the main storage. Result: Empty string if storage is not available or error occurred. String in format "( { mediaUrl: , path: , uuid: , label: