| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 EXPECT_EQ(STATUS_INITIALIZED, status); | 105 EXPECT_EQ(STATUS_INITIALIZED, status); |
| 106 } | 106 } |
| 107 | 107 |
| 108 // This is wrapped in a struct because it needs to be put into a std::map. | 108 // This is wrapped in a struct because it needs to be put into a std::map. |
| 109 typedef struct { | 109 typedef struct { |
| 110 int counter[kNumOfLoggingEvents+1]; | 110 int counter[kNumOfLoggingEvents+1]; |
| 111 } LoggingEventCounts; | 111 } LoggingEventCounts; |
| 112 | 112 |
| 113 // Constructs a map from each frame (RTP timestamp) to counts of each event | 113 // Constructs a map from each frame (RTP timestamp) to counts of each event |
| 114 // type logged for that frame. | 114 // type logged for that frame. |
| 115 std::map<RtpTimestamp, LoggingEventCounts> GetEventCountForFrameEvents( | 115 std::map<RtpTimeTicks, LoggingEventCounts> GetEventCountForFrameEvents( |
| 116 const std::vector<FrameEvent>& frame_events) { | 116 const std::vector<FrameEvent>& frame_events) { |
| 117 std::map<RtpTimestamp, LoggingEventCounts> event_counter_for_frame; | 117 std::map<RtpTimeTicks, LoggingEventCounts> event_counter_for_frame; |
| 118 for (std::vector<FrameEvent>::const_iterator it = frame_events.begin(); | 118 for (const FrameEvent& frame_event : frame_events) { |
| 119 it != frame_events.end(); | 119 auto map_it = event_counter_for_frame.find(frame_event.rtp_timestamp); |
| 120 ++it) { | |
| 121 std::map<RtpTimestamp, LoggingEventCounts>::iterator map_it = | |
| 122 event_counter_for_frame.find(it->rtp_timestamp); | |
| 123 if (map_it == event_counter_for_frame.end()) { | 120 if (map_it == event_counter_for_frame.end()) { |
| 124 LoggingEventCounts new_counter; | 121 LoggingEventCounts new_counter; |
| 125 memset(&new_counter, 0, sizeof(new_counter)); | 122 memset(&new_counter, 0, sizeof(new_counter)); |
| 126 ++(new_counter.counter[it->type]); | 123 ++(new_counter.counter[frame_event.type]); |
| 127 event_counter_for_frame.insert( | 124 event_counter_for_frame.insert( |
| 128 std::make_pair(it->rtp_timestamp, new_counter)); | 125 std::make_pair(frame_event.rtp_timestamp, new_counter)); |
| 129 } else { | 126 } else { |
| 130 ++(map_it->second.counter[it->type]); | 127 ++(map_it->second.counter[frame_event.type]); |
| 131 } | 128 } |
| 132 } | 129 } |
| 133 return event_counter_for_frame; | 130 return event_counter_for_frame; |
| 134 } | 131 } |
| 135 | 132 |
| 136 // Constructs a map from each packet (Packet ID) to counts of each event | 133 // Constructs a map from each packet (Packet ID) to counts of each event |
| 137 // type logged for that packet. | 134 // type logged for that packet. |
| 138 std::map<uint16, LoggingEventCounts> GetEventCountForPacketEvents( | 135 std::map<uint16, LoggingEventCounts> GetEventCountForPacketEvents( |
| 139 const std::vector<PacketEvent>& packet_events) { | 136 const std::vector<PacketEvent>& packet_events) { |
| 140 std::map<uint16, LoggingEventCounts> event_counter_for_packet; | 137 std::map<uint16, LoggingEventCounts> event_counter_for_packet; |
| 141 for (std::vector<PacketEvent>::const_iterator it = packet_events.begin(); | 138 for (const PacketEvent& packet_event : packet_events) { |
| 142 it != packet_events.end(); | 139 auto map_it = event_counter_for_packet.find(packet_event.packet_id); |
| 143 ++it) { | |
| 144 std::map<uint16, LoggingEventCounts>::iterator map_it = | |
| 145 event_counter_for_packet.find(it->packet_id); | |
| 146 if (map_it == event_counter_for_packet.end()) { | 140 if (map_it == event_counter_for_packet.end()) { |
| 147 LoggingEventCounts new_counter; | 141 LoggingEventCounts new_counter; |
| 148 memset(&new_counter, 0, sizeof(new_counter)); | 142 memset(&new_counter, 0, sizeof(new_counter)); |
| 149 ++(new_counter.counter[it->type]); | 143 ++(new_counter.counter[packet_event.type]); |
| 150 event_counter_for_packet.insert( | 144 event_counter_for_packet.insert( |
| 151 std::make_pair(it->packet_id, new_counter)); | 145 std::make_pair(packet_event.packet_id, new_counter)); |
| 152 } else { | 146 } else { |
| 153 ++(map_it->second.counter[it->type]); | 147 ++(map_it->second.counter[packet_event.type]); |
| 154 } | 148 } |
| 155 } | 149 } |
| 156 return event_counter_for_packet; | 150 return event_counter_for_packet; |
| 157 } | 151 } |
| 158 | 152 |
| 159 // Shim that turns forwards packets from a test::PacketPipe to a | 153 // Shim that turns forwards packets from a test::PacketPipe to a |
| 160 // PacketReceiverCallback. | 154 // PacketReceiverCallback. |
| 161 class LoopBackPacketPipe : public test::PacketPipe { | 155 class LoopBackPacketPipe : public test::PacketPipe { |
| 162 public: | 156 public: |
| 163 explicit LoopBackPacketPipe(const PacketReceiverCallback& packet_receiver) | 157 explicit LoopBackPacketPipe(const PacketReceiverCallback& packet_receiver) |
| (...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 | 1058 |
| 1065 RunTasks(750); // Make sure that we send a RTCP message with the log. | 1059 RunTasks(750); // Make sure that we send a RTCP message with the log. |
| 1066 | 1060 |
| 1067 // Logging tests. | 1061 // Logging tests. |
| 1068 // Frame logging. | 1062 // Frame logging. |
| 1069 // Verify that all frames and all required events were logged. | 1063 // Verify that all frames and all required events were logged. |
| 1070 event_subscriber_sender_.GetFrameEventsAndReset(&frame_events_); | 1064 event_subscriber_sender_.GetFrameEventsAndReset(&frame_events_); |
| 1071 | 1065 |
| 1072 // For each frame, count the number of events that occurred for each event | 1066 // For each frame, count the number of events that occurred for each event |
| 1073 // for that frame. | 1067 // for that frame. |
| 1074 std::map<RtpTimestamp, LoggingEventCounts> event_counter_for_frame = | 1068 std::map<RtpTimeTicks, LoggingEventCounts> event_counter_for_frame = |
| 1075 GetEventCountForFrameEvents(frame_events_); | 1069 GetEventCountForFrameEvents(frame_events_); |
| 1076 | 1070 |
| 1077 // Verify that there are logs for expected number of frames. | 1071 // Verify that there are logs for expected number of frames. |
| 1078 EXPECT_EQ(num_frames, static_cast<int>(event_counter_for_frame.size())); | 1072 EXPECT_EQ(num_frames, static_cast<int>(event_counter_for_frame.size())); |
| 1079 | 1073 |
| 1080 // Verify that each frame have the expected types of events logged. | 1074 // Verify that each frame have the expected types of events logged. |
| 1081 for (std::map<RtpTimestamp, LoggingEventCounts>::iterator map_it = | 1075 for (std::map<RtpTimeTicks, LoggingEventCounts>::iterator map_it = |
| 1082 event_counter_for_frame.begin(); | 1076 event_counter_for_frame.begin(); |
| 1083 map_it != event_counter_for_frame.end(); | 1077 map_it != event_counter_for_frame.end(); ++map_it) { |
| 1084 ++map_it) { | |
| 1085 int total_event_count_for_frame = 0; | 1078 int total_event_count_for_frame = 0; |
| 1086 for (int i = 0; i <= kNumOfLoggingEvents; ++i) { | 1079 for (int i = 0; i <= kNumOfLoggingEvents; ++i) { |
| 1087 total_event_count_for_frame += map_it->second.counter[i]; | 1080 total_event_count_for_frame += map_it->second.counter[i]; |
| 1088 } | 1081 } |
| 1089 | 1082 |
| 1090 int expected_event_count_for_frame = 0; | 1083 int expected_event_count_for_frame = 0; |
| 1091 | 1084 |
| 1092 EXPECT_EQ(1, map_it->second.counter[FRAME_CAPTURE_BEGIN]); | 1085 EXPECT_EQ(1, map_it->second.counter[FRAME_CAPTURE_BEGIN]); |
| 1093 expected_event_count_for_frame += | 1086 expected_event_count_for_frame += |
| 1094 map_it->second.counter[FRAME_CAPTURE_BEGIN]; | 1087 map_it->second.counter[FRAME_CAPTURE_BEGIN]; |
| (...skipping 87 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 |