我正在进行VoIP项目。 我有一个通过TCP从我的手机到我的电脑的音频流。我需要获取此流并通过RTP(使用SIP)将其发送到设备。
我可以使用JAIN-SIP与SIP中的设备通话,但我无法发送音频,我不知道该怎么做。 我正在使用JMF,我已经定义了一个自定义DataSource,但我不能用它创建处理器...
有什么想法吗?
感谢您的帮助:)
代码:
在RTPLayer构造函数中:
dataSrc = new DataSource(is, contentType);
dataSrc.connect();
Format[] format = { new AudioFormat(AudioFormat.LINEAR, sampleRate, sampleSizeInBits, channel) };
ProcessorModel pm = new ProcessorModel(dataSrc, format, new ContentDescriptor(contentType));
p = Manager.createRealizedProcessor(pm);
自定义数据源:
import java.io.IOException;
import java.io.InputStream;
import javax.media.Duration;
import javax.media.Time;
import javax.media.protocol.ContentDescriptor;
import javax.media.protocol.InputSourceStream;
import javax.media.protocol.PullDataSource;
import javax.media.protocol.PullSourceStream;
public class DataSource extends PullDataSource {
private InputSourceStream[] m_sources;
private ContentDescriptor m_cd;
private boolean m_connected;
private InputStream m_is;
public DataSource(InputStream is, String contentType) {
super();
m_connected = false;
m_cd = new ContentDescriptor(contentType);
m_is = is;
}
@Override
public PullSourceStream[] getStreams() {
if (!m_connected) {
throw new java.lang.Error("Source is unconnected.");
}
return m_sources;
}
@Override
public void connect() throws IOException {
m_sources = new InputSourceStream[1];
m_sources[0] = new InputSourceStream(m_is, m_cd);
m_connected = true;
}
@Override
public void disconnect() {
if (m_connected)
m_connected = false;
}
@Override
public String getContentType() {
if (!m_connected)
throw new Error("Source is unconnected.");
return m_cd.getContentType();
}
@Override
public Object getControl(String arg0) {
return null;
}
@Override
public Object[] getControls() {
return null;
}
@Override
public Time getDuration() {
return Duration.DURATION_UNKNOWN;
}
@Override
public void start() throws IOException {
}
@Override
public void stop() throws IOException {
}
}
InputStream:
socket = server.accept();
InputStream is = socket.getInputStream();
rtpLayer = new RTPLayer(getHost(), remoteAdress, is, SEND_RCV_RTP_PORT, remotePort, ContentDescriptor.RAW_RTP, sampleRate, bufferSize, 1);