public virtual void VideoResizer(VideoSizeMode videoZoomMode, bool keepAspectRatio, PointF offset, double zoom, double aspectRatioFactor)
{
Trace.WriteLineIf(trace.TraceInfo, "VideoResizer(...)");
int hr = 0;
Rectangle windowRect = this.hostingControl.ClientRectangle;
currentVideoTargetRectangle = windowRect;
currentVideoSourceSize = new Size();
FilterState filterState = GetGraphState();
if (filterState == FilterState.Paused || filterState == FilterState.Running)
{
if (videoZoomMode != VideoSizeMode.StretchToWindow)
{
int arX, arY;
int arX2 = 0, arY2 = 0;
if (useEVR)
{
Size videoSize = new Size(), arVideoSize = new Size();
hr = evrVideoDisplayControl.GetNativeVideoSize(out videoSize, out arVideoSize);
//IMFVideoDisplayControlEx evrVideoDisplayControlPlus = evrVideoDisplayControl as IMFVideoDisplayControlEx;
//hr = evrVideoDisplayControlPlus.GetNativeVideoSize(out videoSize, out arVideoSize);
//hr = evrVideoDisplayControlPlus.GetIdealVideoSize(videoSize, arVideoSize);
arX = videoSize.Width;
arY = videoSize.Height;
arX2 = arVideoSize.Width;
arY2 = arVideoSize.Height;
Trace.WriteLineIf(trace.TraceVerbose, string.Format(("\tvideoRenderer.GetNativeVideoSize({0}, {1})"), videoSize.ToString(), arVideoSize.ToString()));
}
else
hr = (this.videoRenderer as IVMRWindowlessControl9).GetNativeVideoSize(out arX, out arY, out arX2, out arY2);
if (hr >= 0 && arY > 0)
{
//DsError.ThrowExceptionForHR(hr);
//Trace.WriteLineIf(trace.TraceVerbose, string.Format("\tGetNativeVideoSize(width: {0}, height: {1}, arX {2}, arY: {3}", arX, arY, arX2, arY2));
if (arX2 > 0 && arY2 > 0)
{
arX = arX2;
arY = arY2;
}
currentVideoSourceSize.Width = arX;
currentVideoSourceSize.Height = arY;
Size windowSize = windowRect.Size;
double newAspectRation = aspectRatioFactor * (double)arX / (double)arY * (this.useVideo169Mode ? 3.0 / 4.0 : 1.0);
int height = windowSize.Height;
int width = (int)((double)height * newAspectRation);
if (videoZoomMode == VideoSizeMode.FromInside || videoZoomMode == VideoSizeMode.FromOutside)
{
if (videoZoomMode == VideoSizeMode.FromInside && width > windowSize.Width
|| videoZoomMode == VideoSizeMode.FromOutside && width < windowSize.Width)
{
width = windowSize.Width;
height = (int)((double)width / newAspectRation);
}
}
Size size = new Size((int)(zoom * width), (int)(zoom * height));
Point pos = new Point(
(int)(offset.X * (windowRect.Width * 3 - size.Width) - windowRect.Width),
(int)(offset.Y * (windowRect.Height * 3 - size.Height) - windowRect.Height));
//Point pos = new Point(
// (int)(offset.X * (windowRect.Width - size.Width)),
// (int)(offset.Y * (windowRect.Height - size.Height)));
currentVideoTargetRectangle = new Rectangle(pos, size);
}
}
if (useEVR)
{
//hr = evrVideoDisplayControl.SetVideoWindow(this.hostingControl.Handle);
MFVideoNormalizedRect pnrcSource = new MFVideoNormalizedRect(0.0f, 0.0f, 1.0f, 1.0f);
hr = this.evrVideoDisplayControl.SetVideoPosition(pnrcSource, (MediaFoundation.Misc.MFRect)currentVideoTargetRectangle);
this.hostingControl.ModifyBlackBands(GetBlackBands(), Settings.VideoBackgroundColor);
}
else
hr = (this.videoRenderer as IVMRWindowlessControl9).SetVideoPosition(null, DsRect.FromRectangle(currentVideoTargetRectangle));
//Trace.WriteLineIf(trace.TraceVerbose, string.Format(("\tPos {0:F2} {1:F2}, Zoom {2:F2}, ARF {4:F2}, AR {4:F2}"), offset.X, offset.Y, zoom, aspectRatioFactor, (float)videoTargetRect.Width / videoTargetRect.Height));
Trace.WriteLineIf(trace.TraceVerbose, string.Format(("\tvideoRenderer.SetVideoPosition({0})"), currentVideoTargetRectangle.ToString()));
}
}