/* HSC CHANGES START */ public static SessionDescriptor sdpAttirbuteSelection(SessionDescriptor sdp, String a_name) { Vector<MediaDescriptor> new_media = new Vector<MediaDescriptor>(); for (Enumeration<MediaDescriptor> e = sdp.getMediaDescriptors().elements(); e.hasMoreElements(); ) { /* HSC CHANGES END */ MediaDescriptor md = e.nextElement(); AttributeField attr = md.getAttribute(a_name); if (attr != null) { new_media.addElement(new MediaDescriptor(md.getMedia(), md.getConnection(), attr)); } } SessionDescriptor new_sdp = new SessionDescriptor(sdp); new_sdp.removeMediaDescriptors(); new_sdp.addMediaDescriptors(new_media); return new_sdp; }
/* HSC CHANGES START */ public static SessionDescriptor sdpMediaProduct( SessionDescriptor sdp, Vector<MediaDescriptor> m_descs) { Vector<MediaDescriptor> new_media = new Vector<MediaDescriptor>(); if (m_descs != null) { for (Enumeration<MediaDescriptor> e = m_descs.elements(); e.hasMoreElements(); ) { MediaDescriptor spec_md = e.nextElement(); // System.out.print("DEBUG: SDP: sdp_select: // "+spec_md.toString()); MediaDescriptor prev_md = sdp.getMediaDescriptor(spec_md.getMedia().getMedia()); // System.out.print("DEBUG: SDP: sdp_origin: // "+prev_md.toString()); if (prev_md != null) { Vector<AttributeField> spec_attributes = spec_md.getAttributes(); Vector<AttributeField> prev_attributes = prev_md.getAttributes(); if (spec_attributes.size() == 0 || prev_attributes.size() == 0) { new_media.addElement(prev_md); } else { Vector<AttributeField> new_attributes = new Vector<AttributeField>(); for (Enumeration<AttributeField> i = spec_attributes.elements(); i.hasMoreElements(); ) { AttributeField spec_attr = i.nextElement(); String spec_name = spec_attr.getAttributeName(); String spec_value = spec_attr.getAttributeValue(); for (Enumeration<AttributeField> k = prev_attributes.elements(); k.hasMoreElements(); ) { AttributeField prev_attr = k.nextElement(); String prev_name = prev_attr.getAttributeName(); String prev_value = prev_attr.getAttributeValue(); if (prev_name.equals(spec_name) && prev_value.equalsIgnoreCase(spec_value)) { new_attributes.addElement(prev_attr); break; } } } if (new_attributes.size() > 0) new_media.addElement( new MediaDescriptor(prev_md.getMedia(), prev_md.getConnection(), new_attributes)); } } } } SessionDescriptor new_sdp = new SessionDescriptor(sdp); new_sdp.removeMediaDescriptors(); new_sdp.addMediaDescriptors(new_media); return new_sdp; }
public static Map getCodec(SessionDescriptor offers) { Logger logger = Logger.getLogger(Codecs.class.getCanonicalName()); if (offers == null) { logger.warning("offers == null"); return null; } MediaDescriptor mAudio = offers.getMediaDescriptor("audio"); if (mAudio == null) { logger.warning("offer doesn't contain m=audio"); logger.info(offers.toString()); return null; } MediaField m = mAudio.getMedia(); if (m == null) { logger.warning("media field invalid"); return null; } String proto = m.getTransport(); // see http://tools.ietf.org/html/rfc4566#page-22, paragraph 5.14, <fmt> description if (proto.equals("RTP/AVP") || proto.equals("RTP/SAVP") || proto.equals("RTP/SAVPF")) { Vector<String> formats = m.getFormatList(); Vector<String> names = new Vector<String>(formats.size()); Vector<Integer> numbers = new Vector<Integer>(formats.size()); Vector<Codec> codecmap = new Vector<Codec>(formats.size()); // add all avail formats with empty names for (String fmt : formats) { try { int number = Integer.parseInt(fmt); numbers.add(number); names.add(""); codecmap.add(null); } catch (NumberFormatException e) { // continue ... remote sent bogus rtp setting } } ; logger.info("got " + numbers.size() + " format numbers"); // if we have attrs for format -> set name Vector<AttributeField> attrs = offers.getMediaDescriptor("audio").getAttributes("rtpmap"); logger.info("got " + attrs.size() + " rtpmap attributes"); for (AttributeField a : attrs) { String s = a.getValue(); // skip over "rtpmap:" s = s.substring(7, s.indexOf("/")); int i = s.indexOf(" "); try { String name = s.substring(i + 1); int number = Integer.parseInt(s.substring(0, i)); int index = numbers.indexOf(number); logger.info("format offered " + index + ", " + name); if (index >= 0) names.set(index, name.toLowerCase()); } catch (NumberFormatException e) { // continue ... remote sent bogus rtp setting } } Codec codec = null; int index = formats.size() + 1; logger.info("number of local codecs = " + codecs.size()); for (Codec c : codecs) { logger.info("checking " + c.userName() + ", valid = " + c.isValid()); if (!c.isValid()) continue; // search current codec in offers by name int i = names.indexOf(c.userName().toLowerCase()); if (i >= 0) { logger.info("adding codec " + c.userName() + " by name"); codecmap.set(i, c); if ((codec == null) || (i < index)) { codec = c; index = i; continue; } } // search current codec in offers by number i = numbers.indexOf(c.number()); if (i >= 0) { if (names.elementAt(i).equals("")) { logger.info("adding codec " + c.userName() + " by number"); codecmap.set(i, c); if ((codec == null) || (i < index)) { // fmt number has no attr with name codec = c; index = i; continue; } } } } if (codec != null) return new Map(numbers.elementAt(index), codec, numbers, codecmap); else { // no codec found ... we can't talk logger.warning("didn't find any recognised codec"); return null; } } else { /*formats of other protocols not supported yet*/ logger.warning("can't handle protocol: " + proto); return null; } }
/** * Accepts an incoming call. Callback function called when arriving a new INVITE method (incoming * call) */ public void onCallIncoming( Call call, NameAddress callee, NameAddress caller, String sdp, Message invite) { // printLog("INCOMING"); call.ring(); String local_session; if (sdp != null && sdp.length() > 0) { SessionDescriptor remote_sdp = new SessionDescriptor(sdp); SessionDescriptor local_sdp = new SessionDescriptor(call.getLocalSessionDescriptor()); SessionDescriptor new_sdp = new SessionDescriptor( remote_sdp.getOrigin(), remote_sdp.getSessionName(), local_sdp.getConnection(), local_sdp.getTime()); new_sdp.addMediaDescriptors(local_sdp.getMediaDescriptors()); new_sdp = SdpTools.sdpMediaProduct(new_sdp, remote_sdp.getMediaDescriptors()); new_sdp = SdpTools.sdpAttirbuteSelection(new_sdp, "rtpmap"); local_session = new_sdp.toString(); } else local_session = call.getLocalSessionDescriptor(); // accept immediatly call.accept(local_session); }