aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmil Ivov <emcho@jitsi.org>2006-10-23 16:19:40 +0000
committerEmil Ivov <emcho@jitsi.org>2006-10-23 16:19:40 +0000
commit7e02d64f2070a896a84d3d06c5eca6253bbbb491 (patch)
treeac3f5fe88af1e7ad906e61bef5e9e676944d8384
parent7d6b1257f601f5382514b5c7e68ec42871d8ee30 (diff)
downloadjitsi-7e02d64f2070a896a84d3d06c5eca6253bbbb491.zip
jitsi-7e02d64f2070a896a84d3d06c5eca6253bbbb491.tar.gz
jitsi-7e02d64f2070a896a84d3d06c5eca6253bbbb491.tar.bz2
Working on the JMF implementation of the media service.
utility class implementing methods for format conversion
-rw-r--r--src/net/java/sip/communicator/impl/media/MediaUtils.java160
1 files changed, 160 insertions, 0 deletions
diff --git a/src/net/java/sip/communicator/impl/media/MediaUtils.java b/src/net/java/sip/communicator/impl/media/MediaUtils.java
new file mode 100644
index 0000000..7434745
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/media/MediaUtils.java
@@ -0,0 +1,160 @@
+/*
+ * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.impl.media;
+
+import javax.media.format.*;
+import javax.sdp.*;
+import java.util.*;
+
+/**
+ * Implements static utility methods used by media classes.
+ *
+ * @author Emil Ivov
+ */
+public class MediaUtils
+{
+ /**
+ * Returns the String encoding, as specified in AudioFormat and VideoFormat,
+ * corresponding to the format specified in sdpFormatStr
+ * @param sdpEncodingStr the SDP index that we'd like to convert to a JMF
+ * format.
+ * @return one of the AudioFormat.XXX or VideoFormat.XXX format strings.
+ */
+ public static String sdpToJmfEncoding(String sdpEncodingStr)
+ {
+ int sdpEncoding = -1;
+ try
+ {
+ sdpEncoding = Integer.parseInt(sdpEncodingStr);
+ }
+ catch (NumberFormatException ex)
+ {
+ return null;
+ }
+ switch (sdpEncoding)
+ {
+ case SdpConstants.PCMU:
+ return AudioFormat.ULAW_RTP;
+ case SdpConstants.GSM:
+ return AudioFormat.GSM_RTP;
+ case SdpConstants.G723:
+ return AudioFormat.G723_RTP;
+ case SdpConstants.DVI4_8000:
+ return AudioFormat.DVI_RTP;
+ case SdpConstants.DVI4_16000:
+ return AudioFormat.DVI_RTP;
+ case SdpConstants.PCMA:
+ return AudioFormat.ALAW;
+ case SdpConstants.G728:
+ return AudioFormat.G728_RTP;
+ case SdpConstants.G729:
+ return AudioFormat.G729_RTP;
+ case SdpConstants.H263:
+ return VideoFormat.H263_RTP;
+ case SdpConstants.JPEG:
+ return VideoFormat.JPEG_RTP;
+ case SdpConstants.H261:
+ return VideoFormat.H261_RTP;
+ default:
+ return null;
+ }
+ }
+
+ /**
+ * Returns a String containing the SDP encoding number corresponding to
+ * <tt>jmfFormat</tt>.
+ *
+ * @param jmfEncoding one of the AudioFormat.XXX or VideoFormat.XXX format
+ * strings.
+ *
+ * @return a string containing the SDP index corresponding to
+ * <tt>jmfEncoding</tt>.
+ */
+ public static String jmfToSdpEncoding(String jmfEncoding)
+ {
+ if (jmfEncoding == null)
+ {
+ return null;
+ }
+ else if (jmfEncoding.equals(AudioFormat.ULAW_RTP))
+ {
+ return Integer.toString(SdpConstants.PCMU);
+ }
+ else if (jmfEncoding.equals(AudioFormat.GSM_RTP))
+ {
+ return Integer.toString(SdpConstants.GSM);
+ }
+ else if (jmfEncoding.equals(AudioFormat.G723_RTP))
+ {
+ return Integer.toString(SdpConstants.G723);
+ }
+ else if (jmfEncoding.equals(AudioFormat.DVI_RTP))
+ {
+ return Integer.toString(SdpConstants.DVI4_8000);
+ }
+ else if (jmfEncoding.equals(AudioFormat.DVI_RTP))
+ {
+ return Integer.toString(SdpConstants.DVI4_16000);
+ }
+ else if (jmfEncoding.equals(AudioFormat.ALAW))
+ {
+ return Integer.toString(SdpConstants.PCMA);
+ }
+ else if (jmfEncoding.equals(AudioFormat.G728_RTP))
+ {
+ return Integer.toString(SdpConstants.G728);
+ }
+ else if (jmfEncoding.equals(AudioFormat.G729_RTP))
+ {
+ return Integer.toString(SdpConstants.G729);
+ }
+ else if (jmfEncoding.equals(VideoFormat.H263_RTP))
+ {
+ return Integer.toString(SdpConstants.H263);
+ }
+ else if (jmfEncoding.equals(VideoFormat.JPEG_RTP))
+ {
+ return Integer.toString(SdpConstants.JPEG);
+ }
+ else if (jmfEncoding.equals(VideoFormat.H261_RTP))
+ {
+ return Integer.toString(SdpConstants.H261);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Converts the list of <tt>sdpEncodings</tt> to a list of jmf compatible
+ * encoding strings as specified by the static vars in VideoFormat
+ * and AudioFormat.
+ *
+ * @param sdpEncodings a list containing strings representing SDP format
+ * codes.
+ * @return a list of strings representing JMF compatible encoding names.
+ */
+ public static List sdpToJmfEncodings(List sdpEncodings)
+ {
+ ArrayList jmfEncodings = new ArrayList();
+ if (sdpEncodings == null)
+ return jmfEncodings;
+
+ for (int i = 0; i < sdpEncodings.size(); i++)
+ {
+ String jmfEncoding =
+ sdpToJmfEncoding((String)sdpEncodings.get(i));
+ if (jmfEncoding != null)
+ {
+ jmfEncodings.add(jmfEncoding);
+ }
+ }
+ return jmfEncodings;
+ }
+
+}