Reland of Adding a some checks and switching out a few assert for RTC_[D]CHECK. (patchset #1 id:1 of https://codereview.webrtc.org/2018553002/ )
Adding a some checks and switching out a few assert for RTC_[D]CHECK.
These changes are around use of AudioFrame.data_ to help us catch issues earlier since assert() is left out in release builds, including builds with DCHECK enabled. I've also added a few full-on CHECKs to avoid reading past buffer boundaries or continuing on in a failed state.
TBR=kjellander@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Committed: https://crrev.com/60c4e0ae8f124f08372645a95042f4a1246d7aa3
Cr-Commit-Position: refs/heads/master@{#12925}
Committed: https://crrev.com/5771beb265129082d31736259b7dc6ca037cff4d
Cr-Commit-Position: refs/heads/master@{#12926}
Review URL: https://codereview.webrtc.org/2014973002 .
Cr-Commit-Position: refs/heads/master@{#12927}
diff --git a/webrtc/voice_engine/utility.cc b/webrtc/voice_engine/utility.cc
index 605e553..37e12ce 100644
--- a/webrtc/voice_engine/utility.cc
+++ b/webrtc/voice_engine/utility.cc
@@ -10,6 +10,7 @@
#include "webrtc/voice_engine/utility.h"
+#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
#include "webrtc/common_audio/resampler/include/push_resampler.h"
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
@@ -52,21 +53,18 @@
if (resampler->InitializeIfNeeded(sample_rate_hz, dst_frame->sample_rate_hz_,
audio_ptr_num_channels) == -1) {
- LOG(LS_ERROR) << "InitializeIfNeeded failed: sample_rate_hz = "
- << sample_rate_hz << ", dst_frame->sample_rate_hz_ = "
- << dst_frame->sample_rate_hz_
- << ", audio_ptr_num_channels = " << audio_ptr_num_channels;
- assert(false);
+ FATAL() << "InitializeIfNeeded failed: sample_rate_hz = " << sample_rate_hz
+ << ", dst_frame->sample_rate_hz_ = " << dst_frame->sample_rate_hz_
+ << ", audio_ptr_num_channels = " << audio_ptr_num_channels;
}
const size_t src_length = samples_per_channel * audio_ptr_num_channels;
int out_length = resampler->Resample(audio_ptr, src_length, dst_frame->data_,
AudioFrame::kMaxDataSizeSamples);
if (out_length == -1) {
- LOG(LS_ERROR) << "Resample failed: audio_ptr = " << audio_ptr
- << ", src_length = " << src_length
- << ", dst_frame->data_ = " << dst_frame->data_;
- assert(false);
+ FATAL() << "Resample failed: audio_ptr = " << audio_ptr
+ << ", src_length = " << src_length
+ << ", dst_frame->data_ = " << dst_frame->data_;
}
dst_frame->samples_per_channel_ = out_length / audio_ptr_num_channels;
@@ -84,8 +82,10 @@
const int16_t source[],
size_t source_channel,
size_t source_len) {
- assert(target_channel == 1 || target_channel == 2);
- assert(source_channel == 1 || source_channel == 2);
+ RTC_DCHECK_GE(target_channel, 1u);
+ RTC_DCHECK_LE(target_channel, 2u);
+ RTC_DCHECK_GE(source_channel, 1u);
+ RTC_DCHECK_LE(source_channel, 2u);
if (target_channel == 2 && source_channel == 1) {
// Convert source from mono to stereo.