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

Side by Side Diff: webrtc/modules/video_coding/codecs/test/packet_manipulator_unittest.cc

Issue 1528503003: Lint enabled for webrtc/modules/video_coding folder. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase 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 /* 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 #include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h" 11 #include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h"
12 12
13 #include <queue> 13 #include <queue>
14 14
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webrtc/modules/video_coding/include/video_codec_interface.h" 16 #include "webrtc/modules/video_coding/include/video_codec_interface.h"
17 #include "webrtc/modules/video_coding/codecs/test/predictive_packet_manipulator. h" 17 #include "webrtc/modules/video_coding/codecs/test/predictive_packet_manipulator. h"
18 #include "webrtc/test/testsupport/unittest_utils.h" 18 #include "webrtc/test/testsupport/unittest_utils.h"
19 #include "webrtc/typedefs.h" 19 #include "webrtc/typedefs.h"
20 20
21 namespace webrtc { 21 namespace webrtc {
22 namespace test { 22 namespace test {
23 23
24 const double kNeverDropProbability = 0.0; 24 const double kNeverDropProbability = 0.0;
25 const double kAlwaysDropProbability = 1.0; 25 const double kAlwaysDropProbability = 1.0;
26 const int kBurstLength = 1; 26 const int kBurstLength = 1;
27 27
28 class PacketManipulatorTest: public PacketRelatedTest { 28 class PacketManipulatorTest : public PacketRelatedTest {
29 protected: 29 protected:
30 PacketReader packet_reader_; 30 PacketReader packet_reader_;
31 EncodedImage image_; 31 EncodedImage image_;
32 NetworkingConfig drop_config_; 32 NetworkingConfig drop_config_;
33 NetworkingConfig no_drop_config_; 33 NetworkingConfig no_drop_config_;
34 34
35 PacketManipulatorTest() { 35 PacketManipulatorTest() {
36 image_._buffer = packet_data_; 36 image_._buffer = packet_data_;
37 image_._length = kPacketDataLength; 37 image_._length = kPacketDataLength;
38 image_._size = kPacketDataLength; 38 image_._size = kPacketDataLength;
39 39
40 drop_config_.packet_size_in_bytes = kPacketSizeInBytes; 40 drop_config_.packet_size_in_bytes = kPacketSizeInBytes;
41 drop_config_.packet_loss_probability = kAlwaysDropProbability; 41 drop_config_.packet_loss_probability = kAlwaysDropProbability;
42 drop_config_.packet_loss_burst_length = kBurstLength; 42 drop_config_.packet_loss_burst_length = kBurstLength;
43 drop_config_.packet_loss_mode = kUniform; 43 drop_config_.packet_loss_mode = kUniform;
44 44
45 no_drop_config_.packet_size_in_bytes = kPacketSizeInBytes; 45 no_drop_config_.packet_size_in_bytes = kPacketSizeInBytes;
46 no_drop_config_.packet_loss_probability = kNeverDropProbability; 46 no_drop_config_.packet_loss_probability = kNeverDropProbability;
47 no_drop_config_.packet_loss_burst_length = kBurstLength; 47 no_drop_config_.packet_loss_burst_length = kBurstLength;
48 no_drop_config_.packet_loss_mode = kUniform; 48 no_drop_config_.packet_loss_mode = kUniform;
49 } 49 }
50 50
51 virtual ~PacketManipulatorTest() {} 51 virtual ~PacketManipulatorTest() {}
52 52
53 void SetUp() { 53 void SetUp() { PacketRelatedTest::SetUp(); }
54 PacketRelatedTest::SetUp();
55 }
56 54
57 void TearDown() { 55 void TearDown() { PacketRelatedTest::TearDown(); }
58 PacketRelatedTest::TearDown();
59 }
60 56
61 void VerifyPacketLoss(int expected_nbr_packets_dropped, 57 void VerifyPacketLoss(int expected_nbr_packets_dropped,
62 int actual_nbr_packets_dropped, 58 int actual_nbr_packets_dropped,
63 size_t expected_packet_data_length, 59 size_t expected_packet_data_length,
64 uint8_t* expected_packet_data, 60 uint8_t* expected_packet_data,
65 EncodedImage& actual_image) { 61 const EncodedImage& actual_image) {
66 EXPECT_EQ(expected_nbr_packets_dropped, actual_nbr_packets_dropped); 62 EXPECT_EQ(expected_nbr_packets_dropped, actual_nbr_packets_dropped);
67 EXPECT_EQ(expected_packet_data_length, image_._length); 63 EXPECT_EQ(expected_packet_data_length, image_._length);
68 EXPECT_EQ(0, memcmp(expected_packet_data, actual_image._buffer, 64 EXPECT_EQ(0, memcmp(expected_packet_data, actual_image._buffer,
69 expected_packet_data_length)); 65 expected_packet_data_length));
70 } 66 }
71 }; 67 };
72 68
73 TEST_F(PacketManipulatorTest, Constructor) { 69 TEST_F(PacketManipulatorTest, Constructor) {
74 PacketManipulatorImpl manipulator(&packet_reader_, no_drop_config_, false); 70 PacketManipulatorImpl manipulator(&packet_reader_, no_drop_config_, false);
75 } 71 }
76 72
77 TEST_F(PacketManipulatorTest, DropNone) { 73 TEST_F(PacketManipulatorTest, DropNone) {
78 PacketManipulatorImpl manipulator(&packet_reader_, no_drop_config_, false); 74 PacketManipulatorImpl manipulator(&packet_reader_, no_drop_config_, false);
79 int nbr_packets_dropped = manipulator.ManipulatePackets(&image_); 75 int nbr_packets_dropped = manipulator.ManipulatePackets(&image_);
80 VerifyPacketLoss(0, nbr_packets_dropped, kPacketDataLength, 76 VerifyPacketLoss(0, nbr_packets_dropped, kPacketDataLength, packet_data_,
81 packet_data_, image_); 77 image_);
82 } 78 }
83 79
84 TEST_F(PacketManipulatorTest, UniformDropNoneSmallFrame) { 80 TEST_F(PacketManipulatorTest, UniformDropNoneSmallFrame) {
85 size_t data_length = 400; // smaller than the packet size 81 size_t data_length = 400; // smaller than the packet size
86 image_._length = data_length; 82 image_._length = data_length;
87 PacketManipulatorImpl manipulator(&packet_reader_, no_drop_config_, false); 83 PacketManipulatorImpl manipulator(&packet_reader_, no_drop_config_, false);
88 int nbr_packets_dropped = manipulator.ManipulatePackets(&image_); 84 int nbr_packets_dropped = manipulator.ManipulatePackets(&image_);
89 85
90 VerifyPacketLoss(0, nbr_packets_dropped, data_length, 86 VerifyPacketLoss(0, nbr_packets_dropped, data_length, packet_data_, image_);
91 packet_data_, image_);
92 } 87 }
93 88
94 TEST_F(PacketManipulatorTest, UniformDropAll) { 89 TEST_F(PacketManipulatorTest, UniformDropAll) {
95 PacketManipulatorImpl manipulator(&packet_reader_, drop_config_, false); 90 PacketManipulatorImpl manipulator(&packet_reader_, drop_config_, false);
96 int nbr_packets_dropped = manipulator.ManipulatePackets(&image_); 91 int nbr_packets_dropped = manipulator.ManipulatePackets(&image_);
97 VerifyPacketLoss(kPacketDataNumberOfPackets, nbr_packets_dropped, 92 VerifyPacketLoss(kPacketDataNumberOfPackets, nbr_packets_dropped, 0,
98 0, packet_data_, image_); 93 packet_data_, image_);
99 } 94 }
100 95
101 // Use our customized test class to make the second packet being lost 96 // Use our customized test class to make the second packet being lost
102 TEST_F(PacketManipulatorTest, UniformDropSinglePacket) { 97 TEST_F(PacketManipulatorTest, UniformDropSinglePacket) {
103 drop_config_.packet_loss_probability = 0.5; 98 drop_config_.packet_loss_probability = 0.5;
104 PredictivePacketManipulator manipulator(&packet_reader_, drop_config_); 99 PredictivePacketManipulator manipulator(&packet_reader_, drop_config_);
105 manipulator.AddRandomResult(1.0); 100 manipulator.AddRandomResult(1.0);
106 manipulator.AddRandomResult(0.3); // less than 0.5 will cause packet loss 101 manipulator.AddRandomResult(0.3); // less than 0.5 will cause packet loss
107 manipulator.AddRandomResult(1.0); 102 manipulator.AddRandomResult(1.0);
108 103
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 139
145 // Execute the test target method: 140 // Execute the test target method:
146 int nbr_packets_dropped = manipulator.ManipulatePackets(&image_); 141 int nbr_packets_dropped = manipulator.ManipulatePackets(&image_);
147 142
148 // Should discard every packet after the first one. 143 // Should discard every packet after the first one.
149 VerifyPacketLoss(9, nbr_packets_dropped, kPacketSizeInBytes, data, image_); 144 VerifyPacketLoss(9, nbr_packets_dropped, kPacketSizeInBytes, data, image_);
150 } 145 }
151 146
152 } // namespace test 147 } // namespace test
153 } // namespace webrtc 148 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698