Search in sources :

Example 1 with JitterManager

use of com.sun.voip.JitterManager 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)

Aggregations

JitterManager (com.sun.voip.JitterManager)1 MediaInfo (com.sun.voip.MediaInfo)1 RtpReceiverPacket (com.sun.voip.RtpReceiverPacket)1 SampleRateConverter (com.sun.voip.SampleRateConverter)1 SpeechDetector (com.sun.voip.SpeechDetector)1 SpeexDecoder (com.sun.voip.SpeexDecoder)1 SpeexException (com.sun.voip.SpeexException)1 Point (java.awt.Point)1 IOException (java.io.IOException)1 SocketException (java.net.SocketException)1 UnknownHostException (java.net.UnknownHostException)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 ParseException (java.text.ParseException)1 NoSuchElementException (java.util.NoSuchElementException)1