From af1d2bd63a718e800ff81d43a33294265a2913e1 Mon Sep 17 00:00:00 2001 From: Robin ALEXANDER <64310405+colisee@users.noreply.github.com> Date: Wed, 21 Sep 2022 11:28:04 +0200 Subject: [PATCH] Adapt odr-encodermanager to odr-audioenc v3.3.0 (#16) * Remove trailing white spaces * Use odr-audioenc long arguments * Adapt to odr-audioenc v3.3.0 * UX: use verbs in actions-oriented menus Co-authored-by: Robin Alexander --- api/__init__.py | 100 ++++++++++++------------ config/__init__.py | 138 +++++++++++++++++---------------- static/js/odr-encoderconfig.js | 65 +++++++--------- templates/body-nav.html | 4 +- templates/encoderconfig.html | 71 +++++++++-------- 5 files changed, 189 insertions(+), 189 deletions(-) diff --git a/api/__init__.py b/api/__init__.py index 5532ec2..fed9239 100755 --- a/api/__init__.py +++ b/api/__init__.py @@ -87,14 +87,14 @@ def info(self): } info['is_login'] = is_login() info['is_network'] = is_network(self.config_file) - + if is_adcast(self.config_file): info['is_adcast'] = is_adcast(self.config_file) if is_slide_mgnt(self.config_file): info['is_slide_mgnt'] = is_slide_mgnt(self.config_file) - + info['plugins'] = self.conf.getPlugins() - + return info @cherrypy.expose @@ -381,11 +381,11 @@ def getConfig(self, **params): 'driftcomp': 'true', 'silence_detect': 'true', 'silence_duration': '60', + 'audio_gain': '', 'alsa_device': 'plughw:1,0', 'stream_url': '', 'stream_writeicytext': 'true', 'stream_lib': 'gst', - 'stream_gain': '', 'avt_input_uri': 'udp://:32010', 'avt_control_uri': 'udp://192.168.128.111:9325', 'avt_pad_port': '9405', @@ -448,11 +448,11 @@ def getVersion(self, **params): for data in self.conf.config['odr']: if data['uniq_id'] == query['uniq_id']: odr = data - + if 'uniq_id' in odr: if 'path' in odr: output = {} - + for process_path in odr['path']: if process_path.endswith("_path"): if os.path.isfile(odr['path'][process_path]): @@ -469,15 +469,15 @@ def getVersion(self, **params): output["{process}_version".format(process=process_path)] = 'not found' else: return {'status': '0', 'statusText': 'Ok (but path section not found. Probably encoder recently created)', 'data': {}} - + else: return {'status': '-299', 'statusText': 'coder not found', 'data': {}} - + return {'status': '0', 'statusText': 'Ok', 'data': output} else: return {'status': '-298', 'statusText': 'you have to specify uniq_id', 'data': {}} - - + + @cherrypy.expose @cherrypy.tools.json_out() @@ -501,7 +501,7 @@ def setCoder(self): cl = cherrypy.request.headers['Content-Length'] rawbody = cherrypy.request.body.read(int(cl)) param = json.loads(rawbody.decode('utf-8')) - + if 'max_encoder_instance' in self.conf.config['global']: if len(param) >= self.conf.config['global']['max_encoder_instance']+1: return {'status': '-207', 'statusText': 'Maximum encoder instance reached.'} @@ -570,33 +570,33 @@ def setCoder(self): shutil.rmtree(odr['padenc']['slide_directory']) except: pass - + if 'slide_directory_live' in odr['padenc'] and os.path.exists(odr['padenc']['slide_directory_live']): try: shutil.rmtree(odr['padenc']['slide_directory_live']) except: pass - + if 'slide_directory_carousel' in odr['padenc'] and os.path.exists(odr['padenc']['slide_directory_carousel']): try: shutil.rmtree(odr['padenc']['slide_directory_carousel']) except: pass - + if 'slide_directory_ads' in odr['padenc'] and os.path.exists(odr['padenc']['slide_directory_ads']): try: shutil.rmtree(odr['padenc']['slide_directory_ads']) except: pass - + # Remove statistics UNIX Datagram socket if os.path.exists(odr['source']['stats_socket']): try: os.remove(odr['source']['stats_socket']) except: pass - + # Remove service odr-audioencoder service = 'odr-audioencoder-%s' % (odr['uniq_id']) if self.is_program_exist(programs, service): @@ -632,7 +632,7 @@ def setCoder(self): server.supervisor.reloadConfig() except Exception as e: return {'status': '-206', 'statusText': 'Error when removing slide-mgnt-%s (XMLRPC): ' % (odr['uniq_id']) + str(e)} - + # Remove service adcast service = 'adcast-%s' % (odr['uniq_id']) if self.is_program_exist(programs, service): @@ -644,7 +644,7 @@ def setCoder(self): server.supervisor.reloadConfig() except Exception as e: return {'status': '-206', 'statusText': 'Error when removing adcast-%s (XMLRPC): ' % (odr['uniq_id']) + str(e)} - + # Remove configuration_changed information self.conf.delConfigurationChanged(odr['uniq_id']) @@ -695,37 +695,37 @@ def setConfig(self): or ('slide_directory_live' in data['padenc']\ and 'slide_directory_live' in param['padenc']\ and data['padenc']['slide_directory_live'] != param['padenc']['slide_directory_live']): - + if os.path.exists(data['padenc']['slide_directory_live']): try: shutil.rmtree(data['padenc']['slide_directory_live']) except: pass - + if ('slide_directory_carousel' in data['padenc']\ and 'slide_directory_carousel' not in param['padenc'])\ or ('slide_directory_carousel' in data['padenc']\ and 'slide_directory_carousel' in param['padenc']\ and data['padenc']['slide_directory_carousel'] != param['padenc']['slide_directory_carousel']): - + if os.path.exists(data['padenc']['slide_directory_carousel']): try: shutil.rmtree(data['padenc']['slide_directory_carousel']) except: pass - + if ('slide_directory_ads' in data['padenc']\ and 'slide_directory_ads' not in param['padenc'])\ or ('slide_directory_ads' in data['padenc']\ and 'slide_directory_ads' in param['padenc']\ and data['padenc']['slide_directory_ads'] != param['padenc']['slide_directory_ads']): - + if os.path.exists(data['padenc']['slide_directory_ads']): try: shutil.rmtree(data['padenc']['slide_directory_ads']) except: pass - + # Check if PAD socket & DLS file are already used by other encoder for data in self.conf.config['odr']: @@ -742,7 +742,7 @@ def setConfig(self): li = param['padenc']['slide_live_interval'] if param['padenc']['slide_live_interval'] != '' else '35' if int(ll) < int(li): return {'status': '-224', 'statusText': 'Live lifetime (%ssec) can not be smaller than Live interval (%ssec)' % (int(ll), int(li))} - + # Merge change odr = [] for data in self.conf.config['odr']: @@ -818,7 +818,7 @@ def setConfig(self): if param['padenc']['enable'] == 'true'\ and 'slide_mgnt' in self.conf.config['global']\ and (self.conf.config['global']['slide_mgnt'] == True or self.conf.config['global']['slide_mgnt'] == 'true'): - + if not self.is_program_exist(programs, service): try: server.supervisor.reloadConfig() @@ -835,14 +835,14 @@ def setConfig(self): server.supervisor.reloadConfig() except Exception as e: return {'status': '-206', 'statusText': 'Error when removing %s (XMLRPC): ' % (service) + str(e)} - + # Check for adcast service = 'adcast-%s' % (param['uniq_id']) if param['padenc']['enable'] == 'true'\ and ('slide_mgnt' in self.conf.config['global'] and (self.conf.config['global']['slide_mgnt'] == True or self.conf.config['global']['slide_mgnt'] == 'true') )\ and ('adcast' in self.conf.config['global'] and (self.conf.config['global']['adcast'] == True or self.conf.config['global']['adcast'] == 'true') ) \ and ('adcast' in param and param['adcast']['enable'] == 'true'): - + if not self.is_program_exist(programs, service): try: server.supervisor.reloadConfig() @@ -859,13 +859,13 @@ def setConfig(self): server.supervisor.reloadConfig() except Exception as e: return {'status': '-206', 'statusText': 'Error when removing %s (XMLRPC): ' % (service) + str(e)} - + return {'status': '0', 'statusText': 'Ok'} @cherrypy.expose def setSLS(self, uniq_id=None, slide_file=None, rmode=None, **params): self.conf = Config(self.config_file) - + if cherrypy.request.method != 'POST': # it's impossible to use build_response here, because # with an invalid request, the `output` parameter is @@ -873,7 +873,7 @@ def setSLS(self, uniq_id=None, slide_file=None, rmode=None, **params): cherrypy.response.status = 400 cherrypy.response.headers['content-type'] = "text/plain" return "Only HTTP POST are available" - + def build_response(g, r): if rmode and rmode == 'json': cherrypy.response.headers['content-type'] = "application/json" @@ -890,13 +890,13 @@ def build_response(g, r): for o in r: result += '%s: %s\n' % (o['coder_name'], o['statusText'] ) return result - + def process_query(odr, f): output = {} output['coder_name'] = odr['name'] output['coder_uniq_id'] = odr['uniq_id'] output['coder_description'] = odr['description'] - + if 'padenc' in odr: if odr['padenc']['enable'] == 'true': # Find slide directory @@ -905,14 +905,14 @@ def process_query(odr, f): fdest = odr['padenc']['slide_directory_live'] elif odr['padenc']['slide_directory'].strip() != '' and os.path.exists(odr['padenc']['slide_directory']): fdest = odr['padenc']['slide_directory'] - + if not fdest: output['status'] = -208 output['statusText'] = "Destination directory %s not exist" % (fdest) return output - + destPath = "%s/%s" % (fdest,f['name']) - + # Write slide try: with open(destPath, 'wb') as outfile: @@ -925,45 +925,45 @@ def process_query(odr, f): output['status'] = 0 output['statusText'] = "Slide file write to %s (size:%s - %skB)" % (destPath, f['len'], f['len_kb']) return output - + # DLS (odr-padenc process) is disable else: output['status'] = -208 output['statusText'] = 'PAD Encoder is disable' return output - + # padenc is not present in configuration / encoder is not configured. else: output['status'] = -211 output['statusText'] = 'Encoder is not configured' return output - + # check if slide_file parameter is available if not slide_file: return build_response({'status': -401, 'statusText': 'Need slide_file parameter'}, []) - + f= {} f['name'] = slide_file.filename f['ext'] = os.path.splitext(f['name'])[1] f['data'] = slide_file.file.read() f['len'] = len(f['data']) f['len_kb'] = round(len(f['data'])/1000) - + # check if sent file is authorized extension if f['ext'] not in ['.jpg', '.jpeg', '.png', '.apng']: return build_response({'status': -208, 'statusText': 'Unauthorized file extension %s' % (f['ext'])}, []) - + # check if sent file size under slide_size_limit slide_size_limit = 50 if int(f['len_kb']) > int(slide_size_limit): return build_response({'status': -208, 'statusText': 'File is too big %skB (max %skB)' % (f['len_kb'], slide_size_limit)}, []) - + result = [] if uniq_id: # check if uniq_id exist if not any(c['uniq_id'] == uniq_id for c in self.conf.config['odr']): return build_response({'status': -401, 'statusText': 'Unknown uniq_id %s' % (uniq_id)}, []) - + for odr in self.conf.config['odr']: if odr['uniq_id'] == uniq_id: result.append( process_query(odr, f) ) @@ -972,7 +972,7 @@ def process_query(odr, f): result.append( process_query(odr, f) ) return build_response({'status': 0, 'statusText': 'Ok'}, result) - + @cherrypy.expose def setDLS(self, dls=None, artist=None, title=None, output=None, uniq_id=None, **params): @@ -1317,7 +1317,7 @@ def getStatus(self): pn['coder_uniq_id'] = data['uniq_id'] pn['configuration_changed'] = self.conf.getConfigurationChanged(data['uniq_id'], 'odr-audioencoder') output.append( pn ) - + # odr-padencoder if data['padenc']['enable'] == 'true': pn = server.supervisor.getProcessInfo('odr-padencoder-%s' % (data['uniq_id']) ) @@ -1326,7 +1326,7 @@ def getStatus(self): pn['coder_uniq_id'] = data['uniq_id'] pn['configuration_changed'] = self.conf.getConfigurationChanged(data['uniq_id'], 'odr-padencoder') output.append( pn ) - + # slide-mgnt if data['padenc']['enable'] == 'true'\ and 'slide_mgnt' in self.conf.config['global']\ @@ -1334,20 +1334,20 @@ def getStatus(self): and 'slide_directory_live' in data['padenc']\ and 'slide_directory_carousel' in data['padenc']\ and 'slide_directory_ads' in data['padenc']: - + pn = server.supervisor.getProcessInfo('slide-mgnt-%s' % (data['uniq_id']) ) pn['coder_name'] = data['name'] pn['coder_description'] = data['description'] pn['coder_uniq_id'] = data['uniq_id'] pn['configuration_changed'] = self.conf.getConfigurationChanged(data['uniq_id'], 'slide-mgnt') output.append( pn ) - + # adcast if data['padenc']['enable'] == 'true'\ and ('slide_mgnt' in self.conf.config['global'] and (self.conf.config['global']['slide_mgnt'] == True or self.conf.config['global']['slide_mgnt'] == 'true') )\ and ('adcast' in self.conf.config['global'] and (self.conf.config['global']['adcast'] == True or self.conf.config['global']['adcast'] == 'true') )\ and ('adcast' in data and data['adcast']['enable'] == 'true'): - + pn = server.supervisor.getProcessInfo('adcast-%s' % (data['uniq_id']) ) pn['coder_name'] = data['name'] pn['coder_description'] = data['description'] diff --git a/config/__init__.py b/config/__init__.py index 1ec9ccf..152751b 100755 --- a/config/__init__.py +++ b/config/__init__.py @@ -48,7 +48,7 @@ def is_network(config_file): return True else: return False - + def is_adcast(config_file): conf = Config(config_file) if ('adcast' in conf.config['global']) and (conf.config['global']['adcast'] == True or conf.config['global']['adcast'] == 'true'): @@ -58,7 +58,7 @@ def is_adcast(config_file): return False else: return False - + def is_slide_mgnt(config_file): conf = Config(config_file) if ('slide_mgnt' in conf.config['global']) and (conf.config['global']['slide_mgnt'] == True or conf.config['global']['slide_mgnt'] == 'true'): @@ -74,15 +74,15 @@ def __init__(self, config_file): def load(self, config_file): with open(self.config_file) as data_file: self.config = json.load(data_file) - + ## Plugins def initPlugins(self): global loaded_plugins loaded_plugins = [] - + def addPlugins(self, plugin): loaded_plugins.append(plugin) - + def getPlugins(self): return loaded_plugins @@ -166,7 +166,7 @@ def _updateAudioSockets(self): audioSocket[coder['uniq_id']]['status'] = '-512' audioSocket[coder['uniq_id']]['statusText'] = 'Ok - Waiting first data' audioSocket[coder['uniq_id']]['data'] = {} - + #print ('Try to bind socket %s' % (audioSocket[coder['uniq_id']]['stats_socket']), flush=True) try: audioSocket[coder['uniq_id']]['socket'].bind(audioSocket[coder['uniq_id']]['stats_socket']) @@ -343,7 +343,7 @@ def isOutputNotEqual(new, old, ignore_keys = []): self.setConfigurationChanged(coderNew['uniq_id'], 'odr-audioencoder', True) if coderNew['output']['samplerate'] != coderOld['output']['samplerate']: self.setConfigurationChanged(coderNew['uniq_id'], 'odr-audioencoder', True) - + if coderNew['output']['type'] == 'dabp': if coderNew['output']['dabp_sbr'] != coderOld['output']['dabp_sbr']: self.setConfigurationChanged(coderNew['uniq_id'], 'odr-audioencoder', True) @@ -358,11 +358,11 @@ def isOutputNotEqual(new, old, ignore_keys = []): if coderNew['output']['dab_dabpsy'] != coderOld['output']['dab_dabpsy']: self.setConfigurationChanged(coderNew['uniq_id'], 'odr-audioencoder', True) - + # check output if isOutputNotEqual(coderNew['output']['output'], coderOld['output']['output'], ['name']): self.setConfigurationChanged(coderNew['uniq_id'], 'odr-audioencoder', True) - + # check EDI specific parameters if coderNew['output']['edi_identifier'] != coderOld['output']['edi_identifier']: self.setConfigurationChanged(coderNew['uniq_id'], 'odr-audioencoder', True) @@ -379,20 +379,20 @@ def isOutputNotEqual(new, old, ignore_keys = []): self.setConfigurationChanged(coderNew['uniq_id'], 'odr-padencoder', True) if ('slide_mgnt' in config['global'] and (config['global']['slide_mgnt'] == True or config['global']['slide_mgnt'] == 'true') ): self.setConfigurationChanged(coderNew['uniq_id'], 'slide-mgnt', True) - - # CHECK ADCAST / SLIDE-MGNT slide directory + + # CHECK ADCAST / SLIDE-MGNT slide directory if ('slide_mgnt' in config['global'] and (config['global']['slide_mgnt'] == True or config['global']['slide_mgnt'] == 'true') )\ and 'slide_directory_live' in coderNew['padenc']\ and 'slide_directory_live' in coderOld['padenc']\ - and coderNew['padenc']['slide_directory_live'] != coderOld['padenc']['slide_directory_live']: + and coderNew['padenc']['slide_directory_live'] != coderOld['padenc']['slide_directory_live']: self.setConfigurationChanged(coderNew['uniq_id'], 'slide-mgnt', True) - + if ('slide_mgnt' in config['global'] and (config['global']['slide_mgnt'] == True or config['global']['slide_mgnt'] == 'true') )\ and 'slide_directory_carousel' in coderNew['padenc']\ and 'slide_directory_carousel' in coderOld['padenc']\ - and coderNew['padenc']['slide_directory_carousel'] != coderOld['padenc']['slide_directory_carousel']: + and coderNew['padenc']['slide_directory_carousel'] != coderOld['padenc']['slide_directory_carousel']: self.setConfigurationChanged(coderNew['uniq_id'], 'slide-mgnt', True) - + if ('slide_mgnt' in config['global'] and (config['global']['slide_mgnt'] == True or config['global']['slide_mgnt'] == 'true') )\ and 'slide_directory_ads' in coderNew['padenc']\ and 'slide_directory_ads' in coderOld['padenc']\ @@ -402,28 +402,28 @@ def isOutputNotEqual(new, old, ignore_keys = []): and 'adcast' in coderNew\ and 'adcast' in coderOld: self.setConfigurationChanged(coderNew['uniq_id'], 'adcast', True) - + # CHECK SLIDE-MGNT slide interval/liftime if ('slide_mgnt' in config['global'] and (config['global']['slide_mgnt'] == True or config['global']['slide_mgnt'] == 'true') )\ and 'slide_carousel_interval' in coderNew['padenc']\ and 'slide_carousel_interval' in coderOld['padenc']\ - and coderNew['padenc']['slide_carousel_interval'] != coderOld['padenc']['slide_carousel_interval']: + and coderNew['padenc']['slide_carousel_interval'] != coderOld['padenc']['slide_carousel_interval']: self.setConfigurationChanged(coderNew['uniq_id'], 'slide-mgnt', True) - + if ('slide_mgnt' in config['global'] and (config['global']['slide_mgnt'] == True or config['global']['slide_mgnt'] == 'true') )\ and 'slide_live_interval' in coderNew['padenc']\ and 'slide_live_interval' in coderOld['padenc']\ - and coderNew['padenc']['slide_live_interval'] != coderOld['padenc']['slide_live_interval']: + and coderNew['padenc']['slide_live_interval'] != coderOld['padenc']['slide_live_interval']: self.setConfigurationChanged(coderNew['uniq_id'], 'slide-mgnt', True) - + if ('slide_mgnt' in config['global'] and (config['global']['slide_mgnt'] == True or config['global']['slide_mgnt'] == 'true') )\ and 'slide_live_lifetime' in coderNew['padenc']\ and 'slide_live_lifetime' in coderOld['padenc']\ - and coderNew['padenc']['slide_live_lifetime'] != coderOld['padenc']['slide_live_lifetime']: + and coderNew['padenc']['slide_live_lifetime'] != coderOld['padenc']['slide_live_lifetime']: self.setConfigurationChanged(coderNew['uniq_id'], 'slide-mgnt', True) - - - + + + if coderNew['padenc']['slide_once'] != coderOld['padenc']['slide_once']: self.setConfigurationChanged(coderNew['uniq_id'], 'odr-padencoder', True) if coderNew['padenc']['raw_dls'] != coderOld['padenc']['raw_dls']: @@ -441,7 +441,7 @@ def isOutputNotEqual(new, old, ignore_keys = []): if coderNew['padenc']['dls_file'] != coderOld['padenc']['dls_file']: self.setConfigurationChanged(coderNew['uniq_id'], 'odr-audioencoder', True) self.setConfigurationChanged(coderNew['uniq_id'], 'odr-padencoder', True) - + # adcast if ('adcast' in config['global'] and (config['global']['adcast'] == True or config['global']['adcast'] == 'true') )\ and ('slide_mgnt' in config['global'] and (config['global']['slide_mgnt'] == True or config['global']['slide_mgnt'] == 'true') ): @@ -460,8 +460,8 @@ def isOutputNotEqual(new, old, ignore_keys = []): if coderNew['adcast']['listen_addr'] != coderOld['adcast']['listen_addr']: self.setConfigurationChanged(coderNew['uniq_id'], 'adcast', True) self.setConfigurationChanged(coderNew['uniq_id'], 'slide-mgnt', True) - - + + def write(self, config, checkConfigurationChanged=True): if checkConfigurationChanged: @@ -519,7 +519,7 @@ def checkConfigurationFile(self): if 'dls_fifo_file' in coder['padenc']: coder['padenc']['dls_file'] = coder['padenc']['dls_fifo_file'] del coder['padenc']['dls_fifo_file'] - print ('- rename dls_fifo_file to dls_file in padenc configuration file') + print ('- rename dls_fifo_file to dls_file in padenc configuration file') if not 'slide_carousel_interval' in coder['padenc']: coder['padenc']['slide_carousel_interval'] = '' if not 'slide_live_interval' in coder['padenc']: @@ -528,7 +528,7 @@ def checkConfigurationFile(self): coder['padenc']['slide_live_lifetime'] = '' if not 'raw_slides' in coder['padenc']: coder['padenc']['raw_slides'] = 'false' - + if 'source' in coder: if not 'stats_socket' in coder['source']: coder['source']['stats_socket'] = '/var/tmp/'+coder['uniq_id']+'.stats' @@ -542,6 +542,9 @@ def checkConfigurationFile(self): if not 'silence_duration' in coder['source']: coder['source']['silence_duration'] = '30' print ('- add silence_duration to source in configuration file') + if not 'audio_gain' in coder['source']: + coder['source']['audio_gain'] = '' + print ('- add audio_gain to source in configuration file') if 'device' in coder['source']: coder['source']['alsa_device'] = coder['source']['device'] del coder['source']['device'] @@ -556,10 +559,7 @@ def checkConfigurationFile(self): if not 'stream_lib' in coder['source']: coder['source']['stream_lib'] = 'vlc' print ('- add stream_lib to source in configuration file') - if not 'stream_gain' in coder['source']: - coder['source']['stream_gain'] = '' - print ('- add stream_gain to source in configuration file') - + if 'output' in coder: if 'zmq_output' in coder['output']: print ('- rename zmq_output to output in configuration file') @@ -576,7 +576,7 @@ def checkConfigurationFile(self): coder['output']['edi_timestamps_delay'] = '' print ('- add edi_timestamps_delay to output in configuration file') odr.append(coder) - + if 'plugins' not in self.config: plugins = {} else: @@ -625,7 +625,7 @@ def checkSupervisorProcess(self): # Add new supervisor configuration for coder in self.config['odr']: if all (k in coder for k in ("source","output","padenc","path")): - + # odr-audioencoder if not self.is_program_exist(programs, 'odr-audioencoder-%s' % (coder['uniq_id'])): try: @@ -633,7 +633,7 @@ def checkSupervisorProcess(self): server.supervisor.addProcessGroup('odr-audioencoder-%s' % (coder['uniq_id'])) except Exception as e: raise ValueError( 'Error when starting odr-audioencoder-%s (XMLRPC): %s' % (coder['uniq_id'], str(e)) ) - + # odr-padencoder if coder['padenc']['enable'] == 'true': if not self.is_program_exist(programs, 'odr-padencoder-%s' % (coder['uniq_id'])): @@ -642,7 +642,7 @@ def checkSupervisorProcess(self): server.supervisor.addProcessGroup('odr-padencoder-%s' % (coder['uniq_id'])) except Exception as e: raise ValueError( 'Error when starting odr-padencoder-%s (XMLRPC): %s' % (coder['uniq_id'], str(e)) ) - + # slide-mgnt if coder['padenc']['enable'] == 'true'\ and 'slide_mgnt' in self.config['global']\ @@ -650,20 +650,20 @@ def checkSupervisorProcess(self): and 'slide_directory_live' in coder['padenc']\ and 'slide_directory_carousel' in coder['padenc']\ and 'slide_directory_ads' in coder['padenc']: - + if not self.is_program_exist(programs, 'slide-mgnt-%s' % (coder['uniq_id'])): try: server.supervisor.reloadConfig() server.supervisor.addProcessGroup('slide-mgnt-%s' % (coder['uniq_id'])) except Exception as e: raise ValueError( 'Error when starting slide-mgnt-%s (XMLRPC): %s' % (coder['uniq_id'], str(e)) ) - + # adcast if coder['padenc']['enable'] == 'true'\ and ('slide_mgnt' in self.config['global'] and (self.config['global']['slide_mgnt'] == True or self.config['global']['slide_mgnt'] == 'true') )\ and ('adcast' in self.config['global'] and (self.config['global']['adcast'] == True or self.config['global']['adcast'] == 'true') )\ and ('adcast' in coder and coder['adcast']['enable'] == 'true'): - + if not self.is_program_exist(programs, 'adcast-%s' % (coder['uniq_id'])): try: server.supervisor.reloadConfig() @@ -747,7 +747,7 @@ def generateNetworkFiles(self, config): def generateSupervisorFiles(self, config): supervisorConfig = "" - + # Generate ODR process supervisor configuration for odr in config['odr']: if all (k in odr for k in ("source","output","padenc","path")): @@ -763,7 +763,7 @@ def generateSupervisorFiles(self, config): os.makedirs(odr['padenc']['slide_directory']) except Exception as e: raise ValueError('Error when creating slide directory: {}'.format(e)) - + if os.path.exists(odr['padenc']['slide_directory']): command += ' --dir=%s\n' % (odr['padenc']['slide_directory']) if odr['padenc']['slide_once'] == 'true': @@ -775,14 +775,14 @@ def generateSupervisorFiles(self, config): os.makedirs(odr['padenc']['slide_directory_live']) except Exception as e: raise ValueError('Error when creating live slide directory: {}'.format(e)) - + if 'slide_directory_carousel' in odr['padenc']: if not os.path.exists(odr['padenc']['slide_directory_carousel']): try: os.makedirs(odr['padenc']['slide_directory_carousel']) except Exception as e: raise ValueError('Error when creating carousel slide directory: {}'.format(e)) - + if 'slide_directory_ads' in odr['padenc']: if not os.path.exists(odr['padenc']['slide_directory_ads']): try: @@ -799,7 +799,7 @@ def generateSupervisorFiles(self, config): os.makedirs( os.path.dirname(odr['padenc']['dls_file']) ) except Exception as e: raise ValueError('Error when creating dls_file directory: {}'.format(e)) - + # Create file try: f = open(odr['padenc']['dls_file'], 'w') @@ -828,7 +828,7 @@ def generateSupervisorFiles(self, config): if odr['padenc']['raw_dls'] == 'true': command += ' --raw-dls\n' - + if odr['padenc']['raw_slides'] == 'true': command += ' --raw-slides\n' @@ -848,7 +848,7 @@ def generateSupervisorFiles(self, config): supervisorConfig += "# %s\n" % (odr['name']) supervisorConfig += "[program:odr-padencoder-%s]\n" % (odr['uniq_id']) supervisorConfig += "command=%s" % (command) - + # -- default parameters supervisorConfigParam = {} supervisorConfigParam['autostart'] = odr['autostart'] @@ -858,12 +858,12 @@ def generateSupervisorFiles(self, config): supervisorConfigParam['group'] = "odr" supervisorConfigParam['redirect_stderr'] = "true" supervisorConfigParam['stdout_logfile'] = "/var/log/supervisor/odr-padencoder-%s.log" % (odr['uniq_id']) - + # -- override default parameters or add additional parameters if 'supervisor_additional_options' in odr: for key in odr['supervisor_additional_options'].keys(): supervisorConfigParam[key] = odr['supervisor_additional_options'][key] - + # -- generate final padencoder supervisor configuration for key in supervisorConfigParam.keys(): supervisorConfig += "%s=%s\n" % (key, supervisorConfigParam[key]) @@ -882,8 +882,6 @@ def generateSupervisorFiles(self, config): if odr['source']['type'] == 'stream': if odr['source']['stream_lib'] == 'vlc': command += ' --vlc-uri=%s\n' % (odr['source']['stream_url']) - if odr['source']['stream_gain'] != '': - command += ' --vlc-gain=%s\n' % (odr['source']['stream_gain']) if odr['source']['stream_lib'] == 'gst': command += ' --gst-uri=%s\n' % (odr['source']['stream_url']) if odr['source']['type'] == 'aes67': @@ -912,6 +910,10 @@ def generateSupervisorFiles(self, config): if ( odr['source']['type'] == 'alsa' or odr['source']['type'] == 'stream' or odr['source']['type'] == 'aes67' ) and odr['source']['silence_detect'] == 'true' and odr['source']['silence_duration'] != '' and int(odr['source']['silence_duration']) >> 0: command += ' --silence=%s\n' % (odr['source']['silence_duration']) + # audio gain for alsa or stream or aes input type only + if ( odr['source']['type'] == 'alsa' or odr['source']['type'] == 'stream' or odr['source']['type'] == 'aes67' ) and odr['source']['audio_gain'] != '': + command += ' -g %s\n' % (odr['source']['audio_gain']) + # bitrate, samplerate, channels for all input type command += ' --bitrate=%s\n' % (odr['output']['bitrate']) command += ' --rate=%s\n' % (odr['output']['samplerate']) @@ -956,25 +958,25 @@ def generateSupervisorFiles(self, config): for out in odr['output']['output']: if out['enable'] == 'true': if out['type'] == 'zmq': - command += ' -o tcp://%s:%s\n' % (out['host'], out['port']) + command += ' --output=tcp://%s:%s\n' % (out['host'], out['port']) if out['type'] == 'editcp': - command += ' -e tcp://%s:%s\n' % (out['host'], out['port']) + command += ' --edi=tcp://%s:%s\n' % (out['host'], out['port']) # Stats socket if odr['source']['stats_socket'] != '': command += ' --stats=%s\n' % (odr['source']['stats_socket']) - + # EDI specific if 'edi_identifier' in odr['output'] and odr['output']['edi_identifier'] != '': command += ' --identifier="%s"\n' % (odr['output']['edi_identifier']) - + if 'edi_timestamps_delay' in odr['output'] and odr['output']['edi_timestamps_delay'] != '': command += ' --timestamp-delay=%s\n' % (odr['output']['edi_timestamps_delay']) supervisorConfig += "# %s\n" % (odr['name']) supervisorConfig += "[program:odr-audioencoder-%s]\n" % (odr['uniq_id']) supervisorConfig += "command=%s" % (command) - + # -- default parameters supervisorConfigParam = {} supervisorConfigParam['autostart'] = odr['autostart'] @@ -984,17 +986,17 @@ def generateSupervisorFiles(self, config): supervisorConfigParam['group'] = "odr" supervisorConfigParam['redirect_stderr'] = "true" supervisorConfigParam['stdout_logfile'] = "/var/log/supervisor/odr-audioencoder-%s.log" % (odr['uniq_id']) - + # -- override default parameters or add additional parameters if 'supervisor_additional_options' in odr: for key in odr['supervisor_additional_options'].keys(): supervisorConfigParam[key] = odr['supervisor_additional_options'][key] - + # -- generate final audioencoder supervisor configuration for key in supervisorConfigParam.keys(): supervisorConfig += "%s=%s\n" % (key, supervisorConfigParam[key]) supervisorConfig += "\n" - + # Write supervisor slide_mgnt section # If global.slide_mgnt is true if odr['padenc']['enable'] == 'true'\ @@ -1003,7 +1005,7 @@ def generateSupervisorFiles(self, config): and 'slide_directory_live' in odr['padenc']\ and 'slide_directory_carousel' in odr['padenc']\ and 'slide_directory_ads' in odr['padenc']: - + command = 'python3 /usr/local/bin/slide-mgnt.py\n' #command += ' -v\n' command += ' -p %s\n' % (odr['padenc']['pad']) @@ -1022,7 +1024,7 @@ def generateSupervisorFiles(self, config): command += ' -s %s\n' % (odr['adcast']['listen_addr']) if ('adcast' in odr) and (odr['adcast']['enable'] == 'true'): command += ' -r\n' - + supervisorConfig += "# %s\n" % (odr['name']) supervisorConfig += "[program:slide-mgnt-%s]\n" % (odr['uniq_id']) supervisorConfig += "command=%s" % (command) @@ -1035,30 +1037,30 @@ def generateSupervisorFiles(self, config): supervisorConfigParam['group'] = "odr" supervisorConfigParam['redirect_stderr'] = "true" supervisorConfigParam['stdout_logfile'] = "/var/log/supervisor/slide-%s.log" % (odr['uniq_id']) - + # -- override default parameters or add additional parameters if 'supervisor_additional_options' in odr: for key in odr['supervisor_additional_options'].keys(): supervisorConfigParam[key] = odr['supervisor_additional_options'][key] - + # -- generate final slide_mgnt supervisor configuration for key in supervisorConfigParam.keys(): supervisorConfig += "%s=%s\n" % (key, supervisorConfigParam[key]) supervisorConfig += "\n" - + # Write supervisor adcast section if odr['padenc']['enable'] == 'true'\ and ('slide_mgnt' in config['global'] and (config['global']['slide_mgnt'] == True or config['global']['slide_mgnt'] == 'true') )\ and ('adcast' in config['global'] and (config['global']['adcast'] == True or config['global']['adcast'] == 'true') ): - + if ('adcast' in odr) and (odr['adcast']['enable'] == 'true'): command = '/opt/adcast/bin/adcast-slide-controller run\n' command += ' --api-token %s\n' % (odr['adcast']['api_token']) command += ' --uuid %s\n' % (odr['adcast']['uuid']) command += ' --dst-dir %s\n' % (odr['padenc']['slide_directory_ads']) command += ' --listen-addr %s\n' % (odr['adcast']['listen_addr']) - + supervisorConfig += "# %s\n" % (odr['name']) supervisorConfig += "[program:adcast-%s]\n" % (odr['uniq_id']) supervisorConfig += "command=%s" % (command) @@ -1075,12 +1077,12 @@ def generateSupervisorFiles(self, config): if 'supervisor_additional_options' in odr: for key in odr['supervisor_additional_options'].keys(): supervisorConfigParam[key] = odr['supervisor_additional_options'][key] - + # -- generate final adcast supervisor configuration for key in supervisorConfigParam.keys(): supervisorConfig += "%s=%s\n" % (key, supervisorConfigParam[key]) supervisorConfig += "\n" - + # Generate plugins process supervisor configuration if len( loaded_plugins ) != 0: #print ('DEBUG: config - generateSupervisorFiles - process plugins', flush=True) diff --git a/static/js/odr-encoderconfig.js b/static/js/odr-encoderconfig.js index 8dd764f..7fc781b 100755 --- a/static/js/odr-encoderconfig.js +++ b/static/js/odr-encoderconfig.js @@ -75,9 +75,9 @@ function requestCoder() { function requestVersion(reload=false) { coder_uniq_id = $('#tab_coder li.active p.coder_uniq_id').tab('show').html() - + console.log('Version request for: '+coder_uniq_id) - + $.ajax({ type: "GET", url: "/api/getVersion?uniq_id="+coder_uniq_id, @@ -108,7 +108,7 @@ function requestVersion(reload=false) { if (key == 'padenc_path_version') { $('#path_padenc_version').html(val); } if (key == 'sourcecompanion_path_version') { $('#path_sourcecompanion_version').html(val); } }) - + } else { $.gritter.add({ title: 'Load configuration', @@ -157,11 +157,11 @@ function requestConfiguration(reload=false) { $('#source_driftcomp option[value="true"]').prop('selected', true); $('#source_silence_detect option[value="true"]').prop('selected', true); $('#source_silence_duration').val('60'); + $('#source_audio_gain').val(''); $('#source_alsa_device').val('plughw:1,0'); $('#source_stream_url').val(''); $('#source_stream_writeicytext option[value="true"]').prop('selected', true); $('#source_stream_lib option[value="vlc"]').prop('selected', true); - $('#source_stream_gain').val(''); $('#source_avt_input_uri').val('udp://:32010'); $('#source_avt_control_uri').val('udp://192.168.128.111:9325'); $('#source_avt_pad_port').val('9405'); @@ -199,7 +199,7 @@ function requestConfiguration(reload=false) { $('#padenc_raw_slides option[value="false"]').prop('selected', true); $('#padenc_uniform_label').val('5'); $('#padenc_uniform_label_ins').val('2000'); - + if(document.getElementById("padenc_slide_directory_live") !== null) { $('#padenc_slide_directory_live').val('/pad/slide/live/'+coder_uniq_id+'/'); } @@ -228,7 +228,7 @@ function requestConfiguration(reload=false) { $('#adcast_dst_dir').val('/pad/slide/ads/'+coder_uniq_id+'/'); $('#adcast_listen_addr').val('/var/tmp/adcast-'+coder_uniq_id+'.socket'); } - + $('#path_encoder_path').val('/usr/local/bin/odr-audioenc'); $('#path_padenc_path').val('/usr/local/bin/odr-padenc'); $('#path_sourcecompanion_path').val('/usr/local/bin/odr-sourcecompanion'); @@ -248,11 +248,11 @@ function requestConfiguration(reload=false) { if ( form_key == 'padenc_dls_fifo_file') { form_key='padenc_dls_file' } if ( form_key == 'source_device') { form_key='source_alsa_device' } if ( form_key == 'source_url') { form_key='source_stream_url' } - + // Ignore old key if ( form_key == 'padenc_pad_fifo') { return; } - - + + // -- Ignore 'supervisor_additional_options' if ( section_key == 'supervisor_additional_options') { return; @@ -354,11 +354,11 @@ function setConfiguration() { "stream_url": $('#source_stream_url').val(), "stream_writeicytext": $('#source_stream_writeicytext').val(), "stream_lib": $('#source_stream_lib').val(), - "stream_gain": $('#source_stream_gain').val(), "alsa_device": $('#source_alsa_device').val(), "driftcomp": $('#source_driftcomp').val(), "silence_detect": $('#source_silence_detect').val(), "silence_duration": $('#source_silence_duration').val(), + "audio_gain": $('#source_audio_gain').val(), "avt_input_uri": $('#source_avt_input_uri').val(), "avt_control_uri": $('#source_avt_control_uri').val(), "avt_pad_port": $('#source_avt_pad_port').val(), @@ -395,7 +395,7 @@ function setConfiguration() { "uniform_label_ins": $('#padenc_uniform_label_ins').val() }, } - + if (document.getElementById("padenc_slide_directory_live") !== null) { param['padenc']['slide_directory_live'] = $('#padenc_slide_directory_live').val(); } @@ -405,7 +405,7 @@ function setConfiguration() { if (document.getElementById("padenc_slide_directory_ads") !== null) { param['padenc']['slide_directory_ads'] = $('#padenc_slide_directory_ads').val(); } - + if (document.getElementById("padenc_slide_carousel_interval") !== null) { param['padenc']['slide_carousel_interval'] = $('#padenc_slide_carousel_interval').val(); } @@ -415,7 +415,7 @@ function setConfiguration() { if (document.getElementById("padenc_slide_live_lifetime") !== null) { param['padenc']['slide_live_lifetime'] = $('#padenc_slide_live_lifetime').val(); } - + // Only if 'collapseADCAST' exist if(document.getElementById("collapseADCAST") !== null) { adcast = { @@ -428,7 +428,7 @@ function setConfiguration() { } param['adcast'] = adcast } - + $.ajax({ type: "POST", url: "/api/setConfig", @@ -492,17 +492,12 @@ function setEnableDisable(){ $('#source_stream_url').prop('disabled', false); $('#source_stream_writeicytext').prop('disabled', false); $('#source_stream_lib').prop('disabled', false); - if ($('#source_stream_lib').val() == 'vlc') { - $('#source_stream_gain').prop('disabled', false); - } else { - $('#source_stream_gain').prop('disabled', true); - } - $('#source_alsa_device').prop('disabled', true); $('#btn_list_alsa_devices').prop('disabled', true); $('#source_driftcomp').prop('disabled', false); $('#source_silence_detect').prop('disabled', false); $('#source_silence_duration').prop('disabled', false); + $('#source_audio_gain').prop('disabled', false); $('#source_avt_input_uri').prop('disabled', true); $('#source_avt_control_uri').prop('disabled', true); $('#source_avt_pad_port').prop('disabled', true); @@ -547,12 +542,12 @@ function setEnableDisable(){ $('#source_stream_url').prop('disabled', true); $('#source_stream_writeicytext').prop('disabled', true); $('#source_stream_lib').prop('disabled', true); - $('#source_stream_gain').prop('disabled', true); $('#source_alsa_device').prop('disabled', false); $('#btn_list_alsa_devices').prop('disabled', false); $('#source_driftcomp').prop('disabled', false); $('#source_silence_detect').prop('disabled', false); $('#source_silence_duration').prop('disabled', false); + $('#source_audio_gain').prop('disabled', false); $('#source_avt_input_uri').prop('disabled', true); $('#source_avt_control_uri').prop('disabled', true); $('#source_avt_pad_port').prop('disabled', true); @@ -593,12 +588,12 @@ function setEnableDisable(){ $('#source_stream_url').prop('disabled', true); $('#source_stream_writeicytext').prop('disabled', true); $('#source_stream_lib').prop('disabled', true); - $('#source_stream_gain').prop('disabled', true); $('#source_alsa_device').prop('disabled', true); $('#btn_list_alsa_devices').prop('disabled', true); $('#source_driftcomp').prop('disabled', true); $('#source_silence_detect').prop('disabled', true); $('#source_silence_duration').prop('disabled', true); + $('#source_audio_gain').prop('disabled', true); $('#source_avt_input_uri').prop('disabled', false); $('#source_avt_control_uri').prop('disabled', false); $('#source_avt_pad_port').prop('disabled', false); @@ -639,12 +634,12 @@ function setEnableDisable(){ $('#source_stream_url').prop('disabled', true); $('#source_stream_writeicytext').prop('disabled', true); $('#source_stream_lib').prop('disabled', true); - $('#source_stream_gain').prop('disabled', true); $('#source_alsa_device').prop('disabled', true); $('#btn_list_alsa_devices').prop('disabled', true); $('#source_driftcomp').prop('disabled', false); $('#source_silence_detect').prop('disabled', false); $('#source_silence_duration').prop('disabled', false); + $('#source_audio_gain').prop('disabled', false); $('#source_avt_input_uri').prop('disabled', true); $('#source_avt_control_uri').prop('disabled', true); $('#source_avt_pad_port').prop('disabled', true); @@ -816,7 +811,7 @@ $(function(){ $("#source_type").change(function() { setEnableDisable(); }); - + $("#source_stream_lib").change(function() { setEnableDisable(); }); @@ -917,17 +912,17 @@ $(function(){ $("#padenc_slide_directory").val('/var/tmp/slide-'+coder_uniq_id+'/'); } }); - + $('#btn_reset_padenc_slide_directory_live').click(function () { coder_uniq_id = $('#tab_coder li.active p.coder_uniq_id').tab('show').html() $("#padenc_slide_directory_live").val('/pad/slide/live/'+coder_uniq_id+'/'); }); - + $('#btn_reset_padenc_slide_directory_carousel').click(function () { coder_uniq_id = $('#tab_coder li.active p.coder_uniq_id').tab('show').html() $("#padenc_slide_directory_carousel").val('/pad/slide/carousel/'+coder_uniq_id+'/'); }); - + $('#btn_reset_padenc_slide_directory_ads').click(function () { coder_uniq_id = $('#tab_coder li.active p.coder_uniq_id').tab('show').html() $("#padenc_slide_directory_ads").val('/pad/slide/ads/'+coder_uniq_id+'/'); @@ -937,12 +932,12 @@ $(function(){ coder_uniq_id = $('#tab_coder li.active p.coder_uniq_id').tab('show').html() $("#padenc_dls_file").val('/var/tmp/metadata-'+coder_uniq_id+'.dls'); }); - + $('#btn_reset_adcast_listen_addr').click(function () { coder_uniq_id = $('#tab_coder li.active p.coder_uniq_id').tab('show').html() $("#adcast_listen_addr").val('/var/tmp/adcast-'+coder_uniq_id+'.socket'); }); - + $('#btn_reset_path_zmq_key_tmp_file').click(function () { coder_uniq_id = $('#tab_coder li.active p.coder_uniq_id').tab('show').html() $("#path_zmq_key_tmp_file").val('/var/tmp/zmq-'+coder_uniq_id+'.key'); @@ -952,7 +947,7 @@ $(function(){ coder_uniq_id = $('#tab_coder li.active p.coder_uniq_id').tab('show').html() $("#source_stats_socket").val('/var/tmp/'+coder_uniq_id+'.stats'); }); - + $('#btn_adcast_api_test').click(function () { $('#ADCastModal .modal-body').html(''); error_msg = '' @@ -962,7 +957,7 @@ $(function(){ if ($('#adcast_uuid').val() == '') { error_msg += 'UUID can not be empty
' } - + if (error_msg != '') { $('#ADCastModal .modal-body').html('
Warning!
'+error_msg+'
'); } else { @@ -976,7 +971,7 @@ $(function(){ o += 'api token: '+$('#adcast_api_token').val()+'
' o += '' $('#ADCastModal .modal-body').html(o); - + $.ajax({ type: "GET", url: url, @@ -997,7 +992,7 @@ $(function(){ }); } }); - + // Add ZMQ output $('#btn_output_add').click(function () { @@ -1018,9 +1013,9 @@ $(function(){ output_type_editcp_selected = ' selected="selected"' } $( '#output_output' ).append('
/:
') - + //$('#source_stream_lib option[value="vlc"]').prop('selected', true); - + $('#add_output_name').val(''); $('#add_output_host').val(''); $('#add_output_port').val(''); diff --git a/templates/body-nav.html b/templates/body-nav.html index ef290db..f31e0cf 100644 --- a/templates/body-nav.html +++ b/templates/body-nav.html @@ -13,7 +13,7 @@ Encoder @@ -22,7 +22,7 @@