#!/usr/bin/env python # # Sends a dabp file in the format output by ODR-AudioEnc over ZMQ. # Requires at least python 3.3 because we use time.monotonic() # # LICENCE: MIT, see end of file import sys import zmq import argparse import struct import time # First parse the arguments given on command line parser = argparse.ArgumentParser(description='Send .dabp over ZMQ') parser.add_argument('--input', help='.dabp file to send', required=True) parser.add_argument('--bitrate', help='The bitrate of the source file', required=True) parser.add_argument('--to', default='tcp://127.0.0.1:9001', help='Default zmq endpoint to send to (default: tcp://127.0.0.1:9001', required=False) args = parser.parse_args() # The ZMQ frames from the audio encoder are expected # to have the following format, in pseudo C struct, no alignment, # little-endian. See ODR-DabMux' src/input/Zmq.h for reference. # # uint16_t version; // we support version=1 now # uint16_t encoder; // see ZMQ_ENCODER_XYZ # # /* length of the 'data' field */ # uint32_t datasize; # # /* Audio level, peak, linear PCM */ # int16_t audiolevel_left; # int16_t audiolevel_right; # # /* Data follows the header */ # uint8_t data[datasize]; # Using the python struct module, we can represent the above C struct as follows: frame_header = " 0: time.sleep(waiting / 1000) # Keep track of our "absolute frame send time" frame_send_time_ms += 120 # The MIT License (MIT) # # Copyright (c) 2017 Matthias P. Braendli # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE.