TOI2 introduces many new features for controlling the video output resolutions from the IP-STB. The current state of all of the video outputs (HDMI, composite, SCART) is known as a Configuration. A configuration is created, altered and finally applied. Configuration changes can also be rolled back to the previous state.
It is possible to set up rules to handle video mode changes depending on the resolution of the currently playing video. This functionality is known as Adaptive Video Mode, but is not a part of this example. The example shows a simple way to set the output resolutions.
The IP-STB has several video output devices. These might be, for example, HDMI, Composite, and SCART outputs. The number and type of video outputs may differ depending on the IP-STB model being used. See also the Display Info example for more.
// supported modes are those returned in the EDID from the TV
displayInfo = videoConfig.getDisplayInfo(output);
The displayInfo.supportedVideoModes
is an array of the video modes which the TV says it supports. This may be different than the capabilities of the output hardware. To see what the hardware output supports, do the following:
var session = 0;
try {
session = toi.videoOutputService.createVideoConfigurationSession();
}
catch(e) {
alert(e);
}
// the videoOutputInfo contains a list of allowed video modes for the current
// color system (PAL_M, NTSC, etc)
// For a list of all possible modes, use getVideoOutputCapabilityInfo()
var Id = videoConfig.getVideoOutputs()[output];
var modes = session.getVideoOutputInfo(Id).allowedVideoModes;
session.releaseInstance();
There are a few things to note here. First, a configuration session is created. All changes to the video configuration are performed as part of a session. The portal designer configures the video outputs as they wish within this session. If a configuration is not allowed, an exception will be raised here. Finally, all the changes are applied at once with the session.apply() call.
The main advantage to using this session based transaction approach, is that the configuration can easily be rolled back to the previous configuration. This is useful, for example, when presenting the home user with a dialog box saying "Do you wish to save these changes? Press OK. If not, the previous settings will be restored in 10 seconds..."
The example code creates a video configuration session, and then calls videoConfig.getVideoOutputs(). This returns an array, containing the ID for each of the video output devices. The variable currentOutput is used as an index in this array to locate the video output's Id. See the Display Info example for more details on this.
Next, the video output has its getVideoOutputInfo() function called, and the ID of the video output passed as a parameter. This returns a structure whose allowedVideoModes array contains all of the video modes currently possible for the video output. This takes into account the current color system (PAL_B, PAL_M, NTSC, etc). Although the hardware may be able to display VIDEO_MODE_720P50 and VIDEO_MODE_720P60, only the 50hz version is returned in the getVideoOutputInfo() call if the color system is set to PAL. To get the complete list of modes which the output is capable of, use the getVideoOutputCapabilityInfo() function instead.
The example then colors in green those modes which are available from the video output, and also supported by the TV.
// set green color for those modes supported by both TV and video output
for (var i=0; i<modes.length; i++) {
for (var j=0; ji<displayInfo.supportedVideoModes.length;j++) {
if (modes[i] == displayInfo.supportedVideoModes[j]) {
elements[j].setAttribute("fill", "#00aa00");
}
}
}
When the user has selected the video mode to be used, a session is created. The desired mode is passed to the setDefaultVideoMode() function (along with the video output Id), and the session.apply() is called. Once complete, the session instance is released.
var session = null;
try {
var desiredMode = displayInfo.supportedVideoModes[currentlySelected];
// create the session
session = toi.videoOutputService.createVideoConfigurationSession();
session.setDefaultVideoMode(videoConfig.getVideoOutputs()[currentOutput],
desiredMode);
session.apply();
session.releaseInstance();
}
catch(e) {
alert(e);
if (session != null) {
session.releaseInstance();
}
}
The example keeps the session transaction short and neat so it is easy to understand. In practice however, you may wish to have the session open longer, set many parameters at once, and finally apply them all (and present the user with an option to roll back the changes).
The information returned from the TV in the EDID may be overridden by creating an array of the video modes as you would like, and then passing this to the setDisplayInfo() function. From that point on, the overridden data will be used instead of that which is normally returned from the TV. This is useful if, for instance, the TV is not supplying the IP-STB with a correct EDID.
Implement a portal for changing the resolution, but using a rollback transaction system. Upon changing video mode, present the user with a dialog box. If the user presses OK, then keep the changes, otherwise wait for a few seconds and then roll back the changes.