Skip to content

Commit 3b925a9

Browse files
committed
Added options to configure width, height and framerate into the addon
settings interface.
1 parent 6808a4f commit 3b925a9

File tree

6 files changed

+51
-43
lines changed

6 files changed

+51
-43
lines changed

addon.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<addon id="script.service.hyperion" name="Hyperion ambilight" version="1.0.0" provider-name="poljvd|tvdzwan">
2+
<addon id="script.service.hyperion" name="Hyperion ambilight" version="1.0.1" provider-name="poljvd|tvdzwan">
33
<requires>
44
<import addon="xbmc.python" version="2.1.0"/>
55
</requires>
@@ -11,6 +11,6 @@
1111
<website>https://github.com/tvdzwan/hyperion/wiki</website>
1212
<source>https://github.com/poljvd/script.service.hyperion</source>
1313
<forum></forum>
14-
<email></email>
14+
<email></email>
1515
</extension>
1616
</addon>

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
1.0.0
22
- initial addon release
3+
- Added option to set framerate and capture size

resources/language/English/strings.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
<string id="32005">Hyperion priority</string>
88
<string id="32006">Reconnect timeout (s)</string>
99
<string id="32007">Enable when on screensaver</string>
10-
10+
<string id="32008">Width of capture</string>
11+
<string id="32009">Height of capture</string>
12+
<string id="32010">Framerate</string>
1113
<string id="32100">Unable to connect to Hyperion</string>
1214
<string id="32101">Unable to send image to Hyperion</string>
15+
1316
</strings>

resources/lib/settings.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'''
22
XBMC video capturer for Hyperion
3-
3+
44
Copyright (c) 2013 Hyperion Team
55
66
Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -29,7 +29,7 @@
2929
class MyMonitor (xbmc.Monitor):
3030
'''Class to capture changes in settings and screensaver state
3131
'''
32-
32+
3333
def __init__(self, settings):
3434
xbmc.Monitor.__init__(self)
3535
self.__settings = settings
@@ -38,35 +38,35 @@ def __init__(self, settings):
3838

3939
def onAbortRequested(self):
4040
self.__settings.abort = False
41-
41+
4242
def onSettingsChanged(self):
4343
self.__settings.readSettings()
44-
44+
4545
def onScreensaverDeactivated(self):
4646
self.__settings.screensaver = False
47-
48-
def onScreensaverActivated(self):
47+
48+
def onScreensaverActivated(self):
4949
self.__settings.screensaver = True
5050

51-
51+
5252
class Settings:
5353
'''Class which contains all addon settings and xbmc state items of interest
5454
'''
55-
55+
5656
def __init__(self):
5757
'''Constructor
5858
'''
5959
self.rev = 0
6060
self.__monitor = MyMonitor(self)
6161
self.__player = xbmc.Player()
6262
self.readSettings()
63-
63+
6464
def __del__(self):
6565
'''Destructor
6666
'''
6767
del self.__monitor
6868
del self.__player
69-
69+
7070
def readSettings(self):
7171
'''(Re-)read all settings
7272
'''
@@ -78,9 +78,13 @@ def readSettings(self):
7878
self.port = int(addon.getSetting("hyperion_port"))
7979
self.priority = int(addon.getSetting("hyperion_priority"))
8080
self.timeout = int(addon.getSetting("reconnect_timeout"))
81+
self.capture_width = int(addon.getSetting("capture_width"))
82+
self.capture_height = int(addon.getSetting("capture_height"))
83+
self.framerate = int(addon.getSetting("framerate"))
84+
8185
self.showErrorMessage = True
8286
self.rev += 1
83-
87+
8488
def grabbing(self):
8589
'''Check if we grabbing is requested based on the current state and settings
8690
'''

resources/lib/state.py

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'''
22
XBMC video capturer for Hyperion
3-
3+
44
Copyright (c) 2013 Hyperion Team
55
66
Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -27,22 +27,19 @@
2727
from hyperion.Hyperion import Hyperion
2828
from misc import log
2929
from misc import notify
30-
X_SIZE = 300
31-
Y_SIZE = 300
32-
SLEEP_PER_FRAME = 30
3330

3431
class DisconnectedState:
3532
'''
3633
Default state class when disconnected from the Hyperion server
3734
'''
38-
35+
3936
def __init__(self, settings):
4037
'''Constructor
4138
- settings: Settings structure
4239
'''
4340
log("Entering disconnected state")
4441
self.__settings = settings
45-
42+
4643
def execute(self):
4744
'''Execute the state
4845
- return: The new state to execute
@@ -51,7 +48,7 @@ def execute(self):
5148
if not self.__settings.grabbing():
5249
xbmc.sleep(500)
5350
return self
54-
51+
5552
# we are enabled and want to advance to the connected state
5653
try:
5754
nextState = ConnectedState(self.__settings)
@@ -61,10 +58,10 @@ def execute(self):
6158
if self.__settings.showErrorMessage:
6259
notify(xbmcaddon.Addon().getLocalizedString(32100))
6360
self.__settings.showErrorMessage = False
64-
61+
6562
# continue in the error state
6663
return ErrorState(self.__settings)
67-
64+
6865
class ConnectedState:
6966
'''
7067
State class when connected to Hyperion and grabbing video
@@ -82,14 +79,14 @@ def __init__(self, settings):
8279
self.__captureState = None
8380
self.__data = None
8481
self.__useLegacyApi = True
85-
82+
8683
# try to connect to hyperion
8784
self.__hyperion = Hyperion(self.__settings.address, self.__settings.port)
88-
85+
8986
# create the capture object
9087
self.__capture = xbmc.RenderCapture()
91-
self.__capture.capture(X_SIZE, Y_SIZE)
92-
88+
self.__capture.capture(self.__settings.capture_width, self.__settings.capture_height)
89+
9390
def __del__(self):
9491
'''Destructor
9592
'''
@@ -98,7 +95,7 @@ def __del__(self):
9895
del self.__captureState
9996
del self.__data
10097
del self.__useLegacyApi
101-
98+
10299
def execute(self):
103100
'''Execute the state
104101
- return: The new state to execute
@@ -107,7 +104,7 @@ def execute(self):
107104
if not self.__settings.grabbing():
108105
# return to the disconnected state
109106
return DisconnectedState(self.__settings)
110-
107+
111108
# check the xbmc API Version
112109
try:
113110
self.__capture.getCaptureState()
@@ -129,51 +126,51 @@ def execute(self):
129126
if startReadOut:
130127
if self.__useLegacyApi:
131128
self.__data = self.__capture.getImage()
132-
133-
# retrieve image data and reformat into rgb format
129+
130+
# retrieve image data and reformat into rgb format
134131
if self.__capture.getImageFormat() == 'ARGB':
135132
del self.__data[0::4]
136133
elif self.__capture.getImageFormat() == 'BGRA':
137134
del self.__data[3::4]
138135
self.__data[0::3], self.__data[2::3] = self.__data[2::3], self.__data[0::3]
139-
136+
140137
try:
141138
#send image to hyperion
142139
self.__hyperion.sendImage(self.__capture.getWidth(), self.__capture.getHeight(), str(self.__data), self.__settings.priority, 500)
143140
except Exception, e:
144141
# unable to send image. notify and go to the error state
145142
notify(xbmcaddon.Addon().getLocalizedString(32101))
146143
return ErrorState(self.__settings)
147-
144+
148145
if self.__useLegacyApi:
149146
if self.__captureState != xbmc.CAPTURE_STATE_WORKING:
150147
#the current capture is processed or it has failed, we request a new one
151-
self.__capture.capture(X_SIZE, Y_SIZE)
152-
153-
#limit the maximum number of frames sent to hyperion
154-
xbmc.sleep(SLEEP_PER_FRAME)
155-
148+
self.__capture.capture(self.__settings.capture_width, self.__settings.capture_height)
149+
150+
#limit the maximum number of frames sent to hyperion
151+
xbmc.sleep( int(1. / self.__settings.framerate) * 1000 )
152+
156153
return self
157-
154+
158155
class ErrorState:
159156
'''
160157
State class which is activated upon an error
161158
'''
162-
159+
163160
def __init__(self, settings):
164161
'''Constructor
165162
- settings: Settings structure
166163
'''
167164
log("Entering error state")
168165
self.__settings = settings
169-
166+
170167
def execute(self):
171168
'''Execute the state
172169
- return: The new state to execute
173170
'''
174171
# take note of the current revision of the settings
175172
rev = self.__settings.rev
176-
173+
177174
#stay in error state for the specified timeout or until the settings have been changed
178175
i = 0
179176
while (i < self.__settings.timeout) and (rev == self.__settings.rev):
@@ -182,6 +179,6 @@ def execute(self):
182179
else:
183180
xbmc.sleep(1000)
184181
i += 1
185-
182+
186183
# continue in the disconnected state
187184
return DisconnectedState(self.__settings)

resources/settings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
<setting id="hyperion_port" type="number" label="32004" default="19445" />
88
<setting id="hyperion_priority" type="number" label="32005" default="900" />
99
<setting id="reconnect_timeout" type="number" label="32006" default="30" />
10+
<setting id="capture_width" type="number" label="32008" default="64" />
11+
<setting id="capture_height" type="number" label="32009" default="64" />
12+
<setting id="framerate" type="number" label="32010" default="20" />
1013
</category>
1114
</settings>

0 commit comments

Comments
 (0)