Skip to content

Commit

Permalink
Add toolame support
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannQueret committed Feb 8, 2016
1 parent 05afd28 commit 83d9406
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 83 deletions.
22 changes: 13 additions & 9 deletions config.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[global]
encoder_path = /usr/local/bin/dabplus-enc
encoder_dabp_path = /usr/local/bin/dabplus-enc
encoder_dab_path = /usr/local/bin/toolame-dab
mot_path = /usr/local/bin/mot-encoder
zmq_tmp_file = /tmp/zmq.key

Expand All @@ -13,22 +14,25 @@ bind_ip =

[source]
type = stream
url = http://hd.stream.frequence3.net/frequence3.flac
url = http://ice.stream.frequence3.net/frequence3-128.mp3
volume = 0
device = hw:1,0
driftcomp = true

[output]
zmq_host = alf.queret.net:9001
zmq_host = 192.168.0.55:9002
zmq_key =
bitrate = 96
samplerate = 48000
sbr = true
ps = false
afterburner = true
type = dab
dabp_bitrate = 96
dabp_samplerate = 48000
dabp_sbr = true
dabp_ps = false
dabp_afterburner = true
dab_samplerate = 48
dab_bitrate = 128

[mot]
enable = true
enable = false
pad = 34
pad_fifo_file = /tmp/metadata.pad
dls_fifo_file = /tmp/metadata.dls
Expand Down
31 changes: 19 additions & 12 deletions config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def __init__(self,config_file, logger):
self.source_type = self.ConfigSectionMap('source')['type']

# Global configuration
self.global_encoder_path = self.ConfigSectionMap('global')['encoder_path']
self.global_encoder_dabp_path = self.ConfigSectionMap('global')['encoder_dabp_path']
self.global_encoder_dab_path = self.ConfigSectionMap('global')['encoder_dab_path']
self.global_mot_path = self.ConfigSectionMap('global')['mot_path']
self.global_zmq_tmp_file = self.ConfigSectionMap('global')['zmq_tmp_file']

Expand All @@ -63,21 +64,27 @@ def __init__(self,config_file, logger):
# Output configuration
self.output_zmq_host = self.ConfigSectionMap('output')['zmq_host']
self.output_zmq_key = self.ConfigSectionMap('output')['zmq_key']
self.output_type = self.ConfigSectionMap('output')['type']

self.output_samplerate = self.ConfigSectionMap('output')['samplerate']
self.output_bitrate = self.ConfigSectionMap('output')['bitrate']
if self.ConfigSectionMap('output')['sbr'].upper() == 'TRUE':
self.output_sbr = True
#DAB+
self.output_dabp_samplerate = self.ConfigSectionMap('output')['dabp_samplerate']
self.output_dabp_bitrate = self.ConfigSectionMap('output')['dabp_bitrate']
if self.ConfigSectionMap('output')['dabp_sbr'].upper() == 'TRUE':
self.output_dabp_sbr = True
else:
self.output_sbr = False
if self.ConfigSectionMap('output')['ps'].upper() == 'TRUE':
self.output_ps = True
self.output_dabp_sbr = False
if self.ConfigSectionMap('output')['dabp_ps'].upper() == 'TRUE':
self.output_dabp_ps = True
else:
self.output_ps = False
if self.ConfigSectionMap('output')['afterburner'].upper() == 'TRUE':
self.output_afterburner = True
self.output_dabp_ps = False
if self.ConfigSectionMap('output')['dabp_afterburner'].upper() == 'TRUE':
self.output_dabp_afterburner = True
else:
self.output_afterburner = False
self.output_dabp_afterburner = False

#dab
self.output_dab_samplerate = self.ConfigSectionMap('output')['dab_samplerate']
self.output_dab_bitrate = self.ConfigSectionMap('output')['dab_bitrate']

# MOT configuration
if self.ConfigSectionMap('mot')['enable'].upper() == 'TRUE':
Expand Down
96 changes: 58 additions & 38 deletions encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,45 +107,65 @@ def getStatus(self):

def run_encoder(self):
self.autorestart = True
executable = self.config.global_encoder_path
args = executable

if self.config.source_type == 'alsa':
args += ' -d %s' % (self.config.source_device)
if self.config.source_type == 'stream':
args += ' --vlc-uri=%s' % (self.config.source_url)
logger.warn('%s' % args)
if self.config.source_driftcomp == True:
args += ' -D'
logger.warn('%s' % args)
if self.config.output_type == 'dabp':
executable = self.config.global_encoder_dabp_path
args = executable

if self.config.source_type == 'alsa':
args += ' -d %s' % (self.config.source_device)
if self.config.source_type == 'stream':
args += ' --vlc-uri=%s' % (self.config.source_url)
if self.config.source_driftcomp == True:
args += ' -D'

args += ' -b %s -r %s' % (self.config.output_dabp_bitrate, self.config.output_dabp_samplerate)
if self.config.output_dabp_sbr == True:
args += ' --sbr'
if self.config.output_dabp_ps == True:
args += ' --ps'
if self.config.output_dabp_afterburner == False:
args += ' --no-afterburner'

if self.config.mot == True:
if not os.path.exists(self.config.mot_pad_fifo_file) or not stat.S_ISFIFO(os.stat(self.config.mot_pad_fifo_file).st_mode):
logger.warn('dabplus-enc Pad file %s not exist or not a fifo file. Ignoring PAD parameters.' % (self.config.mot_pad_fifo_file))
else:
args += ' --pad=%s' % (self.config.mot_pad)
args += ' --pad-fifo=%s' % (self.config.mot_pad_fifo_file)

args += ' -f raw'
hosts = self.config.output_zmq_host.replace(' ','').split(',')
for host in hosts:
args += ' -o tcp://%s' % (host)

if self.config.output_zmq_key.strip() != '':
if os.access(os.path.dirname(self.config.global_zmq_tmp_file), os.W_OK):
f = open(self.config.global_zmq_tmp_file, 'w')
f.write(self.config.output_zmq_key)
f.close()
args += ' -k %s' % (self.config.global_zmq_tmp_file)
else:
logger.critical('dabplus-enc ZMQ secret key file not writeable. Try to ignoring secret-key parameters.')


args += ' -b %s -r %s' % (self.config.output_bitrate, self.config.output_samplerate)
if self.config.output_sbr == True:
args += ' --sbr'
if self.config.output_ps == True:
args += ' --ps'
if self.config.output_afterburner == False:
args += ' --no-afterburner'
if self.config.output_type == 'dab':
executable = self.config.global_encoder_dab_path
args = executable

if self.config.source_type == 'stream':
args += ' -s %s' % (self.config.output_dab_samplerate)
args += ' -V %s' % (self.config.source_url)
args += ' -b %s' % (self.config.output_dab_bitrate)

hosts = self.config.output_zmq_host.replace(' ','').split(',')
for host in hosts:
args += ' tcp://%s;' % (host)
# Remove the last fucking ;
args = args[:-1]
logger.warn('%s' % args)

if self.config.mot == True:
if not os.path.exists(self.config.mot_pad_fifo_file) or not stat.S_ISFIFO(os.stat(self.config.mot_pad_fifo_file).st_mode):
logger.warn('dabplus-enc Pad file %s not exist or not a fifo file. Ignoring PAD parameters.' % (self.config.mot_pad_fifo_file))
else:
args += ' --pad=%s' % (self.config.mot_pad)
args += ' --pad-fifo=%s' % (self.config.mot_pad_fifo_file)

args += ' -f raw'
hosts = self.config.output_zmq_host.replace(' ','').split(',')
for host in hosts:
args += ' -o tcp://%s' % (host)
if self.config.output_zmq_key.strip() != '':
if os.access(os.path.dirname(self.config.global_zmq_tmp_file), os.W_OK):
f = open(self.config.global_zmq_tmp_file, 'w')
f.write(self.config.output_zmq_key)
f.close()
args += ' -k %s' % (self.config.global_zmq_tmp_file)
else:
logger.critical('dabplus-enc ZMQ secret key file not writeable. Try to ignoring secret-key parameters.')
args = args.split()
encoderProcessProtocol = MyEncoderProcessProtocol(self)
reactor.spawnProcess(encoderProcessProtocol, executable, args, {})
Expand Down Expand Up @@ -218,12 +238,12 @@ def __init__(self, manager):
self.manager = manager

def connectionMade(self):
logger.info('dabplus-enc connection made!')
logger.info('encoder connection made!')
self.manager.encoderProcess = self

def processEnded(self, reason):
logger.info('dabplus-enc process ended, status %s' % (reason.value.exitCode))
logger.debug('dabplus-enc autorestart value : %s' % (self.manager.autorestart))
logger.info('encoder process ended, status %s' % (reason.value.exitCode))
logger.debug('encoder autorestart value : %s' % (self.manager.autorestart))
self.manager.encoderProcess = None
# Stop mot (restart itself)
self.manager.stop_mot(self.manager.autorestart)
Expand Down
58 changes: 45 additions & 13 deletions static/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,48 +146,73 @@ <h4 class="panel-title">
<div id="collapseOutput" class="panel-collapse collapse">
<div class="panel-body">

<h4>Audio encoding configuration</h4>
<div class="form-group">
<label class="control-label col-sm-2" for="output_bitrate">Bitrate:</label>
<label class="control-label col-sm-2" for="output_type">Output type:</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="output_bitrate" placeholder="Enter bitrate (ex: 96)" data-toggle="tooltip" data-placement="top" title="The bitrate value need to be the same on multiplex configuration. Change it according multiplex configuration.">
<select type="select" class="form-control" id="output_type">
<option value="dabp">DAB+</option>
<option value="dab">DAB</option>
</select>
</div>
<label class="control-label col-sm-2" for="output_samplerate">Samplerate:</label>
</div>
<hr />

<h4>DAB+ encoding configuration</h4>
<div class="form-group">
<label class="control-label col-sm-2" for="output_dabp_bitrate">Bitrate:</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="output_samplerate" placeholder="Enter samplerate (ex: 48000)">
<input type="text" class="form-control" id="output_dabp_bitrate" placeholder="Enter bitrate (ex: 96)" data-toggle="tooltip" data-placement="top" title="The bitrate value need to be the same on multiplex configuration. Change it according multiplex configuration.">
</div>
<label class="control-label col-sm-2" for="output_dabp_samplerate">Samplerate:</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="output_dabp_samplerate" placeholder="Enter samplerate (ex: 48000)">
</div>
</div>

<div class="form-group">
<label class="control-label col-sm-2" for="output_sbr">SBR:</label>
<label class="control-label col-sm-2" for="output_dabp_sbr">SBR:</label>
<div class="col-sm-3">
<select type="select" class="form-control" id="output_sbr" data-toggle="tooltip" data-placement="top" title="Enable SBR only on bitrate from 96 kbps.">
<select type="select" class="form-control" id="output_dabp_sbr" data-toggle="tooltip" data-placement="top" title="Enable SBR only on bitrate from 96 kbps.">
<option value="true">true</option>
<option value="false">false</option>
</select>
</div>


<label class="control-label col-sm-2" for="output_ps">PS:</label>
<label class="control-label col-sm-2" for="output_dabp_ps">PS:</label>
<div class="col-sm-3">
<select type="select" class="form-control" id="output_ps" data-toggle="tooltip" data-placement="top" title="Enable PS only on bitrate multiple of 8kbps and under 56 kbps.">
<select type="select" class="form-control" id="output_dabp_ps" data-toggle="tooltip" data-placement="top" title="Enable PS only on bitrate multiple of 8kbps and under 56 kbps.">
<option value="true">true</option>
<option value="false">false</option>
</select>
</div>
</div>

<div class="form-group">
<label class="control-label col-sm-2" for="output_afterburner">After Burner:</label>
<label class="control-label col-sm-2" for="output_dabp_afterburner">After Burner:</label>
<div class="col-sm-3">
<select type="select" class="form-control" id="output_afterburner">
<select type="select" class="form-control" id="output_dabp_afterburner">
<option value="true">true</option>
<option value="false">false</option>
</select>
</div>
</div>
<hr />

<h4>DAB encoding configuration</h4>
<div class="form-group">
<label class="control-label col-sm-2" for="output_dab_bitrate">Bitrate:</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="output_dab_bitrate" placeholder="Enter bitrate (ex: 96)" data-toggle="tooltip" data-placement="top" title="The bitrate value need to be the same on multiplex configuration. Change it according multiplex configuration.">
</div>
<label class="control-label col-sm-2" for="output_dab_samplerate">Samplerate:</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="output_dab_samplerate" placeholder="Enter samplerate (ex: 48000)">
</div>
</div>

<hr />


<h4>ZMQ configuration</h4>
<div class="form-group">
Expand Down Expand Up @@ -298,9 +323,16 @@ <h4 class="panel-title">
<div class="panel-body">

<div class="form-group">
<label class="control-label col-sm-2" for="global_encoder_path">dabplus-enc path:</label>
<label class="control-label col-sm-2" for="global_encoder_dabp_path">dabplus-enc path:</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="global_encoder_dabp_path" placeholder="Enter dabplus-enc full path">
</div>
</div>

<div class="form-group">
<label class="control-label col-sm-2" for="global_encoder_dab_path">toolame-dab path:</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="global_encoder_path" placeholder="Enter dabplus-enc full path">
<input type="text" class="form-control" id="global_encoder_dab_path" placeholder="Enter toolame-dab full path">
</div>
</div>

Expand Down
32 changes: 21 additions & 11 deletions static/js/odr-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,40 @@ function requestConfiguration(callback) {

function setConfiguration(callback) {
var param = {
"global" : { "encoder_path": $('#global_encoder_path').val(),
"global" : {
"encoder_dabp_path": $('#global_encoder_dabp_path').val(),
"encoder_dab_path": $('#global_encoder_dab_path').val(),
"mot_path": $('#global_mot_path').val(),
"zmq_tmp_file": $('#global_zmq_tmp_file').val(),
},
"telnet" : { "bind_ip": $('#telnet_bind_ip').val(),
"telnet" : {
"bind_ip": $('#telnet_bind_ip').val(),
"port": $('#telnet_port').val(),
},
"rpc" : { "bind_ip": $('#rpc_bind_ip').val(),
"rpc" : {
"bind_ip": $('#rpc_bind_ip').val(),
"port": $('#rpc_port').val(),
},
"source" : { "type": $('#source_type').val(),
"source" : {
"type": $('#source_type').val(),
"url": $('#source_url').val(),
"device": $('#source_device').val(),
"driftcomp": $('#source_driftcomp').val(),
},
"output" : { "zmq_host": $('#output_zmq_host').val(),
"output" : {
"type": $('#output_type').val(),
"zmq_host": $('#output_zmq_host').val(),
"zmq_key": $('#output_zmq_key').val(),
"bitrate": $('#output_bitrate').val(),
"samplerate": $('#output_samplerate').val(),
"sbr": $('#output_sbr').val(),
"ps": $('#output_ps').val(),
"afterburner": $('#output_afterburner').val(),
"dabp_bitrate": $('#output_dabp_bitrate').val(),
"dabp_samplerate": $('#output_dabp_samplerate').val(),
"dabp_sbr": $('#output_sbr').val(),
"dabp_ps": $('#output_ps').val(),
"dabp_afterburner": $('#output_afterburner').val(),
"dab_bitrate": $('#output_dab_bitrate').val(),
"dab_samplerate": $('#output_dab_samplerate').val(),
},
"mot" : { "enable": $('#mot_enable').val(),
"mot" : {
"enable": $('#mot_enable').val(),
"pad": $('#mot_pad').val(),
"pad_fifo_file": $('#mot_pad_fifo_file').val(),
"dls_fifo_file": $('#mot_dls_fifo_file').val(),
Expand Down

0 comments on commit 83d9406

Please sign in to comment.