OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 #include <string> | 10 #include <string> |
(...skipping 27 matching lines...) Expand all Loading... |
38 void TestDtxEffect(bool dtx); | 38 void TestDtxEffect(bool dtx); |
39 | 39 |
40 // Prepare |speech_data_| for encoding, read from a hard-coded file. | 40 // Prepare |speech_data_| for encoding, read from a hard-coded file. |
41 // After preparation, |speech_data_.GetNextBlock()| returns a pointer to a | 41 // After preparation, |speech_data_.GetNextBlock()| returns a pointer to a |
42 // block of |block_length_ms| milliseconds. The data is looped every | 42 // block of |block_length_ms| milliseconds. The data is looped every |
43 // |loop_length_ms| milliseconds. | 43 // |loop_length_ms| milliseconds. |
44 void PrepareSpeechData(int channel, int block_length_ms, int loop_length_ms); | 44 void PrepareSpeechData(int channel, int block_length_ms, int loop_length_ms); |
45 | 45 |
46 int EncodeDecode(WebRtcOpusEncInst* encoder, | 46 int EncodeDecode(WebRtcOpusEncInst* encoder, |
47 const int16_t* input_audio, | 47 const int16_t* input_audio, |
48 const int input_samples, | 48 int input_samples, |
49 WebRtcOpusDecInst* decoder, | 49 WebRtcOpusDecInst* decoder, |
50 int16_t* output_audio, | 50 int16_t* output_audio, |
51 int16_t* audio_type); | 51 int16_t* audio_type); |
52 | 52 |
53 void SetMaxPlaybackRate(WebRtcOpusEncInst* encoder, | 53 void SetMaxPlaybackRate(WebRtcOpusEncInst* encoder, |
54 opus_int32 expect, int32_t set); | 54 opus_int32 expect, int32_t set); |
55 | 55 |
56 WebRtcOpusEncInst* opus_encoder_; | 56 WebRtcOpusEncInst* opus_encoder_; |
57 WebRtcOpusDecInst* opus_decoder_; | 57 WebRtcOpusDecInst* opus_decoder_; |
58 | 58 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 int32_t set) { | 90 int32_t set) { |
91 opus_int32 bandwidth; | 91 opus_int32 bandwidth; |
92 EXPECT_EQ(0, WebRtcOpus_SetMaxPlaybackRate(opus_encoder_, set)); | 92 EXPECT_EQ(0, WebRtcOpus_SetMaxPlaybackRate(opus_encoder_, set)); |
93 opus_encoder_ctl(opus_encoder_->encoder, | 93 opus_encoder_ctl(opus_encoder_->encoder, |
94 OPUS_GET_MAX_BANDWIDTH(&bandwidth)); | 94 OPUS_GET_MAX_BANDWIDTH(&bandwidth)); |
95 EXPECT_EQ(expect, bandwidth); | 95 EXPECT_EQ(expect, bandwidth); |
96 } | 96 } |
97 | 97 |
98 int OpusTest::EncodeDecode(WebRtcOpusEncInst* encoder, | 98 int OpusTest::EncodeDecode(WebRtcOpusEncInst* encoder, |
99 const int16_t* input_audio, | 99 const int16_t* input_audio, |
100 const int input_samples, | 100 int input_samples, |
101 WebRtcOpusDecInst* decoder, | 101 WebRtcOpusDecInst* decoder, |
102 int16_t* output_audio, | 102 int16_t* output_audio, |
103 int16_t* audio_type) { | 103 int16_t* audio_type) { |
104 encoded_bytes_ = WebRtcOpus_Encode(encoder, | 104 encoded_bytes_ = WebRtcOpus_Encode(encoder, |
105 input_audio, | 105 input_audio, |
106 input_samples, kMaxBytes, | 106 input_samples, kMaxBytes, |
107 bitstream_); | 107 bitstream_); |
108 return WebRtcOpus_Decode(decoder, bitstream_, | 108 return WebRtcOpus_Decode(decoder, bitstream_, |
109 encoded_bytes_, output_audio, | 109 encoded_bytes_, output_audio, |
110 audio_type); | 110 audio_type); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 for (int i = 0; i < 30; ++i) { | 156 for (int i = 0; i < 30; ++i) { |
157 EXPECT_EQ(kOpus20msFrameSamples, | 157 EXPECT_EQ(kOpus20msFrameSamples, |
158 EncodeDecode(opus_encoder_, silence, | 158 EncodeDecode(opus_encoder_, silence, |
159 kOpus20msFrameSamples, opus_decoder_, | 159 kOpus20msFrameSamples, opus_decoder_, |
160 output_data_decode, &audio_type)); | 160 output_data_decode, &audio_type)); |
161 if (!dtx) { | 161 if (!dtx) { |
162 EXPECT_GT(encoded_bytes_, 1); | 162 EXPECT_GT(encoded_bytes_, 1); |
163 EXPECT_EQ(0, opus_encoder_->in_dtx_mode); | 163 EXPECT_EQ(0, opus_encoder_->in_dtx_mode); |
164 EXPECT_EQ(0, opus_decoder_->in_dtx_mode); | 164 EXPECT_EQ(0, opus_decoder_->in_dtx_mode); |
165 EXPECT_EQ(0, audio_type); // Speech. | 165 EXPECT_EQ(0, audio_type); // Speech. |
166 } else if (1 == encoded_bytes_) { | 166 } else if (encoded_bytes_ == 1) { |
167 EXPECT_EQ(1, opus_encoder_->in_dtx_mode); | 167 EXPECT_EQ(1, opus_encoder_->in_dtx_mode); |
168 EXPECT_EQ(1, opus_decoder_->in_dtx_mode); | 168 EXPECT_EQ(1, opus_decoder_->in_dtx_mode); |
169 EXPECT_EQ(2, audio_type); // Comfort noise. | 169 EXPECT_EQ(2, audio_type); // Comfort noise. |
170 break; | 170 break; |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 // When Opus is in DTX, it wakes up in a regular basis. It sends two packets, | 174 // When Opus is in DTX, it wakes up in a regular basis. It sends two packets, |
175 // one with an arbitrary size and the other of 1-byte, then stops sending for | 175 // one with an arbitrary size and the other of 1-byte, then stops sending for |
176 // 19 frames. | 176 // 19 frames. |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); | 603 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); |
604 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); | 604 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); |
605 } | 605 } |
606 | 606 |
607 INSTANTIATE_TEST_CASE_P(VariousMode, | 607 INSTANTIATE_TEST_CASE_P(VariousMode, |
608 OpusTest, | 608 OpusTest, |
609 Combine(Values(1, 2), Values(0, 1))); | 609 Combine(Values(1, 2), Values(0, 1))); |
610 | 610 |
611 | 611 |
612 } // namespace webrtc | 612 } // namespace webrtc |
OLD | NEW |