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 27 matching lines...) Expand all Loading... |
38 | 38 |
39 virtual void SetUp(); | 39 virtual void SetUp(); |
40 virtual void TearDown(); | 40 virtual void TearDown(); |
41 | 41 |
42 virtual void EncodeABlock(); | 42 virtual void EncodeABlock(); |
43 | 43 |
44 virtual void DecodeABlock(bool lost_previous, bool lost_current); | 44 virtual void DecodeABlock(bool lost_previous, bool lost_current); |
45 | 45 |
46 int block_duration_ms_; | 46 int block_duration_ms_; |
47 int sampling_khz_; | 47 int sampling_khz_; |
48 int block_length_sample_; | 48 size_t block_length_sample_; |
49 | 49 |
50 int channels_; | 50 int channels_; |
51 int bit_rate_; | 51 int bit_rate_; |
52 | 52 |
53 size_t data_pointer_; | 53 size_t data_pointer_; |
54 size_t loop_length_samples_; | 54 size_t loop_length_samples_; |
55 int max_bytes_; | 55 size_t max_bytes_; |
56 int encoded_bytes_; | 56 size_t encoded_bytes_; |
57 | 57 |
58 WebRtcOpusEncInst* opus_encoder_; | 58 WebRtcOpusEncInst* opus_encoder_; |
59 WebRtcOpusDecInst* opus_decoder_; | 59 WebRtcOpusDecInst* opus_decoder_; |
60 | 60 |
61 string in_filename_; | 61 string in_filename_; |
62 | 62 |
63 rtc::scoped_ptr<int16_t[]> in_data_; | 63 rtc::scoped_ptr<int16_t[]> in_data_; |
64 rtc::scoped_ptr<int16_t[]> out_data_; | 64 rtc::scoped_ptr<int16_t[]> out_data_; |
65 rtc::scoped_ptr<uint8_t[]> bit_stream_; | 65 rtc::scoped_ptr<uint8_t[]> bit_stream_; |
66 }; | 66 }; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 115 |
116 void OpusFecTest::TearDown() { | 116 void OpusFecTest::TearDown() { |
117 // Free memory. | 117 // Free memory. |
118 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); | 118 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); |
119 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); | 119 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); |
120 } | 120 } |
121 | 121 |
122 OpusFecTest::OpusFecTest() | 122 OpusFecTest::OpusFecTest() |
123 : block_duration_ms_(kOpusBlockDurationMs), | 123 : block_duration_ms_(kOpusBlockDurationMs), |
124 sampling_khz_(kOpusSamplingKhz), | 124 sampling_khz_(kOpusSamplingKhz), |
125 block_length_sample_(block_duration_ms_ * sampling_khz_), | 125 block_length_sample_( |
| 126 static_cast<size_t>(block_duration_ms_ * sampling_khz_)), |
126 data_pointer_(0), | 127 data_pointer_(0), |
127 max_bytes_(0), | 128 max_bytes_(0), |
128 encoded_bytes_(0), | 129 encoded_bytes_(0), |
129 opus_encoder_(NULL), | 130 opus_encoder_(NULL), |
130 opus_decoder_(NULL) { | 131 opus_decoder_(NULL) { |
131 } | 132 } |
132 | 133 |
133 void OpusFecTest::EncodeABlock() { | 134 void OpusFecTest::EncodeABlock() { |
134 int value = WebRtcOpus_Encode(opus_encoder_, | 135 int value = WebRtcOpus_Encode(opus_encoder_, |
135 &in_data_[data_pointer_], | 136 &in_data_[data_pointer_], |
136 block_length_sample_, | 137 block_length_sample_, |
137 max_bytes_, &bit_stream_[0]); | 138 max_bytes_, &bit_stream_[0]); |
138 EXPECT_GT(value, 0); | 139 EXPECT_GT(value, 0); |
139 | 140 |
140 encoded_bytes_ = value; | 141 encoded_bytes_ = static_cast<size_t>(value); |
141 } | 142 } |
142 | 143 |
143 void OpusFecTest::DecodeABlock(bool lost_previous, bool lost_current) { | 144 void OpusFecTest::DecodeABlock(bool lost_previous, bool lost_current) { |
144 int16_t audio_type; | 145 int16_t audio_type; |
145 int value_1 = 0, value_2 = 0; | 146 int value_1 = 0, value_2 = 0; |
146 | 147 |
147 if (lost_previous) { | 148 if (lost_previous) { |
148 // Decode previous frame. | 149 // Decode previous frame. |
149 if (!lost_current && | 150 if (!lost_current && |
150 WebRtcOpus_PacketHasFec(&bit_stream_[0], encoded_bytes_) == 1) { | 151 WebRtcOpus_PacketHasFec(&bit_stream_[0], encoded_bytes_) == 1) { |
151 value_1 = WebRtcOpus_DecodeFec(opus_decoder_, &bit_stream_[0], | 152 value_1 = WebRtcOpus_DecodeFec(opus_decoder_, &bit_stream_[0], |
152 encoded_bytes_, &out_data_[0], | 153 encoded_bytes_, &out_data_[0], |
153 &audio_type); | 154 &audio_type); |
154 } else { | 155 } else { |
155 value_1 = WebRtcOpus_DecodePlc(opus_decoder_, &out_data_[0], 1); | 156 value_1 = WebRtcOpus_DecodePlc(opus_decoder_, &out_data_[0], 1); |
156 } | 157 } |
157 EXPECT_EQ(block_length_sample_, value_1); | 158 EXPECT_EQ(static_cast<int>(block_length_sample_), value_1); |
158 } | 159 } |
159 | 160 |
160 if (!lost_current) { | 161 if (!lost_current) { |
161 // Decode current frame. | 162 // Decode current frame. |
162 value_2 = WebRtcOpus_Decode(opus_decoder_, &bit_stream_[0], encoded_bytes_, | 163 value_2 = WebRtcOpus_Decode(opus_decoder_, &bit_stream_[0], encoded_bytes_, |
163 &out_data_[value_1 * channels_], &audio_type); | 164 &out_data_[value_1 * channels_], &audio_type); |
164 EXPECT_EQ(block_length_sample_, value_2); | 165 EXPECT_EQ(static_cast<int>(block_length_sample_), value_2); |
165 } | 166 } |
166 } | 167 } |
167 | 168 |
168 TEST_P(OpusFecTest, RandomPacketLossTest) { | 169 TEST_P(OpusFecTest, RandomPacketLossTest) { |
169 const int kDurationMs = 200000; | 170 const int kDurationMs = 200000; |
170 int time_now_ms, fec_frames; | 171 int time_now_ms, fec_frames; |
171 int actual_packet_loss_rate; | 172 int actual_packet_loss_rate; |
172 bool lost_current, lost_previous; | 173 bool lost_current, lost_previous; |
173 mode mode_set[3] = {{true, 0}, | 174 mode mode_set[3] = {{true, 0}, |
174 {false, 0}, | 175 {false, 0}, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 ::std::tr1::make_tuple(1, 32000, string("audio_coding/testfile32kHz"), | 231 ::std::tr1::make_tuple(1, 32000, string("audio_coding/testfile32kHz"), |
231 string("pcm")), | 232 string("pcm")), |
232 ::std::tr1::make_tuple(2, 64000, string("audio_coding/teststereo32kHz"), | 233 ::std::tr1::make_tuple(2, 64000, string("audio_coding/teststereo32kHz"), |
233 string("pcm"))}; | 234 string("pcm"))}; |
234 | 235 |
235 // 64 kbps, stereo | 236 // 64 kbps, stereo |
236 INSTANTIATE_TEST_CASE_P(AllTest, OpusFecTest, | 237 INSTANTIATE_TEST_CASE_P(AllTest, OpusFecTest, |
237 ::testing::ValuesIn(param_set)); | 238 ::testing::ValuesIn(param_set)); |
238 | 239 |
239 } // namespace webrtc | 240 } // namespace webrtc |
OLD | NEW |