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

Side by Side Diff: media/cast/receiver/frame_receiver_unittest.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years 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 <deque> 5 #include <deque>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 10 matching lines...) Expand all
21 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
22 22
23 using ::testing::_; 23 using ::testing::_;
24 24
25 namespace media { 25 namespace media {
26 namespace cast { 26 namespace cast {
27 27
28 namespace { 28 namespace {
29 29
30 const int kPacketSize = 1500; 30 const int kPacketSize = 1500;
31 const uint32 kFirstFrameId = 1234; 31 const uint32_t kFirstFrameId = 1234;
32 const int kPlayoutDelayMillis = 100; 32 const int kPlayoutDelayMillis = 100;
33 33
34 class FakeFrameClient { 34 class FakeFrameClient {
35 public: 35 public:
36 FakeFrameClient() : num_called_(0) {} 36 FakeFrameClient() : num_called_(0) {}
37 virtual ~FakeFrameClient() {} 37 virtual ~FakeFrameClient() {}
38 38
39 void AddExpectedResult(uint32 expected_frame_id, 39 void AddExpectedResult(uint32_t expected_frame_id,
40 const base::TimeTicks& expected_playout_time) { 40 const base::TimeTicks& expected_playout_time) {
41 expected_results_.push_back( 41 expected_results_.push_back(
42 std::make_pair(expected_frame_id, expected_playout_time)); 42 std::make_pair(expected_frame_id, expected_playout_time));
43 } 43 }
44 44
45 void DeliverEncodedFrame(scoped_ptr<EncodedFrame> frame) { 45 void DeliverEncodedFrame(scoped_ptr<EncodedFrame> frame) {
46 SCOPED_TRACE(::testing::Message() << "num_called_ is " << num_called_); 46 SCOPED_TRACE(::testing::Message() << "num_called_ is " << num_called_);
47 ASSERT_TRUE(frame) 47 ASSERT_TRUE(frame)
48 << "If at shutdown: There were unsatisfied requests enqueued."; 48 << "If at shutdown: There were unsatisfied requests enqueued.";
49 ASSERT_FALSE(expected_results_.empty()); 49 ASSERT_FALSE(expected_results_.empty());
50 EXPECT_EQ(expected_results_.front().first, frame->frame_id); 50 EXPECT_EQ(expected_results_.front().first, frame->frame_id);
51 EXPECT_EQ(expected_results_.front().second, frame->reference_time); 51 EXPECT_EQ(expected_results_.front().second, frame->reference_time);
52 expected_results_.pop_front(); 52 expected_results_.pop_front();
53 ++num_called_; 53 ++num_called_;
54 } 54 }
55 55
56 int number_times_called() const { return num_called_; } 56 int number_times_called() const { return num_called_; }
57 57
58 private: 58 private:
59 std::deque<std::pair<uint32, base::TimeTicks> > expected_results_; 59 std::deque<std::pair<uint32_t, base::TimeTicks>> expected_results_;
60 int num_called_; 60 int num_called_;
61 61
62 DISALLOW_COPY_AND_ASSIGN(FakeFrameClient); 62 DISALLOW_COPY_AND_ASSIGN(FakeFrameClient);
63 }; 63 };
64 } // namespace 64 } // namespace
65 65
66 class FrameReceiverTest : public ::testing::Test { 66 class FrameReceiverTest : public ::testing::Test {
67 protected: 67 protected:
68 FrameReceiverTest() { 68 FrameReceiverTest() {
69 testing_clock_ = new base::SimpleTestTickClock(); 69 testing_clock_ = new base::SimpleTestTickClock();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 112 }
113 113
114 void FeedOneFrameIntoReceiver() { 114 void FeedOneFrameIntoReceiver() {
115 // Note: For testing purposes, a frame consists of only a single packet. 115 // Note: For testing purposes, a frame consists of only a single packet.
116 receiver_->ProcessParsedPacket( 116 receiver_->ProcessParsedPacket(
117 rtp_header_, &payload_[0], payload_.size()); 117 rtp_header_, &payload_[0], payload_.size());
118 } 118 }
119 119
120 void FeedLipSyncInfoIntoReceiver() { 120 void FeedLipSyncInfoIntoReceiver() {
121 const base::TimeTicks now = testing_clock_->NowTicks(); 121 const base::TimeTicks now = testing_clock_->NowTicks();
122 const int64 rtp_timestamp = (now - start_time_) * 122 const int64_t rtp_timestamp = (now - start_time_) * config_.rtp_timebase /
123 config_.rtp_timebase / base::TimeDelta::FromSeconds(1); 123 base::TimeDelta::FromSeconds(1);
124 CHECK_LE(0, rtp_timestamp); 124 CHECK_LE(0, rtp_timestamp);
125 uint32 ntp_seconds; 125 uint32_t ntp_seconds;
126 uint32 ntp_fraction; 126 uint32_t ntp_fraction;
127 ConvertTimeTicksToNtp(now, &ntp_seconds, &ntp_fraction); 127 ConvertTimeTicksToNtp(now, &ntp_seconds, &ntp_fraction);
128 TestRtcpPacketBuilder rtcp_packet; 128 TestRtcpPacketBuilder rtcp_packet;
129 rtcp_packet.AddSrWithNtp(config_.sender_ssrc, 129 rtcp_packet.AddSrWithNtp(config_.sender_ssrc, ntp_seconds, ntp_fraction,
130 ntp_seconds, ntp_fraction, 130 static_cast<uint32_t>(rtp_timestamp));
131 static_cast<uint32>(rtp_timestamp));
132 ASSERT_TRUE(receiver_->ProcessPacket(rtcp_packet.GetPacket().Pass())); 131 ASSERT_TRUE(receiver_->ProcessPacket(rtcp_packet.GetPacket().Pass()));
133 } 132 }
134 133
135 FrameReceiverConfig config_; 134 FrameReceiverConfig config_;
136 std::vector<uint8> payload_; 135 std::vector<uint8_t> payload_;
137 RtpCastHeader rtp_header_; 136 RtpCastHeader rtp_header_;
138 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment. 137 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment.
139 base::TimeTicks start_time_; 138 base::TimeTicks start_time_;
140 MockCastTransportSender mock_transport_; 139 MockCastTransportSender mock_transport_;
141 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; 140 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_;
142 scoped_refptr<CastEnvironment> cast_environment_; 141 scoped_refptr<CastEnvironment> cast_environment_;
143 FakeFrameClient frame_client_; 142 FakeFrameClient frame_client_;
144 143
145 // Important for the FrameReceiver to be declared last, since its dependencies 144 // Important for the FrameReceiver to be declared last, since its dependencies
146 // must remain alive until after its destruction. 145 // must remain alive until after its destruction.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 209
211 TEST_F(FrameReceiverTest, ReceivesFramesSkippingWhenAppropriate) { 210 TEST_F(FrameReceiverTest, ReceivesFramesSkippingWhenAppropriate) {
212 CreateFrameReceiverOfAudio(); 211 CreateFrameReceiverOfAudio();
213 212
214 SimpleEventSubscriber event_subscriber; 213 SimpleEventSubscriber event_subscriber;
215 cast_environment_->logger()->Subscribe(&event_subscriber); 214 cast_environment_->logger()->Subscribe(&event_subscriber);
216 215
217 EXPECT_CALL(mock_transport_, SendRtcpFromRtpReceiver(_, _, _, _, _, _, _)) 216 EXPECT_CALL(mock_transport_, SendRtcpFromRtpReceiver(_, _, _, _, _, _, _))
218 .WillRepeatedly(testing::Return()); 217 .WillRepeatedly(testing::Return());
219 218
220 const uint32 rtp_advance_per_frame = 219 const uint32_t rtp_advance_per_frame =
221 config_.rtp_timebase / config_.target_frame_rate; 220 config_.rtp_timebase / config_.target_frame_rate;
222 const base::TimeDelta time_advance_per_frame = 221 const base::TimeDelta time_advance_per_frame =
223 base::TimeDelta::FromSeconds(1) / config_.target_frame_rate; 222 base::TimeDelta::FromSeconds(1) / config_.target_frame_rate;
224 223
225 // Feed and process lip sync in receiver. 224 // Feed and process lip sync in receiver.
226 FeedLipSyncInfoIntoReceiver(); 225 FeedLipSyncInfoIntoReceiver();
227 task_runner_->RunTasks(); 226 task_runner_->RunTasks();
228 const base::TimeTicks first_frame_capture_time = testing_clock_->NowTicks(); 227 const base::TimeTicks first_frame_capture_time = testing_clock_->NowTicks();
229 228
230 // Enqueue a request for a frame. 229 // Enqueue a request for a frame.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 312
314 TEST_F(FrameReceiverTest, ReceivesFramesRefusingToSkipAny) { 313 TEST_F(FrameReceiverTest, ReceivesFramesRefusingToSkipAny) {
315 CreateFrameReceiverOfVideo(); 314 CreateFrameReceiverOfVideo();
316 315
317 SimpleEventSubscriber event_subscriber; 316 SimpleEventSubscriber event_subscriber;
318 cast_environment_->logger()->Subscribe(&event_subscriber); 317 cast_environment_->logger()->Subscribe(&event_subscriber);
319 318
320 EXPECT_CALL(mock_transport_, SendRtcpFromRtpReceiver(_, _, _, _, _, _, _)) 319 EXPECT_CALL(mock_transport_, SendRtcpFromRtpReceiver(_, _, _, _, _, _, _))
321 .WillRepeatedly(testing::Return()); 320 .WillRepeatedly(testing::Return());
322 321
323 const uint32 rtp_advance_per_frame = 322 const uint32_t rtp_advance_per_frame =
324 config_.rtp_timebase / config_.target_frame_rate; 323 config_.rtp_timebase / config_.target_frame_rate;
325 const base::TimeDelta time_advance_per_frame = 324 const base::TimeDelta time_advance_per_frame =
326 base::TimeDelta::FromSeconds(1) / config_.target_frame_rate; 325 base::TimeDelta::FromSeconds(1) / config_.target_frame_rate;
327 326
328 // Feed and process lip sync in receiver. 327 // Feed and process lip sync in receiver.
329 FeedLipSyncInfoIntoReceiver(); 328 FeedLipSyncInfoIntoReceiver();
330 task_runner_->RunTasks(); 329 task_runner_->RunTasks();
331 const base::TimeTicks first_frame_capture_time = testing_clock_->NowTicks(); 330 const base::TimeTicks first_frame_capture_time = testing_clock_->NowTicks();
332 331
333 // Enqueue a request for a frame. 332 // Enqueue a request for a frame.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 EXPECT_GE(kFirstFrameId + 3, frame_events[i].frame_id); 411 EXPECT_GE(kFirstFrameId + 3, frame_events[i].frame_id);
413 const int frame_offset = frame_events[i].frame_id - kFirstFrameId; 412 const int frame_offset = frame_events[i].frame_id - kFirstFrameId;
414 EXPECT_EQ(frame_offset * rtp_advance_per_frame, 413 EXPECT_EQ(frame_offset * rtp_advance_per_frame,
415 frame_events[i].rtp_timestamp); 414 frame_events[i].rtp_timestamp);
416 } 415 }
417 cast_environment_->logger()->Unsubscribe(&event_subscriber); 416 cast_environment_->logger()->Unsubscribe(&event_subscriber);
418 } 417 }
419 418
420 } // namespace cast 419 } // namespace cast
421 } // namespace media 420 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698