Example #1
0
def getMediaStreams():
  audio, video = SDP.media(media='audio'), SDP.media(media='video')			
  audio.fmt = [format(pt=8, name='PCMA', rate=8000)]
  video.fmt = [format(pt=34, name='H263', rate=90000)]
  #video.fmt = [format(pt=122, name='H264', rate=90000)]
  #video.a = ['fmtp:122 profile-level-id=64E00C;max-br=384']
  return (audio, video)
Example #2
0
def createAnswer(streams, offer, **kwargs):
    '''Create an answer SDP for the remote offer SDP using local (streams) list of 
    media Stream objects.'''
    s = SDP()
    s.v = '0'
    for a in "iep": 
        if a in kwargs: s[a] = kwargs[a]
    s.o = SDP.originator()
    s.s = '-'
    s.t = offer.t
    s.m = []
    streams = list(streams) # so that original list is not modified
    for your in offer.m: # for each m= line in offer
        my, i   = None, 0      # answered stream
        while i < len(streams):
            if streams[i].media == your.media: # match the first stream in streams
                my = streams[i].dup() # found, hence
                del streams[i]  #  remove from streams so that we don't match again for another m=
                if your.direction == 'recvonly' :
                    if not my.direction == 'recvonly' :
                        my.direction = 'sendonly'
                    else :
                        my.direction = 'inactive'
                if your.direction == 'sendonly' :
                    if not my.direction == 'sendonly' :
                        my.direction = 'recvonly'
                    else :
                        my.direction = 'inactive'
                found = []
                for fy in your.fmt:  # all offered formats, find the matching pairs
                    for fm in my.fmt:# the preference order is from offer, hence do for fy, then for fm.
                        try: fmpt, fypt = int(fm.pt), int(fy.pt) # try using numeric payload type
                        except: fmpt = fypt = -1
                        if 0<=fmpt<32 and 0<=fypt<32 and fmpt == fypt \
                        or fmpt<0 and fypt<0 and fm.pt == fy.pt \
                        or str(fm.name).lower() == str(fy.name).lower() and fm.rate == fy.rate and fm.count == fy.count: # we don't match the params
                            found.append((fy, fm)); break
                if found: # we found some matching formats, put them in 
                    my.fmt = map(lambda x: x[0], found) # use remote's fy including fy.pt
                else:
                    my.fmt = [format(pt=0)] # no match in formats, but matched media, must put a format with payload type 0
                    my.port = 0             #   and reset the port.
                break
            else: 
                i = i + 1
        if not my: # did not match the stream, must put a stream with port = 0
            my = SDP.media(str(your))
            my.port = 0
        s.m.append(my) # append it to our media

    valid = False
    for my in s.m: # check if any valid matching stream is present with valid port
        if my.port != 0:
            valid = True
            break
        
    return valid and s or None  # if no valid matching stream found, return None
Example #3
0
def createAnswer(streams, offer, **kwargs):
    '''Create an answer SDP for the remote offer SDP using local (streams) list of 
    media Stream objects.'''
    s = SDP()
    s.v = '0'
    for a in "iep":
        if a in kwargs: s[a] = kwargs[a]
    s.o = SDP.originator()
    s.s = '-'
    s.t = offer.t
    s.m = []
    streams = list(streams)  # so that original stream is not modified
    for your in offer.m:  # for each m= line in offer
        my, i = None, 0  # answered stream
        while i < len(streams):
            if streams[
                    i].media == your.media:  # match the first stream in streams
                my = streams[i].dup()  # found, hence
                del streams[
                    i]  #  remove from streams so that we don't match again for another m=
                found = []
                for fy in your.fmt:  # all offered formats, find the matching pairs
                    for fm in my.fmt:  # the preference order is from offer, hence do for fy, then for fm.
                        try:
                            fmpt, fypt = int(fm.pt), int(
                                fy.pt)  # try using numeric payload type
                        except:
                            fmpt = fypt = -1
                        if 0<=fmpt<32 and 0<=fypt<32 and fmpt == fypt \
                        or fmpt<0 and fypt<0 and fm.pt == fy.pt \
                        or str(fm.name).lower() == str(fy.name).lower() and fm.rate == fy.rate and fm.count == fy.count: # we don't match the params
                            found.append((fy, fm))
                            break
                if found:  # we found some matching formats, put them in
                    my.fmt = map(lambda x: x[0],
                                 found)  # use remote's fy including fy.pt
                else:
                    my.fmt = [
                        format(pt=0)
                    ]  # no match in formats, but matched media, must put a format with payload type 0
                    my.port = 0  #   and reset the port.
                break
            else:
                i = i + 1
        if not my:  # did not match the stream, must put a stream with port = 0
            my = SDP.media(str(your))
            my.port = 0
        s.m.append(my)  # append it to our media

    valid = False
    for my in s.m:  # check if any valid matching stream is present with valid port
        if my.port != 0:
            valid = True
            break

    return valid and s or None  # if no valid matching stream found, return None