From 19ecac94bffe24b23b0ff5a86ac86dd6710eae3d Mon Sep 17 00:00:00 2001 From: James Harrison Date: Wed, 16 Dec 2015 01:16:36 +0000 Subject: [PATCH] Fixes some major issue with LinkConfig option loading (namely that some vars that should be bools/ints were being returned as strings and not typecast properly before usage), fixed a documentation line, tweaked boolean flags on the CLI (mostly backwards compatible, but it all works properly now) --- bin/openob | 15 +++++++++------ doc/source/tutorial.rst | 4 ++-- openob/link_config.py | 7 ++++++- openob/rtp/tx.py | 4 +++- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/bin/openob b/bin/openob index 4ff2dca..ac61a3a 100755 --- a/bin/openob +++ b/bin/openob @@ -30,16 +30,19 @@ parser_tx_jack.add_argument('-aj', '--jack_auto', action='store_false', help="Di parser_tx.add_argument('-r', '--samplerate', type=int, default=0, help="Set the sample rate to request from the input (Hz)") parser_tx.add_argument('-e', '--encoding', type=str, choices=['pcm', 'opus'], default='opus', help="The audio encoding type for this link; PCM for linear audio (16-bit), or Opus for encoded audio") parser_tx.add_argument('-p', '--port', type=int, default=3000, help="The base port to use for audio transport. This port must be accessible on the receiving host") -parser_tx.add_argument('-m', '--multicast', type=bool, default=False, help="Start this transmitter in multicast mode, enabling multiple clients to connect at once using the address specified in reciever_host", choices=[True, False]) +parser_tx.add_argument('-m', '--multicast', action='store_true', dest='multicast', help="Start this transmitter in multicast mode, enabling multiple clients to connect at once using the address specified in reciever_host") +parser_tx.add_argument('--no-multicast', action='store_false', dest='multicast', help="Start this transmitter in unicast mode (default)") parser_tx.add_argument('-j', '--jitter_buffer', type=int, default=40, help="The size of the jitter buffer in milliseconds. Affects latency; may be reduced to 5-10ms on fast reliable networks, or increased for poor networks like 3G") parser_tx_opus = parser_tx.add_argument_group('opus', 'Opus encoder options') -parser_tx_opus.add_argument('-b', '--bitrate', type=int, default=96, help="Bitrate if using CELT/Opus (in kbit/s)", choices=[16, 24, 32, 48, 64, 96, 128, 192, 256, 384]) +parser_tx_opus.add_argument('-b', '--bitrate', type=int, default=128, help="Bitrate if using CELT/Opus (in kbit/s)", choices=[16, 24, 32, 48, 64, 96, 128, 192, 256, 384]) parser_tx_opus.add_argument('-l', '--loss', type=int, default=0, help="Expected packet loss percentage for Opus, between 0 and 100", choices=range(0,100), metavar='LOSS') -parser_tx_opus.add_argument('--dtx', type=bool, default=False, help="Enable Opus Discontinuous Transmission support", choices=[True, False]) -parser_tx_opus.add_argument('--fec', type=bool, default=True, help="Enable Opus Inband Forward Error Correction support", choices=[True, False]) -parser_tx_opus.add_argument('--complexity', type=int, default=7, help="Opus Computational Complexity, between 0 and 10 - reduce on CPU-constrained devices", choices=range(0,10)) +parser_tx_opus.add_argument('--dtx', action='store_true', dest='dtx', help="Enable Opus Discontinuous Transmission support") +parser_tx_opus.add_argument('--no-dtx', action='store_false', dest='dtx', help="Disable Opus Discontinuous Transmission support (default)") +parser_tx_opus.add_argument('--fec', action='store_true', dest='fec', help="Enable Opus Inband Forward Error Correction support (default)") +parser_tx_opus.add_argument('--no-fec', action='store_false', dest='fec', help="Disable Opus Inband Forward Error Correction support") +parser_tx_opus.add_argument('--complexity', type=int, default=9, help="Opus Computational Complexity, between 0 and 10 - reduce on CPU-constrained devices", choices=range(0,10)) parser_tx_opus.add_argument('--framesize', type=int, default=20, help="Opus frame size (ms)", choices=[2, 5, 10, 20, 40, 60]) -parser_tx.set_defaults(mode='tx') +parser_tx.set_defaults(mode='tx', fec=True, dtx=False, multicast=False) parser_rx = subparsers.add_parser('rx', formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser_rx.add_argument('-a', '--audio_output', type=str, choices=['auto', 'alsa', 'jack'], default='auto', help="The audio output type for this end of the link") diff --git a/doc/source/tutorial.rst b/doc/source/tutorial.rst index d568358..0d28175 100755 --- a/doc/source/tutorial.rst +++ b/doc/source/tutorial.rst @@ -21,7 +21,7 @@ On Debian you can install the prerequisites with the following command: .. code-block:: bash - sudo apt-get install python-gst0.10 python-setuptools gstreamer0.10-plugins-base gstreamer0.10-plugins-bad gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-ffmpeg gstreamer0.10-tools python-gobject python-gobject-2 gstreamer0.10-alsa python-argparse + sudo apt-get install python-gst0.10 python-setuptools gstreamer0.10-plugins-base gstreamer0.10-plugins-bad gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-tools python-gobject python-gobject-2 gstreamer0.10-alsa python-argparse python-redis This should also work on Ubuntu. Your GStreamer implementation must be recent enough to support Opus; this is supported in Ubuntu 13.04 and Debian Wheezy or newer. In order to ensure compatibility, it is recommended that both ends of the link use the same version of GStreamer, which is most easily achieved by running the same operating system version on each end and installing the distribution's packages as detailed above. @@ -88,4 +88,4 @@ To close the link, just :kbd:`Control-c` both ends to send a kill signal. Further Usage ------------- -OpenOB has many options on the command line. To find out about them, run ``openob -h``, or ``openob your-config-host node-name link-name tx -h`` to find out about tx/rx specific options. \ No newline at end of file +OpenOB has many options on the command line. To find out about them, run ``openob -h``, or ``openob your-config-host node-name link-name tx -h`` to find out about tx/rx specific options. diff --git a/openob/link_config.py b/openob/link_config.py index e71ac22..a392cf6 100755 --- a/openob/link_config.py +++ b/openob/link_config.py @@ -17,6 +17,8 @@ def __init__(self, link_name, redis_host): Set up a new LinkConfig instance - needs to know the link name and configuration host. """ + self.int_properties = ['port', 'jitter_buffer', 'opus_framesize', 'opus_complexity', 'bitrate', 'opus_loss_expectation'] + self.bool_properties = ['opus_dtx', 'opus_fec', 'multicast'] self.link_name = link_name self.redis_host = redis_host self.logger_factory = LoggerFactory() @@ -54,9 +56,12 @@ def get(self, key): """Get a value from the config store""" scoped_key = self.scoped_key(key) value = self.redis.get(scoped_key) + # Do some typecasting - if key == 'port' or key == 'jitter_buffer' or key == 'opus_framesize': + if key in self.int_properties: value = int(value) + if key in self.bool_properties: + value = (value == 'True') self.logger.debug("Fetched %s, got %s" % (scoped_key, value)) return value diff --git a/openob/rtp/tx.py b/openob/rtp/tx.py index c4bf899..d660ca4 100755 --- a/openob/rtp/tx.py +++ b/openob/rtp/tx.py @@ -39,7 +39,7 @@ def __init__(self, node_name, link_config, audio_interface): # Audio resampling and conversion self.audioresample = gst.element_factory_make("audioresample") self.audioconvert = gst.element_factory_make("audioconvert") - self.audioresample.set_property('quality', 6) # SRC + self.audioresample.set_property('quality', 9) # SRC # Encoding and payloading if self.link_config.encoding == 'opus': @@ -51,6 +51,7 @@ def __init__(self, node_name, link_config, audio_interface): self.encoder.set_property('inband-fec', self.link_config.opus_fec) self.encoder.set_property('packet-loss-percentage', int(self.link_config.opus_loss_expectation)) self.encoder.set_property('dtx', self.link_config.opus_dtx) + print(self.encoder.get_properties('bitrate', 'dtx', 'inband-fec')) self.payloader = gst.element_factory_make("rtpopuspay", "payloader") elif self.link_config.encoding == 'pcm': # we have no encoder for PCM operation @@ -64,6 +65,7 @@ def __init__(self, node_name, link_config, audio_interface): self.udpsink_rtpout.set_property('host', self.link_config.receiver_host) self.udpsink_rtpout.set_property('port', self.link_config.port) self.logger.info('Set receiver to %s:%i' % (self.link_config.receiver_host, self.link_config.port)) + if self.link_config.multicast: self.udpsink_rtpout.set_property('auto_multicast', True) self.logger.info('Multicast mode enabled')