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

Side by Side Diff: webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698