From ec1cdc56bc1ed7e9f27ab6f31585174ca191ffd3 Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Sun, 1 Nov 2009 13:12:06 +0000 Subject: [PATCH] In neomedia, allows getting a MediaFormat instance by its RTP payload type (number). --- .../impl/neomedia/MediaUtils.java | 45 +++++++++---------- .../format/MediaFormatFactoryImpl.java | 38 ++++++++++++++++ .../service/neomedia/MediaDirection.java | 1 + .../neomedia/format/MediaFormatFactory.java | 17 +++++++ 4 files changed, 77 insertions(+), 24 deletions(-) diff --git a/src/net/java/sip/communicator/impl/neomedia/MediaUtils.java b/src/net/java/sip/communicator/impl/neomedia/MediaUtils.java index 5989acb9a..cb87daa5c 100644 --- a/src/net/java/sip/communicator/impl/neomedia/MediaUtils.java +++ b/src/net/java/sip/communicator/impl/neomedia/MediaUtils.java @@ -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 mediaFormatImpl = (MediaFormatImpl) mediaFormat; @@ -428,6 +426,26 @@ public static MediaFormat[] getMediaFormats(MediaType mediaType) return mediaFormats.toArray(EMPTY_MEDIA_FORMATS); } + /** + * Gets the MediaFormats (expressed as an array) corresponding to + * a specific RTP payload type. + * + * @param rtpPayloadType the RTP payload type to retrieve the + * corresponding MediaFormats for + * @return an array of MediaFormats 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 MediaFormats (expressed as an array) corresponding to - * a specific RTP payload type (expressed as a String). - * - * @param rtpPayloadTypeStr the RTP payload type to retrieve the - * corresponding MediaFormats for - * @return an array of MediaFormats 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(); - } } 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 ba83423eb..b01b6fdf9 100644 --- a/src/net/java/sip/communicator/impl/neomedia/format/MediaFormatFactoryImpl.java +++ b/src/net/java/sip/communicator/impl/neomedia/format/MediaFormatFactoryImpl.java @@ -42,6 +42,44 @@ public MediaFormat createMediaFormat(String encoding) return createMediaFormat(encoding, CLOCK_RATE_NOT_SPECIFIED); } + /** + * Creates a MediaFormat for the specified RTP payload type with + * default clock rate and set of format parameters. If + * rtpPayloadType is known to this MediaFormatFactory, + * returns a MediaFormat which either an AudioMediaFormat + * or a VideoMediaFormat instance. Otherwise, returns + * null. + * + * @param rtpPayloadType the RTP payload type of the MediaFormat to + * create + * @return a MediaFormat with the specified rtpPayloadType + * which is either an AudioMediaFormat or a + * VideoMediaFormat instance if rtpPayloadType is known to + * this MediaFormatFactory; otherwise, null + * @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 MediaFormat for the specified encoding with * the specified clockRate and a default set of format parameters. diff --git a/src/net/java/sip/communicator/service/neomedia/MediaDirection.java b/src/net/java/sip/communicator/service/neomedia/MediaDirection.java index 4f0bb5089..0295f1bb9 100644 --- a/src/net/java/sip/communicator/service/neomedia/MediaDirection.java +++ b/src/net/java/sip/communicator/service/neomedia/MediaDirection.java @@ -70,6 +70,7 @@ private MediaDirection(String directionName) * @return the name of this MediaDirection (e.g. "sendonly", * "recvonly", "sendrecv"). */ + @Override public String toString() { return directionName; diff --git a/src/net/java/sip/communicator/service/neomedia/format/MediaFormatFactory.java b/src/net/java/sip/communicator/service/neomedia/format/MediaFormatFactory.java index 2e8fb1fff..c0e1d48ad 100644 --- a/src/net/java/sip/communicator/service/neomedia/format/MediaFormatFactory.java +++ b/src/net/java/sip/communicator/service/neomedia/format/MediaFormatFactory.java @@ -39,6 +39,23 @@ public interface MediaFormatFactory */ public MediaFormat createMediaFormat(String encoding); + /** + * Creates a MediaFormat for the specified RTP payload type with + * default clock rate and set of format parameters. If + * rtpPayloadType is known to this MediaFormatFactory, + * returns a MediaFormat which either an AudioMediaFormat + * or a VideoMediaFormat instance. Otherwise, returns + * null. + * + * @param rtpPayloadType the RTP payload type of the MediaFormat to + * create + * @return a MediaFormat with the specified rtpPayloadType + * which is either an AudioMediaFormat or a + * VideoMediaFormat instance if rtpPayloadType is known to + * this MediaFormatFactory; otherwise, null + */ + public MediaFormat createMediaFormat(byte rtpPayloadType); + /** * Creates a MediaFormat for the specified encoding with * the specified clockRate and a default set of format parameters.