public override bool Build(DirectShowLib.IPin source, IBuild build) { bool result = false; if (Abstract.FindCaptureDeviceNameByIdentifier(this.device).NotNull()) { DirectShowLib.IBaseFilter filter = Abstract.FindCaptureDeviceByIdentifier(this.device, false); if (filter.NotNull() && this.SetFormat(filter)) { if (build.Graph.AddFilter(filter, "Capture") == 0) { foreach (Filters.Abstract candidate in this.Next) { if (result = candidate.Build(filter, 0, build)) { break; } } } else { Error.Log.Append(Error.Level.Debug, "Unable to open capture.", "DirectShow was unable to capture \"" + this.device + "\"."); Exception.GraphError.Check(build.Graph.RemoveFilter(filter)); } } } return(result); }
bool SetFormat(DirectShowLib.IBaseFilter filter) { bool result = false; Format.Image wanted = this.Media(filter); if (wanted.NotNull()) { if (wanted.Resolution.NotNull()) { DirectShowLib.AMMediaType[] media = this.GetOutputMediaTypes(filter); if (media.NotNull()) { for (int i = 0; i < media.Length; i++) { DirectShowLib.VideoInfoHeader header = Abstract.GetHeader(media[i]); if (media[i].subType == wanted.Type && header.BmiHeader.Width == wanted.Resolution.Width) { if (header.BmiHeader.Height == wanted.Resolution.Height) { this.SetOutputMedia(filter, media[i]); result = true; break; } else if (wanted.ForceHeight) { header.BmiHeader.Height = wanted.Resolution.Height; header.BmiHeader.ImageSize = header.BmiHeader.Width * header.BmiHeader.Height * header.BmiHeader.BitCount / 8; header.BitRate = (int)((10000000 / header.AvgTimePerFrame) * header.BmiHeader.ImageSize * 8); Abstract.SetHeader(media[i], header); media[i].sampleSize = header.BmiHeader.ImageSize; this.SetOutputMedia(filter, media[i]); result = true; break; } } } } } else { result = true; } } return(result); }