Skip to content

Commit c742f2b

Browse files
committed
Merge pull request #20 from StefanRvO/master
Added option to configure capture size and framerate
2 parents 79cc128 + 94284a7 commit c742f2b

File tree

6 files changed

+51
-40
lines changed

6 files changed

+51
-40
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 & 26 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
@@ -32,14 +32,14 @@ class DisconnectedState:
3232
'''
3333
Default state class when disconnected from the Hyperion server
3434
'''
35-
35+
3636
def __init__(self, settings):
3737
'''Constructor
3838
- settings: Settings structure
3939
'''
4040
log("Entering disconnected state")
4141
self.__settings = settings
42-
42+
4343
def execute(self):
4444
'''Execute the state
4545
- return: The new state to execute
@@ -48,7 +48,7 @@ def execute(self):
4848
if not self.__settings.grabbing():
4949
xbmc.sleep(500)
5050
return self
51-
51+
5252
# we are enabled and want to advance to the connected state
5353
try:
5454
nextState = ConnectedState(self.__settings)
@@ -58,10 +58,10 @@ def execute(self):
5858
if self.__settings.showErrorMessage:
5959
notify(xbmcaddon.Addon().getLocalizedString(32100))
6060
self.__settings.showErrorMessage = False
61-
61+
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
@@ -79,14 +79,14 @@ def __init__(self, settings):
7979
self.__captureState = None
8080
self.__data = None
8181
self.__useLegacyApi = True
82-
82+
8383
# try to connect to hyperion
8484
self.__hyperion = Hyperion(self.__settings.address, self.__settings.port)
85-
85+
8686
# create the capture object
8787
self.__capture = xbmc.RenderCapture()
88-
self.__capture.capture(64, 64)
89-
88+
self.__capture.capture(self.__settings.capture_width, self.__settings.capture_height)
89+
9090
def __del__(self):
9191
'''Destructor
9292
'''
@@ -95,7 +95,7 @@ def __del__(self):
9595
del self.__captureState
9696
del self.__data
9797
del self.__useLegacyApi
98-
98+
9999
def execute(self):
100100
'''Execute the state
101101
- return: The new state to execute
@@ -104,7 +104,7 @@ def execute(self):
104104
if not self.__settings.grabbing():
105105
# return to the disconnected state
106106
return DisconnectedState(self.__settings)
107-
107+
108108
# check the xbmc API Version
109109
try:
110110
self.__capture.getCaptureState()
@@ -126,51 +126,51 @@ def execute(self):
126126
if startReadOut:
127127
if self.__useLegacyApi:
128128
self.__data = self.__capture.getImage()
129-
130-
# retrieve image data and reformat into rgb format
129+
130+
# retrieve image data and reformat into rgb format
131131
if self.__capture.getImageFormat() == 'ARGB':
132132
del self.__data[0::4]
133133
elif self.__capture.getImageFormat() == 'BGRA':
134134
del self.__data[3::4]
135135
self.__data[0::3], self.__data[2::3] = self.__data[2::3], self.__data[0::3]
136-
136+
137137
try:
138138
#send image to hyperion
139139
self.__hyperion.sendImage(self.__capture.getWidth(), self.__capture.getHeight(), str(self.__data), self.__settings.priority, 500)
140140
except Exception, e:
141141
# unable to send image. notify and go to the error state
142142
notify(xbmcaddon.Addon().getLocalizedString(32101))
143143
return ErrorState(self.__settings)
144-
144+
145145
if self.__useLegacyApi:
146146
if self.__captureState != xbmc.CAPTURE_STATE_WORKING:
147147
#the current capture is processed or it has failed, we request a new one
148-
self.__capture.capture(64, 64)
149-
150-
#limit the maximum number of frames sent to hyperion
151-
xbmc.sleep(100)
152-
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+
153153
return self
154-
154+
155155
class ErrorState:
156156
'''
157157
State class which is activated upon an error
158158
'''
159-
159+
160160
def __init__(self, settings):
161161
'''Constructor
162162
- settings: Settings structure
163163
'''
164164
log("Entering error state")
165165
self.__settings = settings
166-
166+
167167
def execute(self):
168168
'''Execute the state
169169
- return: The new state to execute
170170
'''
171171
# take note of the current revision of the settings
172172
rev = self.__settings.rev
173-
173+
174174
#stay in error state for the specified timeout or until the settings have been changed
175175
i = 0
176176
while (i < self.__settings.timeout) and (rev == self.__settings.rev):
@@ -179,6 +179,6 @@ def execute(self):
179179
else:
180180
xbmc.sleep(1000)
181181
i += 1
182-
182+
183183
# continue in the disconnected state
184184
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)