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

Side by Side Diff: webrtc/modules/audio_coding/main/acm2/acm_dump_unittest.cc

Issue 1230973005: Adds logging of configuration information for VideoReceiveStream (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 5 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 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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
(...skipping 13 matching lines...) Expand all
24 24
25 // Files generated at build-time by the protobuf compiler. 25 // Files generated at build-time by the protobuf compiler.
26 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD 26 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD
27 #include "external/webrtc/webrtc/modules/audio_coding/dump.pb.h" 27 #include "external/webrtc/webrtc/modules/audio_coding/dump.pb.h"
28 #else 28 #else
29 #include "webrtc/audio_coding/dump.pb.h" 29 #include "webrtc/audio_coding/dump.pb.h"
30 #endif 30 #endif
31 31
32 namespace webrtc { 32 namespace webrtc {
33 33
34 // Test for the acm dump class. Dumps some RTP packets to disk, then reads them 34 void VerifyReceiveStreamConfig(const ACMDumpEvent& event,
35 const VideoReceiveStream::Config& config) {
36 EXPECT_TRUE(event.has_timestamp_us());
37 ASSERT_TRUE(event.has_type());
38 EXPECT_EQ(ACMDumpEvent::RECEIVER_CONFIG_EVENT, event.type());
39 EXPECT_FALSE(event.has_rtp_packet());
40 EXPECT_FALSE(event.has_rtcp_packet());
41 EXPECT_FALSE(event.has_debug_event());
42 ASSERT_TRUE(event.has_receiver_config());
43 EXPECT_FALSE(event.has_sender_config());
44 EXPECT_FALSE(event.has_audio_receiver_config());
45 EXPECT_FALSE(event.has_audio_sender_config());
46 const ACMDumpVideoReceiveConfig& receiver_config = event.receiver_config();
47 // Check SSRCs.
48 ASSERT_TRUE(receiver_config.has_remote_ssrc());
49 EXPECT_EQ(config.rtp.remote_ssrc, receiver_config.remote_ssrc());
50 ASSERT_TRUE(receiver_config.has_local_ssrc());
51 EXPECT_EQ(config.rtp.local_ssrc, receiver_config.local_ssrc());
52 // Check RTCP settings.
53 ASSERT_TRUE(receiver_config.has_rtcp_mode());
54 if (config.rtp.rtcp_mode == newapi::kRtcpCompound)
55 EXPECT_EQ(ACMDumpVideoReceiveConfig::RTCP_COMPOUND,
56 receiver_config.rtcp_mode());
57 else
58 EXPECT_EQ(ACMDumpVideoReceiveConfig::RTCP_REDUCEDSIZE,
59 receiver_config.rtcp_mode());
60 ASSERT_TRUE(receiver_config.has_receiver_reference_time_report());
61 EXPECT_EQ(config.rtp.rtcp_xr.receiver_reference_time_report,
62 receiver_config.receiver_reference_time_report());
63 ASSERT_TRUE(receiver_config.has_remb());
64 EXPECT_EQ(config.rtp.remb, receiver_config.remb());
65 // Check RTX map.
66 ASSERT_EQ(static_cast<int>(config.rtp.rtx.size()),
67 receiver_config.rtx_map_size());
68 for (int i = 0; i < receiver_config.rtx_map_size(); i++) {
69 const RtxMap& mapping = receiver_config.rtx_map(i);
70 ASSERT_TRUE(mapping.has_payload_type());
71 ASSERT_TRUE(mapping.has_config());
72 EXPECT_EQ(1,
73 static_cast<int>(config.rtp.rtx.count(mapping.payload_type())));
74 const RtxConfig& rtx_config = mapping.config();
75 const VideoReceiveStream::Config::Rtp::Rtx& rtx =
ivoc 2015/07/14 12:13:14 We could consider making this an auto, since it's
terelius 2015/07/16 12:47:03 While I like using auto to hide obvious boiler-pla
ivoc 2015/07/17 12:14:28 Okay, that makes sense.
76 config.rtp.rtx.at(mapping.payload_type());
77 ASSERT_TRUE(rtx_config.has_rtx_ssrc());
78 ASSERT_TRUE(rtx_config.has_rtx_payload_type());
79 EXPECT_EQ(rtx.ssrc, rtx_config.rtx_ssrc());
80 EXPECT_EQ(rtx.payload_type, rtx_config.rtx_payload_type());
81 }
82 // Check header extensions.
83 ASSERT_EQ(static_cast<int>(config.rtp.extensions.size()),
84 receiver_config.header_extensions_size());
85 for (int i = 0; i < receiver_config.header_extensions_size(); i++) {
86 ASSERT_TRUE(receiver_config.header_extensions(i).has_name());
87 ASSERT_TRUE(receiver_config.header_extensions(i).has_id());
88 const std::string& name = receiver_config.header_extensions(i).name();
89 int id = receiver_config.header_extensions(i).id();
90 EXPECT_EQ(config.rtp.extensions[i].id, id);
91 EXPECT_EQ(config.rtp.extensions[i].name, name);
92 }
93 // Check decoders.
94 ASSERT_EQ(static_cast<int>(config.decoders.size()),
95 receiver_config.decoders_size());
96 for (int i = 0; i < receiver_config.decoders_size(); i++) {
97 ASSERT_TRUE(receiver_config.decoders(i).has_name());
98 ASSERT_TRUE(receiver_config.decoders(i).has_payload_type());
99 const std::string& decoder_name = receiver_config.decoders(i).name();
100 int decoder_type = receiver_config.decoders(i).payload_type();
101 EXPECT_EQ(config.decoders[i].payload_name, decoder_name);
102 EXPECT_EQ(config.decoders[i].payload_type, decoder_type);
103 }
104 }
105
106 void VerifySendStreamConfig(const ACMDumpEvent& event,
107 const VideoSendStream::Config& config) {
108 EXPECT_TRUE(event.has_timestamp_us());
ivoc 2015/07/14 12:13:14 I think it would be a good idea to refactor the co
stefan-webrtc 2015/07/14 13:28:56 Agree, these functions are very long. If possible
terelius 2015/07/16 12:47:03 The first 10 lines of each function are similar. I
109 ASSERT_TRUE(event.has_type());
110 EXPECT_EQ(ACMDumpEvent::SENDER_CONFIG_EVENT, event.type());
111 EXPECT_FALSE(event.has_rtp_packet());
112 EXPECT_FALSE(event.has_rtcp_packet());
113 EXPECT_FALSE(event.has_debug_event());
114 EXPECT_FALSE(event.has_receiver_config());
115 ASSERT_TRUE(event.has_sender_config());
116 EXPECT_FALSE(event.has_audio_receiver_config());
117 EXPECT_FALSE(event.has_audio_sender_config());
118 const ACMDumpVideoSendConfig& sender_config = event.sender_config();
119 // Check SSRCs.
120 ASSERT_EQ(static_cast<int>(config.rtp.ssrcs.size()),
121 sender_config.ssrcs_size());
122 for (int i = 0; i < sender_config.ssrcs_size(); i++) {
123 EXPECT_EQ(config.rtp.ssrcs[i], sender_config.ssrcs(i));
124 }
125 // Check header extensions.
126 ASSERT_EQ(static_cast<int>(config.rtp.extensions.size()),
127 sender_config.header_extensions_size());
128 for (int i = 0; i < sender_config.header_extensions_size(); i++) {
129 ASSERT_TRUE(sender_config.header_extensions(i).has_name());
130 ASSERT_TRUE(sender_config.header_extensions(i).has_id());
131 const std::string& name = sender_config.header_extensions(i).name();
132 int id = sender_config.header_extensions(i).id();
133 EXPECT_EQ(config.rtp.extensions[i].id, id);
134 EXPECT_EQ(config.rtp.extensions[i].name, name);
135 }
136 // Check RTX settings.
137 ASSERT_EQ(static_cast<int>(config.rtp.rtx.ssrcs.size()),
138 sender_config.rtx_ssrcs_size());
139 for (int i = 0; i < sender_config.rtx_ssrcs_size(); i++) {
140 EXPECT_EQ(config.rtp.rtx.ssrcs[i], sender_config.rtx_ssrcs(i));
141 }
142 if (sender_config.rtx_ssrcs_size() > 0) {
143 ASSERT_TRUE(sender_config.has_rtx_payload_type());
144 EXPECT_EQ(config.rtp.rtx.payload_type, sender_config.rtx_payload_type());
145 }
146 // Check CNAME.
147 ASSERT_TRUE(sender_config.has_c_name());
148 EXPECT_EQ(config.rtp.c_name, sender_config.c_name());
149 // Check encoder.
150 ASSERT_TRUE(sender_config.has_encoder());
151 ASSERT_TRUE(sender_config.encoder().has_name());
152 ASSERT_TRUE(sender_config.encoder().has_payload_type());
153 EXPECT_EQ(config.encoder_settings.payload_name,
154 sender_config.encoder().name());
155 EXPECT_EQ(config.encoder_settings.payload_type,
156 sender_config.encoder().payload_type());
157 }
158
159 void VerifyRtpEvent(const ACMDumpEvent& event,
160 bool incoming,
161 MediaType media_type,
162 uint8_t* header,
163 size_t header_size,
164 size_t total_size) {
165 EXPECT_TRUE(event.has_timestamp_us());
166 ASSERT_TRUE(event.has_type());
167 EXPECT_EQ(ACMDumpEvent::RTP_EVENT, event.type());
168 ASSERT_TRUE(event.has_rtp_packet());
169 EXPECT_FALSE(event.has_rtcp_packet());
170 EXPECT_FALSE(event.has_debug_event());
171 EXPECT_FALSE(event.has_receiver_config());
172 EXPECT_FALSE(event.has_sender_config());
173 EXPECT_FALSE(event.has_audio_receiver_config());
174 EXPECT_FALSE(event.has_audio_sender_config());
175 const ACMDumpRtpPacket& rtp_packet = event.rtp_packet();
176 ASSERT_TRUE(rtp_packet.has_direction());
177 EXPECT_EQ(incoming ? ACMDumpRtpPacket::INCOMING : ACMDumpRtpPacket::OUTGOING,
178 rtp_packet.direction());
179 ASSERT_TRUE(rtp_packet.has_type());
180 if (media_type == MediaType::VIDEO)
181 EXPECT_EQ(ACMDumpRtpPacket::VIDEO, rtp_packet.type());
182 else if (media_type == MediaType::AUDIO)
183 EXPECT_EQ(ACMDumpRtpPacket::AUDIO, rtp_packet.type());
184 else
185 EXPECT_EQ(ACMDumpRtpPacket::UNKNOWN_TYPE, rtp_packet.type());
186 ASSERT_TRUE(rtp_packet.has_packet_length());
187 EXPECT_EQ(total_size, rtp_packet.packet_length());
188 ASSERT_TRUE(rtp_packet.has_header());
189 ASSERT_EQ(header_size, rtp_packet.header().size());
190 for (size_t i = 0; i < header_size; i++) {
191 EXPECT_EQ(header[i], static_cast<uint8_t>(rtp_packet.header()[i]));
192 }
193 }
194
195 void VerifyRtcpEvent(const ACMDumpEvent& event,
196 bool incoming,
197 MediaType media_type,
198 uint8_t* packet,
199 size_t total_size) {
200 EXPECT_TRUE(event.has_timestamp_us());
201 ASSERT_TRUE(event.has_type());
202 EXPECT_EQ(ACMDumpEvent::RTCP_EVENT, event.type());
203 EXPECT_FALSE(event.has_rtp_packet());
204 ASSERT_TRUE(event.has_rtcp_packet());
205 EXPECT_FALSE(event.has_debug_event());
206 EXPECT_FALSE(event.has_receiver_config());
207 EXPECT_FALSE(event.has_sender_config());
208 EXPECT_FALSE(event.has_audio_receiver_config());
209 EXPECT_FALSE(event.has_audio_sender_config());
210 const ACMDumpRtcpPacket& rtcp_packet = event.rtcp_packet();
211 ASSERT_TRUE(rtcp_packet.has_direction());
212 EXPECT_EQ(
213 incoming ? ACMDumpRtcpPacket::INCOMING : ACMDumpRtcpPacket::OUTGOING,
214 rtcp_packet.direction());
215 ASSERT_TRUE(rtcp_packet.has_type());
216 if (media_type == MediaType::VIDEO)
217 EXPECT_EQ(ACMDumpRtcpPacket::VIDEO, rtcp_packet.type());
218 else if (media_type == MediaType::AUDIO)
219 EXPECT_EQ(ACMDumpRtcpPacket::AUDIO, rtcp_packet.type());
220 else
221 EXPECT_EQ(ACMDumpRtcpPacket::UNKNOWN_TYPE, rtcp_packet.type());
222 ASSERT_TRUE(rtcp_packet.has_data());
223 ASSERT_EQ(total_size, rtcp_packet.data().size());
224 for (size_t i = 0; i < total_size; i++) {
225 EXPECT_EQ(packet[i], static_cast<uint8_t>(rtcp_packet.data()[i]));
226 }
227 }
228
229 void VerifyLogStartEvent(const ACMDumpEvent& event) {
230 EXPECT_TRUE(event.has_timestamp_us());
231 ASSERT_TRUE(event.has_type());
232 EXPECT_EQ(ACMDumpEvent::DEBUG_EVENT, event.type());
233 EXPECT_FALSE(event.has_rtp_packet());
234 EXPECT_FALSE(event.has_rtcp_packet());
235 ASSERT_TRUE(event.has_debug_event());
236 EXPECT_FALSE(event.has_receiver_config());
237 EXPECT_FALSE(event.has_sender_config());
238 EXPECT_FALSE(event.has_audio_receiver_config());
239 EXPECT_FALSE(event.has_audio_sender_config());
240 const ACMDumpDebugEvent& debug_event = event.debug_event();
241 ASSERT_TRUE(debug_event.has_type());
242 EXPECT_EQ(ACMDumpDebugEvent::LOG_START, debug_event.type());
243 // TODO(terelius): Deliberately not verifying that there is a message field
244 // since our protobuf file says that the message is optional. Make a decision.
ivoc 2015/07/14 12:13:14 I think that's fine, especially since the message
terelius 2015/07/16 12:47:03 We might want to make LogStart its own event type
ivoc 2015/07/17 12:14:28 Good idea.
245 }
246
247 void GenerateVideoReceiveConfig(webrtc::VideoReceiveStream::Config* config) {
248 // Create a map from a payload type to an encoder name.
249 VideoReceiveStream::Decoder decoder;
250 decoder.payload_type = rand();
251 decoder.payload_name = (rand() % 2 ? "VP8" : "H264");
252 config->decoders.push_back(decoder);
253 // Add SSRCs for the stream.
254 config->rtp.remote_ssrc = rand();
255 config->rtp.local_ssrc = rand();
256 // Add extensions and settings for RTCP.
257 config->rtp.rtcp_mode = rand() % 2 ? newapi::kRtcpCompound
258 : newapi::kRtcpReducedSize;
259 config->rtp.rtcp_xr.receiver_reference_time_report =
260 static_cast<bool>(rand() % 2);
261 config->rtp.remb = static_cast<bool>(rand() % 2);
262 // Add a map from a payload type to a new ssrc and a new payload type for RTX.
263 webrtc::VideoReceiveStream::Config::Rtp::Rtx rtx_pair;
264 rtx_pair.ssrc = rand();
265 rtx_pair.payload_type = rand();
266 config->rtp.rtx.insert(std::make_pair(rand(), rtx_pair));
267 // Add two random header extensions.
268 const char* extension_name = rand() % 2 ? RtpExtension::kTOffset
269 : RtpExtension::kVideoRotation;
270 config->rtp.extensions.push_back(RtpExtension(extension_name, rand()));
271 extension_name = rand() % 2 ? RtpExtension::kAudioLevel
272 : RtpExtension::kAbsSendTime;
273 config->rtp.extensions.push_back(RtpExtension(extension_name, rand()));
274 }
275
276 void GenerateVideoSendConfig(webrtc::VideoSendStream::Config* config) {
277 // Create a map from a payload type to an encoder name.
278 config->encoder_settings.payload_type = rand();
279 config->encoder_settings.payload_name = (rand() % 2 ? "VP8" : "H264");
280 // Add SSRCs for the stream.
281 config->rtp.ssrcs.push_back(rand());
282 // Add a map from a payload type to new ssrcs and a new payload type for RTX.
283 config->rtp.rtx.ssrcs.push_back(rand());
284 config->rtp.rtx.payload_type = rand();
285 // Add a CNAME.
286 config->rtp.c_name = "some.user@some.host";
287 // Add two random header extensions.
288 const char* extension_name = rand() % 2 ? RtpExtension::kTOffset
289 : RtpExtension::kVideoRotation;
290 config->rtp.extensions.push_back(RtpExtension(extension_name, rand()));
291 extension_name = rand() % 2 ? RtpExtension::kAudioLevel
292 : RtpExtension::kAbsSendTime;
293 config->rtp.extensions.push_back(RtpExtension(extension_name, rand()));
294 }
295
296 // Test for the ACMDump class. Dumps some RTP packets to disk, then reads them
35 // back to see if they match. 297 // back to see if they match.
36 class AcmDumpTest : public ::testing::Test { 298 void LogSessionAndReadBack(size_t rtp_count, unsigned random_seed) {
37 public: 299 std::vector<uint8_t*> rtp_packets;
38 void VerifyResults(const ACMDumpEventStream& parsed_stream, 300 std::vector<size_t> rtp_packet_sizes;
ivoc 2015/07/14 12:13:14 I would prefer a vector<vector<uint8_t>> here, the
stefan-webrtc 2015/07/14 13:28:56 And you can also avoid the delete[]
terelius 2015/07/16 12:47:03 Done.
39 size_t packet_size) { 301 uint8_t* incoming_rtcp_packet;
40 // Verify the result. 302 uint8_t* outgoing_rtcp_packet;
ivoc 2015/07/14 12:13:14 These should be vector<uint8_t>.
terelius 2015/07/16 12:47:03 Done.
41 EXPECT_EQ(5, parsed_stream.stream_size()); 303 size_t incoming_rtcp_packet_size;
42 const ACMDumpEvent& start_event = parsed_stream.stream(2); 304 size_t outgoing_rtcp_packet_size;
43 ASSERT_TRUE(start_event.has_type()); 305 webrtc::VideoReceiveStream::Config receiver_config;
44 EXPECT_EQ(ACMDumpEvent::DEBUG_EVENT, start_event.type()); 306 webrtc::VideoSendStream::Config sender_config;
45 EXPECT_TRUE(start_event.has_timestamp_us()); 307
46 EXPECT_FALSE(start_event.has_packet()); 308 srand(random_seed);
47 ASSERT_TRUE(start_event.has_debug_event()); 309
48 auto start_debug_event = start_event.debug_event(); 310 // Create rtp_count RTP packets containing random data.
49 ASSERT_TRUE(start_debug_event.has_type()); 311 size_t rtp_header_size = 20;
ivoc 2015/07/14 12:13:14 Should be const.
terelius 2015/07/16 12:47:03 Done.
50 EXPECT_EQ(ACMDumpDebugEvent::LOG_START, start_debug_event.type()); 312 for (size_t i = 0; i < rtp_count; i++) {
51 ASSERT_TRUE(start_debug_event.has_message()); 313 size_t packet_size = 1000 + rand() % 30;
52 314 rtp_packets.push_back(new uint8_t[packet_size]);
53 for (int i = 0; i < parsed_stream.stream_size(); i++) { 315 for (size_t j = 0; j < packet_size; j++) {
54 if (i == 2) { 316 rtp_packets[i][j] = rand();
55 // This is the LOG_START packet that was already verified.
56 continue;
57 }
58 const ACMDumpEvent& test_event = parsed_stream.stream(i);
59 ASSERT_TRUE(test_event.has_type());
60 EXPECT_EQ(ACMDumpEvent::RTP_EVENT, test_event.type());
61 EXPECT_TRUE(test_event.has_timestamp_us());
62 EXPECT_FALSE(test_event.has_debug_event());
63 ASSERT_TRUE(test_event.has_packet());
64 const ACMDumpRTPPacket& test_packet = test_event.packet();
65 ASSERT_TRUE(test_packet.has_direction());
66 if (i <= 1) {
67 EXPECT_EQ(ACMDumpRTPPacket::INCOMING, test_packet.direction());
68 } else if (i >= 3) {
69 EXPECT_EQ(ACMDumpRTPPacket::OUTGOING, test_packet.direction());
70 }
71 ASSERT_TRUE(test_packet.has_rtp_data());
72 ASSERT_EQ(packet_size, test_packet.rtp_data().size());
73 for (size_t i = 0; i < packet_size; i++) {
74 EXPECT_EQ(rtp_packet_[i],
75 static_cast<uint8_t>(test_packet.rtp_data()[i]));
76 }
77 } 317 }
78 } 318 rtp_packet_sizes.push_back(packet_size);
79 319 }
80 void Run(int packet_size, int random_seed) { 320 // Create two RTCP packets containing random data.
81 rtp_packet_.clear(); 321 outgoing_rtcp_packet_size = 1000 + rand() % 30;
82 rtp_packet_.reserve(packet_size); 322 outgoing_rtcp_packet = new uint8_t[outgoing_rtcp_packet_size];
83 srand(random_seed); 323 for (size_t j = 0; j < outgoing_rtcp_packet_size; j++) {
84 // Fill the packet vector with random data. 324 outgoing_rtcp_packet[j] = rand();
85 for (int i = 0; i < packet_size; i++) { 325 }
86 rtp_packet_.push_back(rand()); 326 incoming_rtcp_packet_size = 1000 + rand() % 30;
327 incoming_rtcp_packet = new uint8_t[incoming_rtcp_packet_size];
328 for (size_t j = 0; j < incoming_rtcp_packet_size; j++) {
329 incoming_rtcp_packet[j] = rand();
330 }
331 // Create configurations for the video streams.
332 GenerateVideoReceiveConfig(&receiver_config);
333 GenerateVideoSendConfig(&sender_config);
334
335 // Find the name of the current test, in order to use it as a temporary
336 // filename.
337 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
338 const std::string temp_filename =
339 test::OutputPath() + test_info->test_case_name() + test_info->name();
340
341 // When log_dumper goes out of scope, it causes the log file to be flushed
342 // to disk.
343 {
344 rtc::scoped_ptr<AcmDump> log_dumper(AcmDump::Create());
345 log_dumper->LogVideoReceiveStreamConfig(receiver_config);
346 log_dumper->LogVideoSendStreamConfig(sender_config);
347 size_t i = 0;
348 for (; i < rtp_count / 2; i++) {
349 log_dumper->LogRtpHeader(
350 (i % 2 == 0), // Every second packet is incoming.
351 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO,
352 rtp_packets[i],
353 rtp_header_size,
354 rtp_packet_sizes[i]);
87 } 355 }
88 // Find the name of the current test, in order to use it as a temporary 356 log_dumper->LogRtcpPacket(false,
89 // filename. 357 MediaType::AUDIO,
90 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); 358 outgoing_rtcp_packet,
91 const std::string temp_filename = 359 outgoing_rtcp_packet_size);
92 test::OutputPath() + test_info->test_case_name() + test_info->name(); 360 log_dumper->StartLogging(temp_filename, 10000000);
93 361 for (; i < rtp_count; i++) {
94 // When log_dumper goes out of scope, it causes the log file to be flushed 362 log_dumper->LogRtpHeader(
95 // to disk. 363 (i % 2 == 0), // Every second packet is incoming,
96 { 364 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO,
97 rtc::scoped_ptr<AcmDump> log_dumper(AcmDump::Create()); 365 rtp_packets[i],
98 log_dumper->LogRtpPacket(true, rtp_packet_.data(), rtp_packet_.size()); 366 rtp_header_size,
99 log_dumper->LogRtpPacket(true, rtp_packet_.data(), rtp_packet_.size()); 367 rtp_packet_sizes[i]);
100 log_dumper->StartLogging(temp_filename, 10000000);
101 log_dumper->LogRtpPacket(false, rtp_packet_.data(), rtp_packet_.size());
102 log_dumper->LogRtpPacket(false, rtp_packet_.data(), rtp_packet_.size());
103 } 368 }
104 369 log_dumper->LogRtcpPacket(true,
105 // Read the generated file from disk. 370 MediaType::VIDEO,
106 ACMDumpEventStream parsed_stream; 371 incoming_rtcp_packet,
107 372 incoming_rtcp_packet_size);
108 ASSERT_EQ(true, AcmDump::ParseAcmDump(temp_filename, &parsed_stream)); 373 }
109 374
110 VerifyResults(parsed_stream, packet_size); 375 int config_count = 2;
111 376 int rtcp_count = 2;
112 // Clean up temporary file - can be pretty slow. 377 int debug_count = 1; // Only LogStart event,
ivoc 2015/07/14 12:13:14 These should be const.
terelius 2015/07/16 12:47:03 Done.
113 remove(temp_filename.c_str()); 378 int event_count = config_count + debug_count + rtcp_count + rtp_count;
ivoc 2015/07/14 12:13:14 This one as well.
terelius 2015/07/16 12:47:03 Done.
114 } 379
115 std::vector<uint8_t> rtp_packet_; 380 // Read the generated file from disk.
116 }; 381 ACMDumpEventStream parsed_stream;
117 382
118 TEST_F(AcmDumpTest, DumpAndRead) { 383 ASSERT_TRUE(AcmDump::ParseAcmDump(temp_filename, &parsed_stream));
119 Run(256, 321); 384
385 // Verify the result.
386 EXPECT_EQ(event_count, parsed_stream.stream_size());
387 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config);
388 VerifySendStreamConfig(parsed_stream.stream(1), sender_config);
389 size_t i = 0;
390 for (; i < rtp_count / 2; i++) {
391 VerifyRtpEvent(parsed_stream.stream(config_count + i),
392 (i % 2 == 0), // Every second packet is incoming.
393 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO,
394 rtp_packets[i],
395 rtp_header_size,
396 rtp_packet_sizes[i]);
397 }
398 VerifyRtcpEvent(parsed_stream.stream(config_count + rtp_count / 2),
399 false,
400 MediaType::AUDIO,
401 outgoing_rtcp_packet,
402 outgoing_rtcp_packet_size);
403
404 VerifyLogStartEvent(parsed_stream.stream(1 + config_count + rtp_count / 2));
405 for (; i < rtp_count; i++) {
406 VerifyRtpEvent(parsed_stream.stream(2 + config_count + i),
407 (i % 2 == 0), // Every second packet is incoming.
408 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO,
409 rtp_packets[i],
410 rtp_header_size,
411 rtp_packet_sizes[i]);
412 }
413 VerifyRtcpEvent(parsed_stream.stream(2 + config_count + rtp_count),
414 true,
415 MediaType::VIDEO,
416 incoming_rtcp_packet,
417 incoming_rtcp_packet_size);
418
419 // Clean up temporary file - can be pretty slow.
420 remove(temp_filename.c_str());
421
422 // Free allocated memory,
423 for (size_t i = 0; i < rtp_count; i++) {
424 delete[] rtp_packets[i];
425 }
426 delete[] incoming_rtcp_packet;
427 delete[] outgoing_rtcp_packet;
428 }
429
430 TEST(AcmDumpTest, LogSessionAndReadBack) {
431 LogSessionAndReadBack(5, 321);
432 LogSessionAndReadBack(8, 3141592653U);
433 LogSessionAndReadBack(9, 2718281828U);
120 } 434 }
121 435
122 } // namespace webrtc 436 } // namespace webrtc
123 437
124 #endif // RTC_AUDIOCODING_DEBUG_DUMP 438 #endif // RTC_AUDIOCODING_DEBUG_DUMP
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698