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

Side by Side Diff: webrtc/voice_engine/utility.cc

Issue 2007563002: Adding a some checks and switching out a few assert for RTC_[D]CHECK. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 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
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
11 #include "webrtc/voice_engine/utility.h" 11 #include "webrtc/voice_engine/utility.h"
12 12
13 #include "webrtc/base/checks.h"
13 #include "webrtc/base/logging.h" 14 #include "webrtc/base/logging.h"
14 #include "webrtc/common_audio/resampler/include/push_resampler.h" 15 #include "webrtc/common_audio/resampler/include/push_resampler.h"
15 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" 16 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h"
16 #include "webrtc/common_types.h" 17 #include "webrtc/common_types.h"
17 #include "webrtc/modules/include/module_common_types.h" 18 #include "webrtc/modules/include/module_common_types.h"
18 #include "webrtc/modules/utility/include/audio_frame_operations.h" 19 #include "webrtc/modules/utility/include/audio_frame_operations.h"
19 #include "webrtc/voice_engine/voice_engine_defines.h" 20 #include "webrtc/voice_engine/voice_engine_defines.h"
20 21
21 namespace webrtc { 22 namespace webrtc {
22 namespace voe { 23 namespace voe {
(...skipping 22 matching lines...) Expand all
45 // Downmix before resampling. 46 // Downmix before resampling.
46 if (num_channels == 2 && dst_frame->num_channels_ == 1) { 47 if (num_channels == 2 && dst_frame->num_channels_ == 1) {
47 AudioFrameOperations::StereoToMono(src_data, samples_per_channel, 48 AudioFrameOperations::StereoToMono(src_data, samples_per_channel,
48 mono_audio); 49 mono_audio);
49 audio_ptr = mono_audio; 50 audio_ptr = mono_audio;
50 audio_ptr_num_channels = 1; 51 audio_ptr_num_channels = 1;
51 } 52 }
52 53
53 if (resampler->InitializeIfNeeded(sample_rate_hz, dst_frame->sample_rate_hz_, 54 if (resampler->InitializeIfNeeded(sample_rate_hz, dst_frame->sample_rate_hz_,
54 audio_ptr_num_channels) == -1) { 55 audio_ptr_num_channels) == -1) {
55 LOG(LS_ERROR) << "InitializeIfNeeded failed: sample_rate_hz = " 56 RTC_CHECK(false) << "InitializeIfNeeded failed: sample_rate_hz = "
hlundin-webrtc 2016/05/24 06:38:03 Consider FATAL().
tommi 2016/05/24 07:49:13 Done.
56 << sample_rate_hz << ", dst_frame->sample_rate_hz_ = " 57 << sample_rate_hz << ", dst_frame->sample_rate_hz_ = "
57 << dst_frame->sample_rate_hz_ 58 << dst_frame->sample_rate_hz_
58 << ", audio_ptr_num_channels = " << audio_ptr_num_channels; 59 << ", audio_ptr_num_channels = " << audio_ptr_num_channels;
59 assert(false);
60 } 60 }
61 61
62 const size_t src_length = samples_per_channel * audio_ptr_num_channels; 62 const size_t src_length = samples_per_channel * audio_ptr_num_channels;
63 int out_length = resampler->Resample(audio_ptr, src_length, dst_frame->data_, 63 int out_length = resampler->Resample(audio_ptr, src_length, dst_frame->data_,
64 AudioFrame::kMaxDataSizeSamples); 64 AudioFrame::kMaxDataSizeSamples);
65 if (out_length == -1) { 65 if (out_length == -1) {
66 LOG(LS_ERROR) << "Resample failed: audio_ptr = " << audio_ptr 66 RTC_CHECK(false) << "Resample failed: audio_ptr = " << audio_ptr
hlundin-webrtc 2016/05/24 06:38:03 And here.
tommi 2016/05/24 07:49:13 Done.
67 << ", src_length = " << src_length 67 << ", src_length = " << src_length
68 << ", dst_frame->data_ = " << dst_frame->data_; 68 << ", dst_frame->data_ = " << dst_frame->data_;
69 assert(false);
70 } 69 }
71 dst_frame->samples_per_channel_ = out_length / audio_ptr_num_channels; 70 dst_frame->samples_per_channel_ = out_length / audio_ptr_num_channels;
72 71
73 // Upmix after resampling. 72 // Upmix after resampling.
74 if (num_channels == 1 && dst_frame->num_channels_ == 2) { 73 if (num_channels == 1 && dst_frame->num_channels_ == 2) {
75 // The audio in dst_frame really is mono at this point; MonoToStereo will 74 // The audio in dst_frame really is mono at this point; MonoToStereo will
76 // set this back to stereo. 75 // set this back to stereo.
77 dst_frame->num_channels_ = 1; 76 dst_frame->num_channels_ = 1;
78 AudioFrameOperations::MonoToStereo(dst_frame); 77 AudioFrameOperations::MonoToStereo(dst_frame);
79 } 78 }
80 } 79 }
81 80
82 void MixWithSat(int16_t target[], 81 void MixWithSat(int16_t target[],
83 size_t target_channel, 82 size_t target_channel,
84 const int16_t source[], 83 const int16_t source[],
85 size_t source_channel, 84 size_t source_channel,
86 size_t source_len) { 85 size_t source_len) {
87 assert(target_channel == 1 || target_channel == 2); 86 RTC_DCHECK(target_channel == 1 || target_channel == 2);
hlundin-webrtc 2016/05/24 06:38:03 Consider rewriting these as RTC_DCHECK_GE(target_c
tommi 2016/05/24 07:49:13 Done.
88 assert(source_channel == 1 || source_channel == 2); 87 RTC_DCHECK(source_channel == 1 || source_channel == 2);
89 88
90 if (target_channel == 2 && source_channel == 1) { 89 if (target_channel == 2 && source_channel == 1) {
91 // Convert source from mono to stereo. 90 // Convert source from mono to stereo.
92 int32_t left = 0; 91 int32_t left = 0;
93 int32_t right = 0; 92 int32_t right = 0;
94 for (size_t i = 0; i < source_len; ++i) { 93 for (size_t i = 0; i < source_len; ++i) {
95 left = source[i] + target[i * 2]; 94 left = source[i] + target[i * 2];
96 right = source[i] + target[i * 2 + 1]; 95 right = source[i] + target[i * 2 + 1];
97 target[i * 2] = WebRtcSpl_SatW32ToW16(left); 96 target[i * 2] = WebRtcSpl_SatW32ToW16(left);
98 target[i * 2 + 1] = WebRtcSpl_SatW32ToW16(right); 97 target[i * 2 + 1] = WebRtcSpl_SatW32ToW16(right);
99 } 98 }
100 } else if (target_channel == 1 && source_channel == 2) { 99 } else if (target_channel == 1 && source_channel == 2) {
101 // Convert source from stereo to mono. 100 // Convert source from stereo to mono.
102 int32_t temp = 0; 101 int32_t temp = 0;
103 for (size_t i = 0; i < source_len / 2; ++i) { 102 for (size_t i = 0; i < source_len / 2; ++i) {
104 temp = ((source[i * 2] + source[i * 2 + 1]) >> 1) + target[i]; 103 temp = ((source[i * 2] + source[i * 2 + 1]) >> 1) + target[i];
105 target[i] = WebRtcSpl_SatW32ToW16(temp); 104 target[i] = WebRtcSpl_SatW32ToW16(temp);
106 } 105 }
107 } else { 106 } else {
108 int32_t temp = 0; 107 int32_t temp = 0;
109 for (size_t i = 0; i < source_len; ++i) { 108 for (size_t i = 0; i < source_len; ++i) {
110 temp = source[i] + target[i]; 109 temp = source[i] + target[i];
111 target[i] = WebRtcSpl_SatW32ToW16(temp); 110 target[i] = WebRtcSpl_SatW32ToW16(temp);
112 } 111 }
113 } 112 }
114 } 113 }
115 114
116 } // namespace voe 115 } // namespace voe
117 } // namespace webrtc 116 } // namespace webrtc
OLDNEW
« webrtc/voice_engine/channel.cc ('K') | « webrtc/voice_engine/channel.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698