Fixing warning C4267 on Win (more_configs).

This is a follow-up of https://webrtc-review.googlesource.com/c/src/+/12921.

Bug: chromium:759980
Change-Id: Ifd39adb6541c0c7e0337f587a8b34b84a07331ed
Reviewed-on: https://webrtc-review.googlesource.com/13122
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20341}
This commit is contained in:
Mirko Bonadei
2017-10-19 09:00:17 +02:00
committed by Commit Bot
parent 117c48291c
commit 737e073f8d
16 changed files with 70 additions and 43 deletions

View File

@ -108,7 +108,7 @@ class AcmReceiverTestOldApi : public AudioPacketizationCallback,
last_packet_send_timestamp_ = timestamp_;
while (!packet_sent_) {
frame.timestamp_ = timestamp_;
timestamp_ += frame.samples_per_channel_;
timestamp_ += rtc::checked_cast<uint32_t>(frame.samples_per_channel_);
ASSERT_GE(acm_->Add10MsData(frame), 0);
}
}
@ -175,8 +175,9 @@ TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecGetCodec) {
for (size_t n = 0; n < codecs_.size(); ++n) {
if (n & 0x1) { // Just add codecs with odd index.
EXPECT_EQ(
0, receiver_->AddCodec(n, codecs_[n].pltype, codecs_[n].channels,
codecs_[n].plfreq, NULL, codecs_[n].plname));
0, receiver_->AddCodec(rtc::checked_cast<int>(n), codecs_[n].pltype,
codecs_[n].channels, codecs_[n].plfreq, NULL,
codecs_[n].plname));
}
}
// Get codec and compare.
@ -338,7 +339,7 @@ class AcmReceiverTestFaxModeOldApi : public AcmReceiverTestOldApi {
EXPECT_EQ(0,
receiver_->GetAudio(output_sample_rate_hz, &frame, &muted));
EXPECT_EQ(expected_output_ts, frame.timestamp_);
expected_output_ts += 10 * samples_per_ms;
expected_output_ts += rtc::checked_cast<uint32_t>(10 * samples_per_ms);
EXPECT_EQ(10 * samples_per_ms, frame.samples_per_channel_);
EXPECT_EQ(output_sample_rate_hz, frame.sample_rate_hz_);
EXPECT_EQ(output_channels, frame.num_channels_);

View File

@ -37,6 +37,7 @@
#include "rtc_base/md5digest.h"
#include "rtc_base/platform_thread.h"
#include "rtc_base/refcountedobject.h"
#include "rtc_base/safe_conversions.h"
#include "rtc_base/thread_annotations.h"
#include "system_wrappers/include/clock.h"
#include "system_wrappers/include/event_wrapper.h"
@ -122,7 +123,7 @@ class PacketizationCallbackStubOldApi : public AudioPacketizationCallback {
int last_payload_len_bytes() const {
rtc::CritScope lock(&crit_sect_);
return last_payload_vec_.size();
return rtc::checked_cast<int>(last_payload_vec_.size());
}
FrameType last_frame_type() const {
@ -1158,9 +1159,9 @@ class AcmSenderBitExactnessOldApi : public ::testing::Test,
bool RegisterExternalSendCodec(AudioEncoder* external_speech_encoder,
int payload_type) {
payload_type_ = payload_type;
frame_size_rtp_timestamps_ =
frame_size_rtp_timestamps_ = rtc::checked_cast<uint32_t>(
external_speech_encoder->Num10MsFramesInNextPacket() *
external_speech_encoder->RtpTimestampRateHz() / 100;
external_speech_encoder->RtpTimestampRateHz() / 100);
return send_test_->RegisterExternalCodec(external_speech_encoder);
}
@ -1589,7 +1590,7 @@ class AcmSetBitRateTest : public ::testing::Test {
int nr_bytes = 0;
while (std::unique_ptr<test::Packet> next_packet =
send_test_->NextPacket()) {
nr_bytes += next_packet->payload_length_bytes();
nr_bytes += rtc::checked_cast<int>(next_packet->payload_length_bytes());
}
EXPECT_EQ(expected_total_bits, nr_bytes * 8);
}
@ -1742,9 +1743,11 @@ class AcmChangeBitRateOldApi : public AcmSetBitRateOldApi {
if (packet_counter == nr_packets / 2)
send_test_->acm()->SetBitRate(target_bitrate_bps);
if (packet_counter < nr_packets / 2)
nr_bytes_before += next_packet->payload_length_bytes();
nr_bytes_before += rtc::checked_cast<int>(
next_packet->payload_length_bytes());
else
nr_bytes_after += next_packet->payload_length_bytes();
nr_bytes_after += rtc::checked_cast<int>(
next_packet->payload_length_bytes());
packet_counter++;
}
EXPECT_EQ(expected_before_switch_bits, nr_bytes_before * 8);

View File

@ -9,6 +9,7 @@
*/
#include "modules/audio_coding/audio_network_adaptor/bitrate_controller.h"
#include "rtc_base/safe_conversions.h"
#include "test/field_trial.h"
#include "test/gtest.h"
@ -213,8 +214,8 @@ TEST(AnaBitrateControllerTest, CheckBehaviorOnChangingCondition) {
int overall_bitrate = 34567;
size_t overhead_bytes_per_packet = 64;
int frame_length_ms = 20;
int current_bitrate =
overall_bitrate - overhead_bytes_per_packet * 8 * 1000 / frame_length_ms;
int current_bitrate = rtc::checked_cast<int>(
overall_bitrate - overhead_bytes_per_packet * 8 * 1000 / frame_length_ms);
UpdateNetworkMetrics(&controller, rtc::Optional<int>(overall_bitrate),
rtc::Optional<size_t>(overhead_bytes_per_packet));
@ -231,8 +232,9 @@ TEST(AnaBitrateControllerTest, CheckBehaviorOnChangingCondition) {
// Next: change frame length.
frame_length_ms = 60;
current_bitrate += overhead_bytes_per_packet * 8 * 1000 / 20 -
overhead_bytes_per_packet * 8 * 1000 / 60;
current_bitrate += rtc::checked_cast<int>(
overhead_bytes_per_packet * 8 * 1000 / 20 -
overhead_bytes_per_packet * 8 * 1000 / 60);
UpdateNetworkMetrics(&controller, rtc::Optional<int>(overall_bitrate),
rtc::Optional<size_t>(overhead_bytes_per_packet));
CheckDecision(&controller, rtc::Optional<int>(frame_length_ms),
@ -248,8 +250,9 @@ TEST(AnaBitrateControllerTest, CheckBehaviorOnChangingCondition) {
// Next: change frame length.
frame_length_ms = 20;
current_bitrate -= overhead_bytes_per_packet * 8 * 1000 / 20 -
overhead_bytes_per_packet * 8 * 1000 / 60;
current_bitrate -= rtc::checked_cast<int>(
overhead_bytes_per_packet * 8 * 1000 / 20 -
overhead_bytes_per_packet * 8 * 1000 / 60);
UpdateNetworkMetrics(&controller, rtc::Optional<int>(overall_bitrate),
rtc::Optional<size_t>(overhead_bytes_per_packet));
CheckDecision(&controller, rtc::Optional<int>(frame_length_ms),
@ -259,8 +262,9 @@ TEST(AnaBitrateControllerTest, CheckBehaviorOnChangingCondition) {
overall_bitrate -= 100;
current_bitrate -= 100;
frame_length_ms = 60;
current_bitrate += overhead_bytes_per_packet * 8 * 1000 / 20 -
overhead_bytes_per_packet * 8 * 1000 / 60;
current_bitrate += rtc::checked_cast<int>(
overhead_bytes_per_packet * 8 * 1000 / 20 -
overhead_bytes_per_packet * 8 * 1000 / 60);
UpdateNetworkMetrics(&controller, rtc::Optional<int>(overall_bitrate),
rtc::Optional<size_t>(overhead_bytes_per_packet));

View File

@ -13,6 +13,7 @@
#include <vector>
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "rtc_base/safe_conversions.h"
#include "test/gmock.h"
#include "test/gtest.h"
@ -58,8 +59,8 @@ TEST_P(AudioEncoderFactoryTest, CanRunAllSupportedEncoders) {
auto encoder = factory->MakeAudioEncoder(kTestPayloadType, spec.format);
EXPECT_TRUE(encoder);
encoder->Reset();
const int num_samples =
encoder->SampleRateHz() * encoder->NumChannels() / 100;
const int num_samples = rtc::checked_cast<int>(
encoder->SampleRateHz() * encoder->NumChannels() / 100);
rtc::Buffer out;
rtc::BufferT<int16_t> audio;
audio.SetData(num_samples, [](rtc::ArrayView<int16_t> audio) {

View File

@ -14,6 +14,7 @@
#include "common_audio/vad/mock/mock_vad.h"
#include "modules/audio_coding/codecs/cng/audio_encoder_cng.h"
#include "rtc_base/constructormagic.h"
#include "rtc_base/safe_conversions.h"
#include "test/gtest.h"
#include "test/mock_audio_encoder.h"
@ -290,7 +291,8 @@ TEST_F(AudioEncoderCngTest, EncodePassive) {
encoded_info_.encoded_bytes);
EXPECT_EQ(expected_timestamp, encoded_info_.encoded_timestamp);
}
expected_timestamp += kBlocksPerFrame * num_audio_samples_10ms_;
expected_timestamp += rtc::checked_cast<uint32_t>(
kBlocksPerFrame * num_audio_samples_10ms_);
} else {
// Otherwise, expect no output.
EXPECT_EQ(0u, encoded_info_.encoded_bytes);

View File

@ -17,6 +17,7 @@
#include "modules/audio_coding/codecs/isac/main/include/audio_encoder_isac.h"
#include "modules/audio_coding/neteq/tools/input_audio_file.h"
#include "rtc_base/buffer.h"
#include "rtc_base/safe_conversions.h"
#include "test/gtest.h"
#include "test/testsupport/fileutils.h"
@ -163,10 +164,12 @@ void TestGetSetBandwidthInfo(const int16_t* speech_data,
const int send_time = elapsed_time_ms * (sample_rate_hz / 1000);
EXPECT_EQ(0, T::UpdateBwEstimate(
encdec, bitstream1.data(), bitstream1.size(), i, send_time,
channel1.Send(send_time, bitstream1.size())));
channel1.Send(send_time,
rtc::checked_cast<int>(bitstream1.size()))));
EXPECT_EQ(0, T::UpdateBwEstimate(
dec, bitstream2.data(), bitstream2.size(), i, send_time,
channel2.Send(send_time, bitstream2.size())));
channel2.Send(send_time,
rtc::checked_cast<int>(bitstream2.size()))));
// 3. Decode, and get new BW info from the separate decoder.
ASSERT_EQ(0, T::SetDecSampRate(encdec, sample_rate_hz));

View File

@ -10,6 +10,7 @@
#include "modules/audio_coding/acm2/rent_a_codec.h"
#include "modules/audio_coding/codecs/legacy_encoded_audio_frame.h"
#include "rtc_base/safe_conversions.h"
#include "test/gtest.h"
namespace webrtc {
@ -140,8 +141,9 @@ TEST_P(SplitBySamplesTest, PayloadSizes) {
ASSERT_EQ(value, payload[i]);
}
expected_timestamp += expected_split.frame_sizes[i] * samples_per_ms_;
expected_byte_offset += length_bytes;
expected_timestamp += rtc::checked_cast<uint32_t>(
expected_split.frame_sizes[i] * samples_per_ms_);
expected_byte_offset += rtc::checked_cast<uint32_t>(length_bytes);
}
}
}

View File

@ -15,6 +15,7 @@
#include "modules/audio_coding/codecs/opus/opus_interface.h"
#include "modules/audio_coding/neteq/tools/audio_loop.h"
#include "rtc_base/checks.h"
#include "rtc_base/safe_conversions.h"
#include "test/gtest.h"
#include "test/testsupport/fileutils.h"
@ -334,7 +335,7 @@ void OpusTest::TestCbrEffect(bool cbr, int block_length_ms) {
int32_t diff = std::abs((int32_t)encoded_bytes_ - prev_pkt_size);
max_pkt_size_diff = std::max(max_pkt_size_diff, diff);
}
prev_pkt_size = encoded_bytes_;
prev_pkt_size = rtc::checked_cast<int32_t>(encoded_bytes_);
}
if (cbr) {
@ -736,7 +737,9 @@ TEST_P(OpusTest, OpusDecodeRepacketized) {
WebRtcOpus_Encode(opus_encoder_, speech_block.data(),
rtc::CheckedDivExact(speech_block.size(), channels_),
kMaxBytes, bitstream_);
if (opus_repacketizer_cat(rp, bitstream_, encoded_bytes_) == OPUS_OK) {
if (opus_repacketizer_cat(
rp, bitstream_,
rtc::checked_cast<opus_int32>(encoded_bytes_)) == OPUS_OK) {
++num_packets;
if (num_packets == kPackets) {
break;

View File

@ -13,6 +13,7 @@
#include "modules/audio_coding/codecs/red/audio_encoder_copy_red.h"
#include "rtc_base/checks.h"
#include "rtc_base/safe_conversions.h"
#include "test/gtest.h"
#include "test/mock_audio_encoder.h"
@ -59,7 +60,7 @@ class AudioEncoderCopyRedTest : public ::testing::Test {
timestamp_,
rtc::ArrayView<const int16_t>(audio_, num_audio_samples_10ms),
&encoded_);
timestamp_ += num_audio_samples_10ms;
timestamp_ += rtc::checked_cast<uint32_t>(num_audio_samples_10ms);
}
MockAudioEncoder* mock_encoder_;

View File

@ -9,6 +9,7 @@
*/
#include "modules/audio_coding/neteq/audio_multi_vector.h"
#include "rtc_base/safe_conversions.h"
#include <assert.h>
#include <stdlib.h>
@ -51,7 +52,7 @@ class AudioMultiVectorTest : public ::testing::TestWithParam<size_t> {
// And so on.
for (size_t i = 0; i < array_length(); ++i) {
for (size_t j = 1; j <= num_channels_; ++j) {
*ptr = j * 100 + i;
*ptr = rtc::checked_cast<int16_t>(j * 100 + i);
++ptr;
}
}

View File

@ -9,6 +9,7 @@
*/
#include "modules/audio_coding/neteq/audio_vector.h"
#include "rtc_base/safe_conversions.h"
#include <assert.h>
#include <stdlib.h>
@ -25,7 +26,7 @@ class AudioVectorTest : public ::testing::Test {
virtual void SetUp() {
// Populate test array.
for (size_t i = 0; i < array_length(); ++i) {
array_[i] = i;
array_[i] = rtc::checked_cast<int16_t>(i);
}
}
@ -253,7 +254,7 @@ TEST_F(AudioVectorTest, InsertAtEnd) {
for (int i = 0; i < kNewLength; ++i) {
new_array[i] = 100 + i;
}
int insert_position = array_length();
int insert_position = rtc::checked_cast<int>(array_length());
vec.InsertAt(new_array, kNewLength, insert_position);
// Verify that the vector looks as follows:
// {0, 1, ..., kLength - 1, 100, 101, ..., 100 + kNewLength - 1 }.
@ -282,7 +283,8 @@ TEST_F(AudioVectorTest, InsertBeyondEnd) {
for (int i = 0; i < kNewLength; ++i) {
new_array[i] = 100 + i;
}
int insert_position = array_length() + 10; // Too large.
int insert_position = rtc::checked_cast<int>(
array_length() + 10); // Too large.
vec.InsertAt(new_array, kNewLength, insert_position);
// Verify that the vector looks as follows:
// {0, 1, ..., kLength - 1, 100, 101, ..., 100 + kNewLength - 1 }.
@ -338,7 +340,7 @@ TEST_F(AudioVectorTest, OverwriteBeyondEnd) {
for (int i = 0; i < kNewLength; ++i) {
new_array[i] = 100 + i;
}
int insert_position = array_length() - 2;
int insert_position = rtc::checked_cast<int>(array_length() - 2);
vec.OverwriteAt(new_array, kNewLength, insert_position);
ASSERT_EQ(array_length() - 2u + kNewLength, vec.Size());
// Verify that the vector looks as follows:

View File

@ -88,8 +88,8 @@ class ExpandTest : public ::testing::Test {
void SetUp() override {
// Fast-forward the input file until there is speech (about 1.1 second into
// the file).
const size_t speech_start_samples =
static_cast<size_t>(test_sample_rate_hz_ * 1.1f);
const int speech_start_samples =
static_cast<int>(test_sample_rate_hz_ * 1.1f);
ASSERT_TRUE(input_file_.Seek(speech_start_samples));
// Pre-load the sync buffer with speech data.

View File

@ -483,7 +483,7 @@ TEST_F(NetEqImplTest, VerifyTimestampPropagation) {
decoded[i] = next_value_++;
}
*speech_type = kSpeech;
return encoded_len;
return rtc::checked_cast<int>(encoded_len);
}
void Reset() override { next_value_ = 1; }
@ -1312,7 +1312,7 @@ class Decoder120ms : public AudioDecoder {
decoded[i] = next_value_++;
}
*speech_type = speech_type_;
return decoded_len;
return rtc::checked_cast<int>(decoded_len);
}
void Reset() override { next_value_ = 1; }

View File

@ -20,6 +20,7 @@
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "modules/audio_coding/neteq/mock/mock_decoder_database.h"
#include "modules/audio_coding/neteq/packet.h"
#include "rtc_base/safe_conversions.h"
#include "test/gtest.h"
#include "test/mock_audio_decoder_factory.h"
@ -99,7 +100,8 @@ Packet CreateRedPayload(size_t num_payloads,
// Not the last block; set F = 1.
*payload_ptr |= 0x80;
++payload_ptr;
int this_offset = (num_payloads - i - 1) * timestamp_offset;
int this_offset = rtc::checked_cast<int>(
(num_payloads - i - 1) * timestamp_offset);
*payload_ptr = this_offset >> 6;
++payload_ptr;
assert(kPayloadLength <= 1023); // Max length described by 10 bits.

View File

@ -9,6 +9,7 @@
*/
#include "modules/audio_coding/neteq/sync_buffer.h"
#include "rtc_base/safe_conversions.h"
#include "test/gtest.h"
@ -57,7 +58,7 @@ TEST(SyncBuffer, PushBackAndFlush) {
// Populate |new_data|.
for (size_t channel = 0; channel < kChannels; ++channel) {
for (size_t i = 0; i < kNewLen; ++i) {
new_data[channel][i] = i;
new_data[channel][i] = rtc::checked_cast<int16_t>(i);
}
}
// Push back |new_data| into |sync_buffer|. This operation should pop out
@ -97,7 +98,7 @@ TEST(SyncBuffer, PushFrontZeros) {
// Populate |new_data|.
for (size_t channel = 0; channel < kChannels; ++channel) {
for (size_t i = 0; i < kNewLen; ++i) {
new_data[channel][i] = 1000 + i;
new_data[channel][i] = rtc::checked_cast<int16_t>(1000 + i);
}
}
sync_buffer.PushBack(new_data);
@ -130,7 +131,7 @@ TEST(SyncBuffer, GetNextAudioInterleaved) {
// Populate |new_data|.
for (size_t channel = 0; channel < kChannels; ++channel) {
for (size_t i = 0; i < kNewLen; ++i) {
new_data[channel][i] = i;
new_data[channel][i] = rtc::checked_cast<int16_t>(i);
}
}
// Push back |new_data| into |sync_buffer|. This operation should pop out

View File

@ -11,6 +11,7 @@
// Unit tests for test InputAudioFile class.
#include "modules/audio_coding/neteq/tools/input_audio_file.h"
#include "rtc_base/safe_conversions.h"
#include "test/gtest.h"
@ -22,7 +23,7 @@ TEST(TestInputAudioFile, DuplicateInterleaveSeparateSrcDst) {
static const size_t kChannels = 2;
int16_t input[kSamples];
for (size_t i = 0; i < kSamples; ++i) {
input[i] = i;
input[i] = rtc::checked_cast<int16_t>(i);
}
int16_t output[kSamples * kChannels];
InputAudioFile::DuplicateInterleaved(input, kSamples, kChannels, output);
@ -41,7 +42,7 @@ TEST(TestInputAudioFile, DuplicateInterleaveSameSrcDst) {
static const size_t kChannels = 5;
int16_t input[kSamples * kChannels];
for (size_t i = 0; i < kSamples; ++i) {
input[i] = i;
input[i] = rtc::checked_cast<int16_t>(i);
}
InputAudioFile::DuplicateInterleaved(input, kSamples, kChannels, input);