Skip to content

Commit ff96eb2

Browse files
committed
Add "inputs" support to pyCA
Adds support for sending configuration to the agent configuration endpoint in Opencast. Adds a new config option "inputs". It allows users to specifiy for a given event which tracks they would like to show up in the final recording. For example, if the agent is capable of recording both "presenter/source" and "presentation/source", a user may select only "presentation/source" as input.
1 parent 905407a commit ff96eb2

File tree

5 files changed

+86
-8
lines changed

5 files changed

+86
-8
lines changed

etc/pyca.conf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@
4040
# Default: sqlite:///pyca.db
4141
#database = sqlite:///pyca.db
4242

43+
# Selectable inputs
44+
# A track will only be ingested if the flavor of the track matches one of the
45+
# selected inputs.
46+
# If not specified, all inputs are always selected.
47+
# Default: inputs = ''
48+
#inputs = 'presenter/source, presentation/source'
49+
4350

4451
[capture]
4552

@@ -170,7 +177,7 @@ command = 'ffmpeg -nostats -re -f lavfi -r 25 -i testsrc -f lavfi -i si
170177
# org.opencastproject.server.url setting of Opencast.
171178
# Type: string
172179
# Default: https://develop.opencast.org
173-
url = 'https://develop.opencast.org'
180+
url = 'http://localhost:8080'
174181

175182
# Analogue of -k, --insecure option in curl. Allows insercure SSL connections
176183
# while using HTTPS on the server.

pyca/agentstate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
:license: LGPL – see license.lgpl for more details.
88
'''
99

10-
from pyca.utils import set_service_status, update_agent_state, timestamp
10+
from pyca.utils import set_service_status, update_agent_state, timestamp, update_agent_config
1111
from pyca.utils import terminate
1212
from pyca.config import config
1313
from pyca.db import Service, ServiceStatus
@@ -34,6 +34,7 @@ def control_loop():
3434

3535
if not terminate():
3636
update_agent_state()
37+
update_agent_config()
3738

3839
logger.info('Shutting down agentstate service')
3940
set_service_status(Service.AGENTSTATE, ServiceStatus.STOPPED)

pyca/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
cal_lookahead = integer(min=0, default=14)
2121
backup_mode = boolean(default=false)
2222
database = string(default='sqlite:///pyca.db')
23+
inputs = force_list(default=list())
2324
2425
[capture]
2526
directory = string(default='./recordings')

pyca/ingest.py

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,47 @@
2222
logger = logging.getLogger(__name__)
2323
notify = sdnotify.SystemdNotifier()
2424

25+
def inputs_from_event(event):
26+
''' Parse inputs from event attachment
27+
'''
28+
29+
inputs = []
30+
for attachment in event.get_data().get('attach'):
31+
data = attachment.get('data')
32+
if (attachment.get('x-apple-filename') ==
33+
'org.opencastproject.capture.agent.properties'):
34+
for prop in data.split('\n'):
35+
if prop.startswith('capture.device.names'):
36+
param = prop.split('=', 1)
37+
inputs = param[1].split(',')
38+
break
39+
return inputs
40+
41+
def is_track_selected(event, flavor):
42+
''' If inputs are configured, check if track was selected
43+
'''
44+
45+
# inputs not configured -> add all
46+
inputs_conf = config('agent', 'inputs')
47+
if not inputs_conf:
48+
logger.info('No inputs in config')
49+
return True
50+
51+
# Get inputs from event attachment
52+
inputs_event = inputs_from_event(event)
53+
54+
# inputs not in attachment -> add all
55+
if not inputs_event:
56+
logger.info('No inputs in schedule')
57+
return True
58+
59+
# input is selected
60+
if flavor in inputs_event:
61+
return True
62+
63+
# input is not selected
64+
return False
65+
2566

2667
def get_config_params(properties):
2768
'''Extract the set of configuration parameters from the properties attached
@@ -87,12 +128,15 @@ def ingest(event):
87128

88129
# add track
89130
for (flavor, track) in event.get_tracks():
90-
logger.info('Adding track (%s -> %s)', flavor, track)
91-
track = track.encode('ascii', 'ignore')
92-
fields = [('mediaPackage', mediapackage), ('flavor', flavor),
93-
('BODY1', (pycurl.FORM_FILE, track))]
94-
mediapackage = http_request(service_url + '/addTrack', fields,
95-
timeout=0)
131+
if is_track_selected(event, flavor):
132+
logger.info('Adding track (%s -> %s)', flavor, track)
133+
track = track.encode('ascii', 'ignore')
134+
fields = [('mediaPackage', mediapackage), ('flavor', flavor),
135+
('BODY1', (pycurl.FORM_FILE, track))]
136+
mediapackage = http_request(service_url + '/addTrack', fields,
137+
timeout=0)
138+
else:
139+
logger.info('Not adding track (%s -> %s)', flavor, track)
96140

97141
# ingest
98142
logger.info('Ingest recording')

pyca/utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,31 @@ def update_agent_state():
260260

261261
register_ca(status=status)
262262

263+
def update_agent_config():
264+
'''Update the current agent configuration in opencast.
265+
'''
266+
267+
if config('agent', 'backup_mode'):
268+
return
269+
service_endpoint = service('capture.admin')
270+
if not service_endpoint:
271+
logger.warning('Missing endpoint for updating agent status.')
272+
return
273+
274+
inputs = ",".join(config('agent', 'inputs'))
275+
params = [('configuration',
276+
'{\'capture.device.names\': \'' + inputs + '\'}'
277+
)]
278+
279+
name = urlquote(config('agent', 'name').encode('utf-8'), safe='')
280+
url = f'{service_endpoint[0]}/agents/{name}/configuration'
281+
try:
282+
response = http_request(url, params).decode('utf-8')
283+
if response:
284+
logger.info(response)
285+
except pycurl.error as e:
286+
logger.warning('Could not set configuration of agent %s: %s', name, e)
287+
263288

264289
def terminate(shutdown=None):
265290
'''Mark process as to be terminated.

0 commit comments

Comments
 (0)