Example #1
0
        public override string FilterRender(HtmlHelper htmlHelper)
        {
            string SelectedValue = htmlHelper.ViewContext.HttpContext.Request.QueryString[Name];

            if (FilterSource != null)
            {
                SelectListItem item = FilterSource.FirstOrDefault(n => n.Value == SelectedValue);
                if (item != null)
                {
                    item.Selected = true;
                }
                return(htmlHelper.DropDownList(base.Name, FilterSource, "Seçiniz", new { @class = "form-control" }).ToString());
            }

            if (GetMemberType() == typeof(int))
            {
                return(htmlHelper.TextBox(Name, SelectedValue, new { type = "number", @class = "form-control" }).ToString());
            }
            else if (GetMemberType() == typeof(string))
            {
                return(htmlHelper.TextBox(Name, SelectedValue, new { @class = "form-control" }).ToString());
            }
            else if (GetMemberType() == typeof(DateTime))
            {
                return(htmlHelper.TextBox(Name, SelectedValue, new { @class = "form-control" }).ToString());
            }
            else if (GetMemberType() == typeof(bool))
            {
                return(htmlHelper.CheckBox(Name, SelectedValue == "1").ToString());
            }
            else
            {
                return("");
            }
        }
Example #2
0
        /// <summary>
        /// Crée le filtre "File Splitter (demuxer)" et l'ajoute au graphe.
        /// </summary>
        /// <param name="graph">Le graphe.</param>
        /// <param name="filtersConfig">La configuration pour ce fichier.</param>
        /// <param name="sourceOutputPin">Le pin de sortie de la source.</param>
        /// <param name="parserOutputAudioPin">Le pin de sortie audio.</param>
        /// <param name="parserOutputVideoPin">Le pin de sortie vidéo</param>
        /// <returns>Le filtre File SPlitter.</returns>
        internal static IBaseFilter CreateSplitterFilter(IGraphBuilder graph, ExtensionFiltersSource filtersConfig, IPin sourceOutputPin,
                                                         out IPin parserOutputAudioPin, out IPin parserOutputVideoPin)
        {
            Type        filterType   = null;
            IBaseFilter parserFilter = null;

            FilterSource splitterSource = filtersConfig.Splitter;

            if (splitterSource.SourceType != FilterSourceTypeEnum.External)
            {
                throw new InvalidOperationException("The Splitter Filter Source cannot be Automatic");
            }

            CreateFilter(splitterSource.ExternalCLSID, splitterSource.Name, ref filterType, ref parserFilter);

            IPin parserInputPin = DsFindPin.ByDirection(parserFilter, PinDirection.Input, 0);

            int hr = graph.AddFilter(parserFilter, splitterSource.Name);

            DsError.ThrowExceptionForHR(hr);

            // Connectiong FileSource et Splitter
            hr = graph.Connect(sourceOutputPin, parserInputPin);
            DsError.ThrowExceptionForHR(hr);

            SafeRelease(sourceOutputPin);
            SafeRelease(parserInputPin);

            // Pins de sortie

            parserOutputAudioPin = DsFindPin.ByDirection(parserFilter, PinDirection.Output, 0);
            parserOutputVideoPin = DsFindPin.ByDirection(parserFilter, PinDirection.Output, 1);

            // Only video or audio
            if (parserOutputVideoPin == null)
            {
                parserOutputVideoPin = parserOutputAudioPin;
                parserOutputAudioPin = null;
            }

            parserOutputVideoPin.EnumMediaTypes(out IEnumMediaTypes enumMediaTypes);
            AMMediaType[] mts = { null };
            while (enumMediaTypes.Next(1, mts, IntPtr.Zero) == 0)
            {
                if (mts[0].majorType != MediaType.Video)
                {
                    // Invert in case it's not the appropriate media type
                    IPin temp = parserOutputAudioPin;
                    parserOutputAudioPin = parserOutputVideoPin;
                    parserOutputVideoPin = temp;
                    break;
                }
            }

            return(parserFilter);
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="splitCount"></param>
        /// <param name="creator"></param>
        /// <returns></returns>
        public IEnumerable <T> Load(string fileName, int splitCount, Func <string[], T> creator = null)
        {
            try
            {
                creator = creator ?? _Creator;
                Items   = null;
                if (File.Exists(fileName))
                {
                    var lines = File.ReadAllLines(fileName);
                    Items = (FilterSource?.Invoke(lines) ?? lines)
                            .Select(i => creator(i.Split(Separator.ToCharArray(), splitCount, StringSplitOptions.RemoveEmptyEntries)))
                            .ToArray();
                }
            }
            catch (Exception ex)
            {
                this.Error(ex);
            }

            return(Items);
        }
Example #4
0
        /// <summary>
        /// Connecte le File Splitter et le renderer vidéo en créant le décodeur vidéo.
        /// </summary>
        /// <param name="graph">Le graphe.</param>
        /// <param name="filtersConfig">La configuration pour ce fichier.</param>
        /// <param name="parserOutputVideoPin">Le pin de sortie vidéo</param>
        /// <param name="videoRendererInputPin">Le pin d'entrée du Renderer.</param>
        internal static void ConnectSplitterAndRendererWithDecoder(IGraphBuilder graph, ExtensionFiltersSource filtersConfig,
                                                                   IPin parserOutputVideoPin, IPin videoRendererInputPin)
        {
            FilterSource videoFilterSource = filtersConfig.VideoDecoder;

            switch (videoFilterSource.SourceType)
            {
            case FilterSourceTypeEnum.Auto:

                int hr = graph.Connect(parserOutputVideoPin, videoRendererInputPin);
                DsError.ThrowExceptionForHR(hr);

                break;

            case FilterSourceTypeEnum.External:
                if (new Guid(videoFilterSource.ExternalCLSID) == new Guid(CLSID_VIDEO_DECODER_DMO))
                {
                    // The DMO filter is handled differently
                    DMOWrapperFilter  dmoFilter = new DMOWrapperFilter();
                    IDMOWrapperFilter wrapper   = (IDMOWrapperFilter)dmoFilter;
                    hr = wrapper.Init(new Guid(CLSID_VIDEO_DECODER_DMO), DirectShowLib.DMO.DMOCategory.VideoDecoder);

                    DsError.ThrowExceptionForHR(hr);

                    if (dmoFilter is IBaseFilter decoderFilter)
                    {
                        hr = graph.AddFilter(decoderFilter, "WMVideo Decoder DMO");
                        DsError.ThrowExceptionForHR(hr);

                        IPin wmvDecoderInputPin = DsFindPin.ByDirection(decoderFilter, PinDirection.Input, 0);
                        hr = graph.ConnectDirect(parserOutputVideoPin, wmvDecoderInputPin, null);
                        DsError.ThrowExceptionForHR(hr);

                        IPin wmvDecoderOutputPin = DsFindPin.ByDirection(decoderFilter, PinDirection.Output, 0);
                        hr = graph.ConnectDirect(wmvDecoderOutputPin, videoRendererInputPin, null);
                        DsError.ThrowExceptionForHR(hr);

                        SafeRelease(wmvDecoderInputPin);
                        SafeRelease(wmvDecoderOutputPin);
                    }
                    else
                    {
                        wrapper = null;
                        SafeRelease(dmoFilter);
                        dmoFilter = null;
                    }
                }
                else
                {
                    Type        filterType     = null;
                    IBaseFilter externalFilter = null;

                    CreateFilter(videoFilterSource.ExternalCLSID, videoFilterSource.Name, ref filterType, ref externalFilter);

                    hr = graph.AddFilter(externalFilter, videoFilterSource.Name);
                    DsError.ThrowExceptionForHR(hr);

                    IPin externalDecoderInputPin = DsFindPin.ByDirection(externalFilter, PinDirection.Input, 0);
                    hr = graph.ConnectDirect(parserOutputVideoPin, externalDecoderInputPin, null);
                    DsError.ThrowExceptionForHR(hr);

                    IPin externalDecoderOutputPin = DsFindPin.ByDirection(externalFilter, PinDirection.Output, 0);
                    hr = graph.ConnectDirect(externalDecoderOutputPin, videoRendererInputPin, null);
                    DsError.ThrowExceptionForHR(hr);

                    SafeRelease(externalDecoderInputPin);
                    SafeRelease(externalDecoderOutputPin);
                }


                break;

            default:
                throw new ArgumentOutOfRangeException($"{nameof(videoFilterSource)}.{nameof(FilterSource.SourceType)}");
            }
        }
Example #5
0
        /// <summary>
        /// Parse la configuration DirectShow
        /// </summary>
        public static FiltersConfiguration Parse()
        {
            try
            {
                FiltersConfigurationSection configSection = FiltersConfigurationSection.GetConfiguration();

                FiltersConfiguration conf = new FiltersConfiguration();

                foreach (ExtensionElement extension in configSection.Extensions)
                {
                    var ext = new ExtensionFiltersSource()
                    {
                        Extension     = extension.Extension,
                        MinSpeedRatio = extension.MinSpeedRatio,
                        MaxSpeedRatio = extension.MaxSpeedRatio,
                        Splitter      = new FilterSource
                        {
                            Name          = extension.Splitter.Name,
                            SourceType    = extension.Splitter.SourceType,
                            ExternalCLSID = extension.Splitter.ExternalCLSID,
                        },
                        VideoDecoder = new FilterSource
                        {
                            Name          = extension.VideoDecoder.Name,
                            SourceType    = extension.VideoDecoder.SourceType,
                            ExternalCLSID = extension.VideoDecoder.ExternalCLSID,
                        },
                        AudioDecoder = new FilterSource
                        {
                            Name          = extension.AudioDecoder.Name,
                            SourceType    = extension.AudioDecoder.SourceType,
                            ExternalCLSID = extension.AudioDecoder.ExternalCLSID,
                        }
                    };

                    conf[ext.Extension] = ext;
                }

                // Filtres par défaut, minimum requis
                if (conf[".wmv"] == null)
                {
                    conf[".wmv"] = new ExtensionFiltersSource
                    {
                        Extension = ".wmv",
                        Splitter  = new FilterSource
                        {
                            Name          = "GDCL WMV Splitter",
                            SourceType    = FilterSourceTypeEnum.External,
                            ExternalCLSID = CLSID_WMV_SPLITTER,
                        },
                        VideoDecoder = new FilterSource
                        {
                            Name          = "LAV Video Decoder",
                            SourceType    = FilterSourceTypeEnum.External,
                            ExternalCLSID = CLSID_LAV_VIDEO_DECODER,
                        },
                        AudioDecoder = new FilterSource
                        {
                            Name       = "Auto Audio Decoder",
                            SourceType = FilterSourceTypeEnum.Auto,
                        }
                    };
                }

                // Vérification de l'exactitude des valeurs
                if (conf.Select(e => e.Extension).GroupBy(e => e).Any(g => g.Count() > 2))
                {
                    throw new ConfigurationErrorsException("Les extensions configurées doivent être uniques.");
                }

                foreach (var e in conf)
                {
                    if (e.Splitter.SourceType == FilterSourceTypeEnum.Auto)
                    {
                        throw new ConfigurationErrorsException("Le splitter ne peut pas être Auto");
                    }

                    if ((e.MinSpeedRatio.HasValue && !e.MaxSpeedRatio.HasValue) ||
                        (!e.MinSpeedRatio.HasValue && e.MaxSpeedRatio.HasValue))
                    {
                        throw new ConfigurationErrorsException("Les vitesses de lecture doivent être toutes les deux définies");
                    }

                    if (e.MinSpeedRatio.HasValue && e.MaxSpeedRatio.HasValue && e.MinSpeedRatio.Value > e.MaxSpeedRatio.Value)
                    {
                        throw new ConfigurationErrorsException("Les vitesses de lecture sont incorrectes");
                    }

                    var sources = new FilterSource[]
                    {
                        e.Splitter,
                        e.AudioDecoder,
                        e.VideoDecoder
                    };

                    foreach (var source in sources)
                    {
                        if (source.SourceType == FilterSourceTypeEnum.External && string.IsNullOrEmpty(source.ExternalCLSID))
                        {
                            throw new ConfigurationErrorsException("Une source externe doit être accompagnée d'un CLSID externe");
                        }

                        if (source.SourceType == FilterSourceTypeEnum.Auto && !string.IsNullOrEmpty(source.ExternalCLSID))
                        {
                            throw new ConfigurationErrorsException("Une source auto ne doit pas être accompagnée d'un CLSID externe");
                        }
                    }
                }

                return(conf);
            }
            catch (ConfigurationErrorsException ex)
            {
                TraceManager.TraceError(ex, "Erreur de configuration");
                MessageBox.Show(Resources.LocalizationResources.Error_Configuration_Filters, Resources.LocalizationResources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }
            catch (Exception e)
            {
                TraceManager.TraceError(e, "Erreur lors de l'initialisation de la configuration des filtres");
                MessageBox.Show(Resources.LocalizationResources.Exception_GenericMessage, Resources.LocalizationResources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }
        }