private static String preferISAC(String sdpDescription) {
        String[] lines = sdpDescription.split("\r\n");
        int mLineIndex = -1;
        String isac16kRtpMap = null;
        Pattern isac16kPattern =
                Pattern.compile("^a=rtpmap:(\\d+) ISAC/16000[\r]?$");
        for (int i = 0;
             (i < lines.length) && (mLineIndex == -1 || isac16kRtpMap == null);
             ++i) {
            if (lines[i].startsWith("m=audio ")) {
                mLineIndex = i;
                continue;
            }
            Matcher isac16kMatcher = isac16kPattern.matcher(lines[i]);
            if (isac16kMatcher.matches()) {
                isac16kRtpMap = isac16kMatcher.group(1);
                //continue;
            }
        }
        if (mLineIndex == -1) {
            //Log.d(TAG, "No m=audio line, so can't prefer iSAC");
            return sdpDescription;
        }
        if (isac16kRtpMap == null) {
            //Log.d(TAG, "No ISAC/16000 line, so can't prefer iSAC");
            return sdpDescription;
        }
        String[] origMLineParts = lines[mLineIndex].split(" ");
        StringBuilder newMLine = new StringBuilder();
        int origPartIndex = 0;
        // Format is: m=<media> <port> <proto> <fmt> ...
        newMLine.append(origMLineParts[origPartIndex++]).append(" ");
        newMLine.append(origMLineParts[origPartIndex++]).append(" ");
        newMLine.append(origMLineParts[origPartIndex++]).append(" ");
        newMLine.append(isac16kRtpMap);
        for (; origPartIndex < origMLineParts.length; ++origPartIndex) {
            if (!origMLineParts[origPartIndex].equals(isac16kRtpMap)) {
                newMLine.append(" ").append(origMLineParts[origPartIndex]);
            }
        }
        lines[mLineIndex] = newMLine.toString();
        StringBuilder newSdpDescription = new StringBuilder();
        for (String line : lines) {
            newSdpDescription.append(line).append("\r\n");
        }
        return newSdpDescription.toString();
    }
private static String preferISAC ( String sdpDescription ) { String [ ] lines = sdpDescription . split ( "\r\n" ) ; int mLineIndex = - 1 ; String isac16kRtpMap = null ; Pattern isac16kPattern = Pattern . compile ( "^a=rtpmap:(\\d+) ISAC/16000[\r]?$" ) ; for ( int i = 0 ; ( i < lines . length ) && ( mLineIndex == - 1 || isac16kRtpMap == null ) ; ++ i ) { if ( lines [ i ] . startsWith ( "m=audio " ) ) { mLineIndex = i ; continue ; } Matcher isac16kMatcher = isac16kPattern . matcher ( lines [ i ] ) ; if ( isac16kMatcher . matches ( ) ) { isac16kRtpMap = isac16kMatcher . group ( 1 ) ; } } if ( mLineIndex == - 1 ) { return sdpDescription ; } if ( isac16kRtpMap == null ) { return sdpDescription ; } String [ ] origMLineParts = lines [ mLineIndex ] . split ( " " ) ; StringBuilder newMLine = new StringBuilder ( ) ; int origPartIndex = 0 ; newMLine . append ( origMLineParts [ origPartIndex ++ ] ) . append ( " " ) ; newMLine . append ( origMLineParts [ origPartIndex ++ ] ) . append ( " " ) ; newMLine . append ( origMLineParts [ origPartIndex ++ ] ) . append ( " " ) ; newMLine . append ( isac16kRtpMap ) ; for ( ; origPartIndex < origMLineParts . length ; ++ origPartIndex ) { if ( ! origMLineParts [ origPartIndex ] . equals ( isac16kRtpMap ) ) { newMLine . append ( " " ) . append ( origMLineParts [ origPartIndex ] ) ; } } lines [ mLineIndex ] = newMLine . toString ( ) ; StringBuilder newSdpDescription = new StringBuilder ( ) ; for ( String line : lines ) { newSdpDescription . append ( line ) . append ( "\r\n" ) ; } return newSdpDescription . toString ( ) ; }
Mangle SDP to prefer ISAC/16000 over any other audio codec.