Consistently use DCHECK, not ASSERT or assert in talk/media/webrtc/.

BUG=
R=pbos@webrtc.org, tommi@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/49929004

Cr-Commit-Position: refs/heads/master@{#9156}
This commit is contained in:
Fredrik Solenberg 2015-05-07 17:07:34 +02:00
parent e444a3dcd3
commit d3ddc1b69e
9 changed files with 60 additions and 64 deletions

View File

@ -30,6 +30,7 @@
#include <algorithm>
#include "talk/media/base/rtputils.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/gunit.h"
namespace cricket {
@ -54,7 +55,7 @@ FakeVideoSendStream::FakeVideoSendStream(
config_(config),
codec_settings_set_(false),
num_swapped_frames_(0) {
assert(config.encoder_settings.encoder != NULL);
DCHECK(config.encoder_settings.encoder != NULL);
ReconfigureVideoEncoder(encoder_config);
}

View File

@ -54,12 +54,6 @@ namespace cricket {
#define WEBRTC_BOOL_FUNC(method, args) bool method args override
#define WEBRTC_VOID_FUNC(method, args) void method args override
#define WEBRTC_CHECK_CHANNEL(channel) \
if (channels_.find(channel) == channels_.end()) return -1;
#define WEBRTC_ASSERT_CHANNEL(channel) \
ASSERT(channels_.find(channel) != channels_.end());
} // namespace cricket
#endif // TALK_SESSION_PHONE_FAKEWEBRTCCOMMON_H_

View File

@ -45,12 +45,6 @@
namespace cricket {
#define WEBRTC_CHECK_CAPTURER(capturer) \
if (capturers_.find(capturer) == capturers_.end()) return -1;
#define WEBRTC_ASSERT_CAPTURER(capturer) \
ASSERT(capturers_.find(capturer) != capturers_.end());
static const int kMinVideoBitrate = 100;
static const int kStartVideoBitrate = 300;
static const int kMaxVideoBitrate = 1000;

View File

@ -38,6 +38,7 @@
#include "talk/media/webrtc/fakewebrtccommon.h"
#include "talk/media/webrtc/webrtcvoe.h"
#include "webrtc/base/basictypes.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/gunit.h"
#include "webrtc/base/stringutils.h"
#include "webrtc/modules/audio_processing/include/audio_processing.h"
@ -83,6 +84,12 @@ static const webrtc::NetworkStatistics kNetStats = {
7654, // int addedSamples;
}; // These random but non-trivial numbers are used for testing.
#define WEBRTC_CHECK_CHANNEL(channel) \
if (channels_.find(channel) == channels_.end()) return -1;
#define WEBRTC_ASSERT_CHANNEL(channel) \
DCHECK(channels_.find(channel) != channels_.end());
// Verify the header extension ID, if enabled, is within the bounds specified in
// [RFC5285]: 1-14 inclusive.
#define WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id) \
@ -355,7 +362,7 @@ class FakeWebRtcVoiceEngine
return channels_[channel]->packets.empty();
}
void TriggerCallbackOnError(int channel_num, int err_code) {
ASSERT(observer_ != NULL);
DCHECK(observer_ != NULL);
observer_->CallbackOnError(channel_num, err_code);
}
void set_playout_fail_channel(int channel) {

View File

@ -264,7 +264,7 @@ bool WebRtcVideoCapturer::SetApplyRotation(bool enable) {
// Can't take lock here as this will cause deadlock with
// OnIncomingCapturedFrame. In fact, the whole method, including methods it
// calls, can't take lock.
assert(module_);
DCHECK(module_);
const std::string group_name =
webrtc::field_trial::FindFullName("WebRTC-CVO");

View File

@ -52,7 +52,7 @@
#define UNIMPLEMENTED \
LOG(LS_ERROR) << "Call to unimplemented function " << __FUNCTION__; \
ASSERT(false)
RTC_NOTREACHED()
namespace cricket {
namespace {
@ -105,7 +105,7 @@ class WebRtcSimulcastEncoderFactory
webrtc::VideoEncoder* CreateVideoEncoder(
webrtc::VideoCodecType type) override {
ASSERT(factory_ != NULL);
DCHECK(factory_ != NULL);
// If it's a codec type we can simulcast, create a wrapped encoder.
if (type == webrtc::kVideoCodecVP8) {
return new webrtc::SimulcastEncoderAdapter(
@ -558,14 +558,14 @@ WebRtcVideoEngine2::~WebRtcVideoEngine2() {
}
void WebRtcVideoEngine2::SetCallFactory(WebRtcCallFactory* call_factory) {
assert(!initialized_);
DCHECK(!initialized_);
call_factory_ = call_factory;
}
bool WebRtcVideoEngine2::Init(rtc::Thread* worker_thread) {
LOG(LS_INFO) << "WebRtcVideoEngine2::Init";
worker_thread_ = worker_thread;
ASSERT(worker_thread_ != NULL);
DCHECK(worker_thread_ != NULL);
initialized_ = true;
return true;
@ -605,7 +605,7 @@ bool WebRtcVideoEngine2::SetDefaultEncoderConfig(
WebRtcVideoChannel2* WebRtcVideoEngine2::CreateChannel(
const VideoOptions& options,
VoiceMediaChannel* voice_channel) {
assert(initialized_);
DCHECK(initialized_);
LOG(LS_INFO) << "CreateChannel: "
<< (voice_channel != NULL ? "With" : "Without")
<< " voice channel. Options: " << options.ToString();
@ -635,20 +635,20 @@ void WebRtcVideoEngine2::SetLogging(int min_sev, const char* filter) {
LOG(LS_VERBOSE) << "SetLogging: " << min_sev << '"' << filter << '"';
// if min_sev == -1, we keep the current log level.
if (min_sev < 0) {
assert(min_sev == -1);
DCHECK(min_sev == -1);
return;
}
}
void WebRtcVideoEngine2::SetExternalDecoderFactory(
WebRtcVideoDecoderFactory* decoder_factory) {
assert(!initialized_);
DCHECK(!initialized_);
external_decoder_factory_ = decoder_factory;
}
void WebRtcVideoEngine2::SetExternalEncoderFactory(
WebRtcVideoEncoderFactory* encoder_factory) {
assert(!initialized_);
DCHECK(!initialized_);
if (external_encoder_factory_ == encoder_factory)
return;
@ -694,7 +694,7 @@ bool WebRtcVideoEngine2::FindCodec(const VideoCodec& in) {
bool WebRtcVideoEngine2::CanSendCodec(const VideoCodec& requested,
const VideoCodec& current,
VideoCodec* out) {
assert(out != NULL);
DCHECK(out != NULL);
if (requested.width != requested.height &&
(requested.height == 0 || requested.width == 0)) {
@ -760,7 +760,7 @@ std::vector<VideoCodec> WebRtcVideoEngine2::GetSupportedCodecs() const {
// we only support up to 8 external payload types.
const int kExternalVideoPayloadTypeBase = 120;
size_t payload_type = kExternalVideoPayloadTypeBase + i;
assert(payload_type < 128);
DCHECK(payload_type < 128);
VideoCodec codec(static_cast<int>(payload_type),
codecs[i].name,
codecs[i].max_width,
@ -941,7 +941,7 @@ bool WebRtcVideoChannel2::SetSendCodecs(const std::vector<VideoCodec>& codecs) {
send_streams_.begin();
it != send_streams_.end();
++it) {
assert(it->second != NULL);
DCHECK(it->second != NULL);
it->second->SetCodec(supported_codecs.front());
}
@ -1061,7 +1061,7 @@ bool WebRtcVideoChannel2::AddSendStream(const StreamParams& sp) {
send_rtp_extensions_);
uint32 ssrc = sp.first_ssrc();
assert(ssrc != 0);
DCHECK(ssrc != 0);
send_streams_[ssrc] = stream;
if (rtcp_receiver_report_ssrc_ == kDefaultRtcpReceiverReportSsrc) {
@ -1136,7 +1136,7 @@ bool WebRtcVideoChannel2::AddRecvStream(const StreamParams& sp,
return false;
uint32 ssrc = sp.first_ssrc();
assert(ssrc != 0); // TODO(pbos): Is this ever valid?
DCHECK(ssrc != 0); // TODO(pbos): Is this ever valid?
rtc::CritScope stream_lock(&stream_crit_);
// Remove running stream if this was a default stream.
@ -1326,7 +1326,7 @@ void WebRtcVideoChannel2::FillBandwidthEstimationStats(
bool WebRtcVideoChannel2::SetCapturer(uint32 ssrc, VideoCapturer* capturer) {
LOG(LS_INFO) << "SetCapturer: " << ssrc << " -> "
<< (capturer != NULL ? "(capturer)" : "NULL");
assert(ssrc != 0);
DCHECK(ssrc != 0);
{
rtc::CritScope stream_lock(&stream_crit_);
if (send_streams_.find(ssrc) == send_streams_.end()) {
@ -1419,7 +1419,7 @@ void WebRtcVideoChannel2::OnReadyToSend(bool ready) {
bool WebRtcVideoChannel2::MuteStream(uint32 ssrc, bool mute) {
LOG(LS_VERBOSE) << "MuteStream: " << ssrc << " -> "
<< (mute ? "mute" : "unmute");
assert(ssrc != 0);
DCHECK(ssrc != 0);
rtc::CritScope stream_lock(&stream_crit_);
if (send_streams_.find(ssrc) == send_streams_.end()) {
LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc;
@ -1700,7 +1700,7 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::InputFrame(
return;
if (format_.width == 0) { // Dropping frames.
assert(format_.height == 0);
DCHECK(format_.height == 0);
LOG(LS_VERBOSE) << "VideoFormat 0x0 set, Dropping frame.";
return;
}
@ -1870,7 +1870,7 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoder(
// This shouldn't happen, we should not be trying to create something we don't
// support.
assert(false);
DCHECK(false);
return AllocatedEncoder(NULL, webrtc::kVideoCodecUnknown, false);
}
@ -2009,7 +2009,7 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::SetDimensions(
last_dimensions_.height = height;
last_dimensions_.is_screencast = is_screencast;
assert(!parameters_.encoder_config.streams.empty());
DCHECK(!parameters_.encoder_config.streams.empty());
VideoCodecSettings codec_settings;
parameters_.codec_settings.Get(&codec_settings);
@ -2035,7 +2035,7 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::SetDimensions(
void WebRtcVideoChannel2::WebRtcVideoSendStream::Start() {
rtc::CritScope cs(&lock_);
assert(stream_ != NULL);
DCHECK(stream_ != NULL);
stream_->Start();
sending_ = true;
}
@ -2261,7 +2261,7 @@ WebRtcVideoChannel2::WebRtcVideoReceiveStream::CreateOrReuseVideoDecoder(
// This shouldn't happen, we should not be trying to create something we don't
// support.
assert(false);
DCHECK(false);
return AllocatedDecoder(NULL, webrtc::kVideoCodecUnknown, false);
}
@ -2443,7 +2443,7 @@ bool WebRtcVideoChannel2::VideoCodecSettings::operator!=(
std::vector<WebRtcVideoChannel2::VideoCodecSettings>
WebRtcVideoChannel2::MapCodecs(const std::vector<VideoCodec>& codecs) {
assert(!codecs.empty());
DCHECK(!codecs.empty());
std::vector<VideoCodecSettings> video_codecs;
std::map<int, bool> payload_used;
@ -2468,14 +2468,14 @@ WebRtcVideoChannel2::MapCodecs(const std::vector<VideoCodec>& codecs) {
switch (in_codec.GetCodecType()) {
case VideoCodec::CODEC_RED: {
// RED payload type, should not have duplicates.
assert(fec_settings.red_payload_type == -1);
DCHECK(fec_settings.red_payload_type == -1);
fec_settings.red_payload_type = in_codec.id;
continue;
}
case VideoCodec::CODEC_ULPFEC: {
// ULPFEC payload type, should not have duplicates.
assert(fec_settings.ulpfec_payload_type == -1);
DCHECK(fec_settings.ulpfec_payload_type == -1);
fec_settings.ulpfec_payload_type = in_codec.id;
continue;
}
@ -2504,7 +2504,7 @@ WebRtcVideoChannel2::MapCodecs(const std::vector<VideoCodec>& codecs) {
// One of these codecs should have been a video codec. Only having FEC
// parameters into this code is a logic error.
assert(!video_codecs.empty());
DCHECK(!video_codecs.empty());
for (std::map<int, int>::const_iterator it = rtx_mapping.begin();
it != rtx_mapping.end();

View File

@ -109,7 +109,7 @@ class WebRtcVideoEngine2Test : public ::testing::Test {
WebRtcVideoEngine2Test(WebRtcVoiceEngine* voice_engine)
: engine_(voice_engine) {
std::vector<VideoCodec> engine_codecs = engine_.codecs();
assert(!engine_codecs.empty());
DCHECK(!engine_codecs.empty());
bool codec_set = false;
for (size_t i = 0; i < engine_codecs.size(); ++i) {
if (engine_codecs[i].name == "red") {
@ -128,7 +128,7 @@ class WebRtcVideoEngine2Test : public ::testing::Test {
}
}
assert(codec_set);
DCHECK(codec_set);
}
protected:
@ -139,7 +139,7 @@ class WebRtcVideoEngine2Test : public ::testing::Test {
private:
webrtc::Call* CreateCall(const webrtc::Call::Config& config) override {
assert(fake_call_ == NULL);
DCHECK(fake_call_ == NULL);
fake_call_ = new FakeCall(config);
return fake_call_;
}
@ -835,7 +835,7 @@ class WebRtcVideoChannel2Test : public WebRtcVideoEngine2Test,
}
webrtc::Call* CreateCall(const webrtc::Call::Config& config) override {
assert(fake_call_ == NULL);
DCHECK(fake_call_ == NULL);
fake_call_ = new FakeCall(config);
return fake_call_;
}
@ -2566,7 +2566,7 @@ class WebRtcVideoChannel2SimulcastTest : public WebRtcVideoEngine2SimulcastTest,
protected:
webrtc::Call* CreateCall(const webrtc::Call::Config& config) override {
assert(fake_call_ == NULL);
DCHECK(fake_call_ == NULL);
fake_call_ = new FakeCall(config);
return fake_call_;
}
@ -2585,7 +2585,7 @@ class WebRtcVideoChannel2SimulcastTest : public WebRtcVideoEngine2SimulcastTest,
ASSERT_TRUE(channel_->SetSendCodecs(codecs));
std::vector<uint32> ssrcs = MAKE_VECTOR(kSsrcs3);
assert(num_configured_streams <= ssrcs.size());
DCHECK(num_configured_streams <= ssrcs.size());
ssrcs.resize(num_configured_streams);
FakeVideoSendStream* stream =

View File

@ -338,7 +338,7 @@ static void MaybeFixupG722(webrtc::CodecInst* voe_codec, int new_plfreq) {
if (IsCodec(*voe_codec, kG722CodecName)) {
// If the ASSERT triggers, the codec definition in WebRTC VoiceEngine
// has changed, and this special case is no longer needed.
ASSERT(voe_codec->plfreq != new_plfreq);
DCHECK(voe_codec->plfreq != new_plfreq);
voe_codec->plfreq = new_plfreq;
}
}
@ -600,14 +600,14 @@ WebRtcVoiceEngine::~WebRtcVoiceEngine() {
}
// Test to see if the media processor was deregistered properly
ASSERT(SignalRxMediaFrame.is_empty());
ASSERT(SignalTxMediaFrame.is_empty());
DCHECK(SignalRxMediaFrame.is_empty());
DCHECK(SignalTxMediaFrame.is_empty());
tracing_->SetTraceCallback(NULL);
}
bool WebRtcVoiceEngine::Init(rtc::Thread* worker_thread) {
ASSERT(worker_thread == rtc::Thread::Current());
DCHECK(worker_thread == rtc::Thread::Current());
LOG(LS_INFO) << "WebRtcVoiceEngine::Init";
bool res = InitInternal();
if (res) {
@ -1223,7 +1223,7 @@ bool WebRtcVoiceEngine::GetOutputVolume(int* level) {
}
bool WebRtcVoiceEngine::SetOutputVolume(int level) {
ASSERT(level >= 0 && level <= 255);
DCHECK(level >= 0 && level <= 255);
if (voe_wrapper_->volume()->SetSpeakerVolume(level) == -1) {
LOG_RTCERR1(SetSpeakerVolume, level);
return false;
@ -1456,7 +1456,7 @@ void WebRtcVoiceEngine::CallbackOnError(int channel_num, int err_code) {
LOG(LS_WARNING) << "VoiceEngine error " << err_code << " reported on channel "
<< channel_num << ".";
if (FindChannelAndSsrc(channel_num, &channel, &ssrc)) {
ASSERT(channel != NULL);
DCHECK(channel != NULL);
channel->OnError(ssrc, err_code);
} else {
LOG(LS_ERROR) << "VoiceEngine channel " << channel_num
@ -1466,14 +1466,14 @@ void WebRtcVoiceEngine::CallbackOnError(int channel_num, int err_code) {
bool WebRtcVoiceEngine::FindChannelAndSsrc(
int channel_num, WebRtcVoiceMediaChannel** channel, uint32* ssrc) const {
ASSERT(channel != NULL && ssrc != NULL);
DCHECK(channel != NULL && ssrc != NULL);
*channel = NULL;
*ssrc = 0;
// Find corresponding channel and ssrc
for (ChannelList::const_iterator it = channels_.begin();
it != channels_.end(); ++it) {
ASSERT(*it != NULL);
DCHECK(*it != NULL);
if ((*it)->FindSsrc(channel_num, ssrc)) {
*channel = *it;
return true;
@ -1487,14 +1487,14 @@ bool WebRtcVoiceEngine::FindChannelAndSsrc(
// obtain the voice engine's channel number.
bool WebRtcVoiceEngine::FindChannelNumFromSsrc(
uint32 ssrc, MediaProcessorDirection direction, int* channel_num) {
ASSERT(channel_num != NULL);
ASSERT(direction == MPD_RX || direction == MPD_TX);
DCHECK(channel_num != NULL);
DCHECK(direction == MPD_RX || direction == MPD_TX);
*channel_num = -1;
// Find corresponding channel for ssrc.
for (ChannelList::const_iterator it = channels_.begin();
it != channels_.end(); ++it) {
ASSERT(*it != NULL);
DCHECK(*it != NULL);
if (direction & MPD_RX) {
*channel_num = (*it)->GetReceiveChannelNum(ssrc);
}
@ -1804,9 +1804,9 @@ class WebRtcVoiceMediaChannel::WebRtcVoiceChannelRenderer
// TODO(xians): Make sure Start() is called only once.
void Start(AudioRenderer* renderer) {
rtc::CritScope lock(&lock_);
ASSERT(renderer != NULL);
DCHECK(renderer != NULL);
if (renderer_ != NULL) {
ASSERT(renderer_ == renderer);
DCHECK(renderer_ == renderer);
return;
}
@ -2575,7 +2575,7 @@ bool WebRtcVoiceMediaChannel::ChangeSend(int channel, SendFlags send) {
return false;
}
} else { // SEND_NOTHING
ASSERT(send == SEND_NOTHING);
DCHECK(send == SEND_NOTHING);
if (engine()->voe()->base()->StopSend(channel) == -1) {
LOG_RTCERR1(StopSend, channel);
return false;
@ -2866,7 +2866,7 @@ bool WebRtcVoiceMediaChannel::RemoveRecvStream(uint32 ssrc) {
receive_channels_.erase(it);
if (ssrc == default_receive_ssrc_) {
ASSERT(IsDefaultChannel(channel));
DCHECK(IsDefaultChannel(channel));
// Recycle the default channel is for recv stream.
if (playout_)
SetPlayout(voe_channel(), false);
@ -3546,15 +3546,15 @@ bool WebRtcVoiceMediaChannel::GetStats(VoiceMediaInfo* info) {
void WebRtcVoiceMediaChannel::GetLastMediaError(
uint32* ssrc, VoiceMediaChannel::Error* error) {
ASSERT(ssrc != NULL);
ASSERT(error != NULL);
DCHECK(ssrc != NULL);
DCHECK(error != NULL);
FindSsrc(voe_channel(), ssrc);
*error = WebRtcErrorToChannelError(GetLastEngineError());
}
bool WebRtcVoiceMediaChannel::FindSsrc(int channel_num, uint32* ssrc) {
rtc::CritScope lock(&receive_channels_cs_);
ASSERT(ssrc != NULL);
DCHECK(ssrc != NULL);
if (channel_num == -1 && send_ != SEND_NOTHING) {
// Sometimes the VoiceEngine core will throw error with channel_num = -1.
// This means the error is not limited to a specific channel. Signal the

View File

@ -102,7 +102,7 @@ class WebRtcVoiceEngineTestFake : public testing::Test {
public:
explicit ChannelErrorListener(cricket::VoiceMediaChannel* channel)
: ssrc_(0), error_(cricket::VoiceMediaChannel::ERROR_NONE) {
ASSERT(channel != NULL);
DCHECK(channel != NULL);
channel->SignalMediaError.connect(
this, &ChannelErrorListener::OnVoiceChannelError);
}