• Quick Start
  • Booting
  • Platform
  • Portals
  • References
    • API Reference TOI3
    • IIP Reference
  • Resources
ARRIS Enterprises, Inc. Confidential Information

Volume

Controlling the volume on different outputs is performed through the TOI Audio Output Service. This service provides methods to list the audio connections on the STB (such as the analog output, SPDIF, and HDMI outputs) and set volumes.

Initialization

<sdk_root>/examples/example-html-portal/modules/audio/volume.js

function initVolume() {
  ismuted = false;
  // if custom objects don't exist, create them
  var objects = [];
  if (!toi.informationService.isObjectDefined("apps.portal.ismuted")) {
    objects.push({"name": "apps.portal.ismuted",
                  "value": ismuted.toString()});
  }

  if (!toi.informationService.isObjectDefined("apps.portal.volume")) {
    objects.push({"name": "apps.portal.volume",
                  "value": "70"});
    volume = 70;
  }
  if (objects.length > 0) {
    toi.informationService.set(
      objects, toi.consts.ToiInformationService.STORAGE_PERMANENT);
  }
}

The portal uses two custom configuration objects, apps.portal.ismuted and apps.portal.volume to hold the status of the mute flag, and the current global volume level. When initializing, if these configuration objects don't exist then the portal creates them with the storage type ToiInformationService::STORAGE_PERMANENT. This means that the objects values will be saved to the flash memory (if the STB has flash memory) and so they retain their values if the STB restarts.

Configuration objects are created and handled through the TOI Information Service.

ToiInformationService::set() can set many objects at once, and doing so is faster than many individual calls to set().

Setting the volume

There are many ARRIS VIP Set Top Box models, which can have several different combinations of outputs, so the Audio Output Service provides methods to find and iterate over the available audio devices.

The TOI API allows you to set individual audio levels on different connections. For example, the analog outputs and the SPDIF output could both have individual volume levels. This example portal however takes a simpler approach, and sets all adjustable output connections to the same level.

<sdk_root>/examples/example-html-portal/modules/audio/volume.js

function setAllConnectionsVolume(volume) {
  var connections = toi.audioOutputService.getConnections();
  for (var i = 0; i < connections.length; i++) {
    if (connections[i].isAdjustable && connections[i].direction ==
        toi.consts.ToiAudioOutputService.AUDIO_CONNECTION_DIRECTION_OUTPUT) {
      toi.audioOutputService.setVolume(connections[i].id, volume);
    }
  }
}

A more complex implementation may choose to leave the analog/SCART volume at max level, in case a viewer is recording the analog output. In this case, it is not desirable to have volume changes on the analog output, but it is desirable to change the volume on the HDMI output (which we assume the viewer is watching). Each connections[i] has a type member which you can use to determine which connection it is. See ToiAudioConnectionType for more info on connection types. If it is not required to have detailed control of volume per individual audio connection, it is possible to use the simplified ToiAudioOutputService::setMasterVolume().

Save to flash

Each time the volume is adjusted, the portal calls its saveToFlash() function.

<sdk_root>/examples/example-html-portal/modules/audio/volume.js

function saveToFlash() {
  toi.informationService.set(
    [{"name": "apps.portal.ismuted",
      "value": ismuted.toString()},
     {"name": "apps.portal.volume",
      "value": volume.toString()}],
    toi.consts.ToiInformationService.STORAGE_PERMANENT);
}

Here, both of the portals configuration objects, apps.portal.ismuted and apps.portal.volume are saved to flash memory (if the STB has some. If not, an exception (not handled here) will be thrown). Note that the values are converted to strings prior to being saved. All configuration object values are stored as strings.

Since a flash memory block can only be written to a finite number of times before it wears out (approx. 100,000 write cycles), if the volume was written to flash memory each time the remote control button was pressed it would result in a LOT of writes to the flash memory, degrading its overall lifespan. To prevent this, the KreaTV platform buffers up writes to the flash memory. If you set the same object many times, in quick succession, like when zapping channels or changing volume up and down, the writes will be batched together and performed as one write operation. You can see when exactly the write occurs if you watch the log closely. The kreatv-option-is-adapter IIP allows you to set the timeout limit.

5.1.p5

Copyright (c) 2017 ARRIS Enterprises, LLC. All Rights Reserved. ARRIS Enterprises, LLC. Confidential Information.