Commit 64d374b7 authored by Pali Rohár's avatar Pali Rohár

libjingle: Fix processing control rtcp packets

parent 7b04b688
......@@ -147,13 +147,18 @@ LinphoneVoiceChannel::LinphoneVoiceChannel(LinphoneMediaEngine*eng)
talk_base::Thread *thread = talk_base::ThreadManager::Instance()->CurrentThread();
talk_base::SocketServer *ss = thread->socketserver();
socket_.reset(ss->CreateAsyncSocket(SOCK_DGRAM));
socket_.reset(ss->CreateAsyncSocket(SOCK_DGRAM));
socket_->Bind(talk_base::SocketAddress("localhost", 0)); /* 0 means that OS will choose some free port */
port1 = socket_->GetLocalAddress().port(); /* and here we get port choosed by OS */
port2 = PORT_UNUSED;
captport = socket_->GetLocalAddress().port(); /* and here we get port choosed by OS */
socket_->SignalReadEvent.connect(this, &LinphoneVoiceChannel::OnIncomingData);
socketRtcp_.reset(ss->CreateAsyncSocket(SOCK_DGRAM));
socketRtcp_->Bind(talk_base::SocketAddress("localhost", captport+1));
socketRtcp_->SignalReadEvent.connect(this, &LinphoneVoiceChannel::OnIncomingRtcp);
playport = PORT_UNUSED;
audio_stream_ = audio_stream_new(-1, 0); /* -1 means that function will choose some free port */
}
......@@ -226,10 +231,10 @@ bool LinphoneVoiceChannel::SetSendCodecs(const std::vector<AudioCodec>& codecs)
if (!captcard)
return false;
if (audio_stream_start_now(audio_stream_, &av_profile, "localhost", port1, port1+1, pt_, 250, playcard, captcard, 0))
if (audio_stream_start_now(audio_stream_, &av_profile, "localhost", captport, captport+1, pt_, 250, playcard, captcard, 0))
return false;
port2 = rtp_session_get_local_port(audio_stream_get_rtp_session(audio_stream_));
playport = rtp_session_get_local_port(audio_stream_get_rtp_session(audio_stream_));
return true;
}
......@@ -247,20 +252,21 @@ bool LinphoneVoiceChannel::SetSend(SendFlags flag) {
}
void LinphoneVoiceChannel::OnPacketReceived(talk_base::Buffer* packet) {
const void* data = packet->data();
int len = packet->length();
uint8 buf[2048];
memcpy(buf, data, len);
if (port2 == PORT_UNUSED)
if (playport == PORT_UNUSED)
return;
/* We may receive packets with payload type 13: comfort noise. Linphone can't
* handle them, so let's ignore those packets.
*/
int payloadtype = buf[1] & 0x7f;
int payloadtype = ((const uint8*)packet->data())[1] & 0x7f;
if (play_ && payloadtype != 13)
socket_->SendTo(buf, len, talk_base::SocketAddress("localhost",port2));
socket_->SendTo(packet->data(), packet->length(), talk_base::SocketAddress("localhost", playport));
}
void LinphoneVoiceChannel::OnRtcpReceived(talk_base::Buffer* packet) {
if (playport == PORT_UNUSED)
return;
socketRtcp_->SendTo(packet->data(), packet->length(), talk_base::SocketAddress("localhost", playport+1));
}
void LinphoneVoiceChannel::StartRing(bool bIncomingCall)
......@@ -298,14 +304,22 @@ void LinphoneVoiceChannel::StopRing()
void LinphoneVoiceChannel::OnIncomingData(talk_base::AsyncSocket *s)
{
char *buf[2048];
int len;
len = s->Recv(buf, sizeof(buf));
char buf[2048];
int len = s->Recv(buf, sizeof(buf));
talk_base::Buffer packet(buf, len, sizeof(buf));
if (network_interface_ && !mute_)
network_interface_->SendPacket(&packet);
}
void LinphoneVoiceChannel::OnIncomingRtcp(talk_base::AsyncSocket *s)
{
char buf[2048];
int len = s->Recv(buf, sizeof(buf));
talk_base::Buffer packet(buf, len, sizeof(buf));
if (network_interface_)
network_interface_->SendRtcp(&packet);
}
}
#endif // HAVE_LINPHONE
......@@ -132,7 +132,7 @@ class LinphoneVoiceChannel : public VoiceMediaChannel {
// Implement pure virtual methods of MediaChannel.
virtual void OnPacketReceived(talk_base::Buffer* packet);
virtual void OnRtcpReceived(talk_base::Buffer* packet) { OnPacketReceived(packet); }
virtual void OnRtcpReceived(talk_base::Buffer* packet);
virtual bool Mute(bool on) { return mute_; }
virtual bool SetSendBandwidth(bool autobw, int bps) { return true; }
virtual bool SetOptions(int options) { return true; }
......@@ -158,10 +158,12 @@ class LinphoneVoiceChannel : public VoiceMediaChannel {
LinphoneMediaEngine *engine_;
RingStream* ring_stream_;
talk_base::scoped_ptr<talk_base::AsyncSocket> socket_;
talk_base::scoped_ptr<talk_base::AsyncSocket> socketRtcp_;
void OnIncomingData(talk_base::AsyncSocket *s);
void OnIncomingRtcp(talk_base::AsyncSocket *s);
int port1; // local port for audio_stream
int port2; // local port for rtp
int captport; // local port for audio_stream
int playport; // local port for rtp
DISALLOW_COPY_AND_ASSIGN(LinphoneVoiceChannel);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment