def createsdp(hostname, streams):
    params2ignore = set(['encoding-name', 'timestamp-offset', 'payload', 'clock-rate', 'media', 'port'])
    sdp = ['v=0']
    sdp.append(('o=- %d %d IN IP4 %s' % (random.randrange(4294967295), 2, hostname)))
    sdp.append('t=0 0')
    sdp.append('s=GST2SDP')
    streamnumber = 1
    for stream in streams:
        sdp.append(('m=%s %s RTP/AVP %s' % (stream['media'], stream['port'], stream['payload'])))
        sdp.append(('c=IN IP4 %s' % hostname))
        sdp.append(('a=rtpmap:%s %s/%s' % (stream['payload'], stream['encoding-name'], stream['clock-rate'])))
        fmtp = [('a=fmtp:%s' % stream['payload'])]
        for (param, value) in stream.items():
            if ((param[0] == 'a') and (param[1] == '-')):
                aparam = ('%s:%s' % (param.replace('a-', 'a='), value))
                sdp.append(aparam)
            elif (param not in params2ignore):
                fmtp.append((' %s=%s;' % (param, value)))
        fmtp = ''.join(fmtp)
        sdp.append(fmtp)
        sdp.append(('a=control:track%d' % streamnumber))
        streamnumber += 1
    with open('session.sdp', 'w') as f:
        f.write('\r\n'.join(sdp))
def createsdp(hostname, streams):
    params2ignore = set(['encoding-name', 'timestamp-offset', 'payload', 'clock-rate', 'media', 'port'])
    sdp = ['v=0']
    sdp.append(('o=- %d %d IN IP4 %s' % (random.randrange(4294967295), 2, hostname)))
    sdp.append('t=0 0')
    sdp.append('s=GST2SDP')
    streamnumber = 1
    for stream in streams:
        sdp.append(('m=%s %s RTP/AVP %s' % (stream['media'], stream['port'], stream['payload'])))
        sdp.append(('c=IN IP4 %s' % hostname))
        sdp.append(('a=rtpmap:%s %s/%s' % (stream['payload'], stream['encoding-name'], stream['clock-rate'])))
        fmtp = [('a=fmtp:%s' % stream['payload'])]
        for (param, value) in stream.items():
            if ((param[0] == 'a') and (param[1] == '-')):
                aparam = ('%s:%s' % (param.replace('a-', 'a='), value))
                sdp.append(aparam)
            elif (param not in params2ignore):
                fmtp.append((' %s=%s;' % (param, value)))
        fmtp = .join(fmtp)
        sdp.append(fmtp)
        sdp.append(('a=control:track%d' % streamnumber))
        streamnumber += 1
    with open('session.sdp', 'w') as f:
        f.write('\r\n'.join(sdp))