protected override void AddSourceFilter()
    {
      base.AddSourceFilter();
      //var muxer = new CodecInfo { CLSID = "{E4B7FAF9-9CFF-4FD5-AC16-0F250F5F97B7}", Name = "SolveigMM Matroska Muxer" };
      var muxer = new CodecInfo { CLSID = "{A28F324B-DDC5-4999-AA25-D3A7E25EF7A8}", Name = "Haali Matroska Muxer" };
      IBaseFilter muxerFilter = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, muxer.Name);

      // FileSink can be supported by muxer directly (Haali), or we need an additional file sink
      var fileSink = muxerFilter as IFileSinkFilter;
      if (fileSink == null)
      {
        var writer = new CodecInfo { CLSID = "{8596E5F0-0DA5-11D0-BD21-00A0C911CE86}", Name = "File writer" };
        fileSink = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, writer.Name) as IFileSinkFilter;
      }

      if (fileSink != null)
        fileSink.SetFileName(_targetFilename, null);

      using (DSFilter sourceFilter = new DSFilter(_streamSourceFilter))
      using (DSFilter muxerF = new DSFilter(muxerFilter))
      {
        for (int index = 0; index < sourceFilter.Output.Count; index++)
        {
          DSPin pin = sourceFilter.Output[index];
          using (pin)
          {
            if (index < muxerF.Input.Count)
              pin.Connect(muxerF.Input[index]);
          }
        }

        if (muxerF.OutputPin != null)
        {
          using (DSFilter writerF = new DSFilter((IBaseFilter)fileSink))
            muxerF.OutputPin.Connect(writerF.InputPin);
        }
      }
    }
예제 #2
0
 /// <summary>
 /// Try to add filter by name to graph.
 /// </summary>
 /// <param name="codecInfo">Filter name to add</param>
 /// <param name="filterCategory">GUID of filter category (<see cref="FilterCategory"/> members)></param>
 /// <returns>true if successful</returns>
 protected bool TryAdd(CodecInfo codecInfo, Guid filterCategory)
 {
   if (codecInfo == null)
     return false;
   IBaseFilter tempFilter = FilterGraphTools.AddFilterByName(_graphBuilder, filterCategory, codecInfo.Name);
   return tempFilter != null;
 }
예제 #3
0
 /// <summary>
 /// Try to add filter by name to graph.
 /// </summary>
 /// <param name="codecInfo">Filter name to add</param>
 /// <returns>true if successful</returns>
 protected bool TryAdd(CodecInfo codecInfo)
 {
   return TryAdd(codecInfo, FilterCategory.LegacyAmFilterCategory);
 }
예제 #4
0
    /// <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);
      }
    }
예제 #5
0
    /// <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);
      }
    }
예제 #6
0
    /// <summary>
    /// Enumerates available filters and returns a list of <see cref="CodecInfo"/>.
    /// </summary>
    /// <param name="filterCategory">GUID of filter category (<see cref="FilterCategory"/> members)></param>
    /// <returns></returns>
    public static List<CodecInfo> GetFiltersForCategory(Guid filterCategory)
    {
      List<CodecInfo> codecInfos = new List<CodecInfo>();

      using (var filtersInCategory = new DSCategory(filterCategory))
      {
        foreach (var filter in filtersInCategory)
        {
          CodecInfo codecInfo = new CodecInfo(filter.Name, filter.ClassID);
          codecInfos.Add(codecInfo);
        }
      }

      codecInfos.Sort();
      return codecInfos;
    }