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

Side by Side Diff: media/cast/net/rtp/cast_message_builder_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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/test/simple_test_tick_clock.h" 8 #include "base/test/simple_test_tick_clock.h"
9 #include "media/cast/net/rtcp/rtcp.h" 9 #include "media/cast/net/rtcp/rtcp.h"
10 #include "media/cast/net/rtp/cast_message_builder.h" 10 #include "media/cast/net/rtp/cast_message_builder.h"
11 #include "media/cast/net/rtp/framer.h" 11 #include "media/cast/net/rtp/framer.h"
12 #include "media/cast/net/rtp/rtp_defines.h" 12 #include "media/cast/net/rtp/rtp_defines.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace media { 15 namespace media {
16 namespace cast { 16 namespace cast {
17 17
18 namespace { 18 namespace {
19 static const uint32 kSsrc = 0x1234; 19 static const uint32_t kSsrc = 0x1234;
20 static const uint32 kShortTimeIncrementMs = 10; 20 static const uint32_t kShortTimeIncrementMs = 10;
21 static const uint32 kLongTimeIncrementMs = 40; 21 static const uint32_t kLongTimeIncrementMs = 40;
22 static const int64 kStartMillisecond = INT64_C(12345678900000); 22 static const int64_t kStartMillisecond = INT64_C(12345678900000);
23 23
24 typedef std::map<uint32, size_t> MissingPacketsMap; 24 typedef std::map<uint32_t, size_t> MissingPacketsMap;
25 25
26 class NackFeedbackVerification : public RtpPayloadFeedback { 26 class NackFeedbackVerification : public RtpPayloadFeedback {
27 public: 27 public:
28 NackFeedbackVerification() 28 NackFeedbackVerification()
29 : triggered_(false), missing_packets_(), last_frame_acked_(0) {} 29 : triggered_(false), missing_packets_(), last_frame_acked_(0) {}
30 30
31 void CastFeedback(const RtcpCastMessage& cast_feedback) final { 31 void CastFeedback(const RtcpCastMessage& cast_feedback) final {
32 EXPECT_EQ(kSsrc, cast_feedback.media_ssrc); 32 EXPECT_EQ(kSsrc, cast_feedback.media_ssrc);
33 33
34 last_frame_acked_ = cast_feedback.ack_frame_id; 34 last_frame_acked_ = cast_feedback.ack_frame_id;
(...skipping 11 matching lines...) Expand all
46 std::make_pair(frame_it->first, kRtcpCastAllPacketsLost)); 46 std::make_pair(frame_it->first, kRtcpCastAllPacketsLost));
47 } else { 47 } else {
48 missing_packets_.insert( 48 missing_packets_.insert(
49 std::make_pair(frame_it->first, frame_it->second.size())); 49 std::make_pair(frame_it->first, frame_it->second.size()));
50 } 50 }
51 ++frame_it; 51 ++frame_it;
52 } 52 }
53 triggered_ = true; 53 triggered_ = true;
54 } 54 }
55 55
56 size_t num_missing_packets(uint32 frame_id) { 56 size_t num_missing_packets(uint32_t frame_id) {
57 MissingPacketsMap::iterator it; 57 MissingPacketsMap::iterator it;
58 it = missing_packets_.find(frame_id); 58 it = missing_packets_.find(frame_id);
59 if (it == missing_packets_.end()) 59 if (it == missing_packets_.end())
60 return 0; 60 return 0;
61 61
62 return it->second; 62 return it->second;
63 } 63 }
64 64
65 // Holds value for one call. 65 // Holds value for one call.
66 bool triggered() { 66 bool triggered() {
67 bool ret_val = triggered_; 67 bool ret_val = triggered_;
68 triggered_ = false; 68 triggered_ = false;
69 return ret_val; 69 return ret_val;
70 } 70 }
71 71
72 uint32 last_frame_acked() { return last_frame_acked_; } 72 uint32_t last_frame_acked() { return last_frame_acked_; }
73 73
74 private: 74 private:
75 bool triggered_; 75 bool triggered_;
76 MissingPacketsMap missing_packets_; // Missing packets per frame. 76 MissingPacketsMap missing_packets_; // Missing packets per frame.
77 uint32 last_frame_acked_; 77 uint32_t last_frame_acked_;
78 78
79 DISALLOW_COPY_AND_ASSIGN(NackFeedbackVerification); 79 DISALLOW_COPY_AND_ASSIGN(NackFeedbackVerification);
80 }; 80 };
81 } // namespace 81 } // namespace
82 82
83 class CastMessageBuilderTest : public ::testing::Test { 83 class CastMessageBuilderTest : public ::testing::Test {
84 protected: 84 protected:
85 CastMessageBuilderTest() 85 CastMessageBuilderTest()
86 : framer_(&testing_clock_, 86 : framer_(&testing_clock_,
87 &feedback_, 87 &feedback_,
88 kSsrc, 88 kSsrc,
89 true, 89 true,
90 10), 90 10),
91 cast_msg_builder_(new CastMessageBuilder(&testing_clock_, 91 cast_msg_builder_(new CastMessageBuilder(&testing_clock_,
92 &feedback_, 92 &feedback_,
93 &framer_, 93 &framer_,
94 kSsrc, 94 kSsrc,
95 true, 95 true,
96 0)) { 96 0)) {
97 rtp_header_.sender_ssrc = kSsrc; 97 rtp_header_.sender_ssrc = kSsrc;
98 rtp_header_.is_key_frame = false; 98 rtp_header_.is_key_frame = false;
99 testing_clock_.Advance( 99 testing_clock_.Advance(
100 base::TimeDelta::FromMilliseconds(kStartMillisecond)); 100 base::TimeDelta::FromMilliseconds(kStartMillisecond));
101 } 101 }
102 102
103 ~CastMessageBuilderTest() override {} 103 ~CastMessageBuilderTest() override {}
104 104
105 void SetFrameIds(uint32 frame_id, uint32 reference_frame_id) { 105 void SetFrameIds(uint32_t frame_id, uint32_t reference_frame_id) {
106 rtp_header_.frame_id = frame_id; 106 rtp_header_.frame_id = frame_id;
107 rtp_header_.reference_frame_id = reference_frame_id; 107 rtp_header_.reference_frame_id = reference_frame_id;
108 } 108 }
109 109
110 void SetPacketId(uint16 packet_id) { rtp_header_.packet_id = packet_id; } 110 void SetPacketId(uint16_t packet_id) { rtp_header_.packet_id = packet_id; }
111 111
112 void SetMaxPacketId(uint16 max_packet_id) { 112 void SetMaxPacketId(uint16_t max_packet_id) {
113 rtp_header_.max_packet_id = max_packet_id; 113 rtp_header_.max_packet_id = max_packet_id;
114 } 114 }
115 115
116 void SetKeyFrame(bool is_key) { rtp_header_.is_key_frame = is_key; } 116 void SetKeyFrame(bool is_key) { rtp_header_.is_key_frame = is_key; }
117 117
118 void InsertPacket() { 118 void InsertPacket() {
119 bool duplicate; 119 bool duplicate;
120 uint8 payload = 0; 120 uint8_t payload = 0;
121 if (framer_.InsertPacket(&payload, 1, rtp_header_, &duplicate)) { 121 if (framer_.InsertPacket(&payload, 1, rtp_header_, &duplicate)) {
122 cast_msg_builder_->CompleteFrameReceived(rtp_header_.frame_id); 122 cast_msg_builder_->CompleteFrameReceived(rtp_header_.frame_id);
123 } 123 }
124 cast_msg_builder_->UpdateCastMessage(); 124 cast_msg_builder_->UpdateCastMessage();
125 } 125 }
126 126
127 void SetDecoderSlowerThanMaxFrameRate(int max_unacked_frames) { 127 void SetDecoderSlowerThanMaxFrameRate(int max_unacked_frames) {
128 cast_msg_builder_.reset(new CastMessageBuilder(&testing_clock_, 128 cast_msg_builder_.reset(new CastMessageBuilder(&testing_clock_,
129 &feedback_, 129 &feedback_,
130 &framer_, 130 &framer_,
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 } 384 }
385 385
386 TEST_F(CastMessageBuilderTest, SlowDownAck) { 386 TEST_F(CastMessageBuilderTest, SlowDownAck) {
387 SetDecoderSlowerThanMaxFrameRate(3); 387 SetDecoderSlowerThanMaxFrameRate(3);
388 SetFrameIds(0, 0); 388 SetFrameIds(0, 0);
389 SetPacketId(0); 389 SetPacketId(0);
390 SetMaxPacketId(0); 390 SetMaxPacketId(0);
391 SetKeyFrame(true); 391 SetKeyFrame(true);
392 InsertPacket(); 392 InsertPacket();
393 393
394 uint32 frame_id; 394 uint32_t frame_id;
395 testing_clock_.Advance( 395 testing_clock_.Advance(
396 base::TimeDelta::FromMilliseconds(kShortTimeIncrementMs)); 396 base::TimeDelta::FromMilliseconds(kShortTimeIncrementMs));
397 SetKeyFrame(false); 397 SetKeyFrame(false);
398 for (frame_id = 1; frame_id < 3; ++frame_id) { 398 for (frame_id = 1; frame_id < 3; ++frame_id) {
399 EXPECT_TRUE(feedback_.triggered()); 399 EXPECT_TRUE(feedback_.triggered());
400 EXPECT_EQ(frame_id - 1, feedback_.last_frame_acked()); 400 EXPECT_EQ(frame_id - 1, feedback_.last_frame_acked());
401 SetFrameIds(frame_id, frame_id - 1); 401 SetFrameIds(frame_id, frame_id - 1);
402 InsertPacket(); 402 InsertPacket();
403 testing_clock_.Advance( 403 testing_clock_.Advance(
404 base::TimeDelta::FromMilliseconds(kShortTimeIncrementMs)); 404 base::TimeDelta::FromMilliseconds(kShortTimeIncrementMs));
405 } 405 }
406 // We should now have entered the slowdown ACK state. 406 // We should now have entered the slowdown ACK state.
407 uint32 expected_frame_id = 1; 407 uint32_t expected_frame_id = 1;
408 for (; frame_id < 10; ++frame_id) { 408 for (; frame_id < 10; ++frame_id) {
409 if (frame_id % 2) { 409 if (frame_id % 2) {
410 ++expected_frame_id; 410 ++expected_frame_id;
411 EXPECT_TRUE(feedback_.triggered()); 411 EXPECT_TRUE(feedback_.triggered());
412 } else { 412 } else {
413 EXPECT_FALSE(feedback_.triggered()); 413 EXPECT_FALSE(feedback_.triggered());
414 } 414 }
415 EXPECT_EQ(expected_frame_id, feedback_.last_frame_acked()); 415 EXPECT_EQ(expected_frame_id, feedback_.last_frame_acked());
416 SetFrameIds(frame_id, frame_id - 1); 416 SetFrameIds(frame_id, frame_id - 1);
417 InsertPacket(); 417 InsertPacket();
(...skipping 10 matching lines...) Expand all
428 SetFrameIds(frame_id, frame_id - 1); 428 SetFrameIds(frame_id, frame_id - 1);
429 InsertPacket(); 429 InsertPacket();
430 testing_clock_.Advance( 430 testing_clock_.Advance(
431 base::TimeDelta::FromMilliseconds(kShortTimeIncrementMs)); 431 base::TimeDelta::FromMilliseconds(kShortTimeIncrementMs));
432 EXPECT_TRUE(feedback_.triggered()); 432 EXPECT_TRUE(feedback_.triggered());
433 EXPECT_EQ(frame_id, feedback_.last_frame_acked()); 433 EXPECT_EQ(frame_id, feedback_.last_frame_acked());
434 } 434 }
435 435
436 } // namespace cast 436 } // namespace cast
437 } // namespace media 437 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698