private void ConfigureCompressor() { // Have the compressor use the same height and width settings as the device // Because these are structs that access their members through properties // some of the properties (like BitmapInfo) are copied, so we work on the // copy and then restore it at the end BITMAPINFOHEADER bmih = cVI.BitmapInfo; bmih.Width = SystemInformation.PrimaryMonitorSize.Width; bmih.Height = SystemInformation.PrimaryMonitorSize.Height; bmih.Size = (uint)Marshal.SizeOf(typeof(BITMAPINFOHEADER)); bmih.Planes = 1; cVI.BitmapInfo = bmih; // Configure the bit rate cVI.BitRate = (uint)(hsbBitRate.Value * 1024); // Change to kilobits // Update the structure in memory Marshal.StructureToPtr(cVI, cMT.pbFormat, false); // Allow compressor specific configuration // e.g. WM9+ requires extra configuration, others may as well ConfigureWMScreenEncoder(); Console.WriteLine(MediaType.Dump(cMT)); // Use the structure in the compressor IAMStreamConfig iSC = (IAMStreamConfig)cOutputPin; iSC.SetFormat(ref cMT); IAMVideoCompression iVC = (IAMVideoCompression)cOutputPin; }
private void InitializeCompressorMediaType() { ArrayList mts = new ArrayList(); ArrayList ihs = new ArrayList(); ArrayList sccs = new ArrayList(); Pin.GetStreamConfigCaps((IAMStreamConfig)cOutputPin, out mts, out ihs, out sccs); for (int i = 0; i < mts.Count; i++) { Console.WriteLine(MediaType.Dump((_AMMediaType)mts[i])); Console.WriteLine(Pin.DebugStreamConfigCaps(sccs[i])); } // There's only one cMT = (_AMMediaType)mts[0]; cMT.formattype = MediaType.FormatType.FORMAT_VideoInfo; // MediaTypes are local to method, so free them all // then reallocate just the one we want for (int i = 0; i < mts.Count; i++) { _AMMediaType mt = (_AMMediaType)mts[i]; MediaType.Free(ref mt); } cMT.cbFormat = (uint)Marshal.SizeOf(cVI); cMT.pbFormat = Marshal.AllocCoTaskMem((int)cMT.cbFormat); }
/// <summary> /// Show the uncompressed audio format form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAudio_Click(object sender, System.EventArgs e) { try { // Show the form frmAudioFormat af = new frmAudioFormat(ac.CaptureGraph); if (af.ShowDialog(this) == DialogResult.OK) { if (ckTestAudio.Checked) { ckTestAudio.Checked = false; } // Get the media type they selected and set it _AMMediaType mt; object fb; af.GetMediaType(out mt, out fb); #region Log Log("Setting media type to..."); Log(MediaType.Dump(mt) + MediaType.FormatType.Dump(fb)); #endregion Log frmAV.RenderAndRunAudio(ac.CaptureGraph, false); ac.CaptureGraph.RemoveFiltersDownstreamFromSource(MSR.LST.Net.Rtp.PayloadType.dynamicAudio); try { ac.CaptureGraph.Source.SetMediaType(mt, fb); } catch (COMException ex) { Log(DShowError._AMGetErrorText(ex.ErrorCode)); Log(ex.ToString()); } catch (Exception ex) { Log(ex.ToString()); } ac.SaveAudioSettings(); ac.AddAudioCompressor(); frmAV.RenderAndRunAudio(ac.CaptureGraph); UpdateCurrentSettings(); } } catch (COMException ex) { Log(DShowError._AMGetErrorText(ex.ErrorCode)); Log(ex.ToString()); } catch (Exception ex) { Log(ex.ToString()); } }
protected void LogCurrentMediaType(Filter f) { if (f != null) { _AMMediaType mt; object fb; f.GetMediaType(out mt, out fb); Log(string.Format(CultureInfo.CurrentCulture, "\r\nCurrent media type for {0}...", f.FriendlyName) + MediaType.Dump(mt) + MediaType.FormatType.Dump(fb)); } }
/// <summary> /// Restore the video stream's last settings from the registry /// </summary> private void RestoreVideoSettings() { // Read media type from registry byte[] bytes = (byte[])AVReg.ReadValue(DeviceKey(), AVReg.MediaType); if (bytes != null) { AVReg.ms.Position = 0; AVReg.ms.Write(bytes, 0, bytes.Length); AVReg.ms.Position = 0; _AMMediaType mt = (_AMMediaType)AVReg.bf.Deserialize(AVReg.ms); // Read format block from registry if (mt.cbFormat != 0) { bytes = (byte[])AVReg.ReadValue(DeviceKey(), AVReg.FormatBlock); Debug.Assert(bytes.Length == mt.cbFormat); mt.pbFormat = Marshal.AllocCoTaskMem((int)mt.cbFormat); Marshal.Copy(bytes, 0, mt.pbFormat, (int)mt.cbFormat); Log("Restoring stream settings..."); Log(MediaType.Dump(mt)); try { // Set and free cg.Source.SetMediaType(ref mt); } catch (COMException ex) { Log(DShowError._AMGetErrorText(ex.ErrorCode)); Log(ex.ToString()); } catch (Exception ex) { Log(ex.ToString()); } } } }
protected void LogCurrentMediaType(Filter f) { if (f != null) { _AMMediaType mt; object fb; if (f is MSR.LST.MDShow.OpusAudioCompressor) { //TODO: log something useful } else { try { f.GetMediaType(out mt, out fb); Log(string.Format(CultureInfo.CurrentCulture, "\r\nCurrent media type for {0}...", f.FriendlyName) + MediaType.Dump(mt) + MediaType.FormatType.Dump(fb)); } catch { //TODO: log something useful } } } }