def execute(self): '''Execute the state - return: The new state to execute ''' # check if we still need to grab if not self.__settings.grabbing(): # return to the disconnected state return DisconnectedState(self.__settings) # capture an image self.__capture.waitForCaptureStateChangeEvent(200) captureState = self.__capture.getCaptureState() if captureState == xbmc.CAPTURE_STATE_DONE: # retrieve image data and reformat into rgb format data = self.__capture.getImage() if self.__capture.getImageFormat() == 'ARGB': del data[0::4] elif self.__capture.getImageFormat() == 'BGRA': del data[3::4] data[0::3], data[2::3] = data[2::3], data[0::3] try: #send image to hyperion self.__hyperion.sendImage(self.__capture.getWidth(), self.__capture.getHeight(), str(data), self.__settings.priority, 500) except Exception, e: # unable to send image. notify and go to the error state notify(xbmcaddon.Addon().getLocalizedString(32101)) return ErrorState(self.__settings)
def execute(self): '''Execute the state - return: The new state to execute ''' # check if we still need to grab if not self.__settings.grabbing(): self.clear_priority() # return to the disconnected state return DisconnectedState(self.__settings) # capture an image startReadOut = False self.__data = self.__capture.getImage() if len(self.__data) > 0: startReadOut = True if startReadOut: # retrieve image data and reformat into rgb format if self.__capture.getImageFormat() == 'BGRA': del self.__data[3::4] self.__data[0::3], self.__data[2::3] = self.__data[2::3], self.__data[0::3] try: # send image to hyperion self.__hyperion.sendImage(self.__capture.getWidth(), self.__capture.getHeight(), str(self.__data), self.__settings.priority, -1) except Exception, e: # unable to send image. notify and go to the error state notify(xbmcaddon.Addon().getLocalizedString(32101)) return ErrorState(self.__settings)
def process(self): if playerMonitor.getGrabbingState( ) != HyperionPlayer.GRABBING_START or not xbmc.getCondVisibility( "Player.Playing"): xbmc.sleep(100) return rawImgBuf = self.capture.getImage( ) # lets wait up to 250ms for an image, otherwise we are lagging behind heavily rawImgLen = len(rawImgBuf) expectedLen = settings.capture_width * settings.capture_height * 4 if rawImgLen < expectedLen: # Check if we got a null image from the renderer. if rawImgLen == 0: return log("Faulty image! Size was: %d expected: %d" % (rawImgLen, expectedLen)) return # Convert image to RGB from BGRA (default after 17) del rawImgBuf[3::4] rawImgBuf[0::3], rawImgBuf[2::3] = rawImgBuf[2::3], rawImgBuf[0::3] # If this call fails, it will make us reconnect. if not self.hyperion.sendImage(settings.capture_width, settings.capture_height, rawImgBuf, -1): notify(xbmcaddon.Addon().getLocalizedString(32101)) return sleeptime = settings.delay if settings.useDefaultDelay == False: try: videofps = math.ceil( float(xbmc.getInfoLabel('Player.Process(VideoFPS)'))) if videofps == 24: sleeptime = self.__settings.delay24 if videofps == 25: sleeptime = self.__settings.delay25 if videofps == 50: sleeptime = self.__settings.delay50 if videofps == 59: sleeptime = self.__settings.delay59 if videofps == 60: sleeptime = self.__settings.delay60 except ValueError: pass # Minimum sleep of 1 millisecond otherwise the event processing dies. xbmc.sleep(max(1, sleeptime))
def execute(self): '''Execute the state - return: The new state to execute ''' # check if we still need to grab if not self.__settings.grabbing(): # return to the disconnected state return DisconnectedState(self.__settings) # check the xbmc API Version try: self.__capture.getCaptureState() except: self.__useLegacyApi = False # capture an image startReadOut = False if self.__useLegacyApi: self.__capture.waitForCaptureStateChangeEvent(200) self.__captureState = self.__capture.getCaptureState() if self.__captureState == xbmc.CAPTURE_STATE_DONE: startReadOut = True else: self.__data = self.__capture.getImage() if len(self.__data) > 0: startReadOut = True if startReadOut: if self.__useLegacyApi: self.__data = self.__capture.getImage() # retrieve image data and reformat into rgb format if self.__capture.getImageFormat() == 'ARGB': del self.__data[0::4] elif self.__capture.getImageFormat() == 'BGRA': del self.__data[3::4] self.__data[0::3], self.__data[2::3] = self.__data[2::3], self.__data[0::3] try: #send image to hyperion self.__hyperion.sendImage(self.__capture.getWidth(), self.__capture.getHeight(), str(self.__data), self.__settings.priority, 500) except Exception, e: # unable to send image. notify and go to the error state notify(xbmcaddon.Addon().getLocalizedString(32101)) return ErrorState(self.__settings)
def execute(self): '''Execute the state - return: The new state to execute ''' # check if we still need to grab if not self.__settings.grabbing(): self.clear_priority() # return to the disconnected state return DisconnectedState(self.__settings) # capture an image startReadOut = False self.__data = self.__capture.getImage() if len(self.__data) > 0: startReadOut = True if startReadOut: # retrieve image data and reformat into rgb format if self.__capture.getImageFormat() == 'BGRA': del self.__data[3::4] self.__data[0::3], self.__data[2::3] = self.__data[ 2::3], self.__data[0::3] ba = self.__data size = (self.__capture.getWidth(), self.__capture.getHeight()) img = Image.frombuffer('RGB', size, str(ba), 'raw', 'RGB', 0, 1) #img.save("C:/tmp/kodi/image"+str(self.__counter)+".jpg") img.save("/storage/screenshots/" + str(self.__counter) + ".jpg") log("Saved image " + str(self.__counter) + ".jpg") self.__counter += 1 try: # send image to hyperion self.__hyperion.sendImage(self.__capture.getWidth(), self.__capture.getHeight(), str(self.__data), self.__settings.priority, -1) except Exception, e: # unable to send image. notify and go to the error state log(e) notify(xbmcaddon.Addon().getLocalizedString(32101)) return ErrorState(self.__settings)
def execute(self): '''Execute the state - return: The new state to execute ''' # check if we are enabled if not self.__settings.grabbing(): xbmc.sleep(500) return self # we are enabled and want to advance to the connected state try: nextState = ConnectedState(self.__settings) return nextState except Exception, e: # unable to connect. notify and go to the error state if self.__settings.showErrorMessage: notify(xbmcaddon.Addon().getLocalizedString(32100)) self.__settings.showErrorMessage = False # continue in the error state return ErrorState(self.__settings)
def readSettings(self): '''(Re-)read all settings''' misc.log('Reading settings') addon = xbmcaddon.Addon() self.enable = addon.getSetting('hyperion_enable') == 'true' self.enableScreensaver = addon.getSetting( 'screensaver_enable') == 'true' self.address = addon.getSetting('hyperion_host') self.port = int(addon.getSetting('hyperion_port')) self.priority = int(addon.getSetting('hyperion_priority')) self.timeout = int(addon.getSetting('reconnect_timeout')) self.capture_width = int(addon.getSetting('capture_width')) self.capture_height = int(addon.getSetting('capture_height')) self.framerate = int(addon.getSetting('framerate')) self.debug = addon.getSetting('debug') == 'true' self.debug_host = addon.getSetting('debug_host') self.debug_port = int(addon.getSetting('debug_port')) self.showErrorMessage = True self.rev += 1 if self.debug: try: import pydevd pydevd.settrace(host=settings.debug_host, port=settings.debug_port, stdoutToServer=True, stderrToServer=True) self._debugging = True except Exception as exception: misc.notify('Error while enabling debugger: %(exception)r', exception=exception) elif self._debugging: import pydevd pydevd.stoptrace() self._debugging = False