Skip to content

Commit

Permalink
Add explicit type conversions where necessary: media/
Browse files Browse the repository at this point in the history
These are cases that are implicitly narrowing today, and must do so
explicitly in order to enable -Wc++11-narrowing.  No behavior change
intended.

Bug: 1216696
Change-Id: Ic25e15adf0b53f0166b2d7b362365c910fd403bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2948073
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Will Cassella <cassew@google.com>
Reviewed-by: Will Cassella <cassew@google.com>
Cr-Commit-Position: refs/heads/master@{#890792}
  • Loading branch information
pkasting authored and Chromium LUCI CQ committed Jun 9, 2021
1 parent 9ddae15 commit 38bcdc3
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 33 deletions.
4 changes: 2 additions & 2 deletions media/capture/video/win/gpu_memory_buffer_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ base::win::ScopedHandle CreateNV12Texture(ID3D11Device* d3d11_device,
const gfx::Size& size) {
const DXGI_FORMAT dxgi_format = DXGI_FORMAT_NV12;
D3D11_TEXTURE2D_DESC desc = {
.Width = size.width(),
.Height = size.height(),
.Width = static_cast<UINT>(size.width()),
.Height = static_cast<UINT>(size.height()),
.MipLevels = 1,
.ArraySize = 1,
.Format = dxgi_format,
Expand Down
33 changes: 22 additions & 11 deletions media/cdm/cbcs_decryptor_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ TEST_F(CbcsDecryptorTest, OneBlock) {
DCHECK_EQ(kBlockSize, encrypted_block.size());

// Only 1 subsample, all encrypted data.
std::vector<SubsampleEntry> subsamples = {{0, encrypted_block.size()}};
std::vector<SubsampleEntry> subsamples = {
{0, static_cast<uint32_t>(encrypted_block.size())}};

auto encrypted_buffer = CreateEncryptedBuffer(
encrypted_block, iv_, subsamples, EncryptionPattern(1, 9));
Expand All @@ -160,7 +161,8 @@ TEST_F(CbcsDecryptorTest, AdditionalData) {
DCHECK_EQ(kBlockSize, encrypted_block.size());

// Only 1 subsample, all encrypted data.
std::vector<SubsampleEntry> subsamples = {{0, encrypted_block.size()}};
std::vector<SubsampleEntry> subsamples = {
{0, static_cast<uint32_t>(encrypted_block.size())}};

auto encrypted_buffer = CreateEncryptedBuffer(
encrypted_block, iv_, subsamples, EncryptionPattern(1, 9));
Expand Down Expand Up @@ -190,7 +192,8 @@ TEST_F(CbcsDecryptorTest, DifferentPattern) {
DCHECK_EQ(kBlockSize, encrypted_block.size());

// Only 1 subsample, all encrypted data.
std::vector<SubsampleEntry> subsamples = {{0, encrypted_block.size()}};
std::vector<SubsampleEntry> subsamples = {
{0, static_cast<uint32_t>(encrypted_block.size())}};

auto encrypted_buffer = CreateEncryptedBuffer(
encrypted_block, iv_, subsamples, EncryptionPattern(1, 0));
Expand All @@ -202,7 +205,8 @@ TEST_F(CbcsDecryptorTest, EmptyPattern) {
DCHECK_EQ(kBlockSize, encrypted_block.size());

// Only 1 subsample, all encrypted data.
std::vector<SubsampleEntry> subsamples = {{0, encrypted_block.size()}};
std::vector<SubsampleEntry> subsamples = {
{0, static_cast<uint32_t>(encrypted_block.size())}};

// Pattern 0:0 treats the buffer as all encrypted.
auto encrypted_buffer = CreateEncryptedBuffer(
Expand All @@ -215,7 +219,8 @@ TEST_F(CbcsDecryptorTest, PatternTooLarge) {
DCHECK_EQ(kBlockSize, encrypted_block.size());

// Only 1 subsample, all encrypted data.
std::vector<SubsampleEntry> subsamples = {{0, encrypted_block.size()}};
std::vector<SubsampleEntry> subsamples = {
{0, static_cast<uint32_t>(encrypted_block.size())}};

// Pattern 100:0 is too large, so decryption will fail.
auto encrypted_buffer = CreateEncryptedBuffer(
Expand All @@ -238,7 +243,8 @@ TEST_F(CbcsDecryptorTest, BadSubsamples) {
auto encrypted_block = Encrypt(one_block_, *key_, iv_);

// Subsample size > data size.
std::vector<SubsampleEntry> subsamples = {{0, encrypted_block.size() + 1}};
std::vector<SubsampleEntry> subsamples = {
{0, static_cast<uint32_t>(encrypted_block.size() + 1)}};

auto encrypted_buffer = CreateEncryptedBuffer(
encrypted_block, iv_, subsamples, EncryptionPattern(1, 0));
Expand All @@ -248,7 +254,8 @@ TEST_F(CbcsDecryptorTest, BadSubsamples) {
TEST_F(CbcsDecryptorTest, InvalidIv) {
auto encrypted_block = Encrypt(one_block_, *key_, iv_);

std::vector<SubsampleEntry> subsamples = {{0, encrypted_block.size()}};
std::vector<SubsampleEntry> subsamples = {
{0, static_cast<uint32_t>(encrypted_block.size())}};

// Use an invalid IV for decryption. Call should succeed, but return
// something other than the original data.
Expand All @@ -261,7 +268,8 @@ TEST_F(CbcsDecryptorTest, InvalidIv) {
TEST_F(CbcsDecryptorTest, InvalidKey) {
auto encrypted_block = Encrypt(one_block_, *key_, iv_);

std::vector<SubsampleEntry> subsamples = {{0, encrypted_block.size()}};
std::vector<SubsampleEntry> subsamples = {
{0, static_cast<uint32_t>(encrypted_block.size())}};

// Use a different key for decryption. Call should succeed, but return
// something other than the original data.
Expand All @@ -275,7 +283,8 @@ TEST_F(CbcsDecryptorTest, InvalidKey) {
TEST_F(CbcsDecryptorTest, PartialBlock) {
// Only 1 subsample, all "encrypted" data. However, as it's not a full block,
// it will be treated as unencrypted.
std::vector<SubsampleEntry> subsamples = {{0, partial_block_.size()}};
std::vector<SubsampleEntry> subsamples = {
{0, static_cast<uint32_t>(partial_block_.size())}};

auto encrypted_buffer = CreateEncryptedBuffer(partial_block_, iv_, subsamples,
EncryptionPattern(1, 0));
Expand All @@ -290,7 +299,8 @@ TEST_F(CbcsDecryptorTest, SingleBlockWithExtraData) {
auto expected_result = Combine({one_block_, partial_block_});

// Only 1 subsample, all "encrypted" data.
std::vector<SubsampleEntry> subsamples = {{0, encrypted_block.size()}};
std::vector<SubsampleEntry> subsamples = {
{0, static_cast<uint32_t>(encrypted_block.size())}};

auto encrypted_buffer = CreateEncryptedBuffer(
encrypted_block, iv_, subsamples, EncryptionPattern(1, 0));
Expand All @@ -299,7 +309,8 @@ TEST_F(CbcsDecryptorTest, SingleBlockWithExtraData) {

TEST_F(CbcsDecryptorTest, SkipBlock) {
// Only 1 subsample, but all unencrypted data.
std::vector<SubsampleEntry> subsamples = {{one_block_.size(), 0}};
std::vector<SubsampleEntry> subsamples = {
{static_cast<uint32_t>(one_block_.size()), 0}};

auto encrypted_buffer = CreateEncryptedBuffer(one_block_, iv_, subsamples,
EncryptionPattern(1, 0));
Expand Down
2 changes: 1 addition & 1 deletion media/gpu/h264_decoder_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ TEST_F(H264DecoderTest, 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
Original file line number Diff line number Diff line change
Expand Up @@ -1304,8 +1304,8 @@ HRESULT MediaFoundationVideoEncodeAccelerator::InitializeD3DVideoProcessing(
.InputWidth = input_desc.Width,
.InputHeight = input_desc.Height,
.OutputFrameRate = {60, 1},
.OutputWidth = input_visible_size_.width(),
.OutputHeight = input_visible_size_.height(),
.OutputWidth = static_cast<UINT>(input_visible_size_.width()),
.OutputHeight = static_cast<UINT>(input_visible_size_.height()),
.Usage = D3D11_VIDEO_USAGE_PLAYBACK_NORMAL};

Microsoft::WRL::ComPtr<ID3D11Device> texture_device;
Expand Down Expand Up @@ -1336,8 +1336,8 @@ HRESULT MediaFoundationVideoEncodeAccelerator::InitializeD3DVideoProcessing(
video_processor.Get(), 0, FALSE);

D3D11_TEXTURE2D_DESC scaled_desc = {
.Width = input_visible_size_.width(),
.Height = input_visible_size_.height(),
.Width = static_cast<UINT>(input_visible_size_.width()),
.Height = static_cast<UINT>(input_visible_size_.height()),
.MipLevels = 1,
.ArraySize = 1,
.Format = DXGI_FORMAT_NV12,
Expand Down Expand Up @@ -1423,15 +1423,15 @@ HRESULT MediaFoundationVideoEncodeAccelerator::PerformD3DScaling(

D3D11_TEXTURE2D_DESC input_texture_desc = {};
input_texture->GetDesc(&input_texture_desc);
RECT source_rect = {0, 0, input_texture_desc.Width,
input_texture_desc.Height};
RECT source_rect = {0, 0, static_cast<LONG>(input_texture_desc.Width),
static_cast<LONG>(input_texture_desc.Height)};
video_context_->VideoProcessorSetStreamSourceRect(video_processor_.Get(), 0,
TRUE, &source_rect);

D3D11_TEXTURE2D_DESC output_texture_desc = {};
scaled_d3d11_texture_->GetDesc(&output_texture_desc);
RECT dest_rect = {0, 0, output_texture_desc.Width,
output_texture_desc.Height};
RECT dest_rect = {0, 0, static_cast<LONG>(output_texture_desc.Width),
static_cast<LONG>(output_texture_desc.Height)};
video_context_->VideoProcessorSetOutputTargetRect(video_processor_.Get(),
TRUE, &dest_rect);
video_context_->VideoProcessorSetStreamDestRect(video_processor_.Get(), 0,
Expand Down
8 changes: 4 additions & 4 deletions media/gpu/windows/supported_profile_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ bool IsResolutionSupportedForDevice(const gfx::Size& resolution_to_test,
ID3D11VideoDevice* video_device,
DXGI_FORMAT format) {
D3D11_VIDEO_DECODER_DESC desc = {
decoder_guid, // Guid
resolution_to_test.width(), // SampleWidth
resolution_to_test.height(), // SampleHeight
format // OutputFormat
decoder_guid, // Guid
static_cast<UINT>(resolution_to_test.width()), // SampleWidth
static_cast<UINT>(resolution_to_test.height()), // SampleHeight
format // OutputFormat
};

// We've chosen the least expensive test for identifying if a given resolution
Expand Down
12 changes: 7 additions & 5 deletions media/mojo/common/mojo_shared_buffer_video_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ MojoSharedBufferVideoFrame::CreateDefaultForTesting(
return Create(
format, coded_size, visible_rect, dimensions, std::move(handle),
allocation_size,
{0 /* y_offset */, coded_size.GetArea(), coded_size.GetArea() * 5 / 4},
{0 /* y_offset */, static_cast<uint32_t>(coded_size.GetArea()),
static_cast<uint32_t>(coded_size.GetArea() * 5 / 4)},
{coded_size.width(), coded_size.width() / 2, coded_size.width() / 2},
timestamp);
} else {
Expand All @@ -71,10 +72,11 @@ MojoSharedBufferVideoFrame::CreateDefaultForTesting(
// as follows:
// - Yplane, full size (each element represents a 1x1 block)
// - UVplane, full width, half height (each pair represents a 2x2 block)
return Create(format, coded_size, visible_rect, dimensions,
std::move(handle), allocation_size,
{0 /* y_offset */, coded_size.GetArea()},
{coded_size.width(), coded_size.width()}, timestamp);
return Create(
format, coded_size, visible_rect, dimensions, std::move(handle),
allocation_size,
{0 /* y_offset */, static_cast<uint32_t>(coded_size.GetArea())},
{coded_size.width(), coded_size.width()}, timestamp);
}
}

Expand Down
4 changes: 3 additions & 1 deletion media/mojo/services/mojo_cdm_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ class MojoCdmVideoFrame final : public VideoFrameImpl {
natural_size, std::move(handle), buffer_size,
{PlaneOffset(cdm::kYPlane), PlaneOffset(cdm::kUPlane),
PlaneOffset(cdm::kVPlane)},
{Stride(cdm::kYPlane), Stride(cdm::kUPlane), Stride(cdm::kVPlane)},
{static_cast<int32_t>(Stride(cdm::kYPlane)),
static_cast<int32_t>(Stride(cdm::kUPlane)),
static_cast<int32_t>(Stride(cdm::kVPlane))},
base::TimeDelta::FromMicroseconds(Timestamp()));

// |frame| could fail to be created if the memory can't be mapped into
Expand Down
3 changes: 2 additions & 1 deletion media/renderers/win/media_foundation_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ void MediaFoundationRenderer::OnVideoNaturalSizeChange() {
<< hr;
native_video_size_ = {640, 320};
} else {
native_video_size_ = {native_width, native_height};
native_video_size_ = {static_cast<int>(native_width),
static_cast<int>(native_height)};
}

// TODO(frankli): Use actual dest rect provided by client instead of video
Expand Down

0 comments on commit 38bcdc3

Please sign in to comment.