@@ -61,7 +61,7 @@ def execute(self):
61
61
62
62
# continue in the error state
63
63
return ErrorState (self .__settings )
64
-
64
+
65
65
class ConnectedState :
66
66
'''
67
67
State class when connected to Hyperion and grabbing video
@@ -76,6 +76,9 @@ def __init__(self, settings):
76
76
self .__settings = settings
77
77
self .__hyperion = None
78
78
self .__capture = None
79
+ self .__captureState = None
80
+ self .__data = None
81
+ self .__useLegacyApi = True
79
82
80
83
# try to connect to hyperion
81
84
self .__hyperion = Hyperion (self .__settings .address , self .__settings .port )
@@ -89,6 +92,9 @@ def __del__(self):
89
92
'''
90
93
del self .__hyperion
91
94
del self .__capture
95
+ del self .__captureState
96
+ del self .__data
97
+ del self .__useLegacyApi
92
98
93
99
def execute (self ):
94
100
'''Execute the state
@@ -99,29 +105,47 @@ def execute(self):
99
105
# return to the disconnected state
100
106
return DisconnectedState (self .__settings )
101
107
108
+ # check the xbmc API Version
109
+ try :
110
+ self .__capture .getCaptureState ()
111
+ except :
112
+ self .__useLegacyApi = False
113
+
102
114
# 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
108
131
if self .__capture .getImageFormat () == 'ARGB' :
109
- del data [0 ::4 ]
132
+ del self . __data [0 ::4 ]
110
133
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
+
114
137
try :
115
138
#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 )
117
140
except Exception , e :
118
141
# unable to send image. notify and go to the error state
119
142
notify (xbmcaddon .Addon ().getLocalizedString (32101 ))
120
143
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 )
125
149
126
150
#limit the maximum number of frames sent to hyperion
127
151
xbmc .sleep (100 )
@@ -132,7 +156,7 @@ class ErrorState:
132
156
'''
133
157
State class which is activated upon an error
134
158
'''
135
-
159
+
136
160
def __init__ (self , settings ):
137
161
'''Constructor
138
162
- settings: Settings structure
0 commit comments