def main(arguments):
    gstreamer = ('gst-launch-1.0.exe' if ('win' in sys.platform) else 'gst-launch-1.0')
    hostname = arguments.hostname[0]
    encoders = {'h264': (b'GstRtpH264Pay', 'h264parse', 'rtph264pay'), 'vp8': (b'GstRtpVP8Pay', 'vp8enc', 'rtpvp8pay'), 'openh264': (b'GstRtpH264Pay', 'openh264enc', 'rtph264pay')}
    rtppay = encoders[arguments.codec][0]
    port = 5600
    arglist = [gstreamer, '-v', 'rpicamsrc', ('bitrate=%d' % 1500000), '!', 'video/x-raw, width=1280, height=720, framerate=30/1', '!', 'omxh264enc', '!', encoders[arguments.codec][1], '!', encoders[arguments.codec][2], '!', 'multiudpsink', 'clients=']
    for hostname in arguments.hostname:
        arglist[14] += ((hostname + ':5600') + ',')
    print(arglist)
    if arguments.debug:
        print('Calling gstreamer:\n', ' '.join(arglist))
    process = Popen(arglist, stdout=PIPE)

    def signal_handler(signal, frame):
        process.kill()
        print('Terminating child process')
    signal.signal(signal.SIGINT, signal_handler)
    patternGenerated = False
    try:
        p = re.compile((b'/GstPipeline:pipeline\\d+/%b:\\w+\\d+.GstPad:src: caps = (.+)' % rtppay))
        for line in process.stdout:
            pattern = p.search(line)
            if (pattern and (not patternGenerated)):
                parameters = re.findall(b'(([\\w-]+)=(?:\\(\\w+\\))?(?:(\\w+)|(?:"([^"]+)")))', pattern.groups()[0])
                parammap = defaultdict(str)
                for (_, param, value, value2) in parameters:
                    parammap[param.decode('ascii')] = (value.decode('ascii') if value else value2.decode('ascii'))
                    parammap['port'] = port
                if (len(parammap) > 0):
                    patternGenerated = True
                    if arguments.sdp:
                        createsdp(hostname, [parammap])
                    for (param, value) in parammap.items():
                        print(('%s = %s' % (param, value)))
    finally:
        process.wait()
def main(arguments):
    gstreamer = ('gst-launch-1.0.exe' if ('win' in sys.platform) else 'gst-launch-1.0')
    hostname = arguments.hostname[0]
    encoders = {'h264': (b'GstRtpH264Pay', 'h264parse', 'rtph264pay'), 'vp8': (b'GstRtpVP8Pay', 'vp8enc', 'rtpvp8pay'), 'openh264': (b'GstRtpH264Pay', 'openh264enc', 'rtph264pay')}
    rtppay = encoders[arguments.codec][0]
    port = 5600
    arglist = [gstreamer, '-v', 'rpicamsrc', ('bitrate=%d' % 1500000), '!', 'video/x-raw, width=1280, height=720, framerate=30/1', '!', 'omxh264enc', '!', encoders[arguments.codec][1], '!', encoders[arguments.codec][2], '!', 'multiudpsink', 'clients=']
    for hostname in arguments.hostname:
        arglist[14] += ((hostname + ':5600') + ',')
    print(arglist)
    if arguments.debug:
        print('Calling gstreamer:\n', ' '.join(arglist))
    process = Popen(arglist, stdout=PIPE)

    def signal_handler(signal, frame):
        process.kill()
        print('Terminating child process')
    signal.signal(signal.SIGINT, signal_handler)
    patternGenerated = False
    try:
        p = re.compile((b'/GstPipeline:pipeline\\d+/%b:\\w+\\d+.GstPad:src: caps = (.+)' % rtppay))
        for line in process.stdout:
            pattern = p.search(line)
            if (pattern and (not patternGenerated)):
                parameters = re.findall(b'(([\\w-]+)=(?:\\(\\w+\\))?(?:(\\w+)|(?:"([^"]+)")))', pattern.groups()[0])
                parammap = defaultdict(str)
                for (_, param, value, value2) in parameters:
                    parammap[param.decode('ascii')] = (value.decode('ascii') if value else value2.decode('ascii'))
                    parammap['port'] = port
                if (len(parammap) > 0):
                    patternGenerated = True
                    if arguments.sdp:
                        createsdp(hostname, [parammap])
                    for (param, value) in parammap.items():
                        print(('%s = %s' % (param, value)))
    finally:
        process.wait()