/// <summary> /// Resize video /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> public int ResizeVideo(short width, short height) { TRACE(string.Format("ResizeVideo: {0}x{1}", width, height)); int hr = S_Ok; if (m_pVideoDisplay != null) { try { MFRect rcDest = new MFRect(); MFVideoNormalizedRect nRect = new MFVideoNormalizedRect(); nRect.left = 0; nRect.right = 1; nRect.top = 0; nRect.bottom = 1; rcDest.left = 0; rcDest.top = 0; rcDest.right = width; rcDest.bottom = height; m_pVideoDisplay.SetVideoPosition(nRect, rcDest); } catch (Exception e) { hr = Marshal.GetHRForException(e); } } return(hr); }
public HResult ResizeVideo(short width, short height) { HResult hr = HResult.S_OK; TRACE(string.Format("ResizeVideo: {0}x{1}", width, height)); if (m_pVideoDisplay != null) { try { MFRect rcDest = new MFRect(); MFVideoNormalizedRect nRect = new MFVideoNormalizedRect(); nRect.left = 0; nRect.right = 1; nRect.top = 0; nRect.bottom = 1; rcDest.left = 0; rcDest.top = 0; rcDest.right = width; rcDest.bottom = height; hr = m_pVideoDisplay.SetVideoPosition(nRect, rcDest); MFError.ThrowExceptionForHR(hr); } catch (Exception ce) { hr = (HResult)Marshal.GetHRForException(ce); } } return(hr); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Handle size changed events on this control /// </summary> /// <param name="errMsg">the error message</param> /// <param name="ex">the exception. Can be null</param> /// <history> /// 01 Nov 18 Cynic - Originally Written /// </history> private void ctlTantaEVRStreamDisplay_SizeChanged(object sender, EventArgs e) { LogMessage("ctlTantaEVRStreamDisplay_SizeChanged"); HResult hr; if (evrVideoDisplay == null) { return; } try { // we are going to use the size changed event to reset the size of the video on the display. // This is controlled by two windows. // The source window determines which portion of the video is displayed. It is specified in // normalized coordinates. In other words, a value between 0 and 1. To display the entire video // image we would set the source rectangle to { 0, 0, 1, 1}. To display the bottom right quarter // we would set it to { 0.75f, 0.75f, 1, 1}. The default source rectangle is { 0, 0, 1, 1}. // The destination rectangle defines a rectangle within the clipping window (the video surface) where the video appears. // in this control this is the surface of a child panel control. This values is specified in pixels, relative to // the client area of the control. To fill the entire control, set the destination rectangle to { 0, 0, width, height}, // where width and height are dimensions of the window client area. MFRect destinationRect = new MFRect(); MFVideoNormalizedRect sourceRect = new MFVideoNormalizedRect(); // populate a MFVideoNormalizedRect structure that specifies the source rectangle. // This parameter can be NULL. If this parameter is NULL, the source rectangle does not change. sourceRect.left = 0; sourceRect.right = 1; sourceRect.top = 0; sourceRect.bottom = 1; // populate the destination rectangle. This parameter can be NULL. If this parameter is NULL, // the destination rectangle does not change. destinationRect.left = 0; destinationRect.top = 0; destinationRect.right = panelDisplayPanel.Width; destinationRect.bottom = panelDisplayPanel.Height; // now set the video display coordinates hr = evrVideoDisplay.SetVideoPosition(sourceRect, destinationRect); if (hr != HResult.S_OK) { throw new Exception("ctlTantaEVRStreamDisplay_SizeChanged failed. Err=" + hr.ToString()); } } catch (Exception ex) { LogMessage("ctlTantaEVRStreamDisplay_SizeChanged failed exception happened. ex=" + ex.Message); // NotifyPlayerErrored(ex.Message, ex); } }
public EVR() { _renderer = Renderer.EVR; _rcSrc = new MFVideoNormalizedRect(); _rcSrc.left = _rcSrc.top = 0.0f; _rcSrc.right = _rcSrc.bottom = 1.0f; _rcDest = new GDI.RECT(); _rcDest.left = _rcDest.top = 0; }
public EVRRenderer(IPvpPresenterHook pvpPresenterHook) { _pvpPresenterHook = pvpPresenterHook; _renderer = MediaEngine.Renderer.EVR; _rcSrc = new MFVideoNormalizedRect { left = _rcSrc.top = 0.0f, right = _rcSrc.bottom = 1.0f }; _rcDest = new GDI.RECT { left = _rcDest.top = 0 }; }
void VideoInternalWindow_Resize(object sender, EventArgs e) { int top = 0; int left = 0; int width = this.Width; int height = this.Height; if (_detachedWindow != null) { top = _detachedWindow.ClientRectangle.Top; left = _detachedWindow.ClientRectangle.Left; width = _detachedWindow.ClientRectangle.Width; height = _detachedWindow.ClientRectangle.Height; } if (_isInit) { if (_vw != null) { _vw.SetWindowPosition(top, left, width, height); } else if (_evr != null & !_delayedInit) { try { MFRect rcDest = new MFRect(); MFVideoNormalizedRect nRect = new MFVideoNormalizedRect(); nRect.left = 0; nRect.right = 1; nRect.top = 0; nRect.bottom = 1; rcDest.left = top; rcDest.top = left; rcDest.right = width; rcDest.bottom = height; _evr.SetVideoPosition(nRect, rcDest); } catch (Exception ex) { #if DEBUG MessageBox.Show(ex.Message, "Failed to set EVR Window Position"); #endif } } } }
public void SetScale(float fScale) { if (m_ImageHandlers == null || m_ImageHandlers.Length < 2) { return; } if (fScale < 0 || fScale > 1.0) { throw new COMException("Invalid scale", E_InvalidArgument); } if (fScale == m_fScale) { return; // no-op } if (m_pMixer == null) { throw new COMException("No mixer", E_InvalidArgument); } // Get the current position of the substream rectangle. MFVideoNormalizedRect rect = new MFVideoNormalizedRect(); m_pMixer.GetStreamOutputRect(1, rect); // When this method is called, the substream might be positioned anywhere // within the composition rectangle. To resize it, first we scale the // right/bottom edges up to the maximum, and then scale the left/top edges. rect.right = Math.Min(rect.left + fScale, 1.0f); rect.bottom = Math.Min(rect.top + fScale, 1.0f); rect.left -= Math.Max(fScale - (rect.right - rect.left), 0.0f); rect.top -= Math.Max(fScale - (rect.bottom - rect.top), 0.0f); // Set the new position. m_pMixer.SetStreamOutputRect(1, rect); m_fScale = fScale; }
public void Track(Point pt) { if (m_pMixer == null || m_pMapper == null) { throw new COMException("null mixer or mapper", MFError.MF_E_INVALIDREQUEST); } Rectangle r = m_hwndVideo.ClientRectangle; MFRect rc = new MFRect(r.Left, r.Top, r.Right, r.Bottom); // x, y: Mouse coordinates, normalized relative to the composition rectangle. float x = (float)pt.X / rc.right; float y = (float)pt.Y / rc.bottom; // Map the mouse coordinates to the reference stream. m_pMapper.MapOutputCoordinateToInputStream( x, y, // Output coordinates 0, // Output stream (the mixer only has one) 0, // Input stream (0 = ref stream) out x, out y // Receives the normalized input coordinates. ); // Offset by the original hit point. x -= m_ptHitTrack.X; y -= m_ptHitTrack.Y; float max_offset = 1.0f - m_fScale; // Maximum left and top positions for the substream. MFVideoNormalizedRect nrcDest = new MFVideoNormalizedRect(); if (x < 0) { nrcDest.left = 0; nrcDest.right = m_fScale; } else if (x > max_offset) { nrcDest.right = 1; nrcDest.left = max_offset; } else { nrcDest.left = x; nrcDest.right = x + m_fScale; } if (y < 0) { nrcDest.top = 0; nrcDest.bottom = m_fScale; } else if (y > max_offset) { nrcDest.bottom = 1; nrcDest.top = max_offset; } else { nrcDest.top = y; nrcDest.bottom = y + m_fScale; } // Set the new position. m_pMixer.SetStreamOutputRect(1, nrcDest); }