1
Vote

MediaPlayerBase::GetVideoSize() doesn't work with empty source rectangle

description

Code for getting video size looks like this:
      var videoInfo = new VideoInfoHeader();

        /* Read the video info header struct from the native pointer */
        Marshal.PtrToStructure(mediaType.formatPtr, videoInfo);

        Rectangle rect = videoInfo.SrcRect.ToRectangle();
        size = new Size(rect.Width, rect.Height);
The source/clipping rectangle can be empty, in which case GetVideoSize returns Size(0,0), even though a valid width/height can be found in the BITMAPINFOHEADER structure. See "Source and Target Rectangles in Video Renderers" (http://msdn.microsoft.com/en-us/library/windows/desktop/dd377618(v=vs.85).aspx).

Assuming that we do want GetVideoSize to return the clipping source rect when it is set, in my project I changed this to read:
        /* Read the video info header struct from the native pointer */
        Marshal.PtrToStructure(mediaType.formatPtr, videoInfo);

        Rectangle rect = videoInfo.SrcRect.ToRectangle();
        if (!rect.IsEmpty)
            size = new Size(rect.Width, rect.Height);
        else
            size = new Size(videoInfo.BmiHeader.Width, videoInfo.BmiHeader.Height);

comments