FileDocCategorySizeDatePackage
AudioCodec.javaAPI DocAndroid 5.1 API4919Thu Mar 12 22:22:52 GMT 2015android.net.rtp

AudioCodec

public class AudioCodec extends Object
This class defines a collection of audio codecs to be used with {@link AudioStream}s. Their parameters are designed to be exchanged using Session Description Protocol (SDP). Most of the values listed here can be found in RFC 3551, while others are described in separated standards.

Few simple configurations are defined as public static instances for the convenience of direct uses. More complicated ones could be obtained using {@link #getCodec(int, String, String)}. For example, one can use the following snippet to create a mode-1-only AMR codec.

AudioCodec codec = AudioCodec.getCodec(100, "AMR/8000", "mode-set=1");
see
AudioStream

Fields Summary
public final int
type
The RTP payload type of the encoding.
public final String
rtpmap
The encoding parameters to be used in the corresponding SDP attribute.
public final String
fmtp
The format parameters to be used in the corresponding SDP attribute.
public static final AudioCodec
PCMU
G.711 u-law audio codec.
public static final AudioCodec
PCMA
G.711 a-law audio codec.
public static final AudioCodec
GSM
GSM Full-Rate audio codec, also known as GSM-FR, GSM 06.10, GSM, or simply FR.
public static final AudioCodec
GSM_EFR
GSM Enhanced Full-Rate audio codec, also known as GSM-EFR, GSM 06.60, or simply EFR.
public static final AudioCodec
AMR
Adaptive Multi-Rate narrowband audio codec, also known as AMR or AMR-NB. Currently CRC, robust sorting, and interleaving are not supported. See more details about these features in RFC 4867.
private static final AudioCodec[]
sCodecs
Constructors Summary
private AudioCodec(int type, String rtpmap, String fmtp)


           
        this.type = type;
        this.rtpmap = rtpmap;
        this.fmtp = fmtp;
    
Methods Summary
public static android.net.rtp.AudioCodecgetCodec(int type, java.lang.String rtpmap, java.lang.String fmtp)
Creates an AudioCodec according to the given configuration.

param
type The payload type of the encoding defined in RTP/AVP.
param
rtpmap The encoding parameters specified in the corresponding SDP attribute, or null if it is not available.
param
fmtp The format parameters specified in the corresponding SDP attribute, or null if it is not available.
return
The configured AudioCodec or {@code null} if it is not supported.

        if (type < 0 || type > 127) {
            return null;
        }

        AudioCodec hint = null;
        if (rtpmap != null) {
            String clue = rtpmap.trim().toUpperCase();
            for (AudioCodec codec : sCodecs) {
                if (clue.startsWith(codec.rtpmap)) {
                    String channels = clue.substring(codec.rtpmap.length());
                    if (channels.length() == 0 || channels.equals("/1")) {
                        hint = codec;
                    }
                    break;
                }
            }
        } else if (type < 96) {
            for (AudioCodec codec : sCodecs) {
                if (type == codec.type) {
                    hint = codec;
                    rtpmap = codec.rtpmap;
                    break;
                }
            }
        }

        if (hint == null) {
            return null;
        }
        if (hint == AMR && fmtp != null) {
            String clue = fmtp.toLowerCase();
            if (clue.contains("crc=1") || clue.contains("robust-sorting=1") ||
                    clue.contains("interleaving=")) {
                return null;
            }
        }
        return new AudioCodec(type, rtpmap, fmtp);
    
public static android.net.rtp.AudioCodec[]getCodecs()
Returns system supported audio codecs.

        return Arrays.copyOf(sCodecs, sCodecs.length);