Skip to content

Commit

Permalink
Fix -Wc++11-narrowing: media/
Browse files Browse the repository at this point in the history
Bug: 1216696
Change-Id: If65eab84a66d5994c30eee2060923f87413b2f97
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2975071
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Will Cassella <cassew@google.com>
Cr-Commit-Position: refs/heads/master@{#894533}
  • Loading branch information
pkasting authored and Chromium LUCI CQ committed Jun 22, 2021
1 parent d95568c commit 952cf37
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 28 deletions.
4 changes: 2 additions & 2 deletions media/base/android/media_codec_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ static CodecProfileLevel MediaCodecProfileLevelToChromiumProfileLevel(
Java_CodecProfileLevelAdapter_getCodec(env, j_codec_profile_level));
VideoCodecProfile profile = static_cast<VideoCodecProfile>(
Java_CodecProfileLevelAdapter_getProfile(env, j_codec_profile_level));
int level =
Java_CodecProfileLevelAdapter_getLevel(env, j_codec_profile_level);
auto level = static_cast<VideoCodecLevel>(
Java_CodecProfileLevelAdapter_getLevel(env, j_codec_profile_level));
return {codec, profile, level};
}

Expand Down
6 changes: 3 additions & 3 deletions media/base/video_aspect_ratio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace media {

VideoAspectRatio::VideoAspectRatio(Type type, int width, int height) {
type_ = type;
aspect_ratio_ = height ? double{width} / height : 0.0;
aspect_ratio_ = height ? static_cast<double>(width) / height : 0.0;
}

// static
Expand All @@ -29,8 +29,8 @@ VideoAspectRatio::VideoAspectRatio(const gfx::Rect& visible_rect,
// The size of a pixel is:
// (natural_width / visible_width) by (natural_height / visible_height).
// Both are multiplied by (visible_width * visible_height) to avoid division.
double w = double{visible_rect.height()} * natural_size.width();
double h = double{visible_rect.width()} * natural_size.height();
double w = visible_rect.height() * natural_size.width();
double h = visible_rect.width() * natural_size.height();

type_ = Type::kPixel;
aspect_ratio_ = h != 0.0 ? w / h : 0.0;
Expand Down
2 changes: 1 addition & 1 deletion media/capture/video/linux/fake_v4l2_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ int FakeV4L2Impl::ioctl(int fd, int request, void* argp) {
return EBADF;
auto* opened_device = device_iter->second.get();

switch (request) {
switch (static_cast<uint32_t>(request)) {
case VIDIOC_ENUM_FMT:
return opened_device->enum_fmt(reinterpret_cast<v4l2_fmtdesc*>(argp));
case VIDIOC_QUERYCAP:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ void MaybeWriteUma(int number_of_devices, int number_of_suspended_devices) {
} // namespace

std::string MacFourCCToString(OSType fourcc) {
char arr[] = {fourcc >> 24, (fourcc >> 16) & 255, (fourcc >> 8) & 255,
fourcc & 255, 0};
char arr[] = {static_cast<char>(fourcc >> 24),
static_cast<char>(fourcc >> 16), static_cast<char>(fourcc >> 8),
static_cast<char>(fourcc), 0};
return arr;
}

Expand Down
6 changes: 4 additions & 2 deletions media/cdm/cbcs_decryptor_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// only set |subsamples| if |clear_bytes| <= |size|. If |subsamples| is
// empty, the complete buffer is treated as encrypted.
std::vector<media::SubsampleEntry> subsamples;
if (clear_bytes <= size)
subsamples.push_back({clear_bytes, size - clear_bytes});
if (clear_bytes <= size) {
subsamples.push_back(
{clear_bytes, static_cast<uint32_t>(size - clear_bytes)});
}

// |encryption_pattern| is used to determine the encryption pattern. Since
// |crypt_byte_block| must be > 0, use 1 for it. |skip_byte_block| can be 0.
Expand Down
6 changes: 4 additions & 2 deletions media/cdm/cenc_decryptor_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// only set |subsamples| if |clear_bytes| <= |size|. If |subsamples| is
// empty, the complete buffer is treated as encrypted.
std::vector<media::SubsampleEntry> subsamples;
if (clear_bytes <= size)
subsamples.push_back({clear_bytes, size - clear_bytes});
if (clear_bytes <= size) {
subsamples.push_back(
{clear_bytes, static_cast<uint32_t>(size - clear_bytes)});
}

auto encrypted_buffer = media::DecoderBuffer::CopyFrom(data, size);

Expand Down
2 changes: 1 addition & 1 deletion media/formats/webm/webm_cluster_parser_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ TEST_F(WebMClusterParserTest, PreferOpusDurationsOverBlockDurations) {
std::string(), std::string(), kCodecOpus));

// Setting BlockDuration != Opus duration to see which one the parser uses.
int block_duration_ms = packet_ptr->duration_ms() + 10;
double block_duration_ms = packet_ptr->duration_ms() + 10;
if (packet_ptr->duration_ms() > 120) {
EXPECT_MEDIA_LOG(OpusPacketDurationTooHigh(packet_ptr->duration_ms()));
}
Expand Down
2 changes: 1 addition & 1 deletion media/fuchsia/cdm/service/fuchsia_cdm_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct CdmDirectoryInfo {
// addition of most-recently-modified calculation, and inclusion of directory
// node sizes toward the total.
CdmDirectoryInfo GetCdmDirectoryInfo(const base::FilePath& path) {
int64_t directory_size = 0;
uint64_t directory_size = 0;
base::Time last_used;
base::FileEnumerator enumerator(
path, true /* recursive */,
Expand Down
2 changes: 1 addition & 1 deletion media/gpu/h265_decoder_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ TEST_F(H265DecoderTest, SetEncryptedStream) {
const std::vector<SubsampleEntry> subsamples = {
// No encrypted bytes. This test only checks whether the data is passed
// thru to the acclerator so making this completely clear.
{bitstream.size(), 0},
{static_cast<uint32_t>(bitstream.size()), 0},
};

std::unique_ptr<DecryptConfig> decrypt_config =
Expand Down
6 changes: 4 additions & 2 deletions media/gpu/mac/vt_video_decode_accelerator_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/numerics/safe_conversions.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h"
Expand Down Expand Up @@ -249,8 +250,9 @@ bool CreateVideoToolboxSession(
// output size for a 1:1 ratio. (Note though that VideoToolbox does not handle
// top or left crops correctly.) We expect the visible rect to be integral.
CGRect visible_rect = CMVideoFormatDescriptionGetCleanAperture(format, true);
CMVideoDimensions visible_dimensions = {visible_rect.size.width,
visible_rect.size.height};
CMVideoDimensions visible_dimensions = {
base::ClampFloor(visible_rect.size.width),
base::ClampFloor(visible_rect.size.height)};
base::ScopedCFTypeRef<CFMutableDictionaryRef> image_config(
BuildImageConfig(visible_dimensions, is_hbd));
if (!image_config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ uint32_t GetDefaultTargetBitrate(const gfx::Size& resolution,
gfx::Size resolution;
uint32_t bitrate;
} kDefaultTargetBitrates[] = {
{gfx::Size(640, 360), 1 * Mbps}, {gfx::Size(854, 480), 2.5 * Mbps},
{gfx::Size(640, 360), 1 * Mbps}, {gfx::Size(854, 480), 5 * Mbps / 2},
{gfx::Size(1280, 720), 5 * Mbps}, {gfx::Size(1920, 1080), 8 * Mbps},
{gfx::Size(3840, 2160), 18 * Mbps},
};
Expand Down
11 changes: 6 additions & 5 deletions media/gpu/vaapi/vaapi_video_decode_accelerator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,16 @@ class VaapiVideoDecodeAcceleratorTest : public TestWithParam<TestParams>,
.WillOnce(RunClosure(run_loop.QuitClosure()));

const auto tex_target = mock_vaapi_picture_factory_->GetGLTextureTarget();
int irrelevant_id = 2;
int32_t irrelevant_id = 2;
std::vector<PictureBuffer> picture_buffers;
for (size_t picture = 0; picture < num_pictures; ++picture) {
// The picture buffer id, client id and service texture ids are
// arbitrarily chosen.
picture_buffers.push_back({irrelevant_id++, picture_size,
PictureBuffer::TextureIds{irrelevant_id++},
PictureBuffer::TextureIds{irrelevant_id++},
tex_target, PIXEL_FORMAT_XRGB});
picture_buffers.push_back(
{irrelevant_id++, picture_size,
PictureBuffer::TextureIds{static_cast<uint32_t>(irrelevant_id++)},
PictureBuffer::TextureIds{static_cast<uint32_t>(irrelevant_id++)},
tex_target, PIXEL_FORMAT_XRGB});
}

AssignPictureBuffers(picture_buffers);
Expand Down
4 changes: 3 additions & 1 deletion media/gpu/windows/dxva_picture_buffer_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,9 @@ bool EGLStreamPictureBuffer::BindSampleToTexture(
dxgi_buffer->GetSubresourceIndex(&subresource);

EGLAttrib frame_attributes[] = {
EGL_D3D_TEXTURE_SUBRESOURCE_ID_ANGLE, subresource, EGL_NONE,
EGL_D3D_TEXTURE_SUBRESOURCE_ID_ANGLE,
static_cast<EGLAttrib>(subresource),
EGL_NONE,
};

EGLBoolean result = eglStreamPostD3DTextureANGLE(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ HRESULT MediaFoundationVideoEncodeAccelerator::PopulateInputSampleBuffer(
frame->row_bytes(VideoFrame::kYPlane) * frame->rows(VideoFrame::kYPlane);
uint8_t* end = dst_uv + frame->row_bytes(VideoFrame::kUVPlane) *
frame->rows(VideoFrame::kUVPlane);
DCHECK_GE(std::ptrdiff_t{scoped_buffer.max_length()},
DCHECK_GE(static_cast<ptrdiff_t>(scoped_buffer.max_length()),
end - scoped_buffer.get());

if (frame->format() == PIXEL_FORMAT_NV12) {
Expand Down
2 changes: 1 addition & 1 deletion media/renderers/win/media_foundation_audio_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ HRESULT GetAacAudioType(const AudioDecoderConfig decoder_config,
aac_wave_format->wfx.nBlockAlign = 1;

size_t extra_size = wave_format_size - sizeof(WAVEFORMATEX);
aac_wave_format->wfx.cbSize = WORD{extra_size};
aac_wave_format->wfx.cbSize = static_cast<WORD>(extra_size);
aac_wave_format->wPayloadType = 0; // RAW AAC
aac_wave_format->wAudioProfileLevelIndication =
0xFE; // no audio profile specified
Expand Down
4 changes: 2 additions & 2 deletions media/video/openh264_video_encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <limits>

#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
#include "base/system/sys_info.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
Expand Down Expand Up @@ -38,8 +39,7 @@ Status SetUpOpenH264Params(const VideoEncoder::Options& options,

if (options.bitrate.has_value()) {
params->iRCMode = RC_BITRATE_MODE;
params->iTargetBitrate = int{std::min(
options.bitrate.value(), uint64_t{std::numeric_limits<int>::max()})};
params->iTargetBitrate = base::saturated_cast<int>(options.bitrate.value());
} else {
params->iRCMode = RC_OFF_MODE;
}
Expand Down

0 comments on commit 952cf37

Please sign in to comment.