
net.sourceforge.peers.media.CaptureRtpSender Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of phone Show documentation
Show all versions of phone Show documentation
This Java SoftPhone base on Peers
/*
This file is part of Peers, a java SIP softphone.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Copyright 2007-2013 Yohann Martineau
*/
package net.sourceforge.peers.media;
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.util.concurrent.CountDownLatch;
import net.sourceforge.peers.Logger;
import net.sourceforge.peers.rtp.RFC3551;
import net.sourceforge.peers.rtp.RtpSession;
import net.sourceforge.peers.sdp.Codec;
public class CaptureRtpSender {
public static final int PIPE_SIZE = 4096;
private RtpSession rtpSession;
private Capture capture;
private Encoder encoder;
private RtpSender rtpSender;
public CaptureRtpSender(RtpSession rtpSession, SoundSource soundSource,
boolean mediaDebug, Codec codec, Logger logger, String peersHome)
throws IOException {
super();
this.rtpSession = rtpSession;
// the use of PipedInputStream and PipedOutputStream in Capture,
// Encoder and RtpSender imposes a synchronization point at the
// end of life of those threads to a void read end dead exceptions
CountDownLatch latch = new CountDownLatch(3);
PipedOutputStream encodedDataOutput = new PipedOutputStream();
PipedInputStream encodedDataInput = null;
try {
encodedDataInput = new PipedInputStream(encodedDataOutput,
PIPE_SIZE);
} catch (IOException e) {
logger.error("input/output error");
}
rtpSender = new RtpSender(encodedDataInput, rtpSession, mediaDebug,
codec, logger, peersHome, latch);
PipedOutputStream rawDataOutput = new PipedOutputStream();
PipedInputStream rawDataInput = null;
try {
rawDataInput = new PipedInputStream(rawDataOutput, PIPE_SIZE);
} catch (IOException e) {
logger.error("input/output error", e);
//TODO Jerry Cai fix this issue for incoming send DTMF
// return;
}
capture = new Capture(rawDataOutput, soundSource, logger, latch);
switch (codec.getPayloadType()) {
case RFC3551.PAYLOAD_TYPE_PCMU:
encoder = new PcmuEncoder(rawDataInput, encodedDataOutput,
mediaDebug, logger, peersHome, latch);
break;
case RFC3551.PAYLOAD_TYPE_PCMA:
encoder = new PcmaEncoder(rawDataInput, encodedDataOutput,
mediaDebug, logger, peersHome, latch);
break;
default:
encoder = new PcmuEncoder(rawDataInput, encodedDataOutput,
mediaDebug, logger, peersHome, latch);
break;
}
}
public void start() throws IOException {
capture.setStopped(false);
encoder.setStopped(false);
rtpSender.setStopped(false);
Thread captureThread = new Thread(capture,
Capture.class.getSimpleName());
Thread encoderThread = new Thread(encoder,
Encoder.class.getSimpleName());
Thread rtpSenderThread = new Thread(rtpSender,
RtpSender.class.getSimpleName());
captureThread.start();
encoderThread.start();
rtpSenderThread.start();
}
public void stop() {
if (capture != null) {
capture.setStopped(true);
}
if (encoder != null) {
encoder.setStopped(true);
}
if (rtpSender != null) {
rtpSender.setStopped(true);
}
}
public synchronized RtpSession getRtpSession() {
return rtpSession;
}
public RtpSender getRtpSender() {
return rtpSender;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy