public static List <AMMediaType> GetMediaTypes(IPin pin) { List <AMMediaType> mediaTypes = new List <AMMediaType>(); IEnumMediaTypes mediaTypesEnum = null; AMMediaType[] mta = new AMMediaType[1]; if (pin.EnumMediaTypes(out mediaTypesEnum) == 0) { int n; try { while (mediaTypesEnum.Next(1, mta, out n) == 0) { if (n == 1) { mediaTypes.Add(mta[0]); } } } finally { Marshal.ReleaseComObject(mediaTypesEnum); } } return(mediaTypes); }
/// <summary> /// 初始化该引脚的媒体类型 /// </summary> public void InitAMMediaType() { this.MediaTypes = new List <AMMediaType>(); var hr = 0; IEnumMediaTypes enumMediaTypes = null; hr = Pin.EnumMediaTypes(out enumMediaTypes); if (hr != 0) { if (hr != DsResults.E_NotConnected) { DsError.ThrowExceptionForHR(hr); } return; } short count = 128; IntPtr pCount = Marshal.AllocHGlobal(sizeof(short)); Marshal.WriteInt16(pCount, count); AMMediaType[] mediaTypeArr = new AMMediaType[1]; while (enumMediaTypes.Next(1, mediaTypeArr, pCount) == 0) { if (mediaTypeArr[0] != null) { MediaTypes.Add(mediaTypeArr[0]); } } Marshal.ReleaseComObject(enumMediaTypes); }
/// <summary> /// Gets the pin media types. /// </summary> /// <returns>Returns collection of supported media types.</returns> public IEnumerable <AMMediaType> GetMediaTypes() { IEnumMediaTypes mediaTypes = null; try { var hr = Object.EnumMediaTypes(out mediaTypes); DsError.ThrowExceptionForHR(hr); var currentMediaType = new AMMediaType[1]; while (mediaTypes.Next(1, currentMediaType, out _) == 0) { try { yield return(currentMediaType[0]); } finally { DsUtils.FreeAMMediaType(currentMediaType[0]); } } } finally { if (mediaTypes != null) { DsUtils.ReleaseComObject(mediaTypes); } } }
private static bool checkMediaTypes(IPin pin, Guid mediaType, Guid mediaSubType) { int reply = 0; IEnumMediaTypes enumMediaTypes = null; AMMediaType[] mediaTypes = new AMMediaType[1]; reply = pin.EnumMediaTypes(out enumMediaTypes); DsError.ThrowExceptionForHR(reply); while (enumMediaTypes.Next(mediaTypes.Length, mediaTypes, IntPtr.Zero) == 0) { foreach (AMMediaType currentMediaType in mediaTypes) { if (currentMediaType != null) { if (currentMediaType.majorType == mediaType && currentMediaType.subType == mediaSubType) { Marshal.ReleaseComObject(enumMediaTypes); return(true); } } } } Marshal.ReleaseComObject(enumMediaTypes); return(false); }
public void TestNext() { int hr; IntPtr ip = Marshal.AllocCoTaskMem(4); AMMediaType[] ppMediaTypes = new AMMediaType[10]; IEnumMediaTypes enumMediaTypes = GetEnumMediaTypes(); //IntPtr ip2 = Marshal.AllocCoTaskMem(ppMediaTypes.Length * IntPtr.Size); for (int x = 0; x < 3; x++) { hr = enumMediaTypes.Next(ppMediaTypes.Length, ppMediaTypes, ip); //for (int y = 0; y < Marshal.ReadInt32(ip); y++) //{ // ppMediaTypes[y] = new AMMediaType(); // IntPtr ip3 = Marshal.ReadIntPtr(ip2, y * IntPtr.Size); // new IntPtr(ip2.ToInt64() + (y * IntPtr.Size)); // Marshal.PtrToStructure(ip3, ppMediaTypes[y]); //} DsError.ThrowExceptionForHR(hr); } Marshal.FreeCoTaskMem(ip); }
public int Clone(out IEnumMediaTypes ppEnum) { ppEnum = new MediaTypeEnumerator(pin) { index = index }; return(S_OK); }
/// <summary> /// Finds a pin that exists in a graph. /// </summary> /// <param name="majorOrMinorMediaType">The GUID of the major or minor type of the media</param> /// <param name="pinDirection">The direction of the pin - in/out</param> /// <param name="graph">The graph to search in</param> /// <returns>Returns null if the pin was not found, or if a pin is found, returns the first instance of it</returns> protected static IPin FindPinInGraphByMediaType(Guid majorOrMinorMediaType, PinDirection pinDirection, IGraphBuilder graph) { IEnumFilters enumFilters; /* Get the filter enum */ graph.EnumFilters(out enumFilters); /* Init our vars */ var filters = new IBaseFilter[1]; var fetched = IntPtr.Zero; IPin pin = null; IEnumMediaTypes mediaTypesEnum = null; /* Loop over each filter in the graph */ while (enumFilters.Next(1, filters, fetched) == 0) { var filter = filters[0]; int i = 0; /* Loop over each pin in the filter */ while ((pin = DsFindPin.ByDirection(filter, pinDirection, i)) != null) { /* Get the pin enumerator */ pin.EnumMediaTypes(out mediaTypesEnum); var mediaTypesFetched = IntPtr.Zero; var mediaTypes = new AMMediaType[1]; /* Enumerate the media types on the pin */ while (mediaTypesEnum.Next(1, mediaTypes, mediaTypesFetched) == 0) { /* See if the major or subtype meets our requirements */ if (mediaTypes[0].majorType.Equals(majorOrMinorMediaType) || mediaTypes[0].subType.Equals(majorOrMinorMediaType)) { /* We found a match */ goto done; } } i++; } } done: if (mediaTypesEnum != null) { mediaTypesEnum.Reset(); Marshal.ReleaseComObject(mediaTypesEnum); } enumFilters.Reset(); Marshal.ReleaseComObject(enumFilters); return(pin); }
private int getPinMediaType(IPin pPin, Guid majorType, Guid minorType, Guid formatType, ref AMMediaType mediaType) { if (pPin == null) { throw new Exception("No pin"); } int hr; IEnumMediaTypes pEnum = null; hr = pPin.EnumMediaTypes(out pEnum); DsError.ThrowExceptionForHR(hr); bool found = false; IntPtr fetched = IntPtr.Zero; AMMediaType[] pMT = new AMMediaType[1]; hr = pEnum.Next(1, pMT, fetched); while (hr == 0) { if ((majorType.Equals(Guid.Empty)) || (majorType.Equals(pMT[0].majorType))) { if ((minorType.Equals(Guid.Empty)) || (minorType.Equals(pMT[0].subType))) { if ((formatType.Equals(Guid.Empty)) || (formatType.Equals(pMT[0].formatType))) // Match { found = true; mediaType = pMT[0]; break; } } } DsUtils.FreeAMMediaType(pMT[0]); hr = pEnum.Next(1, pMT, fetched); } // End Marshal.ReleaseComObject(pEnum); if (found) { return(0); } else { return(-1); } }
public static string DumpPinInfo(IPin pin) { StringBuilder sb = new StringBuilder(); int hr; sb.AppendLine(">>>>> Pin Info"); { PinInfo pi; hr = pin.QueryPinInfo(out pi); if (0 == hr) { sb.AppendLine(string.Format("PinInfo name: {0} direction: {1}", pi.name, pi.dir.ToString())); } else { sb.AppendLine("PinInfo: " + GetErrorText(hr)); } } // Pins info { IEnumMediaTypes enumMediaTypes = null; AMMediaType[] mediaTypes = new AMMediaType[1] { null }; try { hr = pin.EnumMediaTypes(out enumMediaTypes); DsError.ThrowExceptionForHR(hr); while (enumMediaTypes.Next(1, mediaTypes, IntPtr.Zero) == 0) { sb.AppendLine(DumpAMMediaTypeInfo(mediaTypes[0])); DsUtils.FreeAMMediaType(mediaTypes[0]); mediaTypes[0] = null; } } finally { Marshal.ReleaseComObject(enumMediaTypes); } } sb.AppendLine("<<<<< Pin Info"); return(sb.ToString()); }
public void TestClone() { int hr; AMMediaType[] ppMediaTypes = new AMMediaType[1]; IEnumMediaTypes enumMediaTypes = GetEnumMediaTypes(); IEnumMediaTypes cloneMediaType; hr = enumMediaTypes.Clone(out cloneMediaType); DsError.ThrowExceptionForHR(hr); hr = cloneMediaType.Next(1, ppMediaTypes, IntPtr.Zero); DsError.ThrowExceptionForHR(hr); }
private void logMediaTypes(IPin pin) { IEnumMediaTypes mediaTypes = null; AMMediaType[] mediaType = new AMMediaType[1]; AMMediaType connectedMediaType = new AMMediaType(); reply = pin.ConnectionMediaType(connectedMediaType); reply = pin.EnumMediaTypes(out mediaTypes); if (reply != 0) { LogMessage("Media types cannot be determined at this time (not connected yet?)"); return; } while (mediaTypes.Next(mediaType.Length, mediaType, IntPtr.Zero) == 0) { foreach (AMMediaType currentMediaType in mediaType) { PinInfo pinInfo; reply = pin.QueryPinInfo(out pinInfo); DsError.ThrowExceptionForHR(reply); string majorType = TranslateMediaMajorType(currentMediaType.majorType); string subType = TranslateMediaSubType(currentMediaType.subType); string connectedComment; if (currentMediaType.majorType == connectedMediaType.majorType && currentMediaType.subType == connectedMediaType.subType) { connectedComment = "** Connected **"; } else { connectedComment = string.Empty; } LogMessage("Media type: " + majorType + " ; " + subType + " " + currentMediaType.fixedSizeSamples + " " + currentMediaType.sampleSize + " " + connectedComment); } } }
private static IPin FindPinByMediaType(IBaseFilter filter, PinDirection direction, Guid mType, Guid sType) { IPin pRet = null; IPin tPin = null; int hr; int index = 0; tPin = DsFindPin.ByDirection(filter, direction, index); while (tPin != null) { IEnumMediaTypes emtDvr = null; AMMediaType[] amtDvr = new AMMediaType[1]; try { tPin.EnumMediaTypes(out emtDvr); hr = emtDvr.Next(1, amtDvr, IntPtr.Zero); DsError.ThrowExceptionForHR(hr); if (amtDvr[0] != null && amtDvr[0].majorType == mType && (amtDvr[0].subType == sType || sType == MediaSubType.Null)) { pRet = tPin; break; } } finally { DsUtils.FreeAMMediaType(amtDvr[0]); if (emtDvr != null) { Marshal.ReleaseComObject(emtDvr); } } if (tPin != null) { Marshal.ReleaseComObject(tPin); } tPin = null; index++; tPin = DsFindPin.ByDirection(filter, direction, index); } return(pRet); }
public void TestSkip() { int hr; AMMediaType[] ppMediaTypes = new AMMediaType[1]; IEnumMediaTypes enumMediaTypes = GetEnumMediaTypes(); hr = enumMediaTypes.Next(1, ppMediaTypes, IntPtr.Zero); DsError.ThrowExceptionForHR(hr); hr = enumMediaTypes.Skip(1); DsError.ThrowExceptionForHR(hr); hr = enumMediaTypes.Next(1, ppMediaTypes, IntPtr.Zero); DsError.ThrowExceptionForHR(hr); }
/// <summary> /// Get the IPinIPType for the pin's prefered or connected media type /// </summary> /// <param name="pin"></param> /// <returns></returns> private Type GetPinMajorMediaType(IPin pin) { Type t = null; AMMediaType contype = new AMMediaType(); int hr = pin.ConnectionMediaType(contype); if (hr == 0) { t = PinDataTypes.GetMajorPinType(contype.majorType); DsUtils.FreeAMMediaType(contype); return(t); } else { // wasn't connected, enumerate the prefered media types and get the major type of the first one IEnumMediaTypes penum = null; hr = pin.EnumMediaTypes(out penum); if (hr == 0 && penum != null) { AMMediaType[] mtypes = new AMMediaType[1]; IntPtr fetched = Marshal.AllocCoTaskMem(4); try { if (penum.Next(1, mtypes, fetched) == 0) { t = PinDataTypes.GetMajorPinType(mtypes[0].majorType); DsUtils.FreeAMMediaType(mtypes[0]); Marshal.ReleaseComObject(penum); return(t); } } finally { Marshal.FreeCoTaskMem(fetched); } } } // couldn't get the pin's major media type return(typeof(PinDataTypes.Unknown)); }
public static void SplitterForFile(string file) { int hr; IBaseFilter reader = (IBaseFilter) new AsyncReader(); hr = (reader as IFileSourceFilter).Load(file, null); IPin oPin = DsFindPin.ByDirection(reader, PinDirection.Output, 0); IEnumMediaTypes eMedia = null; AMMediaType[] mediaTypes = new AMMediaType[1]; hr = oPin.EnumMediaTypes(out eMedia); while (eMedia.Next(mediaTypes.Length, mediaTypes, IntPtr.Zero) == 0) { GetDevicesWithThisInPin(mediaTypes[0].majorType, mediaTypes[0].subType); } }
/// <summary> /// 指定したピンが指定したMediaTypeをサポートするか? /// </summary> /// <param name="pin">ピン</param> /// <param name="major">majorType</param> /// <param name="sub">subType or 検証不要な場合 Guid.Empty</param> /// <returns>サポートしてる場合true</returns> public static bool IsPinSupportsMediaType(IPin pin, Guid major, Guid sub) { bool found = false; IEnumMediaTypes enumerator = null; try { pin.EnumMediaTypes(out enumerator); IntPtr pMedia = IntPtr.Zero; AMMediaType media = new AMMediaType(); found = false; enumerator.Reset(); while (!found && enumerator.Next(1, out pMedia, IntPtr.Zero) == S_OK) { if (pMedia == IntPtr.Zero) { continue; } Marshal.PtrToStructure(pMedia, media); if (media.majorType == major && (sub == Guid.Empty || media.subType != sub)) { found = true; } Util.FreeMediaType(media); Marshal.FreeCoTaskMem(pMedia); } } finally { if (enumerator != null) { Marshal.ReleaseComObject(enumerator); } enumerator = null; } return(found); }
public void TestReset() { int hr; IntPtr ip = Marshal.AllocCoTaskMem(4); AMMediaType[] ppMediaTypes = new AMMediaType[1]; IEnumMediaTypes enumMediaTypes = GetEnumMediaTypes(); hr = enumMediaTypes.Next(ppMediaTypes.Length, ppMediaTypes, ip); DsError.ThrowExceptionForHR(hr); Debug.Assert(Marshal.ReadInt32(ip) == 1, "Next"); hr = enumMediaTypes.Reset(); DsError.ThrowExceptionForHR(hr); hr = enumMediaTypes.Next(1, ppMediaTypes, IntPtr.Zero); DsError.ThrowExceptionForHR(hr); Marshal.FreeCoTaskMem(ip); }
public static IPin FindPinForMajorType(IBaseFilter filter, PinDirection direction, Guid majorType) { if (filter == null) { throw new ArgumentNullException("filter"); } int hr = 0; IEnumPins pinsEnum = null; try { hr = filter.EnumPins(out pinsEnum); DsError.ThrowExceptionForHR(hr); var pins = new IPin[1]; int numberFetched = 1; while (numberFetched > 0) { IntPtr pcFetched = Marshal.AllocCoTaskMem(4); try { hr = pinsEnum.Next(1, pins, pcFetched); DsError.ThrowExceptionForHR(hr); numberFetched = Marshal.ReadInt32(pcFetched); } finally { Marshal.FreeCoTaskMem(pcFetched); } if (numberFetched > 0) { PinDirection currentPinDirection; hr = pins[0].QueryDirection(out currentPinDirection); DsError.ThrowExceptionForHR(hr); if (currentPinDirection != direction) { continue; } IEnumMediaTypes mediaTypesEnum = null; try { var mediaTypes = new AMMediaType[1]; pins[0].EnumMediaTypes(out mediaTypesEnum); int numberFetched2 = 1; while (numberFetched2 > 0) { IntPtr fetched2 = IntPtr.Zero; try { hr = mediaTypesEnum.Next(1, mediaTypes, fetched2); DsError.ThrowExceptionForHR(hr); numberFetched2 = Marshal.ReadInt32(fetched2); } finally { Marshal.FreeCoTaskMem(fetched2); } if (numberFetched2 > 0) { if (mediaTypes[0].majorType == majorType) { // success, return the pin return(pins[0]); } } Marshal.ReleaseComObject(pins[0]); } } finally { if (mediaTypesEnum != null) { Marshal.ReleaseComObject(mediaTypesEnum); } } } } } finally { if (pinsEnum != null) { Marshal.ReleaseComObject(pinsEnum); } } return(null); }
/// <summary> /// Retreives detailed information about all pins on a given filter. /// Caller must release all returned data. See IEnumerable<DetailPinInfo>.Release() /// </summary> /// <remarks> /// If an exception occurs, it frees all objects that may already be enumerated /// </remarks> /// <param name="filter">filter to get information about</param> public static List <DetailPinInfo> EnumPinsDetails(this IBaseFilter filter) { List <DetailPinInfo> info = new List <DetailPinInfo>(); int hr; IEnumPins enumPins; IEnumMediaTypes enumMediaTypes = null; IPin[] curPin = new IPin[1]; PinInfo curPinInfo = new PinInfo(); AMMediaType[] curMediaType = new AMMediaType[1]; hr = filter.EnumPins(out enumPins); DsError.ThrowExceptionForHR(hr); try { IntPtr fetched = Marshal.AllocCoTaskMem(4); try { while (enumPins.Next(curPin.Length, curPin, fetched) == 0) { if (Marshal.ReadInt32(fetched) == 1) { info.Add(new DetailPinInfo(curPin[0])); } } } finally { Marshal.FreeCoTaskMem(fetched); } return(info); } catch (Exception ex) { ErrorLogger.DumpToDebug(ex); try { BaseDSGraph.Release(curPin[0]); if (curMediaType[0] != null) { DsUtils.FreeAMMediaType(curMediaType[0]); } DsUtils.FreePinInfo(curPinInfo); info.Release(); } catch (Exception cleanUpEx) { ErrorLogger.DumpToDebug(cleanUpEx); } throw; } finally { BaseDSGraph.Release(enumPins); BaseDSGraph.Release(enumMediaTypes); } }
public int Clone(out IEnumMediaTypes ppEnum) { MediaTypeEnumerator ans = new MediaTypeEnumerator(p); if(c != 0) { ans.Skip(c); } ppEnum = ans; return S_OK; }
public int Clone(out IEnumMediaTypes ppEnum) { ppEnum = new EnumMediaTypes(_types); return((int)HRESULT.S_OK); }
// This method changed to work with Windows 7 // Under this OS, the MPEG-2 Demux now have dozens of outputs pins. // Rendering all of them is not a good solution. // The rendering process must be more smart... private void ConnectFilters() { int hr = 0; int pinNumber = 0; IPin pinOut, pinIn; // After the rendering process, our 4 downstream filters must be rendered bool bdaTIFRendered = false; bool bdaSecTabRendered = false; bool audioRendered = false; bool videoRendered = false; // for each output pins... while (true) { pinOut = DsFindPin.ByDirection(mpeg2Demux, PinDirection.Output, pinNumber); // Is the last pin reached ? if (pinOut == null) { break; } IEnumMediaTypes enumMediaTypes = null; AMMediaType[] mediaTypes = new AMMediaType[1]; try { // Get Pin's MediaType enumerator hr = pinOut.EnumMediaTypes(out enumMediaTypes); DsError.ThrowExceptionForHR(hr); // for each media types... while (enumMediaTypes.Next(mediaTypes.Length, mediaTypes, IntPtr.Zero) == 0) { // Store the majortype and the subtype and free the structure Guid majorType = mediaTypes[0].majorType; Guid subType = mediaTypes[0].subType; DsUtils.FreeAMMediaType(mediaTypes[0]); if (majorType == MediaType.Audio) { // Is the Audio already rendered ? if (!audioRendered) { // Get the first input pin pinIn = DsFindPin.ByDirection(audioRenderer, PinDirection.Input, 0); // Render it with IntelliConnect (a decoder should be added between the two filters. hr = graphBuilder.Connect(pinOut, pinIn); DsError.ThrowExceptionForHR(hr); // Release the Pin Marshal.ReleaseComObject(pinIn); pinIn = null; // Notify that the audio renderer is connected audioRendered = true; } } else if (majorType == MediaType.Video) { // Is the Video already rendered ? if (!videoRendered) { // Get the first input pin pinIn = DsFindPin.ByDirection(videoRenderer, PinDirection.Input, 0); // Render it with IntelliConnect (a decoder should be added between the two filters. hr = graphBuilder.Connect(pinOut, pinIn); DsError.ThrowExceptionForHR(hr); // Release the Pin Marshal.ReleaseComObject(pinIn); pinIn = null; // Notify that the video renderer is connected videoRendered = true; } } else if (majorType == MediaType.Mpeg2Sections) { if (subType == MediaSubType.Mpeg2Data) { // Is the MPEG-2 Sections and Tables Filter already rendered ? if (!bdaSecTabRendered) { // Get the first input pin pinIn = DsFindPin.ByDirection(bdaSecTab, PinDirection.Input, 0); // A direct connection is enough hr = graphBuilder.ConnectDirect(pinOut, pinIn, null); DsError.ThrowExceptionForHR(hr); // Release the Pin Marshal.ReleaseComObject(pinIn); pinIn = null; // Notify that the MPEG-2 Sections and Tables Filter is connected bdaSecTabRendered = true; } } // This sample only support DVB-T or DVB-S so only supporting this subtype is enough. // If you want to support ATSC or ISDB, don't forget to handle these network types. else if (subType == MediaSubType.DvbSI) { // Is the BDA MPEG-2 Transport Information Filter already rendered ? if (!bdaTIFRendered) { // Get the first input pin pinIn = DsFindPin.ByDirection(bdaTIF, PinDirection.Input, 0); // A direct connection is enough hr = graphBuilder.ConnectDirect(pinOut, pinIn, null); DsError.ThrowExceptionForHR(hr); // Release the Pin Marshal.ReleaseComObject(pinIn); pinIn = null; // Notify that the BDA MPEG-2 Transport Information Filter is connected bdaTIFRendered = true; } } } } } finally { // Free COM objects Marshal.ReleaseComObject(enumMediaTypes); enumMediaTypes = null; Marshal.ReleaseComObject(pinOut); pinOut = null; } // Next pin, please ! pinNumber++; } }
int IPin.EnumMediaTypes(out IEnumMediaTypes ppEnum) { ppEnum = new MediaTypeEnumerator(this); return(S_OK); }
public static void AddPreferredFilters(IGraphBuilder graphBuilder, IBaseFilter sourceFilter) { using (Settings xmlreader = new MPSettings()) { bool autodecodersettings = xmlreader.GetValueAsBool("movieplayer", "autodecodersettings", false); if (!autodecodersettings) // the user has not chosen automatic graph building by merits { // bool vc1ICodec,vc1Codec,xvidCodec = false; - will come later bool aacCodec = false; bool h264Codec = false; // check the output pins of the splitter for known media types IEnumPins pinEnum = null; if (sourceFilter.EnumPins(out pinEnum) == 0) { int fetched = 0; IPin[] pins = new IPin[1]; while (pinEnum.Next(1, pins, out fetched) == 0 && fetched > 0) { IPin pin = pins[0]; PinDirection pinDirection; if (pin.QueryDirection(out pinDirection) == 0 && pinDirection == PinDirection.Output) { IEnumMediaTypes enumMediaTypesVideo = null; if (pin.EnumMediaTypes(out enumMediaTypesVideo) == 0) { AMMediaType[] mediaTypes = new AMMediaType[1]; int typesFetched; while (enumMediaTypesVideo.Next(1, mediaTypes, out typesFetched) == 0 && typesFetched > 0) { if (mediaTypes[0].majorType == MediaType.Video && (mediaTypes[0].subType == MediaSubType.H264 || mediaTypes[0].subType == MEDIASUBTYPE_AVC1)) { Logger.Instance.Info("found H264 video on output pin"); h264Codec = true; } else if (mediaTypes[0].majorType == MediaType.Audio && mediaTypes[0].subType == MediaSubType.LATMAAC) { Logger.Instance.Info("found AAC audio on output pin"); aacCodec = true; } } DirectShowUtil.ReleaseComObject(enumMediaTypesVideo); } } DirectShowUtil.ReleaseComObject(pin); } DirectShowUtil.ReleaseComObject(pinEnum); } // add filters for found media types to the graph as configured in MP if (h264Codec) { DirectShowUtil.ReleaseComObject( DirectShowUtil.AddFilterToGraph(graphBuilder, xmlreader.GetValueAsString("movieplayer", "h264videocodec", ""))); } else { DirectShowUtil.ReleaseComObject( DirectShowUtil.AddFilterToGraph(graphBuilder, xmlreader.GetValueAsString("movieplayer", "mpeg2videocodec", ""))); } if (aacCodec) { DirectShowUtil.ReleaseComObject( DirectShowUtil.AddFilterToGraph(graphBuilder, xmlreader.GetValueAsString("movieplayer", "aacaudiocodec", ""))); } else { DirectShowUtil.ReleaseComObject( DirectShowUtil.AddFilterToGraph(graphBuilder, xmlreader.GetValueAsString("movieplayer", "mpeg2audiocodec", ""))); } } } }
public int EnumMediaTypes(out IEnumMediaTypes ppEnum) { ppEnum = new EnumMediaTypes(MediaTypes.ToArray()); return((int)HRESULT.S_OK); }
int IPin.EnumMediaTypes(out IEnumMediaTypes ppEnum) { ppEnum = new MediaTypeEnumerator(this); return S_OK; }
public static IEnumerator <WavFormatInfo> EnumerateFormatsForDirection(IBaseFilter filter, PinDirection direction) { if (filter == null) { throw new ArgumentNullException("filter"); } int hr; IEnumPins pinsEnum = null; try { hr = filter.EnumPins(out pinsEnum); DsError.ThrowExceptionForHR(hr); if (pinsEnum == null) { throw new InvalidOperationException("pinsEnum is null"); } IPin[] pins = new IPin[1]; while (true) { try { int pcFetched; hr = pinsEnum.Next(pins.Length, pins, out pcFetched); DsError.ThrowExceptionForHR(hr); if (pcFetched == 1) { // we have something IPin pin = pins[0]; string queryId; hr = pin.QueryId(out queryId); DsError.ThrowExceptionForHR(hr); PinInfo pinInfo; hr = pin.QueryPinInfo(out pinInfo); DsError.ThrowExceptionForHR(hr); if (pinInfo.dir != direction) { continue; } IEnumMediaTypes mediaTypesEnum = null; try { hr = pin.EnumMediaTypes(out mediaTypesEnum); DsError.ThrowExceptionForHR(hr); AMMediaType[] mediaTypes = new AMMediaType[1]; int mtFetched; while (true) { hr = mediaTypesEnum.Next(1, mediaTypes, out mtFetched); DsError.ThrowExceptionForHR(hr); if (mtFetched == 1) { if (mediaTypes[0].formatType == FormatType.WaveEx) { yield return(new WavFormatInfo(mediaTypes[0])); } } else { break; } } } finally { if (mediaTypesEnum != null) { Marshal.ReleaseComObject(mediaTypesEnum); } } } else { break; } } finally { if (pins[0] != null) { Marshal.ReleaseComObject(pins[0]); } pins[0] = null; } } } finally { if (pinsEnum != null) { Marshal.ReleaseComObject(pinsEnum); } } }
public static VideoInfoHeader2 GetSBEFrameSize(string pathToFile) { int hr = 0; IGraphBuilder graph = null; IBaseFilter capFilter = null; IBaseFilter nRender = null; try { graph = (IGraphBuilder) new FilterGraph(); hr = graph.AddSourceFilter(pathToFile, "Source", out capFilter); DsError.ThrowExceptionForHR(hr); #if DEBUG using (DsROTEntry rot = new DsROTEntry(graph)) { #endif IPin vPin = null; IBaseFilter dec = null; IPin sgIn = null; IBaseFilter mpegDec = null; try { dec = (IBaseFilter) new DTFilter(); hr = graph.AddFilter(dec, "Decrypt"); DsError.ThrowExceptionForHR(hr); nRender = (IBaseFilter) new NullRenderer(); hr = graph.AddFilter((IBaseFilter)nRender, "Video Null Renderer"); DsError.ThrowExceptionForHR(hr); IBaseFilter dec1 = FilterDefinition.AddToFilterGraph(FatAttitude.WTVTranscoder.FilterDefinitions.Decrypt.DTFilterPBDA, ref graph, "Decrypt1"); if (dec1 != null) { Marshal.ReleaseComObject(dec1); } dec1 = null; mpegDec = FilterDefinition.AddToFilterGraph(FatAttitude.WTVTranscoder.FilterDefinitions.Video.VideoDecoderMpeg, ref graph, "MS MPEG Decoder"); sgIn = DsFindPin.ByDirection(mpegDec, PinDirection.Input, 0); IEnumPins ppEnum; IPin[] pPins = new IPin[1]; hr = capFilter.EnumPins(out ppEnum); DsError.ThrowExceptionForHR(hr); try { while (ppEnum.Next(1, pPins, IntPtr.Zero) == 0) { IEnumMediaTypes emtDvr = null; AMMediaType[] amtDvr = new AMMediaType[1]; try { pPins[0].EnumMediaTypes(out emtDvr); hr = emtDvr.Next(1, amtDvr, IntPtr.Zero); DsError.ThrowExceptionForHR(hr); if (amtDvr[0].majorType == MediaType.Video) { if (graph.Connect(pPins[0], sgIn) >= 0) { vPin = pPins[0]; break; } } if (pPins[0] != null) { Marshal.ReleaseComObject(pPins[0]); } } finally { if (emtDvr != null) { Marshal.ReleaseComObject(emtDvr); } DsUtils.FreeAMMediaType(amtDvr[0]); } } } finally { if (ppEnum != null) { Marshal.ReleaseComObject(ppEnum); } } FilterGraphTools.RenderPin(graph, mpegDec, "Video Output 1"); } finally { if (vPin != null) { Marshal.ReleaseComObject(vPin); } if (dec != null) { Marshal.ReleaseComObject(dec); } if (sgIn != null) { Marshal.ReleaseComObject(sgIn); } if (mpegDec != null) { Marshal.ReleaseComObject(mpegDec); } } EventCode ec; IMediaControl mControl = graph as IMediaControl; IMediaEvent mEvent = graph as IMediaEvent; hr = mControl.Pause(); DsError.ThrowExceptionForHR(hr); hr = mControl.Run(); DsError.ThrowExceptionForHR(hr); hr = mEvent.WaitForCompletion(1000, out ec); //DsError.ThrowExceptionForHR(hr); hr = mControl.Pause(); DsError.ThrowExceptionForHR(hr); hr = mControl.Stop(); DsError.ThrowExceptionForHR(hr); IPin mpgOut = null; sgIn = null; AMMediaType mt = new AMMediaType(); try { sgIn = DsFindPin.ByDirection(nRender, PinDirection.Input, 0); if (sgIn != null) { hr = sgIn.ConnectedTo(out mpgOut); DsError.ThrowExceptionForHR(hr); hr = graph.RemoveFilter(nRender); DsError.ThrowExceptionForHR(hr); Marshal.ReleaseComObject(nRender); nRender = null; nRender = (IBaseFilter) new NullRenderer(); hr = graph.AddFilter((IBaseFilter)nRender, "Video Null Renderer"); DsError.ThrowExceptionForHR(hr); hr = graph.Render(mpgOut); DsError.ThrowExceptionForHR(hr); hr = mpgOut.ConnectionMediaType(mt); DsError.ThrowExceptionForHR(hr); if (mt.formatType == FormatType.VideoInfo2) { VideoInfoHeader2 vih = (VideoInfoHeader2)Marshal.PtrToStructure(mt.formatPtr, typeof(VideoInfoHeader2)); return(vih); } } } finally { DsUtils.FreeAMMediaType(mt); if (mpgOut != null) { Marshal.ReleaseComObject(mpgOut); } if (sgIn != null) { Marshal.ReleaseComObject(sgIn); } } #if DEBUG } #endif } finally { if (nRender != null) { Marshal.ReleaseComObject(nRender); } if (capFilter != null) { Marshal.ReleaseComObject(capFilter); } if (graph != null) { while (Marshal.ReleaseComObject(graph) > 0) { ; } } } return(null); }
public int Clone(out IEnumMediaTypes ppEnum) { ppEnum = new MediaTypeEnumerator(pin) { index = index }; return S_OK; }
public void RefreshProperties() { this.Clear(); int hr = 0; // if the pin is connected, get it's ConnectionMediaType bool added = false; AMMediaType contype = new AMMediaType(); try { hr = _pin.ConnectionMediaType(contype); if (hr == 0) { AppendText(ConnectionMediaTypeString(contype)); DsUtils.FreeAMMediaType(contype); return; } } catch (Exception ex) { #if DEBUG MessageBox.Show(ex.Message, "Error getting media connection type"); #endif } // the pin's not connected, so get each of the prefered media types for the pin AppendText("Prefered Media Types:\r\n"); IEnumMediaTypes penum = null; hr = _pin.EnumMediaTypes(out penum); if (hr == 0 && penum != null) { AMMediaType[] mtypes = new AMMediaType[1]; IntPtr fetched = Marshal.AllocCoTaskMem(4); try { while (penum.Next(1, mtypes, fetched) == 0) { AppendText(ConnectionMediaTypeString(mtypes[0])); DsUtils.FreeAMMediaType(mtypes[0]); added = true; } } catch (Exception ex) { #if DEBUG MessageBox.Show(ex.Message, "Error getting pin prefered type"); #endif } finally { Marshal.FreeCoTaskMem(fetched); } // if we added no prefered media types to the textbox, set it to "None" if (added == false) { AppendText("None\r\n"); } Marshal.ReleaseComObject(penum); } }