Fix for QTMOBILITY-1772 VideoWidget example crash on windows
authorLing Hu <ling.hu@nokia.com>
Tue, 19 Jul 2011 00:50:41 +0000 (10:50 +1000)
committerQt by Nokia <qt-info@nokia.com>
Mon, 25 Jul 2011 05:09:35 +0000 (07:09 +0200)
The surface format stride calculation in directshow backend is wrong which results in memory access violation.

Change-Id: I80da5affc9a727513bad9c8d74a9f49d0c1a6c0d
Task-number:QTMOBILITY-1772
Reviewed-by:Michael Goddard
(cherry picked from commit 0b010e781634d3b33750fcead445fc7bd3a6f828)
Reviewed-on: http://codereview.qt.nokia.com/2070
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
src/plugins/directshow/player/directshowmediatype.cpp

index 9e65dc44e252c68fe6b8410e561c8260532de651..ab901c54751fa0ba29ade9818d9d628693757e11 100644 (file)
@@ -153,6 +153,7 @@ QVideoSurfaceFormat DirectShowMediaType::formatFromType(const AM_MEDIA_TYPE &typ
     return QVideoSurfaceFormat();
 }
 
+#define PAD_TO_DWORD(x)  (((x) + 3) & ~3)
 int DirectShowMediaType::bytesPerLine(const QVideoSurfaceFormat &format)
 {
     switch (format.pixelFormat()) {
@@ -162,13 +163,13 @@ int DirectShowMediaType::bytesPerLine(const QVideoSurfaceFormat &format)
         return format.frameWidth() * 4;
     // 24 bpp packed formats.
     case QVideoFrame::Format_RGB24:
-        return format.frameWidth() * 3 + 3 - format.frameWidth() % 4;
+        return PAD_TO_DWORD(format.frameWidth() * 3);
     // 16 bpp packed formats.
     case QVideoFrame::Format_RGB565:
     case QVideoFrame::Format_RGB555:
     case QVideoFrame::Format_YUYV:
     case QVideoFrame::Format_UYVY:
-        return format.frameWidth() * 2 + 3 - format.frameWidth() % 4;
+        return PAD_TO_DWORD(format.frameWidth() * 2);
     // Planar formats.
     case QVideoFrame::Format_IMC1:
     case QVideoFrame::Format_IMC2:
@@ -177,7 +178,7 @@ int DirectShowMediaType::bytesPerLine(const QVideoSurfaceFormat &format)
     case QVideoFrame::Format_YV12:
     case QVideoFrame::Format_NV12:
     case QVideoFrame::Format_YUV420P:
-        return format.frameWidth() + 3 - format.frameWidth() % 4;
+        return PAD_TO_DWORD(format.frameWidth());
     default:
         return 0;
     }