/** * Parse a iq/jingle/description element. * * @param parser * the input to parse * @return a description element * @throws Exception */ public PacketExtension parseExtension(final XmlPullParser parser) throws Exception { boolean done = false; JingleDescription desc = getInstance(); while (!done) { int eventType = parser.next(); String name = parser.getName(); if (eventType == XmlPullParser.START_TAG) { if (name.equals(PayloadType.NODENAME)) { desc.addPayloadType(parsePayload(parser)); } else { throw new Exception("Unknow element \"" + name + "\" in content."); } } else if (eventType == XmlPullParser.END_TAG) { if (name.equals(JingleDescription.NODENAME)) { done = true; } } } return desc; }
/** * Convert a Jingle description to XML. * * @return a string with the XML representation */ public String toXML() { StringBuilder buf = new StringBuilder(); synchronized (payloads) { if (payloads.size() > 0) { buf.append("<").append(getElementName()); buf.append(" xmlns=\"").append(getNamespace()).append("\" >"); for (PayloadType payloadType : payloads) { if (payloadType != null) { buf.append(payloadType.toXML()); } } buf.append("</").append(getElementName()).append(">"); } } return buf.toString(); }
public String toXML() { StringBuilder buf = new StringBuilder(); if (payload != null) { buf.append("<").append(getElementName()).append(" "); // We covert here the payload type to XML if (payload.getId() != PayloadType.INVALID_PT) { buf.append(" id=\"").append(payload.getId()).append("\""); } if (payload.getName() != null) { buf.append(" name=\"").append(payload.getName()).append("\""); } if (payload.getChannels() != 0) { buf.append(" channels=\"").append(payload.getChannels()).append("\""); } if (getChildAttributes() != null) { buf.append(getChildAttributes()); } buf.append("/>"); } return buf.toString(); }
public void sessionEstablished(PayloadType payloadType, TransportCandidate transportCandidate, TransportCandidate transportCandidate1, JingleSession jingleSession) { established = true; mediaReceivedTask = new SwingTimerTask() { public void doRun() { if (!mediaReceived) { if (session != null) { try { session.terminate("No Media Received. This may be caused by firewall configuration problems."); } catch (XMPPException e) { Log.error(e); } } } } }; TaskEngine.getInstance().schedule(mediaReceivedTask, WAIT_FOR_MEDIA_DELAY, WAIT_FOR_MEDIA_DELAY); SwingUtilities.invokeLater(new Runnable() { public void run() { updateOutgoingCallPanel(); } }); }
public void sessionEstablished(PayloadType payloadType, TransportCandidate transportCandidate, TransportCandidate transportCandidate1, JingleSession jingleSession) { established = true; mediaReceivedTask = new SwingTimerTask() { public void doRun() { if (!mediaReceived) { if (session != null) { try { session.terminate("No Media Received. This may be caused by firewall configuration problems."); } catch (XMPPException e) { Log.error(e); } } } } }; TaskEngine.getInstance().schedule(mediaReceivedTask, WAIT_FOR_MEDIA_DELAY, WAIT_FOR_MEDIA_DELAY); }
/** * Generate a list of payload types * * @return A testing list */ private ArrayList<PayloadType> getTestPayloads1() { ArrayList<PayloadType> result = new ArrayList<PayloadType>(); result.add(new PayloadType.Audio(34, "supercodec-1", 2, 14000)); result.add(new PayloadType.Audio(56, "supercodec-2", 1, 44000)); result.add(new PayloadType.Audio(36, "supercodec-3", 2, 28000)); result.add(new PayloadType.Audio(45, "supercodec-4", 1, 98000)); return result; }
private ArrayList<PayloadType> getTestPayloads2() { ArrayList<PayloadType> result = new ArrayList<PayloadType>(); result.add(new PayloadType.Audio(27, "supercodec-3", 2, 28000)); result.add(new PayloadType.Audio(56, "supercodec-2", 1, 44000)); result.add(new PayloadType.Audio(32, "supercodec-4", 1, 98000)); result.add(new PayloadType.Audio(34, "supercodec-1", 2, 14000)); return result; }
/** * Generate a list of payload types * * @return A testing list */ private List<PayloadType> getTestPayloads1() { List<PayloadType> result = new ArrayList<PayloadType>(); result.add(new PayloadType.Audio(34, "supercodec-1", 2, 14000)); result.add(new PayloadType.Audio(56, "supercodec-2", 1, 44000)); result.add(new PayloadType.Audio(36, "supercodec-3", 2, 28000)); result.add(new PayloadType.Audio(45, "supercodec-4", 1, 98000)); return result; }
private List<PayloadType> getTestPayloads2() { List<PayloadType> result = new ArrayList<PayloadType>(); result.add(new PayloadType.Audio(27, "supercodec-3", 2, 28000)); result.add(new PayloadType.Audio(56, "supercodec-2", 1, 44000)); result.add(new PayloadType.Audio(32, "supercodec-4", 1, 98000)); result.add(new PayloadType.Audio(34, "supercodec-1", 2, 14000)); return result; }
private List<PayloadType> getTestPayloads3() { List<PayloadType> result = new ArrayList<PayloadType>(); result.add(new PayloadType.Audio(91, "badcodec-1", 2, 28000)); result.add(new PayloadType.Audio(92, "badcodec-2", 1, 44000)); result.add(new PayloadType.Audio(93, "badcodec-3", 1, 98000)); result.add(new PayloadType.Audio(94, "badcodec-4", 2, 14000)); return result; }
/** * Test for the difference of payloads. */ public void testDifference() { ArrayList<Audio> set1 = new ArrayList<Audio>(); ArrayList<Audio> set2 = new ArrayList<Audio>(); PayloadType.Audio common1 = new PayloadType.Audio(34, "supercodec-1", 2, 14000); PayloadType.Audio common2 = new PayloadType.Audio(56, "supercodec-2", 1, 44000); set1.add(common1); set1.add(common2); set1.add(new PayloadType.Audio(36, "supercodec-3", 2, 28000)); set1.add(new PayloadType.Audio(45, "supercodec-4", 1, 98000)); set2.add(new PayloadType.Audio(27, "supercodec-3", 2, 28000)); set2.add(common2); set2.add(new PayloadType.Audio(32, "supercodec-4", 1, 98000)); set2.add(common1); // Get the difference ArrayList<Audio> commonSet = new ArrayList<Audio>(); commonSet.addAll(set1); commonSet.retainAll(set2); assertTrue(commonSet.size() == 2); System.out.println("Codec " + ((PayloadType.Audio)commonSet.get(0)).getId()); System.out.println("Codec " + ((PayloadType.Audio)commonSet.get(1)).getId()); assertTrue(commonSet.contains(common1)); assertTrue(commonSet.contains(common2)); }
/** * Test for the difference of payloads when we are handling the same sets. */ public void testDifferenceSameSet() { ArrayList<Audio> set1 = new ArrayList<Audio>(); ArrayList<Audio> set2 = new ArrayList<Audio>(); PayloadType.Audio common1 = new PayloadType.Audio(34, "supercodec-1", 2, 14000); PayloadType.Audio common2 = new PayloadType.Audio(56, "supercodec-2", 1, 44000); PayloadType.Audio common3 = new PayloadType.Audio(0, "supercodec-3", 1, 44000); PayloadType.Audio common4 = new PayloadType.Audio(120, "supercodec-4", 2, 66060); set1.add(common1); set1.add(common2); set1.add(common3); set1.add(common4); set2.add(common1); set2.add(common2); set2.add(common3); set2.add(common4); // Get the difference ArrayList<Audio> commonSet = new ArrayList<Audio>(); commonSet.addAll(set1); commonSet.retainAll(set2); assertTrue(commonSet.size() == 4); assertTrue(commonSet.contains(common1)); assertTrue(commonSet.contains(common2)); }
/** * Return a JMF AudioFormat for a given Jingle Payload type. * Return null if the payload is not supported by this jmf API. * * @param payloadtype payloadtype * @return correspondent audioType */ public static AudioFormat getAudioFormat(PayloadType payloadtype) { switch (payloadtype.getId()) { case 0: return new AudioFormat(AudioFormat.ULAW_RTP); case 3: return new AudioFormat(AudioFormat.GSM_RTP); case 4: return new AudioFormat(AudioFormat.G723_RTP); default: return null; } }
/** * Returns a new JingleMediaSession * * @param payloadType payloadType * @param remote remote Candidate * @param local local Candidate * @return JingleMediaSession JingleMediaSession */ public JingleMediaSession createMediaSession(PayloadType payloadType, final TransportCandidate remote, final TransportCandidate local, final JingleSession jingleSession) { ScreenShareSession session = null; session = new ScreenShareSession(payloadType, remote, local, "Screen", jingleSession); if (encoder != null) { session.setEncoder(encoder); } if (decoder != null) { session.setDecoder(decoder); } return session; }
/** * Returns a new JingleMediaSession * * @param payloadType payloadType * @param remote remote Candidate * @param local local Candidate * @return JingleMediaSession JingleMediaSession */ public JingleMediaSession createMediaSession(PayloadType payloadType, final TransportCandidate remote, final TransportCandidate local, final JingleSession jingleSession) { TestMediaSession session = null; session = new TestMediaSession(payloadType, remote, local, "", jingleSession); return session; }
/** * Return all supported Payloads for this Manager. * * @return The Payload List */ public List<PayloadType> getPayloads() { List<PayloadType> list = new ArrayList<PayloadType>(); if (preferredPayloadType != null) list.add(preferredPayloadType); for (JingleMediaManager manager : managers) { for (PayloadType payloadType : manager.getPayloads()) { if (!list.contains(payloadType) && !payloadType.equals(preferredPayloadType)) list.add(payloadType); } } return list; }
/** * Returns a new JingleMediaSession * * @param payloadType payloadType * @param remote remote Candidate * @param local local Candidate * @return JingleMediaSession JingleMediaSession */ public JingleMediaSession createMediaSession(PayloadType payloadType, final TransportCandidate remote, final TransportCandidate local, final JingleSession jingleSession) { for (JingleMediaManager manager : managers) { if (manager.getPayloads().contains(payloadType)) { return manager.createMediaSession(payloadType, remote, local, jingleSession); } } return null; }
public void triggerContentEstablished() { PayloadType bestCommonAudioPt = getMediaNegotiator().getBestCommonAudioPt(); TransportCandidate bestRemoteCandidate = getTransportNegotiator().getBestRemoteCandidate(); TransportCandidate acceptedLocalCandidate = getTransportNegotiator().getAcceptedLocalCandidate(); // Trigger the session established flag triggerContentEstablished(bestCommonAudioPt, bestRemoteCandidate, acceptedLocalCandidate); }
/** * Trigger a session established event. */ private void triggerContentEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc) { // Let the session know that we've established a content/media segment. JingleSession session = getSession(); if (session != null) { List<JingleListener> listeners = session.getListenersList(); for (JingleListener li : listeners) { if (li instanceof JingleSessionListener) { JingleSessionListener sli = (JingleSessionListener) li; sli.sessionEstablished(pt, rc, lc, session); } } } // Create a media session for each media manager in the session. if (mediaNeg.getMediaManager() != null) { rc.removeCandidateEcho(); lc.removeCandidateEcho(); jingleMediaSession = getMediaNegotiator().getMediaManager().createMediaSession(pt, rc, lc, session); jingleMediaSession.addMediaReceivedListener(session); if (jingleMediaSession != null) { jingleMediaSession.startTrasmit(); jingleMediaSession.startReceive(); for (TransportCandidate candidate : getTransportNegotiator().getOfferedCandidates()) candidate.removeCandidateEcho(); } JingleMediaManager mediaManager = getMediaNegotiator().getMediaManager(); getSession().addJingleMediaSession(mediaManager.getName(), jingleMediaSession); } }
public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) { if (lc instanceof ICECandidate) { if (((ICECandidate) lc).getType().equals("relay")) { RTPBridge rtpBridge = RTPBridge.relaySession(lc.getConnection(), lc.getSessionId(), lc.getPassword(), rc, lc); } } }
/** * Parse an audio payload type. */ public JinglePayloadType parsePayload(final XmlPullParser parser) throws Exception { JinglePayloadType pte = super.parsePayload(parser); PayloadType.Audio pt = new PayloadType.Audio(pte.getPayloadType()); int ptClockRate = 0; try { ptClockRate = Integer.parseInt(parser.getAttributeValue("", "clockrate")); } catch (Exception e) { } pt.setClockRate(ptClockRate); return new JinglePayloadType.Audio(pt); }
/** * Parse an audio payload type. */ public PayloadType parsePayload(final XmlPullParser parser) throws Exception { PayloadType pte = super.parsePayload(parser); PayloadType.Audio pt = new PayloadType.Audio(pte); int ptClockRate = 0; try { ptClockRate = Integer.parseInt(parser.getAttributeValue("", "clockrate")); } catch (Exception e) { } pt.setClockRate(ptClockRate); return pt; }
/** * Adds a audio payload type to the packet. * * @param pt the audio payload type to add. */ public void addPayloadType(final PayloadType pt) { synchronized (payloads) { if (pt == null) { LOGGER.error("Null payload type"); } else { payloads.add(pt); } } }
/** * Adds a list of payloads to the packet. * * @param pts the payloads to add. */ public void addAudioPayloadTypes(final List<PayloadType> pts) { synchronized (payloads) { Iterator<PayloadType> ptIter = pts.iterator(); while (ptIter.hasNext()) { PayloadType.Audio pt = (PayloadType.Audio) ptIter.next(); addPayloadType(new PayloadType.Audio(pt)); } } }
/** * Return the list of Payload types contained in the description. * * @return a list of PayloadType.Audio */ public List<PayloadType> getAudioPayloadTypesList() { ArrayList<PayloadType> result = new ArrayList<PayloadType>(); Iterator<PayloadType> jinglePtsIter = getPayloadTypes(); while (jinglePtsIter.hasNext()) { PayloadType jpt = (PayloadType) jinglePtsIter.next(); if (jpt instanceof PayloadType.Audio) { PayloadType.Audio jpta = (PayloadType.Audio) jpt; result.add(jpta); } } return result; }
/** * Adds a list of payloads to the packet. * * @param pts the payloads to add. */ public void addAudioPayloadTypes(final List<PayloadType.Audio> pts) { synchronized (payloads) { Iterator<PayloadType.Audio> ptIter = pts.iterator(); while (ptIter.hasNext()) { PayloadType.Audio pt = ptIter.next(); addJinglePayloadType(new JinglePayloadType.Audio(pt)); } } }
/** * Return the list of Payload types contained in the description. * * @return a list of PayloadType.Audio */ public ArrayList<PayloadType.Audio> getAudioPayloadTypesList() { ArrayList<PayloadType.Audio> result = new ArrayList<PayloadType.Audio>(); Iterator<JinglePayloadType> jinglePtsIter = getJinglePayloadTypes(); while (jinglePtsIter.hasNext()) { JinglePayloadType jpt = jinglePtsIter.next(); if (jpt instanceof JinglePayloadType.Audio) { JinglePayloadType.Audio jpta = (JinglePayloadType.Audio) jpt; result.add((PayloadType.Audio)jpta.getPayloadType()); } } return result; }
protected String getChildAttributes() { StringBuilder buf = new StringBuilder(); PayloadType pt = getPayloadType(); if (pt instanceof PayloadType.Audio) { PayloadType.Audio pta = (PayloadType.Audio) pt; buf.append(" clockrate=\"").append(pta.getClockRate()).append("\" "); } return buf.toString(); }
public void testEqualsObject() { PayloadType p1 = new PayloadType(0, "pt1", 2); PayloadType p2 = new PayloadType(0, "pt1", 2); assertTrue(p1.equals(p2)); }
/** * Setup API supported Payloads */ private void setupPayloads() { payloads.add(new PayloadType.Audio(3, "gsm")); payloads.add(new PayloadType.Audio(4, "g723")); payloads.add(new PayloadType.Audio(0, "PCMU", 16000)); }
/** * Setup API supported Payloads */ private void setupPayloads() { payloads.add(new PayloadType.Audio(30, "sshare")); }
public PayloadType getPreferredPayloadType() { return super.getPreferredPayloadType(); }
/** * Setup API supported Payloads */ private void setupPayloads() { payloads.add(new PayloadType.Audio(15, "speex")); }
public void setPayloads(List<PayloadType> payloads) { this.payloads.addAll(payloads); }
public PayloadType getPreferredPayloadType() { if (preferredPayloadType != null) return preferredPayloadType; return super.getPreferredPayloadType(); }
public void setPreferredPayloadType(PayloadType preferredPayloadType) { this.preferredPayloadType = preferredPayloadType; }
public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) { }