Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(458)

Side by Side Diff: content/shell/test_runner/mock_webrtc_peer_connection_handler.cc

Issue 2808113002: Reland of TCRtpReceiver.getContributingSources() added. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/memory/ptr_util.h"
15 #include "content/shell/test_runner/mock_webrtc_data_channel_handler.h" 16 #include "content/shell/test_runner/mock_webrtc_data_channel_handler.h"
16 #include "content/shell/test_runner/mock_webrtc_dtmf_sender_handler.h" 17 #include "content/shell/test_runner/mock_webrtc_dtmf_sender_handler.h"
17 #include "content/shell/test_runner/test_interfaces.h" 18 #include "content/shell/test_runner/test_interfaces.h"
18 #include "content/shell/test_runner/web_test_delegate.h" 19 #include "content/shell/test_runner/web_test_delegate.h"
19 #include "third_party/WebKit/public/platform/WebMediaStream.h" 20 #include "third_party/WebKit/public/platform/WebMediaStream.h"
20 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 21 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
21 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" 22 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
22 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h" 23 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h"
23 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" 24 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h"
24 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h" 25 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h"
25 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h " 26 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h "
27 #include "third_party/WebKit/public/platform/WebRTCRtpContributingSource.h"
26 #include "third_party/WebKit/public/platform/WebRTCRtpReceiver.h" 28 #include "third_party/WebKit/public/platform/WebRTCRtpReceiver.h"
27 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h" 29 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h"
28 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" 30 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h"
29 #include "third_party/WebKit/public/platform/WebString.h" 31 #include "third_party/WebKit/public/platform/WebString.h"
30 #include "third_party/WebKit/public/platform/WebVector.h" 32 #include "third_party/WebKit/public/platform/WebVector.h"
31 33
32 using namespace blink; 34 using namespace blink;
33 35
34 namespace test_runner { 36 namespace test_runner {
35 37
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 return nullptr; 232 return nullptr;
231 return std::unique_ptr<blink::WebRTCStats>( 233 return std::unique_ptr<blink::WebRTCStats>(
232 new MockWebRTCStats(stats_[i_++])); 234 new MockWebRTCStats(stats_[i_++]));
233 } 235 }
234 236
235 private: 237 private:
236 std::vector<MockWebRTCStats> stats_; 238 std::vector<MockWebRTCStats> stats_;
237 size_t i_; 239 size_t i_;
238 }; 240 };
239 241
242 class MockWebRTCRtpContributingSource
243 : public blink::WebRTCRtpContributingSource {
244 public:
245 MockWebRTCRtpContributingSource(
246 blink::WebRTCRtpContributingSourceType source_type,
247 double timestamp_ms,
248 uint32_t source)
249 : source_type_(source_type),
250 timestamp_ms_(timestamp_ms),
251 source_(source) {}
252 ~MockWebRTCRtpContributingSource() override {}
253
254 blink::WebRTCRtpContributingSourceType SourceType() const override {
255 return source_type_;
256 }
257 double TimestampMs() const override { return timestamp_ms_; }
258 uint32_t Source() const override { return source_; }
259
260 private:
261 blink::WebRTCRtpContributingSourceType source_type_;
262 double timestamp_ms_;
263 uint32_t source_;
264 };
265
240 class MockWebRTCRtpReceiver : public blink::WebRTCRtpReceiver { 266 class MockWebRTCRtpReceiver : public blink::WebRTCRtpReceiver {
241 public: 267 public:
242 MockWebRTCRtpReceiver(uintptr_t id, const blink::WebMediaStreamTrack& track) 268 MockWebRTCRtpReceiver(uintptr_t id, const blink::WebMediaStreamTrack& track)
243 : id_(id), track_(track) {} 269 : id_(id), track_(track), num_packets_(0) {}
244 ~MockWebRTCRtpReceiver() override {} 270 ~MockWebRTCRtpReceiver() override {}
245 271
246 uintptr_t Id() const override { return id_; } 272 uintptr_t Id() const override { return id_; }
247 const blink::WebMediaStreamTrack& Track() const override { return track_; } 273 const blink::WebMediaStreamTrack& Track() const override { return track_; }
248 274
275 // Every time called, mocks that a new packet has arrived updating the i-th
276 // CSRC such that the |kNumCSRCsActive| latest updated CSRCs are returned. "i"
277 // is the sequence number modulo number of CSRCs. Also returns an SSRC with
278 // the latest timestamp. For example, if 2 out of 3 CSRCs should be active,
279 // this will return the following "(type, source, timestamp)":
280 // - 1st call: { (CSRC, 0, 0), (SSRC, 0, 0) }
281 // - 2nd call: { (CSRC, 0, 0000), (CSRC, 1, 5000), (SSRC, 0, 5000) }
282 // - 3rd call: { (CSRC, 1, 5000), (CSRC, 2, 10000), (SSRC, 0, 10000) }
283 // - 4th call: { (CSRC, 2, 10000), (CSRC, 0, 15000), (SSRC, 0, 15000) }
284 // RTCPeerConnection-getReceivers.html depends on this behavior.
285 blink::WebVector<std::unique_ptr<blink::WebRTCRtpContributingSource>>
286 GetSources() override {
287 ++num_packets_;
288 size_t num_csrcs = std::min(kNumCSRCsActive, num_packets_);
289 blink::WebVector<std::unique_ptr<blink::WebRTCRtpContributingSource>>
290 contributing_sources(num_csrcs + 1);
291 for (size_t i = 0; i < num_csrcs; ++i) {
292 size_t sequence_number = num_packets_ - num_csrcs + i;
293 contributing_sources[i] =
294 base::MakeUnique<MockWebRTCRtpContributingSource>(
295 blink::WebRTCRtpContributingSourceType::CSRC,
296 // Return value should include timestamps for the last 10 seconds,
297 // we pretend |10000.0 / kNumCSRCsActive| milliseconds have passed
298 // per packet in the sequence, starting from 0. This is not
299 // relative to any real clock.
300 sequence_number * 10000.0 / kNumCSRCsActive,
301 sequence_number % kNumCSRCs);
302 }
303 contributing_sources[num_csrcs] =
304 base::MakeUnique<MockWebRTCRtpContributingSource>(
305 blink::WebRTCRtpContributingSourceType::SSRC,
306 contributing_sources[num_csrcs - 1]->TimestampMs(), 0);
307 return contributing_sources;
308 }
309
249 private: 310 private:
311 const size_t kNumCSRCs = 3;
312 const size_t kNumCSRCsActive = 2;
313
250 uintptr_t id_; 314 uintptr_t id_;
251 blink::WebMediaStreamTrack track_; 315 blink::WebMediaStreamTrack track_;
316 size_t num_packets_;
252 }; 317 };
253 318
254 } // namespace 319 } // namespace
255 320
256 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler() 321 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler()
257 : weak_factory_(this) {} 322 : weak_factory_(this) {}
258 323
259 MockWebRTCPeerConnectionHandler::~MockWebRTCPeerConnectionHandler() {} 324 MockWebRTCPeerConnectionHandler::~MockWebRTCPeerConnectionHandler() {}
260 325
261 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler( 326 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler(
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 const WebMediaStreamTrack& track) { 674 const WebMediaStreamTrack& track) {
610 return new MockWebRTCDTMFSenderHandler(track, interfaces_->GetDelegate()); 675 return new MockWebRTCDTMFSenderHandler(track, interfaces_->GetDelegate());
611 } 676 }
612 677
613 void MockWebRTCPeerConnectionHandler::Stop() { 678 void MockWebRTCPeerConnectionHandler::Stop() {
614 stopped_ = true; 679 stopped_ = true;
615 weak_factory_.InvalidateWeakPtrs(); 680 weak_factory_.InvalidateWeakPtrs();
616 } 681 }
617 682
618 } // namespace test_runner 683 } // namespace test_runner
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698