MediaParser { public static void excludeCodec(MediaDescription md, String[] excludedCodecs) throws SdpParseException { Media media = md.getMedia(); Set<String> excludeFormats = new HashSet<String>(); for (String excludeCodec : excludedCodecs) { for (String standardPayload : payloadVsFormat.keySet()) { String standardCodec = payloadVsFormat.get(standardPayload); if (excludeCodec.equalsIgnoreCase(standardCodec)) { excludeFormats.add(standardPayload); break; } } } Iterator attributes = md.getAttributes(false).iterator(); if (attributes != null) { while (attributes.hasNext()) { Attribute a = (Attribute) attributes.next(); for (String excludeCodec : excludedCodecs) { if (RTPMAP.equals(a.getName())) { String tokens[] = a.getValue().split(" "); String[] tokens1 = tokens[1].split("/"); String encodingName = tokens1[0]; if (encodingName.equals(excludeCodec)) { excludeFormats.add(tokens[0]); attributes.remove(); } } } } attributes = md.getAttributes(false).iterator(); while (attributes.hasNext()) { Attribute a = (Attribute) attributes.next(); for (String f : excludeFormats) { if (FMTP.equals(a.getName())) { String tokens[] = a.getValue().split(" "); if (tokens[0].equals(f)) { attributes.remove(); } } } } } Vector formats = media.getMediaFormats(false); formats.removeAll(excludeFormats); }  static void excludeCodec(MediaDescription md, String[] excludedCodecs); static void RequiredCodec(MediaDescription md, String[] excludedCodecs); final static String AUDIO; final static String VIDEO; final static String RTPMAP; final static String FMTP; static Map<String, String> payloadVsFormat; }
@Test public void testExcludes() throws Exception { System.out.println(richOffer); System.out.println("--------------"); String[] excludes = new String[] { "G723","G729","EVRC0","AMR-WB", "telephone-event","PCMA","PCMU" }; SessionDescription sessiondescription = sdpFactory.createSessionDescription(richOffer); Vector v = sessiondescription.getMediaDescriptions(false); Iterator itr = v.iterator(); while (itr.hasNext()) { MediaDescription m = (MediaDescription) itr.next(); MediaParser.excludeCodec(m, excludes); } System.out.println(sessiondescription); System.out.println(AVProfile.G729.encode()); }