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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_format_vp8_test_helper.cc

Issue 2522553002: RtpPacketizer::NextPacket fills RtpPacket instead of payload. (Closed)
Patch Set: Named kTheMagicSix Created 4 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 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 11
12 #include "webrtc/modules/rtp_rtcp/source/rtp_format_vp8_test_helper.h" 12 #include "webrtc/modules/rtp_rtcp/source/rtp_format_vp8_test_helper.h"
13 13
14 #include "webrtc/test/gtest.h" 14 #include "webrtc/test/gtest.h"
15 15
16 namespace webrtc { 16 namespace webrtc {
17 17
18 namespace test { 18 namespace test {
19 19
20 constexpr RtpPacketToSend::ExtensionManager* kNoExtensions = nullptr;
21
20 RtpFormatVp8TestHelper::RtpFormatVp8TestHelper(const RTPVideoHeaderVP8* hdr) 22 RtpFormatVp8TestHelper::RtpFormatVp8TestHelper(const RTPVideoHeaderVP8* hdr)
21 : payload_data_(NULL), 23 : packet_(kNoExtensions),
22 buffer_(NULL), 24 payload_data_(NULL),
23 data_ptr_(NULL), 25 data_ptr_(NULL),
24 fragmentation_(NULL), 26 fragmentation_(NULL),
25 hdr_info_(hdr), 27 hdr_info_(hdr),
26 payload_start_(0), 28 payload_start_(0),
27 payload_size_(0), 29 payload_size_(0),
28 buffer_size_(0),
29 sloppy_partitioning_(false), 30 sloppy_partitioning_(false),
30 inited_(false) {} 31 inited_(false) {}
31 32
32 RtpFormatVp8TestHelper::~RtpFormatVp8TestHelper() { 33 RtpFormatVp8TestHelper::~RtpFormatVp8TestHelper() {
33 delete fragmentation_; 34 delete fragmentation_;
34 delete [] payload_data_; 35 delete [] payload_data_;
35 delete [] buffer_;
36 } 36 }
37 37
38 bool RtpFormatVp8TestHelper::Init(const size_t* partition_sizes, 38 bool RtpFormatVp8TestHelper::Init(const size_t* partition_sizes,
39 size_t num_partitions) { 39 size_t num_partitions) {
40 if (inited_) return false; 40 if (inited_) return false;
41 fragmentation_ = new RTPFragmentationHeader; 41 fragmentation_ = new RTPFragmentationHeader;
42 fragmentation_->VerifyAndAllocateFragmentationHeader(num_partitions); 42 fragmentation_->VerifyAndAllocateFragmentationHeader(num_partitions);
43 payload_size_ = 0; 43 payload_size_ = 0;
44 // Calculate sum payload size. 44 // Calculate sum payload size.
45 for (size_t p = 0; p < num_partitions; ++p) { 45 for (size_t p = 0; p < num_partitions; ++p) {
46 payload_size_ += partition_sizes[p]; 46 payload_size_ += partition_sizes[p];
47 } 47 }
48 buffer_size_ = payload_size_ + 6; // Add space for payload descriptor.
49 payload_data_ = new uint8_t[payload_size_]; 48 payload_data_ = new uint8_t[payload_size_];
50 buffer_ = new uint8_t[buffer_size_];
51 size_t j = 0; 49 size_t j = 0;
52 // Loop through the partitions again. 50 // Loop through the partitions again.
53 for (size_t p = 0; p < num_partitions; ++p) { 51 for (size_t p = 0; p < num_partitions; ++p) {
54 fragmentation_->fragmentationLength[p] = partition_sizes[p]; 52 fragmentation_->fragmentationLength[p] = partition_sizes[p];
55 fragmentation_->fragmentationOffset[p] = j; 53 fragmentation_->fragmentationOffset[p] = j;
56 for (size_t i = 0; i < partition_sizes[p]; ++i) { 54 for (size_t i = 0; i < partition_sizes[p]; ++i) {
57 assert(j < payload_size_); 55 assert(j < payload_size_);
58 payload_data_[j++] = p; // Set the payload value to the partition index. 56 payload_data_[j++] = p; // Set the payload value to the partition index.
59 } 57 }
60 } 58 }
61 data_ptr_ = payload_data_; 59 data_ptr_ = payload_data_;
62 inited_ = true; 60 inited_ = true;
63 return true; 61 return true;
64 } 62 }
65 63
66 void RtpFormatVp8TestHelper::GetAllPacketsAndCheck( 64 void RtpFormatVp8TestHelper::GetAllPacketsAndCheck(
67 RtpPacketizerVp8* packetizer, 65 RtpPacketizerVp8* packetizer,
68 const size_t* expected_sizes, 66 const size_t* expected_sizes,
69 const int* expected_part, 67 const int* expected_part,
70 const bool* expected_frag_start, 68 const bool* expected_frag_start,
71 size_t expected_num_packets) { 69 size_t expected_num_packets) {
72 ASSERT_TRUE(inited_); 70 ASSERT_TRUE(inited_);
73 size_t send_bytes = 0;
74 bool last = false; 71 bool last = false;
75 for (size_t i = 0; i < expected_num_packets; ++i) { 72 for (size_t i = 0; i < expected_num_packets; ++i) {
76 std::ostringstream ss; 73 std::ostringstream ss;
77 ss << "Checking packet " << i; 74 ss << "Checking packet " << i;
78 SCOPED_TRACE(ss.str()); 75 SCOPED_TRACE(ss.str());
79 EXPECT_TRUE(packetizer->NextPacket(buffer_, &send_bytes, &last)); 76 EXPECT_TRUE(packetizer->NextPacket(&packet_, &last));
80 CheckPacket(send_bytes, expected_sizes[i], last, 77 CheckPacket(expected_sizes[i], last, expected_frag_start[i]);
81 expected_frag_start[i]);
82 } 78 }
83 EXPECT_TRUE(last); 79 EXPECT_TRUE(last);
84 } 80 }
85 81
86 // Payload descriptor 82 // Payload descriptor
87 // 0 1 2 3 4 5 6 7 83 // 0 1 2 3 4 5 6 7
88 // +-+-+-+-+-+-+-+-+ 84 // +-+-+-+-+-+-+-+-+
89 // |X|R|N|S|PartID | (REQUIRED) 85 // |X|R|N|S|PartID | (REQUIRED)
90 // +-+-+-+-+-+-+-+-+ 86 // +-+-+-+-+-+-+-+-+
91 // X: |I|L|T|K| RSV | (OPTIONAL) 87 // X: |I|L|T|K| RSV | (OPTIONAL)
(...skipping 28 matching lines...) Expand all
120 #define EXPECT_BIT_K_EQ(x, a) EXPECT_BIT_EQ(x, 4, a) 116 #define EXPECT_BIT_K_EQ(x, a) EXPECT_BIT_EQ(x, 4, a)
121 117
122 #define EXPECT_TID_EQ(x, a) EXPECT_EQ((((x) & 0xC0) >> 6), a) 118 #define EXPECT_TID_EQ(x, a) EXPECT_EQ((((x) & 0xC0) >> 6), a)
123 119
124 #define EXPECT_BIT_Y_EQ(x, a) EXPECT_BIT_EQ(x, 5, a) 120 #define EXPECT_BIT_Y_EQ(x, a) EXPECT_BIT_EQ(x, 5, a)
125 121
126 #define EXPECT_KEYIDX_EQ(x, a) EXPECT_EQ(((x) & 0x1F), a) 122 #define EXPECT_KEYIDX_EQ(x, a) EXPECT_EQ(((x) & 0x1F), a)
127 123
128 void RtpFormatVp8TestHelper::CheckHeader(bool frag_start) { 124 void RtpFormatVp8TestHelper::CheckHeader(bool frag_start) {
129 payload_start_ = 1; 125 payload_start_ = 1;
130 EXPECT_BIT_EQ(buffer_[0], 6, 0); // Check reserved bit. 126 rtc::ArrayView<const uint8_t> buffer = packet_.payload();
127 EXPECT_BIT_EQ(buffer[0], 6, 0); // Check reserved bit.
131 128
132 if (hdr_info_->pictureId != kNoPictureId || 129 if (hdr_info_->pictureId != kNoPictureId ||
133 hdr_info_->temporalIdx != kNoTemporalIdx || 130 hdr_info_->temporalIdx != kNoTemporalIdx ||
134 hdr_info_->tl0PicIdx != kNoTl0PicIdx || 131 hdr_info_->tl0PicIdx != kNoTl0PicIdx ||
135 hdr_info_->keyIdx != kNoKeyIdx) { 132 hdr_info_->keyIdx != kNoKeyIdx) {
136 EXPECT_BIT_X_EQ(buffer_[0], 1); 133 EXPECT_BIT_X_EQ(buffer[0], 1);
137 ++payload_start_; 134 ++payload_start_;
138 CheckPictureID(); 135 CheckPictureID();
139 CheckTl0PicIdx(); 136 CheckTl0PicIdx();
140 CheckTIDAndKeyIdx(); 137 CheckTIDAndKeyIdx();
141 } else { 138 } else {
142 EXPECT_BIT_X_EQ(buffer_[0], 0); 139 EXPECT_BIT_X_EQ(buffer[0], 0);
143 } 140 }
144 141
145 EXPECT_BIT_N_EQ(buffer_[0], hdr_info_->nonReference ? 1 : 0); 142 EXPECT_BIT_N_EQ(buffer[0], hdr_info_->nonReference ? 1 : 0);
146 EXPECT_BIT_S_EQ(buffer_[0], frag_start ? 1 : 0); 143 EXPECT_BIT_S_EQ(buffer[0], frag_start ? 1 : 0);
147 144
148 // Check partition index. 145 // Check partition index.
149 if (!sloppy_partitioning_) { 146 if (!sloppy_partitioning_) {
150 // The test payload data is constructed such that the payload value is the 147 // The test payload data is constructed such that the payload value is the
151 // same as the partition index. 148 // same as the partition index.
152 EXPECT_EQ(buffer_[0] & 0x0F, buffer_[payload_start_]); 149 EXPECT_EQ(buffer[0] & 0x0F, buffer[payload_start_]);
153 } else { 150 } else {
154 // Partition should be set to 0. 151 // Partition should be set to 0.
155 EXPECT_EQ(buffer_[0] & 0x0F, 0); 152 EXPECT_EQ(buffer[0] & 0x0F, 0);
156 } 153 }
157 } 154 }
158 155
159 // Verify that the I bit and the PictureID field are both set in accordance 156 // Verify that the I bit and the PictureID field are both set in accordance
160 // with the information in hdr_info_->pictureId. 157 // with the information in hdr_info_->pictureId.
161 void RtpFormatVp8TestHelper::CheckPictureID() { 158 void RtpFormatVp8TestHelper::CheckPictureID() {
159 auto buffer = packet_.payload();
162 if (hdr_info_->pictureId != kNoPictureId) { 160 if (hdr_info_->pictureId != kNoPictureId) {
163 EXPECT_BIT_I_EQ(buffer_[1], 1); 161 EXPECT_BIT_I_EQ(buffer[1], 1);
164 if (hdr_info_->pictureId > 0x7F) { 162 if (hdr_info_->pictureId > 0x7F) {
165 EXPECT_BIT_EQ(buffer_[payload_start_], 7, 1); 163 EXPECT_BIT_EQ(buffer[payload_start_], 7, 1);
166 EXPECT_EQ(buffer_[payload_start_] & 0x7F, 164 EXPECT_EQ(buffer[payload_start_] & 0x7F,
167 (hdr_info_->pictureId >> 8) & 0x7F); 165 (hdr_info_->pictureId >> 8) & 0x7F);
168 EXPECT_EQ(buffer_[payload_start_ + 1], 166 EXPECT_EQ(buffer[payload_start_ + 1], hdr_info_->pictureId & 0xFF);
169 hdr_info_->pictureId & 0xFF);
170 payload_start_ += 2; 167 payload_start_ += 2;
171 } else { 168 } else {
172 EXPECT_BIT_EQ(buffer_[payload_start_], 7, 0); 169 EXPECT_BIT_EQ(buffer[payload_start_], 7, 0);
173 EXPECT_EQ(buffer_[payload_start_] & 0x7F, 170 EXPECT_EQ(buffer[payload_start_] & 0x7F, (hdr_info_->pictureId) & 0x7F);
174 (hdr_info_->pictureId) & 0x7F);
175 payload_start_ += 1; 171 payload_start_ += 1;
176 } 172 }
177 } else { 173 } else {
178 EXPECT_BIT_I_EQ(buffer_[1], 0); 174 EXPECT_BIT_I_EQ(buffer[1], 0);
179 } 175 }
180 } 176 }
181 177
182 // Verify that the L bit and the TL0PICIDX field are both set in accordance 178 // Verify that the L bit and the TL0PICIDX field are both set in accordance
183 // with the information in hdr_info_->tl0PicIdx. 179 // with the information in hdr_info_->tl0PicIdx.
184 void RtpFormatVp8TestHelper::CheckTl0PicIdx() { 180 void RtpFormatVp8TestHelper::CheckTl0PicIdx() {
181 auto buffer = packet_.payload();
185 if (hdr_info_->tl0PicIdx != kNoTl0PicIdx) { 182 if (hdr_info_->tl0PicIdx != kNoTl0PicIdx) {
186 EXPECT_BIT_L_EQ(buffer_[1], 1); 183 EXPECT_BIT_L_EQ(buffer[1], 1);
187 EXPECT_EQ(buffer_[payload_start_], hdr_info_->tl0PicIdx); 184 EXPECT_EQ(buffer[payload_start_], hdr_info_->tl0PicIdx);
188 ++payload_start_; 185 ++payload_start_;
189 } else { 186 } else {
190 EXPECT_BIT_L_EQ(buffer_[1], 0); 187 EXPECT_BIT_L_EQ(buffer[1], 0);
191 } 188 }
192 } 189 }
193 190
194 // Verify that the T bit and the TL0PICIDX field, and the K bit and KEYIDX 191 // Verify that the T bit and the TL0PICIDX field, and the K bit and KEYIDX
195 // field are all set in accordance with the information in 192 // field are all set in accordance with the information in
196 // hdr_info_->temporalIdx and hdr_info_->keyIdx, respectively. 193 // hdr_info_->temporalIdx and hdr_info_->keyIdx, respectively.
197 void RtpFormatVp8TestHelper::CheckTIDAndKeyIdx() { 194 void RtpFormatVp8TestHelper::CheckTIDAndKeyIdx() {
195 auto buffer = packet_.payload();
198 if (hdr_info_->temporalIdx == kNoTemporalIdx && 196 if (hdr_info_->temporalIdx == kNoTemporalIdx &&
199 hdr_info_->keyIdx == kNoKeyIdx) { 197 hdr_info_->keyIdx == kNoKeyIdx) {
200 EXPECT_BIT_T_EQ(buffer_[1], 0); 198 EXPECT_BIT_T_EQ(buffer[1], 0);
201 EXPECT_BIT_K_EQ(buffer_[1], 0); 199 EXPECT_BIT_K_EQ(buffer[1], 0);
202 return; 200 return;
203 } 201 }
204 if (hdr_info_->temporalIdx != kNoTemporalIdx) { 202 if (hdr_info_->temporalIdx != kNoTemporalIdx) {
205 EXPECT_BIT_T_EQ(buffer_[1], 1); 203 EXPECT_BIT_T_EQ(buffer[1], 1);
206 EXPECT_TID_EQ(buffer_[payload_start_], hdr_info_->temporalIdx); 204 EXPECT_TID_EQ(buffer[payload_start_], hdr_info_->temporalIdx);
207 EXPECT_BIT_Y_EQ(buffer_[payload_start_], hdr_info_->layerSync ? 1 : 0); 205 EXPECT_BIT_Y_EQ(buffer[payload_start_], hdr_info_->layerSync ? 1 : 0);
208 } else { 206 } else {
209 EXPECT_BIT_T_EQ(buffer_[1], 0); 207 EXPECT_BIT_T_EQ(buffer[1], 0);
210 EXPECT_TID_EQ(buffer_[payload_start_], 0); 208 EXPECT_TID_EQ(buffer[payload_start_], 0);
211 EXPECT_BIT_Y_EQ(buffer_[payload_start_], 0); 209 EXPECT_BIT_Y_EQ(buffer[payload_start_], 0);
212 } 210 }
213 if (hdr_info_->keyIdx != kNoKeyIdx) { 211 if (hdr_info_->keyIdx != kNoKeyIdx) {
214 EXPECT_BIT_K_EQ(buffer_[1], 1); 212 EXPECT_BIT_K_EQ(buffer[1], 1);
215 EXPECT_KEYIDX_EQ(buffer_[payload_start_], hdr_info_->keyIdx); 213 EXPECT_KEYIDX_EQ(buffer[payload_start_], hdr_info_->keyIdx);
216 } else { 214 } else {
217 EXPECT_BIT_K_EQ(buffer_[1], 0); 215 EXPECT_BIT_K_EQ(buffer[1], 0);
218 EXPECT_KEYIDX_EQ(buffer_[payload_start_], 0); 216 EXPECT_KEYIDX_EQ(buffer[payload_start_], 0);
219 } 217 }
220 ++payload_start_; 218 ++payload_start_;
221 } 219 }
222 220
223 // Verify that the payload (i.e., after the headers) of the packet stored in 221 // Verify that the payload (i.e., after the headers) of the packet stored in
224 // buffer_ is identical to the expected (as found in data_ptr_). 222 // buffer_ is identical to the expected (as found in data_ptr_).
225 void RtpFormatVp8TestHelper::CheckPayload(size_t payload_end) { 223 void RtpFormatVp8TestHelper::CheckPayload() {
224 auto buffer = packet_.payload();
225 size_t payload_end = buffer.size();
226 for (size_t i = payload_start_; i < payload_end; ++i, ++data_ptr_) 226 for (size_t i = payload_start_; i < payload_end; ++i, ++data_ptr_)
227 EXPECT_EQ(buffer_[i], *data_ptr_); 227 EXPECT_EQ(buffer[i], *data_ptr_);
228 } 228 }
229 229
230 // Verify that the input variable "last" agrees with the position of data_ptr_. 230 // Verify that the input variable "last" agrees with the position of data_ptr_.
231 // If data_ptr_ has advanced payload_size_ bytes from the start (payload_data_) 231 // If data_ptr_ has advanced payload_size_ bytes from the start (payload_data_)
232 // we are at the end and last should be true. Otherwise, it should be false. 232 // we are at the end and last should be true. Otherwise, it should be false.
233 void RtpFormatVp8TestHelper::CheckLast(bool last) const { 233 void RtpFormatVp8TestHelper::CheckLast(bool last) const {
234 EXPECT_EQ(last, data_ptr_ == payload_data_ + payload_size_); 234 EXPECT_EQ(last, data_ptr_ == payload_data_ + payload_size_);
235 } 235 }
236 236
237 // Verify the contents of a packet. Check the length versus expected_bytes, 237 // Verify the contents of a packet. Check the length versus expected_bytes,
238 // the header, payload, and "last" flag. 238 // the header, payload, and "last" flag.
239 void RtpFormatVp8TestHelper::CheckPacket(size_t send_bytes, 239 void RtpFormatVp8TestHelper::CheckPacket(size_t expect_bytes,
240 size_t expect_bytes,
241 bool last, 240 bool last,
242 bool frag_start) { 241 bool frag_start) {
243 EXPECT_EQ(expect_bytes, send_bytes); 242 EXPECT_EQ(expect_bytes, packet_.payload_size());
244 CheckHeader(frag_start); 243 CheckHeader(frag_start);
245 CheckPayload(send_bytes); 244 CheckPayload();
246 CheckLast(last); 245 CheckLast(last);
247 } 246 }
248 247
249 } // namespace test 248 } // namespace test
250 249
251 } // namespace webrtc 250 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_format_vp8_test_helper.h ('k') | webrtc/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698