In neomedia, converts RTP payload type from int to byte. Also fixes and adds javadocs.

cusax-fix
Lyubomir Marinov 17 years ago
parent 7dc4fc7c99
commit c1aae59627

@ -6,7 +6,6 @@
*/
package net.java.sip.communicator.impl.neomedia;
import javax.media.*;
import javax.media.format.*;
import javax.media.rtp.*;

@ -32,9 +32,17 @@ public class MediaUtils
*/
public static final MediaFormat[] EMPTY_MEDIA_FORMATS = new MediaFormat[0];
/**
* The <tt>Map</tt> of JMF-specific encodings to well-known encodings as
* defined in RFC 3551.
*/
private static final Map<String, String> jmfEncodingToEncodings
= new HashMap<String, String>();
/**
* The <tt>MediaFormat</tt>s which do not have RTP payload types assigned by
* RFC 3551 and are thus refered to as having dynamic RTP payload types.
*/
private static final List<MediaFormat> rtpPayloadTypelessMediaFormats
= new ArrayList<MediaFormat>();
@ -49,44 +57,44 @@ public class MediaUtils
static
{
addMediaFormats(
SdpConstants.PCMU,
(byte) SdpConstants.PCMU,
"PCMU",
MediaType.AUDIO,
AudioFormat.ULAW_RTP,
8000);
addMediaFormats(
SdpConstants.GSM,
(byte) SdpConstants.GSM,
"GSM",
MediaType.AUDIO,
AudioFormat.GSM_RTP,
8000);
Map<String, String> g723FormatProperties
Map<String, String> g723FormatParams
= new HashMap<String, String>();
g723FormatProperties.put("annexa", "no");
g723FormatProperties.put("bitrate", "6.3");
g723FormatParams.put("annexa", "no");
g723FormatParams.put("bitrate", "6.3");
addMediaFormats(
SdpConstants.G723,
(byte) SdpConstants.G723,
"G723",
MediaType.AUDIO,
AudioFormat.G723_RTP,
g723FormatProperties,
g723FormatParams,
8000);
addMediaFormats(
SdpConstants.DVI4_8000,
(byte) SdpConstants.DVI4_8000,
"DVI4",
MediaType.AUDIO,
AudioFormat.DVI_RTP,
8000);
addMediaFormats(
SdpConstants.DVI4_16000,
(byte) SdpConstants.DVI4_16000,
"DVI4",
MediaType.AUDIO,
AudioFormat.DVI_RTP,
16000);
addMediaFormats(
SdpConstants.PCMA,
(byte) SdpConstants.PCMA,
"PCMA",
MediaType.AUDIO,
Constants.ALAW_RTP,
@ -106,44 +114,44 @@ public class MediaUtils
16000,
32000);
addMediaFormats(
SdpConstants.G728,
(byte) SdpConstants.G728,
"G728",
MediaType.AUDIO,
AudioFormat.G728_RTP,
8000);
if (EncodingConfiguration.G729)
addMediaFormats(
SdpConstants.G729,
(byte) SdpConstants.G729,
"G729",
MediaType.AUDIO,
AudioFormat.G729_RTP,
8000);
addMediaFormats(
SdpConstants.H263,
(byte) SdpConstants.H263,
"H263",
MediaType.VIDEO,
VideoFormat.H263_RTP);
addMediaFormats(
SdpConstants.JPEG,
(byte) SdpConstants.JPEG,
"JPEG",
MediaType.VIDEO,
VideoFormat.JPEG_RTP);
addMediaFormats(
SdpConstants.H261,
(byte) SdpConstants.H261,
"H261",
MediaType.VIDEO,
VideoFormat.H261_RTP);
Map<String, String> h264FormatProperties
Map<String, String> h264FormatParams
= new HashMap<String, String>();
h264FormatProperties.put("packetization-mode", "1");
h264FormatParams.put("packetization-mode", "1");
addMediaFormats(
MediaFormat.RTP_PAYLOAD_TYPE_UNKNOWN,
"H264",
MediaType.VIDEO,
Constants.H264_RTP,
h264FormatProperties);
h264FormatParams);
}
/**
@ -164,7 +172,7 @@ public class MediaUtils
* <tt>MediaFormat</tt>s to be associated with <tt>rtpPayloadType</tt>
*/
private static void addMediaFormats(
int rtpPayloadType,
byte rtpPayloadType,
String encoding,
MediaType mediaType,
String jmfEncoding,
@ -199,7 +207,7 @@ private static void addMediaFormats(
* <tt>MediaFormat</tt>s to be associated with <tt>rtpPayloadType</tt>
*/
private static void addMediaFormats(
int rtpPayloadType,
byte rtpPayloadType,
String encoding,
MediaType mediaType,
String jmfEncoding,
@ -279,7 +287,7 @@ private static void addMediaFormats(
else
rtpPayloadTypeStrToMediaFormats
.put(
Integer.toString(rtpPayloadType),
Byte.toString(rtpPayloadType),
mediaFormats.toArray(EMPTY_MEDIA_FORMATS));
jmfEncodingToEncodings
@ -313,12 +321,13 @@ else if (format instanceof VideoFormat)
else
clockRate = Format.NOT_SPECIFIED;
int rtpPayloadType = getRTPPayloadType(format.getEncoding(), clockRate);
byte rtpPayloadType = getRTPPayloadType(format.getEncoding(), clockRate);
if (MediaFormatImpl.RTP_PAYLOAD_TYPE_UNKNOWN != rtpPayloadType)
{
for (MediaFormat mediaFormat
: rtpPayloadTypeToMediaFormats(Integer.toString(rtpPayloadType)))
: rtpPayloadTypeToMediaFormats(
Byte.toString(rtpPayloadType)))
{
MediaFormatImpl<? extends Format> mediaFormatImpl
= (MediaFormatImpl<? extends Format>) mediaFormat;
@ -330,6 +339,16 @@ else if (format instanceof VideoFormat)
return null;
}
/**
* Gets the <tt>MediaFormat</tt> known to <tt>MediaUtils</tt> and having the
* specified well-known <tt>encoding</tt> (name) and <tt>clockRate</tt>.
*
* @param encoding the well-known encoding (name) of the
* <tt>MediaFormat</tt> to get
* @param clockRate the clock rate of the <tt>MediaFormat</tt> to get
* @return the <tt>MediaFormat</tt> known to <tt>MediaUtils</tt> and having
* the specified <tt>encoding</tt> and <tt>clockRate</tt>
*/
public static MediaFormat getMediaFormat(String encoding, double clockRate)
{
for (MediaFormat format : getMediaFormats(encoding))
@ -386,6 +405,15 @@ public static List<MediaFormat> getMediaFormats(String encoding)
return mediaFormats;
}
/**
* Gets the <tt>MediaFormat</tt>s known to <tt>MediaUtils</tt> and being of
* the specified <tt>MediaType</tt>.
*
* @param mediaType the <tt>MediaType</tt> of the <tt>MediaFormat</tt>s to
* get
* @return the <tt>MediaFormat</tt>s known to <tt>MediaUtils</tt> and being
* of the specified <tt>mediaType</tt>
*/
public static MediaFormat[] getMediaFormats(MediaType mediaType)
{
List<MediaFormat> mediaFormats = new ArrayList<MediaFormat>();
@ -417,17 +445,22 @@ public static String jmfEncodingToEncoding(String jmfEncoding)
}
/**
* Gets the RTP payload type corresponding to a specific JMF encoding.
* Gets the RTP payload type corresponding to a specific JMF encoding and
* clock rate.
*
* @param jmfEncoding the JMF encoding as returned by
* {@link Format#getEncoding()} or the respective <tt>AudioFormat</tt> and
* <tt>VideoFormat</tt> encoding constants to get the corresponding RTP
* payload type of
* @param clockRate the clock rate to be taken into account in the search
* for the RTP payload type if the JMF encoding does not uniquely identify
* it
* @return the RTP payload type corresponding to the specified JMF encoding
* if known in RFC 3551 "RTP Profile for Audio and Video Conferences with
* Minimal Control"; otherwise, {@link MediaFormat#RTP_PAYLOAD_TYPE_UNKNOWN}
* and clock rate if known in RFC 3551 "RTP Profile for Audio and Video
* Conferences with Minimal Control"; otherwise,
* {@link MediaFormat#RTP_PAYLOAD_TYPE_UNKNOWN}
*/
public static int getRTPPayloadType(String jmfEncoding, double clockRate)
public static byte getRTPPayloadType(String jmfEncoding, double clockRate)
{
if (jmfEncoding == null)
return MediaFormat.RTP_PAYLOAD_TYPE_UNKNOWN;

@ -23,13 +23,19 @@ public class MediaFormatFactoryImpl
{
/**
* Creates a new <tt>AudioMediaFormat</tt> instance with a specific encoding
* (name).
* Creates a <tt>MediaFormat</tt> for the specified <tt>encoding</tt> with
* default clock rate and set of format parameters. If <tt>encoding</tt> is
* known to this <tt>MediaFormatFactory</tt>, returns a
* <tt>MediaFormat</tt> which either an <tt>AudioMediaFormat</tt> or a
* <tt>VideoMediaFormat</tt> instance. Otherwise, returns <tt>null</tt>.
*
* @param encoding the encoding (name) of the new instance
* @return a new <tt>AudioMediaFormat</tt> instance with the specified
* encoding (name)
* @see MediaFormatFactory#createAudioMediaFormat(String)
* @param encoding the well-known encoding (name) to create a
* <tt>MediaFormat</tt> for
* @return a <tt>MediaFormat</tt> with the specified <tt>encoding</tt> which
* is either an <tt>AudioMediaFormat</tt> or a <tt>VideoMediaFormat</tt>
* instance if <tt>encoding</tt> is known to this
* <tt>MediaFormatFactory</tt>; otherwise, <tt>null</tt>
* @see MediaFormatFactory#createMediaFormat(String)
*/
public MediaFormat createMediaFormat(String encoding)
{
@ -37,14 +43,22 @@ public MediaFormat createMediaFormat(String encoding)
}
/**
* Creates a new <tt>AudioMediaFormat</tt> instance with specific encoding
* (name) and clock rate.
* Creates a <tt>MediaFormat</tt> for the specified <tt>encoding</tt> with
* the specified <tt>clockRate</tt> and a default set of format parameters.
* If <tt>encoding</tt> is known to this <tt>MediaFormatFactory</tt>,
* returns a <tt>MediaFormat</tt> which either an <tt>AudioMediaFormat</tt>
* or a <tt>VideoMediaFormat</tt> instance. Otherwise, returns
* <tt>null</tt>.
*
* @param encoding the encoding (name) of the new instance
* @param clockRate the clock rate of the new instance
* @return a new <tt>AudioMediaFormat</tt> instance with the specified
* encoding (name) and clock rate
* @see MediaFormatFactory#createAudioMediaFormat(String, double)
* @param encoding the well-known encoding (name) to create a
* <tt>MediaFormat</tt> for
* @param clockRate the clock rate in Hz to create a <tt>MediaFormat</tt>
* for
* @return a <tt>MediaFormat</tt> with the specified <tt>encoding</tt> and
* <tt>clockRate</tt> which is either an <tt>AudioMediaFormat</tt> or a
* <tt>VideoMediaFormat</tt> instance if <tt>encoding</tt> is known to this
* <tt>MediaFormatFactory</tt>; otherwise, <tt>null</tt>
* @see MediaFormatFactory#createMediaFormat(String, double)
*/
public MediaFormat createMediaFormat(
String encoding,
@ -87,16 +101,24 @@ public AudioMediaFormat createAudioMediaFormat(
}
/**
* Creates a new <tt>AudioMediaFormat</tt> instance with specific encoding
* (name), clock rate and set of format-specific parameters.
* Creates a <tt>MediaFormat</tt> for the specified <tt>encoding</tt>,
* <tt>clockRate</tt> and set of format parameters. If <tt>encoding</tt> is
* known to this <tt>MediaFormatFactory</tt>, returns a <tt>MediaFormat</tt>
* which either an <tt>AudioMediaFormat</tt> or a <tt>VideoMediaFormat</tt>
* instance. Otherwise, returns <tt>null</tt>.
*
* @param encoding the encoding (name) of the new instance
* @param clockRate the clock rate of the new instance
* @param formatParams the set of format-specific parameters of the new
* instance
* @return a new <tt>AudioMediaFormat</tt> instance with the specified
* encoding (name), clock rate and set of format-specific parameters
* @see MediaFormatFactory#createAudioMediaFormat(String, double, Map)
* @param encoding the well-known encoding (name) to create a
* <tt>MediaFormat</tt> for
* @param clockRate the clock rate in Hz to create a <tt>MediaFormat</tt>
* for
* @param formatParams any codec specific parameters which have been
* received via SIP/SDP or XMPP/Jingle
* @return a <tt>MediaFormat</tt> with the specified <tt>encoding</tt>,
* <tt>clockRate</tt> and set of format parameters which is either an
* <tt>AudioMediaFormat</tt> or a <tt>VideoMediaFormat</tt> instance if
* <tt>encoding</tt> is known to this <tt>MediaFormatFactory</tt>;
* otherwise, <tt>null</tt>
* @see MediaFormatFactory#createMediaFormat(String, double, Map)
*/
public MediaFormat createMediaFormat(
String encoding,
@ -182,6 +204,53 @@ public AudioMediaFormat createAudioMediaFormat(
return null;
}
/**
* Gets the <tt>MediaFormat</tt>s among the specified <tt>mediaFormats</tt>
* which have the specified <tt>encoding</tt> and, optionally,
* <tt>clockRate</tt>.
*
* @param mediaFormats the <tt>MediaFormat</tt>s from which to filter out
* only the ones which have the specified <tt>encoding</tt> and, optionally,
* <tt>clockRate</tt>
* @param encoding the well-known encoding (name) of the
* <tt>MediaFormat</tt>s to be retrieved
* @param clockRate the clock rate of the <tt>MediaFormat</tt>s to be
* retrieved; {@link #CLOCK_RATE_NOT_SPECIFIED} if any clock rate is
* acceptable
* @return a <tt>List</tt> of the <tt>MediaFormat</tt>s among
* <tt>mediaFormats</tt> which have the specified <tt>encoding</tt> and,
* optionally, <tt>clockRate</tt>
*/
private List<MediaFormat> getMatchingMediaFormats(
MediaFormat[] mediaFormats,
String encoding,
double clockRate)
{
List<MediaFormat> supportedMediaFormats = new ArrayList<MediaFormat>();
for (MediaFormat mediaFormat : mediaFormats)
if (mediaFormat.getEncoding().equals(encoding)
&& ((CLOCK_RATE_NOT_SPECIFIED == clockRate)
|| (mediaFormat.getClockRate() == clockRate)))
supportedMediaFormats.add(mediaFormat);
return supportedMediaFormats;
}
/**
* Gets the <tt>MediaFormat</tt>s supported by this
* <tt>MediaFormatFactory</tt> and the <tt>MediaService</tt> associated with
* it and having the specified <tt>encoding</tt> and, optionally,
* <tt>clockRate</tt>.
*
* @param encoding the well-known encoding (name) of the
* <tt>MediaFormat</tt>s to be retrieved
* @param clockRate the clock rate of the <tt>MediaFormat</tt>s to be
* retrieved; {@link #CLOCK_RATE_NOT_SPECIFIED} if any clock rate is
* acceptable
* @return a <tt>List</tt> of the <tt>MediaFormat</tt>s supported by the
* <tt>MediaService</tt> associated with this <tt>MediaFormatFactory</tt>
* and having the specified encoding and, optionally, clock rate
*/
private List<MediaFormat> getSupportedMediaFormats(
String encoding,
double clockRate)
@ -190,7 +259,7 @@ private List<MediaFormat> getSupportedMediaFormats(
= NeomediaActivator
.getMediaServiceImpl().getEncodingConfiguration();
List<MediaFormat> supportedMediaFormats
= getSupportedMediaFormats(
= getMatchingMediaFormats(
encodingConfiguration
.getSupportedEncodings(MediaType.AUDIO),
encoding,
@ -198,26 +267,11 @@ private List<MediaFormat> getSupportedMediaFormats(
if (supportedMediaFormats.isEmpty())
supportedMediaFormats
= getSupportedMediaFormats(
= getMatchingMediaFormats(
encodingConfiguration
.getSupportedEncodings(MediaType.VIDEO),
encoding,
clockRate);
return supportedMediaFormats;
}
private List<MediaFormat> getSupportedMediaFormats(
MediaFormat[] mediaFormats,
String encoding,
double clockRate)
{
List<MediaFormat> supportedMediaFormats = new ArrayList<MediaFormat>();
for (MediaFormat mediaFormat : mediaFormats)
if (mediaFormat.getEncoding().equals(encoding)
&& ((CLOCK_RATE_NOT_SPECIFIED == clockRate)
|| (mediaFormat.getClockRate() == clockRate)))
supportedMediaFormats.add(mediaFormat);
return supportedMediaFormats;
}
}

@ -310,7 +310,7 @@ public String getJMFEncoding()
* Control"; otherwise, {@link #RTP_PAYLOAD_TYPE_UNKNOWN}
* @see MediaFormat#getRTPPayloadType()
*/
public int getRTPPayloadType()
public byte getRTPPayloadType()
{
return MediaUtils.getRTPPayloadType(getJMFEncoding(), getClockRate());
}

@ -30,7 +30,7 @@ public interface MediaFormat
* type (number) known in RFC 3551 "RTP Profile for Audio and Video
* Conferences with Minimal Control".
*/
public static final int RTP_PAYLOAD_TYPE_UNKNOWN = -1;
public static final byte RTP_PAYLOAD_TYPE_UNKNOWN = -1;
/**
* Returns the type of this <tt>MediaFormat</tt> (e.g. audio or video).
@ -97,5 +97,5 @@ public interface MediaFormat
* in RFC 3551 "RTP Profile for Audio and Video Conferences with Minimal
* Control"; otherwise, {@link #RTP_PAYLOAD_TYPE_UNKNOWN}
*/
public int getRTPPayloadType();
public byte getRTPPayloadType();
}

@ -9,9 +9,10 @@
import java.util.*;
/**
* The MediaFormatFactory allows creating instances of Audio and Video formats.
* Allows the creation of audio and video <tt>MediaFormat</tt> instances.
*
* @author Emil Ivov
* @author Lubomir Marinov
*/
public interface MediaFormatFactory
{
@ -23,26 +24,37 @@ public interface MediaFormatFactory
public static final double CLOCK_RATE_NOT_SPECIFIED = -1;
/**
* Creates an <tt>AudioMediaFormat</tt> for the specified <tt>encoding</tt>,
* <tt>clockRate</tt>, a default clock rate for the specified
* <tt>encoding</tt>, a single audio channel, and no format parameters.
*
* @param encoding the encoding of the format to create.
* Creates a <tt>MediaFormat</tt> for the specified <tt>encoding</tt> with
* default clock rate and set of format parameters. If <tt>encoding</tt> is
* known to this <tt>MediaFormatFactory</tt>, returns a
* <tt>MediaFormat</tt> which either an <tt>AudioMediaFormat</tt> or a
* <tt>VideoMediaFormat</tt> instance. Otherwise, returns <tt>null</tt>.
*
* @return a newly created <tt>AudioMediaFormat</tt> with the specified
* parameters.
* @param encoding the well-known encoding (name) to create a
* <tt>MediaFormat</tt> for
* @return a <tt>MediaFormat</tt> with the specified <tt>encoding</tt> which
* is either an <tt>AudioMediaFormat</tt> or a <tt>VideoMediaFormat</tt>
* instance if <tt>encoding</tt> is known to this
* <tt>MediaFormatFactory</tt>; otherwise, <tt>null</tt>
*/
public MediaFormat createMediaFormat(String encoding);
/**
* Creates an <tt>AudioMediaFormat</tt> for the specified <tt>encoding</tt>,
* <tt>clockRate</tt>, a single audio channel, and no format parameters.
*
* @param encoding the encoding of the format to create.
* @param clockRate the rate in Hz of the audio format
* Creates a <tt>MediaFormat</tt> for the specified <tt>encoding</tt> with
* the specified <tt>clockRate</tt> and a default set of format parameters.
* If <tt>encoding</tt> is known to this <tt>MediaFormatFactory</tt>,
* returns a <tt>MediaFormat</tt> which either an <tt>AudioMediaFormat</tt>
* or a <tt>VideoMediaFormat</tt> instance. Otherwise, returns
* <tt>null</tt>.
*
* @return a newly created <tt>AudioMediaFormat</tt> with the specified
* parameters.
* @param encoding the well-known encoding (name) to create a
* <tt>MediaFormat</tt> for
* @param clockRate the clock rate in Hz to create a <tt>MediaFormat</tt>
* for
* @return a <tt>MediaFormat</tt> with the specified <tt>encoding</tt> and
* <tt>clockRate</tt> which is either an <tt>AudioMediaFormat</tt> or a
* <tt>VideoMediaFormat</tt> instance if <tt>encoding</tt> is known to this
* <tt>MediaFormatFactory</tt>; otherwise, <tt>null</tt>
*/
public MediaFormat createMediaFormat(
String encoding,
@ -64,17 +76,23 @@ public AudioMediaFormat createAudioMediaFormat(
String encoding, double clockRate, int channels);
/**
* Creates an <tt>AudioMediaFormat</tt> for the specified <tt>encoding</tt>,
* <tt>clockRate</tt>, <tt>formatParams</tt> parameters and a single audio
* channel.
*
* @param encoding the encoding of the format to create.
* @param clockRate the rate in Hz of the audio format
* @param formatParams any codec specific params that have been received via
* SIP/SDP or XMPP/Jingle.
* Creates a <tt>MediaFormat</tt> for the specified <tt>encoding</tt>,
* <tt>clockRate</tt> and set of format parameters. If <tt>encoding</tt> is
* known to this <tt>MediaFormatFactory</tt>, returns a <tt>MediaFormat</tt>
* which either an <tt>AudioMediaFormat</tt> or a <tt>VideoMediaFormat</tt>
* instance. Otherwise, returns <tt>null</tt>.
*
* @return a newly created <tt>AudioMediaFormat</tt> with the specified
* parameters.
* @param encoding the well-known encoding (name) to create a
* <tt>MediaFormat</tt> for
* @param clockRate the clock rate in Hz to create a <tt>MediaFormat</tt>
* for
* @param formatParams any codec specific parameters which have been
* received via SIP/SDP or XMPP/Jingle
* @return a <tt>MediaFormat</tt> with the specified <tt>encoding</tt>,
* <tt>clockRate</tt> and set of format parameters which is either an
* <tt>AudioMediaFormat</tt> or a <tt>VideoMediaFormat</tt> instance if
* <tt>encoding</tt> is known to this <tt>MediaFormatFactory</tt>;
* otherwise, <tt>null</tt>
*/
public MediaFormat createMediaFormat(
String encoding,

Loading…
Cancel
Save