Chromium Code Reviews| Index: content/shell/test_runner/mock_webrtc_peer_connection_handler.cc |
| diff --git a/content/shell/test_runner/mock_webrtc_peer_connection_handler.cc b/content/shell/test_runner/mock_webrtc_peer_connection_handler.cc |
| index 053bb3193d72489a2adb1ac60764f2a5255b10a2..8cbe000225220f8146ad85c5593d2a9439893862 100644 |
| --- a/content/shell/test_runner/mock_webrtc_peer_connection_handler.cc |
| +++ b/content/shell/test_runner/mock_webrtc_peer_connection_handler.cc |
| @@ -23,6 +23,7 @@ |
| #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" |
| #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h" |
| #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h" |
| +#include "third_party/WebKit/public/platform/WebRTCRtpContributingSource.h" |
| #include "third_party/WebKit/public/platform/WebRTCRtpReceiver.h" |
| #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h" |
| #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" |
| @@ -237,18 +238,76 @@ class MockWebRTCStatsReport : public blink::WebRTCStatsReport { |
| size_t i_; |
| }; |
| +class MockWebRTCRtpContributingSource |
| + : public blink::WebRTCRtpContributingSource { |
| + public: |
| + MockWebRTCRtpContributingSource( |
| + blink::WebRTCRtpContributingSourceType source_type, |
| + double timestamp, |
| + uint32_t source) |
| + : source_type_(source_type), timestamp_(timestamp), source_(source) {} |
| + ~MockWebRTCRtpContributingSource() override {} |
| + |
| + blink::WebRTCRtpContributingSourceType sourceType() const override { |
| + return source_type_; |
| + } |
| + double timestamp() const override { return timestamp_; } |
| + uint32_t source() const override { return source_; } |
| + |
| + private: |
| + blink::WebRTCRtpContributingSourceType source_type_; |
| + double timestamp_; |
| + uint32_t source_; |
| +}; |
| + |
| class MockWebRTCRtpReceiver : public blink::WebRTCRtpReceiver { |
| public: |
| MockWebRTCRtpReceiver(uintptr_t id, const blink::WebMediaStreamTrack& track) |
| - : id_(id), track_(track) {} |
| + : id_(id), track_(track), num_packtes_(0) {} |
|
Taylor_Brandstetter
2017/04/05 19:28:28
Typo, should be num_packets_
hbos_chromium
2017/04/06 08:59:43
Done.
|
| ~MockWebRTCRtpReceiver() override {} |
| uintptr_t id() const override { return id_; } |
| const blink::WebMediaStreamTrack& track() const override { return track_; } |
| + // Every time called, mocks that a new packet has arrived updating the i-th |
| + // CSRC such that the |kNumCSRCsActive| latest updated CSRCs are returned. "i" |
| + // is the sequence number modulo number of CSRCs. Also returns an SSRC with |
| + // the latest timestamp. For example, if 2 out of 3 CSRCs should be active, |
| + // this will return the following "(type, source, timestamp)": |
| + // - 1st call: { (CSRC, 0, 0), (SSRC, 0, 0) } |
| + // - 2nd call: { (CSRC, 0, 0), (CSRC, 1, 5), (SSRC, 0, 5) } |
| + // - 3rd call: { (CSRC, 1, 5), (CSRC, 2, 10), (SSRC, 0, 10) } |
| + // - 4th call: { (CSRC, 2, 10), (CSRC, 0, 15), (SSRC, 0, 15) } |
|
Taylor_Brandstetter
2017/04/05 19:28:28
May want to mention the fact that RTCPeerConnectio
hbos_chromium
2017/04/06 08:59:43
Done.
|
| + blink::WebVector<std::unique_ptr<blink::WebRTCRtpContributingSource>> |
| + getSources() override { |
| + ++num_packtes_; |
| + size_t num_csrcs = std::min(kNumCSRCsActive, num_packtes_); |
| + blink::WebVector<std::unique_ptr<blink::WebRTCRtpContributingSource>> |
| + contributing_sources(num_csrcs + 1); |
| + for (size_t i = 0; i < num_csrcs; ++i) { |
| + size_t sequence_number = num_packtes_ - num_csrcs + i; |
| + contributing_sources[i].reset(new MockWebRTCRtpContributingSource( |
| + blink::WebRTCRtpContributingSourceType::CSRC, |
| + // Return value should include timestamps for the last 10 seconds, we |
| + // pretend |10.0 / kNumCSRCsActive| seconds have passed |
| + // per packet in the sequence, starting from 0. This is not relative |
| + // to any real clock. |
| + sequence_number * 10.0 / kNumCSRCsActive, |
| + sequence_number % kNumCSRCs)); |
| + } |
| + contributing_sources[num_csrcs].reset(new MockWebRTCRtpContributingSource( |
| + blink::WebRTCRtpContributingSourceType::SSRC, |
| + contributing_sources[num_csrcs - 1]->timestamp(), 0)); |
| + return contributing_sources; |
| + } |
| + |
| private: |
| + const size_t kNumCSRCs = 3; |
| + const size_t kNumCSRCsActive = 2; |
| + |
| uintptr_t id_; |
| blink::WebMediaStreamTrack track_; |
| + size_t num_packtes_; |
| }; |
| } // namespace |