Replace some asserts with DCHECKs

NOPRESUBMIT=true
BUG=webrtc:6779

Review-Url: https://codereview.webrtc.org/2535643002
Cr-Commit-Position: refs/heads/master@{#15295}
This commit is contained in:
kwiberg 2016-11-29 05:30:40 -08:00 committed by Commit bot
parent 5049942219
commit b890c95c33
13 changed files with 55 additions and 50 deletions

View File

@ -10,11 +10,11 @@
#include "webrtc/common_audio/fir_filter.h"
#include <assert.h>
#include <string.h>
#include <memory>
#include "webrtc/base/checks.h"
#include "webrtc/common_audio/fir_filter_neon.h"
#include "webrtc/common_audio/fir_filter_sse.h"
#include "webrtc/system_wrappers/include/cpu_features_wrapper.h"
@ -39,7 +39,7 @@ FIRFilter* FIRFilter::Create(const float* coefficients,
size_t coefficients_length,
size_t max_input_length) {
if (!coefficients || coefficients_length <= 0 || max_input_length <= 0) {
assert(false);
RTC_NOTREACHED();
return NULL;
}
@ -80,7 +80,7 @@ FIRFilterC::FIRFilterC(const float* coefficients, size_t coefficients_length)
}
void FIRFilterC::Filter(const float* in, size_t length, float* out) {
assert(length > 0);
RTC_DCHECK_GT(length, 0);
// Convolves the input signal |in| with the filter kernel |coefficients_|
// taking into account the previous state.

View File

@ -11,9 +11,9 @@
#include "webrtc/common_audio/fir_filter_neon.h"
#include <arm_neon.h>
#include <assert.h>
#include <string.h>
#include "webrtc/base/checks.h"
#include "webrtc/system_wrappers/include/aligned_malloc.h"
namespace webrtc {
@ -43,7 +43,7 @@ FIRFilterNEON::FIRFilterNEON(const float* coefficients,
}
void FIRFilterNEON::Filter(const float* in, size_t length, float* out) {
assert(length > 0);
RTC_DCHECK_GT(length, 0);
memcpy(&state_[state_length_], in, length * sizeof(*in));

View File

@ -10,11 +10,11 @@
#include "webrtc/common_audio/fir_filter_sse.h"
#include <assert.h>
#include <stdint.h>
#include <string.h>
#include <xmmintrin.h>
#include "webrtc/base/checks.h"
#include "webrtc/system_wrappers/include/aligned_malloc.h"
namespace webrtc {
@ -44,7 +44,7 @@ FIRFilterSSE2::FIRFilterSSE2(const float* coefficients,
}
void FIRFilterSSE2::Filter(const float* in, size_t length, float* out) {
assert(length > 0);
RTC_DCHECK_GT(length, 0);
memcpy(&state_[state_length_], in, length * sizeof(*in));

View File

@ -87,12 +87,12 @@
#include "webrtc/common_audio/resampler/sinc_resampler.h"
#include <assert.h>
#include <math.h>
#include <string.h>
#include <limits>
#include "webrtc/base/checks.h"
#include "webrtc/system_wrappers/include/cpu_features_wrapper.h"
#include "webrtc/typedefs.h"
@ -118,6 +118,8 @@ double SincScaleFactor(double io_ratio) {
} // namespace
const size_t SincResampler::kKernelSize;
// If we know the minimum architecture at compile time, avoid CPU detection.
#if defined(WEBRTC_ARCH_X86_FAMILY)
#if defined(__SSE2__)
@ -165,11 +167,11 @@ SincResampler::SincResampler(double io_sample_rate_ratio,
r2_(input_buffer_.get() + kKernelSize / 2) {
#if defined(WEBRTC_CPU_DETECTION)
InitializeCPUSpecificFeatures();
assert(convolve_proc_);
RTC_DCHECK(convolve_proc_);
#endif
assert(request_frames_ > 0);
RTC_DCHECK_GT(request_frames_, 0);
Flush();
assert(block_size_ > kKernelSize);
RTC_DCHECK_GT(block_size_, kKernelSize);
memset(kernel_storage_.get(), 0,
sizeof(*kernel_storage_.get()) * kKernelStorageSize);
@ -192,11 +194,11 @@ void SincResampler::UpdateRegions(bool second_load) {
block_size_ = r4_ - r2_;
// r1_ at the beginning of the buffer.
assert(r1_ == input_buffer_.get());
RTC_DCHECK_EQ(r1_, input_buffer_.get());
// r1_ left of r2_, r4_ left of r3_ and size correct.
assert(r2_ - r1_ == r4_ - r3_);
RTC_DCHECK_EQ(r2_ - r1_, r4_ - r3_);
// r2_ left of r3.
assert(r2_ < r3_);
RTC_DCHECK_LT(r2_, r3_);
}
void SincResampler::InitializeKernel() {
@ -283,7 +285,7 @@ void SincResampler::Resample(size_t frames, float* destination) {
for (int i = static_cast<int>(
ceil((block_size_ - virtual_source_idx_) / current_io_ratio));
i > 0; --i) {
assert(virtual_source_idx_ < block_size_);
RTC_DCHECK_LT(virtual_source_idx_, block_size_);
// |virtual_source_idx_| lies in between two kernel offsets so figure out
// what they are.
@ -301,8 +303,8 @@ void SincResampler::Resample(size_t frames, float* destination) {
// Ensure |k1|, |k2| are 16-byte aligned for SIMD usage. Should always be
// true so long as kKernelSize is a multiple of 16.
assert(0u == (reinterpret_cast<uintptr_t>(k1) & 0x0F));
assert(0u == (reinterpret_cast<uintptr_t>(k2) & 0x0F));
RTC_DCHECK_EQ(0, reinterpret_cast<uintptr_t>(k1) % 16);
RTC_DCHECK_EQ(0, reinterpret_cast<uintptr_t>(k2) % 16);
// Initialize input pointer based on quantized |virtual_source_idx_|.
const float* const input_ptr = r1_ + source_idx;

View File

@ -11,13 +11,13 @@
#ifndef WEBRTC_COMMON_TYPES_H_
#define WEBRTC_COMMON_TYPES_H_
#include <assert.h>
#include <stddef.h>
#include <string.h>
#include <string>
#include <vector>
#include "webrtc/base/checks.h"
#include "webrtc/base/optional.h"
#include "webrtc/common_video/rotation.h"
#include "webrtc/typedefs.h"
@ -805,13 +805,13 @@ struct RtpPacketCounter {
}
void Subtract(const RtpPacketCounter& other) {
assert(header_bytes >= other.header_bytes);
RTC_DCHECK_GE(header_bytes, other.header_bytes);
header_bytes -= other.header_bytes;
assert(payload_bytes >= other.payload_bytes);
RTC_DCHECK_GE(payload_bytes, other.payload_bytes);
payload_bytes -= other.payload_bytes;
assert(padding_bytes >= other.padding_bytes);
RTC_DCHECK_GE(padding_bytes, other.padding_bytes);
padding_bytes -= other.padding_bytes;
assert(packets >= other.packets);
RTC_DCHECK_GE(packets, other.packets);
packets -= other.packets;
}

View File

@ -10,9 +10,10 @@
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
#include <assert.h>
#include <string.h>
#include "webrtc/base/checks.h"
// NOTE(ajm): Path provided by gyp.
#include "libyuv.h" // NOLINT
@ -49,14 +50,14 @@ VideoType RawVideoTypeToCommonVideoVideoType(RawVideoType type) {
case kVideoMJPEG:
return kMJPG;
default:
assert(false);
RTC_NOTREACHED();
}
return kUnknown;
}
size_t CalcBufferSize(VideoType type, int width, int height) {
assert(width >= 0);
assert(height >= 0);
RTC_DCHECK_GE(width, 0);
RTC_DCHECK_GE(height, 0);
size_t buffer_size = 0;
switch (type) {
case kI420:
@ -84,7 +85,7 @@ size_t CalcBufferSize(VideoType type, int width, int height) {
buffer_size = width * height * 4;
break;
default:
assert(false);
RTC_NOTREACHED();
break;
}
return buffer_size;
@ -135,7 +136,7 @@ int PrintVideoFrame(const VideoFrame& frame, FILE* file) {
int ExtractBuffer(const rtc::scoped_refptr<VideoFrameBuffer>& input_frame,
size_t size,
uint8_t* buffer) {
assert(buffer);
RTC_DCHECK(buffer);
if (!input_frame)
return -1;
int width = input_frame->width();
@ -200,7 +201,7 @@ libyuv::RotationMode ConvertRotationMode(VideoRotation rotation) {
case kVideoRotation_270:
return libyuv::kRotate270;
}
assert(false);
RTC_NOTREACHED();
return libyuv::kRotate0;
}
@ -238,7 +239,7 @@ int ConvertVideoType(VideoType video_type) {
case kARGB1555:
return libyuv::FOURCC_RGBO;
}
assert(false);
RTC_NOTREACHED();
return libyuv::FOURCC_ANY;
}

View File

@ -10,8 +10,6 @@
#include "webrtc/common_video/video_render_frames.h"
#include <assert.h>
#include "webrtc/base/logging.h"
#include "webrtc/base/timeutils.h"
#include "webrtc/modules/include/module_common_types.h"

View File

@ -7,6 +7,8 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
#include "webrtc/base/platform_thread.h"
#include "webrtc/modules/audio_device/dummy/file_audio_device.h"
@ -492,7 +494,7 @@ bool FileAudioDevice::PlayThreadProcess()
_critSect.Enter();
_playoutFramesLeft = _ptrAudioBuffer->GetPlayoutData(_playoutBuffer);
assert(_playoutFramesLeft == _playoutFramesIn10MS);
RTC_DCHECK_EQ(_playoutFramesIn10MS, _playoutFramesLeft);
if (_outputFile.is_open()) {
_outputFile.Write(_playoutBuffer, kPlayoutBufferSize);
}

View File

@ -131,8 +131,8 @@ MouseCursorMonitorX11::~MouseCursorMonitorX11() {
void MouseCursorMonitorX11::Init(Callback* callback, Mode mode) {
// Init can be called only once per instance of MouseCursorMonitor.
assert(!callback_);
assert(callback);
RTC_DCHECK(!callback_);
RTC_DCHECK(callback);
callback_ = callback;
mode_ = mode;
@ -152,7 +152,7 @@ void MouseCursorMonitorX11::Init(Callback* callback, Mode mode) {
}
void MouseCursorMonitorX11::Capture() {
assert(callback_);
RTC_DCHECK(callback_);
// Process X11 events in case XFixes has sent cursor notification.
x_display_->ProcessPendingXEvents();
@ -204,7 +204,7 @@ bool MouseCursorMonitorX11::HandleXEvent(const XEvent& event) {
}
void MouseCursorMonitorX11::CaptureCursor() {
assert(have_xfixes_);
RTC_DCHECK(have_xfixes_);
XFixesCursorImage* img;
{

View File

@ -292,7 +292,7 @@ bool ScreenCapturerLinux::HandleXEvent(const XEvent& event) {
std::unique_ptr<DesktopFrame> ScreenCapturerLinux::CaptureScreen() {
std::unique_ptr<SharedDesktopFrame> frame = queue_.current_frame()->Share();
assert(x_server_pixel_buffer_.window_size().equals(frame->size()));
RTC_DCHECK(x_server_pixel_buffer_.window_size().equals(frame->size()));
// Pass the screen size to the helper, so it can clip the invalid region if it
// expands that region to a grid.

View File

@ -89,9 +89,9 @@ class YuvFileGenerator : public FrameGenerator {
frame_buffer_(new uint8_t[frame_size_]),
frame_display_count_(frame_repeat_count),
current_display_count_(0) {
assert(width > 0);
assert(height > 0);
assert(frame_repeat_count > 0);
RTC_DCHECK_GT(width, 0);
RTC_DCHECK_GT(height, 0);
RTC_DCHECK_GT(frame_repeat_count, 0);
}
virtual ~YuvFileGenerator() {
@ -287,7 +287,7 @@ FrameGenerator* FrameGenerator::CreateFromYuvFile(
size_t width,
size_t height,
int frame_repeat_count) {
assert(!filenames.empty());
RTC_DCHECK(!filenames.empty());
std::vector<FILE*> files;
for (const std::string& filename : filenames) {
FILE* file = fopen(filename.c_str(), "rb");
@ -307,7 +307,7 @@ FrameGenerator* FrameGenerator::CreateScrollingInputFromYuvFiles(
size_t target_height,
int64_t scroll_time_ms,
int64_t pause_time_ms) {
assert(!filenames.empty());
RTC_DCHECK(!filenames.empty());
std::vector<FILE*> files;
for (const std::string& filename : filenames) {
FILE* file = fopen(filename.c_str(), "rb");

View File

@ -12,6 +12,7 @@
#include <string.h>
#include "webrtc/base/checks.h"
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
namespace webrtc {
@ -21,7 +22,7 @@ GlRenderer::GlRenderer()
: is_init_(false), buffer_(NULL), width_(0), height_(0) {}
void GlRenderer::Init() {
assert(!is_init_);
RTC_DCHECK(!is_init_);
is_init_ = true;
glGenTextures(1, &texture_);
@ -52,7 +53,7 @@ void GlRenderer::ResizeViewport(size_t width, size_t height) {
}
void GlRenderer::ResizeVideo(size_t width, size_t height) {
assert(is_init_);
RTC_DCHECK(is_init_);
width_ = width;
height_ = height;
@ -60,7 +61,7 @@ void GlRenderer::ResizeVideo(size_t width, size_t height) {
delete[] buffer_;
buffer_ = new uint8_t[buffer_size_];
assert(buffer_ != NULL);
RTC_DCHECK(buffer_);
memset(buffer_, 0, buffer_size_);
glBindTexture(GL_TEXTURE_2D, texture_);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
@ -70,7 +71,7 @@ void GlRenderer::ResizeVideo(size_t width, size_t height) {
}
void GlRenderer::OnFrame(const webrtc::VideoFrame& frame) {
assert(is_init_);
RTC_DCHECK(is_init_);
if (static_cast<size_t>(frame.width()) != width_ ||
static_cast<size_t>(frame.height()) != height_) {

View File

@ -9,6 +9,7 @@
*/
#include "webrtc/test/win/d3d_renderer.h"
#include "webrtc/base/checks.h"
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
namespace webrtc {
@ -37,8 +38,8 @@ D3dRenderer::D3dRenderer(size_t width, size_t height)
d3d_device_(NULL),
texture_(NULL),
vertex_buffer_(NULL) {
assert(width > 0);
assert(height > 0);
RTC_DCHECK_GT(width, 0);
RTC_DCHECK_GT(height, 0);
}
D3dRenderer::~D3dRenderer() { Destroy(); }
@ -61,7 +62,7 @@ void D3dRenderer::Destroy() {
if (hwnd_ != NULL) {
DestroyWindow(hwnd_);
assert(!IsWindow(hwnd_));
RTC_DCHECK(!IsWindow(hwnd_));
hwnd_ = NULL;
}
}