aboutsummaryrefslogtreecommitdiff
path: root/talk/app
diff options
context:
space:
mode:
authormallinath@webrtc.org <mallinath@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d>2014-02-03 16:57:16 +0000
committermallinath@webrtc.org <mallinath@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d>2014-02-03 16:57:16 +0000
commit67ee6b9a6260fa80b83326c4b4fec8857c0e578c (patch)
treed3fa9d2520edad8f96494a9e0f9e247c9ab8a54f /talk/app
parent422fdbf5028ac2540599170675dcf1af38545c22 (diff)
downloadwebrtc-67ee6b9a6260fa80b83326c4b4fec8857c0e578c.tar.gz
Update talk to 60923971
Review URL: https://webrtc-codereview.appspot.com/7909004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5475 4adac7df-926f-26a2-2b94-8c16560cd09d
Diffstat (limited to 'talk/app')
-rw-r--r--talk/app/webrtc/jsepsessiondescription.cc16
-rw-r--r--talk/app/webrtc/jsepsessiondescription_unittest.cc22
-rw-r--r--talk/app/webrtc/mediastreamhandler.cc36
-rw-r--r--talk/app/webrtc/mediastreamhandler.h27
-rw-r--r--talk/app/webrtc/mediastreaminterface.h22
-rw-r--r--talk/app/webrtc/peerconnectioninterface_unittest.cc1
-rw-r--r--talk/app/webrtc/webrtcsession.cc2
-rw-r--r--talk/app/webrtc/webrtcsession_unittest.cc4
8 files changed, 115 insertions, 15 deletions
diff --git a/talk/app/webrtc/jsepsessiondescription.cc b/talk/app/webrtc/jsepsessiondescription.cc
index 8ec145808a..d7b37b5d76 100644
--- a/talk/app/webrtc/jsepsessiondescription.cc
+++ b/talk/app/webrtc/jsepsessiondescription.cc
@@ -118,9 +118,6 @@ bool JsepSessionDescription::AddCandidate(
}
if (mediasection_index >= number_of_mediasections())
return false;
- if (candidate_collection_[mediasection_index].HasCandidate(candidate)) {
- return true; // Silently ignore this candidate if we already have it.
- }
const std::string content_name =
description_->contents()[mediasection_index].name;
const cricket::TransportInfo* transport_info =
@@ -137,10 +134,15 @@ bool JsepSessionDescription::AddCandidate(
updated_candidate.set_password(transport_info->description.ice_pwd);
}
- candidate_collection_[mediasection_index].add(
- new JsepIceCandidate(candidate->sdp_mid(),
- static_cast<int>(mediasection_index),
- updated_candidate));
+ scoped_ptr<JsepIceCandidate> updated_candidate_wrapper(
+ new JsepIceCandidate(candidate->sdp_mid(),
+ static_cast<int>(mediasection_index),
+ updated_candidate));
+ if (!candidate_collection_[mediasection_index].HasCandidate(
+ updated_candidate_wrapper.get()))
+ candidate_collection_[mediasection_index].add(
+ updated_candidate_wrapper.release());
+
return true;
}
diff --git a/talk/app/webrtc/jsepsessiondescription_unittest.cc b/talk/app/webrtc/jsepsessiondescription_unittest.cc
index 671df36d96..55eb3d5392 100644
--- a/talk/app/webrtc/jsepsessiondescription_unittest.cc
+++ b/talk/app/webrtc/jsepsessiondescription_unittest.cc
@@ -204,6 +204,28 @@ TEST_F(JsepSessionDescriptionTest, AddBadCandidate) {
EXPECT_FALSE(jsep_desc_->AddCandidate(&bad_candidate2));
}
+// Tests that repeatedly adding the same candidate, with or without credentials,
+// does not increase the number of candidates in the description.
+TEST_F(JsepSessionDescriptionTest, AddCandidateDuplicates) {
+ JsepIceCandidate jsep_candidate("", 0, candidate_);
+ EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
+ EXPECT_EQ(1u, jsep_desc_->candidates(0)->count());
+
+ // Add the same candidate again. It should be ignored.
+ EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
+ EXPECT_EQ(1u, jsep_desc_->candidates(0)->count());
+
+ // Create a new candidate, identical except that the ufrag and pwd are now
+ // populated.
+ candidate_.set_username(kCandidateUfragVoice);
+ candidate_.set_password(kCandidatePwdVoice);
+ JsepIceCandidate jsep_candidate_with_credentials("", 0, candidate_);
+
+ // This should also be identified as redundant and ignored.
+ EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate_with_credentials));
+ EXPECT_EQ(1u, jsep_desc_->candidates(0)->count());
+}
+
// Test that we can serialize a JsepSessionDescription and deserialize it again.
TEST_F(JsepSessionDescriptionTest, SerializeDeserialize) {
std::string sdp = Serialize(jsep_desc_.get());
diff --git a/talk/app/webrtc/mediastreamhandler.cc b/talk/app/webrtc/mediastreamhandler.cc
index b09af7892f..932d55ee7b 100644
--- a/talk/app/webrtc/mediastreamhandler.cc
+++ b/talk/app/webrtc/mediastreamhandler.cc
@@ -56,14 +56,38 @@ void TrackHandler::OnChanged() {
}
}
+LocalAudioSinkAdapter::LocalAudioSinkAdapter() : sink_(NULL) {}
+
+LocalAudioSinkAdapter::~LocalAudioSinkAdapter() {}
+
+void LocalAudioSinkAdapter::OnData(const void* audio_data,
+ int bits_per_sample,
+ int sample_rate,
+ int number_of_channels,
+ int number_of_frames) {
+ talk_base::CritScope lock(&lock_);
+ if (sink_) {
+ sink_->OnData(audio_data, bits_per_sample, sample_rate,
+ number_of_channels, number_of_frames);
+ }
+}
+
+void LocalAudioSinkAdapter::SetSink(cricket::AudioRenderer::Sink* sink) {
+ talk_base::CritScope lock(&lock_);
+ ASSERT(!sink || !sink_);
+ sink_ = sink;
+}
+
LocalAudioTrackHandler::LocalAudioTrackHandler(
AudioTrackInterface* track,
uint32 ssrc,
AudioProviderInterface* provider)
: TrackHandler(track, ssrc),
audio_track_(track),
- provider_(provider) {
+ provider_(provider),
+ sink_adapter_(new LocalAudioSinkAdapter()) {
OnEnabledChanged();
+ track->AddSink(sink_adapter_.get());
}
LocalAudioTrackHandler::~LocalAudioTrackHandler() {
@@ -74,6 +98,7 @@ void LocalAudioTrackHandler::OnStateChanged() {
}
void LocalAudioTrackHandler::Stop() {
+ audio_track_->RemoveSink(sink_adapter_.get());
cricket::AudioOptions options;
provider_->SetAudioSend(ssrc(), false, options, NULL);
}
@@ -84,8 +109,13 @@ void LocalAudioTrackHandler::OnEnabledChanged() {
options = static_cast<LocalAudioSource*>(
audio_track_->GetSource())->options();
}
- provider_->SetAudioSend(ssrc(), audio_track_->enabled(), options,
- audio_track_->GetRenderer());
+
+ // Use the renderer if the audio track has one, otherwise use the sink
+ // adapter owned by this class.
+ cricket::AudioRenderer* renderer = audio_track_->GetRenderer() ?
+ audio_track_->GetRenderer() : sink_adapter_.get();
+ ASSERT(renderer);
+ provider_->SetAudioSend(ssrc(), audio_track_->enabled(), options, renderer);
}
RemoteAudioTrackHandler::RemoteAudioTrackHandler(
diff --git a/talk/app/webrtc/mediastreamhandler.h b/talk/app/webrtc/mediastreamhandler.h
index 0cd34d615a..625de85019 100644
--- a/talk/app/webrtc/mediastreamhandler.h
+++ b/talk/app/webrtc/mediastreamhandler.h
@@ -40,6 +40,7 @@
#include "talk/app/webrtc/mediastreamprovider.h"
#include "talk/app/webrtc/peerconnectioninterface.h"
#include "talk/base/thread.h"
+#include "talk/media/base/audiorenderer.h"
namespace webrtc {
@@ -67,6 +68,28 @@ class TrackHandler : public ObserverInterface {
bool enabled_;
};
+// LocalAudioSinkAdapter receives data callback as a sink to the local
+// AudioTrack, and passes the data to the sink of AudioRenderer.
+class LocalAudioSinkAdapter : public AudioTrackSinkInterface,
+ public cricket::AudioRenderer {
+ public:
+ LocalAudioSinkAdapter();
+ virtual ~LocalAudioSinkAdapter();
+
+ private:
+ // AudioSinkInterface implementation.
+ virtual void OnData(const void* audio_data, int bits_per_sample,
+ int sample_rate, int number_of_channels,
+ int number_of_frames) OVERRIDE;
+
+ // cricket::AudioRenderer implementation.
+ virtual void SetSink(cricket::AudioRenderer::Sink* sink) OVERRIDE;
+
+ cricket::AudioRenderer::Sink* sink_;
+ // Critical section protecting |sink_|.
+ talk_base::CriticalSection lock_;
+};
+
// LocalAudioTrackHandler listen to events on a local AudioTrack instance
// connected to a PeerConnection and orders the |provider| to executes the
// requested change.
@@ -86,6 +109,10 @@ class LocalAudioTrackHandler : public TrackHandler {
private:
AudioTrackInterface* audio_track_;
AudioProviderInterface* provider_;
+
+ // Used to pass the data callback from the |audio_track_| to the other
+ // end of cricket::AudioRenderer.
+ talk_base::scoped_ptr<LocalAudioSinkAdapter> sink_adapter_;
};
// RemoteAudioTrackHandler listen to events on a remote AudioTrack instance
diff --git a/talk/app/webrtc/mediastreaminterface.h b/talk/app/webrtc/mediastreaminterface.h
index b2c4468fb9..96d09428ab 100644
--- a/talk/app/webrtc/mediastreaminterface.h
+++ b/talk/app/webrtc/mediastreaminterface.h
@@ -147,15 +147,33 @@ class VideoTrackInterface : public MediaStreamTrackInterface {
class AudioSourceInterface : public MediaSourceInterface {
};
+// Interface for receiving audio data from a AudioTrack.
+class AudioTrackSinkInterface {
+ public:
+ virtual void OnData(const void* audio_data,
+ int bits_per_sample,
+ int sample_rate,
+ int number_of_channels,
+ int number_of_frames) = 0;
+ protected:
+ virtual ~AudioTrackSinkInterface() {}
+};
+
class AudioTrackInterface : public MediaStreamTrackInterface {
public:
// TODO(xians): Figure out if the following interface should be const or not.
virtual AudioSourceInterface* GetSource() const = 0;
+ // Adds/Removes a sink that will receive the audio data from the track.
+ // TODO(xians): Make them pure virtual after Chrome implements these
+ // interfaces.
+ virtual void AddSink(AudioTrackSinkInterface* sink) {}
+ virtual void RemoveSink(AudioTrackSinkInterface* sink) {}
+
// Gets a pointer to the audio renderer of this AudioTrack.
// The pointer is valid for the lifetime of this AudioTrack.
- // TODO(xians): Make the following interface pure virtual once Chrome has its
- // implementation.
+ // TODO(xians): Remove the following interface after Chrome switches to
+ // AddSink() and RemoveSink() interfaces.
virtual cricket::AudioRenderer* GetRenderer() { return NULL; }
protected:
diff --git a/talk/app/webrtc/peerconnectioninterface_unittest.cc b/talk/app/webrtc/peerconnectioninterface_unittest.cc
index f9d5e2eee8..98e0645839 100644
--- a/talk/app/webrtc/peerconnectioninterface_unittest.cc
+++ b/talk/app/webrtc/peerconnectioninterface_unittest.cc
@@ -180,7 +180,6 @@ class MockPeerConnectionObserver : public PeerConnectionObserver {
EXPECT_EQ(pc_->ice_gathering_state(), new_state);
}
virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
-
EXPECT_NE(PeerConnectionInterface::kIceGatheringNew,
pc_->ice_gathering_state());
diff --git a/talk/app/webrtc/webrtcsession.cc b/talk/app/webrtc/webrtcsession.cc
index 0de46e71bf..59d72709f3 100644
--- a/talk/app/webrtc/webrtcsession.cc
+++ b/talk/app/webrtc/webrtcsession.cc
@@ -786,7 +786,7 @@ bool WebRtcSession::ProcessIceMessage(const IceCandidateInterface* candidate) {
return false;
}
- return UseCandidatesInSessionDescription(remote_desc_.get());
+ return UseCandidate(candidate);
}
bool WebRtcSession::GetTrackIdBySsrc(uint32 ssrc, std::string* id) {
diff --git a/talk/app/webrtc/webrtcsession_unittest.cc b/talk/app/webrtc/webrtcsession_unittest.cc
index 6d3a58131e..ba58936e39 100644
--- a/talk/app/webrtc/webrtcsession_unittest.cc
+++ b/talk/app/webrtc/webrtcsession_unittest.cc
@@ -1421,10 +1421,12 @@ TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
EXPECT_EQ(1, candidates->at(0)->candidate().component());
EXPECT_EQ(2, candidates->at(1)->candidate().component());
+ // |ice_candidate3| is identical to |ice_candidate2|. It can be added
+ // successfully, but the total count of candidates will not increase.
candidate.set_component(2);
JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
- ASSERT_EQ(3u, candidates->count());
+ ASSERT_EQ(2u, candidates->count());
JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));