In neomedia, allows getting a MediaFormat instance by its RTP payload type (number).

cusax-fix
Lyubomir Marinov 17 years ago
parent c1aae59627
commit ec1cdc56bc

@ -325,9 +325,7 @@ else if (format instanceof VideoFormat)
if (MediaFormatImpl.RTP_PAYLOAD_TYPE_UNKNOWN != rtpPayloadType)
{
for (MediaFormat mediaFormat
: rtpPayloadTypeToMediaFormats(
Byte.toString(rtpPayloadType)))
for (MediaFormat mediaFormat : getMediaFormats(rtpPayloadType))
{
MediaFormatImpl<? extends Format> mediaFormatImpl
= (MediaFormatImpl<? extends Format>) mediaFormat;
@ -428,6 +426,26 @@ public static MediaFormat[] getMediaFormats(MediaType mediaType)
return mediaFormats.toArray(EMPTY_MEDIA_FORMATS);
}
/**
* Gets the <tt>MediaFormat</tt>s (expressed as an array) corresponding to
* a specific RTP payload type.
*
* @param rtpPayloadType the RTP payload type to retrieve the
* corresponding <tt>MediaFormat</tt>s for
* @return an array of <tt>MediaFormat</tt>s corresponding to the specified
* RTP payload type
*/
public static MediaFormat[] getMediaFormats(byte rtpPayloadType)
{
MediaFormat[] mediaFormats
= rtpPayloadTypeStrToMediaFormats.get(Byte.toString(rtpPayloadType));
return
(mediaFormats == null)
? EMPTY_MEDIA_FORMATS
: mediaFormats.clone();
}
/**
* Gets the well-known encoding (name) as defined in RFC 3551 "RTP Profile
* for Audio and Video Conferences with Minimal Control" corresponding to a
@ -493,25 +511,4 @@ else if (jmfEncoding.equals(VideoFormat.H261_RTP))
else
return MediaFormat.RTP_PAYLOAD_TYPE_UNKNOWN;
}
/**
* Gets the <tt>MediaFormat</tt>s (expressed as an array) corresponding to
* a specific RTP payload type (expressed as a <tt>String</tt>).
*
* @param rtpPayloadTypeStr the RTP payload type to retrieve the
* corresponding <tt>MediaFormat</tt>s for
* @return an array of <tt>MediaFormat</tt>s corresponding to the specified
* RTP payload type
*/
private static MediaFormat[] rtpPayloadTypeToMediaFormats(
String rtpPayloadTypeStr)
{
MediaFormat[] mediaFormats
= rtpPayloadTypeStrToMediaFormats.get(rtpPayloadTypeStr);
return
(mediaFormats == null)
? EMPTY_MEDIA_FORMATS
: mediaFormats.clone();
}
}

@ -42,6 +42,44 @@ public MediaFormat createMediaFormat(String encoding)
return createMediaFormat(encoding, CLOCK_RATE_NOT_SPECIFIED);
}
/**
* Creates a <tt>MediaFormat</tt> for the specified RTP payload type with
* default clock rate and set of format parameters. If
* <tt>rtpPayloadType</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 rtpPayloadType the RTP payload type of the <tt>MediaFormat</tt> to
* create
* @return a <tt>MediaFormat</tt> with the specified <tt>rtpPayloadType</tt>
* which is either an <tt>AudioMediaFormat</tt> or a
* <tt>VideoMediaFormat</tt> instance if <tt>rtpPayloadType</tt> is known to
* this <tt>MediaFormatFactory</tt>; otherwise, <tt>null</tt>
* @see MediaFormatFactory#createMediaFormat(byte)
*/
public MediaFormat createMediaFormat(byte rtpPayloadType)
{
/*
* We know which are the MediaFormat instance with the specified
* rtpPayloadType but we cannot directly return them because they do not
* reflect the user configuration with respect to being enabled and
* disabled.
*/
for (MediaFormat rtpPayloadTypeMediaFormat
: MediaUtils.getMediaFormats(rtpPayloadType))
{
MediaFormat mediaFormat
= createMediaFormat(
rtpPayloadTypeMediaFormat.getEncoding(),
rtpPayloadTypeMediaFormat.getClockRate());
if (mediaFormat != null)
return mediaFormat;
}
return null;
}
/**
* Creates a <tt>MediaFormat</tt> for the specified <tt>encoding</tt> with
* the specified <tt>clockRate</tt> and a default set of format parameters.

@ -70,6 +70,7 @@ private MediaDirection(String directionName)
* @return the name of this <tt>MediaDirection</tt> (e.g. "sendonly",
* "recvonly", "sendrecv").
*/
@Override
public String toString()
{
return directionName;

@ -39,6 +39,23 @@ public interface MediaFormatFactory
*/
public MediaFormat createMediaFormat(String encoding);
/**
* Creates a <tt>MediaFormat</tt> for the specified RTP payload type with
* default clock rate and set of format parameters. If
* <tt>rtpPayloadType</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 rtpPayloadType the RTP payload type of the <tt>MediaFormat</tt> to
* create
* @return a <tt>MediaFormat</tt> with the specified <tt>rtpPayloadType</tt>
* which is either an <tt>AudioMediaFormat</tt> or a
* <tt>VideoMediaFormat</tt> instance if <tt>rtpPayloadType</tt> is known to
* this <tt>MediaFormatFactory</tt>; otherwise, <tt>null</tt>
*/
public MediaFormat createMediaFormat(byte rtpPayloadType);
/**
* Creates a <tt>MediaFormat</tt> for the specified <tt>encoding</tt> with
* the specified <tt>clockRate</tt> and a default set of format parameters.

Loading…
Cancel
Save