OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // This test generate synthetic data. For audio it's a sinusoid waveform with | 5 // This test generate synthetic data. For audio it's a sinusoid waveform with |
6 // frequency kSoundFrequency and different amplitudes. For video it's a pattern | 6 // frequency kSoundFrequency and different amplitudes. For video it's a pattern |
7 // that is shifting by one pixel per frame, each pixels neighbors right and down | 7 // that is shifting by one pixel per frame, each pixels neighbors right and down |
8 // is this pixels value +1, since the pixel value is 8 bit it will wrap | 8 // is this pixels value +1, since the pixel value is 8 bit it will wrap |
9 // frequently within the image. Visually this will create diagonally color bands | 9 // frequently within the image. Visually this will create diagonally color bands |
10 // that moves across the screen | 10 // that moves across the screen |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 EXPECT_EQ(STATUS_INITIALIZED, status); | 106 EXPECT_EQ(STATUS_INITIALIZED, status); |
107 } | 107 } |
108 | 108 |
109 // This is wrapped in a struct because it needs to be put into a std::map. | 109 // This is wrapped in a struct because it needs to be put into a std::map. |
110 typedef struct { | 110 typedef struct { |
111 int counter[kNumOfLoggingEvents+1]; | 111 int counter[kNumOfLoggingEvents+1]; |
112 } LoggingEventCounts; | 112 } LoggingEventCounts; |
113 | 113 |
114 // Constructs a map from each frame (RTP timestamp) to counts of each event | 114 // Constructs a map from each frame (RTP timestamp) to counts of each event |
115 // type logged for that frame. | 115 // type logged for that frame. |
116 std::map<RtpTimestamp, LoggingEventCounts> GetEventCountForFrameEvents( | 116 std::map<RtpTimeTicks, LoggingEventCounts> GetEventCountForFrameEvents( |
117 const std::vector<FrameEvent>& frame_events) { | 117 const std::vector<FrameEvent>& frame_events) { |
118 std::map<RtpTimestamp, LoggingEventCounts> event_counter_for_frame; | 118 std::map<RtpTimeTicks, LoggingEventCounts> event_counter_for_frame; |
119 for (std::vector<FrameEvent>::const_iterator it = frame_events.begin(); | 119 for (const FrameEvent& frame_event : frame_events) { |
120 it != frame_events.end(); | 120 auto map_it = event_counter_for_frame.find(frame_event.rtp_timestamp); |
121 ++it) { | |
122 std::map<RtpTimestamp, LoggingEventCounts>::iterator map_it = | |
123 event_counter_for_frame.find(it->rtp_timestamp); | |
124 if (map_it == event_counter_for_frame.end()) { | 121 if (map_it == event_counter_for_frame.end()) { |
125 LoggingEventCounts new_counter; | 122 LoggingEventCounts new_counter; |
126 memset(&new_counter, 0, sizeof(new_counter)); | 123 memset(&new_counter, 0, sizeof(new_counter)); |
127 ++(new_counter.counter[it->type]); | 124 ++(new_counter.counter[frame_event.type]); |
128 event_counter_for_frame.insert( | 125 event_counter_for_frame.insert( |
129 std::make_pair(it->rtp_timestamp, new_counter)); | 126 std::make_pair(frame_event.rtp_timestamp, new_counter)); |
130 } else { | 127 } else { |
131 ++(map_it->second.counter[it->type]); | 128 ++(map_it->second.counter[frame_event.type]); |
132 } | 129 } |
133 } | 130 } |
134 return event_counter_for_frame; | 131 return event_counter_for_frame; |
135 } | 132 } |
136 | 133 |
137 // Constructs a map from each packet (Packet ID) to counts of each event | 134 // Constructs a map from each packet (Packet ID) to counts of each event |
138 // type logged for that packet. | 135 // type logged for that packet. |
139 std::map<uint16_t, LoggingEventCounts> GetEventCountForPacketEvents( | 136 std::map<uint16_t, LoggingEventCounts> GetEventCountForPacketEvents( |
140 const std::vector<PacketEvent>& packet_events) { | 137 const std::vector<PacketEvent>& packet_events) { |
141 std::map<uint16_t, LoggingEventCounts> event_counter_for_packet; | 138 std::map<uint16_t, LoggingEventCounts> event_counter_for_packet; |
142 for (std::vector<PacketEvent>::const_iterator it = packet_events.begin(); | 139 for (const PacketEvent& packet_event : packet_events) { |
143 it != packet_events.end(); | 140 auto map_it = event_counter_for_packet.find(packet_event.packet_id); |
144 ++it) { | |
145 std::map<uint16_t, LoggingEventCounts>::iterator map_it = | |
146 event_counter_for_packet.find(it->packet_id); | |
147 if (map_it == event_counter_for_packet.end()) { | 141 if (map_it == event_counter_for_packet.end()) { |
148 LoggingEventCounts new_counter; | 142 LoggingEventCounts new_counter; |
149 memset(&new_counter, 0, sizeof(new_counter)); | 143 memset(&new_counter, 0, sizeof(new_counter)); |
150 ++(new_counter.counter[it->type]); | 144 ++(new_counter.counter[packet_event.type]); |
151 event_counter_for_packet.insert( | 145 event_counter_for_packet.insert( |
152 std::make_pair(it->packet_id, new_counter)); | 146 std::make_pair(packet_event.packet_id, new_counter)); |
153 } else { | 147 } else { |
154 ++(map_it->second.counter[it->type]); | 148 ++(map_it->second.counter[packet_event.type]); |
155 } | 149 } |
156 } | 150 } |
157 return event_counter_for_packet; | 151 return event_counter_for_packet; |
158 } | 152 } |
159 | 153 |
160 // Shim that turns forwards packets from a test::PacketPipe to a | 154 // Shim that turns forwards packets from a test::PacketPipe to a |
161 // PacketReceiverCallback. | 155 // PacketReceiverCallback. |
162 class LoopBackPacketPipe : public test::PacketPipe { | 156 class LoopBackPacketPipe : public test::PacketPipe { |
163 public: | 157 public: |
164 explicit LoopBackPacketPipe(const PacketReceiverCallback& packet_receiver) | 158 explicit LoopBackPacketPipe(const PacketReceiverCallback& packet_receiver) |
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 | 1059 |
1066 RunTasks(750); // Make sure that we send a RTCP message with the log. | 1060 RunTasks(750); // Make sure that we send a RTCP message with the log. |
1067 | 1061 |
1068 // Logging tests. | 1062 // Logging tests. |
1069 // Frame logging. | 1063 // Frame logging. |
1070 // Verify that all frames and all required events were logged. | 1064 // Verify that all frames and all required events were logged. |
1071 event_subscriber_sender_.GetFrameEventsAndReset(&frame_events_); | 1065 event_subscriber_sender_.GetFrameEventsAndReset(&frame_events_); |
1072 | 1066 |
1073 // For each frame, count the number of events that occurred for each event | 1067 // For each frame, count the number of events that occurred for each event |
1074 // for that frame. | 1068 // for that frame. |
1075 std::map<RtpTimestamp, LoggingEventCounts> event_counter_for_frame = | 1069 std::map<RtpTimeTicks, LoggingEventCounts> event_counter_for_frame = |
1076 GetEventCountForFrameEvents(frame_events_); | 1070 GetEventCountForFrameEvents(frame_events_); |
1077 | 1071 |
1078 // Verify that there are logs for expected number of frames. | 1072 // Verify that there are logs for expected number of frames. |
1079 EXPECT_EQ(num_frames, static_cast<int>(event_counter_for_frame.size())); | 1073 EXPECT_EQ(num_frames, static_cast<int>(event_counter_for_frame.size())); |
1080 | 1074 |
1081 // Verify that each frame have the expected types of events logged. | 1075 // Verify that each frame have the expected types of events logged. |
1082 for (std::map<RtpTimestamp, LoggingEventCounts>::iterator map_it = | 1076 for (std::map<RtpTimeTicks, LoggingEventCounts>::iterator map_it = |
1083 event_counter_for_frame.begin(); | 1077 event_counter_for_frame.begin(); |
1084 map_it != event_counter_for_frame.end(); | 1078 map_it != event_counter_for_frame.end(); ++map_it) { |
1085 ++map_it) { | |
1086 int total_event_count_for_frame = 0; | 1079 int total_event_count_for_frame = 0; |
1087 for (int i = 0; i <= kNumOfLoggingEvents; ++i) { | 1080 for (int i = 0; i <= kNumOfLoggingEvents; ++i) { |
1088 total_event_count_for_frame += map_it->second.counter[i]; | 1081 total_event_count_for_frame += map_it->second.counter[i]; |
1089 } | 1082 } |
1090 | 1083 |
1091 int expected_event_count_for_frame = 0; | 1084 int expected_event_count_for_frame = 0; |
1092 | 1085 |
1093 EXPECT_EQ(1, map_it->second.counter[FRAME_CAPTURE_BEGIN]); | 1086 EXPECT_EQ(1, map_it->second.counter[FRAME_CAPTURE_BEGIN]); |
1094 expected_event_count_for_frame += | 1087 expected_event_count_for_frame += |
1095 map_it->second.counter[FRAME_CAPTURE_BEGIN]; | 1088 map_it->second.counter[FRAME_CAPTURE_BEGIN]; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 test_receiver_audio_callback_->number_times_called()); | 1175 test_receiver_audio_callback_->number_times_called()); |
1183 | 1176 |
1184 RunTasks(750); // Make sure that we send a RTCP message with the log. | 1177 RunTasks(750); // Make sure that we send a RTCP message with the log. |
1185 | 1178 |
1186 // Logging tests. | 1179 // Logging tests. |
1187 // Verify that all frames and all required events were logged. | 1180 // Verify that all frames and all required events were logged. |
1188 event_subscriber_sender_.GetFrameEventsAndReset(&frame_events_); | 1181 event_subscriber_sender_.GetFrameEventsAndReset(&frame_events_); |
1189 | 1182 |
1190 // Construct a map from each frame (RTP timestamp) to a count of each event | 1183 // Construct a map from each frame (RTP timestamp) to a count of each event |
1191 // type logged for that frame. | 1184 // type logged for that frame. |
1192 std::map<RtpTimestamp, LoggingEventCounts> event_counter_for_frame = | 1185 std::map<RtpTimeTicks, LoggingEventCounts> event_counter_for_frame = |
1193 GetEventCountForFrameEvents(frame_events_); | 1186 GetEventCountForFrameEvents(frame_events_); |
1194 | 1187 |
1195 int encoded_count = 0; | 1188 int encoded_count = 0; |
1196 | 1189 |
1197 // Verify the right number of events were logged for each event type. | 1190 // Verify the right number of events were logged for each event type. |
1198 for (std::map<RtpTimestamp, LoggingEventCounts>::iterator it = | 1191 for (std::map<RtpTimeTicks, LoggingEventCounts>::iterator it = |
1199 event_counter_for_frame.begin(); | 1192 event_counter_for_frame.begin(); |
1200 it != event_counter_for_frame.end(); | 1193 it != event_counter_for_frame.end(); ++it) { |
1201 ++it) { | |
1202 encoded_count += it->second.counter[FRAME_ENCODED]; | 1194 encoded_count += it->second.counter[FRAME_ENCODED]; |
1203 } | 1195 } |
1204 | 1196 |
1205 EXPECT_EQ(num_audio_frames_requested, encoded_count); | 1197 EXPECT_EQ(num_audio_frames_requested, encoded_count); |
1206 | 1198 |
1207 // Verify that each frame have the expected types of events logged. | 1199 // Verify that each frame have the expected types of events logged. |
1208 for (std::map<RtpTimestamp, LoggingEventCounts>::const_iterator map_it = | 1200 for (std::map<RtpTimeTicks, LoggingEventCounts>::const_iterator map_it = |
1209 event_counter_for_frame.begin(); | 1201 event_counter_for_frame.begin(); |
1210 map_it != event_counter_for_frame.end(); ++map_it) { | 1202 map_it != event_counter_for_frame.end(); ++map_it) { |
1211 int total_event_count_for_frame = 0; | 1203 int total_event_count_for_frame = 0; |
1212 for (int j = 0; j <= kNumOfLoggingEvents; ++j) | 1204 for (int j = 0; j <= kNumOfLoggingEvents; ++j) |
1213 total_event_count_for_frame += map_it->second.counter[j]; | 1205 total_event_count_for_frame += map_it->second.counter[j]; |
1214 | 1206 |
1215 int expected_event_count_for_frame = 0; | 1207 int expected_event_count_for_frame = 0; |
1216 | 1208 |
1217 EXPECT_EQ(1, map_it->second.counter[FRAME_ENCODED]); | 1209 EXPECT_EQ(1, map_it->second.counter[FRAME_ENCODED]); |
1218 expected_event_count_for_frame += | 1210 expected_event_count_for_frame += |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1444 EXPECT_LT(jump, 220u); | 1436 EXPECT_LT(jump, 220u); |
1445 } | 1437 } |
1446 | 1438 |
1447 // TODO(pwestin): Add repeatable packet loss test. | 1439 // TODO(pwestin): Add repeatable packet loss test. |
1448 // TODO(pwestin): Add test for misaligned send get calls. | 1440 // TODO(pwestin): Add test for misaligned send get calls. |
1449 // TODO(pwestin): Add more tests that does not resample. | 1441 // TODO(pwestin): Add more tests that does not resample. |
1450 // TODO(pwestin): Add test when we have starvation for our RunTask. | 1442 // TODO(pwestin): Add test when we have starvation for our RunTask. |
1451 | 1443 |
1452 } // namespace cast | 1444 } // namespace cast |
1453 } // namespace media | 1445 } // namespace media |
OLD | NEW |