Beispiel #1
0
 public StreamInfo(IAMStreamSelect streamSelector, int streamIndex, string name, int lcid)
 {
     StreamSelector = streamSelector;
     StreamIndex    = streamIndex;
     Name           = name;
     LCID           = lcid;
 }
Beispiel #2
0
        public void RenderAudio(IGraphBuilder pGraphBuilder, IBaseFilter splitter)
        {
            var pPin = DsUtils.GetPin(splitter, PinDirection.Output, new[] { MediaType.Audio });

            if (pPin != null)
            {
                _streamSelect = splitter as IAMStreamSelect;
                if (_streamSelect != null && BuildSoundRenderer(pGraphBuilder))
                {
                    var pInputPin = DsUtils.GetPin(_directSoundBaseFilter, PinDirection.Input);
                    var hr        = pGraphBuilder.Connect(pPin, pInputPin);
                    Marshal.ReleaseComObject(pInputPin);
                    if (hr == DsHlp.S_OK || hr == DsHlp.VFW_S_PARTIAL_RENDER)
                    {
                        _audioStreams.AddRange(_streamSelect.GetSelectableStreams().Where(s => s.MajorType == MediaType.Audio));
                    }
                    else
                    {
                        pGraphBuilder.RemoveFilter(_directSoundBaseFilter);
                        Marshal.FinalReleaseComObject(_directSoundBaseFilter);
                        _directSoundBaseFilter = null;
                        _basicAudio            = null;
                    }
                }

                Marshal.ReleaseComObject(pPin);
            }
        }
 public StreamInfo(IAMStreamSelect streamSelector, int streamIndex, string name, int lcid)
 {
   StreamSelector = streamSelector;
   StreamIndex = streamIndex;
   Name = name;
   LCID = lcid;
 }
Beispiel #4
0
 public StreamInfo(IAMStreamSelect streamSelector, int streamIndex, string name, int lcid)
 {
     StreamSelector = streamSelector;
     StreamIndex    = streamIndex;
     Name           = name;
     LCID           = lcid;
     IsAutoSubtitle = false;
 }
Beispiel #5
0
 public StreamInfo(IAMStreamSelect streamSelector, int streamIndex, string name, int lcid)
 {
   StreamSelector = streamSelector;
   StreamIndex = streamIndex;
   Name = name;
   LCID = lcid;
   IsAutoSubtitle = false;
 }
Beispiel #6
0
        public int OnRequestAudioChange()
        {
            IAMStreamSelect streamSelect = _sourceFilter as IAMStreamSelect;

            if (streamSelect != null)
            {
                streamSelect.Enable(0, 0);
            }
            return(0);
        }
Beispiel #7
0
        private void AddStreams(IAMStreamSelect pStrm)
        {
            int cStreams = 0;

            pStrm.Count(out cStreams);
            //GET STREAMS
            for (int istream = 0; istream < cStreams; istream++)
            {
                AMMediaType             sType;
                AMStreamSelectInfoFlags sFlag;
                int    sPDWGroup, sPLCid;
                string sName;
                object pppunk, ppobject;
                //STREAM INFO
                pStrm.Info(istream, out sType, out sFlag, out sPLCid,
                           out sPDWGroup, out sName, out pppunk, out ppobject);

                //SUBTITLE
                if (sPDWGroup == 2 && sName.LastIndexOf("No ") == -1)
                {
                    intSubs.Add(istream);
                    // Try Find Language by LCID
                    String langName = "";
                    if (sPLCid != 0)
                    {
                        int    size         = Util.Win32API.GetLocaleInfo(sPLCid, 2, null, 0);
                        String languageName = new String(' ', size);

                        Util.Win32API.GetLocaleInfo(sPLCid, 2, languageName, size);
                        if (!languageName.Equals(new String(' ', size)))
                        {
                            if (languageName.Contains("\0"))
                            {
                                langName = languageName.Substring(0, languageName.IndexOf("\0"));
                            }
                            else
                            {
                                langName = languageName;
                            }
                            int ipos = langName.IndexOf("(");
                            if (ipos > 0)
                            {
                                langName = langName.Substring(0, ipos);
                                langName = langName.Trim();
                            }
                        }
                    }
                    else
                    {
                        langName = sName;
                    }
                    intNames.Add(langName);
                }
            }
        }
        private void Config()
        {
            IGraphBuilder gb = (IGraphBuilder) new FilterGraph();
            IBaseFilter   pFilter;

            int hr = gb.RenderFile(@"nwn.mp1", null);

            DsError.ThrowExceptionForHR(hr);

            hr = gb.FindFilterByName("MPEG-I Stream Splitter", out pFilter);
            DsError.ThrowExceptionForHR(hr);

            m_ss = pFilter as IAMStreamSelect;
        }
Beispiel #9
0
        public static bool SelectStream(this IAMStreamSelect pStreamSelect, int index)
        {
            var result = false;

            int count;
            var hr = pStreamSelect.Count(out count);

            if (DsHlp.SUCCEEDED(hr) && count > index)
            {
                hr     = pStreamSelect.Enable(index, AMStreamSelectEnableFlags.Enable);
                result = DsHlp.SUCCEEDED(hr);
            }

            return(result);
        }
Beispiel #10
0
 public void FreeSubtitles()
 {
     if (vobSub != null)
     {
         DirectShowUtil.ReleaseComObject(vobSub);
     }
     if (embeddedSelector != null)
     {
         DirectShowUtil.ReleaseComObject(embeddedSelector);
     }
     vobSub           = null;
     embeddedSelector = null;
     intSubs.Clear();
     intNames.Clear();
     extCount = 0;
     current  = -1;
 }
Beispiel #11
0
        public static SelectableStream GetSelectableStream(this IAMStreamSelect pStreamSelect, int index)
        {
            SelectableStream result = null;

            pStreamSelect.InspectStream(index, (mt, name, enabled) =>
            {
                result = new SelectableStream
                {
                    Index     = index,
                    Name      = name,
                    Enabled   = enabled,
                    MajorType = mt.majorType,
                    SubType   = mt.subType
                };
            });

            return(result);
        }
Beispiel #12
0
        public static bool IsStreamSelected(this IAMStreamSelect pStreamSelect, int index)
        {
            var result = false;

            int count;
            var hr = pStreamSelect.Count(out count);

            if (DsHlp.SUCCEEDED(hr) && count > index)
            {
                var stream = pStreamSelect.GetSelectableStream(index);
                if (stream != null)
                {
                    result = stream.Enabled;
                }
            }

            return(result);
        }
Beispiel #13
0
        public void RenderSubpicture(IGraphBuilder pGraphBuilder, IBaseFilter splitter, IRenderer renderer)
        {
            var pPin = DsUtils.GetPin(splitter, PinDirection.Output, new[] { MediaType.Subtitle });

            if (pPin != null)
            {
                try
                {
                    _streamSelect = splitter as IAMStreamSelect;
                    if (_streamSelect != null)
                    {
                        TryRenderSubpicture(pGraphBuilder, pPin, renderer);
                    }
                }
                finally
                {
                    Marshal.ReleaseComObject(pPin);
                }
            }
        }
Beispiel #14
0
        public static IEnumerable <SelectableStream> GetSelectableStreams(this IAMStreamSelect pStreamSelect)
        {
            var result = new List <SelectableStream>();

            int count;
            var hr = pStreamSelect.Count(out count);

            if (DsHlp.SUCCEEDED(hr) && count > 0)
            {
                for (var i = 0; i < count; i++)
                {
                    var stream = pStreamSelect.GetSelectableStream(i);
                    if (stream != null)
                    {
                        result.Add(stream);
                    }
                }
            }

            return(result);
        }
Beispiel #15
0
        public static void InspectStream(this IAMStreamSelect pStreamSelect, int index, Action <AMMediaType, string, bool> inspect)
        {
            IntPtr ppmt;
            AMStreamSelectInfoFlags pdwFlags;
            int    plcid;
            int    pdwGroup;
            IntPtr ppszName;
            IntPtr ppObject;
            IntPtr ppUnk;

            var hr = pStreamSelect.Info(index, out ppmt, out pdwFlags, out plcid, out pdwGroup, out ppszName, out ppObject, out ppUnk);

            if (DsHlp.SUCCEEDED(hr))
            {
                var mt      = ppmt != IntPtr.Zero ? (AMMediaType)Marshal.PtrToStructure(ppmt, typeof(AMMediaType)) : new AMMediaType();
                var name    = Marshal.PtrToStringAuto(ppszName);
                var enabled = (pdwFlags & AMStreamSelectInfoFlags.Enabled) != AMStreamSelectInfoFlags.Disabled ||
                              (pdwFlags & AMStreamSelectInfoFlags.Exclusive) != AMStreamSelectInfoFlags.Disabled;

                inspect(mt, name, enabled);

                if (ppmt != IntPtr.Zero)
                {
                    DsUtils.FreeFormatBlock(ppmt);
                    Marshal.FreeCoTaskMem(ppmt);
                }

                Marshal.FreeCoTaskMem(ppszName);
                if (ppObject != IntPtr.Zero)
                {
                    Marshal.Release(ppObject);
                }
                if (ppUnk != IntPtr.Zero)
                {
                    Marshal.Release(ppUnk);
                }
            }
        }
    private void AddStreams(IAMStreamSelect pStrm)
    {
      int cStreams = 0;
      pStrm.Count(out cStreams);
      //GET STREAMS
      for (int istream = 0; istream < cStreams; istream++)
      {
        AMMediaType sType;
        AMStreamSelectInfoFlags sFlag;
        int sPDWGroup, sPLCid;
        string sName;
        object pppunk, ppobject;
        //STREAM INFO
        pStrm.Info(istream, out sType, out sFlag, out sPLCid,
                   out sPDWGroup, out sName, out pppunk, out ppobject);

        //SUBTITLE
        if (sPDWGroup == 2 && sName.LastIndexOf("No ") == -1)
        {
          intSubs.Add(istream);
          // Try Find Language by LCID
          String langName = "";
          if (sPLCid != 0)
          {
            int size = Util.Win32API.GetLocaleInfo(sPLCid, 2, null, 0);
            String languageName = new String(' ', size);

            Util.Win32API.GetLocaleInfo(sPLCid, 2, languageName, size);
            if (!languageName.Equals(new String(' ', size)))
            {
              if (languageName.Contains("\0"))
                langName = languageName.Substring(0, languageName.IndexOf("\0"));
              else
                langName = languageName;
              int ipos = langName.IndexOf("(");
              if (ipos > 0)
              {
                langName = langName.Substring(0, ipos);
                langName = langName.Trim();
              }
            }
          }
          else
          {
            langName = sName;
          }
          intNames.Add(langName);
        }
      }
    }
        public bool LoadSubtitles(IGraphBuilder graphBuilder, string filename)
        {
            FreeSubtitles();
            LoadSettings();

            {
                //remove InternalScriptRenderer as it takes subtitle pin
                IBaseFilter isr = null;
                DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.InternalScriptRenderer, out isr);
                if (isr != null)
                {
                    graphBuilder.RemoveFilter(isr);
                    DirectShowUtil.ReleaseComObject(isr);
                }
            }

            vobSub = (IDirectVobSub)DirectVobSubUtil.AddToGraph(graphBuilder);
            if (vobSub == null)
            {
                return(false);
            }

            {
                //set style
                Log.Debug("VideoPlayerVMR9: Setting DirectVobsub parameters");
                LOGFONT logFont = new LOGFONT();
                int     txtcolor;
                bool    fShadow, fOutLine, fAdvancedRenderer = false;
                int     size = Marshal.SizeOf(typeof(LOGFONT));
                vobSub.get_TextSettings(logFont, size, out txtcolor, out fShadow, out fOutLine, out fAdvancedRenderer);
                FontStyle fontStyle = defStyle.fontIsBold ? FontStyle.Regular : FontStyle.Bold;
                Font      Subfont   = new Font(defStyle.fontName, defStyle.fontSize, fontStyle, GraphicsUnit.Point,
                                               (byte)defStyle.fontCharset);
                Subfont.ToLogFont(logFont);
                fShadow  = defStyle.shadow > 0;
                fOutLine = defStyle.isBorderOutline;
                vobSub.put_TextSettings(logFont, size, defStyle.fontColor, fShadow, fOutLine, fAdvancedRenderer);
                vobSub.put_FileName(filename);

                bool fBuffer, fOnlyForced, fPolygonize;
                vobSub.get_VobSubSettings(out fBuffer, out fOnlyForced, out fPolygonize);
                if (selectionOff)
                {
                    vobSub.put_VobSubSettings(fBuffer, false, fPolygonize);
                }
                else
                {
                    vobSub.put_VobSubSettings(fBuffer, !this.autoShow, fPolygonize);
                }
            }

            {
                //load sub streams
                IBaseFilter hms = null;
                DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.HaaliGuid, out hms);
                if (hms == null)
                {
                    DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.LAVFilterSource, out hms);
                }
                if (hms == null)
                {
                    DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.LAVFilter, out hms);
                }
                embeddedSelector = hms as IAMStreamSelect;
                if (embeddedSelector != null)
                {
                    AddStreams(embeddedSelector);
                }

                vobSub.get_LanguageCount(out extCount);
                if (intSubs.Count > 0)
                {
                    //if there are embedded subtitles,
                    //last stream of directvobsub is currently selected embedded subtitle
                    extCount--;
                }
            }

            FFDShowEngine.DisableFFDShowSubtitles(graphBuilder);

            Current = 0;
            if (selectionOff)
            {
                Enable = false;
            }
            return(true);
        }
        private void AddStreams(IAMStreamSelect pStrm)
        {
            int cStreams = 0;

            pStrm.Count(out cStreams);
            //GET STREAMS
            for (int istream = 0; istream < cStreams; istream++)
            {
                AMMediaType             sType;
                AMStreamSelectInfoFlags sFlag;
                int    sPDWGroup, sPLCid;
                string sName;
                object pppunk, ppobject;
                //STREAM INFO
                pStrm.Info(istream, out sType, out sFlag, out sPLCid,
                           out sPDWGroup, out sName, out pppunk, out ppobject);

                //SUBTITLE
                if (sPDWGroup == 2 && sName.LastIndexOf("No ") == -1)
                {
                    intSubs.Add(istream);

                    // Add subtitle names
                    if (sName.ToLowerInvariant().Contains("forced"))
                    {
                        Regex regexLAVF  = new Regex(@"(?:S:\s)(?<lang_or_title>.+?)(?:\s*\[(?<lang>[^\]]*?)\])?(?:\s*\((?<info>[^\)]*?)\))?$");
                        Match resultLAVF = regexLAVF.Match(sName);
                        if (resultLAVF.Success)
                        {
                            string lang_or_title = resultLAVF.Groups[1].Value;
                            string lang          = resultLAVF.Groups[2].Value;
                            string info          = resultLAVF.Groups[3].Value;
                            if (lang.ToLowerInvariant().Contains("forced") || info.ToLowerInvariant().Contains("forced"))
                            {
                                if (!lang_or_title.ToLowerInvariant().Contains("forced"))
                                {
                                    sName = "S: " + lang_or_title + " Forced ";
                                }
                            }
                        }
                    }
                    SubtitleNames?.Add(sName);

                    // Add language names
                    // Try Find Language by LCID
                    string langName = "";
                    if (sPLCid != 0)
                    {
                        int    size         = Util.Win32API.GetLocaleInfo(sPLCid, 2, null, 0);
                        String languageName = new String(' ', size);

                        Util.Win32API.GetLocaleInfo(sPLCid, 2, languageName, size);
                        if (!languageName.Equals(new String(' ', size)))
                        {
                            if (languageName.Contains("\0"))
                            {
                                langName = languageName.Substring(0, languageName.IndexOf("\0"));
                            }
                            else
                            {
                                langName = languageName;
                            }
                            int ipos = langName.IndexOf("(");
                            if (ipos > 0)
                            {
                                langName = langName.Substring(0, ipos);
                                langName = langName.Trim();
                            }
                        }
                    }
                    else
                    {
                        langName = sName;
                    }
                    SubtitleLanguages.Add(langName);
                }
            }
        }
Beispiel #19
0
        public FilterStream(int id, IAMStreamSelect streams)
        {
            SS = streams;
            ID = id;

            Refresh(false);
        }
Beispiel #20
0
    private void ParseStreams(IAMStreamSelect pStrm)
    {
      int cStreams = 0;
      pStrm.Count(out cStreams);

      _audioStreams.Clear();
      _subtitleStreams.Clear();

      for (int istream = 0; istream < cStreams; istream++)
      {
        AMMediaType sType;
        AMStreamSelectInfoFlags sFlag;
        int sPDWGroup;
        int sPLCid;
        string sName;
        object pppunk; 
        object ppobject;

        pStrm.Info(istream, out sType, out sFlag, out sPLCid, out sPDWGroup, out sName, out pppunk, out ppobject);

        if (sPDWGroup == 1)
        {
          StreamInfo info = new StreamInfo(istream, sName);
          _audioStreams.Add(info);
        }

        if (sPDWGroup == 2)
        {
          StreamInfo info = new StreamInfo(istream, sName);
          _subtitleStreams.Add(info);
        }
      }
    }
    public bool LoadSubtitles(IGraphBuilder graphBuilder, string filename)
    {
      FreeSubtitles();
      LoadSettings();

      {
        //remove InternalScriptRenderer as it takes subtitle pin
        IBaseFilter isr = null;
        DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.InternalScriptRenderer, out isr);
        if (isr != null)
        {
          graphBuilder.RemoveFilter(isr);
          DirectShowUtil.ReleaseComObject(isr);
        }
      }

      vobSub = (IDirectVobSub)DirectVobSubUtil.AddToGraph(graphBuilder);
      if (vobSub == null)
        return false;

      {
        //set style
        Log.Debug("VideoPlayerVMR9: Setting DirectVobsub parameters");
        LOGFONT logFont = new LOGFONT();
        int txtcolor;
        bool fShadow, fOutLine, fAdvancedRenderer = false;
        int size = Marshal.SizeOf(typeof(LOGFONT));
        vobSub.get_TextSettings(logFont, size, out txtcolor, out fShadow, out fOutLine, out fAdvancedRenderer);
        FontStyle fontStyle = defStyle.fontIsBold ? FontStyle.Regular : FontStyle.Bold;
        Font Subfont = new Font(defStyle.fontName, defStyle.fontSize, fontStyle, GraphicsUnit.Point,
                                (byte)defStyle.fontCharset);
        Subfont.ToLogFont(logFont);
        fShadow = defStyle.shadow > 0;
        fOutLine = defStyle.isBorderOutline;
        vobSub.put_TextSettings(logFont, size, defStyle.fontColor, fShadow, fOutLine, fAdvancedRenderer);
        vobSub.put_FileName(filename);

        bool fBuffer, fOnlyForced, fPolygonize;
        vobSub.get_VobSubSettings(out fBuffer, out fOnlyForced, out fPolygonize);
        vobSub.put_VobSubSettings(fBuffer, !this.autoShow, fPolygonize);
      }

      {
        //load sub streams
        IBaseFilter hms = null;
        DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.HaaliGuid, out hms);
        if (hms == null)
          DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.LAVFilterSource, out hms);
        if (hms == null)
          DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.LAVFilter, out hms);
        embeddedSelector = hms as IAMStreamSelect;
        if (embeddedSelector != null)
        {
          AddStreams(embeddedSelector);
        }

        vobSub.get_LanguageCount(out extCount);
        if (intSubs.Count > 0)
        {
          //if there are embedded subtitles,
          //last stream of directvobsub is currently selected embedded subtitle
          extCount--;
        }
      }

      FFDShowEngine.DisableFFDShowSubtitles(graphBuilder);

      Current = 0;
      if (selectionOff)
      {
        Enable = false;
      }
      else
      {
        Enable = autoShow;
      }
      return true;
    }
 public void FreeSubtitles()
 {
   if (vobSub != null)
     DirectShowUtil.ReleaseComObject(vobSub);
   if (embeddedSelector != null)
     DirectShowUtil.ReleaseComObject(embeddedSelector);
   vobSub = null;
   embeddedSelector = null;
   intSubs.Clear();
   intNames.Clear();
   extCount = 0;
   current = -1;
 }
    private void AddStreams(IAMStreamSelect pStrm)
    {
      int cStreams = 0;
      pStrm.Count(out cStreams);
      //GET STREAMS
      for (int istream = 0; istream < cStreams; istream++)
      {
        AMMediaType sType;
        AMStreamSelectInfoFlags sFlag;
        int sPDWGroup, sPLCid;
        string sName;
        object pppunk, ppobject;
        //STREAM INFO
        pStrm.Info(istream, out sType, out sFlag, out sPLCid,
                   out sPDWGroup, out sName, out pppunk, out ppobject);

        //SUBTITLE
        if (sPDWGroup == 2 && sName.LastIndexOf("No ") == -1)
        {
          intSubs.Add(istream);

          // Add subtitle names
          if (sName.ToLowerInvariant().Contains("forced"))
          {
            Regex regexLAVF = new Regex(@"(?:S:\s)(?<lang_or_title>.+?)(?:\s*\[(?<lang>[^\]]*?)\])?(?:\s*\((?<info>[^\)]*?)\))?$");
            Match resultLAVF = regexLAVF.Match(sName);
            if (resultLAVF.Success)
            {
              string lang_or_title = resultLAVF.Groups[1].Value;
              string lang = resultLAVF.Groups[2].Value;
              string info = resultLAVF.Groups[3].Value;
              if (lang.ToLowerInvariant().Contains("forced") || info.ToLowerInvariant().Contains("forced"))
              {
                if (!lang_or_title.ToLowerInvariant().Contains("forced"))
                {
                  sName = "S: " + lang_or_title + " Forced ";
                }
              }
            }
          }
          SubtitleNames?.Add(sName);

          // Add language names
          // Try Find Language by LCID
          string langName = "";
          if (sPLCid != 0)
          {
            int size = Util.Win32API.GetLocaleInfo(sPLCid, 2, null, 0);
            String languageName = new String(' ', size);

            Util.Win32API.GetLocaleInfo(sPLCid, 2, languageName, size);
            if (!languageName.Equals(new String(' ', size)))
            {
              if (languageName.Contains("\0"))
                langName = languageName.Substring(0, languageName.IndexOf("\0"));
              else
                langName = languageName;
              int ipos = langName.IndexOf("(");
              if (ipos > 0)
              {
                langName = langName.Substring(0, ipos);
                langName = langName.Trim();
              }
            }
          }
          else
          {
            langName = sName;
          }
          SubtitleLanguages.Add(langName);
        }
      }
    }