Mission planner: Added feature to select video capture resolution (Allows to

capture PAL-format video)
This commit is contained in:
Janne Mantyharju 2011-10-07 11:43:11 +03:00
parent 9e5f175e95
commit 05ee33d9ad
5 changed files with 1570 additions and 687 deletions

View File

@ -61,25 +61,43 @@ namespace WebCamService
#endregion
/// <summary> Use capture device zero, default frame rate and size</summary>
public Capture()
{
//_Capture(0, 0, 0, 0);
}
/// <summary> Use specified capture device, default frame rate and size</summary>
public Capture(int iDeviceNum)
/// <summary> Use capture with selected media caps</summary>
public Capture(int iDeviceNum, AMMediaType media)
{
_Capture(iDeviceNum, 0, 0, 0);
}
/// <summary> Use specified capture device, specified frame rate and default size</summary>
public Capture(int iDeviceNum, int iFrameRate)
{
_Capture(iDeviceNum, iFrameRate, 0, 0);
}
/// <summary> Use specified capture device, specified frame rate and size</summary>
public Capture(int iDeviceNum, int iFrameRate, int iWidth, int iHeight)
{
_Capture(iDeviceNum, iFrameRate, iWidth, iHeight);
DsDevice[] capDevices;
// Get the collection of video devices
capDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
if (iDeviceNum + 1 > capDevices.Length)
{
throw new Exception("No video capture devices found at that index!");
}
try
{
// Set up the capture graph
SetupGraph(capDevices[iDeviceNum], media);
// tell the callback to ignore new images
m_PictureReady = new ManualResetEvent(false);
m_bGotOne = true;
m_bRunning = false;
timer1.Interval = 1000 / 15; // 15 fps
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();
}
catch
{
Dispose();
throw;
}
}
/// <summary> release everything. </summary>
public void Dispose()
@ -195,41 +213,6 @@ namespace WebCamService
return list;
}
// Internal capture
private void _Capture(int iDeviceNum, int iFrameRate, int iWidth, int iHeight)
{
DsDevice[] capDevices;
// Get the collection of video devices
capDevices = DsDevice.GetDevicesOfCat( FilterCategory.VideoInputDevice );
if (iDeviceNum + 1 > capDevices.Length)
{
throw new Exception("No video capture devices found at that index!");
}
try
{
// Set up the capture graph
SetupGraph( capDevices[iDeviceNum], iFrameRate, iWidth, iHeight);
// tell the callback to ignore new images
m_PictureReady = new ManualResetEvent(false);
m_bGotOne = true;
m_bRunning = false;
timer1.Interval = 1000 / 15; // 15 fps
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();
}
catch
{
Dispose();
throw;
}
}
public bool showhud = true;
void timer1_Tick(object sender, EventArgs e)
@ -248,7 +231,7 @@ namespace WebCamService
}
/// <summary> build the capture graph for grabber. </summary>
private void SetupGraph(DsDevice dev, int iFrameRate, int iWidth, int iHeight)
private void SetupGraph(DsDevice dev, AMMediaType media)
{
int hr;
@ -328,11 +311,7 @@ namespace WebCamService
hr = m_FilterGraph.AddFilter( baseGrabFlt, "Ds.NET Grabber" );
DsError.ThrowExceptionForHR( hr );
// If any of the default config items are set
if (iFrameRate + iHeight + iWidth > 0)
{
SetConfigParms(capGraph, capFilter, iFrameRate, iWidth, iHeight);
}
SetConfigParms(capGraph, capFilter, media);
hr = capGraph.RenderStream(PinCategory.Capture, MediaType.Video, capFilter, pAVIDecompressor, baseGrabFlt);
if (hr < 0)
@ -409,11 +388,10 @@ namespace WebCamService
}
// Set the Framerate, and video size
private void SetConfigParms(ICaptureGraphBuilder2 capGraph, IBaseFilter capFilter, int iFrameRate, int iWidth, int iHeight)
private void SetConfigParms(ICaptureGraphBuilder2 capGraph, IBaseFilter capFilter, AMMediaType media)
{
int hr;
object o;
AMMediaType media;
// Find the stream config interface
hr = capGraph.FindInterface(
@ -423,36 +401,7 @@ namespace WebCamService
if (videoStreamConfig == null)
{
throw new Exception("Failed to get IAMStreamConfig");
}
// Get the existing format block
hr = videoStreamConfig.GetFormat( out media);
DsError.ThrowExceptionForHR( hr );
// copy out the videoinfoheader
VideoInfoHeader v = new VideoInfoHeader();
Marshal.PtrToStructure( media.formatPtr, v );
// if overriding the framerate, set the frame rate
if (iFrameRate > 0)
{
v.AvgTimePerFrame = 10000000 / iFrameRate;
}
// if overriding the width, set the width
if (iWidth > 0)
{
v.BmiHeader.Width = iWidth;
}
// if overriding the Height, set the Height
if (iHeight > 0)
{
v.BmiHeader.Height = iHeight;
}
// Copy the media structure back
Marshal.StructureToPtr( v, media.formatPtr, false );
}
// Set the new format
hr = videoStreamConfig.SetFormat( media );

View File

@ -141,6 +141,12 @@
this.RLL2SRV_P = new System.Windows.Forms.DomainUpDown();
this.label52 = new System.Windows.Forms.Label();
this.TabAC2 = new System.Windows.Forms.TabPage();
this.groupBox5 = new System.Windows.Forms.GroupBox();
this.THR_RATE_IMAX = new System.Windows.Forms.DomainUpDown();
this.THR_RATE_I = new System.Windows.Forms.DomainUpDown();
this.label20 = new System.Windows.Forms.Label();
this.THR_RATE_P = new System.Windows.Forms.DomainUpDown();
this.label25 = new System.Windows.Forms.Label();
this.CHK_lockrollpitch = new System.Windows.Forms.CheckBox();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.WP_SPEED_MAX = new System.Windows.Forms.DomainUpDown();
@ -217,6 +223,7 @@
this.RATE_RLL_P = new System.Windows.Forms.DomainUpDown();
this.label91 = new System.Windows.Forms.Label();
this.TabPlanner = new System.Windows.Forms.TabPage();
this.CMB_videoresolutions = new System.Windows.Forms.ComboBox();
this.label12 = new System.Windows.Forms.Label();
this.CHK_GDIPlus = new System.Windows.Forms.CheckBox();
this.label24 = new System.Windows.Forms.Label();
@ -259,19 +266,15 @@
this.BUT_videostop = new ArdupilotMega.MyButton();
this.BUT_videostart = new ArdupilotMega.MyButton();
this.TabSetup = new System.Windows.Forms.TabPage();
this.label109 = new System.Windows.Forms.Label();
this.BUT_rerequestparams = new ArdupilotMega.MyButton();
this.BUT_writePIDS = new ArdupilotMega.MyButton();
this.BUT_save = new ArdupilotMega.MyButton();
this.BUT_load = new ArdupilotMega.MyButton();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.BUT_compare = new ArdupilotMega.MyButton();
this.groupBox5 = new System.Windows.Forms.GroupBox();
this.THR_RATE_IMAX = new System.Windows.Forms.DomainUpDown();
this.label14 = new System.Windows.Forms.Label();
this.THR_RATE_I = new System.Windows.Forms.DomainUpDown();
this.label20 = new System.Windows.Forms.Label();
this.THR_RATE_P = new System.Windows.Forms.DomainUpDown();
this.label25 = new System.Windows.Forms.Label();
this.label26 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.Params)).BeginInit();
this.ConfigTabs.SuspendLayout();
this.TabAPM2.SuspendLayout();
@ -288,6 +291,7 @@
this.groupBox9.SuspendLayout();
this.groupBox8.SuspendLayout();
this.TabAC2.SuspendLayout();
this.groupBox5.SuspendLayout();
this.groupBox4.SuspendLayout();
this.groupBox6.SuspendLayout();
this.groupBox7.SuspendLayout();
@ -300,7 +304,6 @@
this.groupBox25.SuspendLayout();
this.TabPlanner.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.NUM_tracklength)).BeginInit();
this.groupBox5.SuspendLayout();
this.SuspendLayout();
//
// Params
@ -1007,6 +1010,43 @@
resources.ApplyResources(this.TabAC2, "TabAC2");
this.TabAC2.Name = "TabAC2";
//
// groupBox5
//
this.groupBox5.Controls.Add(this.label14);
this.groupBox5.Controls.Add(this.THR_RATE_IMAX);
this.groupBox5.Controls.Add(this.THR_RATE_I);
this.groupBox5.Controls.Add(this.label20);
this.groupBox5.Controls.Add(this.THR_RATE_P);
this.groupBox5.Controls.Add(this.label25);
resources.ApplyResources(this.groupBox5, "groupBox5");
this.groupBox5.Name = "groupBox5";
this.groupBox5.TabStop = false;
//
// THR_RATE_IMAX
//
resources.ApplyResources(this.THR_RATE_IMAX, "THR_RATE_IMAX");
this.THR_RATE_IMAX.Name = "THR_RATE_IMAX";
//
// THR_RATE_I
//
resources.ApplyResources(this.THR_RATE_I, "THR_RATE_I");
this.THR_RATE_I.Name = "THR_RATE_I";
//
// label20
//
resources.ApplyResources(this.label20, "label20");
this.label20.Name = "label20";
//
// THR_RATE_P
//
resources.ApplyResources(this.THR_RATE_P, "THR_RATE_P");
this.THR_RATE_P.Name = "THR_RATE_P";
//
// label25
//
resources.ApplyResources(this.label25, "label25");
this.label25.Name = "label25";
//
// CHK_lockrollpitch
//
resources.ApplyResources(this.CHK_lockrollpitch, "CHK_lockrollpitch");
@ -1459,6 +1499,8 @@
//
// TabPlanner
//
this.TabPlanner.Controls.Add(this.label26);
this.TabPlanner.Controls.Add(this.CMB_videoresolutions);
this.TabPlanner.Controls.Add(this.label12);
this.TabPlanner.Controls.Add(this.CHK_GDIPlus);
this.TabPlanner.Controls.Add(this.label24);
@ -1503,6 +1545,13 @@
resources.ApplyResources(this.TabPlanner, "TabPlanner");
this.TabPlanner.Name = "TabPlanner";
//
// CMB_videoresolutions
//
this.CMB_videoresolutions.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CMB_videoresolutions.FormattingEnabled = true;
resources.ApplyResources(this.CMB_videoresolutions, "CMB_videoresolutions");
this.CMB_videoresolutions.Name = "CMB_videoresolutions";
//
// label12
//
resources.ApplyResources(this.label12, "label12");
@ -1788,6 +1837,7 @@
this.CMB_videosources.FormattingEnabled = true;
resources.ApplyResources(this.CMB_videosources, "CMB_videosources");
this.CMB_videosources.Name = "CMB_videosources";
this.CMB_videosources.SelectedIndexChanged += new System.EventHandler(this.CMB_videosources_SelectedIndexChanged);
this.CMB_videosources.MouseClick += new System.Windows.Forms.MouseEventHandler(this.CMB_videosources_MouseClick);
//
// BUT_Joystick
@ -1817,6 +1867,11 @@
this.TabSetup.Name = "TabSetup";
this.TabSetup.UseVisualStyleBackColor = true;
//
// label109
//
resources.ApplyResources(this.label109, "label109");
this.label109.Name = "label109";
//
// BUT_rerequestparams
//
resources.ApplyResources(this.BUT_rerequestparams, "BUT_rerequestparams");
@ -1856,47 +1911,15 @@
this.BUT_compare.UseVisualStyleBackColor = true;
this.BUT_compare.Click += new System.EventHandler(this.BUT_compare_Click);
//
// groupBox5
//
this.groupBox5.Controls.Add(this.THR_RATE_IMAX);
this.groupBox5.Controls.Add(this.label14);
this.groupBox5.Controls.Add(this.THR_RATE_I);
this.groupBox5.Controls.Add(this.label20);
this.groupBox5.Controls.Add(this.THR_RATE_P);
this.groupBox5.Controls.Add(this.label25);
resources.ApplyResources(this.groupBox5, "groupBox5");
this.groupBox5.Name = "groupBox5";
this.groupBox5.TabStop = false;
//
// THR_RATE_IMAX
//
resources.ApplyResources(this.THR_RATE_IMAX, "THR_RATE_IMAX");
this.THR_RATE_IMAX.Name = "THR_RATE_IMAX";
//
// label14
//
resources.ApplyResources(this.label14, "label14");
this.label14.Name = "label14";
//
// THR_RATE_I
// label26
//
resources.ApplyResources(this.THR_RATE_I, "THR_RATE_I");
this.THR_RATE_I.Name = "THR_RATE_I";
//
// label20
//
resources.ApplyResources(this.label20, "label20");
this.label20.Name = "label20";
//
// THR_RATE_P
//
resources.ApplyResources(this.THR_RATE_P, "THR_RATE_P");
this.THR_RATE_P.Name = "THR_RATE_P";
//
// label25
//
resources.ApplyResources(this.label25, "label25");
this.label25.Name = "label25";
resources.ApplyResources(this.label26, "label26");
this.label26.Name = "label26";
//
// Configuration
//
@ -1929,6 +1952,7 @@
this.groupBox8.ResumeLayout(false);
this.TabAC2.ResumeLayout(false);
this.TabAC2.PerformLayout();
this.groupBox5.ResumeLayout(false);
this.groupBox4.ResumeLayout(false);
this.groupBox6.ResumeLayout(false);
this.groupBox7.ResumeLayout(false);
@ -1941,7 +1965,6 @@
this.groupBox25.ResumeLayout(false);
this.TabPlanner.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.NUM_tracklength)).EndInit();
this.groupBox5.ResumeLayout(false);
this.ResumeLayout(false);
}
@ -2183,10 +2206,13 @@
private System.Windows.Forms.CheckBox CHK_GDIPlus;
private System.Windows.Forms.GroupBox groupBox5;
private System.Windows.Forms.DomainUpDown THR_RATE_IMAX;
private System.Windows.Forms.Label label14;
private System.Windows.Forms.DomainUpDown THR_RATE_I;
private System.Windows.Forms.Label label20;
private System.Windows.Forms.DomainUpDown THR_RATE_P;
private System.Windows.Forms.Label label25;
private System.Windows.Forms.ComboBox CMB_videoresolutions;
private System.Windows.Forms.Label label109;
private System.Windows.Forms.Label label14;
private System.Windows.Forms.Label label26;
}
}

View File

@ -11,6 +11,8 @@ using System.Text.RegularExpressions;
using System.Collections;
using System.Globalization;
using System.Threading;
using DirectShowLib;
using System.Runtime.InteropServices;
namespace ArdupilotMega.GCSViews
{
@ -22,6 +24,29 @@ namespace ArdupilotMega.GCSViews
internal bool startup = true;
List<CultureInfo> languages = new List<CultureInfo>();
public class GCSBitmapInfo
{
public int Width { get; set; }
public int Height { get; set; }
public long Fps { get; set; }
public string Standard { get; set; }
public AMMediaType Media { get; set; }
public GCSBitmapInfo(int width, int height, long fps, string standard, AMMediaType media)
{
Width = width;
Height = height;
Fps = fps;
Standard = standard;
Media = media;
}
public override string ToString()
{
return Width.ToString() + " x " + Height.ToString() + String.Format(" {0:0.00} fps ", 10000000.0 / Fps) + Standard;
}
}
public struct paramsettings // hk's
{
public string name;
@ -202,6 +227,7 @@ namespace ArdupilotMega.GCSViews
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Configuration));
string data = resources.GetString("MAVParam");
string[] tips = data.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var tip in tips)
@ -630,9 +656,11 @@ namespace ArdupilotMega.GCSViews
// stop first
BUT_videostop_Click(sender, e);
GCSBitmapInfo bmp = (GCSBitmapInfo)CMB_videoresolutions.SelectedItem;
try
{
MainV2.cam = new WebCamService.Capture(CMB_videosources.SelectedIndex, 0, 0, 0);
MainV2.cam = new WebCamService.Capture(CMB_videosources.SelectedIndex, bmp.Media);
MainV2.cam.showhud = CHK_hudshow.Checked;
@ -666,6 +694,58 @@ namespace ArdupilotMega.GCSViews
capt.Dispose();
}
private void CMB_videosources_SelectedIndexChanged(object sender, EventArgs e)
{
int hr;
int count;
int size;
object o;
IBaseFilter capFilter = null;
ICaptureGraphBuilder2 capGraph = null;
AMMediaType media = null;
VideoInfoHeader v;
VideoStreamConfigCaps c;
List<GCSBitmapInfo> modes = new List<GCSBitmapInfo>();
// Get the ICaptureGraphBuilder2
capGraph = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
IFilterGraph2 m_FilterGraph = (IFilterGraph2)new FilterGraph();
DsDevice[] capDevices;
capDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
// Add the video device
hr = m_FilterGraph.AddSourceFilterForMoniker(capDevices[CMB_videosources.SelectedIndex].Mon, null, "Video input", out capFilter);
DsError.ThrowExceptionForHR(hr);
// Find the stream config interface
hr = capGraph.FindInterface(PinCategory.Capture, MediaType.Video, capFilter, typeof(IAMStreamConfig).GUID, out o);
DsError.ThrowExceptionForHR(hr);
IAMStreamConfig videoStreamConfig = o as IAMStreamConfig;
if (videoStreamConfig == null)
{
throw new Exception("Failed to get IAMStreamConfig");
}
hr = videoStreamConfig.GetNumberOfCapabilities(out count, out size);
DsError.ThrowExceptionForHR(hr);
IntPtr TaskMemPointer = Marshal.AllocCoTaskMem(size);
for (int i = 0; i < count; i++)
{
IntPtr ptr = IntPtr.Zero;
hr = videoStreamConfig.GetStreamCaps(i, out media, TaskMemPointer);
v = (VideoInfoHeader)Marshal.PtrToStructure(media.formatPtr, typeof(VideoInfoHeader));
c = (VideoStreamConfigCaps)Marshal.PtrToStructure(TaskMemPointer, typeof(VideoStreamConfigCaps));
modes.Add(new GCSBitmapInfo(v.BmiHeader.Width, v.BmiHeader.Height, c.MaxFrameInterval, c.VideoStandard.ToString(), media));
}
Marshal.FreeCoTaskMem(TaskMemPointer);
DsUtils.FreeAMMediaType(media);
CMB_videoresolutions.DataSource = modes;
}
private void CHK_hudshow_CheckedChanged(object sender, EventArgs e)
{
GCSViews.FlightData.myhud.hudon = CHK_hudshow.Checked;

File diff suppressed because it is too large Load Diff