OLD | NEW |
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 |
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 NetEqOutputType type; | 998 NetEqOutputType type; |
999 EXPECT_EQ(NetEq::kOK, | 999 EXPECT_EQ(NetEq::kOK, |
1000 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, | 1000 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
1001 &num_channels, &type)); | 1001 &num_channels, &type)); |
1002 ASSERT_EQ(kMaxOutputSize, samples_per_channel); | 1002 ASSERT_EQ(kMaxOutputSize, samples_per_channel); |
1003 EXPECT_EQ(1, num_channels); | 1003 EXPECT_EQ(1, num_channels); |
1004 EXPECT_EQ(kOutputNormal, type); | 1004 EXPECT_EQ(kOutputNormal, type); |
1005 | 1005 |
1006 EXPECT_CALL(mock_decoder, Die()); | 1006 EXPECT_CALL(mock_decoder, Die()); |
1007 } | 1007 } |
1008 } // namespace webrtc | 1008 |
| 1009 // This test checks the behavior of NetEq when audio decoder fails. |
| 1010 TEST_F(NetEqImplTest, DecodingError) { |
| 1011 UseNoMocks(); |
| 1012 CreateInstance(); |
| 1013 |
| 1014 const uint8_t kPayloadType = 17; // Just an arbitrary number. |
| 1015 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test. |
| 1016 const int kSampleRateHz = 8000; |
| 1017 |
| 1018 // We let decoder gives 5 ms each time, and therefore, 2 packets make 10 ms. |
| 1019 const size_t kFrameLengthSamples = |
| 1020 static_cast<size_t>(5 * kSampleRateHz / 1000); |
| 1021 |
| 1022 const size_t kPayloadLengthBytes = 1; // This can be arbitrary. |
| 1023 |
| 1024 uint8_t payload[kPayloadLengthBytes] = {0}; |
| 1025 |
| 1026 WebRtcRTPHeader rtp_header; |
| 1027 rtp_header.header.payloadType = kPayloadType; |
| 1028 rtp_header.header.sequenceNumber = 0x1234; |
| 1029 rtp_header.header.timestamp = 0x12345678; |
| 1030 rtp_header.header.ssrc = 0x87654321; |
| 1031 |
| 1032 // Create a mock decoder object. |
| 1033 MockAudioDecoder mock_decoder; |
| 1034 EXPECT_CALL(mock_decoder, Reset()).WillRepeatedly(Return()); |
| 1035 EXPECT_CALL(mock_decoder, Channels()).WillRepeatedly(Return(1)); |
| 1036 EXPECT_CALL(mock_decoder, IncomingPacket(_, kPayloadLengthBytes, _, _, _)) |
| 1037 .WillRepeatedly(Return(0)); |
| 1038 EXPECT_CALL(mock_decoder, PacketDuration(_, _)) |
| 1039 .WillRepeatedly(Return(kFrameLengthSamples)); |
| 1040 EXPECT_CALL(mock_decoder, ErrorCode()) |
| 1041 .WillOnce(Return(NetEq::kDecoderErrorCode)); |
| 1042 EXPECT_CALL(mock_decoder, HasDecodePlc()) |
| 1043 .WillOnce(Return(false)); |
| 1044 int16_t dummy_output[kFrameLengthSamples] = {0}; |
| 1045 |
| 1046 { |
| 1047 InSequence sequence; // Dummy variable. |
| 1048 // Mock decoder works normally the first time. |
| 1049 EXPECT_CALL(mock_decoder, |
| 1050 Decode(_, kPayloadLengthBytes, kSampleRateHz, _, _, _)) |
| 1051 .Times(3) |
| 1052 .WillRepeatedly( |
| 1053 DoAll(SetArrayArgument<4>(dummy_output, |
| 1054 dummy_output + kFrameLengthSamples), |
| 1055 SetArgPointee<5>(AudioDecoder::kSpeech), |
| 1056 Return(kFrameLengthSamples))) |
| 1057 .RetiresOnSaturation(); |
| 1058 |
| 1059 // Then mock decoder fails. A common reason for failure can be buffer being |
| 1060 // too short |
| 1061 EXPECT_CALL(mock_decoder, |
| 1062 Decode(_, kPayloadLengthBytes, kSampleRateHz, _, _, _)) |
| 1063 .WillOnce(Return(-1)) |
| 1064 .RetiresOnSaturation(); |
| 1065 |
| 1066 // Mock decoder finally returns to normal. |
| 1067 EXPECT_CALL(mock_decoder, |
| 1068 Decode(_, kPayloadLengthBytes, kSampleRateHz, _, _, _)) |
| 1069 .Times(2) |
| 1070 .WillRepeatedly( |
| 1071 DoAll(SetArrayArgument<4>(dummy_output, |
| 1072 dummy_output + kFrameLengthSamples), |
| 1073 SetArgPointee<5>(AudioDecoder::kSpeech), |
| 1074 Return(kFrameLengthSamples))); |
| 1075 } |
| 1076 |
| 1077 EXPECT_EQ(NetEq::kOK, |
| 1078 neteq_->RegisterExternalDecoder(&mock_decoder, kDecoderPCM16B, |
| 1079 kPayloadType, kSampleRateHz)); |
| 1080 |
| 1081 // Insert packets. |
| 1082 for (int i = 0; i < 6; ++i) { |
| 1083 rtp_header.header.sequenceNumber += 1; |
| 1084 rtp_header.header.timestamp += kFrameLengthSamples; |
| 1085 EXPECT_EQ(NetEq::kOK, |
| 1086 neteq_->InsertPacket(rtp_header, payload, kPayloadLengthBytes, |
| 1087 kReceiveTime)); |
| 1088 } |
| 1089 |
| 1090 // Pull audio. |
| 1091 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); |
| 1092 int16_t output[kMaxOutputSize]; |
| 1093 size_t samples_per_channel; |
| 1094 int num_channels; |
| 1095 NetEqOutputType type; |
| 1096 EXPECT_EQ(NetEq::kOK, |
| 1097 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 1098 &num_channels, &type)); |
| 1099 EXPECT_EQ(kMaxOutputSize, samples_per_channel); |
| 1100 EXPECT_EQ(1, num_channels); |
| 1101 EXPECT_EQ(kOutputNormal, type); |
| 1102 |
| 1103 // Pull audio again. Decoder fails. |
| 1104 EXPECT_EQ(NetEq::kFail, |
| 1105 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 1106 &num_channels, &type)); |
| 1107 EXPECT_EQ(kMaxOutputSize, samples_per_channel); |
| 1108 EXPECT_EQ(1, num_channels); |
| 1109 // TODO(minyue): should NetEq better give kOutputPLC, since it is actually an |
| 1110 // expansion. |
| 1111 EXPECT_EQ(kOutputNormal, type); |
| 1112 |
| 1113 // Pull audio again, should continue an expansion. |
| 1114 EXPECT_EQ(NetEq::kOK, |
| 1115 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 1116 &num_channels, &type)); |
| 1117 EXPECT_EQ(kMaxOutputSize, samples_per_channel); |
| 1118 EXPECT_EQ(1, num_channels); |
| 1119 EXPECT_EQ(kOutputPLC, type); |
| 1120 |
| 1121 // Pull audio again, should behave normal. |
| 1122 EXPECT_EQ(NetEq::kOK, |
| 1123 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 1124 &num_channels, &type)); |
| 1125 EXPECT_EQ(kMaxOutputSize, samples_per_channel); |
| 1126 EXPECT_EQ(1, num_channels); |
| 1127 EXPECT_EQ(kOutputNormal, type); |
| 1128 |
| 1129 EXPECT_CALL(mock_decoder, Die()); |
| 1130 } |
| 1131 |
| 1132 // This test checks the behavior of NetEq when audio decoder fails. |
| 1133 TEST_F(NetEqImplTest, DecodingErrorDuringInternalCng) { |
| 1134 UseNoMocks(); |
| 1135 CreateInstance(); |
| 1136 |
| 1137 const uint8_t kPayloadType = 17; // Just an arbitrary number. |
| 1138 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test. |
| 1139 const int kSampleRateHz = 8000; |
| 1140 |
| 1141 // We let decoder gives 5 ms each time. |
| 1142 const size_t kFrameLengthSamples = |
| 1143 static_cast<size_t>(5 * kSampleRateHz / 1000); |
| 1144 |
| 1145 const size_t kPayloadLengthBytes = 1; // This can be arbitrary. |
| 1146 |
| 1147 uint8_t payload[kPayloadLengthBytes] = {0}; |
| 1148 |
| 1149 WebRtcRTPHeader rtp_header; |
| 1150 rtp_header.header.payloadType = kPayloadType; |
| 1151 rtp_header.header.sequenceNumber = 0x1234; |
| 1152 rtp_header.header.timestamp = 0x12345678; |
| 1153 rtp_header.header.ssrc = 0x87654321; |
| 1154 |
| 1155 // Create a mock decoder object. |
| 1156 MockAudioDecoder mock_decoder; |
| 1157 EXPECT_CALL(mock_decoder, Reset()).WillRepeatedly(Return()); |
| 1158 EXPECT_CALL(mock_decoder, Channels()).WillRepeatedly(Return(1)); |
| 1159 EXPECT_CALL(mock_decoder, IncomingPacket(_, kPayloadLengthBytes, _, _, _)) |
| 1160 .WillRepeatedly(Return(0)); |
| 1161 EXPECT_CALL(mock_decoder, PacketDuration(_, _)) |
| 1162 .WillRepeatedly(Return(kFrameLengthSamples)); |
| 1163 EXPECT_CALL(mock_decoder, ErrorCode()) |
| 1164 .WillOnce(Return(NetEq::kDecoderErrorCode)); |
| 1165 int16_t dummy_output[kFrameLengthSamples] = {0}; |
| 1166 |
| 1167 { |
| 1168 InSequence sequence; // Dummy variable. |
| 1169 // Mock decoder works normally the first 2 times. |
| 1170 EXPECT_CALL(mock_decoder, |
| 1171 Decode(_, kPayloadLengthBytes, kSampleRateHz, _, _, _)) |
| 1172 .Times(2) |
| 1173 .WillRepeatedly( |
| 1174 DoAll(SetArrayArgument<4>(dummy_output, |
| 1175 dummy_output + kFrameLengthSamples), |
| 1176 SetArgPointee<5>(AudioDecoder::kComfortNoise), |
| 1177 Return(kFrameLengthSamples))) |
| 1178 .RetiresOnSaturation(); |
| 1179 |
| 1180 // Then mock decoder fails. A common reason for failure can be buffer being |
| 1181 // too short |
| 1182 EXPECT_CALL(mock_decoder, |
| 1183 Decode(nullptr, 0, kSampleRateHz, _, _, _)) |
| 1184 .WillOnce(Return(-1)) |
| 1185 .RetiresOnSaturation(); |
| 1186 |
| 1187 // Mock decoder finally returns to normal. |
| 1188 EXPECT_CALL(mock_decoder, |
| 1189 Decode(nullptr, 0, kSampleRateHz, _, _, _)) |
| 1190 .Times(2) |
| 1191 .WillRepeatedly( |
| 1192 DoAll(SetArrayArgument<4>(dummy_output, |
| 1193 dummy_output + kFrameLengthSamples), |
| 1194 SetArgPointee<5>(AudioDecoder::kComfortNoise), |
| 1195 Return(kFrameLengthSamples))); |
| 1196 } |
| 1197 |
| 1198 EXPECT_EQ(NetEq::kOK, |
| 1199 neteq_->RegisterExternalDecoder(&mock_decoder, kDecoderPCM16B, |
| 1200 kPayloadType, kSampleRateHz)); |
| 1201 |
| 1202 // Insert 2 packets. This will make netEq into codec internal CNG mode. |
| 1203 for (int i = 0; i < 2; ++i) { |
| 1204 rtp_header.header.sequenceNumber += 1; |
| 1205 rtp_header.header.timestamp += kFrameLengthSamples; |
| 1206 EXPECT_EQ(NetEq::kOK, |
| 1207 neteq_->InsertPacket(rtp_header, payload, kPayloadLengthBytes, |
| 1208 kReceiveTime)); |
| 1209 } |
| 1210 |
| 1211 // Pull audio. |
| 1212 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000); |
| 1213 int16_t output[kMaxOutputSize]; |
| 1214 size_t samples_per_channel; |
| 1215 int num_channels; |
| 1216 NetEqOutputType type; |
| 1217 EXPECT_EQ(NetEq::kOK, |
| 1218 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 1219 &num_channels, &type)); |
| 1220 EXPECT_EQ(kMaxOutputSize, samples_per_channel); |
| 1221 EXPECT_EQ(1, num_channels); |
| 1222 EXPECT_EQ(kOutputCNG, type); |
| 1223 |
| 1224 // Pull audio again. Decoder fails. |
| 1225 EXPECT_EQ(NetEq::kFail, |
| 1226 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 1227 &num_channels, &type)); |
| 1228 EXPECT_EQ(kMaxOutputSize, samples_per_channel); |
| 1229 EXPECT_EQ(1, num_channels); |
| 1230 // TODO(minyue): should NetEq better give kOutputPLC, since it is actually an |
| 1231 // expansion. |
| 1232 EXPECT_EQ(kOutputCNG, type); |
| 1233 |
| 1234 // Pull audio again, should behave normal. |
| 1235 EXPECT_EQ(NetEq::kOK, |
| 1236 neteq_->GetAudio(kMaxOutputSize, output, &samples_per_channel, |
| 1237 &num_channels, &type)); |
| 1238 EXPECT_EQ(kMaxOutputSize, samples_per_channel); |
| 1239 EXPECT_EQ(1, num_channels); |
| 1240 EXPECT_EQ(kOutputCNG, type); |
| 1241 |
| 1242 EXPECT_CALL(mock_decoder, Die()); |
| 1243 } |
| 1244 |
| 1245 }// namespace webrtc |
OLD | NEW |