Index: webrtc/api/peerconnection_unittest.cc |
diff --git a/webrtc/api/peerconnection_unittest.cc b/webrtc/api/peerconnection_unittest.cc |
index 24411ab729060c09c9658aab987b49e0b9db85f5..4d9bf8f8bd3e88af38712c44a376909ac7ce58c9 100644 |
--- a/webrtc/api/peerconnection_unittest.cc |
+++ b/webrtc/api/peerconnection_unittest.cc |
@@ -146,6 +146,37 @@ class SignalingMessageReceiver { |
virtual ~SignalingMessageReceiver() {} |
}; |
+class MockRtpReceiverObserver : public webrtc::RtpReceiverObserverInterface { |
+ public: |
+ MockRtpReceiverObserver() |
pthatcher1
2016/06/08 17:35:55
I'd suggest just passing the kind (or expected cri
|
+ : is_first_audio_packet_recevied_(false), |
+ is_first_video_packet_recevied_(false), |
+ kind_("unset") {} |
+ |
+ void OnFirstPacketReceived(cricket::MediaType media_type) override { |
+ if (media_type == cricket::MEDIA_TYPE_AUDIO) { |
+ is_first_audio_packet_recevied_ = true; |
+ } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { |
+ is_first_video_packet_recevied_ = true; |
+ } |
pthatcher1
2016/06/08 17:35:55
Given the unlikelyhood of getting the wrong media
|
+ } |
+ |
+ void SetKind(std::string kind) { kind_ = kind; } |
+ |
+ std::string kind() { return kind_; } |
+ |
+ bool IsFirstAudioPacketReceived() { return is_first_audio_packet_recevied_; } |
pthatcher1
2016/06/08 17:35:55
Using lowercase first_x_packet_received() is proba
|
+ |
+ bool IsFirstVideoPacketReceived() { return is_first_video_packet_recevied_; } |
+ |
+ virtual ~MockRtpReceiverObserver() {} |
+ |
+ private: |
+ bool is_first_audio_packet_recevied_; |
+ bool is_first_video_packet_recevied_; |
pthatcher1
2016/06/08 17:35:55
You can use "= false" here and avoid needing to se
pthatcher1
2016/06/08 17:35:55
Just "first_x_packet_received_" would be enough.
|
+ std::string kind_; |
pthatcher1
2016/06/08 17:35:55
I think it might make more sense to store the expe
|
+}; |
+ |
class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
public SignalingMessageReceiver, |
public ObserverInterface { |
@@ -777,6 +808,11 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
return pc()->ice_gathering_state(); |
} |
+ std::vector<std::unique_ptr<MockRtpReceiverObserver>> const& |
+ rtp_receiver_observers() { |
+ return rtp_receiver_observers_; |
+ } |
+ |
private: |
class DummyDtmfObserver : public DtmfSenderObserverInterface { |
public: |
@@ -867,6 +903,8 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
std::unique_ptr<SessionDescriptionInterface> desc( |
webrtc::CreateSessionDescription("offer", msg, nullptr)); |
EXPECT_TRUE(DoSetRemoteDescription(desc.release())); |
+ // Register the RtpReceiverObserver after receivers are created. |
+ SetRtpReceiverObservers(); |
std::unique_ptr<SessionDescriptionInterface> answer; |
EXPECT_TRUE(DoCreateAnswer(&answer)); |
std::string sdp; |
@@ -883,6 +921,8 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
std::unique_ptr<SessionDescriptionInterface> desc( |
webrtc::CreateSessionDescription("answer", msg, nullptr)); |
EXPECT_TRUE(DoSetRemoteDescription(desc.release())); |
+ // Register the RtpReceiverObserver after receivers are created. |
+ SetRtpReceiverObservers(); |
} |
bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc, |
@@ -940,6 +980,16 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
return true; |
} |
+ void SetRtpReceiverObservers() { |
+ for (auto receiver : pc()->GetReceivers()) { |
+ std::unique_ptr<MockRtpReceiverObserver> observer( |
+ new MockRtpReceiverObserver()); |
+ observer->SetKind(receiver->track()->kind()); |
+ receiver->SetObserver(observer.get()); |
+ rtp_receiver_observers_.push_back(std::move(observer)); |
+ } |
+ } |
+ |
bool DoSetRemoteDescription(SessionDescriptionInterface* desc) { |
rtc::scoped_refptr<MockSetSessionDescriptionObserver> |
observer(new rtc::RefCountedObject< |
@@ -1023,6 +1073,8 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
rtc::scoped_refptr<DataChannelInterface> data_channel_; |
std::unique_ptr<MockDataChannelObserver> data_observer_; |
+ |
+ std::vector<std::unique_ptr<MockRtpReceiverObserver>> rtp_receiver_observers_; |
}; |
class P2PTestConductor : public testing::Test { |
@@ -1312,6 +1364,23 @@ class P2PTestConductor : public testing::Test { |
return old; |
} |
+ void CheckRtpReceiverObserverAreCalled(PeerConnectionTestClient* client) { |
+ for (auto const& observer : client->rtp_receiver_observers()) { |
+ if (observer->kind() == webrtc::MediaStreamTrackInterface::kAudioKind) { |
+ EXPECT_TRUE_WAIT(observer->IsFirstAudioPacketReceived(), |
+ kMaxWaitForFramesMs); |
+ EXPECT_FALSE(observer->IsFirstVideoPacketReceived()); |
+ } else if (observer->kind() == |
+ webrtc::MediaStreamTrackInterface::kVideoKind) { |
+ EXPECT_FALSE(observer->IsFirstAudioPacketReceived()); |
+ EXPECT_TRUE_WAIT(observer->IsFirstVideoPacketReceived(), |
+ kMaxWaitForFramesMs); |
+ } else { |
+ EXPECT_TRUE(false) << "Unknown RtpReceiver kind."; |
+ } |
pthatcher1
2016/06/08 17:35:55
With my other suggestion about ASSERT_EQ(media_typ
Zhi Huang
2016/06/09 00:37:36
This make the code much cleaner.
|
+ } |
+ } |
+ |
private: |
// |worker_thread_| is used by both |initiating_client_| and |
// |receiving_client_|. Must be destroyed last. |
@@ -1329,6 +1398,13 @@ class P2PTestConductor : public testing::Test { |
// https://code.google.com/p/webrtc/issues/detail?id=1205 for details. |
#if !defined(THREAD_SANITIZER) |
+TEST_F(P2PTestConductor, TestRtpReceiverObserverCallbackFunction) { |
+ ASSERT_TRUE(CreateTestClients()); |
+ LocalP2PTest(); |
+ CheckRtpReceiverObserverAreCalled(initializing_client()); |
+ CheckRtpReceiverObserverAreCalled(receiving_client()); |
+} |
+ |
// This test sets up a Jsep call between two parties and test Dtmf. |
// TODO(holmer): Disabled due to sometimes crashing on buildbots. |
// See issue webrtc/2378. |