public DsGuid GetCLSID() { return(DsGuid.FromGuid( String.IsNullOrEmpty(CLSID) ? Guid.Empty : new Guid(CLSID))); }
/// <summary> /// Retrieve a list of crossbar filters in the graph. /// Most hardware devices should have a maximum of 2 crossbars, /// one for video and another for audio. /// </summary> protected static IEnumerable <IAMCrossbar> findCrossbars(ICaptureGraphBuilder2 graphBuilder, IBaseFilter deviceFilter) { //var crossbars = new List<IAMCrossbar>(); DsGuid category = DsGuid.FromGuid(FindDirection.UpstreamOnly); DsGuid type = new DsGuid(); Guid riid = typeof(IAMCrossbar).GUID; object comObj = null; object comObjNext = null; // Find the first interface, look upstream from the selected device int hr = graphBuilder.FindInterface(category, type, deviceFilter, riid, out comObj); while ((hr == 0) && (comObj != null)) { // If found, add to the list if (comObj is IAMCrossbar) { yield return(comObj as IAMCrossbar); //crossbars.Add(comObj as IAMCrossbar); // Find the second interface, look upstream from the next found crossbar hr = graphBuilder.FindInterface(category, type, comObj as IBaseFilter, riid, out comObjNext); comObj = comObjNext; } else { comObj = null; } } //return (crossbars); }
/// <summary> /// Adds a IWMWriterNetworkSink to the current AsfWriter output filter /// </summary> /// <param name="streamPort">The port out of which to stream the transcoded file</param> private void AddStreamSinkToCurrentOutputFilter(int streamPort) { int hr; DirectShowLib.IServiceProvider pServiceProvider; // http://msdn.microsoft.com/en-us/library/dd390985%28VS.85%29.aspx WMAsfWriter asfwriter = (WMAsfWriter)currentOutputFilter; pServiceProvider = (DirectShowLib.IServiceProvider)asfwriter; // Get access to WMwriterAdvanced2 object using pServiceProvider (poss not futureproof) (see http://groups.google.com/group/microsoft.public.win32.programmer.directx.video/browse_thread/thread/36b154d41cb76ffd/c571d6ef56de11af?#c571d6ef56de11af ) DsGuid dsgWMwriterAdvanced2 = DsGuid.FromGuid(new Guid(GUIDs.IWMWriterAdvanced2)); IWMWriterAdvanced2 WMWriterAdvanced2 = null; object o = null; hr = pServiceProvider.QueryService(dsgWMwriterAdvanced2, dsgWMwriterAdvanced2, out o); // FAILS IN A STA THREAD DsError.ThrowExceptionForHR(hr); WMWriterAdvanced2 = (IWMWriterAdvanced2)o; IWMWriterNetworkSink nsink; WMUtils.WMCreateWriterNetworkSink(out nsink); NetworkSink = nsink; dc.Add(nsink); nsink.SetMaximumClients(1); nsink.SetNetworkProtocol(NetProtocol.HTTP); NetworkSink.Open(ref streamPort); // Will throw exception if port is in use int nSinks; WMWriterAdvanced2.GetSinkCount(out nSinks); if (nSinks > 0) { IWMWriterSink pSink = null; WMWriterAdvanced2.GetSink(0, out pSink); if (pSink != null) { WMWriterAdvanced2.RemoveSink(pSink); } Marshal.ReleaseComObject(pSink); pSink = null; } WMWriterAdvanced2.AddSink(NetworkSink); }
void ConfigureASFWriter(WMAsfWriter asf_filter, WTVStreamingVideoRequest strq, FrameSize SourceFrameSize) { int hr; // Now it's added to the graph, configure it with the selected WM Profile SendDebugMessage("Getting WM profile with quality of " + strq.Quality.ToString(), 0); WindowsMediaLib.IWMProfileManager profileManager; WMUtils.WMCreateProfileManager(out profileManager); IWMProfile wmProfile; string txtPrxProfile = getPRXProfileForQuality(strq.Quality); if (!(string.IsNullOrEmpty(txtPrxProfile))) { SendDebugMessage("Adjusting WM profile to fit video within designated frame size", 0); // SET VIDEO SIZE TO FIT WITHIN THE RIGHT FRAME SendDebugMessage("Source video size is " + SourceFrameSize.ToString(), 0); FrameSize containerSize = frameSizeForStreamRequest(strq); SendDebugMessage("Container size is " + containerSize.ToString(), 0); FrameSize newVideoSize = new FrameSize(SourceFrameSize, containerSize); SendDebugMessage("Output size is " + newVideoSize.ToString(), 0); SetProfileFrameSize(ref txtPrxProfile, newVideoSize); SetProfileCustomSettings(ref txtPrxProfile, ref strq); // returns immediately if not custom quality SendDebugMessage("Configuring ASF Writer with profile", 0); profileManager.LoadProfileByData(txtPrxProfile, out wmProfile); WindowsMediaLib.IConfigAsfWriter configWriter = (WindowsMediaLib.IConfigAsfWriter)asf_filter; configWriter.ConfigureFilterUsingProfile(wmProfile); configWriter.SetIndexMode(true); // yes index - DEFAULT /* Additional config - TEST * //DirectShowLib.IConfigAsfWriter2 configAsfWriter2 = (DirectShowLib.IConfigAsfWriter2)asf_filter; * //configAsfWriter2.SetParam(ASFWriterConfig.AutoIndex, 0, 0); // IT IS DEFAULT */ // (NOT WORKING) // SET ANAMORPHIC VIDEO MARKERS WITHIN STREAM (ASPECT RATIO) ******************************* UInt32 uiAspectX = (UInt32)SourceFrameSize.Width; byte[] bAspectX = BitConverter.GetBytes(uiAspectX); UInt32 uiAspectY = (UInt32)SourceFrameSize.Height; byte[] bAspectY = BitConverter.GetBytes(uiAspectY); DirectShowLib.IServiceProvider pServiceProvider; // http://msdn.microsoft.com/en-us/library/dd390985%28VS.85%29.aspx pServiceProvider = (DirectShowLib.IServiceProvider)asf_filter; DsGuid dsgIWMHeaderinfo = DsGuid.FromGuid(new Guid(GUIDs.IWMWriterAdvanced2)); object o3 = null; hr = pServiceProvider.QueryService(dsgIWMHeaderinfo, dsgIWMHeaderinfo, out o3); // FAILS IN A STA THREAD DsError.ThrowExceptionForHR(hr); IWMHeaderInfo headerinfo = (IWMHeaderInfo)o3; // Get access to WMwriterAdvanced2 object using pServiceProvider (poss not futureproof) (see http://groups.google.com/group/microsoft.public.win32.programmer.directx.video/browse_thread/thread/36b154d41cb76ffd/c571d6ef56de11af?#c571d6ef56de11af ) DsGuid dsgWMwriterAdvanced2 = DsGuid.FromGuid(new Guid(GUIDs.IWMWriterAdvanced2)); object o = null; hr = pServiceProvider.QueryService(dsgWMwriterAdvanced2, dsgWMwriterAdvanced2, out o); // FAILS IN A STA THREAD DsError.ThrowExceptionForHR(hr); IWMWriterAdvanced2 WMWriterAdvanced2 = null; WMWriterAdvanced2 = (IWMWriterAdvanced2)o; // Get Access to IWMHeaderInfo3 through WMWriterAdvanced2 object o2 = null; //pServiceProvider = (DirectShowLib.IServiceProvider)WMWriterAdvanced2; DsGuid dsgIWMHeaderInfo3 = DsGuid.FromGuid(new Guid(GUIDs.IWMHeaderInfo3)); hr = pServiceProvider.QueryService(dsgWMwriterAdvanced2, dsgIWMHeaderInfo3, out o2); // LET'S SEE DsError.ThrowExceptionForHR(hr); IWMHeaderInfo3 WMHeaderInfo3 = null; WMHeaderInfo3 = (IWMHeaderInfo3)o2; short pwIndex; // Add Aspect Ratio information WMHeaderInfo3.AddAttribute(2, "AspectRatioX", out pwIndex, AttrDataType.DWORD, 0, bAspectX, bAspectX.Length); WMHeaderInfo3.AddAttribute(2, "AspectRatioY", out pwIndex, AttrDataType.DWORD, 0, bAspectY, bAspectY.Length); // Try with other interface too headerinfo.SetAttribute(2, "AspectRatioX", AttrDataType.DWORD, bAspectX, Convert.ToInt16(bAspectX.Length)); headerinfo.SetAttribute(2, "AspectRatioY", AttrDataType.DWORD, bAspectY, Convert.ToInt16(bAspectY.Length)); // ************ DEINTERLACE (experimental) if (strq.DeInterlaceMode > 0) { DeInterlaceModes dimode = DeInterlaceModes.WM_DM_NOTINTERLACED; // Deinterlace Mode if (strq.DeInterlaceMode == 1) { dimode = DeInterlaceModes.WM_DM_DEINTERLACE_NORMAL; } else if (strq.DeInterlaceMode == 2) { dimode = DeInterlaceModes.WM_DM_DEINTERLACE_HALFSIZE; } // Index of video pin int pinIndex = FilterGraphTools.FindPinIndexByMediaType(currentOutputFilter, PinDirection.Input, MediaType.Video, MediaSubType.Null); byte[] bDiMode = BitConverter.GetBytes((int)dimode); short szOf = (short)bDiMode.Length; // Set to use deinterlace mode try { WMWriterAdvanced2.SetInputSetting(pinIndex, g_wszDeinterlaceMode, AttrDataType.DWORD, bDiMode, szOf); } catch (Exception ex) { SendDebugMessageWithException("Could not set interlace mode:", ex); } } } else { SendDebugMessage("Warning - PRX Profile string was empty; using default WM config."); } }
/// <summary> Populate the collection by looking for commonly implemented property pages. </summary> protected static IEnumerable <PropertyPage> addFromGraph(ICaptureGraphBuilder2 graphBuilder, IBaseFilter videoDeviceFilter, IBaseFilter audioDeviceFilter, IBaseFilter videoCompressorFilter, IBaseFilter audioCompressorFilter, SourceCollection videoSources, SourceCollection audioSources) { var result = new List <PropertyPage>(); object filter = null; Trace.Assert(graphBuilder != null); // 1. the video capture filter addIfSupported(result, videoDeviceFilter, "Video Capture Device"); // 2. the video capture pin DsGuid cat = DsGuid.FromGuid(PinCategory.Capture); DsGuid med = DsGuid.FromGuid(MediaType.Interleaved); Guid iid = typeof(IAMStreamConfig).GUID; int hr = graphBuilder.FindInterface(cat, med, videoDeviceFilter, iid, out filter); //int hr = graphBuilder.FindInterface(ref cat, ref med, videoDeviceFilter, ref iid, out filter); if (hr != 0) { med = DsGuid.FromGuid(MediaType.Video); hr = graphBuilder.FindInterface(cat, med, videoDeviceFilter, iid, out filter); if (hr != 0) { filter = null; } } addIfSupported(result, filter, "Video Capture Pin"); // 3. the video preview pin cat = DsGuid.FromGuid(PinCategory.Preview); med = DsGuid.FromGuid(MediaType.Interleaved); iid = typeof(IAMStreamConfig).GUID; hr = graphBuilder.FindInterface(cat, med, videoDeviceFilter, iid, out filter); if (hr != 0) { med = DsGuid.FromGuid(MediaType.Video); hr = graphBuilder.FindInterface(cat, med, videoDeviceFilter, iid, out filter); if (hr != 0) { filter = null; } } addIfSupported(result, filter, "Video Preview Pin"); // 4. the video crossbar(s) var crossbars = new List <IAMCrossbar>(); int num = 1; for (int c = 0; c < videoSources.Count; c++) { CrossbarSource s = videoSources[c] as CrossbarSource; if (s != null) { if (crossbars.IndexOf(s.Crossbar) < 0) { crossbars.Add(s.Crossbar); if (addIfSupported(result, s.Crossbar, "Video Crossbar " + (num == 1 ? "" : num.ToString()))) { num++; } } } } crossbars.Clear(); // 5. the video compressor addIfSupported(result, videoCompressorFilter, "Video Compressor"); // 6. the video TV tuner cat = DsGuid.FromGuid(PinCategory.Capture); med = DsGuid.FromGuid(MediaType.Interleaved); iid = typeof(IAMTVTuner).GUID; hr = graphBuilder.FindInterface(cat, med, videoDeviceFilter, iid, out filter); if (hr != 0) { med = DsGuid.FromGuid(MediaType.Video); hr = graphBuilder.FindInterface(cat, med, videoDeviceFilter, iid, out filter); if (hr != 0) { filter = null; } } addIfSupported(result, filter, "TV Tuner"); // 7. the video compressor (VFW) IAMVfwCompressDialogs compressDialog = videoCompressorFilter as IAMVfwCompressDialogs; if (compressDialog != null) { VfwCompressorPropertyPage page = new VfwCompressorPropertyPage("Video Compressor", compressDialog); result.Add(page); } // 8. the audio capture filter addIfSupported(result, audioDeviceFilter, "Audio Capture Device"); // 9. the audio capture pin cat = DsGuid.FromGuid(PinCategory.Capture); med = DsGuid.FromGuid(MediaType.Audio); iid = typeof(IAMStreamConfig).GUID; hr = graphBuilder.FindInterface(cat, med, audioDeviceFilter, iid, out filter); if (hr != 0) { filter = null; } addIfSupported(result, filter, "Audio Capture Pin"); // 9. the audio preview pin cat = DsGuid.FromGuid(PinCategory.Preview); med = DsGuid.FromGuid(MediaType.Audio); iid = typeof(IAMStreamConfig).GUID; hr = graphBuilder.FindInterface(cat, med, audioDeviceFilter, iid, out filter); if (hr != 0) { filter = null; } addIfSupported(result, filter, "Audio Preview Pin"); // 10. the audio crossbar(s) num = 1; for (int c = 0; c < audioSources.Count; c++) { CrossbarSource s = audioSources[c] as CrossbarSource; if (s != null) { if (crossbars.IndexOf(s.Crossbar) < 0) { crossbars.Add(s.Crossbar); if (addIfSupported(result, s.Crossbar, "Audio Crossbar " + (num == 1 ? "" : num.ToString()))) { num++; } } } } crossbars.Clear(); // 11. the audio compressor addIfSupported(result, audioCompressorFilter, "Audio Compressor"); return(result); }