/// <summary> /// The compressor could be audio or video. If there is already an existing compressor of the /// given type, remove it and any downstream filters before adding the given compressor. /// The graph my not yet contain a DV Splitter, in which case, add the splitter first. /// </summary> /// <param name="fiCompressor"></param> public override void AddCompressor(FilterInfo fiCompressor) { Stop(); if (!AddDVSplitter()) { throw new ApplicationException("Failed to add DV Splitter Filter"); } if (fiCompressor.Category.Equals(Filter.CLSID_AudioCompressorCategory)) { if (audioCompressor != null) { RemoveFiltersDownstreamFromPin(splitterAudioOut); RemoveAndDispose(audioCompressor); audioCompressor = null; } audioCompressor = (Compressor)Filter.CreateFilter(fiCompressor); iGB.AddFilter(audioCompressor.BaseFilter, audioCompressor.FriendlyName); audioCompressor.AddedToGraph(fgm); compressor = audioCompressor; _AMMediaType[] mts = Pin.GetMediaTypes(splitterAudioOut); //Returns one DVInfo mt. foreach (_AMMediaType mt in mts) { Debug.WriteLine(MediaType.Dump(mt)); } try { iGB.Connect(this.splitterAudioOut, audioCompressor.InputPin); } catch (COMException) { RemoveAndDispose(audioCompressor); audioCompressor = null; throw; } } else if (fiCompressor.Category.Equals(Filter.CLSID_VideoCompressorCategory)) { if (videoCompressor != null) { RemoveFiltersDownstreamFromPin(splitterVideoOut); RemoveAndDispose(videoCompressor); videoCompressor = null; } videoCompressor = (Compressor)Filter.CreateFilter(fiCompressor); iGB.AddFilter(videoCompressor.BaseFilter, videoCompressor.FriendlyName); videoCompressor.AddedToGraph(fgm); compressor = videoCompressor; try { iGB.Connect(this.splitterVideoOut, videoCompressor.InputPin); } catch (COMException) { RemoveAndDispose(videoCompressor); videoCompressor = null; throw; } } }
public void GetAudioMediaTypes(out _AMMediaType[] mts, out object[] fbs) { if (!AddDVSplitter()) { throw new ApplicationException("Failed to add DV Splitter"); } Pin.GetMediaTypes(this.splitterAudioOut, out mts, out fbs); }
/// <summary> /// Configure the Opus encoder filter /// after the encoder is in the graph and connected /// to the source. /// /// Warning: This might not work for a DVCaptureGraph. /// </summary> /// <param name="cg"></param> /// <param name="j"></param> public override void PostConnectConfig(Dictionary <string, Object> args) { CaptureGraph cg = args["CaptureGraph"] as CaptureGraph; IAudioCaptureGraph iacg = cg as IAudioCaptureGraph; _AMMediaType[] mts = Pin.GetMediaTypes(cg.Source.OutputPin); bool mtSet = false; foreach (_AMMediaType mt in mts) { WAVEFORMATEX wfex = (WAVEFORMATEX)MediaType.FormatType.MarshalData(mt); if ((wfex.SamplesPerSec == Frequency) && (wfex.Channels == Channels) && (wfex.BitsPerSample == Depth)) { cg.Source.SetMediaType(mt); mtSet = true; break; } } if (!mtSet) { throw new ApplicationException("The audio device doesn't support the configured values of SamplesPerSec/Channels/BitsPerSample."); } IOpusEncoderCtl iOpus = (IOpusEncoderCtl)iacg.AudioCompressor.BaseFilter; iOpus.SetSignal(Signal); int br = BitRate; if (br == 0) { br = ManualBitRate; } iOpus.SetBitRate(br); iOpus.SetComplexity(Complexity); iOpus.SetMaxBandwidth(MaxBandwidth); iOpus.SetVbr(VBR); iOpus.SetVbrConstraint(VBRConstraint); iOpus.SetDtx(DTX); iOpus.SetPacketLossPerc(PacketLossPerc); iOpus.SetLsbDepth(LSBDepth); iOpus.SetForcedChannels(ForcedChannels); }
public void GetAudioMediaType(out _AMMediaType mt, out object formatBlock) { _AMMediaType[] mts; object[] formats; //GetMediaType does not work with this pin because it cannot be cast to IAMStreamConfig. if (!AddDVSplitter()) { throw new ApplicationException("Failed to add DV Splitter"); } Pin.GetMediaTypes(this.splitterAudioOut, out mts, out formats); //Is it safe to assume one audio media type? if (mts.Length > 0) { mt = mts[0]; formatBlock = formats[0]; } else { mt = new _AMMediaType(); formatBlock = null; } }