| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 static const bool sub_packets_dummy = | 96 static const bool sub_packets_dummy = |
| 97 RegisterFlagValidator(&FLAGS_sub_packets, &ValidateSubPackets); | 97 RegisterFlagValidator(&FLAGS_sub_packets, &ValidateSubPackets); |
| 98 | 98 |
| 99 } // namepsace | 99 } // namepsace |
| 100 | 100 |
| 101 class NetEqOpusQualityTest : public NetEqQualityTest { | 101 class NetEqOpusQualityTest : public NetEqQualityTest { |
| 102 protected: | 102 protected: |
| 103 NetEqOpusQualityTest(); | 103 NetEqOpusQualityTest(); |
| 104 void SetUp() override; | 104 void SetUp() override; |
| 105 void TearDown() override; | 105 void TearDown() override; |
| 106 virtual int EncodeBlock(int16_t* in_data, int block_size_samples, | 106 virtual int EncodeBlock(int16_t* in_data, size_t block_size_samples, |
| 107 uint8_t* payload, int max_bytes); | 107 uint8_t* payload, size_t max_bytes); |
| 108 private: | 108 private: |
| 109 WebRtcOpusEncInst* opus_encoder_; | 109 WebRtcOpusEncInst* opus_encoder_; |
| 110 OpusRepacketizer* repacketizer_; | 110 OpusRepacketizer* repacketizer_; |
| 111 int sub_block_size_samples_; | 111 size_t sub_block_size_samples_; |
| 112 int bit_rate_kbps_; | 112 int bit_rate_kbps_; |
| 113 bool fec_; | 113 bool fec_; |
| 114 bool dtx_; | 114 bool dtx_; |
| 115 int complexity_; | 115 int complexity_; |
| 116 int maxplaybackrate_; | 116 int maxplaybackrate_; |
| 117 int target_loss_rate_; | 117 int target_loss_rate_; |
| 118 int sub_packets_; | 118 int sub_packets_; |
| 119 int application_; | 119 int application_; |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 NetEqOpusQualityTest::NetEqOpusQualityTest() | 122 NetEqOpusQualityTest::NetEqOpusQualityTest() |
| 123 : NetEqQualityTest(kOpusBlockDurationMs * FLAGS_sub_packets, | 123 : NetEqQualityTest(kOpusBlockDurationMs * FLAGS_sub_packets, |
| 124 kOpusSamplingKhz, | 124 kOpusSamplingKhz, |
| 125 kOpusSamplingKhz, | 125 kOpusSamplingKhz, |
| 126 kDecoderOpus), | 126 kDecoderOpus), |
| 127 opus_encoder_(NULL), | 127 opus_encoder_(NULL), |
| 128 repacketizer_(NULL), | 128 repacketizer_(NULL), |
| 129 sub_block_size_samples_(kOpusBlockDurationMs * kOpusSamplingKhz), | 129 sub_block_size_samples_( |
| 130 static_cast<size_t>(kOpusBlockDurationMs * kOpusSamplingKhz)), |
| 130 bit_rate_kbps_(FLAGS_bit_rate_kbps), | 131 bit_rate_kbps_(FLAGS_bit_rate_kbps), |
| 131 fec_(FLAGS_fec), | 132 fec_(FLAGS_fec), |
| 132 dtx_(FLAGS_dtx), | 133 dtx_(FLAGS_dtx), |
| 133 complexity_(FLAGS_complexity), | 134 complexity_(FLAGS_complexity), |
| 134 maxplaybackrate_(FLAGS_maxplaybackrate), | 135 maxplaybackrate_(FLAGS_maxplaybackrate), |
| 135 target_loss_rate_(FLAGS_reported_loss_rate), | 136 target_loss_rate_(FLAGS_reported_loss_rate), |
| 136 sub_packets_(FLAGS_sub_packets) { | 137 sub_packets_(FLAGS_sub_packets) { |
| 137 // Redefine decoder type if input is stereo. | 138 // Redefine decoder type if input is stereo. |
| 138 if (channels_ > 1) { | 139 if (channels_ > 1) { |
| 139 decoder_type_ = kDecoderOpus_2ch; | 140 decoder_type_ = kDecoderOpus_2ch; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 166 } | 167 } |
| 167 | 168 |
| 168 void NetEqOpusQualityTest::TearDown() { | 169 void NetEqOpusQualityTest::TearDown() { |
| 169 // Free memory. | 170 // Free memory. |
| 170 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); | 171 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); |
| 171 opus_repacketizer_destroy(repacketizer_); | 172 opus_repacketizer_destroy(repacketizer_); |
| 172 NetEqQualityTest::TearDown(); | 173 NetEqQualityTest::TearDown(); |
| 173 } | 174 } |
| 174 | 175 |
| 175 int NetEqOpusQualityTest::EncodeBlock(int16_t* in_data, | 176 int NetEqOpusQualityTest::EncodeBlock(int16_t* in_data, |
| 176 int block_size_samples, | 177 size_t block_size_samples, |
| 177 uint8_t* payload, int max_bytes) { | 178 uint8_t* payload, size_t max_bytes) { |
| 178 EXPECT_EQ(block_size_samples, sub_block_size_samples_ * sub_packets_); | 179 EXPECT_EQ(block_size_samples, sub_block_size_samples_ * sub_packets_); |
| 179 int16_t* pointer = in_data; | 180 int16_t* pointer = in_data; |
| 180 int value; | 181 int value; |
| 181 opus_repacketizer_init(repacketizer_); | 182 opus_repacketizer_init(repacketizer_); |
| 182 for (int idx = 0; idx < sub_packets_; idx++) { | 183 for (int idx = 0; idx < sub_packets_; idx++) { |
| 183 value = WebRtcOpus_Encode(opus_encoder_, pointer, sub_block_size_samples_, | 184 value = WebRtcOpus_Encode(opus_encoder_, pointer, sub_block_size_samples_, |
| 184 max_bytes, payload); | 185 max_bytes, payload); |
| 185 Log() << "Encoded a frame with Opus mode " | 186 Log() << "Encoded a frame with Opus mode " |
| 186 << (value == 0 ? 0 : payload[0] >> 3) | 187 << (value == 0 ? 0 : payload[0] >> 3) |
| 187 << std::endl; | 188 << std::endl; |
| 188 if (OPUS_OK != opus_repacketizer_cat(repacketizer_, payload, value)) { | 189 if (OPUS_OK != opus_repacketizer_cat(repacketizer_, payload, value)) { |
| 189 opus_repacketizer_init(repacketizer_); | 190 opus_repacketizer_init(repacketizer_); |
| 190 // If the repacketization fails, we discard this frame. | 191 // If the repacketization fails, we discard this frame. |
| 191 return 0; | 192 return 0; |
| 192 } | 193 } |
| 193 pointer += sub_block_size_samples_ * channels_; | 194 pointer += sub_block_size_samples_ * channels_; |
| 194 } | 195 } |
| 195 value = opus_repacketizer_out(repacketizer_, payload, max_bytes); | 196 value = opus_repacketizer_out(repacketizer_, payload, |
| 197 static_cast<opus_int32>(max_bytes)); |
| 196 EXPECT_GE(value, 0); | 198 EXPECT_GE(value, 0); |
| 197 return value; | 199 return value; |
| 198 } | 200 } |
| 199 | 201 |
| 200 TEST_F(NetEqOpusQualityTest, Test) { | 202 TEST_F(NetEqOpusQualityTest, Test) { |
| 201 Simulate(); | 203 Simulate(); |
| 202 } | 204 } |
| 203 | 205 |
| 204 } // namespace test | 206 } // namespace test |
| 205 } // namespace webrtc | 207 } // namespace webrtc |
| OLD | NEW |