From 7e5d9edfdfe82e06182b790afe848cd0da179a87 Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Fri, 27 Jan 2023 15:10:22 +0100 Subject: [PATCH] webrtc_libyuv: Raise warnings for unhandled types at compile time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:14830 Change-Id: Ib5141e585f673098bbedd2872dbd6e6ed9df4864 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/291528 Reviewed-by: Erik Språng Reviewed-by: Stefan Holmer Commit-Queue: Erik Språng Cr-Commit-Position: refs/heads/main@{#39408} --- common_video/libyuv/webrtc_libyuv.cc | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/common_video/libyuv/webrtc_libyuv.cc b/common_video/libyuv/webrtc_libyuv.cc index 14e2d22612..46322501ad 100644 --- a/common_video/libyuv/webrtc_libyuv.cc +++ b/common_video/libyuv/webrtc_libyuv.cc @@ -22,7 +22,6 @@ namespace webrtc { size_t CalcBufferSize(VideoType type, int width, int height) { RTC_DCHECK_GE(width, 0); RTC_DCHECK_GE(height, 0); - size_t buffer_size = 0; switch (type) { case VideoType::kI420: case VideoType::kIYUV: @@ -30,26 +29,23 @@ size_t CalcBufferSize(VideoType type, int width, int height) { case VideoType::kNV12: { int half_width = (width + 1) >> 1; int half_height = (height + 1) >> 1; - buffer_size = width * height + half_width * half_height * 2; - break; + return width * height + half_width * half_height * 2; } case VideoType::kRGB565: case VideoType::kYUY2: case VideoType::kUYVY: - buffer_size = width * height * 2; - break; + return width * height * 2; case VideoType::kRGB24: - buffer_size = width * height * 3; - break; + return width * height * 3; case VideoType::kBGRA: case VideoType::kARGB: - buffer_size = width * height * 4; - break; - default: - RTC_DCHECK_NOTREACHED(); + return width * height * 4; + case VideoType::kMJPEG: + case VideoType::kUnknown: break; } - return buffer_size; + RTC_DCHECK_NOTREACHED() << "Unexpected pixel format " << type; + return 0; } int ExtractBuffer(const rtc::scoped_refptr& input_frame, @@ -109,7 +105,7 @@ int ConvertVideoType(VideoType video_type) { case VideoType::kNV12: return libyuv::FOURCC_NV12; } - RTC_DCHECK_NOTREACHED(); + RTC_DCHECK_NOTREACHED() << "Unexpected pixel format " << video_type; return libyuv::FOURCC_ANY; }