Fixes crash in WgcCaptureSession::ProcessFrame
This change fixes a minor issue where we previosuly assumed that the
following was true:
RTC_DCHECK_EQ(map_info.RowPitch, current_frame->stride())
It turns out that this is not always the case when sharing a window
where the stride can sometimes be a few bytes smaller than the
rowpitch.
The code is behind a command-line flag and no tests are affected.
Given limited review resources I therefore plan to bypass the CQ.
I know that it is not recommended but the change has been tested
locally on two different Windows platforms and it does avoid an
existing crash.
Code-Review: alcooper@chromium.org
No-Try: true
Bug: chromium:1421242
Change-Id: I01e7105a6f9fca7ce1349a57635dd373c28d160b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/309342
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Henrik Andreassson <henrika@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40308}
diff --git a/modules/desktop_capture/win/wgc_capture_session.cc b/modules/desktop_capture/win/wgc_capture_session.cc
index 61138c0..a291f20 100644
--- a/modules/desktop_capture/win/wgc_capture_session.cc
+++ b/modules/desktop_capture/win/wgc_capture_session.cc
@@ -455,8 +455,11 @@
uint8_t* dst_data = current_frame->data();
uint8_t* prev_data =
frame_content_can_be_compared ? previous_frame->data() : nullptr;
- RTC_DCHECK_EQ(map_info.RowPitch, current_frame->stride());
- const int width_in_bytes = map_info.RowPitch;
+
+ const int width_in_bytes =
+ current_frame->size().width() * DesktopFrame::kBytesPerPixel;
+ RTC_DCHECK_GE(current_frame->stride(), width_in_bytes);
+ RTC_DCHECK_GE(map_info.RowPitch, width_in_bytes);
const int middle_pixel_offset =
(image_width / 2) * DesktopFrame::kBytesPerPixel;
for (int i = 0; i < image_height; i++) {
@@ -466,10 +469,10 @@
uint8_t* current_pixel = dst_data + middle_pixel_offset;
frame_content_has_changed =
memcmp(previous_pixel, current_pixel, DesktopFrame::kBytesPerPixel);
- prev_data += width_in_bytes;
+ prev_data += current_frame->stride();
}
- dst_data += width_in_bytes;
- src_data += width_in_bytes;
+ dst_data += current_frame->stride();
+ src_data += map_info.RowPitch;
}
d3d_context->Unmap(mapped_texture_.Get(), 0);