Skip to content

Commit 79cc128

Browse files
committed
Merge pull request #18 from iLLiac4/master
Kodi v17 api changes
2 parents 0759c90 + b661576 commit 79cc128

File tree

1 file changed

+40
-16
lines changed

1 file changed

+40
-16
lines changed

resources/lib/state.py

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def execute(self):
6161

6262
# continue in the error state
6363
return ErrorState(self.__settings)
64-
64+
6565
class ConnectedState:
6666
'''
6767
State class when connected to Hyperion and grabbing video
@@ -76,6 +76,9 @@ def __init__(self, settings):
7676
self.__settings = settings
7777
self.__hyperion = None
7878
self.__capture = None
79+
self.__captureState = None
80+
self.__data = None
81+
self.__useLegacyApi = True
7982

8083
# try to connect to hyperion
8184
self.__hyperion = Hyperion(self.__settings.address, self.__settings.port)
@@ -89,6 +92,9 @@ def __del__(self):
8992
'''
9093
del self.__hyperion
9194
del self.__capture
95+
del self.__captureState
96+
del self.__data
97+
del self.__useLegacyApi
9298

9399
def execute(self):
94100
'''Execute the state
@@ -99,29 +105,47 @@ def execute(self):
99105
# return to the disconnected state
100106
return DisconnectedState(self.__settings)
101107

108+
# check the xbmc API Version
109+
try:
110+
self.__capture.getCaptureState()
111+
except:
112+
self.__useLegacyApi = False
113+
102114
# capture an image
103-
self.__capture.waitForCaptureStateChangeEvent(200)
104-
captureState = self.__capture.getCaptureState()
105-
if captureState == xbmc.CAPTURE_STATE_DONE:
106-
# retrieve image data and reformat into rgb format
107-
data = self.__capture.getImage()
115+
startReadOut = False
116+
if self.__useLegacyApi:
117+
self.__capture.waitForCaptureStateChangeEvent(200)
118+
self.__captureState = self.__capture.getCaptureState()
119+
if self.__captureState == xbmc.CAPTURE_STATE_DONE:
120+
startReadOut = True
121+
else:
122+
self.__data = self.__capture.getImage()
123+
if len(self.__data) > 0:
124+
startReadOut = True
125+
126+
if startReadOut:
127+
if self.__useLegacyApi:
128+
self.__data = self.__capture.getImage()
129+
130+
# retrieve image data and reformat into rgb format
108131
if self.__capture.getImageFormat() == 'ARGB':
109-
del data[0::4]
132+
del self.__data[0::4]
110133
elif self.__capture.getImageFormat() == 'BGRA':
111-
del data[3::4]
112-
data[0::3], data[2::3] = data[2::3], data[0::3]
113-
134+
del self.__data[3::4]
135+
self.__data[0::3], self.__data[2::3] = self.__data[2::3], self.__data[0::3]
136+
114137
try:
115138
#send image to hyperion
116-
self.__hyperion.sendImage(self.__capture.getWidth(), self.__capture.getHeight(), str(data), self.__settings.priority, 500)
139+
self.__hyperion.sendImage(self.__capture.getWidth(), self.__capture.getHeight(), str(self.__data), self.__settings.priority, 500)
117140
except Exception, e:
118141
# unable to send image. notify and go to the error state
119142
notify(xbmcaddon.Addon().getLocalizedString(32101))
120143
return ErrorState(self.__settings)
121-
122-
if captureState != xbmc.CAPTURE_STATE_WORKING:
123-
#the current capture is processed or it has failed, we request a new one
124-
self.__capture.capture(64, 64)
144+
145+
if self.__useLegacyApi:
146+
if self.__captureState != xbmc.CAPTURE_STATE_WORKING:
147+
#the current capture is processed or it has failed, we request a new one
148+
self.__capture.capture(64, 64)
125149

126150
#limit the maximum number of frames sent to hyperion
127151
xbmc.sleep(100)
@@ -132,7 +156,7 @@ class ErrorState:
132156
'''
133157
State class which is activated upon an error
134158
'''
135-
159+
136160
def __init__(self, settings):
137161
'''Constructor
138162
- settings: Settings structure

0 commit comments

Comments
 (0)