I have used directshow.net now two years and I am really happy with it. Thanks
for developers.
Now I have problem to change my video window size in while running graph. I
have form panel that size i change while running. Wideo size does not change.
When I use ivideowindow mode, it works by calling configure ivideowindow. But
I need Windowless mode. Is it possible to change window size while graph
running?
Code
private void ConfigureVMR9InWindowlessMode()
{
int hr = 0;
// Set "Parent" window
hr = windowlessCtrl.SetVideoClippingWindow(this.vikkuna1.Handle);
DsError.ThrowExceptionForHR(hr);
// Set Aspect-Ratio
hr = windowlessCtrl.SetAspectRatioMode(VMR9AspectRatioMode.None);
DsError.ThrowExceptionForHR(hr);
// Add delegates for Windowless operations
AddHandlers();
// Call the resize handler to configure the output size
MainForm_ResizeMove(null, null);
}
private void AddHandlers()
{
// Add handlers for VMR purpose
this.vikkuna1.Paint += new PaintEventHandler(MainForm_Paint); // for WM_PAINT
this.vikkuna1.Resize += new EventHandler(MainForm_ResizeMove); // for WM_SIZE
this.vikkuna1.Move += new EventHandler(MainForm_ResizeMove); // for WM_MOVE
SystemEvents.DisplaySettingsChanged += new
EventHandler(SystemEvents_DisplaySettingsChanged); // for WM_DISPLAYCHANGE
}
private void MainForm_Paint(object sender, PaintEventArgs e)
{
if (windowlessCtrl != null)
{
IntPtr hdc = e.Graphics.GetHdc();
int hr = windowlessCtrl.RepaintVideo(this.vikkuna1.Handle, hdc);
e.Graphics.ReleaseHdc(hdc);
}
}
private void MainForm_ResizeMove(object sender, EventArgs e)
{
if (windowlessCtrl != null)
{
int hr = windowlessCtrl.SetVideoPosition(null,
DsRect.FromRectangle(this.vikkuna1.ClientRectangle));
}
}
private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
{
if (windowlessCtrl != null)
{
int hr = windowlessCtrl.DisplayModeChanged();
}
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Rectangle rc = new Rectangle(0, 0, vikkunamain.Width, vikkunamain.Height);
int hr = windowlessCtrl.SetVideoPosition(null, rc);
in running but I get error message:
"
An unhandled exception of type
'System.Runtime.InteropServices.InvalidComObjectException' occurred in
video.exe
Additional information: COM object that has been separated from its underlying
RCW cannot be used.
"
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Then you have released something you still need.
I don't know much about C#, I use VB, so I didn't have a closer look at your
code.
The windowlessCtrl must have been released or something upon which it depends.
Peter
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The "underlying RCW cannot be used" error can also be linked to a
STA problem. In STA threading model, when you create a COM object in a thead
A, it can't be use in a thread B.
There is many topics in this forum that address this problem. Try a search
with STAThread or MTAThread...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have used directshow.net now two years and I am really happy with it. Thanks
for developers.
Now I have problem to change my video window size in while running graph. I
have form panel that size i change while running. Wideo size does not change.
When I use ivideowindow mode, it works by calling configure ivideowindow. But
I need Windowless mode. Is it possible to change window size while graph
running?
Code
private void ConfigureVMR9InWindowlessMode()
{
int hr = 0;
IVMRFilterConfig9 filterConfig = (IVMRFilterConfig9)vmr9prev;
// Not really needed for VMR9 but don't forget calling it with VMR7
hr = filterConfig.SetNumberOfStreams(1);
DsError.ThrowExceptionForHR(hr);
// Change VMR9 mode to Windowless
hr = filterConfig.SetRenderingMode(VMR9Mode.Windowless);
DsError.ThrowExceptionForHR(hr);
windowlessCtrl = (IVMRWindowlessControl9)vmr9prev;
// Set "Parent" window
hr = windowlessCtrl.SetVideoClippingWindow(this.vikkuna1.Handle);
DsError.ThrowExceptionForHR(hr);
// Set Aspect-Ratio
hr = windowlessCtrl.SetAspectRatioMode(VMR9AspectRatioMode.None);
DsError.ThrowExceptionForHR(hr);
// Add delegates for Windowless operations
AddHandlers();
// Call the resize handler to configure the output size
MainForm_ResizeMove(null, null);
}
private void AddHandlers()
{
// Add handlers for VMR purpose
this.vikkuna1.Paint += new PaintEventHandler(MainForm_Paint); // for WM_PAINT
this.vikkuna1.Resize += new EventHandler(MainForm_ResizeMove); // for WM_SIZE
this.vikkuna1.Move += new EventHandler(MainForm_ResizeMove); // for WM_MOVE
SystemEvents.DisplaySettingsChanged += new
EventHandler(SystemEvents_DisplaySettingsChanged); // for WM_DISPLAYCHANGE
}
private void MainForm_Paint(object sender, PaintEventArgs e)
{
if (windowlessCtrl != null)
{
IntPtr hdc = e.Graphics.GetHdc();
int hr = windowlessCtrl.RepaintVideo(this.vikkuna1.Handle, hdc);
e.Graphics.ReleaseHdc(hdc);
}
}
private void MainForm_ResizeMove(object sender, EventArgs e)
{
if (windowlessCtrl != null)
{
int hr = windowlessCtrl.SetVideoPosition(null,
DsRect.FromRectangle(this.vikkuna1.ClientRectangle));
}
}
private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
{
if (windowlessCtrl != null)
{
int hr = windowlessCtrl.DisplayModeChanged();
}
}
You have to change the size yourself with SetVideoPosition.
From the BitmapMixer sample:
private void MainForm_ResizeMove(object sender, EventArgs e)
{
if (windowlessCtrl != null)
{
int hr = windowlessCtrl.SetVideoPosition(null,
DsRect.FromRectangle(this.ClientRectangle));
}
}
Peter
Thanks Peter,
Actually I have tryed that
code:
Rectangle rc = new Rectangle(0, 0, vikkunamain.Width, vikkunamain.Height);
int hr = windowlessCtrl.SetVideoPosition(null, rc);
in running but I get error message:
"
An unhandled exception of type
'System.Runtime.InteropServices.InvalidComObjectException' occurred in
video.exe
Additional information: COM object that has been separated from its underlying
RCW cannot be used.
"
Then you have released something you still need.
I don't know much about C#, I use VB, so I didn't have a closer look at your
code.
The windowlessCtrl must have been released or something upon which it depends.
Peter
The "underlying RCW cannot be used" error can also be linked to a
STA problem. In STA threading model, when you create a COM object in a thead
A, it can't be use in a thread B.
There is many topics in this forum that address this problem. Try a search
with STAThread or MTAThread...
Thanks Peter and Nowinskie. Problek solved.
Reason for error was VMR releasing before
hr = windowlessCtrl.SetVideoPosition
call.