diff --git a/src/org/jitsi/impl/neomedia/MediaUtils.java b/src/org/jitsi/impl/neomedia/MediaUtils.java index 0ac5ac2a80438102d1bc405900b7f2d9346a6661..1442206efdddff9d5de196bbd2bde7a0b3857a76 100644 --- a/src/org/jitsi/impl/neomedia/MediaUtils.java +++ b/src/org/jitsi/impl/neomedia/MediaUtils.java @@ -183,6 +183,7 @@ public class MediaUtils "opus", MediaType.AUDIO, Constants.OPUS_RTP, + 2, opusFormatParams, null, 48000); @@ -418,12 +419,55 @@ private static void addMediaFormats( * @param clockRates the optional list of clock rates of the * <tt>MediaFormat</tt>s to be associated with <tt>rtpPayloadType</tt> */ + private static void addMediaFormats( + byte rtpPayloadType, + String encoding, + MediaType mediaType, + String jmfEncoding, + Map<String, String> formatParameters, + Map<String, String> advancedAttributes, + double... clockRates) + { + addMediaFormats( + rtpPayloadType, + encoding, + mediaType, + jmfEncoding, + 1 /* channel */, + formatParameters, + advancedAttributes, + clockRates); + } + + /** + * Adds a new mapping of a specific RTP payload type to a list of + * <tt>MediaFormat</tt>s of a specific <tt>MediaType</tt>, with a specific + * JMF encoding and, optionally, with specific clock rates. + * + * @param rtpPayloadType the RTP payload type to be associated with a list + * of <tt>MediaFormat</tt>s + * @param encoding the well-known encoding (name) corresponding to + * <tt>rtpPayloadType</tt> (in contrast to the JMF-specific encoding + * specified by <tt>jmfEncoding</tt>) + * @param mediaType the <tt>MediaType</tt> of the <tt>MediaFormat</tt>s to + * be associated with <tt>rtpPayloadType</tt> + * @param jmfEncoding the JMF encoding of the <tt>MediaFormat</tt>s to be + * associated with <tt>rtpPayloadType</tt> + * @param channels number of channels + * @param formatParameters the set of format-specific parameters of the + * <tt>MediaFormat</tt>s to be associated with <tt>rtpPayloadType</tt> + * @param advancedAttributes the set of advanced attributes of the + * <tt>MediaFormat</tt>s to be associated with <tt>rtpPayload</tt> + * @param clockRates the optional list of clock rates of the + * <tt>MediaFormat</tt>s to be associated with <tt>rtpPayloadType</tt> + */ @SuppressWarnings("unchecked") private static void addMediaFormats( byte rtpPayloadType, String encoding, MediaType mediaType, String jmfEncoding, + int channels, Map<String, String> formatParameters, Map<String, String> advancedAttributes, double... clockRates) @@ -441,7 +485,14 @@ private static void addMediaFormats( switch (mediaType) { case AUDIO: - format = new AudioFormat(jmfEncoding); + if(channels == 1) + format = new AudioFormat(jmfEncoding); + else + format = new AudioFormat( + jmfEncoding, + Format.NOT_SPECIFIED, + Format.NOT_SPECIFIED, + channels); break; case VIDEO: format diff --git a/src/org/jitsi/impl/neomedia/codec/audio/opus/JNIDecoder.java b/src/org/jitsi/impl/neomedia/codec/audio/opus/JNIDecoder.java index ccebdbe2e956466b95f843ec22c3cf6dc590949c..7afbd439038f3b07a7b79c47c0fdbdcc452dd312 100644 --- a/src/org/jitsi/impl/neomedia/codec/audio/opus/JNIDecoder.java +++ b/src/org/jitsi/impl/neomedia/codec/audio/opus/JNIDecoder.java @@ -72,7 +72,7 @@ public class JNIDecoder } /** - * Number of channels + * Number of channels to decode into. */ private int channels = 1; @@ -191,8 +191,8 @@ protected int doProcess(Buffer inBuffer, Buffer outBuffer) * operate as if PLC has been specified. */ boolean decodeFEC - = ((lostSeqNoCount != 0) - && (lastFrameSizeInSamplesPerChannel != 0)); + = ((lostSeqNoCount != 0) + && (lastFrameSizeInSamplesPerChannel != 0)); if ((inBuffer.getFlags() & Buffer.FLAG_SKIP_FEC) != 0) { @@ -215,8 +215,8 @@ protected int doProcess(Buffer inBuffer, Buffer outBuffer) if (decodeFEC) { - inLength - = (lostSeqNoCount == 1) ? inLength /* FEC */ : 0 /* PLC */; + inLength + = (lostSeqNoCount == 1) ? inLength /* FEC */ : 0 /* PLC */; byte[] out = validateByteArraySize( @@ -280,8 +280,8 @@ protected int doProcess(Buffer inBuffer, Buffer outBuffer) += frameSizeInSamplesPerChannel; outBuffer.setFlags( - outBuffer.getFlags() - & ~(BUFFER_FLAG_FEC | BUFFER_FLAG_PLC)); + outBuffer.getFlags() + & ~(BUFFER_FLAG_FEC | BUFFER_FLAG_PLC)); /* * When we encounter a lost frame, we will presume that it was @@ -373,39 +373,9 @@ public Format setInputFormat(Format format) if (inFormat != null) { - double outSampleRate; - int outChannels; - if (outputFormat == null) { - outSampleRate = Format.NOT_SPECIFIED; - outChannels = Format.NOT_SPECIFIED; - } - else - { - AudioFormat outAudioFormat = (AudioFormat) outputFormat; - - outSampleRate = outAudioFormat.getSampleRate(); - outChannels = outAudioFormat.getChannels(); - } - - AudioFormat inAudioFormat = (AudioFormat) inFormat; - double inSampleRate = inAudioFormat.getSampleRate(); - int inChannels = inAudioFormat.getChannels(); - - if ((outSampleRate != inSampleRate) || (outChannels != inChannels)) - { - setOutputFormat( - new AudioFormat( - AudioFormat.LINEAR, - inSampleRate, - 16, - inChannels, - AudioFormat.LITTLE_ENDIAN, - AudioFormat.SIGNED, - /* frameSizeInBits */ Format.NOT_SPECIFIED, - /* frameRate */ Format.NOT_SPECIFIED, - Format.byteArray)); + setOutputFormat(SUPPORTED_OUTPUT_FORMATS[0]); } } return inFormat; diff --git a/src/org/jitsi/impl/neomedia/codec/audio/opus/JNIEncoder.java b/src/org/jitsi/impl/neomedia/codec/audio/opus/JNIEncoder.java index 12ba9fb60b84ecebd7660b2ae697fbfee0bd26a0..efff0b889bc88899f059cb8724e849801df27246 100644 --- a/src/org/jitsi/impl/neomedia/codec/audio/opus/JNIEncoder.java +++ b/src/org/jitsi/impl/neomedia/codec/audio/opus/JNIEncoder.java @@ -64,7 +64,7 @@ public class JNIEncoder Constants.OPUS_RTP, 48000, /* sampleSizeInBits */ Format.NOT_SPECIFIED, - 1, + /* channels */ 2, /* endian */ Format.NOT_SPECIFIED, /* signed */ Format.NOT_SPECIFIED, /* frameSizeInBits */ Format.NOT_SPECIFIED,