123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- using DirectShow;
- using Sonic;
- using System;
- using System.Drawing;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- using VideoPlayLib.MadVR;
- namespace VideoPlayLib
- {
- internal class VideoInControl : BaseObject, IDisposable
- {
- private const int OaTrue = -1;
- private const int OaFalse = 0;
- private readonly Control _ctl;
- private readonly object _flt;
- private readonly Size _szOrignal;
- private readonly float _vdoRatio;
- private readonly IVideoWindow _ivw;
- private readonly IBasicVideo2 _ibv2;
- private readonly IMadVRInfo _imvr;
- public VideoInControl(DSFilter madVr, Control ctl, bool fitWindow = true)
- {
- _ctl = ctl;
- _flt = madVr.Value;
- _imvr = (IMadVRInfo)_flt;
- _ivw = (IVideoWindow)_flt;
- _ibv2 = (IBasicVideo2)_flt;
- _ivw.put_Owner(_ctl.Handle);
- _ivw.put_MessageDrain(_ctl.Handle);
- _ivw.put_FullScreenMode(OaFalse);
- _ivw.put_WindowStyle(0x40000000 | 0x4000000);
- CheckError(_imvr.GetSize("originalVideoSize", out _szOrignal));
-
- _vdoRatio = (float)_szOrignal.Width / _szOrignal.Height;
- if (fitWindow)
- {
- _ctl.ClientSize = _szOrignal;
- }
- ctl.Resize += EventHandler;
- EventHandler(null, null);
- }
- public VideoInControl(Graph graph, Control ctl)
- {
- _ctl = ctl;
- _flt = graph.Value;
- _ivw = (IVideoWindow)_flt;
- _ibv2 = (IBasicVideo2)_flt;
- _ivw.put_Owner(_ctl.Handle);
- _ivw.put_MessageDrain(_ctl.Handle);
- _ivw.put_FullScreenMode(OaFalse);
- _ivw.put_WindowStyle(0x40000000 | 0x4000000);
- ctl.Resize += EventHandler;
- EventHandler(null, null);
- }
- private void EventHandler(object sender, EventArgs e)
- {
- var ctl = sender as Control ?? _ctl;
- _ivw.SetWindowPosition(0, 0, ctl.ClientSize.Width, ctl.ClientSize.Height);
- if(_szOrignal==Size.Empty)
- return;
- int resultWidth, resultHeight, marginV, marginH;
-
- var ctlRatio = (float)ctl.ClientSize.Width / ctl.ClientSize.Height;
- if (_vdoRatio > ctlRatio)
- {
-
- resultWidth = ctl.ClientSize.Width;
- marginH = 0;
- resultHeight = (int)(((float)ctl.Width / _szOrignal.Width) * _szOrignal.Height);
- marginV = (ctl.ClientSize.Height - resultHeight) / 2;
- }
- else
- {
-
- resultHeight = ctl.ClientSize.Height;
- marginV = 0;
- resultWidth = (int)(((float)ctl.Height / _szOrignal.Height) * _szOrignal.Width);
- marginH = (ctl.ClientSize.Width - resultWidth) / 2;
- }
- _ibv2.SetDestinationPosition(marginH, marginV, resultWidth, resultHeight);
- }
- public void Dispose()
- {
- Marshal.ReleaseComObject(_ivw);
- Marshal.ReleaseComObject(_ibv2);
- Marshal.ReleaseComObject(_imvr);
- }
- }
- }
|