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

Side by Side Diff: media/cast/net/rtp/rtp_packetizer_unittest.cc

Issue 1377273003: cast: cleanup rtp header and parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 5 years, 2 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
« no previous file with comments | « media/cast/net/rtp/rtp_packet_builder.cc ('k') | media/cast/net/rtp/rtp_parser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "media/cast/net/rtp/rtp_packetizer.h" 5 #include "media/cast/net/rtp/rtp_packetizer.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/test/simple_test_tick_clock.h" 10 #include "base/test/simple_test_tick_clock.h"
11 #include "media/cast/logging/logging_impl.h" 11 #include "media/cast/logging/logging_impl.h"
12 #include "media/cast/logging/simple_event_subscriber.h" 12 #include "media/cast/logging/simple_event_subscriber.h"
13 #include "media/cast/net/pacing/paced_sender.h" 13 #include "media/cast/net/pacing/paced_sender.h"
14 #include "media/cast/net/rtp/packet_storage.h" 14 #include "media/cast/net/rtp/packet_storage.h"
15 #include "media/cast/net/rtp/rtp_header_parser.h" 15 #include "media/cast/net/rtp/rtp_parser.h"
16 #include "media/cast/test/fake_single_thread_task_runner.h" 16 #include "media/cast/test/fake_single_thread_task_runner.h"
17 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
18 18
19 namespace media { 19 namespace media {
20 namespace cast { 20 namespace cast {
21 21
22 namespace { 22 namespace {
23 static const int kPayload = 127; 23 static const int kPayload = 127;
24 static const uint32 kTimestampMs = 10; 24 static const uint32 kTimestampMs = 10;
25 static const uint16 kSeqNum = 33; 25 static const uint16 kSeqNum = 33;
26 static const int kMaxPacketLength = 1500; 26 static const int kMaxPacketLength = 1500;
27 static const int kSsrc = 0x12345; 27 static const int kSsrc = 0x12345;
28 static const unsigned int kFrameSize = 5000; 28 static const unsigned int kFrameSize = 5000;
29 } 29 }
30 30
31 class TestRtpPacketTransport : public PacketSender { 31 class TestRtpPacketTransport : public PacketSender {
32 public: 32 public:
33 explicit TestRtpPacketTransport(RtpPacketizerConfig config) 33 explicit TestRtpPacketTransport(RtpPacketizerConfig config)
34 : config_(config), 34 : config_(config),
35 sequence_number_(kSeqNum), 35 sequence_number_(kSeqNum),
36 packets_sent_(0), 36 packets_sent_(0),
37 expected_number_of_packets_(0), 37 expected_number_of_packets_(0),
38 expected_packet_id_(0), 38 expected_packet_id_(0),
39 expected_frame_id_(0), 39 expected_frame_id_(0),
40 expected_rtp_timestamp_(0) {} 40 expected_rtp_timestamp_(0) {}
41 41
42 void VerifyRtpHeader(const RtpCastTestHeader& rtp_header) { 42 void VerifyRtpHeader(const RtpCastHeader& rtp_header) {
43 VerifyCommonRtpHeader(rtp_header); 43 VerifyCommonRtpHeader(rtp_header);
44 VerifyCastRtpHeader(rtp_header); 44 VerifyCastRtpHeader(rtp_header);
45 } 45 }
46 46
47 void VerifyCommonRtpHeader(const RtpCastTestHeader& rtp_header) { 47 void VerifyCommonRtpHeader(const RtpCastHeader& rtp_header) {
48 EXPECT_EQ(kPayload, rtp_header.payload_type); 48 EXPECT_EQ(kPayload, rtp_header.payload_type);
49 EXPECT_EQ(sequence_number_, rtp_header.sequence_number); 49 EXPECT_EQ(sequence_number_, rtp_header.sequence_number);
50 EXPECT_EQ(expected_rtp_timestamp_, rtp_header.rtp_timestamp); 50 EXPECT_EQ(expected_rtp_timestamp_, rtp_header.rtp_timestamp);
51 EXPECT_EQ(config_.ssrc, rtp_header.ssrc); 51 EXPECT_EQ(config_.ssrc, rtp_header.sender_ssrc);
52 EXPECT_EQ(0, rtp_header.num_csrcs); 52 EXPECT_EQ(0, rtp_header.num_csrcs);
53 } 53 }
54 54
55 void VerifyCastRtpHeader(const RtpCastTestHeader& rtp_header) { 55 void VerifyCastRtpHeader(const RtpCastHeader& rtp_header) {
56 EXPECT_FALSE(rtp_header.is_key_frame); 56 EXPECT_FALSE(rtp_header.is_key_frame);
57 EXPECT_EQ(expected_frame_id_, rtp_header.frame_id); 57 EXPECT_EQ(expected_frame_id_, rtp_header.frame_id);
58 EXPECT_EQ(expected_packet_id_, rtp_header.packet_id); 58 EXPECT_EQ(expected_packet_id_, rtp_header.packet_id);
59 EXPECT_EQ(expected_number_of_packets_ - 1, rtp_header.max_packet_id); 59 EXPECT_EQ(expected_number_of_packets_ - 1, rtp_header.max_packet_id);
60 EXPECT_TRUE(rtp_header.is_reference); 60 EXPECT_TRUE(rtp_header.is_reference);
61 EXPECT_EQ(expected_frame_id_ - 1u, rtp_header.reference_frame_id); 61 EXPECT_EQ(expected_frame_id_ - 1u, rtp_header.reference_frame_id);
62 } 62 }
63 63
64 bool SendPacket(PacketRef packet, const base::Closure& cb) final { 64 bool SendPacket(PacketRef packet, const base::Closure& cb) final {
65 ++packets_sent_; 65 ++packets_sent_;
66 RtpHeaderParser parser(&packet->data[0], packet->data.size()); 66 RtpParser parser(kSsrc, kPayload);
67 RtpCastTestHeader rtp_header; 67 RtpCastHeader rtp_header;
68 parser.Parse(&rtp_header); 68 const uint8* payload_data;
69 size_t payload_size;
70 parser.ParsePacket(&packet->data[0], packet->data.size(), &rtp_header,
71 &payload_data, &payload_size);
69 VerifyRtpHeader(rtp_header); 72 VerifyRtpHeader(rtp_header);
70 ++sequence_number_; 73 ++sequence_number_;
71 ++expected_packet_id_; 74 ++expected_packet_id_;
72 return true; 75 return true;
73 } 76 }
74 77
75 int64 GetBytesSent() final { return 0; } 78 int64 GetBytesSent() final { return 0; }
76 79
77 size_t number_of_packets_received() const { return packets_sent_; } 80 size_t number_of_packets_received() const { return packets_sent_; }
78 81
79 void set_expected_number_of_packets(size_t expected_number_of_packets) { 82 void set_expected_number_of_packets(size_t expected_number_of_packets) {
80 expected_number_of_packets_ = expected_number_of_packets; 83 expected_number_of_packets_ = expected_number_of_packets;
81 } 84 }
82 85
83 void set_rtp_timestamp(uint32 rtp_timestamp) { 86 void set_rtp_timestamp(uint32 rtp_timestamp) {
84 expected_rtp_timestamp_ = rtp_timestamp; 87 expected_rtp_timestamp_ = rtp_timestamp;
85 } 88 }
86 89
87 RtpPacketizerConfig config_; 90 RtpPacketizerConfig config_;
88 uint32 sequence_number_; 91 uint32 sequence_number_;
89 size_t packets_sent_; 92 size_t packets_sent_;
90 size_t number_of_packets_; 93 size_t number_of_packets_;
91 size_t expected_number_of_packets_; 94 size_t expected_number_of_packets_;
92 // Assuming packets arrive in sequence. 95 // Assuming packets arrive in sequence.
93 int expected_packet_id_; 96 int expected_packet_id_;
94 uint32 expected_frame_id_; 97 uint32 expected_frame_id_;
95 uint32 expected_rtp_timestamp_; 98 uint32 expected_rtp_timestamp_;
96 99
100 private:
97 DISALLOW_COPY_AND_ASSIGN(TestRtpPacketTransport); 101 DISALLOW_COPY_AND_ASSIGN(TestRtpPacketTransport);
98 }; 102 };
99 103
100 class RtpPacketizerTest : public ::testing::Test { 104 class RtpPacketizerTest : public ::testing::Test {
101 protected: 105 protected:
102 RtpPacketizerTest() 106 RtpPacketizerTest()
103 : task_runner_(new test::FakeSingleThreadTaskRunner(&testing_clock_)) { 107 : task_runner_(new test::FakeSingleThreadTaskRunner(&testing_clock_)) {
104 config_.sequence_number = kSeqNum; 108 config_.sequence_number = kSeqNum;
105 config_.ssrc = kSsrc; 109 config_.ssrc = kSsrc;
106 config_.payload_type = kPayload; 110 config_.payload_type = kPayload;
(...skipping 26 matching lines...) Expand all
133 base::SimpleTestTickClock testing_clock_; 137 base::SimpleTestTickClock testing_clock_;
134 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; 138 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_;
135 EncodedFrame video_frame_; 139 EncodedFrame video_frame_;
136 PacketStorage packet_storage_; 140 PacketStorage packet_storage_;
137 RtpPacketizerConfig config_; 141 RtpPacketizerConfig config_;
138 scoped_ptr<TestRtpPacketTransport> transport_; 142 scoped_ptr<TestRtpPacketTransport> transport_;
139 LoggingImpl logging_; 143 LoggingImpl logging_;
140 scoped_ptr<PacedSender> pacer_; 144 scoped_ptr<PacedSender> pacer_;
141 scoped_ptr<RtpPacketizer> rtp_packetizer_; 145 scoped_ptr<RtpPacketizer> rtp_packetizer_;
142 146
147 private:
143 DISALLOW_COPY_AND_ASSIGN(RtpPacketizerTest); 148 DISALLOW_COPY_AND_ASSIGN(RtpPacketizerTest);
144 }; 149 };
145 150
146 TEST_F(RtpPacketizerTest, SendStandardPackets) { 151 TEST_F(RtpPacketizerTest, SendStandardPackets) {
147 size_t expected_num_of_packets = kFrameSize / kMaxPacketLength + 1; 152 size_t expected_num_of_packets = kFrameSize / kMaxPacketLength + 1;
148 transport_->set_expected_number_of_packets(expected_num_of_packets); 153 transport_->set_expected_number_of_packets(expected_num_of_packets);
149 transport_->set_rtp_timestamp(video_frame_.rtp_timestamp); 154 transport_->set_rtp_timestamp(video_frame_.rtp_timestamp);
150 155
151 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(kTimestampMs)); 156 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(kTimestampMs));
152 video_frame_.reference_time = testing_clock_.NowTicks(); 157 video_frame_.reference_time = testing_clock_.NowTicks();
(...skipping 14 matching lines...) Expand all
167 video_frame_.reference_time = testing_clock_.NowTicks(); 172 video_frame_.reference_time = testing_clock_.NowTicks();
168 rtp_packetizer_->SendFrameAsPackets(video_frame_); 173 rtp_packetizer_->SendFrameAsPackets(video_frame_);
169 RunTasks(33 + 1); 174 RunTasks(33 + 1);
170 EXPECT_EQ(expected_num_of_packets, rtp_packetizer_->send_packet_count()); 175 EXPECT_EQ(expected_num_of_packets, rtp_packetizer_->send_packet_count());
171 EXPECT_EQ(kFrameSize, rtp_packetizer_->send_octet_count()); 176 EXPECT_EQ(kFrameSize, rtp_packetizer_->send_octet_count());
172 EXPECT_EQ(expected_num_of_packets, transport_->number_of_packets_received()); 177 EXPECT_EQ(expected_num_of_packets, transport_->number_of_packets_received());
173 } 178 }
174 179
175 } // namespace cast 180 } // namespace cast
176 } // namespace media 181 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/net/rtp/rtp_packet_builder.cc ('k') | media/cast/net/rtp/rtp_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698