/// <summary> /// Adds the EVR to graph. /// </summary> protected virtual void AddEvr() { ServiceRegistration.Get <ILogger>().Debug("{0}: Initialize EVR", PlayerTitle); _evr = (IBaseFilter) new EnhancedVideoRenderer(); IntPtr upDevice = SkinContext.Device.NativePointer; int hr = EvrInit(_evrCallback, (uint)upDevice.ToInt32(), _evr, SkinContext.Form.Handle, out _presenterInstance); if (hr != 0) { SafeEvrDeinit(); FilterGraphTools.TryRelease(ref _evr); throw new VideoPlayerException("Initializing of EVR failed"); } // Check if CC is enabled, in this case the EVR needs one more input pin VideoSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <VideoSettings>(); if (settings.EnableClosedCaption) { _streamCount++; } // Set the number of video/subtitle/cc streams that are allowed to be connected to EVR. This has to be done after the custom presenter is initialized. IEVRFilterConfig config = (IEVRFilterConfig)_evr; config.SetNumberOfStreams(_streamCount); _graphBuilder.AddFilter(_evr, EVR_FILTER_NAME); }
protected override void AddSourceFilter() { string sourceFilterName = GetSourceFilterName(_resourceAccessor.ResourcePathName); if (!string.IsNullOrEmpty(sourceFilterName)) { IBaseFilter sourceFilter = null; try { if (sourceFilterName == MPUrlSourceFilter.Downloader.FilterName) { _filterWrapper = FilterLoader.LoadFilterFromDll( Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), @"MPUrlSourceSplitter\MPUrlSourceSplitter.ax"), new Guid(MPUrlSourceFilter.Downloader.FilterCLSID)); sourceFilter = _filterWrapper.GetFilter(); if (sourceFilter != null) { _graphBuilder.AddFilter(sourceFilter, MPUrlSourceFilter.Downloader.FilterName); } } else { sourceFilter = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, sourceFilterName); } if (sourceFilter == null) { throw new OnlineVideosException(string.Format("Could not create instance of source filter: '{0}'", sourceFilterName)); } var filterStateEx = sourceFilter as MPUrlSourceFilter.IFilterStateEx; if (filterStateEx != null) { LoadAndWaitForMPUrlSourceFilter(filterStateEx); } else { var fileSourceFilter = sourceFilter as IFileSourceFilter; if (fileSourceFilter != null) { Marshal.ThrowExceptionForHR(fileSourceFilter.Load(_resourceAccessor.ResourcePathName, null)); } else { throw new OnlineVideosException(string.Format("'{0}' does not implement IFileSourceFilter", sourceFilterName)); } } FilterGraphTools.RenderOutputPins(_graphBuilder, sourceFilter); } finally { FilterGraphTools.TryRelease(ref sourceFilter); } } else { base.AddSourceFilter(); } }
public virtual void ReleaseGUIResources() { // Releases all Direct3D related resources _initialized = false; FilterState state; IMediaControl mc = (IMediaControl)_graphBuilder; mc.GetState(10, out state); if (state != FilterState.Stopped) { mc.StopWhenReady(); mc.Stop(); } if (_evr != null) { // Get the currently connected EVR Pins to restore the connections later FilterGraphTools.GetConnectedPins(_evr, PinDirection.Input, _evrConnectionPins); _graphBuilder.RemoveFilter(_evr); FilterGraphTools.TryRelease(ref _evr); } EvrDeinit(_presenterInstance); FreeEvrCallback(); }
/// <summary> /// Enumerates available filters and returns a list of <see cref="CodecInfo"/>. /// </summary> /// <param name="filterCategory">GUID of filter category (<see cref="DirectShowLib.FilterCategory"/> members)></param> /// <returns></returns> public static List <CodecInfo> GetFiltersForCategory(Guid filterCategory) { List <CodecInfo> codecInfos = new List <CodecInfo>(); ICreateDevEnum devEnum = null; IEnumMoniker enumMoniker = null; try { devEnum = (ICreateDevEnum) new CreateDevEnum(); int catResult = devEnum.CreateClassEnumerator(filterCategory, out enumMoniker, CDef.None); if (catResult == 0) { IMoniker[] moniker = new IMoniker[1]; while (enumMoniker.Next(1, moniker, IntPtr.Zero) == 0) { string filterName = FilterGraphTools.GetFriendlyName(moniker[0]); Guid filterClassId = FilterGraphTools.GetCLSID(moniker[0]); CodecInfo codecInfo = new CodecInfo(filterName, filterClassId); codecInfos.Add(codecInfo); FilterGraphTools.TryRelease(ref moniker[0]); } } codecInfos.Sort(); return(codecInfos); } finally { FilterGraphTools.TryRelease(ref enumMoniker); FilterGraphTools.TryRelease(ref devEnum); } }
/// <summary> /// Frees the audio/video codecs. /// </summary> protected override void FreeCodecs() { _pendingCmd = false; FilterGraphTools.TryRelease(ref _cmdOption); FilterGraphTools.TryRelease(ref _line21Decoder); FilterGraphTools.TryRelease(ref _dvdCtrl); FilterGraphTools.TryRelease(ref _dvdInfo); FilterGraphTools.TryRelease(ref _dvdGraph); base.FreeCodecs(); }
public static void AddStreamSourceFilter(string sourceFilterName, IResourceAccessor resourceAccessor, IGraphBuilder graphBuilder, out FilterFileWrapper filterWrapper) { filterWrapper = null; IBaseFilter sourceFilter = null; try { if (sourceFilterName == Utils.FilterName) { var filterPath = FileUtils.BuildAssemblyRelativePath(@"MPUrlSourceSplitter\MPUrlSourceSplitter.ax"); filterWrapper = FilterLoader.LoadFilterFromDll(filterPath, new Guid(Utils.FilterCLSID)); sourceFilter = filterWrapper.GetFilter(); if (sourceFilter != null) { graphBuilder.AddFilter(sourceFilter, Utils.FilterName); } } else { sourceFilter = FilterGraphTools.AddFilterByName(graphBuilder, FilterCategory.LegacyAmFilterCategory, sourceFilterName); } if (sourceFilter == null) { throw new UPnPRendererExceptions(string.Format("Could not create instance of source filter: '{0}'", sourceFilterName)); } string url = resourceAccessor.ResourcePathName; var filterStateEx = sourceFilter as OnlineVideos.MPUrlSourceFilter.IFilterStateEx; if (filterStateEx != null) { LoadAndWaitForMPUrlSourceFilter(url, filterStateEx); } else { var fileSourceFilter = sourceFilter as IFileSourceFilter; if (fileSourceFilter != null) { Marshal.ThrowExceptionForHR(fileSourceFilter.Load(resourceAccessor.ResourcePathName, null)); } else { throw new UPnPRendererExceptions(string.Format("'{0}' does not implement IFileSourceFilter", sourceFilterName)); } } FilterGraphTools.RenderOutputPins(graphBuilder, sourceFilter); } finally { FilterGraphTools.TryRelease(ref sourceFilter); } }
/// <summary> /// Frees the audio/video codecs. /// </summary> protected override void FreeCodecs() { // Free subtitle filter FilterGraphTools.TryDispose(ref _subtitleRenderer); FilterGraphTools.TryRelease(ref _subtitleFilter); // Free base class base.FreeCodecs(); // Free file source FilterGraphTools.TryRelease(ref _fileSource); }
/// <summary> /// Gets a list of DirectShow filter names that accept the passed MediaType/MediaSubType and output the passed MediaType/MediaSubType. /// </summary> /// <param name="inputMediaAndSubTypes">Array of MediaType/MediaSubType</param> /// <param name="outputMediaAndSubTypes">Array of MediaType/MediaSubType</param> /// <param name="merit"></param> /// <returns>List of names</returns> public static List <CodecInfo> GetFilters(Guid[] inputMediaAndSubTypes, Guid[] outputMediaAndSubTypes, Merit merit) { List <CodecInfo> filters = new List <CodecInfo>(); IEnumMoniker enumMoniker = null; IMoniker[] moniker = new IMoniker[1]; IFilterMapper2 mapper = (IFilterMapper2) new FilterMapper2(); try { mapper.EnumMatchingFilters( out enumMoniker, 0, true, merit, true, inputMediaAndSubTypes.Length, inputMediaAndSubTypes, null, null, false, true, outputMediaAndSubTypes.Length, outputMediaAndSubTypes, null, null); do { try { enumMoniker.Next(1, moniker, IntPtr.Zero); } catch { } if ((moniker[0] == null)) { break; } string filterName = FilterGraphTools.GetFriendlyName(moniker[0]); Guid filterClassId = FilterGraphTools.GetCLSID(moniker[0]); CodecInfo codecInfo = new CodecInfo(filterName, filterClassId); filters.Add(codecInfo); FilterGraphTools.TryRelease(ref moniker[0]); } while (true); filters.Sort(); return(filters); } finally { FilterGraphTools.TryRelease(ref enumMoniker); FilterGraphTools.TryRelease(ref mapper); } }
protected void AddFileSource() { IBaseFilter sourceFilter = null; try { sourceFilter = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, SOURCE_FILTER_NAME); FilterGraphTools.RenderOutputPins(_graphBuilder, sourceFilter); } finally { FilterGraphTools.TryRelease(ref sourceFilter); } }
protected override void FreeCodecs() { // Free all filters from graph if (_graphBuilder != null) { FilterGraphTools.RemoveAllFilters(_graphBuilder, true); } FilterGraphTools.TryDispose(ref _rot); FilterGraphTools.TryRelease(ref _graphBuilder); // Free file source FilterGraphTools.TryRelease(ref _fileSource); }
/// <summary> /// Frees the audio/video codecs. /// </summary> protected override void FreeCodecs() { // Release stream selectors ReleaseStreamSelectors(); // Free EVR SafeEvrDeinit(); FreeEvrCallback(); FilterGraphTools.TryRelease(ref _evr); base.FreeCodecs(); FilterGraphTools.TryDispose(ref _mpcSubsRenderer); FilterGraphTools.TryDispose(ref _rot); FilterGraphTools.TryRelease(ref _graphBuilder, true); }
/// <summary> /// Frees the audio/video codecs. /// </summary> protected override void FreeCodecs() { // Free subtitle filter FilterGraphTools.TryDispose(ref _subtitleRenderer); FilterGraphTools.TryRelease(ref _subtitleFilter); // Free locally mounted remote resources FilterGraphTools.TryDispose(ref _localFsRaHelper); // Free base class base.FreeCodecs(); // Free file source FilterGraphTools.TryRelease(ref _sourceFilter); }
/// <summary> /// Frees the audio/video codecs. /// </summary> protected override void FreeCodecs() { // Release stream selectors ReleaseStreamSelectors(); // Free all filters from graph if (_graphBuilder != null) { FilterGraphTools.RemoveAllFilters(_graphBuilder, true); } // Free EVR EvrDeinit(_presenterInstance); FreeEvrCallback(); FilterGraphTools.TryRelease(ref _evr); FilterGraphTools.TryDispose(ref _rot); FilterGraphTools.TryRelease(ref _graphBuilder); }
/// <summary> /// Gets a unique file name for the current DVD which contains the disc's ID. /// </summary> protected string GetResumeFilename() { long discId = 0; IBaseFilter dvdbasefilter = (IBaseFilter) new DVDNavigator(); IDvdInfo2 dvdInfo = dvdbasefilter as IDvdInfo2; StringBuilder path = new StringBuilder(1024); if (dvdInfo != null) { int actualSize; dvdInfo.GetDVDDirectory(path, 1024, out actualSize); dvdInfo.GetDiscID(path.ToString(), out discId); } FilterGraphTools.TryRelease(ref dvdbasefilter); FilterGraphTools.TryRelease(ref _dvdInfo); return(String.Format(@"D_{0:X}.dat", discId)); }
protected override void FreeCodecs() { // Signal shutdown _shutdownEvent.Set(); if (!_eventThread.Join(100)) { _eventThread.Abort(); } // Free subtitle filter FilterGraphTools.TryDispose(ref _subtitleRenderer); FilterGraphTools.TryRelease(ref _subtitleFilter); // Free OSD renderer FilterGraphTools.TryDispose(ref _osdRenderer); // Free file source FilterGraphTools.TryRelease(ref _bdReader); FilterGraphTools.TryDispose(ref _fileSource); // Free base class base.FreeCodecs(); }
/// <summary> /// Adds preferred audio/video codecs. /// </summary> protected virtual void AddPreferredCodecs() { VideoSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <VideoSettings>(); if (settings == null) { return; } //IAMPluginControl is supported in Win7 and later only. DirectShowPluginControl dspc = null; IAMPluginControl pc = null; try { dspc = new DirectShowPluginControl(); pc = dspc as IAMPluginControl; if (pc != null) { // Set black list of codecs to ignore, they are known to cause issues like hangs and crashes // MPEG Audio Decoder if (settings.DisabledCodecs != null && settings.DisabledCodecs.Any()) { foreach (var disabledCodec in settings.DisabledCodecs) { ServiceRegistration.Get <ILogger>().Info("{0}: Disable codec '{1}'", PlayerTitle, disabledCodec.Name); pc.SetDisabled(disabledCodec.GetCLSID(), true); } } if (settings.Mpeg2Codec != null) { pc.SetPreferredClsid(MediaSubType.Mpeg2Video, settings.Mpeg2Codec.GetCLSID()); } if (settings.H264Codec != null) { pc.SetPreferredClsid(MediaSubType.H264, settings.H264Codec.GetCLSID()); } if (settings.AVCCodec != null) { pc.SetPreferredClsid(CodecHandler.MEDIASUBTYPE_AVC, settings.AVCCodec.GetCLSID()); } if (settings.HEVCCodec != null) { DsGuid clsid = settings.HEVCCodec.GetCLSID(); pc.SetPreferredClsid(CodecHandler.MEDIASUBTYPE_HVC1, clsid); pc.SetPreferredClsid(CodecHandler.MEDIASUBTYPE_HEVC, clsid); } if (settings.Splitter != null) { pc.SetPreferredClsid(Guid.Empty, settings.Splitter.GetCLSID()); } if (settings.AudioCodecLATMAAC != null) { pc.SetPreferredClsid(CodecHandler.MEDIASUBTYPE_LATM_AAC_AUDIO, settings.AudioCodecLATMAAC.GetCLSID()); } if (settings.AudioCodecAAC != null) { pc.SetPreferredClsid(CodecHandler.MEDIASUBTYPE_AAC_AUDIO, settings.AudioCodecAAC.GetCLSID()); } if (settings.AudioCodec != null) { DsGuid clsid = settings.AudioCodec.GetCLSID(); foreach (Guid guid in new[] { MediaSubType.Mpeg2Audio, MediaSubType.MPEG1AudioPayload, CodecHandler.WMMEDIASUBTYPE_MP3, CodecHandler.MEDIASUBTYPE_MPEG1_AUDIO, CodecHandler.MEDIASUBTYPE_MPEG2_AUDIO }) { pc.SetPreferredClsid(guid, clsid); } } } } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Debug("{0}: Exception in IAMPluginControl: {1}", PlayerTitle, ex.ToString()); } finally { FilterGraphTools.TryRelease(ref dspc); } }
public void Dispose() { FilterGraphTools.TryRelease(ref _filter, true); Utilities.SystemAPI.NativeMethods.FreeLibrary(_dllHandle); }
/// <summary> /// Reconnects all filters in graph. /// </summary> /// <param name="graphBuilder">IGraphBuilder</param> /// <param name="filter">Current IBaseFilter in graph</param> static void ReConnectAll(IGraphBuilder graphBuilder, IBaseFilter filter) { IEnumPins pinEnum; FilterInfo info = FilterGraphTools.QueryFilterInfoAndFree(filter); IntPtr ptrFetched = Marshal.AllocCoTaskMem(4); int hr = filter.EnumPins(out pinEnum); if ((hr == 0) && (pinEnum != null)) { ServiceRegistration.Get <ILogger>().Info("got pins"); IPin[] pins = new IPin[1]; int iFetched; int iPinNo = 0; do { // Get the next pin iPinNo++; hr = pinEnum.Next(1, pins, ptrFetched); // In case of error stop the pin enumeration if (hr != 0) { break; } iFetched = Marshal.ReadInt32(ptrFetched); if (iFetched == 1 && pins[0] != null) { PinInfo pinInfo; hr = pins[0].QueryPinInfo(out pinInfo); if (hr == 0) { ServiceRegistration.Get <ILogger>().Info(" got pin#{0}:{1}", iPinNo - 1, pinInfo.name); FilterGraphTools.FreePinInfo(pinInfo); } else { ServiceRegistration.Get <ILogger>().Info(" got pin:?"); } PinDirection pinDir; pins[0].QueryDirection(out pinDir); if (pinDir == PinDirection.Output) { IntPtr other_ptr; hr = pins[0].ConnectedTo(out other_ptr); if (hr == 0 && other_ptr != IntPtr.Zero) { ServiceRegistration.Get <ILogger>().Info("Reconnecting {0}:{1}", info.achName, pinInfo.name); hr = graphBuilder.Reconnect(pins[0]); if (hr != 0) { ServiceRegistration.Get <ILogger>().Warn("Reconnect failed: {0}:{1}, code: 0x{2:x}", info.achName, pinInfo.name, hr); } IPin other = Marshal.GetObjectForIUnknown(other_ptr) as IPin; PinInfo otherPinInfo; other.QueryPinInfo(out otherPinInfo); ReConnectAll(graphBuilder, otherPinInfo.filter); FilterGraphTools.FreePinInfo(otherPinInfo); Marshal.ReleaseComObject(other); } } Marshal.ReleaseComObject(pins[0]); } else { ServiceRegistration.Get <ILogger>().Info("no pins?"); break; } }while (iFetched == 1); FilterGraphTools.TryRelease(ref pinEnum); Marshal.FreeCoTaskMem(ptrFetched); } }