Search in sources :

Example 76 with ParseException

use of java.text.ParseException in project Openfire by igniterealtime.

the class MemberReceiver method initialize.

/**
     * Initialize this member.  The call has been established and
     * we now know the port at which the member (CallParticipant)
     * listens for data.
     */
public void initialize(ConferenceManager conferenceManager, CallHandler callHandler, byte mediaPayload, byte telephoneEventPayload, RtcpReceiver rtcpReceiver) {
    this.conferenceManager = conferenceManager;
    this.telephoneEventPayload = telephoneEventPayload;
    this.rtcpReceiver = rtcpReceiver;
    this.callHandler = callHandler;
    Logger.writeFile("Call " + cp + " MemberReceiver initialization started..." + cp.getProtocol());
    conferenceWhisperGroup = conferenceManager.getWGManager().getConferenceWhisperGroup();
    MediaInfo conferenceMediaInfo = conferenceManager.getMediaInfo();
    int outSampleRate = conferenceMediaInfo.getSampleRate();
    int outChannels = conferenceMediaInfo.getChannels();
    jitterManager = new JitterManager("Call " + cp.toString());
    if (cp.voiceDetection()) {
        if (Logger.logLevel >= Logger.LOG_MOREINFO) {
            Logger.println("Call " + cp + " starting speech Detector...");
        }
        speechDetector = new SpeechDetector(this.toString(), conferenceMediaInfo);
    }
    if (cp.getProtocol() != null && ("WebRtc".equals(cp.getProtocol()) || "Rtmfp".equals(cp.getProtocol()) || "Speaker".equals(cp.getProtocol()))) {
        conferenceManager.getConferenceReceiver().addMember(this);
        if (cp.getJoinConfirmationTimeout() == 0) {
            joinConfirmationReceived = true;
            readyToReceiveData = true;
            playJoinTreatment();
        }
    } else {
        try {
            myMediaInfo = SdpManager.findMediaInfo(mediaPayload);
        } catch (ParseException e) {
            Logger.println("Call " + cp + " Invalid mediaPayload " + mediaPayload);
            callHandler.cancelRequest("Invalid mediaPayload " + mediaPayload);
            return;
        }
        Logger.println("My media info:  " + myMediaInfo);
        int inSampleRate = myMediaInfo.getSampleRate();
        int inChannels = myMediaInfo.getChannels();
        //if (cp.getPhoneNumber().indexOf("@") >= 0) {
        ConferenceReceiver conferenceReceiver = conferenceManager.getConferenceReceiver();
        conferenceManager.getConferenceReceiver().addMember(this);
        /*
		 * For input treatments, the treatment manager does the resampling.
		 */
        if (cp.getInputTreatment() == null) {
            if (inSampleRate != outSampleRate || inChannels != outChannels) {
                try {
                    Logger.println("Call " + cp + " resample received data from " + inSampleRate + "/" + inChannels + " to " + outSampleRate + "/" + outChannels);
                    inSampleRateConverter = new SampleRateConverter(this.toString(), inSampleRate, inChannels, outSampleRate, outChannels);
                } catch (IOException e) {
                    callHandler.cancelRequest(e.getMessage());
                    return;
                }
            }
        }
        packet = new RtpReceiverPacket(cp.toString(), myMediaInfo.getEncoding(), inSampleRate, inChannels);
        if (initializationDone) {
            /*
			 * This is a re-initialize
			 */
            return;
        }
        //if (telephoneEventPayload == 0 && (cp.dtmfDetection() || cp.getJoinConfirmationTimeout() != 0)) {
        Logger.println("Call " + cp + " starting dtmf Detector..." + telephoneEventPayload + " " + cp.dtmfDetection());
        dtmfDecoder = new DtmfDecoder(this, myMediaInfo);
        if (myMediaInfo.getEncoding() == RtpPacket.SPEEX_ENCODING) {
            try {
                speexDecoder = new SpeexDecoder(inSampleRate, inChannels);
                Logger.println("Call " + cp + " created SpeexDecoder");
            } catch (SpeexException e) {
                Logger.println("Call " + cp + e.getMessage());
                callHandler.cancelRequest(e.getMessage());
                return;
            }
        } else if (myMediaInfo.getEncoding() == RtpPacket.PCM_ENCODING) {
            try {
                opusDecoder = Opus.decoder_create(opusSampleRate, opusChannels);
                if (opusDecoder == 0) {
                    Logger.println("Call " + cp + " OPUS decoder creation error ");
                    callHandler.cancelRequest("OPUS decoder creation error ");
                    return;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (cp.getJoinConfirmationTimeout() == 0) {
            joinConfirmationReceived = true;
            readyToReceiveData = true;
            playJoinTreatment();
        }
        if (cp.getInputTreatment() != null && cp.getInputTreatment().length() > 0) {
            String absolutePath = cp.getInputTreatment();
            try {
                if (cp.getRecordDirectory() != null) {
                    absolutePath = Recorder.getAbsolutePath(cp.getRecordDirectory(), cp.getInputTreatment());
                }
                if (Logger.logLevel >= Logger.LOG_INFO) {
                    Logger.println("Call " + cp + " New input treatment:  " + absolutePath);
                }
                synchronized (this) {
                    new InputTreatment(this, absolutePath, 0, conferenceMediaInfo.getSampleRate(), conferenceMediaInfo.getChannels());
                }
            } catch (IOException e) {
                e.printStackTrace();
                Logger.println("MemberReceiver:  Invalid input treatment " + absolutePath + ":  " + e.getMessage());
                callHandler.cancelRequest("Invalid input treatment " + absolutePath + ":  " + e.getMessage());
                return;
            }
        }
        String forwardingCallId = cp.getForwardingCallId();
        if (forwardingCallId != null) {
            CallHandler forwardingCall = CallHandler.findCall(forwardingCallId);
            if (forwardingCall == null) {
                Logger.println("Invalid forwardingCallId:  " + forwardingCallId);
                callHandler.cancelRequest("Invalid forwardingCallId:  " + forwardingCallId);
                return;
            }
            ConferenceMember m = forwardingCall.getMember();
            m.getMemberReceiver().addForwardMember(member.getMemberSender());
            /*
			 * If the source of the data is an input treatment, there
			 * is no need to have the forwarding call receive data
			 * from the remote side.
			 */
            if (cp.getInputTreatment() != null) {
                m.setConferenceMuted(true);
            }
        }
    }
    initializationDone = true;
    Logger.writeFile("Call " + cp + " MemberReceiver initialization done...");
}
Also used : SampleRateConverter(com.sun.voip.SampleRateConverter) IOException(java.io.IOException) JitterManager(com.sun.voip.JitterManager) Point(java.awt.Point) SpeexException(com.sun.voip.SpeexException) SpeexException(com.sun.voip.SpeexException) SocketException(java.net.SocketException) NoSuchElementException(java.util.NoSuchElementException) ParseException(java.text.ParseException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) MediaInfo(com.sun.voip.MediaInfo) ParseException(java.text.ParseException) SpeexDecoder(com.sun.voip.SpeexDecoder) SpeechDetector(com.sun.voip.SpeechDetector) RtpReceiverPacket(com.sun.voip.RtpReceiverPacket)

Example 77 with ParseException

use of java.text.ParseException in project Openfire by igniterealtime.

the class SipUtil method getUserNameFromSdp.

public static String getUserNameFromSdp(Request request) {
    byte[] rawContent = request.getRawContent();
    if (rawContent == null) {
        return null;
    }
    String sdpBody = new String(rawContent);
    SdpInfo sdpInfo;
    try {
        sdpInfo = SdpManager.parseSdp(sdpBody);
    } catch (ParseException e) {
        return null;
    }
    return sdpInfo.getUserName();
}
Also used : SdpInfo(com.sun.voip.SdpInfo) ParseException(java.text.ParseException)

Example 78 with ParseException

use of java.text.ParseException in project Openfire by igniterealtime.

the class SipUtil method isSipUri.

public static boolean isSipUri(String phoneNumber) {
    if (phoneNumber == null || phoneNumber.indexOf("sip:") != 0) {
        return false;
    }
    Address address = null;
    SipURI sipURI = null;
    String host = null;
    String user = null;
    try {
        address = addressFactory.createAddress(phoneNumber);
        sipURI = (SipURI) address.getURI();
        host = sipURI.getHost();
        user = sipURI.getUser();
    } catch (ParseException e) {
        return false;
    }
    return user != null;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) InetAddress(java.net.InetAddress) ParseException(java.text.ParseException)

Example 79 with ParseException

use of java.text.ParseException in project Openfire by igniterealtime.

the class SipUtil method sendOK.

/*
     * Send an OK with no SDP
     */
public void sendOK(Request request, ServerTransaction st) throws TransactionDoesNotExistException, ParseException, SipException {
    Response response = messageFactory.createResponse(Response.OK, request);
    ToHeader to = (ToHeader) response.getHeader(ToHeader.NAME);
    if (to == null) {
        Logger.println("something is wrong, no to header...");
        return;
    }
    try {
        if (to.getTag() == null || to.getTag().trim().length() == 0) {
            Dialog dialog = st.getDialog();
            to.setTag(Integer.toString(dialog.hashCode()));
        }
    } catch (ParseException ex) {
        Logger.println("can't set to tag");
        return;
    }
    /*
	 * Contact Header (where subsequent requests should be sent to)
         * e.g. Contact: "Awarenex" <sip:Awarenex@152.70.1.43:5060>;
         *   where   "Awarenex" <sip:... == (local Address)
         */
    Address address = (Address) to.getAddress();
    SipURI toURI = (SipURI) address.getURI();
    SipURI contactURI = addressFactory.createSipURI(toURI.getUser(), ourPublicIpAddress);
    contactURI.setPort(ourPublicSipPort);
    Address contactAddress = addressFactory.createAddress(contactURI);
    contactAddress.setDisplayName(to.getName());
    ContactHeader contactHeader = headerFactory.createContactHeader(contactAddress);
    response.addHeader(contactHeader);
    try {
        st.sendResponse(response);
    } catch (InvalidArgumentException e) {
        Logger.println("SendOk:  " + e.getMessage());
        throw new SipException("Failed to send response:  " + e.getMessage());
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) InetAddress(java.net.InetAddress) ParseException(java.text.ParseException)

Example 80 with ParseException

use of java.text.ParseException in project Openfire by igniterealtime.

the class WGManager method destroyWhisperGroup.

public void destroyWhisperGroup(String id) throws ParseException {
    synchronized (whisperGroups) {
        WhisperGroup whisperGroup = findWhisperGroup(id);
        if (whisperGroup == null) {
            Logger.println("can't find whisperGroup " + id);
            throw new ParseException("can't find whisperGroup " + id, 0);
        }
        synchronized (whisperGroup) {
            ArrayList members = whisperGroup.getMembers();
            /*
		 * We don't want to be called recursively when we
		 * remove the last member!
		 */
            whisperGroup.setTransient(false);
            while (members.size() > 0) {
                ConferenceMember member = (ConferenceMember) members.get(0);
                member.removeCall(id);
            }
        }
        whisperGroups.remove(whisperGroup);
    }
    if (Logger.logLevel >= Logger.LOG_INFO) {
        Logger.println("Whisper group " + id + " destroyed.");
    }
}
Also used : ArrayList(java.util.ArrayList) ParseException(java.text.ParseException)

Aggregations

ParseException (java.text.ParseException)1141 Date (java.util.Date)435 SimpleDateFormat (java.text.SimpleDateFormat)387 IOException (java.io.IOException)118 DateFormat (java.text.DateFormat)117 Calendar (java.util.Calendar)104 ArrayList (java.util.ArrayList)98 Test (org.junit.Test)58 HashMap (java.util.HashMap)45 Matcher (java.util.regex.Matcher)39 File (java.io.File)38 GregorianCalendar (java.util.GregorianCalendar)34 Map (java.util.Map)28 BigDecimal (java.math.BigDecimal)23 Timestamp (java.sql.Timestamp)21 List (java.util.List)21 Locale (java.util.Locale)20 SipException (javax.sip.SipException)20 InputStream (java.io.InputStream)19 TimeZone (java.util.TimeZone)19