Author: ygrego Date: 2015-02-25 17:07:03 +0000 (Wed, 25 Feb 2015) New Revision: 880 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/880 Log: Implementation of method "prevChannel" and 3 methods(_findChannel,_isAValidDVBTChannel, verifyASuitableTunerAvailable) useful to perform this functionality. Modified: oipf/js/impl/VideoBroadcastObject.js Modified: oipf/js/impl/VideoBroadcastObject.js =================================================================== --- oipf/js/impl/VideoBroadcastObject.js 2015-02-25 17:03:09 UTC (rev 879) +++ oipf/js/impl/VideoBroadcastObject.js 2015-02-25 17:07:03 UTC (rev 880) @@ -122,7 +122,7 @@ * Visibility Type: readonly Channel */ currentChannel: null, - createdCallback: function () { + createdCallback: function() { console.log("[INFO] createdCallback called."); }, init: function (requiredCapabilities) { @@ -188,9 +188,7 @@ * 100 | unidentified error. * --------------------------------------------------------------------------------------------------------------------------------------------------------------- */ - onChannelChangeError: function (channel, errorState) { - - }, + onChannelChangeError: null, /*! * Description: * The function that is called when the play state of the video/broadcast object changes. This function may @@ -214,28 +212,26 @@ * * • Channel channel – the channel to which the tuner switched. This object SHALL have the same properties with the same values as the currentChannel object (see * section 7.13.7). */ - onChannelChangeSucceeded: function (channel) { - - }, + onChannelChangeSucceeded: null, /* * Description: * The function that is called when the value of fullScreen changes. */ - onFullScreenChange: function () { + onFullScreenChange: function() { }, /* * Description: * The function that is called when the video object gains focus. */ - onfocus: function () { + onfocus: function() { }, /* * Description: * The function that is called when the video object loses focus. */ - onblur: function () { + onblur: function() { }, /* @@ -245,7 +241,7 @@ * in section 7.13.9. The method SHALL return the value null if the channel list is not * (partially) managed by the OITF (i.e., if the channel list information is managed entirely in the network). */ - getChannelConfig: function () { + getChannelConfig: function() { return oipfObjectFactory.createChannelConfig(); }, /* @@ -273,7 +269,7 @@ * * TODO : binding of necessary ressources */ - bindToCurrentChannel: function () { + bindToCurrentChannel: function() { var channelConfig = this.getChannelConfig(); var currentChan = channelConfig.currentChannel; var self = this; @@ -317,7 +313,7 @@ * * • Channel channel – the channel to which the tuner switched. This object SHALL have the same properties with the same values as the currentChannel object (see * section 7.13.7). */ - createChannelObject: function (idType, dsd, sid) { + createChannelObject: function(idType, dsd, sid) { }, /* @@ -329,7 +325,7 @@ * * • Channel channel – the channel to which the tuner switched. This object SHALL have the same properties with the same values as the currentChannel object (see * section 7.13.7). */ - createChannelObject: function (idType, onid, tsid, sid, sourceID, ipBroadcastID) { + createChannelObject: function(idType, onid, tsid, sid, sourceID, ipBroadcastID) { }, /* @@ -341,7 +337,7 @@ * * • Channel channel – the channel to which the tuner switched. This object SHALL have the same properties with the same values as the currentChannel object (see * section 7.13.7). */ - setChannel: function (channel, trickplay, contentAccessDescriptorURL) { + setChannel: function(channel, trickplay, contentAccessDescriptorURL) { }, /* @@ -354,8 +350,7 @@ * If the current channel is not part of the channel list, it is implementation dependent whether * the method call succeeds or fails and, if it succeeds, which channel is selected. In both * cases, all appropriate functions SHALL be called and DOM events dispatched. - * - * TODO: Actually,this specific case will not be taken into consideration. + * * If the previous channel is a channel that cannot be received over the tuner currently used by * the video/broadcast object, the OITF SHALL relay the channel switch request to a local * physical or logical tuner that is not in use and that can tune to the specified channel. The @@ -377,67 +372,97 @@ * not valid in the Unrealized state and SHALL fail. * */ - prevChannel: function () { - + prevChannel: function() { //claimed scarce resources - //Call method to claim scarces resources + //Call method to claim scarce resources - switch (this.playstate) { + var channelConfig = this.getChannelConfig(); + var favouriteLists = channelConfig.favouriteLists; + //Verify that OITF maintain channel list or favourite list by itself + if (channelConfig && favouriteLists && (this.playstate > 0) && (this.playstate < 4)) { - case 0: - break; + //Verify that the currentChannel exists in the channel list of channel configuration + if (!channelConfig.channelList.getChannel(this.currentChannel.channelId)) { + var self = this; + setTimeout(function () { + self.onChannelChangeError && self.onChannelChangeError(null, 100); + }, 0); + + if (this.playstate == 1) { + self = this; + setTimeout(function () { + self.onPlayStateChange && self.onPlayStateChange(0, 100); + }, 0); + } + } else { - case 1: - try { - - if (channelConfig === null) { - - throw new Error(); - - } else { - - - } - - if (currentChan) { - - this.currentChannel = currentChan; - - } else { - - throw new Error(); - } - - } catch (e) { - //When the OITF does not maintain channel list and favourite list by itself - this.onChannelChangeError && this.onChannelChangeError(null, 10); + /* + * The norm affirm that the value "undefined" for the property "currentFavouriteList" + * means no current favourite list is activating. + * But test on this value for "currentFavouriteList" can cause confusion + * and when her value equals null, we have not the wanted behaviours. + */ + if (channelConfig.currentFavouriteList.length == 0) { + //Find the previous channel into channel list + var channelsList = channelConfig.channelLists; + } else { + //Find the previous channel into the current favourite list + channelsList = channelConfig.currentFavouriteList; } - this.onPlayStateChange && this.onPlayStateChange(2, 20);//Parameter error here equals to 20 but not defined in the norm, means there is no error - break; + var previousChannel = this._findChannel(channelsList, this.currentChannel, - 1); + var tunerFound = this._verifyASuitableTunerAvailable(previousChannel.idType); + if (tunerFound) { + //ToDO: Error handling, if the switch fail, this instruction correspond to channel switch. + this.currentChannel = previousChannel; + self = this; + setTimeout(function () { + self.onPlayStateChange && self.onPlayStateChange(1); + self.onChannelChangeSucceeded && self.onChannelChangeSucceeded(previousChannel); + }, 0); + } + } - case 2: - break; - - case 3: - - this.onPlayStateChange && this.onPlayStateChange(1); - - break; - + } else { + //When the OITF does not maintain channel list or favourite list by itself + self = this; + setTimeout(function () { + self.onChannelChangeError && self.onChannelChangeError(null, 10); + }, 0); } - return this.currentChannel; - }, /* * Description: - * The function that is called when a request to switch a tuner to another channel has successfully completed. - * This function may be called either in response to a channel change initiated by the application, or a channel - * change initiated by the OITF (see section 7.13.1.1). The specified function is called with argument channel, - * which is defined as follows: + * Requests the OITF to switch the tuner that is currently in use by the video/broadcast + * object to the channel that precedes the current channel in the active favourite list, or, if no + * favourite list is currently selected, to the previous channel in the channel list. If it has reached + * the start of the favourite/channel list, it SHALL cycle to the last channel in the list. * - * • Channel channel – the channel to which the tuner switched. This object SHALL have the same properties with the same values as the currentChannel object (see * section 7.13.7). + * If the current channel is not part of the channel list, it is implementation dependent whether + * the method call succeeds or fails and, if it succeeds, which channel is selected. In both + * cases, all appropriate functions SHALL be called and DOM events dispatched. + * + * If the next channel is a channel that cannot be received over the tuner currently used by + * the video/broadcast object, the OITF SHALL relay the channel switch request to a local + * physical or logical tuner that is not in use and that can tune to the specified channel. The + * behaviour is defined in more detail in the description of the setChannel method. + * + * If an error occurs during switching to the next channel, the OITF SHALL trigger the + * function specified by the onChannelChangeError property with the appropriate channel + * and errorState value, and dispatch the corresponding DOM event (see below). + * + * If the OITF does not maintain the channel list and favourite list by itself, the request SHALL + * fail and the OITF SHALL trigger the onChannelChangeError function with the channel + * property having the value null , and errorState=10 (“channel cannot be changed by + * nextChannel()/prevChannel() methods”). + * + * If successful, the OITF SHALL trigger the function specified by the + * onChannelChangeSucceeded property with the appropriate channel value, and also + * dispatch the corresponding DOM event. + * Calls to this method are valid in the Connecting, Presenting and Stopped states. They are + * not valid in the Unrealized state and SHALL fail. + * */ - nextChannel: function () { + nextChannel: function() { }, @@ -450,7 +475,7 @@ * * • Channel channel – the channel to which the tuner switched. This object SHALL have the same properties with the same values as the currentChannel object (see * section 7.13.7). */ - setFullScreen: function (fullscreen) { + setFullScreen: function(fullscreen) { }, /* @@ -462,7 +487,7 @@ * * • Channel channel – the channel to which the tuner switched. This object SHALL have the same properties with the same values as the currentChannel object (see * section 7.13.7). */ - setVolume: function (volume) { + setVolume: function(volume) { }, /* @@ -474,7 +499,7 @@ * * • Channel channel – the channel to which the tuner switched. This object SHALL have the same properties with the same values as the currentChannel object (see * section 7.13.7). */ - getVolume: function () { + getVolume: function() { }, @@ -487,22 +512,76 @@ * * • Channel channel – the channel to which the tuner switched. This object SHALL have the same properties with the same values as the currentChannel object (see * section 7.13.7). */ - release: function () { + release: function() { }, /* * Description: - * The function that is called when a request to switch a tuner to another channel has successfully completed. - * This function may be called either in response to a channel change initiated by the application, or a channel - * change initiated by the OITF (see section 7.13.1.1). The specified function is called with argument channel, - * which is defined as follows: - * + * Stop presenting broadcast video. If the video/broadcast object is in any state other than the + * unrealized state, it SHALL transition to the stopped state and stop video and audio + * presentation. This SHALL have no effect on access to non-media broadcast resources such + * as EIT information. + * Calling this method from the unrealized state SHALL have no effect. + * See section 7.13.1.1 for more information of its usage. + * * • Channel channel – the channel to which the tuner switched. This object SHALL have the same properties with the same values as the currentChannel object (see * section 7.13.7). */ - stop: function () { + stop: function() { + }, + + _findChannel: function(channelCollection, channel, step) { + + for (var keys = Object.keys(channelCollection) in channelCollection) { + if (channelCollection[keys] == channel) { + return channelCollection[(keys%channelCollection.length)+step]; + } + } + return null; + }, + + _isAValidDVBTChannel: function(channel) { + return (channel.onid != null) && (channel.tsid != null) && (channel.sid != null); + }, + + /* + * Description: + * This method verify that a tuner is available to receive a channel with this "idType". + * And return the first tuner found which match the "idType". + * Actually all video broadcast will use the same tuner because there is only one and + * this choice would be directed by parameter. + * + * ToDo :Normally the method should check if the tuner don't locked by another object but + * no way to do that in the norm. + * + * Argument: + * - idType : the type of tuner researched. + * + * Return: Tuner + */ + _verifyASuitableTunerAvailable: function(idType) { + var config = oipfObjectFactory.createConfigurationObject(); + var availableTuners = config.localSystem.tuners; + + for (var tKeys = Object.keys(availableTuners) in availableTuners) { + var tunerIdTypes = availableTuners[tKeys].idTypes; + for (var tunerIdKeys = Object.keys(availableTuners[tKeys]) in tunerIdTypes) { + var tuner = availableTuners[tKeys]; + if (tunerIdTypes[tunerIdKeys] == idType) { + return tuner; + } + } + } + + if (idType == 40 || idType == 41) { + this.onChannelChangeError && this.onChannelChangeError(null, 8); + } else { + //this.onChannelChangeError && this.onChannelChangeError(null, 2); + this.onChannelChangeError && this.onChannelChangeError(null, 0); + } + return null; } }); \ No newline at end of file
participants (1)
-
ygrego@users.nuiton.org