Exemplo n.º 1
0
class ConnectedState:
    '''
    State class when connected to Hyperion and grabbing video
    '''
    def __init__(self, settings):
        '''Constructor
          - settings: Settings structure
        '''
        log("Entering connected state")

        self.__settings = settings
        self.__hyperion = None
        self.__capture = None
        self.__captureState = None
        self.__data = None
        self.__counter = 0

        # try to connect to hyperion
        self.__hyperion = Hyperion(self.__settings.address,
                                   self.__settings.port)

        # Force clearing of priority (mainly for Orbs)
        self.clear_priority()

        # create the capture object
        self.__capture = xbmc.RenderCapture()
        self.__capture.capture(self.__settings.capture_width,
                               self.__settings.capture_height)

    def __del__(self):
        '''Destructor
        '''
        del self.__hyperion
        del self.__capture
        del self.__captureState
        del self.__data

    def clear_priority(self):
        # Force clearing of priority (mainly for Orbs)
        xbmc.sleep(1000)
        self.__hyperion.clear(self.__settings.priority)
        xbmc.sleep(1000)
        self.__hyperion.clear(self.__settings.priority)

    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)
        else:
Exemplo n.º 2
0
    load_settings()

    monitor = MyMonitor()
    player = xbmc.Player()

    capture = xbmc.RenderCapture()
    capture.capture(HYPERION_WIDTH, HYPERION_HEIGHT)
    hyperion = Hyperion(HYPERION_IP, HYPERION_PORT)

    while not monitor.abortRequested():
        try:
            if enabled and player.isPlayingVideo():
                data = capture.getImage()
                if len(data) == 0:
                    capture.capture(HYPERION_WIDTH, HYPERION_HEIGHT)
                    hyperion.clear(HYPERION_PRIORITY)
                    continue

                if capture.getImageFormat() == 'ARGB':
                    del data[0::4]
                elif capture.getImageFormat() == 'BGRA':
                    del data[3::4]
                    data[0::3], data[2::3] = data[2::3], data[0::3]

                hyperion.sendImage(capture.getWidth(), capture.getHeight(),
                                   bytes(data), HYPERION_PRIORITY, -1)
            else:
                hyperion.clear(HYPERION_PRIORITY)
                monitor.waitForAbort(1.0)
        except Exception as e:
            notify('Something went wrong')
Exemplo n.º 3
0
class ConnectedState:
    '''
    State class when connected to Hyperion and grabbing video
    '''

    def __init__(self, settings):
        '''Constructor
          - settings: Settings structure
        '''
        log("Entering connected state")

        self.__settings = settings
        self.__hyperion = None
        self.__capture = None
        self.__captureState = None
        self.__data = None

        # try to connect to hyperion
        self.__hyperion = Hyperion(self.__settings.address, self.__settings.port)

        # Force clearing of priority (mainly for Orbs)
        self.clear_priority()

        # create the capture object
        self.__capture = xbmc.RenderCapture()
        self.__capture.capture(self.__settings.capture_width, self.__settings.capture_height)

    def __del__(self):
        '''Destructor
        '''
        del self.__hyperion
        del self.__capture
        del self.__captureState
        del self.__data

    def clear_priority(self):
        # Force clearing of priority (mainly for Orbs)
        xbmc.sleep(1000)
        self.__hyperion.clear(self.__settings.priority)
        xbmc.sleep(1000)
        self.__hyperion.clear(self.__settings.priority)

    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)
        else: