diff --git a/src/net/java/sip/communicator/impl/media/codec/audio/speex/JavaDecoder.java b/src/net/java/sip/communicator/impl/media/codec/audio/speex/JavaDecoder.java index 6612a9e6c..eafdad8a9 100644 --- a/src/net/java/sip/communicator/impl/media/codec/audio/speex/JavaDecoder.java +++ b/src/net/java/sip/communicator/impl/media/codec/audio/speex/JavaDecoder.java @@ -23,35 +23,45 @@ public class JavaDecoder private Format lastFormat = null; private SpeexDecoder decoder = null; + /** + * Creates the decoder and inits supported input formats. + */ public JavaDecoder() { - inputFormats = new Format[] - { - new AudioFormat( - Constants.SPEEX_RTP, - 8000, - 8, - 1, - Format.NOT_SPECIFIED, - Format.NOT_SPECIFIED - )}; - supportedInputFormats = new AudioFormat[] - { + { new AudioFormat(Constants.SPEEX_RTP, 8000, 8, 1, Format.NOT_SPECIFIED, - Format.NOT_SPECIFIED)}; + Format.NOT_SPECIFIED), + new AudioFormat(Constants.SPEEX_RTP, + 16000, + 8, + 1, + Format.NOT_SPECIFIED, + Format.NOT_SPECIFIED), + new AudioFormat(Constants.SPEEX_RTP, + 32000, + 8, + 1, + Format.NOT_SPECIFIED, + Format.NOT_SPECIFIED) + }; + inputFormats = supportedInputFormats; defaultOutputFormats = new AudioFormat[] - { - new AudioFormat(AudioFormat.LINEAR)}; + {new AudioFormat(AudioFormat.LINEAR)}; PLUGIN_NAME = "Speex Decoder"; } + /** + * Returns the output format that matches the supplied input format. + * @param in + * @return + */ protected Format[] getMatchingOutputFormats(Format in) { AudioFormat af = (AudioFormat) in; @@ -71,10 +81,15 @@ protected Format[] getMatchingOutputFormats(Format in) } - + /** + * Does nothing. + */ public void open() {} + /** + * Does nothing. + */ public void close() {} @@ -84,12 +99,28 @@ private void initConverter(AudioFormat inFormat) decoder = new SpeexDecoder(); - decoder.init(0, - (int) (inFormat).getSampleRate(), + int sampleRate = + (int)inFormat.getSampleRate(); + + int band = JavaEncoder.NARROW_BAND; + + if(sampleRate == 16000) + band = JavaEncoder.WIDE_BAND; + else if(sampleRate == 32000) + band = JavaEncoder.ULTRA_WIDE_BAND; + + decoder.init(band, + sampleRate, inFormat.getChannels(), false); } + /** + * Process the input and decodes it. + * @param inputBuffer the input data. + * @param outputBuffer the result data. + * @return state of the process. + */ public int process(Buffer inputBuffer, Buffer outputBuffer) { if (!checkInputBuffer(inputBuffer)) diff --git a/src/net/java/sip/communicator/impl/media/codec/audio/speex/JavaEncoder.java b/src/net/java/sip/communicator/impl/media/codec/audio/speex/JavaEncoder.java index b550c7fe2..a3356817f 100644 --- a/src/net/java/sip/communicator/impl/media/codec/audio/speex/JavaEncoder.java +++ b/src/net/java/sip/communicator/impl/media/codec/audio/speex/JavaEncoder.java @@ -22,14 +22,21 @@ public class JavaEncoder { private Format lastFormat = null; - private static int FRAME_SIZE = 320; + private int FRAME_SIZE = -1; private SpeexEncoder encoder = null; + final static int NARROW_BAND= 0; + final static int WIDE_BAND= 1; + final static int ULTRA_WIDE_BAND= 2; + + /** + * Creates the encoder and init supported formats + */ public JavaEncoder() { supportedInputFormats = new AudioFormat[] - { + { new AudioFormat( AudioFormat.LINEAR, 8000, @@ -37,7 +44,24 @@ public JavaEncoder() 1, AudioFormat.LITTLE_ENDIAN, //isBigEndian(), AudioFormat.SIGNED //isSigned()); - )}; + ), + new AudioFormat( + AudioFormat.LINEAR, + 16000, + 16, + 1, + AudioFormat.LITTLE_ENDIAN, //isBigEndian(), + AudioFormat.SIGNED //isSigned()); + ), + new AudioFormat( + AudioFormat.LINEAR, + 32000, + 16, + 1, + AudioFormat.LITTLE_ENDIAN, //isBigEndian(), + AudioFormat.SIGNED //isSigned()); + ) + }; defaultOutputFormats = new AudioFormat[] {new AudioFormat(Constants.SPEEX_RTP)}; @@ -45,6 +69,11 @@ public JavaEncoder() PLUGIN_NAME = "pcm to speex converter"; } + /** + * Returns the output format that matches the supplied input format. + * @param in + * @return + */ protected Format[] getMatchingOutputFormats(Format in) { AudioFormat af = (AudioFormat) in; @@ -62,11 +91,17 @@ protected Format[] getMatchingOutputFormats(Format in) return supportedOutputFormats; } - public void open() throws ResourceUnavailableException + /** + * Does nothing. + */ + public void open() { } + /** + * Does nothing. + */ public void close() { @@ -78,9 +113,32 @@ private void initConverter(AudioFormat inFormat) encoder = new SpeexEncoder(); - encoder.init(0, 4, (int)inFormat.getSampleRate(), 1); + int sampleRate = + (int)inFormat.getSampleRate(); + + int band = NARROW_BAND; + FRAME_SIZE = 320; + + if(sampleRate == 16000) + { + band = WIDE_BAND; + FRAME_SIZE = 640; + } + else if(sampleRate == 32000) + { + band = ULTRA_WIDE_BAND; + FRAME_SIZE = 1280; + } + + encoder.init(band, 4, sampleRate, 1); } + /** + * Process the input and encodes it. + * @param inputBuffer the input data. + * @param outputBuffer the result data. + * @return state of the process. + */ public int process(Buffer inputBuffer, Buffer outputBuffer) { if (!checkInputBuffer(inputBuffer)) diff --git a/src/net/java/sip/communicator/impl/neomedia/format/MediaFormatFactoryImpl.java b/src/net/java/sip/communicator/impl/neomedia/format/MediaFormatFactoryImpl.java index 04207e5f7..c3922ab7c 100644 --- a/src/net/java/sip/communicator/impl/neomedia/format/MediaFormatFactoryImpl.java +++ b/src/net/java/sip/communicator/impl/neomedia/format/MediaFormatFactoryImpl.java @@ -353,8 +353,10 @@ private List getMatchingMediaFormats( { List supportedMediaFormats = new ArrayList(); + // uses equalsIgnoreCase, as some clients transmit some of the codecs + // starting with capital letters for (MediaFormat mediaFormat : mediaFormats) - if (mediaFormat.getEncoding().equals(encoding) + if (mediaFormat.getEncoding().equalsIgnoreCase(encoding) && ((CLOCK_RATE_NOT_SPECIFIED == clockRate) || (mediaFormat.getClockRate() == clockRate))) supportedMediaFormats.add(mediaFormat);