use of com.sun.voip.SampleRateConverter 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...");
}
use of com.sun.voip.SampleRateConverter in project Openfire by igniterealtime.
the class MemberSender 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, InetSocketAddress memberAddress, byte mediaPayload, byte telephoneEventPayload) {
this.conferenceManager = conferenceManager;
this.memberAddress = memberAddress;
this.telephoneEventPayload = telephoneEventPayload;
this.callHandler = callHandler;
Logger.writeFile("Call " + cp + " MemberSender initialization started ..." + cp.getProtocol());
conferenceMediaInfo = conferenceManager.getMediaInfo();
outSampleRate = conferenceMediaInfo.getSampleRate();
outChannels = conferenceMediaInfo.getChannels();
try {
myMediaInfo = SdpManager.findMediaInfo(mediaPayload);
} catch (ParseException e) {
Logger.println("Call " + cp + " Invalid mediaPayload " + mediaPayload);
callHandler.cancelRequest("Invalid mediaPayload " + mediaPayload);
return;
}
int inSampleRate = myMediaInfo.getSampleRate();
int inChannels = myMediaInfo.getChannels();
/*
* No data is ever sent to an input treatment unless it's a recorder
*/
if (cp.getInputTreatment() == null || cp.isRecorder() == true) {
if (inSampleRate != outSampleRate || inChannels != outChannels) {
Logger.println("Call " + cp + " resample data to send from " + inSampleRate + "/" + inChannels + " to " + outSampleRate + "/" + outChannels);
try {
outSampleRateConverter = new SampleRateConverter(this.toString(), outSampleRate, outChannels, inSampleRate, inChannels);
} catch (IOException e) {
callHandler.cancelRequest(e.getMessage());
return;
}
}
}
senderPacket = new RtpSenderPacket(myMediaInfo.getEncoding(), inSampleRate, inChannels);
if (myMediaInfo.getEncoding() == RtpPacket.SPEEX_ENCODING) {
try {
speexEncoder = new SpeexEncoder(inSampleRate, inChannels);
Logger.println("Call " + cp + " created SpeexEncoder");
} catch (SpeexException e) {
Logger.println("Call " + cp + " Speex initialization for encoding failed: " + e.getMessage());
callHandler.cancelRequest(e.getMessage());
return;
}
}
if (myMediaInfo.getEncoding() == RtpPacket.PCM_ENCODING) {
try {
opusEncoder = Opus.encoder_create(opusSampleRate, opusChannels);
if (opusEncoder == 0) {
Logger.println("Call " + cp + " OPUS encoder creation error ");
callHandler.cancelRequest("OPUS encoder creation error ");
return;
}
} catch (Exception e) {
e.printStackTrace();
}
}
initializationDone = true;
Logger.writeFile("Call " + cp + " MemberSender initialization done...");
}
Aggregations