| 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 11 matching lines...) Expand all Loading... |
| 22 namespace webrtc { | 22 namespace webrtc { |
| 23 | 23 |
| 24 void ComfortNoise::Reset() { | 24 void ComfortNoise::Reset() { |
| 25 first_call_ = true; | 25 first_call_ = true; |
| 26 internal_error_code_ = 0; | 26 internal_error_code_ = 0; |
| 27 } | 27 } |
| 28 | 28 |
| 29 int ComfortNoise::UpdateParameters(Packet* packet) { | 29 int ComfortNoise::UpdateParameters(Packet* packet) { |
| 30 assert(packet); // Existence is verified by caller. | 30 assert(packet); // Existence is verified by caller. |
| 31 // Get comfort noise decoder. | 31 // Get comfort noise decoder. |
| 32 AudioDecoder* cng_decoder = decoder_database_->GetDecoder( | 32 if (decoder_database_->SetActiveCngDecoder(packet->header.payloadType) |
| 33 packet->header.payloadType); | 33 != kOK) { |
| 34 if (!cng_decoder) { | |
| 35 delete [] packet->payload; | 34 delete [] packet->payload; |
| 36 delete packet; | 35 delete packet; |
| 37 return kUnknownPayloadType; | 36 return kUnknownPayloadType; |
| 38 } | 37 } |
| 39 decoder_database_->SetActiveCngDecoder(packet->header.payloadType); | 38 CNG_dec_inst* cng_inst = decoder_database_->GetActiveCngDecoder(); |
| 40 CNG_dec_inst* cng_inst = cng_decoder->CngDecoderInstance(); | |
| 41 int16_t ret = WebRtcCng_UpdateSid(cng_inst, | 39 int16_t ret = WebRtcCng_UpdateSid(cng_inst, |
| 42 packet->payload, | 40 packet->payload, |
| 43 packet->payload_length); | 41 packet->payload_length); |
| 44 delete [] packet->payload; | 42 delete [] packet->payload; |
| 45 delete packet; | 43 delete packet; |
| 46 if (ret < 0) { | 44 if (ret < 0) { |
| 47 internal_error_code_ = WebRtcCng_GetErrorCodeDec(cng_inst); | 45 internal_error_code_ = WebRtcCng_GetErrorCodeDec(cng_inst); |
| 48 LOG(LS_ERROR) << "WebRtcCng_UpdateSid produced " << internal_error_code_; | 46 LOG(LS_ERROR) << "WebRtcCng_UpdateSid produced " << internal_error_code_; |
| 49 return kInternalError; | 47 return kInternalError; |
| 50 } | 48 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 64 | 62 |
| 65 size_t number_of_samples = requested_length; | 63 size_t number_of_samples = requested_length; |
| 66 int16_t new_period = 0; | 64 int16_t new_period = 0; |
| 67 if (first_call_) { | 65 if (first_call_) { |
| 68 // Generate noise and overlap slightly with old data. | 66 // Generate noise and overlap slightly with old data. |
| 69 number_of_samples = requested_length + overlap_length_; | 67 number_of_samples = requested_length + overlap_length_; |
| 70 new_period = 1; | 68 new_period = 1; |
| 71 } | 69 } |
| 72 output->AssertSize(number_of_samples); | 70 output->AssertSize(number_of_samples); |
| 73 // Get the decoder from the database. | 71 // Get the decoder from the database. |
| 74 AudioDecoder* cng_decoder = decoder_database_->GetActiveCngDecoder(); | 72 CNG_dec_inst* cng_inst = decoder_database_->GetActiveCngDecoder(); |
| 75 if (!cng_decoder) { | 73 if (!cng_inst) { |
| 76 LOG(LS_ERROR) << "Unknwown payload type"; | 74 LOG(LS_ERROR) << "Unknwown payload type"; |
| 77 return kUnknownPayloadType; | 75 return kUnknownPayloadType; |
| 78 } | 76 } |
| 79 CNG_dec_inst* cng_inst = cng_decoder->CngDecoderInstance(); | |
| 80 // The expression &(*output)[0][0] is a pointer to the first element in | 77 // The expression &(*output)[0][0] is a pointer to the first element in |
| 81 // the first channel. | 78 // the first channel. |
| 82 if (WebRtcCng_Generate(cng_inst, &(*output)[0][0], number_of_samples, | 79 if (WebRtcCng_Generate(cng_inst, &(*output)[0][0], number_of_samples, |
| 83 new_period) < 0) { | 80 new_period) < 0) { |
| 84 // Error returned. | 81 // Error returned. |
| 85 output->Zeros(requested_length); | 82 output->Zeros(requested_length); |
| 86 internal_error_code_ = WebRtcCng_GetErrorCodeDec(cng_inst); | 83 internal_error_code_ = WebRtcCng_GetErrorCodeDec(cng_inst); |
| 87 LOG(LS_ERROR) << "WebRtcCng_Generate produced " << internal_error_code_; | 84 LOG(LS_ERROR) << "WebRtcCng_Generate produced " << internal_error_code_; |
| 88 return kInternalError; | 85 return kInternalError; |
| 89 } | 86 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } | 127 } |
| 131 // Remove |overlap_length_| samples from the front of |output| since they | 128 // Remove |overlap_length_| samples from the front of |output| since they |
| 132 // were mixed into |sync_buffer_| above. | 129 // were mixed into |sync_buffer_| above. |
| 133 output->PopFront(overlap_length_); | 130 output->PopFront(overlap_length_); |
| 134 } | 131 } |
| 135 first_call_ = false; | 132 first_call_ = false; |
| 136 return kOK; | 133 return kOK; |
| 137 } | 134 } |
| 138 | 135 |
| 139 } // namespace webrtc | 136 } // namespace webrtc |
| OLD | NEW |