OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/test_runner/mock_webrtc_peer_connection_handler.h" | 5 #include "content/shell/test_runner/mock_webrtc_peer_connection_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "content/shell/test_runner/mock_webrtc_data_channel_handler.h" | 15 #include "content/shell/test_runner/mock_webrtc_data_channel_handler.h" |
16 #include "content/shell/test_runner/mock_webrtc_dtmf_sender_handler.h" | 16 #include "content/shell/test_runner/mock_webrtc_dtmf_sender_handler.h" |
17 #include "content/shell/test_runner/test_interfaces.h" | 17 #include "content/shell/test_runner/test_interfaces.h" |
18 #include "content/shell/test_runner/web_test_delegate.h" | 18 #include "content/shell/test_runner/web_test_delegate.h" |
19 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 19 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
20 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 20 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
21 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 21 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
22 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h" | 22 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h" |
23 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" | 23 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" |
24 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h" | 24 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h" |
25 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h " | 25 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h " |
26 #include "third_party/WebKit/public/platform/WebRTCRtpContributingSource.h" | |
26 #include "third_party/WebKit/public/platform/WebRTCRtpReceiver.h" | 27 #include "third_party/WebKit/public/platform/WebRTCRtpReceiver.h" |
27 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h" | 28 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h" |
28 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" | 29 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" |
29 #include "third_party/WebKit/public/platform/WebString.h" | 30 #include "third_party/WebKit/public/platform/WebString.h" |
30 #include "third_party/WebKit/public/platform/WebVector.h" | 31 #include "third_party/WebKit/public/platform/WebVector.h" |
31 | 32 |
32 using namespace blink; | 33 using namespace blink; |
33 | 34 |
34 namespace test_runner { | 35 namespace test_runner { |
35 | 36 |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 return nullptr; | 231 return nullptr; |
231 return std::unique_ptr<blink::WebRTCStats>( | 232 return std::unique_ptr<blink::WebRTCStats>( |
232 new MockWebRTCStats(stats_[i_++])); | 233 new MockWebRTCStats(stats_[i_++])); |
233 } | 234 } |
234 | 235 |
235 private: | 236 private: |
236 std::vector<MockWebRTCStats> stats_; | 237 std::vector<MockWebRTCStats> stats_; |
237 size_t i_; | 238 size_t i_; |
238 }; | 239 }; |
239 | 240 |
241 class MockWebRTCRtpContributingSource | |
242 : public blink::WebRTCRtpContributingSource { | |
243 public: | |
244 MockWebRTCRtpContributingSource( | |
245 blink::WebRTCRtpContributingSourceType source_type, | |
246 double timestamp, | |
247 uint32_t source) | |
248 : source_type_(source_type), timestamp_(timestamp), source_(source) {} | |
249 ~MockWebRTCRtpContributingSource() override {} | |
250 | |
251 blink::WebRTCRtpContributingSourceType sourceType() const override { | |
252 return source_type_; | |
253 } | |
254 double timestamp() const override { return timestamp_; } | |
255 uint32_t source() const override { return source_; } | |
256 | |
257 private: | |
258 blink::WebRTCRtpContributingSourceType source_type_; | |
259 double timestamp_; | |
260 uint32_t source_; | |
261 }; | |
262 | |
240 class MockWebRTCRtpReceiver : public blink::WebRTCRtpReceiver { | 263 class MockWebRTCRtpReceiver : public blink::WebRTCRtpReceiver { |
241 public: | 264 public: |
242 MockWebRTCRtpReceiver(uintptr_t id, const blink::WebMediaStreamTrack& track) | 265 MockWebRTCRtpReceiver(uintptr_t id, const blink::WebMediaStreamTrack& track) |
243 : id_(id), track_(track) {} | 266 : 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.
| |
244 ~MockWebRTCRtpReceiver() override {} | 267 ~MockWebRTCRtpReceiver() override {} |
245 | 268 |
246 uintptr_t id() const override { return id_; } | 269 uintptr_t id() const override { return id_; } |
247 const blink::WebMediaStreamTrack& track() const override { return track_; } | 270 const blink::WebMediaStreamTrack& track() const override { return track_; } |
248 | 271 |
272 // Every time called, mocks that a new packet has arrived updating the i-th | |
273 // CSRC such that the |kNumCSRCsActive| latest updated CSRCs are returned. "i" | |
274 // is the sequence number modulo number of CSRCs. Also returns an SSRC with | |
275 // the latest timestamp. For example, if 2 out of 3 CSRCs should be active, | |
276 // this will return the following "(type, source, timestamp)": | |
277 // - 1st call: { (CSRC, 0, 0), (SSRC, 0, 0) } | |
278 // - 2nd call: { (CSRC, 0, 0), (CSRC, 1, 5), (SSRC, 0, 5) } | |
279 // - 3rd call: { (CSRC, 1, 5), (CSRC, 2, 10), (SSRC, 0, 10) } | |
280 // - 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.
| |
281 blink::WebVector<std::unique_ptr<blink::WebRTCRtpContributingSource>> | |
282 getSources() override { | |
283 ++num_packtes_; | |
284 size_t num_csrcs = std::min(kNumCSRCsActive, num_packtes_); | |
285 blink::WebVector<std::unique_ptr<blink::WebRTCRtpContributingSource>> | |
286 contributing_sources(num_csrcs + 1); | |
287 for (size_t i = 0; i < num_csrcs; ++i) { | |
288 size_t sequence_number = num_packtes_ - num_csrcs + i; | |
289 contributing_sources[i].reset(new MockWebRTCRtpContributingSource( | |
290 blink::WebRTCRtpContributingSourceType::CSRC, | |
291 // Return value should include timestamps for the last 10 seconds, we | |
292 // pretend |10.0 / kNumCSRCsActive| seconds have passed | |
293 // per packet in the sequence, starting from 0. This is not relative | |
294 // to any real clock. | |
295 sequence_number * 10.0 / kNumCSRCsActive, | |
296 sequence_number % kNumCSRCs)); | |
297 } | |
298 contributing_sources[num_csrcs].reset(new MockWebRTCRtpContributingSource( | |
299 blink::WebRTCRtpContributingSourceType::SSRC, | |
300 contributing_sources[num_csrcs - 1]->timestamp(), 0)); | |
301 return contributing_sources; | |
302 } | |
303 | |
249 private: | 304 private: |
305 const size_t kNumCSRCs = 3; | |
306 const size_t kNumCSRCsActive = 2; | |
307 | |
250 uintptr_t id_; | 308 uintptr_t id_; |
251 blink::WebMediaStreamTrack track_; | 309 blink::WebMediaStreamTrack track_; |
310 size_t num_packtes_; | |
252 }; | 311 }; |
253 | 312 |
254 } // namespace | 313 } // namespace |
255 | 314 |
256 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler() | 315 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler() |
257 : weak_factory_(this) {} | 316 : weak_factory_(this) {} |
258 | 317 |
259 MockWebRTCPeerConnectionHandler::~MockWebRTCPeerConnectionHandler() {} | 318 MockWebRTCPeerConnectionHandler::~MockWebRTCPeerConnectionHandler() {} |
260 | 319 |
261 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler( | 320 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler( |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
605 const WebMediaStreamTrack& track) { | 664 const WebMediaStreamTrack& track) { |
606 return new MockWebRTCDTMFSenderHandler(track, interfaces_->GetDelegate()); | 665 return new MockWebRTCDTMFSenderHandler(track, interfaces_->GetDelegate()); |
607 } | 666 } |
608 | 667 |
609 void MockWebRTCPeerConnectionHandler::stop() { | 668 void MockWebRTCPeerConnectionHandler::stop() { |
610 stopped_ = true; | 669 stopped_ = true; |
611 weak_factory_.InvalidateWeakPtrs(); | 670 weak_factory_.InvalidateWeakPtrs(); |
612 } | 671 } |
613 | 672 |
614 } // namespace test_runner | 673 } // namespace test_runner |
OLD | NEW |